Skip to content

Commit 0d50b24

Browse files
Ming Leikawasaki
authored andcommitted
ublk: avoid to pass struct ublksrv_io_cmd * to ublk_commit_and_fetch()
Refactor ublk_commit_and_fetch() in the following way for removing parameter of `struct ublksrv_io_cmd *`: - return `struct request *` from ublk_fill_io_cmd(), so that we can use request reference reliably in this way cause both request and io_uring_cmd reference share same storage - move ublk_fill_io_cmd() before calling into ublk_commit_and_fetch(), so that ublk_fill_io_cmd() could be run with per-io lock held for supporting command batch. - pass ->zone_append_lba to ublk_commit_and_fetch() directly The main motivation is to reproduce ublk_commit_and_fetch() for fetching io command batch with multishot uring_cmd. Reviewed-by: Caleb Sander Mateos <[email protected]> Signed-off-by: Ming Lei <[email protected]>
1 parent 6d4bb66 commit 0d50b24

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,17 +2003,22 @@ static inline int ublk_check_cmd_op(u32 cmd_op)
20032003
return 0;
20042004
}
20052005

2006-
static inline void ublk_fill_io_cmd(struct ublk_io *io,
2007-
struct io_uring_cmd *cmd, unsigned long buf_addr,
2008-
int result)
2006+
/* Once we return, `io->req` can't be used any more */
2007+
static inline struct request *
2008+
ublk_fill_io_cmd(struct ublk_io *io, struct io_uring_cmd *cmd,
2009+
unsigned long buf_addr, int result)
20092010
{
2011+
struct request *req = io->req;
2012+
20102013
io->cmd = cmd;
20112014
io->flags |= UBLK_IO_FLAG_ACTIVE;
20122015
io->addr = buf_addr;
20132016
io->res = result;
20142017

20152018
/* now this cmd slot is owned by ublk driver */
20162019
io->flags &= ~UBLK_IO_FLAG_OWNED_BY_SRV;
2020+
2021+
return req;
20172022
}
20182023

20192024
static inline void ublk_prep_cancel(struct io_uring_cmd *cmd,
@@ -2179,10 +2184,8 @@ static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_queue *ubq,
21792184
return ret;
21802185
}
21812186

2182-
static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
2183-
struct ublk_io *io, struct io_uring_cmd *cmd,
2184-
const struct ublksrv_io_cmd *ub_cmd,
2185-
unsigned int issue_flags)
2187+
static int ublk_check_commit_and_fetch(const struct ublk_queue *ubq,
2188+
struct ublk_io *io, __u64 buf_addr)
21862189
{
21872190
struct request *req = io->req;
21882191

@@ -2191,17 +2194,25 @@ static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
21912194
* COMMIT_AND_FETCH_REQ has to provide IO buffer if
21922195
* NEED GET DATA is not enabled or it is Read IO.
21932196
*/
2194-
if (!ub_cmd->addr && (!ublk_need_get_data(ubq) ||
2197+
if (!buf_addr && (!ublk_need_get_data(ubq) ||
21952198
req_op(req) == REQ_OP_READ))
21962199
return -EINVAL;
2197-
} else if (req_op(req) != REQ_OP_ZONE_APPEND && ub_cmd->addr) {
2200+
} else if (req_op(req) != REQ_OP_ZONE_APPEND && buf_addr) {
21982201
/*
21992202
* User copy requires addr to be unset when command is
22002203
* not zone append
22012204
*/
22022205
return -EINVAL;
22032206
}
22042207

2208+
return 0;
2209+
}
2210+
2211+
static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
2212+
struct ublk_io *io, struct io_uring_cmd *cmd,
2213+
struct request *req, unsigned int issue_flags,
2214+
__u64 zone_append_lba)
2215+
{
22052216
if (ublk_support_auto_buf_reg(ubq)) {
22062217
int ret;
22072218

@@ -2227,10 +2238,8 @@ static int ublk_commit_and_fetch(const struct ublk_queue *ubq,
22272238
return ret;
22282239
}
22292240

2230-
ublk_fill_io_cmd(io, cmd, ub_cmd->addr, ub_cmd->result);
2231-
22322241
if (req_op(req) == REQ_OP_ZONE_APPEND)
2233-
req->__sector = ub_cmd->zone_append_lba;
2242+
req->__sector = zone_append_lba;
22342243

22352244
if (ublk_need_req_ref(ubq))
22362245
ublk_sub_req_ref(io, req);
@@ -2336,7 +2345,12 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
23362345
return ublk_daemon_register_io_buf(cmd, ubq, io, ub_cmd->addr,
23372346
issue_flags);
23382347
case UBLK_IO_COMMIT_AND_FETCH_REQ:
2339-
ret = ublk_commit_and_fetch(ubq, io, cmd, ub_cmd, issue_flags);
2348+
ret = ublk_check_commit_and_fetch(ubq, io, ub_cmd->addr);
2349+
if (ret)
2350+
goto out;
2351+
req = ublk_fill_io_cmd(io, cmd, ub_cmd->addr, ub_cmd->result);
2352+
ret = ublk_commit_and_fetch(ubq, io, cmd, req, issue_flags,
2353+
ub_cmd->zone_append_lba);
23402354
if (ret)
23412355
goto out;
23422356
break;
@@ -2346,8 +2360,7 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
23462360
* uring_cmd active first and prepare for handling new requeued
23472361
* request
23482362
*/
2349-
req = io->req;
2350-
ublk_fill_io_cmd(io, cmd, ub_cmd->addr, 0);
2363+
req = ublk_fill_io_cmd(io, cmd, ub_cmd->addr, 0);
23512364
if (likely(ublk_get_data(ubq, io, req))) {
23522365
__ublk_prep_compl_io_cmd(io, req);
23532366
return UBLK_IO_RES_OK;

0 commit comments

Comments
 (0)