Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration
@ 2017-12-03  8:25 Sagi Grimberg
  2017-12-03  8:25 ` [PATCH v2 2/2] nvmetcli: decorate namespace, subsystem and port UI Sagi Grimberg
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Sagi Grimberg @ 2017-12-03  8:25 UTC (permalink / raw)


for running: nvmetcli ls

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
Changes from v1:
- Added a man entry for nvmetcli ls cmdline operation

 Documentation/nvmetcli.txt |  1 +
 nvmetcli                   | 10 +++++++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/nvmetcli.txt b/Documentation/nvmetcli.txt
index 1f381cc7ad2e..05a0344dfd91 100644
--- a/Documentation/nvmetcli.txt
+++ b/Documentation/nvmetcli.txt
@@ -105,6 +105,7 @@ and not enter the interactive configuration shell.
                             Without specifying the filename this will use
                             */etc/nvmet/config.json*.
 | clear                   | Clears a current NVMe Target configuration.
+| ls                      | Dumps the current NVMe Target configuration.
 |==================
 
 EXAMPLES
diff --git a/nvmetcli b/nvmetcli
index 4fbc12ec430f..0c590c9638f1 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -549,6 +549,7 @@ def usage():
     print("syntax: %s save [file_to_save_to]" % sys.argv[0])
     print("        %s restore [file_to_restore_from]" % sys.argv[0])
     print("        %s clear" % sys.argv[0])
+    print("        %s ls" % sys.argv[0])
     sys.exit(-1)
 
 
@@ -572,7 +573,14 @@ def clear(unused):
     nvme.Root().clear_existing()
 
 
-funcs = dict(save=save, restore=restore, clear=clear)
+def ls(unused):
+    shell = configshell.shell.ConfigShell('~/.nvmetcli')
+    UIRootNode(shell)
+    shell.run_cmdline("ls")
+    sys.exit(0)
+
+
+funcs = dict(save=save, restore=restore, clear=clear, ls=ls)
 
 
 def main():
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] nvmetcli: decorate namespace, subsystem and port UI
  2017-12-03  8:25 [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration Sagi Grimberg
@ 2017-12-03  8:25 ` Sagi Grimberg
  2017-12-04  8:33   ` Johannes Thumshirn
  2017-12-04  8:32 ` [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration Johannes Thumshirn
  2017-12-04 20:13 ` Christoph Hellwig
  2 siblings, 1 reply; 5+ messages in thread
From: Sagi Grimberg @ 2017-12-03  8:25 UTC (permalink / raw)


Display some info on the on the UI node.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
Changes from v1:
- Fixed nguid_set detection to refer to hex digits

 nvmetcli | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/nvmetcli b/nvmetcli
index 0c590c9638f1..ead6429d5be5 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -24,7 +24,11 @@ import os
 import sys
 import configshell_fb as configshell
 import nvmet as nvme
+from string import hexdigits
+import uuid
 
+def ngiud_set(nguid):
+    return any(c in hexdigits and c != '0' for c in nguid)
 
 class UINode(configshell.node.ConfigNode):
     def __init__(self, name, parent=None, cfnode=None, shell=None):
@@ -160,6 +164,13 @@ class UISubsystemNode(UINode):
         UINamespacesNode(self)
         UIAllowedHostsNode(self)
 
+    def summary(self):
+        info = []
+        info.append("version=" + self.cfnode.get_attr("attr","version"))
+        info.append("allow_any=" + self.cfnode.get_attr("attr","allow_any_host"))
+        info.append("serial=" + self.cfnode.get_attr("attr","serial"))
+        return (", ".join(info), True)
+
 
 class UINamespacesNode(UINode):
     def __init__(self, parent):
@@ -247,6 +258,19 @@ class UINamespaceNode(UINode):
                 raise configshell.ExecutionError(
                     "The Namespace could not be disabled.")
 
+    def summary(self):
+        info = []
+        info.append("path=" + self.cfnode.get_attr("device", "path"))
+        ns_uuid = self.cfnode.get_attr("device", "uuid")
+        if uuid.UUID(ns_uuid).int != 0:
+            info.append("uuid=" + str(ns_uuid))
+        ns_nguid = self.cfnode.get_attr("device", "nguid")
+        if ngiud_set(ns_nguid):
+            info.append("nguid=" + ns_nguid)
+        info.append("enabled" if self.cfnode.get_enable() else "disabled")
+        ns_enabled = self.cfnode.get_enable()
+        return (", ".join(info), True if ns_enabled == 1 else ns_enabled)
+
 
 class UIAllowedHostsNode(UINode):
     def __init__(self, parent):
@@ -356,6 +380,12 @@ class UIPortNode(UINode):
         UIPortSubsystemsNode(self)
         UIReferralsNode(self)
 
+    def summary(self):
+        info = []
+        info.append("traddr=" + self.cfnode.get_attr("addr", "traddr"))
+        info.append("trsvcid=" + self.cfnode.get_attr("addr", "trsvcid"))
+        info.append("trtype=" + self.cfnode.get_attr("addr", "trtype"))
+        return (", ".join(info), True)
 
 class UIPortSubsystemsNode(UINode):
     def __init__(self, parent):
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration
  2017-12-03  8:25 [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration Sagi Grimberg
  2017-12-03  8:25 ` [PATCH v2 2/2] nvmetcli: decorate namespace, subsystem and port UI Sagi Grimberg
@ 2017-12-04  8:32 ` Johannes Thumshirn
  2017-12-04 20:13 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2017-12-04  8:32 UTC (permalink / raw)


Sagi Grimberg <sagi at grimberg.me> writes:
> for running: nvmetcli ls

Nice one,
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de>
-- 
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] nvmetcli: decorate namespace, subsystem and port UI
  2017-12-03  8:25 ` [PATCH v2 2/2] nvmetcli: decorate namespace, subsystem and port UI Sagi Grimberg
@ 2017-12-04  8:33   ` Johannes Thumshirn
  0 siblings, 0 replies; 5+ messages in thread
From: Johannes Thumshirn @ 2017-12-04  8:33 UTC (permalink / raw)


Looks good,
Reviewed-by: Johannes Thumshirn <jthumshirn at suse.de>
-- 
Johannes Thumshirn                                          Storage
jthumshirn at suse.de                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 N?rnberg
GF: Felix Imend?rffer, Jane Smithard, Graham Norton
HRB 21284 (AG N?rnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration
  2017-12-03  8:25 [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration Sagi Grimberg
  2017-12-03  8:25 ` [PATCH v2 2/2] nvmetcli: decorate namespace, subsystem and port UI Sagi Grimberg
  2017-12-04  8:32 ` [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration Johannes Thumshirn
@ 2017-12-04 20:13 ` Christoph Hellwig
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2017-12-04 20:13 UTC (permalink / raw)


Thanks Sagi,

I've applied both patches.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-04 20:13 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-03  8:25 [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration Sagi Grimberg
2017-12-03  8:25 ` [PATCH v2 2/2] nvmetcli: decorate namespace, subsystem and port UI Sagi Grimberg
2017-12-04  8:33   ` Johannes Thumshirn
2017-12-04  8:32 ` [PATCH v2 1/2] nvmetcli: Expose ls to dump UI configuration Johannes Thumshirn
2017-12-04 20:13 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox