Skip to content

Commit a180203

Browse files
committed
ioctl: nvme_dsm use nvme_passthru_cmd directly
Drop struct nvme_dsm_args. Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
1 parent 499a108 commit a180203

File tree

5 files changed

+33
-54
lines changed

5 files changed

+33
-54
lines changed

src/libnvme.map

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ LIBNVME_2_0 {
6767
nvme_directive_send;
6868
nvme_directive_send_id_endir;
6969
nvme_disconnect_ctrl;
70-
nvme_dsm;
7170
nvme_dump_config;
7271
nvme_dump_tree;
7372
nvme_errno_to_string;

src/nvme/api-types.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -449,26 +449,6 @@ struct nvme_io_args {
449449
__u8 pif;
450450
};
451451

452-
/**
453-
* struct nvme_dsm_args - Arguments for the NVMe Dataset Management command
454-
* @result: The command completion result from CQE dword0
455-
* @dsm: The data set management attributes
456-
* @args_size: Size of &struct nvme_dsm_args
457-
* @timeout: Timeout in ms
458-
* @nsid: Namespace identifier
459-
* @attrs: DSM attributes, see &enum nvme_dsm_attributes
460-
* @nr_ranges: Number of block ranges in the data set management attributes
461-
*/
462-
struct nvme_dsm_args {
463-
__u32 *result;
464-
struct nvme_dsm_range *dsm;
465-
int args_size;
466-
__u32 timeout;
467-
__u32 nsid;
468-
__u32 attrs;
469-
__u16 nr_ranges;
470-
};
471-
472452
/**
473453
* struct nvme_copy_args - Arguments for the NVMe Copy command
474454
* @sdlba: Start destination LBA

src/nvme/ioctl.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,24 +1751,6 @@ int nvme_io(nvme_link_t l, struct nvme_io_args *args, __u8 opcode)
17511751
return nvme_submit_io_passthru(l, &cmd, args->result);
17521752
}
17531753

1754-
int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args)
1755-
{
1756-
struct nvme_passthru_cmd cmd = {
1757-
.opcode = nvme_cmd_dsm,
1758-
.nsid = args->nsid,
1759-
.addr = (__u64)(uintptr_t)args->dsm,
1760-
.data_len = args->nr_ranges * sizeof(*args->dsm),
1761-
.cdw10 = args->nr_ranges - 1,
1762-
.cdw11 = args->attrs,
1763-
.timeout_ms = args->timeout,
1764-
};
1765-
1766-
if (args->args_size < sizeof(*args))
1767-
return -EINVAL;
1768-
1769-
return nvme_submit_io_passthru(l, &cmd, args->result);
1770-
}
1771-
17721754
int nvme_copy(nvme_link_t l, struct nvme_copy_args *args)
17731755
{
17741756
const size_t size_v1 = sizeof_args(struct nvme_copy_args, format, __u64);

src/nvme/ioctl.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ enum nvme_cmd_dword_fields {
327327
NVME_ZNS_MGMT_RECV_ZRAS_FEAT_MASK = 0x1,
328328
NVME_DIM_TAS_SHIFT = 0,
329329
NVME_DIM_TAS_MASK = 0xF,
330+
NVME_DSM_CDW10_NR_SHIFT = 0,
331+
NVME_DSM_CDW10_NR_MASK = 0xff,
332+
NVME_DSM_CDW11_IDR_SHIFT = 0,
333+
NVME_DSM_CDW11_IDR_MASK = 0x1,
334+
NVME_DSM_CDW11_IDW_SHIFT = 1,
335+
NVME_DSM_CDW11_IDW_MASK = 0x1,
336+
NVME_DSM_CDW11_AD_SHIFT = 2,
337+
NVME_DSM_CDW11_AD_MASK = 0x1,
330338
};
331339

332340
/**
@@ -3800,7 +3808,10 @@ static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args)
38003808
/**
38013809
* nvme_dsm() - Send an nvme data set management command
38023810
* @l: Link handle
3803-
* @args: &struct nvme_dsm_args argument structure
3811+
* @dsm: The data set management attributes
3812+
* @nr_ranges: Number of block ranges in the data set management attributes
3813+
* @attrs: DSM attributes, see &enum nvme_dsm_attributes
3814+
* @nsid: Namespace identifier
38043815
*
38053816
* The Dataset Management command is used by the host to indicate attributes
38063817
* for ranges of logical blocks. This includes attributes like frequency that
@@ -3811,7 +3822,23 @@ static inline int nvme_verify(nvme_link_t l, struct nvme_io_args *args)
38113822
* Return: 0 on success, the nvme command status if a response was
38123823
* received (see &enum nvme_status_field) or a negative error otherwise.
38133824
*/
3814-
int nvme_dsm(nvme_link_t l, struct nvme_dsm_args *args);
3825+
static inline int nvme_dsm(nvme_link_t l, struct nvme_dsm_range *dsm, __u16 nr_ranges, __u32 attrs,
3826+
__u32 nsid, __u32 *result)
3827+
{
3828+
__u32 cdw10 = NVME_SET(nr_ranges - 1, DSM_CDW10_NR);
3829+
__u32 cdw11 = attrs;
3830+
3831+
struct nvme_passthru_cmd cmd = {
3832+
.opcode = nvme_cmd_dsm,
3833+
.nsid = nsid,
3834+
.addr = (__u64)(uintptr_t)dsm,
3835+
.data_len = nr_ranges * sizeof(*dsm),
3836+
.cdw10 = cdw10,
3837+
.cdw11 = cdw11,
3838+
};
3839+
3840+
return nvme_submit_io_passthru(l, &cmd, result);
3841+
}
38153842

38163843
/**
38173844
* nvme_copy() - Copy command

test/ioctl/misc.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,29 +1109,20 @@ static void test_dsm(void)
11091109
dsm = malloc(dsm_size);
11101110
check(dsm, "dsm: ENOMEM");
11111111

1112-
struct nvme_dsm_args args = {
1113-
.result = &result,
1114-
.dsm = dsm,
1115-
.args_size = sizeof(args),
1116-
.nsid = TEST_NSID,
1117-
.attrs = NVME_DSMGMT_AD,
1118-
.nr_ranges = nr_ranges,
1119-
};
1120-
11211112
struct mock_cmd mock_io_cmd = {
11221113
.opcode = nvme_cmd_dsm,
11231114
.nsid = TEST_NSID,
1124-
.cdw10 = args.nr_ranges - 1,
1125-
.cdw11 = args.attrs,
1115+
.cdw10 = nr_ranges - 1,
1116+
.cdw11 = NVME_DSMGMT_AD,
11261117
.data_len = dsm_size,
1127-
.in_data = args.dsm,
1118+
.in_data = dsm,
11281119
};
11291120

11301121
int err;
11311122

11321123
arbitrary(dsm, dsm_size);
11331124
set_mock_io_cmds(&mock_io_cmd, 1);
1134-
err = nvme_dsm(test_link, &args);
1125+
err = nvme_dsm(test_link, dsm, nr_ranges, NVME_DSMGMT_AD, TEST_NSID, &result);
11351126
end_mock_cmds();
11361127
check(err == 0, "returned error %d", err);
11371128
check(result == 0, "returned result %u", result);

0 commit comments

Comments
 (0)