From b171dce243e6674e164081b5b1409fec96edd5ee Mon Sep 17 00:00:00 2001 From: Hannes Reinecke Date: Fri, 17 Dec 2021 08:03:42 +0100 Subject: [PATCH] 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 --- src/nvme/ioctl.c | 21 ++++++++++----------- src/nvme/ioctl.h | 20 +++++++++++++++++--- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 4c2b92bf..005ba0f5 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -1586,22 +1586,21 @@ int nvme_io(struct nvme_io_args *args, __u8 opcode) return nvme_submit_io_passthru(args->fd, &cmd, args->result); } -int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges, - struct nvme_dsm_range *dsm, __u32 timeout, __u32 *result) +int nvme_dsm(struct nvme_dsm_args *args) { - __u32 cdw11 = attrs; - struct nvme_passthru_cmd cmd = { .opcode = nvme_cmd_dsm, - .nsid = nsid, - .addr = (__u64)(uintptr_t)dsm, - .data_len = nr_ranges * sizeof(*dsm), - .cdw10 = nr_ranges - 1, - .cdw11 = cdw11, - .timeout_ms = timeout, + .nsid = args->nsid, + .addr = (__u64)(uintptr_t)args->dsm, + .data_len = args->nr_ranges * sizeof(*args->dsm), + .cdw10 = args->nr_ranges - 1, + .cdw11 = args->attrs, + .timeout_ms = args->timeout, }; - return nvme_submit_io_passthru(fd, &cmd, result); + if (args->args_size < sizeof(*args)) + return -EINVAL; + return nvme_submit_io_passthru(args->fd, &cmd, args->result); } int nvme_copy(int fd, __u32 nsid, struct nvme_copy_range *copy, __u64 sdlba, diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 1016bc6e..6c56b58a 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -3712,7 +3712,7 @@ static inline int nvme_verify(struct nvme_io_args *args) } /** - * nvme_dsm() - Send an nvme data set management command + * nvme_dsm_args - Arguments for the NVMe Dataset Management command * @fd: File descriptor of nvme device * @nsid: Namespace identifier * @attrs: DSM attributes, see &enum nvme_dsm_attributes @@ -3720,6 +3720,21 @@ static inline int nvme_verify(struct nvme_io_args *args) * @dsm: The data set management attributes * @timeout: Timeout in ms * @result: The command completion result from CQE dword0 + */ +struct nvme_dsm_args { + int args_size; + int fd; + __u32 nsid; + __u32 attrs; + __u16 nr_ranges; + struct nvme_dsm_range *dsm; + __u32 timeout; + __u32 *result; +}; + +/** + * nvme_dsm() - Send an nvme data set management command + * @args: &struct nvme_dsm_args argument structure * * The Dataset Management command is used by the host to indicate attributes * 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) * Return: The nvme command status if a response was received (see * &enum nvme_status_field) or -1 with errno set otherwise. */ -int nvme_dsm(int fd, __u32 nsid, __u32 attrs, __u16 nr_ranges, - struct nvme_dsm_range *dsm, __u32 timeout, __u32 *result); +int nvme_dsm(struct nvme_dsm_args *args); /** * nvme_copy() - -- 2.50.1