diff mbox series

[1/3] src/feature: add IO_URING feature checking

Message ID 20200916171443.29546-2-zlang@redhat.com (mailing list archive)
State New, archived
Headers show
Series xfstests: add IO_URING test cases | expand

Commit Message

Zorro Lang Sept. 16, 2020, 5:14 p.m. UTC
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 <zlang@redhat.com>
---
 src/Makefile  |  4 ++++
 src/feature.c | 41 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 3 deletions(-)

Comments

Brian Foster Oct. 2, 2020, 6:19 p.m. UTC | #1
On Thu, Sep 17, 2020 at 01:14:41AM +0800, Zorro Lang wrote:
> 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 <zlang@redhat.com>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  src/Makefile  |  4 ++++
>  src/feature.c | 41 ++++++++++++++++++++++++++++++++++++++---
>  2 files changed, 42 insertions(+), 3 deletions(-)
> 
> diff --git a/src/Makefile b/src/Makefile
> index 643c1916..f1422c5c 100644
> --- a/src/Makefile
> +++ b/src/Makefile
> @@ -65,6 +65,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 <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);
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/src/Makefile b/src/Makefile
index 643c1916..f1422c5c 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -65,6 +65,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 <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);