mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
unit-test: better check for O_DIRECT
Instead of guessing tmpfs usage, just directly try if we could reopen file with O_DIRECT on the used filesystem.
This commit is contained in:
parent
52a52d5567
commit
037165300e
@ -52,19 +52,27 @@ static void *_fix_init(struct io_engine *engine)
|
||||
uint8_t buffer[T_BLOCK_SIZE];
|
||||
struct fixture *f = malloc(sizeof(*f));
|
||||
unsigned b, i;
|
||||
struct statvfs fsdata = { 0 };
|
||||
static int _runs_is_tmpfs = -1;
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
T_ASSERT(f);
|
||||
|
||||
if (_runs_is_tmpfs == -1) {
|
||||
// With testing in tmpfs directory O_DIRECT cannot be used
|
||||
// tmpfs has f_fsid == 0 (unsure if this is best guess)
|
||||
_runs_is_tmpfs = (statvfs(".", &fsdata) == 0 && !fsdata.f_fsid) ? 1 : 0;
|
||||
if (_runs_is_tmpfs)
|
||||
snprintf(f->fname, sizeof(f->fname), "unit-test-XXXXXX");
|
||||
/* coverity[secure_temp] don't care */
|
||||
f->fd = mkstemp(f->fname);
|
||||
T_ASSERT(f->fd >= 0);
|
||||
(void) close(f->fd);
|
||||
// test if we can reopen with O_DIRECT
|
||||
if ((f->fd = open(f->fname, O_RDWR | O_DIRECT)) >= 0) {
|
||||
_runs_is_tmpfs = 0;
|
||||
(void) close(f->fd);
|
||||
} else {
|
||||
_runs_is_tmpfs = 1; // likely running on tmpfs
|
||||
printf(" Running test in tmpfs, *NOT* using O_DIRECT\n");
|
||||
}
|
||||
|
||||
T_ASSERT(f);
|
||||
(void) unlink(f->fname);
|
||||
}
|
||||
|
||||
snprintf(f->fname, sizeof(f->fname), "unit-test-XXXXXX");
|
||||
/* coverity[secure_temp] don't care */
|
||||
|
Loading…
Reference in New Issue
Block a user