From: jaredeh Date: Wed, 9 Jan 2019 18:33:57 +0000 (-0800) Subject: timeout option added to ns_create/delete (#440) X-Git-Tag: v1.7~3 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=727ba86c0ad6eb489be67b5bf47cc6a5d95eeee6;p=users%2Fsagi%2Fnvme-cli.git timeout option added to ns_create/delete (#440) * adding timeout option to create namespace command * Add --timeout to nvme_delete --- diff --git a/nvme-ioctl.c b/nvme-ioctl.c index 8b31cedd..dbd8843b 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -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); diff --git a/nvme-ioctl.h b/nvme-ioctl.h index 08feb89b..c82149c7 100644 --- a/nvme-ioctl.h +++ b/nvme-ioctl.h @@ -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 86d8e839..e236eaa1 100644 --- 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)