]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
Use argument structure for nvme_virtual_mgmt()
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 6a624b8bfd1f3070cb6acc4ba047d7314ace90e5..f1ef3efa880db704d931d303bfdb57664e6421d0 100644 (file)
@@ -1490,22 +1490,23 @@ int nvme_dev_self_test(struct nvme_dev_self_test_args *args)
        return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
 }
 
-int nvme_virtual_mgmt(int fd, enum nvme_virt_mgmt_act act,
-                     enum nvme_virt_mgmt_rt rt, __u16 cntlid, __u16 nr,
-                     __u32 *result)
+int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args)
 {
-       __u32 cdw10 = NVME_SET(act, VIRT_MGMT_CDW10_ACT) |
-                       NVME_SET(rt, VIRT_MGMT_CDW10_RT) |
-                       NVME_SET(cntlid, VIRT_MGMT_CDW10_CNTLID);
-       __u32 cdw11 = NVME_SET(nr, VIRT_MGMT_CDW11_NR);
+       __u32 cdw10 = NVME_SET(args->act, VIRT_MGMT_CDW10_ACT) |
+                       NVME_SET(args->rt, VIRT_MGMT_CDW10_RT) |
+                       NVME_SET(args->cntlid, VIRT_MGMT_CDW10_CNTLID);
+       __u32 cdw11 = NVME_SET(args->nr, VIRT_MGMT_CDW11_NR);
 
        struct nvme_passthru_cmd cmd = {
-               .opcode = nvme_admin_virtual_mgmt,
-               .cdw10  = cdw10,
-               .cdw11  = cdw11,
+               .opcode         = nvme_admin_virtual_mgmt,
+               .cdw10          = cdw10,
+               .cdw11          = cdw11,
+               .timeout_ms     = args->timeout,
        };
 
-       return nvme_submit_admin_passthru(fd, &cmd, result);
+       if (args->args_size < sizeof(*args))
+               return -EINVAL;
+       return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
 }
 
 int nvme_submit_io_passthru64(int fd, struct nvme_passthru_cmd64 *cmd,
index 55f097044a59ad5b71687f7a785f12bd539c4a7f..f35c7aa8c44d842b064068898b96330ba4325713 100644 (file)
@@ -3518,13 +3518,30 @@ struct nvme_dev_self_test_args {
 int nvme_dev_self_test(struct nvme_dev_self_test_args *args);
 
 /**
- * nvme_virtual_mgmt() - Virtualization resource management
+ * nvme_virtual_mgmt_args - Arguments for the NVMe Virtualization
+ *                         resource management command
  * @fd:                File descriptor of nvme device
  * @act:       Virtual resource action, see &enum nvme_virt_mgmt_act
  * @rt:                Resource type to modify, see &enum nvme_virt_mgmt_rt
  * @cntlid:    Controller id for which resources are bing modified
  * @nr:                Number of resources being allocated or assigned
+ * @timeout:   Timeout in ms
  * @result:    If successful, the CQE dword0
+ */
+struct nvme_virtual_mgmt_args {
+       int args_size;
+       int fd;
+       enum nvme_virt_mgmt_act act;
+       enum nvme_virt_mgmt_rt rt;
+       __u16 cntlid;
+       __u16 nr;
+       __u32 timeout;
+       __u32 *result;
+};
+
+/**
+ * nvme_virtual_mgmt() - Virtualization resource management
+ * @args:      &struct nvme_virtual_mgmt_args argument structure
  *
  * The Virtualization Management command is supported by primary controllers
  * that support the Virtualization Enhancements capability. This command is
@@ -3537,9 +3554,7 @@ int nvme_dev_self_test(struct nvme_dev_self_test_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_virtual_mgmt(int fd, enum nvme_virt_mgmt_act act,
-                     enum nvme_virt_mgmt_rt rt, __u16 cntlid, __u16 nr,
-                     __u32 *result);
+int nvme_virtual_mgmt(struct nvme_virtual_mgmt_args *args);
 
 /**
  * nvme_flush() - Send an nvme flush command