diff mbox series

[1/3] fsstress: check io_uring_queue_init errno properly

Message ID 20240306091935.4090399-2-zlang@kernel.org (mailing list archive)
State New, archived
Headers show
Series fstests: fix io_uring testing | expand

Commit Message

Zorro Lang March 6, 2024, 9:19 a.m. UTC
As the manual of io_uring_queue_init says "io_uring_queue_init(3)
returns 0 on success and -errno on failure". We should check if the
return value is -ENOSYS, not the errno.

Fixes: d15b1721f284 ("ltp/fsstress: don't fail on io_uring ENOSYS")
Signed-off-by: Zorro Lang <zlang@kernel.org>
---
 ltp/fsstress.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Darrick J. Wong March 6, 2024, 3:53 p.m. UTC | #1
On Wed, Mar 06, 2024 at 05:19:33PM +0800, Zorro Lang wrote:
> As the manual of io_uring_queue_init says "io_uring_queue_init(3)
> returns 0 on success and -errno on failure". We should check if the
> return value is -ENOSYS, not the errno.

/me checks liburing source code and sees that the library returns a
negative error code without touching errno (the semi global error code
variable) at all.  That's an unfortunate quirk of the manpage, but this
code here is correct...

> Fixes: d15b1721f284 ("ltp/fsstress: don't fail on io_uring ENOSYS")
> Signed-off-by: Zorro Lang <zlang@kernel.org>
> ---
>  ltp/fsstress.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/ltp/fsstress.c b/ltp/fsstress.c
> index 63c75767..482395c4 100644
> --- a/ltp/fsstress.c
> +++ b/ltp/fsstress.c
> @@ -763,8 +763,8 @@ int main(int argc, char **argv)
>  #ifdef URING
>  			have_io_uring = true;
>  			/* If ENOSYS, just ignore uring, other errors are fatal. */
> -			if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
> -				if (errno == ENOSYS) {
> +			if ((c = io_uring_queue_init(URING_ENTRIES, &ring, 0)) != 0) {
> +				if (c == -ENOSYS) {
>  					have_io_uring = false;
>  				} else {
>  					fprintf(stderr, "io_uring_queue_init failed\n");

But why not:

			c = io_uring_queue_init(...);
			switch (c) {
			case 0:
				have_io_uring = true;
				break;
			case -ENOSYS:
				have_io_uring = false;
				break;
			default:
				fprintf(stderr, "io_uring_queue_init failed\n");
				break;
			}

Especially since you add another case in the next patch?

I'll leave the style nits up to you though:
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D


--D

> -- 
> 2.43.0
> 
>
Jeff Moyer March 6, 2024, 3:56 p.m. UTC | #2
Zorro Lang <zlang@kernel.org> writes:

> As the manual of io_uring_queue_init says "io_uring_queue_init(3)
> returns 0 on success and -errno on failure". We should check if the
> return value is -ENOSYS, not the errno.
>
> Fixes: d15b1721f284 ("ltp/fsstress: don't fail on io_uring ENOSYS")
> Signed-off-by: Zorro Lang <zlang@kernel.org>
> ---
>  ltp/fsstress.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/ltp/fsstress.c b/ltp/fsstress.c
> index 63c75767..482395c4 100644
> --- a/ltp/fsstress.c
> +++ b/ltp/fsstress.c
> @@ -763,8 +763,8 @@ int main(int argc, char **argv)
>  #ifdef URING
>  			have_io_uring = true;
>  			/* If ENOSYS, just ignore uring, other errors are fatal. */
> -			if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
> -				if (errno == ENOSYS) {
> +			if ((c = io_uring_queue_init(URING_ENTRIES, &ring, 0)) != 0) {
> +				if (c == -ENOSYS) {
>  					have_io_uring = false;
>  				} else {
>  					fprintf(stderr, "io_uring_queue_init failed\n");

Reviewed-by: Jeff Moyer <jmoyer@redhat.com>
Zorro Lang March 6, 2024, 7:34 p.m. UTC | #3
On Wed, Mar 06, 2024 at 07:53:57AM -0800, Darrick J. Wong wrote:
> On Wed, Mar 06, 2024 at 05:19:33PM +0800, Zorro Lang wrote:
> > As the manual of io_uring_queue_init says "io_uring_queue_init(3)
> > returns 0 on success and -errno on failure". We should check if the
> > return value is -ENOSYS, not the errno.
> 
> /me checks liburing source code and sees that the library returns a
> negative error code without touching errno (the semi global error code
> variable) at all.  That's an unfortunate quirk of the manpage, but this
> code here is correct...

Yeah, that confuse me too, especially some io_uring functions set errno,
some return -errno ...

> 
> > Fixes: d15b1721f284 ("ltp/fsstress: don't fail on io_uring ENOSYS")
> > Signed-off-by: Zorro Lang <zlang@kernel.org>
> > ---
> >  ltp/fsstress.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/ltp/fsstress.c b/ltp/fsstress.c
> > index 63c75767..482395c4 100644
> > --- a/ltp/fsstress.c
> > +++ b/ltp/fsstress.c
> > @@ -763,8 +763,8 @@ int main(int argc, char **argv)
> >  #ifdef URING
> >  			have_io_uring = true;
> >  			/* If ENOSYS, just ignore uring, other errors are fatal. */
> > -			if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
> > -				if (errno == ENOSYS) {
> > +			if ((c = io_uring_queue_init(URING_ENTRIES, &ring, 0)) != 0) {
> > +				if (c == -ENOSYS) {
> >  					have_io_uring = false;
> >  				} else {
> >  					fprintf(stderr, "io_uring_queue_init failed\n");
> 
> But why not:
> 
> 			c = io_uring_queue_init(...);
> 			switch (c) {
> 			case 0:
> 				have_io_uring = true;
> 				break;
> 			case -ENOSYS:
> 				have_io_uring = false;
> 				break;
> 			default:
> 				fprintf(stderr, "io_uring_queue_init failed\n");
> 				break;
> 			}
> 
> Especially since you add another case in the next patch?

Sure, that looks more clearly, I'll change this part. Thanks!

> 
> I'll leave the style nits up to you though:
> Reviewed-by: Darrick J. Wong <djwong@kernel.org>
> 
> --D
> 
> 
> --D
> 
> > -- 
> > 2.43.0
> > 
> > 
>
diff mbox series

Patch

diff --git a/ltp/fsstress.c b/ltp/fsstress.c
index 63c75767..482395c4 100644
--- a/ltp/fsstress.c
+++ b/ltp/fsstress.c
@@ -763,8 +763,8 @@  int main(int argc, char **argv)
 #ifdef URING
 			have_io_uring = true;
 			/* If ENOSYS, just ignore uring, other errors are fatal. */
-			if (io_uring_queue_init(URING_ENTRIES, &ring, 0)) {
-				if (errno == ENOSYS) {
+			if ((c = io_uring_queue_init(URING_ENTRIES, &ring, 0)) != 0) {
+				if (c == -ENOSYS) {
 					have_io_uring = false;
 				} else {
 					fprintf(stderr, "io_uring_queue_init failed\n");