Skip to content

Commit 1e124c1

Browse files
Ming Leikawasaki
authored andcommitted
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 <[email protected]>
1 parent e7e0622 commit 1e124c1

6 files changed

Lines changed: 28 additions & 29 deletions

File tree

tools/testing/selftests/ublk/fault_inject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int ublk_fault_inject_queue_io(struct ublk_thread *t,
5151
io_uring_prep_timeout(sqe, &ts, 1, 0);
5252
sqe->user_data = build_user_data(tag, ublksrv_get_op(iod), 0, q->q_id, 1);
5353

54-
ublk_queued_tgt_io(q, tag, 1);
54+
ublk_queued_tgt_io(t, q, tag, 1);
5555

5656
return 0;
5757
}
@@ -66,8 +66,8 @@ static void ublk_fault_inject_tgt_io_done(struct ublk_thread *t,
6666
if (cqe->res != -ETIME)
6767
ublk_err("%s: unexpected cqe res %d\n", __func__, cqe->res);
6868

69-
if (ublk_completed_tgt_io(q, tag))
70-
ublk_complete_io(q, tag, iod->nr_sectors << 9);
69+
if (ublk_completed_tgt_io(t, q, tag))
70+
ublk_complete_io(t, q, tag, iod->nr_sectors << 9);
7171
else
7272
ublk_err("%s: io not complete after 1 cqe\n", __func__);
7373
}

tools/testing/selftests/ublk/file_backed.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ static int ublk_loop_queue_io(struct ublk_thread *t, struct ublk_queue *q,
107107
{
108108
int queued = loop_queue_tgt_io(t, q, tag);
109109

110-
ublk_queued_tgt_io(q, tag, queued);
110+
ublk_queued_tgt_io(t, q, tag, queued);
111111
return 0;
112112
}
113113

@@ -130,8 +130,8 @@ static void ublk_loop_io_done(struct ublk_thread *t, struct ublk_queue *q,
130130
if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF))
131131
io->tgt_ios += 1;
132132

133-
if (ublk_completed_tgt_io(q, tag))
134-
ublk_complete_io(q, tag, io->result);
133+
if (ublk_completed_tgt_io(t, q, tag))
134+
ublk_complete_io(t, q, tag, io->result);
135135
}
136136

137137
static int ublk_loop_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)

tools/testing/selftests/ublk/kublk.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,8 @@ static void ublk_set_auto_buf_reg(const struct ublk_queue *q,
589589
sqe->addr = ublk_auto_buf_reg_to_sqe_addr(&buf);
590590
}
591591

592-
int ublk_queue_io_cmd(struct ublk_io *io)
592+
int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io)
593593
{
594-
struct ublk_thread *t = io->t;
595594
struct ublk_queue *q = ublk_io_to_queue(io);
596595
struct ublksrv_io_cmd *cmd;
597596
struct io_uring_sqe *sqe[1];
@@ -685,9 +684,8 @@ static void ublk_submit_fetch_commands(struct ublk_thread *t)
685684
int tag = i % dinfo->queue_depth;
686685
q = &t->dev->q[q_id];
687686
io = &q->ios[tag];
688-
io->t = t;
689687
io->buf_index = j++;
690-
ublk_queue_io_cmd(io);
688+
ublk_queue_io_cmd(t, io);
691689
}
692690
} else {
693691
/*
@@ -697,9 +695,8 @@ static void ublk_submit_fetch_commands(struct ublk_thread *t)
697695
struct ublk_queue *q = &t->dev->q[t->idx];
698696
for (i = 0; i < q->q_depth; i++) {
699697
io = &q->ios[i];
700-
io->t = t;
701698
io->buf_index = i;
702-
ublk_queue_io_cmd(io);
699+
ublk_queue_io_cmd(t, io);
703700
}
704701
}
705702
}
@@ -770,7 +767,7 @@ static void ublk_handle_cqe(struct ublk_thread *t,
770767
q->tgt_ops->queue_io(t, q, tag);
771768
} else if (cqe->res == UBLK_IO_RES_NEED_GET_DATA) {
772769
io->flags |= UBLKSRV_NEED_GET_DATA | UBLKSRV_IO_FREE;
773-
ublk_queue_io_cmd(io);
770+
ublk_queue_io_cmd(t, io);
774771
} else {
775772
/*
776773
* COMMIT_REQ will be completed immediately since no fetching

tools/testing/selftests/ublk/kublk.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ struct ublk_io {
136136
unsigned short buf_index;
137137
unsigned short tgt_ios;
138138
void *private_data;
139-
struct ublk_thread *t;
140139
};
141140

142141
struct ublk_tgt_ops {
@@ -232,7 +231,7 @@ struct ublk_dev {
232231

233232

234233
extern unsigned int ublk_dbg_mask;
235-
extern int ublk_queue_io_cmd(struct ublk_io *io);
234+
extern int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io);
236235

237236

238237
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)
402401
return &q->ios[tag];
403402
}
404403

405-
static inline int ublk_complete_io(struct ublk_queue *q, unsigned tag, int res)
404+
static inline int ublk_complete_io(struct ublk_thread *t, struct ublk_queue *q,
405+
unsigned tag, int res)
406406
{
407407
struct ublk_io *io = &q->ios[tag];
408408

409409
ublk_mark_io_done(io, res);
410410

411-
return ublk_queue_io_cmd(io);
411+
return ublk_queue_io_cmd(t, io);
412412
}
413413

414-
static inline void ublk_queued_tgt_io(struct ublk_queue *q, unsigned tag, int queued)
414+
static inline void ublk_queued_tgt_io(struct ublk_thread *t, struct ublk_queue *q,
415+
unsigned tag, int queued)
415416
{
416417
if (queued < 0)
417-
ublk_complete_io(q, tag, queued);
418+
ublk_complete_io(t, q, tag, queued);
418419
else {
419420
struct ublk_io *io = ublk_get_io(q, tag);
420421

421-
io->t->io_inflight += queued;
422+
t->io_inflight += queued;
422423
io->tgt_ios = queued;
423424
io->result = 0;
424425
}
425426
}
426427

427-
static inline int ublk_completed_tgt_io(struct ublk_queue *q, unsigned tag)
428+
static inline int ublk_completed_tgt_io(struct ublk_thread *t,
429+
struct ublk_queue *q, unsigned tag)
428430
{
429431
struct ublk_io *io = ublk_get_io(q, tag);
430432

431-
io->t->io_inflight--;
433+
t->io_inflight--;
432434

433435
return --io->tgt_ios == 0;
434436
}

tools/testing/selftests/ublk/null.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ static void ublk_null_io_done(struct ublk_thread *t, struct ublk_queue *q,
108108
if (op == ublk_cmd_op_nr(UBLK_U_IO_REGISTER_IO_BUF))
109109
io->tgt_ios += 1;
110110

111-
if (ublk_completed_tgt_io(q, tag))
112-
ublk_complete_io(q, tag, io->result);
111+
if (ublk_completed_tgt_io(t, q, tag))
112+
ublk_complete_io(t, q, tag, io->result);
113113
}
114114

115115
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,
125125
else if (zc)
126126
queued = null_queue_zc_io(t, q, tag);
127127
else {
128-
ublk_complete_io(q, tag, iod->nr_sectors << 9);
128+
ublk_complete_io(t, q, tag, iod->nr_sectors << 9);
129129
return 0;
130130
}
131-
ublk_queued_tgt_io(q, tag, queued);
131+
ublk_queued_tgt_io(t, q, tag, queued);
132132
return 0;
133133
}
134134

tools/testing/selftests/ublk/stripe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static int ublk_stripe_queue_io(struct ublk_thread *t, struct ublk_queue *q,
226226
{
227227
int queued = stripe_queue_tgt_io(t, q, tag);
228228

229-
ublk_queued_tgt_io(q, tag, queued);
229+
ublk_queued_tgt_io(t, q, tag, queued);
230230
return 0;
231231
}
232232

@@ -262,13 +262,13 @@ static void ublk_stripe_io_done(struct ublk_thread *t, struct ublk_queue *q,
262262
}
263263
}
264264

265-
if (ublk_completed_tgt_io(q, tag)) {
265+
if (ublk_completed_tgt_io(t, q, tag)) {
266266
int res = io->result;
267267

268268
if (!res)
269269
res = iod->nr_sectors << 9;
270270

271-
ublk_complete_io(q, tag, res);
271+
ublk_complete_io(t, q, tag, res);
272272

273273
free_stripe_array(io->private_data);
274274
io->private_data = NULL;

0 commit comments

Comments
 (0)