Re: [PATCH] io_uring: introduce add/post event and put function

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

 



On 11/21/19 2:00 AM, Bob Liu wrote:
> * Only complie-tested right now. *
> There are so many duplicated code doing add/post event and then put req.
> Put them to common funcs io_cqring_event_posted_and_put() and
> io_cqring_add_event_and_put().
> 
> Signed-off-by: Bob Liu <bob.liu@xxxxxxxxxx>
> ---
>   fs/io_uring.c | 145 ++++++++++++++++++++++++++++++----------------------------
>   1 file changed, 74 insertions(+), 71 deletions(-)
> 
> diff --git a/fs/io_uring.c b/fs/io_uring.c
> index 299a218..816eef3 100644
> --- a/fs/io_uring.c
> +++ b/fs/io_uring.c
> @@ -1039,6 +1039,56 @@ static void io_double_put_req(struct io_kiocb *req)
>   		io_free_req(req);
>   }
>   
> +/*
> + * Add event to io_cqring and put req.
> + */
> +static void io_cqring_add_event_and_put(struct io_kiocb *req, long ret,
> +		int should_fail_link, bool double_put, struct io_kiocb **nxt)
> +{
> +	if (should_fail_link == 1) {
> +		if (ret < 0 && (req->flags & REQ_F_LINK))
> +			req->flags |= REQ_F_FAIL_LINK;
> +	} else if (should_fail_link == 2) {
> +		/* Don't care about ret < 0 when should_fail_link == 2 */
> +		if (req->flags & REQ_F_LINK)
> +			req->flags |= REQ_F_FAIL_LINK;
> +	}
> +
> +	io_cqring_add_event(req, ret);
> +
> +	if (double_put)
> +		io_double_put_req(req);
> +	else {
> +		if (nxt)
> +			io_put_req_find_next(req, nxt);
> +		else
> +			io_put_req(req);
> +	}
> +}

I'd really like to clean up this part, as it's both duplicated a lot and
also fragile in terms of places forgetting to do part of the necessary
dance. However, this helper is a bit of a monster (and the other one as
well), it's hard to know what this does:

	io_cqring_add_event_and_put(req, ret, 1, false, nxt);

without looking up what '1' and 'false' might be. Having multiple int
values for should_fail_link is also a bit, well, tricky. Maybe it needs
to be two helpers?

And if it does need something like 'should_fail_link', I think that'd be
done cleaner by using some sort of mask. IO_PUT_ERROR_ON_NEGATIVE,
IO_PUT_ERROR_ALWAYS, or something like that. Then you can tell in the
caller what it's going to do, rather than having to look up if what '1'
or '2' as the argument means.

-- 
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