mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-28 09:22:08 +00:00
ublk: remove ublk_commit_and_fetch()
Remove ublk_commit_and_fetch() and open code request completion. Consolidate accesses to struct ublk_io in UBLK_IO_COMMIT_AND_FETCH_REQ. When the ublk_io daemon task restriction is relaxed in the future, ublk_io will need to be protected by a lock. Unregister the auto-registered buffer and complete the request last, as these don't need to happen under the lock. Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250713143415.2857561-10-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
3446583f81
commit
b749965edd
@ -714,13 +714,12 @@ static inline void ublk_put_req_ref(struct ublk_io *io, struct request *req)
|
|||||||
__ublk_complete_rq(req);
|
__ublk_complete_rq(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void ublk_sub_req_ref(struct ublk_io *io, struct request *req)
|
static inline bool ublk_sub_req_ref(struct ublk_io *io, struct request *req)
|
||||||
{
|
{
|
||||||
unsigned sub_refs = UBLK_REFCOUNT_INIT - io->task_registered_buffers;
|
unsigned sub_refs = UBLK_REFCOUNT_INIT - io->task_registered_buffers;
|
||||||
|
|
||||||
io->task_registered_buffers = 0;
|
io->task_registered_buffers = 0;
|
||||||
if (refcount_sub_and_test(sub_refs, &io->ref))
|
return refcount_sub_and_test(sub_refs, &io->ref);
|
||||||
__ublk_complete_rq(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool ublk_need_get_data(const struct ublk_queue *ubq)
|
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,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ublk_commit_and_fetch(const struct ublk_queue *ubq,
|
static bool ublk_need_complete_req(const struct ublk_queue *ubq,
|
||||||
struct ublk_io *io, struct io_uring_cmd *cmd,
|
struct ublk_io *io,
|
||||||
struct request *req, unsigned int issue_flags,
|
struct request *req)
|
||||||
__u64 zone_append_lba, u16 buf_idx)
|
|
||||||
{
|
{
|
||||||
if (buf_idx != UBLK_INVALID_BUF_IDX)
|
|
||||||
io_buffer_unregister_bvec(cmd, buf_idx, issue_flags);
|
|
||||||
|
|
||||||
if (req_op(req) == REQ_OP_ZONE_APPEND)
|
|
||||||
req->__sector = zone_append_lba;
|
|
||||||
|
|
||||||
if (ublk_need_req_ref(ubq))
|
if (ublk_need_req_ref(ubq))
|
||||||
ublk_sub_req_ref(io, req);
|
return ublk_sub_req_ref(io, req);
|
||||||
else
|
return true;
|
||||||
__ublk_complete_rq(req);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ublk_get_data(const struct ublk_queue *ubq, struct ublk_io *io,
|
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,
|
|||||||
unsigned tag = ub_cmd->tag;
|
unsigned tag = ub_cmd->tag;
|
||||||
struct request *req;
|
struct request *req;
|
||||||
int ret;
|
int ret;
|
||||||
|
bool compl;
|
||||||
|
|
||||||
pr_devel("%s: received: cmd op %d queue %d tag %d result %d\n",
|
pr_devel("%s: received: cmd op %d queue %d tag %d result %d\n",
|
||||||
__func__, cmd->cmd_op, ub_cmd->q_id, tag,
|
__func__, cmd->cmd_op, ub_cmd->q_id, tag,
|
||||||
@ -2367,8 +2359,16 @@ static int __ublk_ch_uring_cmd(struct io_uring_cmd *cmd,
|
|||||||
io->res = ub_cmd->result;
|
io->res = ub_cmd->result;
|
||||||
req = ublk_fill_io_cmd(io, cmd);
|
req = ublk_fill_io_cmd(io, cmd);
|
||||||
ret = ublk_config_io_buf(ubq, io, cmd, ub_cmd->addr, &buf_idx);
|
ret = ublk_config_io_buf(ubq, io, cmd, ub_cmd->addr, &buf_idx);
|
||||||
ublk_commit_and_fetch(ubq, io, cmd, req, issue_flags,
|
compl = ublk_need_complete_req(ubq, io, req);
|
||||||
ub_cmd->zone_append_lba, buf_idx);
|
|
||||||
|
/* can't touch 'ublk_io' any more */
|
||||||
|
if (buf_idx != UBLK_INVALID_BUF_IDX)
|
||||||
|
io_buffer_unregister_bvec(cmd, buf_idx, issue_flags);
|
||||||
|
if (req_op(req) == REQ_OP_ZONE_APPEND)
|
||||||
|
req->__sector = ub_cmd->zone_append_lba;
|
||||||
|
if (compl)
|
||||||
|
__ublk_complete_rq(req);
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user