All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 nvmetcli] nvmetcli: expose nvmet port status and state
@ 2018-04-12 13:32 Sagi Grimberg
  2018-04-13 16:53 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Sagi Grimberg @ 2018-04-12 13:32 UTC (permalink / raw)


status reflects if any subsystems are bound and can
accept existing connections. state reflects the
physical state of the port. Also colorize UI if
port state is down.

Signed-off-by: Sagi Grimberg <sagi at grimberg.me>
---
 nvmet/nvme.py | 13 +++++++++++++
 nvmetcli      |  9 ++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/nvmet/nvme.py b/nvmet/nvme.py
index c245a4240dd9..f5d0555d2acd 100644
--- a/nvmet/nvme.py
+++ b/nvmet/nvme.py
@@ -618,6 +618,19 @@ class Port(CFSNode):
 
     portid = property(_get_portid, doc="Get the Port ID as an int.")
 
+    def _get_state(self):
+        self._check_self()
+        _state = None
+        path = "%s/trstate" % self.path
+        if not os.path.isfile(path):
+            return None
+
+        with open(path, 'r') as file_fd:
+            _state = file_fd.read().strip()
+        return _state
+
+    state = property(_get_state, doc="Get the Port state.")
+
     def _list_subsystems(self):
         return [os.path.basename(name)
                 for name in os.listdir("%s/subsystems/" % self._path)]
diff --git a/nvmetcli b/nvmetcli
index 6b102a235450..5d5aabc89b1c 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -388,7 +388,14 @@ class UIPortNode(UINode):
         if trsvcid != "none":
             info.append("trsvcid=%s" % trsvcid)
         enabled = not (not self.cfnode.subsystems and not list(self.cfnode.referrals))
-        return (", ".join(info), True if enabled else 0)
+        info.append("status=" + ("enabled" if enabled else "disabled"))
+        if not enabled:
+            ret = 0
+        else:
+            trstate = self.cfnode.state
+            info.append("state=" + trstate)
+            ret = True if trstate == "up" else False
+        return (", ".join(info), ret)
 
 class UIPortSubsystemsNode(UINode):
     def __init__(self, parent):
-- 
2.14.1

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

* [PATCH v2 nvmetcli] nvmetcli: expose nvmet port status and state
  2018-04-12 13:32 [PATCH v2 nvmetcli] nvmetcli: expose nvmet port status and state Sagi Grimberg
@ 2018-04-13 16:53 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2018-04-13 16:53 UTC (permalink / raw)


Thanks,

applied.

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

end of thread, other threads:[~2018-04-13 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-12 13:32 [PATCH v2 nvmetcli] nvmetcli: expose nvmet port status and state Sagi Grimberg
2018-04-13 16:53 ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.