]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
NVMe: Add support for identify namespace list
authorKeith Busch <keith.busch@intel.com>
Mon, 1 Dec 2014 21:15:16 +0000 (14:15 -0700)
committerKeith Busch <keith.busch@intel.com>
Mon, 1 Dec 2014 21:15:16 +0000 (14:15 -0700)
Signed-off-by: Keith Busch <keith.busch@intel.com>
Documentation/nvme-list-ns.txt [new file with mode: 0644]
nvme.c

diff --git a/Documentation/nvme-list-ns.txt b/Documentation/nvme-list-ns.txt
new file mode 100644 (file)
index 0000000..13a12d6
--- /dev/null
@@ -0,0 +1,38 @@
+nvme-id-ns(1)
+=============
+
+NAME
+----
+nvme-list-ns - Send NVMe Identify List Namespaces, return result and structure
+
+SYNOPSIS
+--------
+[verse]
+'nvme list-ns' <device> [--namespace-id=<nsid> | -n <nsid>]
+
+DESCRIPTION
+-----------
+For the NVMe device given, sends an identify command for namespace list
+and provides the result and returned structure.
+
+The <device> parameter is mandatory and may be either the NVMe character
+device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).
+If the starting namespace in the list always begins with 0 unless the
+`'--namespace-id'` option is given to override.
+
+On success, the namespace array is printed for each index and nsid for
+a valid nsid.
+
+OPTIONS
+-------
+-n <nsid>::
+--namespace-id=<nsid>::
+       Retrieve the identify list structure starting with the given nsid.
+
+EXAMPLES
+--------
+No examples yet.
+
+NVME
+----
+Part of the nvme-user suite
diff --git a/nvme.c b/nvme.c
index f92856e211e27b2b0c1ea060872fb4ff0cbdc7e5..df0c689f7fc29663b1a231f51bf23c3f8226acc6 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -46,6 +46,7 @@ static const char *devicename;
 #define COMMAND_LIST \
        ENTRY(ID_CTRL, "id-ctrl", "Send NVMe Identify Controller", id_ctrl) \
        ENTRY(ID_NS, "id-ns", "Send NVMe Identify Namespace, disaply structure", id_ns) \
+       ENTRY(LIST_NS, "list-ns", "Send NVMe Identify List, disaply structure", list_ns) \
        ENTRY(GET_NS_ID, "get-ns-id", "Retrieve the namespace ID of opend block device", get_ns_id) \
        ENTRY(GET_LOG, "get-log", "Generic NVMe get log, returns log in raw format", get_log) \
        ENTRY(GET_FW_LOG, "fw-log", "Retrieve FW Log, show it", get_fw_log) \
@@ -696,6 +697,39 @@ static int get_log(int argc, char **argv)
        }
 }
 
+static int list_ns(int argc, char **argv)
+{
+       int opt, err, i, long_index = 0;
+       unsigned int nsid = 0;
+       static struct option opts[] = {
+               {"namespace-id", required_argument, 0, 'n'},
+               {0, 0, 0, 0 }
+       };
+       __u32 ns_list[1024];
+
+       while ((opt = getopt_long(argc, (char **)argv, "n:", opts,
+                                                       &long_index)) != -1) {
+               switch (opt) {
+               case 'n':
+                       get_int(optarg, &nsid);
+                       break;
+               default:
+                       return EINVAL;
+               }
+       }
+       get_dev(optind, argc, argv);
+       err = identify(nsid, ns_list, 2);
+       if (!err) {
+               for (i = 0; i < 1024; i++)
+                       if (ns_list[i])
+                               printf("[%4u]:%#x\n", i, ns_list[i]);
+       }
+       else if (err > 0)
+               fprintf(stderr, "NVMe Status: %s NSID:%d\n",
+                               nvme_status_to_string(err), nsid);
+       return err;
+}
+
 static int id_ctrl(int argc, char **argv)
 {
        int opt, err, raw = 0, vs = 0, long_index = 0;
@@ -1524,7 +1558,7 @@ static int resv_report(int argc, char **argv)
                        printf("NVME Reservation Report success\n");
                        show_nvme_resv_report(status);
                } else
-                       d_raw(status, numd << 2);
+                       d_raw((unsigned char *)status, numd << 2);
        }
        return 0;
 }