[PATCH v2 3/9] nfs-sysfs.py: Add a command for printing individual xprts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Anna Schumaker <Anna.Schumaker@xxxxxxxxxx>

This shows more detailed information than what is presented with xprt
switches. I take the chance to add a main-export indicator to the
small_str() used when printing out xprt-switches.

Signed-off-by: Anna Schumaker <Anna.Schumaker@xxxxxxxxxx>
---
 tools/nfs-sysfs/nfs-sysfs.py |  2 ++
 tools/nfs-sysfs/xprt.py      | 38 +++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/tools/nfs-sysfs/nfs-sysfs.py b/tools/nfs-sysfs/nfs-sysfs.py
index 90efcbed7ac8..dfad6ac08fa0 100755
--- a/tools/nfs-sysfs/nfs-sysfs.py
+++ b/tools/nfs-sysfs/nfs-sysfs.py
@@ -11,8 +11,10 @@ parser.set_defaults(func=show_small_help)
 
 
 import switch
+import xprt
 subparser = parser.add_subparsers(title="commands")
 switch.add_command(subparser)
+xprt.add_command(subparser)
 
 
 args = parser.parse_args()
diff --git a/tools/nfs-sysfs/xprt.py b/tools/nfs-sysfs/xprt.py
index d37537771c1d..fbdd9bfc9375 100644
--- a/tools/nfs-sysfs/xprt.py
+++ b/tools/nfs-sysfs/xprt.py
@@ -1,12 +1,48 @@
+import sysfs
+
 class Xprt:
     def __init__(self, path):
         self.path = path
         self.id = int(str(path).rsplit("-", 2)[1])
         self.type = str(path).rsplit("-", 2)[2]
         self.dstaddr = open(path / "dstaddr", 'r').readline().strip()
+        self.srcaddr = open(path / "srcaddr", 'r').readline().strip()
+
+        with open(path / "xprt_state") as f:
+            self.state = ','.join(f.readline().split()[1:])
+        self.__dict__.update(sysfs.read_info_file(path / "xprt_info"))
 
     def __lt__(self, rhs):
         return self.id < rhs.id
 
+    def __str__(self):
+        state = self.state
+        if self.main_xprt:
+            state = "MAIN," + self.state
+
+        line = "xprt %s: %s, %s, port %s, state <%s>" % \
+                (self.id, self.type, self.dstaddr, self.dst_port, state)
+        line += "\n	Source: %s, port %s, Requests: %s" % \
+                (self.srcaddr, self.src_port, self.num_reqs)
+        line += "\n	Congestion: cur %s, win %s, Slots: min %s, max %s" % \
+                (self.cur_cong, self.cong_win, self.min_num_slots, self.max_num_slots)
+        line += "\n	Queues: binding %s, sending %s, pending %s, backlog %s, tasks %s" % \
+                (self.binding_q_len, self.sending_q_len, self.pending_q_len, self.backlog_q_len, self.tasks_queuelen)
+        return line
+
     def small_str(self):
-        return "xprt %s: %s, %s" % (self.id, self.type, self.dstaddr)
+        return "xprt %s: %s, %s%s" % (self.id, self.type, self.dstaddr,
+                                     f" [main]" if self.main_xprt else "" )
+
+
+def list_xprts(args):
+    xprts = [ Xprt(f) for f in (sysfs.SUNRPC / "xprt-switches").glob("**/xprt-*") ]
+    xprts.sort()
+    for xprt in xprts:
+        if args.id == None or xprt.id == args.id[0]:
+            print(xprt)
+
+def add_command(subparser):
+    parser = subparser.add_parser("xprt", help="Commands for individual xprts")
+    parser.add_argument("--id", metavar="ID", nargs=1, type=int, help="Id of a specific xprt to show")
+    parser.set_defaults(func=list_xprts)
-- 
2.32.0




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux