From 6f87118198dd512b4251e8bd441d98ef3573423f Mon Sep 17 00:00:00 2001 From: Zorro Lang Date: Sun, 8 Nov 2020 20:26:21 +0800 Subject: [PATCH] src/feature: add IO_URING feature checking IO_URING is a new feature for GNU/Linux system, if someone case of xfstests tests this feature, better to check if current system supports it, or need _notrun. Signed-off-by: Zorro Lang Reviewed-by: Eryu Guan Signed-off-by: Eryu Guan --- src/Makefile | 4 ++++ src/feature.c | 41 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Makefile b/src/Makefile index 020e1dc9..919d77c4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -66,6 +66,10 @@ SUBDIRS += aio-dio-regress LLDLIBS += -laio endif +ifeq ($(HAVE_URING), true) +LLDLIBS += -luring +endif + CFILES = $(TARGETS:=.c) LDIRT = $(TARGETS) fssum diff --git a/src/feature.c b/src/feature.c index a7eb7595..df550cf6 100644 --- a/src/feature.c +++ b/src/feature.c @@ -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 @@ -39,6 +40,10 @@ #include #endif +#ifdef HAVE_LIBURING_H +#include +#endif + #ifndef USRQUOTA #define USRQUOTA 0 #endif @@ -59,7 +64,7 @@ usage(void) fprintf(stderr, "Usage: feature [-v] - \n"); fprintf(stderr, " feature [-v] -c \n"); fprintf(stderr, " feature [-v] -t \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); -- 2.30.2