From: Keith Busch Date: Fri, 18 Mar 2016 17:57:02 +0000 (-0600) Subject: Use enum instead of hard-coded values X-Git-Tag: v0.6~6 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=70a2bfd4291ad621284813b872aef123c6511cbb;p=users%2Fsagi%2Fnvme-cli.git Use enum instead of hard-coded values Define constants to make clear what a device is doing. Noticing that one identify mode was never used, so adding an option. Signed-off-by: Keith Busch --- diff --git a/Documentation/nvme-id-ns.1 b/Documentation/nvme-id-ns.1 index 31b68240..5e04d73f 100644 --- a/Documentation/nvme-id-ns.1 +++ b/Documentation/nvme-id-ns.1 @@ -2,12 +2,12 @@ .\" Title: nvme-id-ns .\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] .\" Generator: DocBook XSL Stylesheets v1.76.1 -.\" Date: 02/26/2016 +.\" Date: 03/18/2016 .\" Manual: NVMe Manual .\" Source: NVMe .\" Language: English .\" -.TH "NVME\-ID\-NS" "1" "02/26/2016" "NVMe" "NVMe Manual" +.TH "NVME\-ID\-NS" "1" "03/18/2016" "NVMe" "NVMe Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- @@ -33,7 +33,7 @@ nvme-id-ns \- Send NVMe Identify Namespace, return result and structure .sp .nf \fInvme id\-ns\fR [\-v | \-\-vendor\-specific] [\-b | \-\-raw\-binary] - [\-\-namespace\-id= | \-n ] + [\-\-namespace\-id= | \-n ] [\-f | \-\-force] .fi .SH "DESCRIPTION" .sp @@ -49,6 +49,11 @@ On success, the structure may be returned in one of several ways depending on th Retrieve the identify namespace structure for the given nsid\&. This is required for the character devices, or overrides the block nsid if given\&. .RE .PP +\-f, \-\-force +.RS 4 +Request controller return the indentify namespace structure even if the namespace is not attached to the controller\&. This is valid only for controllers at or newer than revision 1\&.2\&. Controllers at revision lower than this may interpret the command incorrectly\&. +.RE +.PP \-b, \-\-raw\-binary .RS 4 Print the raw buffer to stdout\&. Structure is not parsed by program\&. This overrides the vendor specific and human readable options\&. diff --git a/Documentation/nvme-id-ns.html b/Documentation/nvme-id-ns.html index 150514ed..7215fe43 100644 --- a/Documentation/nvme-id-ns.html +++ b/Documentation/nvme-id-ns.html @@ -435,7 +435,7 @@ thead, p.table.header { p.table { margin-top: 0; } -/* Because the table frame attribute is overridden by CSS in most browsers. */ +/* Because the table frame attribute is overriden by CSS in most browsers. */ div.tableblock > table[frame="void"] { border-style: none; } @@ -753,7 +753,7 @@ nvme-id-ns(1) Manual Page
nvme id-ns <device> [-v | --vendor-specific] [-b | --raw-binary]
-                    [--namespace-id=<nsid> | -n <nsid>]
+ [--namespace-id=<nsid> | -n <nsid>] [-f | --force]
@@ -792,6 +792,20 @@ raw buffer may be printed to stdout.

+-f +
+
+--force +
+
+

+ Request controller return the indentify namespace structure even + if the namespace is not attached to the controller. This is valid + only for controllers at or newer than revision 1.2. Controllers + at revision lower than this may interpret the command incorrectly. +

+
+
-b
@@ -929,7 +943,7 @@ int main(int argc, char **argv)

diff --git a/Documentation/nvme-id-ns.txt b/Documentation/nvme-id-ns.txt index 912676af..0802ef27 100644 --- a/Documentation/nvme-id-ns.txt +++ b/Documentation/nvme-id-ns.txt @@ -9,7 +9,7 @@ SYNOPSIS -------- [verse] 'nvme id-ns' [-v | --vendor-specific] [-b | --raw-binary] - [--namespace-id= | -n ] + [--namespace-id= | -n ] [-f | --force] DESCRIPTION ----------- @@ -35,6 +35,13 @@ OPTIONS is required for the character devices, or overrides the block nsid if given. +-f:: +--force:: + Request controller return the indentify namespace structure even + if the namespace is not attached to the controller. This is valid + only for controllers at or newer than revision 1.2. Controllers + at revision lower than this may interpret the command incorrectly. + -b:: --raw-binary:: Print the raw buffer to stdout. Structure is not parsed by diff --git a/linux/nvme.h b/linux/nvme.h index f48c0f08..865e3e3b 100644 --- a/linux/nvme.h +++ b/linux/nvme.h @@ -120,6 +120,16 @@ enum { NVME_CTRL_VWC_PRESENT = 1 << 0, }; +enum { + NVME_ID_CNS_NS = 0x00, + NVME_ID_CNS_CTRL = 0x01, + NVME_ID_CNS_NS_ACTIVE_LIST = 0x02, + NVME_ID_CNS_NS_PRESENT_LIST = 0x10, + NVME_ID_CNS_NS_PRESENT = 0x11, + NVME_ID_CNS_CTRL_NS_LIST = 0x12, + NVME_ID_CNS_CTRL_LIST = 0x13, +}; + struct nvme_lbaf { __le16 ms; __u8 ds; diff --git a/nvme-ioctl.c b/nvme-ioctl.c index 6acfb85a..d807a1e3 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -335,17 +335,23 @@ int nvme_identify_ctrl(int fd, void *data) int nvme_identify_ns(int fd, __u32 nsid, bool present, void *data) { - return nvme_identify(fd, nsid, present ? 0x11 : 0, data); + int cns = present ? NVME_ID_CNS_NS_PRESENT : NVME_ID_CNS_NS; + + return nvme_identify(fd, nsid, cns, data); } int nvme_identify_ns_list(int fd, __u32 nsid, bool all, void *data) { - return nvme_identify(fd, nsid, all ? 0x10 : 0x2, data); + int cns = all ? NVME_ID_CNS_NS_ACTIVE_LIST : NVME_ID_CNS_NS_PRESENT_LIST; + + return nvme_identify(fd, nsid, cns, data); } int nvme_identify_ctrl_list(int fd, __u32 nsid, __u16 cntid, void *data) { - return nvme_identify(fd, nsid, (cntid << 16) | (nsid ? 0x13 : 0x12), data); + int cns = nsid ? NVME_ID_CNS_CTRL_NS_LIST : NVME_ID_CNS_CTRL_LIST; + + return nvme_identify(fd, nsid, (cntid << 16) | cns, data); } int nvme_get_log(int fd, __u32 nsid, __u32 cdw10, __u32 data_len, void *data) @@ -369,18 +375,18 @@ int nvme_log(int fd, __u32 nsid, __u8 log_id, __u32 data_len, void *data) int nvme_fw_log(int fd, struct nvme_firmware_log_page *fw_log) { - return nvme_log(fd, 0xffffffff, 3, sizeof(*fw_log), fw_log); + return nvme_log(fd, 0xffffffff, NVME_LOG_FW_SLOT, sizeof(*fw_log), fw_log); } int nvme_error_log(int fd, __u32 nsid, int entries, struct nvme_error_log_page *err_log) { - return nvme_log(fd, nsid, 1, entries * sizeof(*err_log), err_log); + return nvme_log(fd, nsid, NVME_LOG_ERROR, entries * sizeof(*err_log), err_log); } int nvme_smart_log(int fd, __u32 nsid, struct nvme_smart_log *smart_log) { - return nvme_log(fd, nsid, 2, sizeof(*smart_log), smart_log); + return nvme_log(fd, nsid, NVME_LOG_SMART, sizeof(*smart_log), smart_log); } int nvme_intel_smart_log(int fd, __u32 nsid, diff --git a/nvme.c b/nvme.c index 1230d627..ecfd65af 100644 --- a/nvme.c +++ b/nvme.c @@ -886,6 +886,7 @@ static int id_ns(int argc, char **argv) "given device, returns properties of the specified namespace "\ "in either human-readable or binary format. Can also return "\ "binary vendor-specific namespace attributes."; + const char *force = "Return this namespace, even if not attaced (1.2 devices only)"; const char *vendor_specific = "dump binary vendor infos"; const char *raw_binary = "show infos in binary format"; const char *human_readable = "show infos in readable format"; @@ -899,6 +900,7 @@ static int id_ns(int argc, char **argv) __u8 vendor_specific; __u8 raw_binary; __u8 human_readable; + __u8 force; }; struct config cfg = { @@ -907,6 +909,7 @@ static int id_ns(int argc, char **argv) const struct argconfig_commandline_options command_line_options[] = { {"namespace-id", 'n', "NUM", CFG_POSITIVE, &cfg.namespace_id, required_argument, namespace_id}, + {"force", 'f', "FLAG", CFG_NONE, &cfg.force, no_argument, force}, {"vendor-specific", 'v', "FLAG", CFG_NONE, &cfg.vendor_specific, no_argument, vendor_specific}, {"raw-binary", 'b', "FLAG", CFG_NONE, &cfg.raw_binary, no_argument, raw_binary}, {"human-readable", 'H', "FLAG", CFG_NONE, &cfg.human_readable, no_argument, human_readable}, @@ -920,7 +923,6 @@ static int id_ns(int argc, char **argv) if (cfg.human_readable) flags |= HUMAN; - if (!cfg.namespace_id) { cfg.namespace_id = nvme_get_nsid(fd); if (cfg.namespace_id <= 0) { @@ -928,7 +930,8 @@ static int id_ns(int argc, char **argv) exit(errno); } } - err = nvme_identify_ns(fd, cfg.namespace_id, 0, &ns); + + err = nvme_identify_ns(fd, cfg.namespace_id, cfg.force, &ns); if (!err) { if (cfg.raw_binary) d_raw((unsigned char *)&ns, sizeof(ns));