Skip to content

Commit 2f1e07d

Browse files
dong-liuliuaxboe
authored andcommitted
block: ublk: check IO buffer based on flag need_get_data
Currently, uring_cmd with UBLK_IO_FETCH_REQ or UBLK_IO_COMMIT_AND_FETCH_REQ is always checked whether userspace server has provided IO buffer even flag UBLK_F_NEED_GET_DATA is configured. This is a excessive check. If UBLK_F_NEED_GET_DATA is configured, FETCH_RQ doesn't need to provide IO buffer; COMMIT_AND_FETCH_REQ also doesn't need to do that if the IO type is not READ. Check ub_cmd->addr together with ublk_need_get_data() and IO type in ublk_ch_uring_cmd(). With this fix, userspace server doesn't need to preserve buffers for every ublk_io when flag UBLK_F_NEED_GET_DATA is configured, in order to save memory. Signed-off-by: Liu Xiaodong <[email protected]> Fixes: c86019f ("ublk_drv: add support for UBLK_IO_NEED_GET_DATA") Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 460e9be commit 2f1e07d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/block/ublk_drv.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
12651265
u32 cmd_op = cmd->cmd_op;
12661266
unsigned tag = ub_cmd->tag;
12671267
int ret = -EINVAL;
1268+
struct request *req;
12681269

12691270
pr_devel("%s: received: cmd op %d queue %d tag %d result %d\n",
12701271
__func__, cmd->cmd_op, ub_cmd->q_id, tag,
@@ -1315,8 +1316,8 @@ static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
13151316
*/
13161317
if (io->flags & UBLK_IO_FLAG_OWNED_BY_SRV)
13171318
goto out;
1318-
/* FETCH_RQ has to provide IO buffer */
1319-
if (!ub_cmd->addr)
1319+
/* FETCH_RQ has to provide IO buffer if NEED GET DATA is not enabled */
1320+
if (!ub_cmd->addr && !ublk_need_get_data(ubq))
13201321
goto out;
13211322
io->cmd = cmd;
13221323
io->flags |= UBLK_IO_FLAG_ACTIVE;
@@ -1325,8 +1326,12 @@ static int ublk_ch_uring_cmd(struct io_uring_cmd *cmd, unsigned int issue_flags)
13251326
ublk_mark_io_ready(ub, ubq);
13261327
break;
13271328
case UBLK_IO_COMMIT_AND_FETCH_REQ:
1328-
/* FETCH_RQ has to provide IO buffer */
1329-
if (!ub_cmd->addr)
1329+
req = blk_mq_tag_to_rq(ub->tag_set.tags[ub_cmd->q_id], tag);
1330+
/*
1331+
* COMMIT_AND_FETCH_REQ has to provide IO buffer if NEED GET DATA is
1332+
* not enabled or it is Read IO.
1333+
*/
1334+
if (!ub_cmd->addr && (!ublk_need_get_data(ubq) || req_op(req) == REQ_OP_READ))
13301335
goto out;
13311336
if (!(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV))
13321337
goto out;

0 commit comments

Comments
 (0)