Skip to content

Commit 5621c41

Browse files
Ming Leikawasaki
authored andcommitted
ublk: remove ublk_commit_and_fetch()
Remove ublk_commit_and_fetch() and open code request completion. Now request reference is stored in 'ublk_io', which becomes one global variable, the motivation is to centralize access 'struct ublk_io' reference, then we can introduce lock to protect `ublk_io` in future for supporting io batch. Signed-off-by: Ming Lei <[email protected]>
1 parent c3b6baa commit 5621c41

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,12 @@ static inline void ublk_put_req_ref(struct ublk_io *io, struct request *req)
713713
__ublk_complete_rq(req);
714714
}
715715

716-
static inline void ublk_sub_req_ref(struct ublk_io *io, struct request *req)
716+
static inline bool ublk_sub_req_ref(struct ublk_io *io, struct request *req)
717717
{
718718
unsigned sub_refs = UBLK_REFCOUNT_INIT - io->task_registered_buffers;
719719

720720
io->task_registered_buffers = 0;
721-
if (refcount_sub_and_test(sub_refs, &io->ref))
722-
__ublk_complete_rq(req);
721+
return refcount_sub_and_test(sub_refs, &io->ref);
723722
}
724723

725724
static inline bool ublk_need_get_data(const struct ublk_queue *ubq)
@@ -2243,21 +2242,13 @@ static int ublk_check_commit_and_fetch(const struct ublk_queue *ubq,
22432242
return 0;
22442243
}
22452244

2246-
static void ublk_commit_and_fetch(const struct ublk_queue *ubq,
2247-
struct ublk_io *io, struct io_uring_cmd *cmd,
2248-
struct request *req, unsigned int issue_flags,
2249-
__u64 zone_append_lba, u16 buf_idx)
2245+
static bool ublk_need_complete_req(const struct ublk_queue *ubq,
2246+
struct ublk_io *io,
2247+
struct request *req)
22502248
{
2251-
if (buf_idx != UBLK_INVALID_BUF_IDX)
2252-
io_buffer_unregister_bvec(cmd, buf_idx, issue_flags);
2253-
2254-
if (req_op(req) == REQ_OP_ZONE_APPEND)
2255-
req->__sector = zone_append_lba;
2256-
22572249
if (ublk_need_req_ref(ubq))
2258-
ublk_sub_req_ref(io, req);
2259-
else
2260-
__ublk_complete_rq(req);
2250+
return ublk_sub_req_ref(io, req);
2251+
return true;
22612252
}
22622253

22632254
static bool ublk_get_data(const struct ublk_queue *ubq, struct ublk_io *io,
@@ -2290,6 +2281,7 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
22902281
unsigned tag = ub_cmd->tag;
22912282
struct request *req;
22922283
int ret;
2284+
bool compl;
22932285

22942286
pr_devel("%s: received: cmd op %d queue %d tag %d result %d\n",
22952287
__func__, cmd->cmd_op, ub_cmd->q_id, tag,
@@ -2366,8 +2358,16 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
23662358
goto out;
23672359
req = ublk_fill_io_cmd(io, cmd, ub_cmd->result);
23682360
ret = ublk_config_io_buf(ubq, io, cmd, ub_cmd->addr, &buf_idx);
2369-
ublk_commit_and_fetch(ubq, io, cmd, req, issue_flags,
2370-
ub_cmd->zone_append_lba, buf_idx);
2361+
compl = ublk_need_complete_req(ubq, io, req);
2362+
2363+
/* can't touch 'ublk_io' any more */
2364+
if (buf_idx != UBLK_INVALID_BUF_IDX)
2365+
io_buffer_unregister_bvec(cmd, buf_idx, issue_flags);
2366+
if (req_op(req) == REQ_OP_ZONE_APPEND)
2367+
req->__sector = ub_cmd->zone_append_lba;
2368+
if (compl)
2369+
__ublk_complete_rq(req);
2370+
23712371
if (ret)
23722372
goto out;
23732373
break;

0 commit comments

Comments
 (0)