]> www.infradead.org Git - users/hch/nvmetcli.git/commitdiff
nvmetcli: expose nvmet port status and state
authorSagi Grimberg <sagi@grimberg.me>
Thu, 12 Apr 2018 13:32:33 +0000 (16:32 +0300)
committerChristoph Hellwig <hch@lst.de>
Fri, 13 Apr 2018 16:52:55 +0000 (18:52 +0200)
The status attribute reflects if any subsystems are bound and can accept
existing connections. The state attribute reflects the physical state of
the port.  Also colorize UI if port state is down.

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Christoph Hellwig <hch@lst.de>
nvmet/nvme.py
nvmetcli

index c245a4240dd956f52f775f103a7e298aa4b63a7c..f5d0555d2acdbde96b63ed476db8616b10279e14 100644 (file)
@@ -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)]
index 6b102a235450c41ce4a31521d5bede0618781d99..5d5aabc89b1c25103d887d49aec65a4ab8089f27 100755 (executable)
--- 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):