src/feature: add IO_URING feature checking
[xfstests-dev.git] / src / feature.c
index a7eb75950b4ba2e70e3cefc32f49db08d63f9f1b..df550cf6e1919c4ff6a861ca5689f6d50207dc9a 100644 (file)
@@ -19,6 +19,7 @@
  *
  * Test for machine features
  *   -A  test whether AIO syscalls are available
+ *   -R  test whether IO_URING syscalls are available
  *   -o  report a number of online cpus
  *   -s  report pagesize
  *   -w  report bits per long
 #include <libaio.h>
 #endif
 
+#ifdef HAVE_LIBURING_H
+#include <liburing.h>
+#endif
+
 #ifndef USRQUOTA
 #define USRQUOTA  0
 #endif
@@ -59,7 +64,7 @@ usage(void)
        fprintf(stderr, "Usage: feature [-v] -<q|u|g|p|U|G|P> <filesystem>\n");
        fprintf(stderr, "       feature [-v] -c <file>\n");
        fprintf(stderr, "       feature [-v] -t <file>\n");
-       fprintf(stderr, "       feature -A | -o | -s | -w\n");
+       fprintf(stderr, "       feature -A | -R | -o | -s | -w\n");
        exit(1);
 }
 
@@ -215,6 +220,29 @@ check_aio_support(void)
 #endif
 }
 
+static int
+check_uring_support(void)
+{
+#ifdef HAVE_LIBURING_H
+       struct io_uring ring;
+       int err;
+
+       err = io_uring_queue_init(1, &ring, 0);
+       if (err == 0)
+               return 0;
+
+       if (err == -ENOSYS) /* CONFIG_IO_URING=n */
+               return 1;
+
+       fprintf(stderr, "unexpected error from io_uring_queue_init(): %s\n",
+               strerror(-err));
+       return 2;
+#else
+       /* liburing is unavailable, assume IO_URING is unsupported */
+       return 1;
+#endif
+}
+
 
 int
 main(int argc, char **argv)
@@ -228,6 +256,7 @@ main(int argc, char **argv)
        int     pflag = 0;
        int     Pflag = 0;
        int     qflag = 0;
+       int     Rflag = 0;
        int     sflag = 0;
        int     uflag = 0;
        int     Uflag = 0;
@@ -235,7 +264,7 @@ main(int argc, char **argv)
        int     oflag = 0;
        char    *fs = NULL;
 
-       while ((c = getopt(argc, argv, "ActgGopPqsuUvw")) != EOF) {
+       while ((c = getopt(argc, argv, "ActgGopPqRsuUvw")) != EOF) {
                switch (c) {
                case 'A':
                        Aflag++;
@@ -264,6 +293,9 @@ main(int argc, char **argv)
                case 'q':
                        qflag++;
                        break;
+               case 'R':
+                       Rflag++;
+                       break;
                case 's':
                        sflag++;
                        break;
@@ -289,7 +321,7 @@ main(int argc, char **argv)
                if (optind != argc-1)   /* need a device */
                        usage();
                fs = argv[argc-1];
-       } else if (Aflag || wflag || sflag || oflag) {
+       } else if (Aflag || Rflag || wflag || sflag || oflag) {
                if (optind != argc)
                        usage();
        } else 
@@ -317,6 +349,9 @@ main(int argc, char **argv)
        if (Aflag)
                return(check_aio_support());
 
+       if (Rflag)
+               return(check_uring_support());
+
        if (sflag) {
                printf("%d\n", getpagesize());
                exit(0);