Skip to content

Commit b171dce

Browse files
hreineckedwsuse
authored andcommitted
Use argument structure for nvme_dsm()
Use an argument structure instead of passing all arguments one by one. This allows for a future expansion of the argument list without having to change the library ABI. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent 0358361 commit b171dce

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/nvme/ioctl.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,22 +1586,21 @@ int nvme_io(struct nvme_io_args *args, __u8 opcode)
15861586
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
15871587
}
15881588

1589-
int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges,
1590-
struct nvme_dsm_range *dsm, __u32 timeout, __u32 *result)
1589+
int nvme_dsm(struct nvme_dsm_args *args)
15911590
{
1592-
__u32 cdw11 = attrs;
1593-
15941591
struct nvme_passthru_cmd cmd = {
15951592
.opcode = nvme_cmd_dsm,
1596-
.nsid = nsid,
1597-
.addr = (__u64)(uintptr_t)dsm,
1598-
.data_len = nr_ranges * sizeof(*dsm),
1599-
.cdw10 = nr_ranges - 1,
1600-
.cdw11 = cdw11,
1601-
.timeout_ms = timeout,
1593+
.nsid = args->nsid,
1594+
.addr = (__u64)(uintptr_t)args->dsm,
1595+
.data_len = args->nr_ranges * sizeof(*args->dsm),
1596+
.cdw10 = args->nr_ranges - 1,
1597+
.cdw11 = args->attrs,
1598+
.timeout_ms = args->timeout,
16021599
};
16031600

1604-
return nvme_submit_io_passthru(fd, &cmd, result);
1601+
if (args->args_size < sizeof(*args))
1602+
return -EINVAL;
1603+
return nvme_submit_io_passthru(args->fd, &cmd, args->result);
16051604
}
16061605

16071606
int nvme_copy(int fd, __u32 nsid, struct nvme_copy_range *copy, __u64 sdlba,

src/nvme/ioctl.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,14 +3712,29 @@ static inline int nvme_verify(struct nvme_io_args *args)
37123712
}
37133713

37143714
/**
3715-
* nvme_dsm() - Send an nvme data set management command
3715+
* nvme_dsm_args - Arguments for the NVMe Dataset Management command
37163716
* @fd: File descriptor of nvme device
37173717
* @nsid: Namespace identifier
37183718
* @attrs: DSM attributes, see &enum nvme_dsm_attributes
37193719
* @nr_ranges: Number of block ranges in the data set management attributes
37203720
* @dsm: The data set management attributes
37213721
* @timeout: Timeout in ms
37223722
* @result: The command completion result from CQE dword0
3723+
*/
3724+
struct nvme_dsm_args {
3725+
int args_size;
3726+
int fd;
3727+
__u32 nsid;
3728+
__u32 attrs;
3729+
__u16 nr_ranges;
3730+
struct nvme_dsm_range *dsm;
3731+
__u32 timeout;
3732+
__u32 *result;
3733+
};
3734+
3735+
/**
3736+
* nvme_dsm() - Send an nvme data set management command
3737+
* @args: &struct nvme_dsm_args argument structure
37233738
*
37243739
* The Dataset Management command is used by the host to indicate attributes
37253740
* for ranges of logical blocks. This includes attributes like frequency that
@@ -3730,8 +3745,7 @@ static inline int nvme_verify(struct nvme_io_args *args)
37303745
* Return: The nvme command status if a response was received (see
37313746
* &enum nvme_status_field) or -1 with errno set otherwise.
37323747
*/
3733-
int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges,
3734-
struct nvme_dsm_range *dsm, __u32 timeout, __u32 *result);
3748+
int nvme_dsm(struct nvme_dsm_args *args);
37353749

37363750
/**
37373751
* nvme_copy() -

0 commit comments

Comments
 (0)