Skip to content

Commit 6ed6476

Browse files
calebsanderaxboe
authored andcommitted
selftests: ublk: add kublk support for integrity params
Add integrity param command line arguments to kublk. Plumb these to struct ublk_params for the null and fault_inject targets, as they don't need to actually read or write the integrity data. Forbid the integrity params for loop or stripe until the integrity data copy is implemented. Signed-off-by: Caleb Sander Mateos <csander@purestorage.com> Reviewed-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 261b67f commit 6ed6476

6 files changed

Lines changed: 78 additions & 0 deletions

File tree

tools/testing/selftests/ublk/fault_inject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static int ublk_fault_inject_tgt_init(const struct dev_ctx *ctx,
3333
.dev_sectors = dev_size >> 9,
3434
},
3535
};
36+
ublk_set_integrity_params(ctx, &dev->tgt.params);
3637

3738
dev->private_data = (void *)(unsigned long)(ctx->fault_inject.delay_us * 1000);
3839
return 0;

tools/testing/selftests/ublk/file_backed.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ static int ublk_loop_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
158158
ublk_err("%s: not support auto_zc_fallback\n", __func__);
159159
return -EINVAL;
160160
}
161+
if (ctx->metadata_size) {
162+
ublk_err("%s: integrity not supported\n", __func__);
163+
return -EINVAL;
164+
}
161165

162166
ret = backing_file_tgt_init(dev);
163167
if (ret)

tools/testing/selftests/ublk/kublk.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Description: uring_cmd based ublk
44
*/
55

6+
#include <linux/fs.h>
67
#include "kublk.h"
78

89
#define MAX_NR_TGT_ARG 64
@@ -1550,6 +1551,8 @@ static void __cmd_create_help(char *exe, bool recovery)
15501551
printf("\t[--foreground] [--quiet] [-z] [--auto_zc] [--auto_zc_fallback] [--debug_mask mask] [-r 0|1] [-g] [-u]\n");
15511552
printf("\t[-e 0|1 ] [-i 0|1] [--no_ublk_fixed_fd]\n");
15521553
printf("\t[--nthreads threads] [--per_io_tasks]\n");
1554+
printf("\t[--integrity_capable] [--integrity_reftag] [--metadata_size SIZE] "
1555+
"[--pi_offset OFFSET] [--csum_type ip|t10dif|nvme] [--tag_size SIZE]\n");
15531556
printf("\t[target options] [backfile1] [backfile2] ...\n");
15541557
printf("\tdefault: nr_queues=2(max 32), depth=128(max 1024), dev_id=-1(auto allocation)\n");
15551558
printf("\tdefault: nthreads=nr_queues");
@@ -1613,6 +1616,12 @@ int main(int argc, char *argv[])
16131616
{ "nthreads", 1, NULL, 0 },
16141617
{ "per_io_tasks", 0, NULL, 0 },
16151618
{ "no_ublk_fixed_fd", 0, NULL, 0 },
1619+
{ "integrity_capable", 0, NULL, 0 },
1620+
{ "integrity_reftag", 0, NULL, 0 },
1621+
{ "metadata_size", 1, NULL, 0 },
1622+
{ "pi_offset", 1, NULL, 0 },
1623+
{ "csum_type", 1, NULL, 0 },
1624+
{ "tag_size", 1, NULL, 0 },
16161625
{ 0, 0, 0, 0 }
16171626
};
16181627
const struct ublk_tgt_ops *ops = NULL;
@@ -1623,6 +1632,7 @@ int main(int argc, char *argv[])
16231632
.nr_hw_queues = 2,
16241633
.dev_id = -1,
16251634
.tgt_type = "unknown",
1635+
.csum_type = LBMD_PI_CSUM_NONE,
16261636
};
16271637
int ret = -EINVAL, i;
16281638
int tgt_argc = 1;
@@ -1697,6 +1707,28 @@ int main(int argc, char *argv[])
16971707
ctx.per_io_tasks = 1;
16981708
if (!strcmp(longopts[option_idx].name, "no_ublk_fixed_fd"))
16991709
ctx.no_ublk_fixed_fd = 1;
1710+
if (!strcmp(longopts[option_idx].name, "integrity_capable"))
1711+
ctx.integrity_flags |= LBMD_PI_CAP_INTEGRITY;
1712+
if (!strcmp(longopts[option_idx].name, "integrity_reftag"))
1713+
ctx.integrity_flags |= LBMD_PI_CAP_REFTAG;
1714+
if (!strcmp(longopts[option_idx].name, "metadata_size"))
1715+
ctx.metadata_size = strtoul(optarg, NULL, 0);
1716+
if (!strcmp(longopts[option_idx].name, "pi_offset"))
1717+
ctx.pi_offset = strtoul(optarg, NULL, 0);
1718+
if (!strcmp(longopts[option_idx].name, "csum_type")) {
1719+
if (!strcmp(optarg, "ip")) {
1720+
ctx.csum_type = LBMD_PI_CSUM_IP;
1721+
} else if (!strcmp(optarg, "t10dif")) {
1722+
ctx.csum_type = LBMD_PI_CSUM_CRC16_T10DIF;
1723+
} else if (!strcmp(optarg, "nvme")) {
1724+
ctx.csum_type = LBMD_PI_CSUM_CRC64_NVME;
1725+
} else {
1726+
ublk_err("invalid csum_type: %s\n", optarg);
1727+
return -EINVAL;
1728+
}
1729+
}
1730+
if (!strcmp(longopts[option_idx].name, "tag_size"))
1731+
ctx.tag_size = strtoul(optarg, NULL, 0);
17001732
break;
17011733
case '?':
17021734
/*
@@ -1739,6 +1771,21 @@ int main(int argc, char *argv[])
17391771
return -EINVAL;
17401772
}
17411773

1774+
if (ctx.metadata_size) {
1775+
if (!(ctx.flags & UBLK_F_USER_COPY)) {
1776+
ublk_err("integrity requires user_copy\n");
1777+
return -EINVAL;
1778+
}
1779+
1780+
ctx.flags |= UBLK_F_INTEGRITY;
1781+
} else if (ctx.integrity_flags ||
1782+
ctx.pi_offset ||
1783+
ctx.csum_type != LBMD_PI_CSUM_NONE ||
1784+
ctx.tag_size) {
1785+
ublk_err("integrity parameters require metadata_size\n");
1786+
return -EINVAL;
1787+
}
1788+
17421789
i = optind;
17431790
while (i < argc && ctx.nr_files < MAX_BACK_FILES) {
17441791
ctx.files[ctx.nr_files++] = argv[i++];

tools/testing/selftests/ublk/kublk.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ struct dev_ctx {
7878
unsigned int auto_zc_fallback:1;
7979
unsigned int per_io_tasks:1;
8080
unsigned int no_ublk_fixed_fd:1;
81+
__u32 integrity_flags;
82+
__u8 metadata_size;
83+
__u8 pi_offset;
84+
__u8 csum_type;
85+
__u8 tag_size;
8186

8287
int _evtfd;
8388
int _shmid;
@@ -202,6 +207,22 @@ struct ublk_dev {
202207

203208
extern int ublk_queue_io_cmd(struct ublk_thread *t, struct ublk_io *io);
204209

210+
static inline void ublk_set_integrity_params(const struct dev_ctx *ctx,
211+
struct ublk_params *params)
212+
{
213+
if (!ctx->metadata_size)
214+
return;
215+
216+
params->types |= UBLK_PARAM_TYPE_INTEGRITY;
217+
params->integrity = (struct ublk_param_integrity) {
218+
.flags = ctx->integrity_flags,
219+
.interval_exp = params->basic.logical_bs_shift,
220+
.metadata_size = ctx->metadata_size,
221+
.pi_offset = ctx->pi_offset,
222+
.csum_type = ctx->csum_type,
223+
.tag_size = ctx->tag_size,
224+
};
225+
}
205226

206227
static inline int ublk_io_auto_zc_fallback(const struct ublksrv_io_desc *iod)
207228
{

tools/testing/selftests/ublk/null.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ static int ublk_null_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
3636
.max_segments = 32,
3737
},
3838
};
39+
ublk_set_integrity_params(ctx, &dev->tgt.params);
3940

4041
if (info->flags & UBLK_F_SUPPORT_ZERO_COPY)
4142
dev->tgt.sq_depth = dev->tgt.cq_depth = 2 * info->queue_depth;

tools/testing/selftests/ublk/stripe.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ static int ublk_stripe_tgt_init(const struct dev_ctx *ctx, struct ublk_dev *dev)
298298
ublk_err("%s: not support auto_zc_fallback\n", __func__);
299299
return -EINVAL;
300300
}
301+
if (ctx->metadata_size) {
302+
ublk_err("%s: integrity not supported\n", __func__);
303+
return -EINVAL;
304+
}
301305

302306
if ((chunk_size & (chunk_size - 1)) || !chunk_size) {
303307
ublk_err("invalid chunk size %u\n", chunk_size);

0 commit comments

Comments
 (0)