[PATCH libaio 22/28] harness: Add fallback code for filesystems not supporting O_DIRECT
authorGuillem Jover <guillem@hadrons.org>
Sat, 20 Jul 2019 19:21:01 +0000 (21:21 +0200)
committerGuillem Jover <guillem@debian.org>
Tue, 2 Nov 2021 23:56:45 +0000 (23:56 +0000)
When running the harness on a filesystem such as a tmpfs, which do not
support O_DIRECT, fallback to calls without the flag.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
[JEM: change from duplicating the open call to using F_SETFL]
[JEM: 18 and 21 require O_DIRECT-skip if not present]
Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
Gbp-Pq: Topic upstream
Gbp-Pq: Name 0022-harness-Add-fallback-code-for-filesystems-not-suppor.patch

harness/cases/17.t
harness/cases/18.t
harness/cases/19.t
harness/cases/21.t

index 38ada4d8619bafa3f44e12028b32fef179651848..b4b6660a932483168928d6021c488557606d2341 100644 (file)
@@ -119,7 +119,7 @@ void prune(io_context_t io_ctx, int max_ios, int getevents_type)
 
 void run_test(int max_ios, int getevents_type)
 {
-       int fd, ret;
+       int fd, ret, flags;
        long i, to_submit;
        struct iocb **iocb_sub;
        io_context_t io_ctx;
@@ -137,9 +137,16 @@ void run_test(int max_ios, int getevents_type)
        events = calloc(max_ios, sizeof(*events));
 
        unlink(filename);
-       fd = open(filename, O_CREAT | O_RDWR | O_DIRECT, 0644);
+       fd = open(filename, O_CREAT | O_RDWR, 0644);
        assert(fd >= 0);
 
+       /*
+        * Use O_DIRECT if it's available.  If it's not, the test code
+        * will still operate correctly, just potentially slower.
+        */
+       flags = fcntl(fd, F_GETFL, 0);
+       fcntl(fd, F_SETFL, flags | O_DIRECT);
+
        ret = ftruncate(fd, max_ios * io_size);
        assert(!ret);
 
index daa1d26adcd6f5f66dcd3e77f53637b4ff61fa96..e8dbcd178064284e75e99a55a90c3b9fb65fde5e 100644 (file)
@@ -53,6 +53,8 @@ aio_worker(void *ptr)
        assert(buffer != NULL);
 
        fd = open(FILENAME, O_DIRECT|O_RDONLY);
+       if (fd < 0 && errno == EINVAL)
+               exit(3); /* skip this test, O_DIRECT is unavailable */
        assert(fd >= 0);
 
        for (i = 0; i < 1000; i++) {
index 5c3e0d68b3682e17c1f3436f25c6c71b3a164e38..ba1c620167fe0e5ee652ceac432a016f810539a4 100644 (file)
@@ -38,15 +38,21 @@ struct aio_ring {
 int
 open_temp_file(void)
 {
-       int fd;
+       int fd, flags;
        char template[sizeof(TEMPLATE)];
 
        strncpy(template, TEMPLATE, sizeof(template));
-       fd = mkostemp(template, O_DIRECT);
+       fd = mkstemp(template);
        if (fd < 0) {
                perror("mkstemp");
                exit(1);
        }
+       /*
+        * O_DIRECT is desirable, but not required for this test.
+        */
+       flags = fcntl(F_GETFL, 0);
+       fcntl(F_SETFL, flags | O_DIRECT);
+
        unlink(template);
        return fd;
 }
index fe33a9de66c64738eb49d29286b4d6428b4826f6..ba988ed72320cb0cb8d9187977a1f2097ea5a104 100644 (file)
@@ -92,7 +92,10 @@ test_main()
         */
        flags = fcntl(fd, F_GETFL);
        ret = fcntl(fd, F_SETFL, flags | O_DIRECT);
-       if (ret != 0) {
+       if (ret < 0) {
+               /* SKIP this test if O_DIRECT is not available on this fs */
+               if (errno == EINVAL)
+                       return 3;
                perror("fcntl");
                return 1;
        }