From: Uday Shankar <ushankar@purestorage.com>
To: Ming Lei <ming.lei@redhat.com>, Jens Axboe <axboe@kernel.dk>
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
Uday Shankar <ushankar@purestorage.com>,
Caleb Sander Mateos <csander@purestorage.com>
Subject: [PATCH 3/4] ublk: factor out ublk_get_data
Date: Mon, 21 Apr 2025 17:46:42 -0600 [thread overview]
Message-ID: <20250421-ublk_constify-v1-3-3371f9e9f73c@purestorage.com> (raw)
In-Reply-To: <20250421-ublk_constify-v1-0-3371f9e9f73c@purestorage.com>
Move all the logic for the UBLK_IO_NEED_GET_DATA opcode into its own
function. This also allows us to mark ublk_queue pointers as const for
that operation, which can help prevent data races since we may allow
concurrent operation on one ublk_queue in the future.
Suggested-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Uday Shankar <ushankar@purestorage.com>
Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
---
drivers/block/ublk_drv.c | 32 +++++++++++++++++++-------------
1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/drivers/block/ublk_drv.c b/drivers/block/ublk_drv.c
index a617ffde412936d3c37a3ded08a79e3557f4f56f..f5d4593d5941931efa7bc7d2106830cd2981f4bd 100644
--- a/drivers/block/ublk_drv.c
+++ b/drivers/block/ublk_drv.c
@@ -1241,7 +1241,7 @@ static void ublk_cmd_tw_cb(struct io_uring_cmd *cmd,
ublk_dispatch_req(ubq, pdu->req, issue_flags);
}
-static void ublk_queue_cmd(struct ublk_queue *ubq, struct request *rq)
+static void ublk_queue_cmd(const struct ublk_queue *ubq, struct request *rq)
{
struct io_uring_cmd *cmd = ubq->ios[rq->tag].cmd;
struct ublk_uring_cmd_pdu *pdu = ublk_get_uring_cmd_pdu(cmd);
@@ -1864,15 +1864,6 @@ static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq)
}
}
-static void ublk_handle_need_get_data(struct ublk_device *ub, int q_id,
- int tag)
-{
- struct ublk_queue *ubq = ublk_get_queue(ub, q_id);
- struct request *req = blk_mq_tag_to_rq(ub->tag_set.tags[q_id], tag);
-
- ublk_queue_cmd(ubq, req);
-}
-
static inline int ublk_check_cmd_op(u32 cmd_op)
{
u32 ioc_type = _IOC_TYPE(cmd_op);
@@ -2032,6 +2023,22 @@ static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
return 0;
}
+static int ublk_get_data(const struct ublk_queue *ubq, struct ublk_io *io,
+ struct io_uring_cmd *cmd,
+ const struct ublksrv_io_cmd *ub_cmd)
+{
+ struct blk_mq_tags *tags = ubq->dev->tag_set.tags[ub_cmd->q_id];
+ struct request *req = blk_mq_tag_to_rq(tags, ub_cmd->tag);
+
+ if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
+ return -EINVAL;
+
+ ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
+ ublk_queue_cmd(ubq, req);
+
+ return 0;
+}
+
static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
unsigned int issue_flags,
const struct ublksrv_io_cmd *ub_cmd)
@@ -2097,10 +2104,9 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
goto out;
break;
case UBLK_IO_NEED_GET_DATA:
- if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
+ ret = ublk_get_data(ubq, io, cmd, ub_cmd);
+ if (ret)
goto out;
- ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
- ublk_handle_need_get_data(ub, ub_cmd->q_id, ub_cmd->tag);
break;
default:
goto out;
--
2.34.1
next prev parent reply other threads:[~2025-04-21 23:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-21 23:46 [PATCH 0/4] ublk: refactor __ublk_ch_uring_cmd Uday Shankar
2025-04-21 23:46 ` [PATCH 1/4] ublk: factor out ublk_commit_and_fetch Uday Shankar
2025-04-22 2:16 ` Ming Lei
2025-04-21 23:46 ` [PATCH 2/4] ublk: mark ublk_queue as const for ublk_register_io_buf Uday Shankar
2025-04-21 23:46 ` Uday Shankar [this message]
2025-04-22 2:17 ` [PATCH 3/4] ublk: factor out ublk_get_data Ming Lei
2025-04-21 23:46 ` [PATCH 4/4] ublk: factor out error handling in __ublk_ch_uring_cmd Uday Shankar
2025-04-22 2:17 ` Ming Lei
2025-04-24 21:50 ` [PATCH 0/4] ublk: refactor __ublk_ch_uring_cmd Uday Shankar
2025-04-25 2:40 ` Jens Axboe
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=20250421-ublk_constify-v1-3-3371f9e9f73c@purestorage.com \
--to=ushankar@purestorage.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.lei@redhat.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
all inboxes | Powered by JetHome®