]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
Use argument structure for nvme_sanize_nvm()
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 15fe32550c84ada6bc1358ea9a4fc0eb8e336dae..7725da791dfe84f967a62fe4be2d78117585c1c4 100644 (file)
@@ -1453,25 +1453,25 @@ int nvme_get_property(struct nvme_get_property_args *args)
        return nvme_submit_admin_passthru64(args->fd, &cmd, args->value);
 }
 
-int nvme_sanitize_nvm(int fd, enum nvme_sanitize_sanact sanact, bool ause,
-                     __u8 owpass, bool oipbp, bool nodas, __u32 ovrpat,
-                     __u32 timeout, __u32 *result)
+int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args)
 {
-       __u32 cdw10 = NVME_SET(sanact, SANITIZE_CDW10_SANACT) |
-                       NVME_SET(!!ause, SANITIZE_CDW10_AUSE) |
-                       NVME_SET(owpass, SANITIZE_CDW10_OWPASS) |
-                       NVME_SET(!!oipbp, SANITIZE_CDW10_OIPBP) |
-                       NVME_SET(!!nodas, SANITIZE_CDW10_NODAS);
-       __u32 cdw11 = ovrpat;
+       __u32 cdw10 = NVME_SET(args->sanact, SANITIZE_CDW10_SANACT) |
+                       NVME_SET(!!args->ause, SANITIZE_CDW10_AUSE) |
+                       NVME_SET(args->owpass, SANITIZE_CDW10_OWPASS) |
+                       NVME_SET(!!args->oipbp, SANITIZE_CDW10_OIPBP) |
+                       NVME_SET(!!args->nodas, SANITIZE_CDW10_NODAS);
+       __u32 cdw11 = args->ovrpat;
 
        struct nvme_passthru_cmd cmd = {
                .opcode         = nvme_admin_sanitize_nvm,
                .cdw10          = cdw10,
                .cdw11          = cdw11,
-               .timeout_ms     = timeout,
+               .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_dev_self_test(int fd, __u32 nsid, enum nvme_dst_stc stc)
index 167a0524cf29fa39e71a0a622f783effd704f16b..b20eb1d4ca4cd3818785bf269fb02002d250ee36 100644 (file)
@@ -3437,7 +3437,7 @@ struct nvme_get_property_args {
 int nvme_get_property(struct nvme_get_property_args *args);
 
 /**
- * nvme_sanitize_nvm() - Start a sanitize operation
+ * nvme_sanitize_nvm_args - Arguments for the NVMe Sanitize NVM command
  * @fd:                File descriptor of nvme device
  * @sanact:    Sanitize action, see &enum nvme_sanitize_sanact
  * @ause:      Set to allow unrestriced sanitize exit
@@ -3447,6 +3447,23 @@ int nvme_get_property(struct nvme_get_property_args *args);
  * @ovrpat:    Overwrite pattern
  * @timeout:   Timeout in ms
  * @result:    The command completion result from CQE dword0
+ */
+struct nvme_sanitize_nvm_args {
+       int args_size;
+       int fd;
+       enum nvme_sanitize_sanact sanact;
+       bool ause;
+       __u8 owpass;
+       bool oipbp;
+       bool nodas;
+       __u32 ovrpat;
+       __u32 timeout;
+       __u32 *result;
+};
+
+/**
+ * nvme_sanitize_nvm() - Start a sanitize operation
+ * @args:      &struct nvme_sanitize_nvm_args argument structure
  *
  * A sanitize operation alters all user data in the NVM subsystem such that
  * recovery of any previous user data from any cache, the non-volatile media,
@@ -3461,9 +3478,7 @@ int nvme_get_property(struct nvme_get_property_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_sanitize_nvm(int fd, enum nvme_sanitize_sanact sanact, bool ause,
-                     __u8 owpass, bool oipbp, bool nodas, __u32 ovrpat,
-                     __u32 timeout, __u32 *result);
+int nvme_sanitize_nvm(struct nvme_sanitize_nvm_args *args);
 
 /**
  * nvme_dev_self_test() - Start or abort a self test