Skip to content

Commit 9810362

Browse files
calebsanderaxboe
authored andcommitted
ublk: don't call ublk_dispatch_req() for NEED_GET_DATA
ublk_dispatch_req() currently handles 3 different cases: incoming ublk requests that don't need to wait for a data buffer, incoming requests that do need to wait for a buffer, and resuming those requests once the buffer is provided. But the call site that provides a data buffer (UBLK_IO_NEED_GET_DATA) is separate from those for incoming requests. So simplify the function by splitting the UBLK_IO_NEED_GET_DATA case into its own function ublk_get_data(). This avoids several redundant checks in the UBLK_IO_NEED_GET_DATA case, and streamlines the incoming request cases. Don't call ublk_fill_io_cmd() for UBLK_IO_NEED_GET_DATA, as it's no longer necessary to set io->cmd or the UBLK_IO_FLAG_ACTIVE flag for ublk_dispatch_req(). Since UBLK_IO_NEED_GET_DATA no longer relies on ublk_dispatch_req() calling io_uring_cmd_done(), return the UBLK_IO_RES_OK status directly from the ->uring_cmd() handler. If ublk_start_io() fails, don't complete the UBLK_IO_NEED_GET_DATA command, matching the existing behavior. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250430225234.2676781-8-csander@purestorage.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 2fcb88b commit 9810362

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

drivers/block/ublk_drv.c

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,25 +1212,12 @@ static void ublk_dispatch_req(struct ublk_queue *ubq,
12121212
* so immediately pass UBLK_IO_RES_NEED_GET_DATA to ublksrv
12131213
* and notify it.
12141214
*/
1215-
if (!(io->flags & UBLK_IO_FLAG_NEED_GET_DATA)) {
1216-
io->flags |= UBLK_IO_FLAG_NEED_GET_DATA;
1217-
pr_devel("%s: need get data. qid %d tag %d io_flags %x\n",
1218-
__func__, ubq->q_id, req->tag, io->flags);
1219-
ublk_complete_io_cmd(io, UBLK_IO_RES_NEED_GET_DATA,
1220-
issue_flags);
1221-
return;
1222-
}
1223-
/*
1224-
* We have handled UBLK_IO_NEED_GET_DATA command,
1225-
* so clear UBLK_IO_FLAG_NEED_GET_DATA now and just
1226-
* do the copy work.
1227-
*/
1228-
io->flags &= ~UBLK_IO_FLAG_NEED_GET_DATA;
1229-
/* update iod->addr because ublksrv may have passed a new io buffer */
1230-
ublk_get_iod(ubq, req->tag)->addr = io->addr;
1231-
pr_devel("%s: update iod->addr: qid %d tag %d io_flags %x addr %llx\n",
1232-
__func__, ubq->q_id, req->tag, io->flags,
1233-
ublk_get_iod(ubq, req->tag)->addr);
1215+
io->flags |= UBLK_IO_FLAG_NEED_GET_DATA;
1216+
pr_devel("%s: need get data. qid %d tag %d io_flags %x\n",
1217+
__func__, ubq->q_id, req->tag, io->flags);
1218+
ublk_complete_io_cmd(io, UBLK_IO_RES_NEED_GET_DATA,
1219+
issue_flags);
1220+
return;
12341221
}
12351222

12361223
if (!ublk_start_io(ubq, req, io))
@@ -2045,6 +2032,24 @@ static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
20452032
return 0;
20462033
}
20472034

2035+
static bool ublk_get_data(const struct ublk_queue *ubq, struct ublk_io *io,
2036+
struct request *req)
2037+
{
2038+
/*
2039+
* We have handled UBLK_IO_NEED_GET_DATA command,
2040+
* so clear UBLK_IO_FLAG_NEED_GET_DATA now and just
2041+
* do the copy work.
2042+
*/
2043+
io->flags &= ~UBLK_IO_FLAG_NEED_GET_DATA;
2044+
/* update iod->addr because ublksrv may have passed a new io buffer */
2045+
ublk_get_iod(ubq, req->tag)->addr = io->addr;
2046+
pr_devel("%s: update iod->addr: qid %d tag %d io_flags %x addr %llx\n",
2047+
__func__, ubq->q_id, req->tag, io->flags,
2048+
ublk_get_iod(ubq, req->tag)->addr);
2049+
2050+
return ublk_start_io(ubq, req, io);
2051+
}
2052+
20482053
static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
20492054
unsigned int issue_flags,
20502055
const struct ublksrv_io_cmd *ub_cmd)
@@ -2110,10 +2115,12 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
21102115
case UBLK_IO_NEED_GET_DATA:
21112116
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
21122117
goto out;
2113-
ublk_fill_io_cmd(io, cmd, ub_cmd->addr);
2118+
io->addr = ub_cmd->addr;
21142119
req = blk_mq_tag_to_rq(ub->tag_set.tags[ub_cmd->q_id], tag);
2115-
ublk_dispatch_req(ubq, req, issue_flags);
2116-
return -EIOCBQUEUED;
2120+
if (!ublk_get_data(ubq, io, req))
2121+
return -EIOCBQUEUED;
2122+
2123+
return UBLK_IO_RES_OK;
21172124
default:
21182125
goto out;
21192126
}

0 commit comments

Comments
 (0)