selftests: ublk: pass 'ublk_thread *' to more common helpers
Pass 'ublk_thread *' to more common helpers, then we can avoid to store this reference into 'struct ublk_io'. Prepare for supporting to handle IO via different task context. Signed-off-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250713143415.2857561-14-ming.lei@redhat.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
@@ -51,7 +51,7 @@ static int ublk_fault_inject_queue_io(struct ublk_thread *t,
|
||||
io_uring_prep_timeout(sqe, &ts, 1, 0);
|
||||
sqe->user_data = build_user_data(tag, ublksrv_get_op(iod), 0, q->q_id, 1);
|
||||
|
||||
ublk_queued_tgt_io(q, tag, 1);
|
||||
ublk_queued_tgt_io(t, q, tag, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -66,8 +66,8 @@ static void ublk_fault_inject_tgt_io_done(struct ublk_thread *t,
|
||||
if (cqe->res != -ETIME)
|
||||
ublk_err("%s: unexpected cqe res %d\n", __func__, cqe->res);
|
||||
|
||||
if (ublk_completed_tgt_io(q, tag))
|
||||
ublk_complete_io(q, tag, iod->nr_sectors << 9);
|
||||
if (ublk_completed_tgt_io(t, q, tag))
|
||||
ublk_complete_io(t, q, tag, iod->nr_sectors << 9);
|
||||
else
|
||||
ublk_err("%s: io not complete after 1 cqe\n", __func__);
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ static int ublk_loop_queue_io(struct ublk_thread *t, struct ublk_queue *q,
|
||||
{
|
||||
int queued = loop_queue_tgt_io(t, q, tag);
|
||||
|
||||
ublk_queued_tgt_io(q, tag, queued);
|
||||
ublk_queued_tgt_io(t, q, tag, queued);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -130,8 +130,8 @@ static void ublk_loop_io_done(struct ublk_thread *t, struct ublk_queue *q,
|
||||
if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF))
|
||||
io->tgt_ios += 1;
|
||||
|
||||
if (ublk_completed_tgt_io(q, tag))
|
||||
ublk_complete_io(q, tag, io->result);
|
||||
if (ublk_completed_tgt_io(t, q, tag))
|
||||
ublk_complete_io(t, q, tag, io->result);
|
||||
}
|
||||
|
||||
static int ublk_loop_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
|
||||
|
||||
@@ -589,9 +589,8 @@ static void ublk_set_auto_buf_reg(const struct ublk_queue *q,
|
||||
sqe->addr = ublk_auto_buf_reg_to_sqe_addr(&buf);
|
||||
}
|
||||
|
||||
int ublk_queue_io_cmd(struct ublk_io *io)
|
||||
int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io)
|
||||
{
|
||||
struct ublk_thread *t = io->t;
|
||||
struct ublk_queue *q = ublk_io_to_queue(io);
|
||||
struct ublksrv_io_cmd *cmd;
|
||||
struct io_uring_sqe *sqe[1];
|
||||
@@ -685,9 +684,8 @@ static void ublk_submit_fetch_commands(struct ublk_thread *t)
|
||||
int tag = i % dinfo->queue_depth;
|
||||
q = &t->dev->q[q_id];
|
||||
io = &q->ios[tag];
|
||||
io->t = t;
|
||||
io->buf_index = j++;
|
||||
ublk_queue_io_cmd(io);
|
||||
ublk_queue_io_cmd(t, io);
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
@@ -697,9 +695,8 @@ static void ublk_submit_fetch_commands(struct ublk_thread *t)
|
||||
struct ublk_queue *q = &t->dev->q[t->idx];
|
||||
for (i = 0; i < q->q_depth; i++) {
|
||||
io = &q->ios[i];
|
||||
io->t = t;
|
||||
io->buf_index = i;
|
||||
ublk_queue_io_cmd(io);
|
||||
ublk_queue_io_cmd(t, io);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -770,7 +767,7 @@ static void ublk_handle_cqe(struct ublk_thread *t,
|
||||
q->tgt_ops->queue_io(t, q, tag);
|
||||
} else if (cqe->res == UBLK_IO_RES_NEED_GET_DATA) {
|
||||
io->flags |= UBLKSRV_NEED_GET_DATA | UBLKSRV_IO_FREE;
|
||||
ublk_queue_io_cmd(io);
|
||||
ublk_queue_io_cmd(t, io);
|
||||
} else {
|
||||
/*
|
||||
* COMMIT_REQ will be completed immediately since no fetching
|
||||
|
||||
@@ -136,7 +136,6 @@ struct ublk_io {
|
||||
unsigned short buf_index;
|
||||
unsigned short tgt_ios;
|
||||
void *private_data;
|
||||
struct ublk_thread *t;
|
||||
};
|
||||
|
||||
struct ublk_tgt_ops {
|
||||
@@ -232,7 +231,7 @@ struct ublk_dev {
|
||||
|
||||
|
||||
extern unsigned int ublk_dbg_mask;
|
||||
extern int ublk_queue_io_cmd(struct ublk_io *io);
|
||||
extern int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io);
|
||||
|
||||
|
||||
static inline int ublk_io_auto_zc_fallback(const struct ublksrv_io_desc *iod)
|
||||
@@ -402,33 +401,36 @@ static inline struct ublk_io *ublk_get_io(struct ublk_queue *q, unsigned tag)
|
||||
return &q->ios[tag];
|
||||
}
|
||||
|
||||
static inline int ublk_complete_io(struct ublk_queue *q, unsigned tag, int res)
|
||||
static inline int ublk_complete_io(struct ublk_thread *t, struct ublk_queue *q,
|
||||
unsigned tag, int res)
|
||||
{
|
||||
struct ublk_io *io = &q->ios[tag];
|
||||
|
||||
ublk_mark_io_done(io, res);
|
||||
|
||||
return ublk_queue_io_cmd(io);
|
||||
return ublk_queue_io_cmd(t, io);
|
||||
}
|
||||
|
||||
static inline void ublk_queued_tgt_io(struct ublk_queue *q, unsigned tag, int queued)
|
||||
static inline void ublk_queued_tgt_io(struct ublk_thread *t, struct ublk_queue *q,
|
||||
unsigned tag, int queued)
|
||||
{
|
||||
if (queued < 0)
|
||||
ublk_complete_io(q, tag, queued);
|
||||
ublk_complete_io(t, q, tag, queued);
|
||||
else {
|
||||
struct ublk_io *io = ublk_get_io(q, tag);
|
||||
|
||||
io->t->io_inflight += queued;
|
||||
t->io_inflight += queued;
|
||||
io->tgt_ios = queued;
|
||||
io->result = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static inline int ublk_completed_tgt_io(struct ublk_queue *q, unsigned tag)
|
||||
static inline int ublk_completed_tgt_io(struct ublk_thread *t,
|
||||
struct ublk_queue *q, unsigned tag)
|
||||
{
|
||||
struct ublk_io *io = ublk_get_io(q, tag);
|
||||
|
||||
io->t->io_inflight--;
|
||||
t->io_inflight--;
|
||||
|
||||
return --io->tgt_ios == 0;
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ static void ublk_null_io_done(struct ublk_thread *t, struct ublk_queue *q,
|
||||
if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF))
|
||||
io->tgt_ios += 1;
|
||||
|
||||
if (ublk_completed_tgt_io(q, tag))
|
||||
ublk_complete_io(q, tag, io->result);
|
||||
if (ublk_completed_tgt_io(t, q, tag))
|
||||
ublk_complete_io(t, q, tag, io->result);
|
||||
}
|
||||
|
||||
static int ublk_null_queue_io(struct ublk_thread *t, struct ublk_queue *q,
|
||||
@@ -125,10 +125,10 @@ static int ublk_null_queue_io(struct ublk_thread *t, struct ublk_queue *q,
|
||||
else if (zc)
|
||||
queued = null_queue_zc_io(t, q, tag);
|
||||
else {
|
||||
ublk_complete_io(q, tag, iod->nr_sectors << 9);
|
||||
ublk_complete_io(t, q, tag, iod->nr_sectors << 9);
|
||||
return 0;
|
||||
}
|
||||
ublk_queued_tgt_io(q, tag, queued);
|
||||
ublk_queued_tgt_io(t, q, tag, queued);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -226,7 +226,7 @@ static int ublk_stripe_queue_io(struct ublk_thread *t, struct ublk_queue *q,
|
||||
{
|
||||
int queued = stripe_queue_tgt_io(t, q, tag);
|
||||
|
||||
ublk_queued_tgt_io(q, tag, queued);
|
||||
ublk_queued_tgt_io(t, q, tag, queued);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -262,13 +262,13 @@ static void ublk_stripe_io_done(struct ublk_thread *t, struct ublk_queue *q,
|
||||
}
|
||||
}
|
||||
|
||||
if (ublk_completed_tgt_io(q, tag)) {
|
||||
if (ublk_completed_tgt_io(t, q, tag)) {
|
||||
int res = io->result;
|
||||
|
||||
if (!res)
|
||||
res = iod->nr_sectors << 9;
|
||||
|
||||
ublk_complete_io(q, tag, res);
|
||||
ublk_complete_io(t, q, tag, res);
|
||||
|
||||
free_stripe_array(io->private_data);
|
||||
io->private_data = NULL;
|
||||
|
||||
Reference in New Issue
Block a user