From: Jens Axboe <[email protected]>
To: Bob Liu <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] io_uring: introduce add/post event and put function
Date: Thu, 21 Nov 2019 07:05:32 -0700 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
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 <[email protected]>
> ---
> 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
prev parent reply other threads:[~2019-11-21 15:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-21 9:00 [PATCH] io_uring: introduce add/post event and put function Bob Liu
2019-11-21 14:05 ` Jens Axboe [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox