Skip to content

Commit 0841ca0

Browse files
committed
ioctl: fix dms command
The DSM ranges data struct needs to be initialized. The rework dropped this part. Also the number of ranges for CDW10 is a 0's value (sic). Fixes: 6c991dc ("src: rework nvme_dsm command") Signed-off-by: Daniel Wagner <[email protected]>
1 parent a160388 commit 0841ca0

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

libnvme/src/nvme/ioctl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4393,9 +4393,9 @@ static inline int nvme_flush(struct nvme_transport_handle *hdl, __u32 nsid)
43934393
* @cmd: Passthru command to use
43944394
* @nsid: Namespace identifier
43954395
* @nr: Number of block ranges in the data set management attributes
4396-
* @idr: DSM Deallocate attribute
4397-
* @idw: DSM Integral Dataset for Read attribute
4398-
* @ad: DSM Integral Dataset for Read attribute
4396+
* @idr: DSM Integral Dataset for Read attribute
4397+
* @idw: DSM Integral Dataset for Write attribute
4398+
* @ad: DSM Deallocate attribute
43994399
* @data: User space destination address to transfer the data
44004400
* @len: Length of provided user buffer to hold the log data in bytes
44014401
*/
@@ -4410,7 +4410,7 @@ nvme_init_dsm(struct nvme_passthru_cmd *cmd,
44104410
cmd->nsid = nsid;
44114411
cmd->data_len = len;
44124412
cmd->addr = (__u64)(uintptr_t)data;
4413-
cmd->cdw10 = NVME_FIELD_ENCODE(nr,
4413+
cmd->cdw10 = NVME_FIELD_ENCODE(nr - 1,
44144414
NVME_DSM_CDW10_NR_SHIFT,
44154415
NVME_DSM_CDW10_NR_MASK);
44164416
cmd->cdw11 = NVME_FIELD_ENCODE(idr,

libnvme/test/ioctl/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ static void test_dsm(void)
989989

990990
arbitrary(dsm, dsm_size);
991991
set_mock_io_cmds(&mock_io_cmd, 1);
992-
nvme_init_dsm(&cmd, TEST_NSID, nr_ranges - 1, 0, 0, 1, dsm, dsm_size);
992+
nvme_init_dsm(&cmd, TEST_NSID, nr_ranges, 0, 0, 1, dsm, dsm_size);
993993
err = nvme_submit_io_passthru(test_hdl, &cmd, &result);
994994
end_mock_cmds();
995995
check(err == 0, "returned error %d", err);

nvme.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7299,12 +7299,12 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi
72997299
_cleanup_nvme_transport_handle_ struct nvme_transport_handle *hdl = NULL;
73007300
_cleanup_free_ struct nvme_dsm_range *dsm = NULL;
73017301
struct nvme_passthru_cmd cmd;
7302-
uint16_t nr, nc, nb, ns;
73037302
__u32 ctx_attrs[256] = {0,};
73047303
__u32 nlbs[256] = {0,};
73057304
__u64 slbas[256] = {0,};
7306-
int err;
73077305
nvme_print_flags_t flags;
7306+
uint16_t nc, nb, ns;
7307+
int err;
73087308

73097309
struct config {
73107310
__u32 namespace_id;
@@ -7351,8 +7351,11 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi
73517351
nc = argconfig_parse_comma_sep_array_u32(cfg.ctx_attrs, ctx_attrs, ARRAY_SIZE(ctx_attrs));
73527352
nb = argconfig_parse_comma_sep_array_u32(cfg.blocks, nlbs, ARRAY_SIZE(nlbs));
73537353
ns = argconfig_parse_comma_sep_array_u64(cfg.slbas, slbas, ARRAY_SIZE(slbas));
7354-
nr = max(nc, max(nb, ns));
7355-
if (!nr || nr > 256) {
7354+
if (nc != nb || nb != ns) {
7355+
nvme_show_error("No valid range definition provided");
7356+
return -EINVAL;
7357+
}
7358+
if (!nc || nc > 256) {
73567359
nvme_show_error("No range definition provided");
73577360
return -EINVAL;
73587361
}
@@ -7364,15 +7367,19 @@ static int dsm(int argc, char **argv, struct command *acmd, struct plugin *plugi
73647367
return err;
73657368
}
73667369
}
7367-
if (!cfg.cdw11)
7368-
cfg.cdw11 = (cfg.ad << 2) | (cfg.idw << 1) | (cfg.idr << 0);
7370+
if (cfg.cdw11) {
7371+
cfg.ad = NVME_GET(cfg.cdw11, DSM_CDW11_AD);
7372+
cfg.idw = NVME_GET(cfg.cdw11, DSM_CDW11_IDW);
7373+
cfg.idr = NVME_GET(cfg.cdw11, DSM_CDW11_IDR);
7374+
}
73697375

7370-
dsm = nvme_alloc(sizeof(*dsm) * 256);
7376+
dsm = nvme_alloc(sizeof(*dsm) * nc);
73717377
if (!dsm)
73727378
return -ENOMEM;
73737379

7374-
nvme_init_dsm(&cmd, cfg.namespace_id, nr, cfg.idr, cfg.idw, cfg.ad, dsm,
7375-
sizeof(*dsm) * 256);
7380+
nvme_init_dsm_range(dsm, ctx_attrs, nlbs, slbas, nc);
7381+
nvme_init_dsm(&cmd, cfg.namespace_id, nc, cfg.idr, cfg.idw, cfg.ad, dsm,
7382+
sizeof(*dsm) * nc);
73767383
err = nvme_submit_io_passthru(hdl, &cmd, NULL);
73777384
if (err < 0)
73787385
nvme_show_error("data-set management: %s", nvme_strerror(err));

0 commit comments

Comments
 (0)