Skip to content

Commit 0f3ebf2

Browse files
Ming Leiaxboe
authored andcommitted
selftests: ublk: add stripe target
Add ublk stripe target which can take 1~4 underlying backing files or block device, with stripe size 4k ~ 512K. Add two basic tests(write verify & mkfs/mount/umount) over ublk/stripe. This target is helpful to cover multiple IOs aiming at same fixed/registered IO kernel buffer. It is also capable of verifying vectored registered (kernel)buffers in future for zero copy, so far it isn't supported yet. Todo: support vectored registered kernel buffer for ublk/zc. Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 263846e commit 0f3ebf2

File tree

6 files changed

+397
-2
lines changed

6 files changed

+397
-2
lines changed

tools/testing/selftests/ublk/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ TEST_PROGS += test_loop_01.sh
1111
TEST_PROGS += test_loop_02.sh
1212
TEST_PROGS += test_loop_03.sh
1313
TEST_PROGS += test_loop_04.sh
14+
TEST_PROGS += test_stripe_01.sh
15+
TEST_PROGS += test_stripe_02.sh
1416

1517
TEST_PROGS += test_stress_01.sh
1618
TEST_PROGS += test_stress_02.sh
@@ -19,7 +21,7 @@ TEST_GEN_PROGS_EXTENDED = kublk
1921

2022
include ../lib.mk
2123

22-
$(TEST_GEN_PROGS_EXTENDED): kublk.c null.c file_backed.c common.c
24+
$(TEST_GEN_PROGS_EXTENDED): kublk.c null.c file_backed.c common.c stripe.c
2325

2426
check:
2527
shellcheck -x -f gcc *.sh

tools/testing/selftests/ublk/kublk.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ unsigned int ublk_dbg_mask = UBLK_LOG;
99
static const struct ublk_tgt_ops *tgt_ops_list[] = {
1010
&null_tgt_ops,
1111
&loop_tgt_ops,
12+
&stripe_tgt_ops,
1213
};
1314

1415
static const struct ublk_tgt_ops *ublk_find_tgt(const char *name)
@@ -1060,8 +1061,9 @@ int main(int argc, char *argv[])
10601061
{ "depth", 1, NULL, 'd' },
10611062
{ "debug_mask", 1, NULL, 0 },
10621063
{ "quiet", 0, NULL, 0 },
1063-
{ "zero_copy", 1, NULL, 'z' },
1064+
{ "zero_copy", 0, NULL, 'z' },
10641065
{ "foreground", 0, NULL, 0 },
1066+
{ "chunk_size", 1, NULL, 0 },
10651067
{ 0, 0, 0, 0 }
10661068
};
10671069
int option_idx, opt;
@@ -1071,6 +1073,7 @@ int main(int argc, char *argv[])
10711073
.nr_hw_queues = 2,
10721074
.dev_id = -1,
10731075
.tgt_type = "unknown",
1076+
.chunk_size = 65536, /* def chunk size is 64K */
10741077
};
10751078
int ret = -EINVAL, i;
10761079

@@ -1107,6 +1110,8 @@ int main(int argc, char *argv[])
11071110
ublk_dbg_mask = 0;
11081111
if (!strcmp(longopts[option_idx].name, "foreground"))
11091112
ctx.fg = 1;
1113+
if (!strcmp(longopts[option_idx].name, "chunk_size"))
1114+
ctx.chunk_size = strtol(optarg, NULL, 10);
11101115
}
11111116
}
11121117

tools/testing/selftests/ublk/kublk.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <sys/inotify.h>
2020
#include <sys/wait.h>
2121
#include <sys/eventfd.h>
22+
#include <sys/uio.h>
2223
#include <liburing.h>
2324
#include <linux/ublk_cmd.h>
2425
#include "ublk_dep.h"
@@ -66,6 +67,9 @@ struct dev_ctx {
6667
unsigned int all:1;
6768
unsigned int fg:1;
6869

70+
/* stripe */
71+
unsigned int chunk_size;
72+
6973
int _evtfd;
7074
};
7175

@@ -352,7 +356,15 @@ static inline int ublk_queue_use_zc(const struct ublk_queue *q)
352356

353357
extern const struct ublk_tgt_ops null_tgt_ops;
354358
extern const struct ublk_tgt_ops loop_tgt_ops;
359+
extern const struct ublk_tgt_ops stripe_tgt_ops;
355360

356361
void backing_file_tgt_deinit(struct ublk_dev *dev);
357362
int backing_file_tgt_init(struct ublk_dev *dev);
363+
364+
static inline unsigned int ilog2(unsigned int x)
365+
{
366+
if (x == 0)
367+
return 0;
368+
return (sizeof(x) * 8 - 1) - __builtin_clz(x);
369+
}
358370
#endif

0 commit comments

Comments
 (0)