]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
timeout option added to ns_create/delete (#440)
authorjaredeh <jaredeh@gmail.com>
Wed, 9 Jan 2019 18:33:57 +0000 (10:33 -0800)
committerKeith Busch <keith.busch@intel.com>
Wed, 9 Jan 2019 18:33:57 +0000 (11:33 -0700)
* adding timeout option to create namespace command

* Add --timeout to nvme_delete

nvme-ioctl.c
nvme-ioctl.h
nvme.c

index 8b31cedd22c43444b0918fdc5f3fe32c90ce9669..dbd8843b1982765007af0dce436a870c185fb9c2 100644 (file)
@@ -675,7 +675,7 @@ int nvme_format(int fd, __u32 nsid, __u8 lbaf, __u8 ses, __u8 pi,
 }
 
 int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
-                  __u8 dps, __u8 nmic, __u32 *result)
+                  __u8 dps, __u8 nmic, __u32 timeout, __u32 *result)
 {
        struct nvme_id_ns ns = {
                .nsze           = cpu_to_le64(nsze),
@@ -689,6 +689,7 @@ int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
                .addr           = (__u64)(uintptr_t) ((void *)&ns),
                .cdw10          = 0,
                .data_len       = 0x1000,
+               .timeout_ms     = timeout,
        };
        int err;
 
@@ -698,12 +699,13 @@ int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
        return err;
 }
 
-int nvme_ns_delete(int fd, __u32 nsid)
+int nvme_ns_delete(int fd, __u32 nsid, __u32 timeout)
 {
        struct nvme_admin_cmd cmd = {
                .opcode         = nvme_admin_ns_mgmt,
                .nsid           = nsid,
                .cdw10          = 1,
+               .timeout_ms     = timeout,
        };
 
        return nvme_submit_admin_passthru(fd, &cmd);
index 08feb89b291967437e82c0c5bdcae32aba9d156e..c82149c7aa7626a6aa54e7cb58a8d1d742d0abd7 100644 (file)
@@ -6,6 +6,8 @@
 #include "linux/nvme_ioctl.h"
 #include "nvme.h"
 
+#define NVME_IOCTL_TIMEOUT 120000 /* in milliseconds */
+
 int nvme_get_nsid(int fd);
 
 /* Generic passthrough */
@@ -105,8 +107,8 @@ int nvme_format(int fd, __u32 nsid, __u8 lbaf, __u8 ses, __u8 pi,
                __u8 pil, __u8 ms, __u32 timeout);
 
 int nvme_ns_create(int fd, __u64 nsze, __u64 ncap, __u8 flbas,
-                  __u8 dps, __u8 nmic, __u32 *result);
-int nvme_ns_delete(int fd, __u32 nsid);
+                  __u8 dps, __u8 nmic, __u32 timeout, __u32 *result);
+int nvme_ns_delete(int fd, __u32 nsid, __u32 timeout);
 
 int nvme_ns_attachment(int fd, __u32 nsid, __u16 num_ctrls,
                       __u16 *ctrlist, bool attach);
diff --git a/nvme.c b/nvme.c
index 86d8e839b853a252ee4e9150100b72579fdd5f6d..e236eaa10d27515503c08e1572ad5fd12a8fcd83 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -1018,18 +1018,22 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *
                "becomes inactive when that namespace is detached or, if "\
                "the namespace is not already inactive, once deleted.";
        const char *namespace_id = "namespace to delete";
+       const char *timeout = "timeout value, in milliseconds";
        int err, fd;
 
        struct config {
                __u32   namespace_id;
+               __u32   timeout;
        };
 
        struct config cfg = {
                .namespace_id    = 0,
+               .timeout      = NVME_IOCTL_TIMEOUT,
        };
 
        const struct argconfig_commandline_options command_line_options[] = {
                {"namespace-id", 'n', "NUM",  CFG_POSITIVE, &cfg.namespace_id,    required_argument, namespace_id},
+               {"timeout", 't', "NUM", CFG_POSITIVE,  &cfg.timeout, required_argument, timeout},
                {NULL}
        };
 
@@ -1050,7 +1054,7 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *
                goto close_fd;
        }
 
-       err = nvme_ns_delete(fd, cfg.namespace_id);
+       err = nvme_ns_delete(fd, cfg.namespace_id, cfg.timeout);
        if (!err)
                printf("%s: Success, deleted nsid:%d\n", cmd->name,
                                                                cfg.namespace_id);
@@ -1163,6 +1167,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
        const char *flbas = "FLBA size";
        const char *dps = "data protection capabilities";
        const char *nmic = "multipath and sharing capabilities";
+       const char *timeout = "timeout value, in milliseconds";
 
        int err = 0, fd;
        __u32 nsid;
@@ -1173,9 +1178,11 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                __u8    flbas;
                __u8    dps;
                __u8    nmic;
+               __u32   timeout;
        };
 
        struct config cfg = {
+               .timeout      = NVME_IOCTL_TIMEOUT,
        };
 
        const struct argconfig_commandline_options command_line_options[] = {
@@ -1184,6 +1191,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                {"flbas", 'f', "NUM", CFG_BYTE,        &cfg.flbas, required_argument, flbas},
                {"dps",   'd', "NUM", CFG_BYTE,        &cfg.dps,   required_argument, dps},
                {"nmic",  'm', "NUM", CFG_BYTE,        &cfg.nmic,  required_argument, nmic},
+               {"timeout", 't', "NUM", CFG_POSITIVE,  &cfg.timeout, required_argument, timeout},
                {NULL}
        };
 
@@ -1191,7 +1199,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
        if (fd < 0)
                return fd;
 
-       err = nvme_ns_create(fd, cfg.nsze, cfg.ncap, cfg.flbas, cfg.dps, cfg.nmic, &nsid);
+       err = nvme_ns_create(fd, cfg.nsze, cfg.ncap, cfg.flbas, cfg.dps, cfg.nmic, cfg.timeout, &nsid);
        if (!err)
                printf("%s: Success, created nsid:%d\n", cmd->name, nsid);
        else if (err > 0)