diff mbox series

[v8,4/9] rpcctl: Add a command for printing rpc client information

Message ID 20220215192150.53811-5-Anna.Schumaker@Netapp.com (mailing list archive)
State New, archived
Headers show
Series Add a tool for using the new sysfs files | expand

Commit Message

Schumaker, Anna Feb. 15, 2022, 7:21 p.m. UTC
From: Anna Schumaker <Anna.Schumaker@Netapp.com>

It's mostly the same information as with xprt-switches, except with
rpc-client id prepended to the first line.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
v8: Better exception handling if an RpcClient isn't found
---
 tools/rpcctl/rpcctl.py | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/rpcctl/rpcctl.py b/tools/rpcctl/rpcctl.py
index 6b9627318949..2e710b5627f0 100755
--- a/tools/rpcctl/rpcctl.py
+++ b/tools/rpcctl/rpcctl.py
@@ -99,17 +99,18 @@  class Xprt:
 
 
 class XprtSwitch:
-    def __init__(self, path):
+    def __init__(self, path, sep=":"):
         self.path = path
         self.name = path.stem
         self.info = read_info_file(path / "xprt_switch_info")
         self.xprts = sorted([ Xprt(p) for p in self.path.iterdir() if p.is_dir() ])
+        self.sep = sep
 
     def __lt__(self, rhs):
         return self.name < rhs.name
 
     def __str__(self):
-        switch =  f"{self.name}: " \
+        switch =  f"{self.name}{self.sep} " \
                   f"xprts {self.info['num_xprts']}, " \
                   f"active {self.info['num_active']}, " \
                   f"queue {self.info['queue_len']}"
@@ -137,6 +138,39 @@  class XprtSwitch:
             print(switch)
 
 
+class RpcClient:
+    def __init__(self, path):
+        self.path = path
+        self.name = path.stem
+        self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",")
+
+    def __lt__(self, rhs):
+        return self.name < rhs.name
+
+    def __str__(self):
+        return f"{self.name}: {self.switch}"
+
+    def add_command(subparser):
+        parser = subparser.add_parser("client", help="Commands for rpc clients")
+        parser.set_defaults(func=RpcClient.show, client=None)
+        subparser = parser.add_subparsers()
+
+        show = subparser.add_parser("show", help="Show rpc clients")
+        show.add_argument("client", metavar="CLIENT", nargs='?',
+                          help="Name of a specific rpc client to show")
+        parser.set_defaults(func=RpcClient.show)
+
+    def get_by_name(name):
+        rpc_clients = sunrpc / "rpc-clients"
+        if name:
+            return [ RpcClient(rpc_clients / name) ]
+        return [ RpcClient(f) for f in sorted(rpc_clients.iterdir()) ]
+
+    def show(args):
+        for client in RpcClient.get_by_name(args.client):
+            print(client)
+
+
 parser = argparse.ArgumentParser()
 
 def show_small_help(args):
@@ -145,6 +179,7 @@  def show_small_help(args):
 parser.set_defaults(func=show_small_help)
 
 subparser = parser.add_subparsers(title="commands")
+RpcClient.add_command(subparser)
 XprtSwitch.add_command(subparser)
 Xprt.add_command(subparser)