From: Caleb Sander Mateos <csander@purestorage.com>
To: Ming Lei <ming.lei@redhat.com>
Cc: Jens Axboe <axboe@kernel.dk>,
io-uring@vger.kernel.org,
Pavel Begunkov <asml.silence@gmail.com>,
linux-block@vger.kernel.org,
Uday Shankar <ushankar@purestorage.com>,
Keith Busch <kbusch@kernel.org>
Subject: Re: [RFC PATCH 4/7] ublk: convert to refcount_t
Date: Mon, 28 Apr 2025 10:13:35 -0700 [thread overview]
Message-ID: <CADUfDZrr19VZTm+rfN3Ks9Rrvek2CEBBt0V=CLO2uHayWffcow@mail.gmail.com> (raw)
In-Reply-To: <20250428094420.1584420-5-ming.lei@redhat.com>
On Mon, Apr 28, 2025 at 2:45 AM Ming Lei <ming.lei@redhat.com> wrote:
>
> Convert to refcount_t and prepare for supporting to register bvec buffer
> automatically, which needs to initialize reference counter as 2, and
> kref doesn't provide this interface, so convert to refcount_t.
>
> Suggested-by: Caleb Sander Mateos <csander@purestorage.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> drivers/block/ublk_drv.c | 19 +++++--------------
> 1 file changed, 5 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> index ac56482b55f5..9cd331d12fa6 100644
> --- a/drivers/block/ublk_drv.c
> +++ b/drivers/block/ublk_drv.c
> @@ -79,7 +79,7 @@
> UBLK_PARAM_TYPE_DMA_ALIGN | UBLK_PARAM_TYPE_SEGMENT)
>
> struct ublk_rq_data {
> - struct kref ref;
> + refcount_t ref;
> };
>
> struct ublk_uring_cmd_pdu {
> @@ -484,7 +484,6 @@ static blk_status_t ublk_setup_iod_zoned(struct ublk_queue *ubq,
> #endif
>
> static inline void __ublk_complete_rq(struct request *req);
> -static void ublk_complete_rq(struct kref *ref);
>
> static dev_t ublk_chr_devt;
> static const struct class ublk_chr_class = {
> @@ -644,7 +643,7 @@ static inline void ublk_init_req_ref(const struct ublk_queue *ubq,
> if (ublk_need_req_ref(ubq)) {
> struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
>
> - kref_init(&data->ref);
> + refcount_set(&data->ref, 1);
> }
> }
>
> @@ -654,7 +653,7 @@ static inline bool ublk_get_req_ref(const struct ublk_queue *ubq,
> if (ublk_need_req_ref(ubq)) {
> struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
>
> - return kref_get_unless_zero(&data->ref);
> + return refcount_inc_not_zero(&data->ref);
> }
>
> return true;
> @@ -666,7 +665,8 @@ static inline void ublk_put_req_ref(const struct ublk_queue *ubq,
> if (ublk_need_req_ref(ubq)) {
> struct ublk_rq_data *data = blk_mq_rq_to_pdu(req);
>
> - kref_put(&data->ref, ublk_complete_rq);
> + if(refcount_dec_and_test(&data->ref))
nit: missing space after if
Other than that,
Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
> + __ublk_complete_rq(req);
> } else {
> __ublk_complete_rq(req);
> }
> @@ -1124,15 +1124,6 @@ static inline void __ublk_complete_rq(struct request *req)
> blk_mq_end_request(req, res);
> }
>
> -static void ublk_complete_rq(struct kref *ref)
> -{
> - struct ublk_rq_data *data = container_of(ref, struct ublk_rq_data,
> - ref);
> - struct request *req = blk_mq_rq_from_pdu(data);
> -
> - __ublk_complete_rq(req);
> -}
> -
> static void ublk_complete_io_cmd(struct ublk_io *io, struct request *req,
> int res, unsigned issue_flags)
> {
> --
> 2.47.0
>
next prev parent reply other threads:[~2025-04-28 17:13 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-28 9:44 [RFC PATCH 0/7] ublk: support to register bvec buffer automatically Ming Lei
2025-04-28 9:44 ` [RFC PATCH 1/7] io_uring: add 'struct io_buf_data' for register/unregister bvec buffer Ming Lei
2025-04-29 0:35 ` Caleb Sander Mateos
2025-04-28 9:44 ` [RFC PATCH 2/7] io_uring: add helper __io_buffer_[un]register_bvec Ming Lei
2025-04-29 0:36 ` Caleb Sander Mateos
2025-04-28 9:44 ` [RFC PATCH 3/7] io_uring: support to register bvec buffer to specified io_uring Ming Lei
2025-04-28 10:28 ` Pavel Begunkov
2025-04-29 0:46 ` Caleb Sander Mateos
2025-04-29 0:47 ` Ming Lei
2025-04-30 8:25 ` Pavel Begunkov
2025-04-30 14:44 ` Ming Lei
2025-04-29 0:43 ` Caleb Sander Mateos
2025-04-30 15:34 ` Ming Lei
2025-05-02 1:31 ` Caleb Sander Mateos
2025-05-02 15:59 ` Ming Lei
2025-05-02 21:21 ` Caleb Sander Mateos
2025-05-03 1:00 ` Ming Lei
2025-05-03 18:55 ` Caleb Sander Mateos
2025-05-06 2:45 ` Ming Lei
2025-04-28 9:44 ` [RFC PATCH 4/7] ublk: convert to refcount_t Ming Lei
2025-04-28 17:13 ` Caleb Sander Mateos [this message]
2025-04-28 9:44 ` [RFC PATCH 5/7] ublk: prepare for supporting to register request buffer automatically Ming Lei
2025-04-29 0:50 ` Caleb Sander Mateos
2025-04-28 9:44 ` [RFC PATCH 6/7] ublk: register buffer to specified io_uring & buf index via UBLK_F_AUTO_BUF_REG Ming Lei
2025-04-29 0:52 ` Caleb Sander Mateos
2025-04-30 15:45 ` Ming Lei
2025-04-30 16:30 ` Caleb Sander Mateos
2025-05-02 14:09 ` Ming Lei
2025-04-28 9:44 ` [RFC PATCH 7/7] selftests: ublk: support UBLK_F_AUTO_BUF_REG Ming Lei
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 \
--in-reply-to='CADUfDZrr19VZTm+rfN3Ks9Rrvek2CEBBt0V=CLO2uHayWffcow@mail.gmail.com' \
--to=csander@purestorage.com \
--cc=asml.silence@gmail.com \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=ushankar@purestorage.com \
/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