Re: io_uring_peek_cqe and EAGAIN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 4/20/20 10:27 AM, William Dauchy wrote:
> Hello,
> 
> While doing some tests which are open/read/close files I saw that I
> was getting -EAGAIN return value sometimesi on io_uring_peek_cqe,
> and more often after dropping caches.
> In parrallel, when reading examples provided by liburing, we can see
> that getting this error is making the example fail (such as in
> io_uring-cp). So I was wondering whether it was stupid to change the
> example to something like:
> 
> diff --git a/examples/io_uring-cp.c b/examples/io_uring-cp.c
> index cc7a227..2d6d190 100644
> --- a/examples/io_uring-cp.c
> +++ b/examples/io_uring-cp.c
> @@ -170,11 +170,11 @@ static int copy_file(struct io_uring *ring, off_t insize)
>      ret = io_uring_wait_cqe(ring, &cqe);
>      got_comp = 1;
>     } else {
> -    ret = io_uring_peek_cqe(ring, &cqe);
> -    if (ret == -EAGAIN) {
> -     cqe = NULL;
> -     ret = 0;
> -    }
> +    do {
> +     ret = io_uring_peek_cqe(ring, &cqe)
> +     if (ret != -EAGAIN)
> +      break;
> +    } while (1);

I don't think the change is correct. That's not saying that the original
code is necessarily correct, though! Basically there are two cases there:

1) We haven't gotten a completion yet, we'll wait for it.
2) We already found at least one completion. We don't want
   to _wait_ for more, but we can peek and see if there are more.

Hence we don't want to turn case 2 into a loop, we should just
continue.

How is it currently failing for you?

-- 
Jens Axboe




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux