The test is only allowed to run in systems that know and in filesystems which support O_DIRECT.
Signed-off-by: Fabiano Rosas <faro...@suse.de> --- - added ifdefs for O_DIRECT and a probing function --- tests/qtest/migration-helpers.c | 39 +++++++++++++++++++++++++++++++++ tests/qtest/migration-helpers.h | 1 + tests/qtest/migration-test.c | 35 +++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/tests/qtest/migration-helpers.c b/tests/qtest/migration-helpers.c index 24fb7b3525..02b92f0cb6 100644 --- a/tests/qtest/migration-helpers.c +++ b/tests/qtest/migration-helpers.c @@ -292,3 +292,42 @@ char *resolve_machine_version(const char *alias, const char *var1, return find_common_machine_version(machine_name, var1, var2); } + +#ifdef O_DIRECT +/* + * Probe for O_DIRECT support on the filesystem. Since this is used + * for tests, be conservative, if anything fails, assume it's + * unsupported. + */ +bool probe_o_direct_support(const char *tmpfs) +{ + g_autofree char *filename = g_strdup_printf("%s/probe-o-direct", tmpfs); + int fd, flags = O_CREAT | O_RDWR | O_DIRECT; + void *buf; + ssize_t ret, len; + uint64_t offset; + + fd = open(filename, flags, 0660); + if (fd < 0) { + unlink(filename); + return false; + } + + /* + * Assuming 4k should be enough to satisfy O_DIRECT alignment + * requirements. The migration code uses 1M to be conservative. + */ + len = 0x100000; + offset = 0x100000; + + buf = g_malloc0(len); + ret = pwrite(fd, buf, len, offset); + unlink(filename); + + if (ret < 0) { + return false; + } + + return true; +} +#endif diff --git a/tests/qtest/migration-helpers.h b/tests/qtest/migration-helpers.h index e31dc85cc7..15df009d35 100644 --- a/tests/qtest/migration-helpers.h +++ b/tests/qtest/migration-helpers.h @@ -47,4 +47,5 @@ char *find_common_machine_version(const char *mtype, const char *var1, const char *var2); char *resolve_machine_version(const char *alias, const char *var1, const char *var2); +bool probe_o_direct_support(const char *tmpfs); #endif /* MIGRATION_HELPERS_H */ diff --git a/tests/qtest/migration-test.c b/tests/qtest/migration-test.c index 5c5725687c..192b8ec993 100644 --- a/tests/qtest/migration-test.c +++ b/tests/qtest/migration-test.c @@ -2222,6 +2222,36 @@ static void test_multifd_file_fixed_ram(void) test_file_common(&args, true); } +#ifdef O_DIRECT +static void *migrate_multifd_fixed_ram_dio_start(QTestState *from, + QTestState *to) +{ + migrate_multifd_fixed_ram_start(from, to); + + migrate_set_parameter_bool(from, "direct-io", true); + migrate_set_parameter_bool(to, "direct-io", true); + + return NULL; +} + +static void test_multifd_file_fixed_ram_dio(void) +{ + g_autofree char *uri = g_strdup_printf("file:%s/%s", tmpfs, + FILE_TEST_FILENAME); + MigrateCommon args = { + .connect_uri = uri, + .listen_uri = "defer", + .start_hook = migrate_multifd_fixed_ram_dio_start, + }; + + if (!probe_o_direct_support(tmpfs)) { + g_test_skip("Filesystem does not support O_DIRECT"); + return; + } + + test_file_common(&args, true); +} +#endif static void test_precopy_tcp_plain(void) { @@ -3476,6 +3506,11 @@ int main(int argc, char **argv) qtest_add_func("/migration/multifd/file/fixed-ram/live", test_multifd_file_fixed_ram_live); +#ifdef O_DIRECT + qtest_add_func("/migration/multifd/file/fixed-ram/dio", + test_multifd_file_fixed_ram_dio); +#endif + #ifdef CONFIG_GNUTLS qtest_add_func("/migration/precopy/unix/tls/psk", test_precopy_unix_tls_psk); -- 2.35.3