]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
Use argument structure for nvme_dsm()
authorHannes Reinecke <hare@suse.de>
Fri, 17 Dec 2021 07:03:42 +0000 (08:03 +0100)
committerDaniel Wagner <dwagner@suse.de>
Mon, 10 Jan 2022 16:55:18 +0000 (17:55 +0100)
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 <hare@suse.de>
src/nvme/ioctl.c
src/nvme/ioctl.h

index 4c2b92bfbef8257431ec2792a5f0f2ec137a8c74..005ba0f5093c7e45b3fcd3b80708afc72c294cad 100644 (file)
@@ -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,
index 1016bc6eae56fb3bf161b59e472904f84ddb3ff3..6c56b58a035da82de0afd8ec9fd9b4b4af1937dd 100644 (file)
@@ -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() -