Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: nitzanc@mellanox.com (Nitzan Carmi)
Subject: [PATCH 4/3 rfc nvmetcli] nvmetcli: expose nvmet port status and state
Date: Tue, 27 Mar 2018 11:34:00 +0300	[thread overview]
Message-ID: <1522139640-1961-1-git-send-email-nitzanc@mellanox.com> (raw)
In-Reply-To: <20180322190303.10951-5-sagi@grimberg.me>

Hi Sagi,

Please see my suggestion below, for a minor improvement to your
nvmetcli patch, which makes the built-in "status" UI function
available for the port (like in namespaces).

Besides, I think the terminology of "status"/"state" might be confusing.
Don't you think it is better to stay with "trstate"/"tractive" namings?

Nitzan.

---
 nvmet/nvme.py |  5 +++++
 nvmetcli      | 15 +++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/nvmet/nvme.py b/nvmet/nvme.py
index c245a42..dc28b31 100644
--- a/nvmet/nvme.py
+++ b/nvmet/nvme.py
@@ -625,6 +625,11 @@ class Port(CFSNode):
     subsystems = property(_list_subsystems,
                           doc="Get the list of Subsystem for this Port.")
 
+    def _is_active(self):
+        return bool(int(self.get_attr("addr", "tractive")))
+
+    active = property(_is_active, doc="Physical state of the port")
+
     def add_subsystem(self, nqn):
         '''
         Enable access to the Subsystem identified by I{nqn} through this Port.
diff --git a/nvmetcli b/nvmetcli
index 1a7cf67..46e34b2 100755
--- a/nvmetcli
+++ b/nvmetcli
@@ -380,6 +380,11 @@ class UIPortNode(UINode):
         UIPortSubsystemsNode(self)
         UIReferralsNode(self)
 
+    def status(self):
+        status = "enabled" if self.cfnode.subsystems else "disabled"
+        state = "up" if self.cfnode.active else "down"
+        return "status=%s, state=%s" % (status, state)
+
     def summary(self):
         info = []
         info.append("trtype=" + self.cfnode.get_attr("addr", "trtype"))
@@ -387,14 +392,8 @@ class UIPortNode(UINode):
         trsvcid = self.cfnode.get_attr("addr", "trsvcid")
         if trsvcid != "none":
             info.append("trsvcid=%s" % trsvcid)
-        enabled = not (not self.cfnode.subsystems and not list(self.cfnode.referrals))
-        info.append("status=" + ("enabled" if enabled else "disabled"))
-        if not enabled:
-            ret = 0
-        else:
-            active = not (not int(self.cfnode.get_attr("addr", "tractive")))
-            info.append("state=" + ("up" if active else "down"))
-            ret = True if active else False
+        info.append(self.status())
+        ret = self.cfnode.active
         return (", ".join(info), ret)
 
 class UIPortSubsystemsNode(UINode):
-- 
1.8.3.1

  reply	other threads:[~2018-03-27  8:34 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-22 19:02 [PATCH rfc 0/3] nvmet-rdma automatic port re-activation Sagi Grimberg
2018-03-22 19:03 ` [PATCH rfc 1/3] nvmet-rdma: automatic listening " Sagi Grimberg
2018-03-25  8:25   ` Max Gurtovoy
2018-03-26  7:01   ` Max Gurtovoy
2018-04-04 13:06     ` Sagi Grimberg
2018-03-22 19:03 ` [PATCH rfc 2/3] nvmet: Add fabrics ops to port Sagi Grimberg
2018-03-22 19:03 ` [PATCH rfc 3/3] nvmet: Add port transport active flag Sagi Grimberg
2018-03-26  7:52   ` Max Gurtovoy
2018-04-04 13:08     ` Sagi Grimberg
2018-03-22 19:03 ` [PATCH 4/3 rfc nvmetcli] nvmetcli: expose nvmet port status and state Sagi Grimberg
2018-03-27  8:34   ` Nitzan Carmi [this message]
2018-04-11 16:17 ` [PATCH rfc 0/3] nvmet-rdma automatic port re-activation Max Gurtovoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1522139640-1961-1-git-send-email-nitzanc@mellanox.com \
    --to=nitzanc@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox