From: Ming Lei <ming.lei@redhat.com>
To: Caleb Sander Mateos <csander@purestorage.com>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org,
Uday Shankar <ushankar@purestorage.com>
Subject: Re: [PATCH V3 06/27] ublk: add helper of __ublk_fetch()
Date: Sun, 16 Nov 2025 20:02:08 +0800 [thread overview]
Message-ID: <aRm9QLOI5LT9w-HB@fedora> (raw)
In-Reply-To: <CADUfDZoSiEjY0w7V1j09u1B=quJsizYKjOBQAGW61PcFtog7GA@mail.gmail.com>
On Fri, Nov 14, 2025 at 09:21:53PM -0800, Caleb Sander Mateos wrote:
> On Wed, Nov 12, 2025 at 1:39 AM Ming Lei <ming.lei@redhat.com> wrote:
> >
> > Add helper __ublk_fetch() for refactoring ublk_fetch().
> >
> > Meantime move ublk_config_io_buf() out of __ublk_fetch() to make
> > the code structure cleaner.
> >
> > Signed-off-by: Ming Lei <ming.lei@redhat.com>
> > ---
> > drivers/block/ublk_drv.c | 46 +++++++++++++++++++++-------------------
> > 1 file changed, 24 insertions(+), 22 deletions(-)
> >
> > diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
> > index 5e83c1b2a69e..dd9c35758a46 100644
> > --- a/drivers/block/ublk_drv.c
> > +++ b/drivers/block/ublk_drv.c
> > @@ -2234,39 +2234,41 @@ static int ublk_check_fetch_buf(const struct ublk_device *ub, __u64 buf_addr)
> > return 0;
> > }
> >
> > -static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
> > - struct ublk_io *io, __u64 buf_addr)
> > +static int __ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
> > + struct ublk_io *io)
> > {
> > - int ret = 0;
> > -
> > - /*
> > - * When handling FETCH command for setting up ublk uring queue,
> > - * ub->mutex is the innermost lock, and we won't block for handling
> > - * FETCH, so it is fine even for IO_URING_F_NONBLOCK.
> > - */
> > - mutex_lock(&ub->mutex);
> > /* UBLK_IO_FETCH_REQ is only allowed before dev is setup */
> > - if (ublk_dev_ready(ub)) {
> > - ret = -EBUSY;
> > - goto out;
> > - }
> > + if (ublk_dev_ready(ub))
> > + return -EBUSY;
> >
> > /* allow each command to be FETCHed at most once */
> > - if (io->flags & UBLK_IO_FLAG_ACTIVE) {
> > - ret = -EINVAL;
> > - goto out;
> > - }
> > + if (io->flags & UBLK_IO_FLAG_ACTIVE)
> > + return -EINVAL;
> >
> > WARN_ON_ONCE(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV);
> >
> > ublk_fill_io_cmd(io, cmd);
> > - ret = ublk_config_io_buf(ub, io, cmd, buf_addr, NULL);
> > - if (ret)
> > - goto out;
> >
> > WRITE_ONCE(io->task, get_task_struct(current));
> > ublk_mark_io_ready(ub);
> > -out:
> > +
> > + return 0;
> > +}
> > +
> > +static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
> > + struct ublk_io *io, __u64 buf_addr)
> > +{
> > + int ret;
> > +
> > + /*
> > + * When handling FETCH command for setting up ublk uring queue,
> > + * ub->mutex is the innermost lock, and we won't block for handling
> > + * FETCH, so it is fine even for IO_URING_F_NONBLOCK.
> > + */
> > + mutex_lock(&ub->mutex);
> > + ret = __ublk_fetch(cmd, ub, io);
> > + if (!ret)
> > + ret = ublk_config_io_buf(ub, io, cmd, buf_addr, NULL);
>
> This changes ublk_config_io_buf() to be called *after*
> ublk_mark_io_ready(). Is that safe? It seems like io->addr could be
> read in ublk_setup_iod() as soon as the ublk device is marked as ready
> for I/O.
disk can't be added unless acquiring ub->mutex, so it is safe.
Thanks,
Ming
next prev parent reply other threads:[~2025-11-16 12:02 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 9:37 [PATCH V3 00/27] ublk: add UBLK_F_BATCH_IO Ming Lei
2025-11-12 9:37 ` [PATCH V3 01/27] kfifo: add kfifo_alloc_node() helper for NUMA awareness Ming Lei
2025-11-12 19:29 ` Andrew Morton
2025-11-13 1:21 ` Ming Lei
2025-11-13 22:06 ` Andrew Morton
2025-11-15 4:14 ` Caleb Sander Mateos
2025-11-16 11:59 ` Ming Lei
2025-11-12 9:37 ` [PATCH V3 02/27] ublk: add parameter `struct io_uring_cmd *` to ublk_prep_auto_buf_reg() Ming Lei
2025-11-12 9:37 ` [PATCH V3 03/27] ublk: add `union ublk_io_buf` with improved naming Ming Lei
2025-11-12 9:37 ` [PATCH V3 04/27] ublk: refactor auto buffer register in ublk_dispatch_req() Ming Lei
2025-11-15 5:10 ` Caleb Sander Mateos
2025-11-12 9:37 ` [PATCH V3 05/27] ublk: pass const pointer to ublk_queue_is_zoned() Ming Lei
2025-11-15 5:11 ` Caleb Sander Mateos
2025-11-12 9:37 ` [PATCH V3 06/27] ublk: add helper of __ublk_fetch() Ming Lei
2025-11-15 5:21 ` Caleb Sander Mateos
2025-11-16 12:02 ` Ming Lei [this message]
2025-11-17 18:29 ` Caleb Sander Mateos
2025-11-12 9:37 ` [PATCH V3 07/27] ublk: define ublk_ch_batch_io_fops for the coming feature F_BATCH_IO Ming Lei
2025-11-12 9:37 ` [PATCH V3 08/27] ublk: prepare for not tracking task context for command batch Ming Lei
2025-11-15 5:25 ` Caleb Sander Mateos
2025-11-16 12:02 ` Ming Lei
2025-11-12 9:37 ` [PATCH V3 09/27] ublk: add new batch command UBLK_U_IO_PREP_IO_CMDS & UBLK_U_IO_COMMIT_IO_CMDS Ming Lei
2025-11-17 21:08 ` Caleb Sander Mateos
2025-11-18 2:11 ` Ming Lei
2025-11-18 2:38 ` Caleb Sander Mateos
2025-11-19 2:37 ` Caleb Sander Mateos
2025-11-19 2:39 ` Caleb Sander Mateos
2025-11-19 9:49 ` Ming Lei
2025-11-12 9:37 ` [PATCH V3 10/27] ublk: handle UBLK_U_IO_PREP_IO_CMDS Ming Lei
2025-11-19 2:49 ` Caleb Sander Mateos
2025-11-19 9:56 ` Ming Lei
2025-11-19 16:09 ` Caleb Sander Mateos
2025-11-12 9:37 ` [PATCH V3 11/27] ublk: handle UBLK_U_IO_COMMIT_IO_CMDS Ming Lei
2025-11-12 9:37 ` [PATCH V3 12/27] ublk: add io events fifo structure Ming Lei
2025-11-12 9:37 ` [PATCH V3 13/27] ublk: add batch I/O dispatch infrastructure Ming Lei
2025-11-12 9:37 ` [PATCH V3 14/27] ublk: add UBLK_U_IO_FETCH_IO_CMDS for batch I/O processing Ming Lei
2025-11-12 9:37 ` [PATCH V3 15/27] ublk: abort requests filled in event kfifo Ming Lei
2025-11-12 9:37 ` [PATCH V3 16/27] ublk: add new feature UBLK_F_BATCH_IO Ming Lei
2025-11-12 9:37 ` [PATCH V3 17/27] ublk: document " Ming Lei
2025-11-12 9:37 ` [PATCH V3 18/27] ublk: implement batch request completion via blk_mq_end_request_batch() Ming Lei
2025-11-12 9:37 ` [PATCH V3 19/27] selftests: ublk: fix user_data truncation for tgt_data >= 256 Ming Lei
2025-11-12 9:37 ` [PATCH V3 20/27] selftests: ublk: replace assert() with ublk_assert() Ming Lei
2025-11-12 9:37 ` [PATCH V3 21/27] selftests: ublk: add ublk_io_buf_idx() for returning io buffer index Ming Lei
2025-11-12 9:38 ` [PATCH V3 22/27] selftests: ublk: add batch buffer management infrastructure Ming Lei
2025-11-12 9:38 ` [PATCH V3 23/27] selftests: ublk: handle UBLK_U_IO_PREP_IO_CMDS Ming Lei
2025-11-12 9:38 ` [PATCH V3 24/27] selftests: ublk: handle UBLK_U_IO_COMMIT_IO_CMDS Ming Lei
2025-11-12 9:38 ` [PATCH V3 25/27] selftests: ublk: handle UBLK_U_IO_FETCH_IO_CMDS Ming Lei
2025-11-12 9:38 ` [PATCH V3 26/27] selftests: ublk: add --batch/-b for enabling F_BATCH_IO Ming Lei
2025-11-12 9:38 ` [PATCH V3 27/27] selftests: ublk: support arbitrary threads/queues combination 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=aRm9QLOI5LT9w-HB@fedora \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=linux-block@vger.kernel.org \
--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