]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Use enum instead of hard-coded values
authorKeith Busch <keith.busch@intel.com>
Fri, 18 Mar 2016 17:57:02 +0000 (11:57 -0600)
committerKeith Busch <keith.busch@intel.com>
Tue, 29 Mar 2016 18:25:51 +0000 (12:25 -0600)
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 <keith.busch@intel.com>
Documentation/nvme-id-ns.1
Documentation/nvme-id-ns.html
Documentation/nvme-id-ns.txt
linux/nvme.h
nvme-ioctl.c
nvme.c

index 31b68240ea7ff03da146f840dd722da7709b7eb6..5e04d73f2b4431f4bb4d8437d3fc0de0c506379c 100644 (file)
@@ -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 <http://docbook.sf.net/>
-.\"      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 <device> [\-v | \-\-vendor\-specific] [\-b | \-\-raw\-binary]
-                    [\-\-namespace\-id=<nsid> | \-n <nsid>]
+                    [\-\-namespace\-id=<nsid> | \-n <nsid>] [\-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\&.
index 150514ed5846f937c51738ddf5dbac914860b722..7215fe4314aceeee4eb5be2716342edf6dc17c93 100644 (file)
@@ -435,7 +435,7 @@ thead, p.table.header {
 p.table {\r
   margin-top: 0;\r
 }\r
-/* Because the table frame attribute is overridden by CSS in most browsers. */\r
+/* Because the table frame attribute is overriden by CSS in most browsers. */\r
 div.tableblock > table[frame="void"] {\r
   border-style: none;\r
 }\r
@@ -753,7 +753,7 @@ nvme-id-ns(1) Manual Page
 <div class="sectionbody">\r
 <div class="verseblock">\r
 <pre class="content"><em>nvme id-ns</em> &lt;device&gt; [-v | --vendor-specific] [-b | --raw-binary]\r
-                    [--namespace-id=&lt;nsid&gt; | -n &lt;nsid&gt;]</pre>\r
+                    [--namespace-id=&lt;nsid&gt; | -n &lt;nsid&gt;] [-f | --force]</pre>\r
 <div class="attribution">\r
 </div></div>\r
 </div>\r
@@ -792,6 +792,20 @@ raw buffer may be printed to stdout.</p></div>
 </p>\r
 </dd>\r
 <dt class="hdlist1">\r
+-f\r
+</dt>\r
+<dt class="hdlist1">\r
+--force\r
+</dt>\r
+<dd>\r
+<p>\r
+        Request controller return the indentify namespace structure even\r
+        if the namespace is not attached to the controller. This is valid\r
+        only for controllers at or newer than revision 1.2. Controllers\r
+        at revision lower than this may interpret the command incorrectly.\r
+</p>\r
+</dd>\r
+<dt class="hdlist1">\r
 -b\r
 </dt>\r
 <dt class="hdlist1">\r
@@ -929,7 +943,7 @@ int main(int argc, char **argv)
 <div id="footnotes"><hr /></div>\r
 <div id="footer">\r
 <div id="footer-text">\r
-Last updated 2016-02-26 08:27:57 MST\r
+Last updated 2016-03-18 11:56:04 MDT\r
 </div>\r
 </div>\r
 </body>\r
index 912676af91c68fc12414acb999c7cefb72cbf581..0802ef27facf6fc8e896471f913cf76b3d080728 100644 (file)
@@ -9,7 +9,7 @@ SYNOPSIS
 --------
 [verse]
 'nvme id-ns' <device> [-v | --vendor-specific] [-b | --raw-binary]
-                   [--namespace-id=<nsid> | -n <nsid>]
+                   [--namespace-id=<nsid> | -n <nsid>] [-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
index f48c0f08f6eabded125e299c850df1740d4d98c8..865e3e3b0971c9423415d5435a324b0eb9f8a2fe 100644 (file)
@@ -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;
index 6acfb85a769894c715e5f80a4749297636320a07..d807a1e3ffb6d33c633b2c871b745250141f064a 100644 (file)
@@ -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 1230d627e730668838b3578ca401a6e175c896c9..ecfd65af2310c20830364f28ad7a83b0f4e9a0e4 100644 (file)
--- 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));