1
0
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:
Zdenek Kabelac 2021-10-15 09:44:15 +02:00
parent 52a52d5567
commit 037165300e

View File

@ -49,31 +49,39 @@ static uint64_t byte(block_address b, uint64_t offset)
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 };
uint8_t buffer[T_BLOCK_SIZE];
struct fixture *f = malloc(sizeof(*f));
unsigned b, i;
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");
}
(void) unlink(f->fname);
}
T_ASSERT(f);
snprintf(f->fname, sizeof(f->fname), "unit-test-XXXXXX");
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);
for (b = 0; b < NR_BLOCKS; b++) {
for (i = 0; i < sizeof(buffer); i++)
buffer[i] = _pattern_at(INIT_PATTERN, byte(b, i));
for (i = 0; i < sizeof(buffer); i++)
buffer[i] = _pattern_at(INIT_PATTERN, byte(b, i));
T_ASSERT(write(f->fd, buffer, T_BLOCK_SIZE) > 0);
}
@ -89,7 +97,7 @@ static void *_fix_init(struct io_engine *engine)
f->di = bcache_set_fd(f->fd);
return f;
return f;
}
static void *_async_init(void)