ltp/fsstress: don't fail on io_uring ENOSYS
authorEric Sandeen <sandeen@redhat.com>
Thu, 28 Jan 2021 21:31:40 +0000 (15:31 -0600)
committerEryu Guan <guaneryu@gmail.com>
Sun, 7 Feb 2021 14:41:58 +0000 (22:41 +0800)
We might have URING #defined at build time, but be running on a kernel
which does not support it.

For that reason, we should not exit with an error if
io_uring_queue_init() fails with ENOSYS. We can just note the lack of
support and skip all future io_uring operations.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
ltp/fsstress.c

index 22df5e3..7375193 100644 (file)
@@ -35,6 +35,7 @@ io_context_t  io_ctx;
 #include <liburing.h>
 #define URING_ENTRIES  1
 struct io_uring        ring;
+bool have_io_uring;                    /* to indicate runtime availability */
 #endif
 #include <sys/syscall.h>
 #include <sys/xattr.h>
@@ -706,9 +707,15 @@ int main(int argc, char **argv)
                        }
 #endif
 #ifdef URING
+                       have_io_uring = true;
+                       /* If ENOSYS, just ignore uring, other errors are fatal. */
                        if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
-                               fprintf(stderr, "io_uring_queue_init failed\n");
-                               exit(1);
+                               if (errno == ENOSYS) {
+                                       have_io_uring = false;
+                               } else {
+                                       fprintf(stderr, "io_uring_queue_init failed\n");
+                                       exit(1);
+                               }
                        }
 #endif
                        for (i = 0; !loops || (i < loops); i++)
@@ -720,7 +727,8 @@ int main(int argc, char **argv)
                        }
 #endif
 #ifdef URING
-                       io_uring_queue_exit(&ring);
+                       if (have_io_uring)
+                               io_uring_queue_exit(&ring);
 #endif
                        cleanup_flist();
                        free(freq_table);
@@ -2208,6 +2216,9 @@ do_uring_rw(int opno, long r, int flags)
        struct iovec    iovec;
        int             iswrite = (flags & (O_WRONLY | O_RDWR)) ? 1 : 0;
 
+       if (!have_io_uring)
+               return;
+
        init_pathname(&f);
        if (!get_fname(FT_REGFILE, r, &f, NULL, NULL, &v)) {
                if (v)