Skip to content

Commit 8842b72

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: prepare for supporting stripe target
- pass 'truct dev_ctx *ctx' to target init function - add 'private_data' to 'struct ublk_dev' for storing target specific data - add 'private_data' to 'struct ublk_io' for storing per-IO data - add 'tgt_ios' to 'struct ublk_io' for counting how many io_uring ios for handling the current io command - add helper ublk_get_io() for supporting stripe target - add two helpers for simplifying target io handling Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 10d962d commit 8842b72

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

tools/testing/selftests/ublk/file_backed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static void ublk_loop_io_done(struct ublk_queue *q, int tag,
123123
q->io_inflight--;
124124
}
125125

126-
static int ublk_loop_tgt_init(struct ublk_dev *dev)
126+
static int ublk_loop_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
127127
{
128128
unsigned long long bytes;
129129
int ret;

tools/testing/selftests/ublk/kublk.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ static int ublk_queue_init(struct ublk_queue *q)
381381

382382
#define WAIT_USEC 100000
383383
#define MAX_WAIT_USEC (3 * 1000000)
384-
static int ublk_dev_prep(struct ublk_dev *dev)
384+
static int ublk_dev_prep(const struct dev_ctx *ctx, struct ublk_dev *dev)
385385
{
386386
int dev_id = dev->dev_info.dev_id;
387387
unsigned int wait_usec = 0;
@@ -404,7 +404,7 @@ static int ublk_dev_prep(struct ublk_dev *dev)
404404

405405
dev->fds[0] = fd;
406406
if (dev->tgt.ops->init_tgt)
407-
ret = dev->tgt.ops->init_tgt(dev);
407+
ret = dev->tgt.ops->init_tgt(ctx, dev);
408408
if (ret)
409409
close(dev->fds[0]);
410410
return ret;
@@ -666,7 +666,7 @@ static int ublk_start_daemon(const struct dev_ctx *ctx, struct ublk_dev *dev)
666666

667667
ublk_dbg(UBLK_DBG_DEV, "%s enter\n", __func__);
668668

669-
ret = ublk_dev_prep(dev);
669+
ret = ublk_dev_prep(ctx, dev);
670670
if (ret)
671671
return ret;
672672

tools/testing/selftests/ublk/kublk.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ struct ublk_io {
9494
unsigned short refs; /* used by target code only */
9595

9696
int result;
97+
98+
unsigned short tgt_ios;
99+
void *private_data;
97100
};
98101

99102
struct ublk_tgt_ops {
100103
const char *name;
101-
int (*init_tgt)(struct ublk_dev *);
104+
int (*init_tgt)(const struct dev_ctx *ctx, struct ublk_dev *);
102105
void (*deinit_tgt)(struct ublk_dev *);
103106

104107
int (*queue_io)(struct ublk_queue *, int tag);
@@ -146,6 +149,8 @@ struct ublk_dev {
146149
int nr_fds;
147150
int ctrl_fd;
148151
struct io_uring ring;
152+
153+
void *private_data;
149154
};
150155

151156
#ifndef offsetof
@@ -303,6 +308,11 @@ static inline void ublk_set_sqe_cmd_op(struct io_uring_sqe *sqe, __u32 cmd_op)
303308
addr[1] = 0;
304309
}
305310

311+
static inline struct ublk_io *ublk_get_io(struct ublk_queue *q, unsigned tag)
312+
{
313+
return &q->ios[tag];
314+
}
315+
306316
static inline int ublk_complete_io(struct ublk_queue *q, unsigned tag, int res)
307317
{
308318
struct ublk_io *io = &q->ios[tag];
@@ -312,6 +322,28 @@ static inline int ublk_complete_io(struct ublk_queue *q, unsigned tag, int res)
312322
return ublk_queue_io_cmd(q, io, tag);
313323
}
314324

325+
static inline void ublk_queued_tgt_io(struct ublk_queue *q, unsigned tag, int queued)
326+
{
327+
if (queued < 0)
328+
ublk_complete_io(q, tag, queued);
329+
else {
330+
struct ublk_io *io = ublk_get_io(q, tag);
331+
332+
q->io_inflight += queued;
333+
io->tgt_ios = queued;
334+
io->result = 0;
335+
}
336+
}
337+
338+
static inline int ublk_completed_tgt_io(struct ublk_queue *q, unsigned tag)
339+
{
340+
struct ublk_io *io = ublk_get_io(q, tag);
341+
342+
q->io_inflight--;
343+
344+
return --io->tgt_ios == 0;
345+
}
346+
315347
static inline int ublk_queue_use_zc(const struct ublk_queue *q)
316348
{
317349
return q->state & UBLKSRV_ZC;

tools/testing/selftests/ublk/null.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "kublk.h"
44

5-
static int ublk_null_tgt_init(struct ublk_dev *dev)
5+
static int ublk_null_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
66
{
77
const struct ublksrv_ctrl_dev_info *info = &dev->dev_info;
88
unsigned long dev_size = 250UL << 30;

0 commit comments

Comments
 (0)