1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +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

@ -52,19 +52,27 @@ static void *_fix_init(struct io_engine *engine)
uint8_t buffer[T_BLOCK_SIZE]; uint8_t buffer[T_BLOCK_SIZE];
struct fixture *f = malloc(sizeof(*f)); struct fixture *f = malloc(sizeof(*f));
unsigned b, i; unsigned b, i;
struct statvfs fsdata = { 0 };
static int _runs_is_tmpfs = -1; static int _runs_is_tmpfs = -1;
memset(buffer, 0, sizeof(buffer)); memset(buffer, 0, sizeof(buffer));
T_ASSERT(f);
if (_runs_is_tmpfs == -1) { if (_runs_is_tmpfs == -1) {
// With testing in tmpfs directory O_DIRECT cannot be used snprintf(f->fname, sizeof(f->fname), "unit-test-XXXXXX");
// tmpfs has f_fsid == 0 (unsure if this is best guess) /* coverity[secure_temp] don't care */
_runs_is_tmpfs = (statvfs(".", &fsdata) == 0 && !fsdata.f_fsid) ? 1 : 0; f->fd = mkstemp(f->fname);
if (_runs_is_tmpfs) 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"); 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 */ /* coverity[secure_temp] don't care */