All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/6] Add a tool for using the new sysfs files
@ 2021-06-08 17:46 schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 1/6] nfs-sysfs: Add an nfs-sysfs.py tool schumaker.anna
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: schumaker.anna @ 2021-06-08 17:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Anna.Schumaker

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

These patches implement a tool that can be used to read and write the
sysfs files, with subcommands! They need Olga's most recent patches to
run.

The following subcommands are implemented:
  nfs-sysfs.py rpc-client
  nfs-sysfs.py xprt
  nfs-sysfs.py xprt set
  nfs-sysfs.py xprt-switch
  nfs-sysfs.py xprt-switch set

So you can print out information about every xprt-switch with:
	anna@client % ./nfs-sysfs.py xprt-switch
	switch 0: num_xprts 1, num_active 1, queue_len 0
		xprt 0: local, /var/run/gssproxy.sock
	switch 1: num_xprts 1, num_active 1, queue_len 0
		xprt 1: local, /var/run/rpcbind.sock
	switch 2: num_xprts 4, num_active 4, queue_len 0
		xprt 2: tcp, 192.168.111.188
		xprt 3: tcp, 192.168.111.188
		xprt 5: tcp, 192.168.111.188
		xprt 6: tcp, 192.168.111.188
	switch 3: num_xprts 1, num_active 1, queue_len 0
		xprt 7: tcp, 192.168.111.1
	switch 4: num_xprts 1, num_active 1, queue_len 0
		xprt 4: tcp, 192.168.111.188

And information about each xprt:
	anna@client % ./nfs-sysfs.py xprt
	xprt 0: local, /var/run/gssproxy.sock, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	xprt 1: local, /var/run/rpcbind.sock, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	xprt 2: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	xprt 3: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	xprt 4: tcp, 192.168.111.188, state <BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	xprt 5: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	xprt 6: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	xprt 7: tcp, 192.168.111.1, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0

You can use the `set` subcommand to change the dstaddr of individual xprts:
	anna@client % ./nfs-sysfs.py xprt --id 2
	xprt 2: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
	anna@client % sudo ./nfs-sysfs.py xprt set --id 2 --dstaddr server2.nowheycreamery.vm
	xprt 2: tcp, 192.168.111.186, state <CONNECTED,BOUND>, num_reqs 2
		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0

Or for changing the dstaddr of all xprts attached to a switch:
	anna@client % ./nfs-sysfs.py xprt-switch --id 2
	switch 2: num_xprts 4, num_active 4, queue_len 0
		xprt 2: tcp, 192.168.111.188
		xprt 3: tcp, 192.168.111.188
		xprt 5: tcp, 192.168.111.188
		xprt 6: tcp, 192.168.111.188
	anna@client % sudo ./nfs-sysfs.py xprt-switch set --id 2 --dstaddr server2.nowheycreamery.vm
	switch 2: num_xprts 4, num_active 4, queue_len 0
		xprt 2: tcp, 192.168.111.186
		xprt 3: tcp, 192.168.111.186
		xprt 5: tcp, 192.168.111.186
		xprt 6: tcp, 192.168.111.186


I'm sure this needs lots of polish before it's ready for inclusion,
along with needing a Makefile so it can be installed (I've just been
running it out of the nfs-utils/tools/nfs-sysfs/ directory). But it's
still a start, and I wanted to post it before going on New Baby Leave
Part 2 (June 12 - July 11).

What does everybody think?
Anna


Anna Schumaker (6):
  nfs-sysfs: Add an nfs-sysfs.py tool
  nfs-sysfs.py: Add a command for printing xprt switch information
  nfs-sysfs.py: Add a command for printing individual xprts
  nfs-sysfs.py: Add a command for printing rpc-client information
  nfs-sysfs.py: Add a command for changing xprt dstaddr
  nfs-sysfs.py: Add a command for changing xprt-switch dstaddrs

 tools/nfs-sysfs/client.py    | 27 ++++++++++++++
 tools/nfs-sysfs/nfs-sysfs.py | 23 ++++++++++++
 tools/nfs-sysfs/switch.py    | 51 +++++++++++++++++++++++++++
 tools/nfs-sysfs/sysfs.py     | 28 +++++++++++++++
 tools/nfs-sysfs/xprt.py      | 68 ++++++++++++++++++++++++++++++++++++
 5 files changed, 197 insertions(+)
 create mode 100644 tools/nfs-sysfs/client.py
 create mode 100755 tools/nfs-sysfs/nfs-sysfs.py
 create mode 100644 tools/nfs-sysfs/switch.py
 create mode 100644 tools/nfs-sysfs/sysfs.py
 create mode 100644 tools/nfs-sysfs/xprt.py

-- 
2.32.0


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

* [RFC PATCH 1/6] nfs-sysfs: Add an nfs-sysfs.py tool
  2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
@ 2021-06-08 17:46 ` schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 2/6] nfs-sysfs.py: Add a command for printing xprt switch information schumaker.anna
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: schumaker.anna @ 2021-06-08 17:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Anna.Schumaker

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

This will be used to print and manipulate the sunrpc sysfs directory
files. Running without arguments prints both usage information and the
location of the sunrpc sysfs directory.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 tools/nfs-sysfs/nfs-sysfs.py | 13 +++++++++++++
 tools/nfs-sysfs/sysfs.py     | 18 ++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100755 tools/nfs-sysfs/nfs-sysfs.py
 create mode 100644 tools/nfs-sysfs/sysfs.py

diff --git a/tools/nfs-sysfs/nfs-sysfs.py b/tools/nfs-sysfs/nfs-sysfs.py
new file mode 100755
index 000000000000..8ff59ea9e81b
--- /dev/null
+++ b/tools/nfs-sysfs/nfs-sysfs.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+import argparse
+import sysfs
+
+parser = argparse.ArgumentParser()
+
+def show_small_help(args):
+    parser.print_usage()
+    print("sunrpc dir:", sysfs.SUNRPC)
+parser.set_defaults(func=show_small_help)
+
+args = parser.parse_args()
+args.func(args)
diff --git a/tools/nfs-sysfs/sysfs.py b/tools/nfs-sysfs/sysfs.py
new file mode 100644
index 000000000000..0b358f57bb28
--- /dev/null
+++ b/tools/nfs-sysfs/sysfs.py
@@ -0,0 +1,18 @@
+import pathlib
+import sys
+
+MOUNT = None
+with open("/proc/mounts", 'r') as f:
+    for line in f:
+        if "sysfs" in line:
+            MOUNT = line.split()[1]
+            break
+
+if MOUNT == None:
+    print("ERROR: sysfs is not mounted")
+    sys.exit(1)
+
+SUNRPC = pathlib.Path(MOUNT) / "kernel" / "sunrpc"
+if not SUNRPC.is_dir():
+    print("ERROR: sysfs does not have sunrpc directory")
+    sys.exit(1)
-- 
2.32.0


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

* [RFC PATCH 2/6] nfs-sysfs.py: Add a command for printing xprt switch information
  2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 1/6] nfs-sysfs: Add an nfs-sysfs.py tool schumaker.anna
@ 2021-06-08 17:46 ` schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 3/6] nfs-sysfs.py: Add a command for printing individual xprts schumaker.anna
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: schumaker.anna @ 2021-06-08 17:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Anna.Schumaker

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

This combines the information found in xprt_switch_info with a subset of
the information found in each xprt subdirectory

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 tools/nfs-sysfs/nfs-sysfs.py |  6 ++++++
 tools/nfs-sysfs/switch.py    | 35 +++++++++++++++++++++++++++++++++++
 tools/nfs-sysfs/sysfs.py     | 10 ++++++++++
 tools/nfs-sysfs/xprt.py      | 12 ++++++++++++
 4 files changed, 63 insertions(+)
 create mode 100644 tools/nfs-sysfs/switch.py
 create mode 100644 tools/nfs-sysfs/xprt.py

diff --git a/tools/nfs-sysfs/nfs-sysfs.py b/tools/nfs-sysfs/nfs-sysfs.py
index 8ff59ea9e81b..90efcbed7ac8 100755
--- a/tools/nfs-sysfs/nfs-sysfs.py
+++ b/tools/nfs-sysfs/nfs-sysfs.py
@@ -9,5 +9,11 @@ def show_small_help(args):
     print("sunrpc dir:", sysfs.SUNRPC)
 parser.set_defaults(func=show_small_help)
 
+
+import switch
+subparser = parser.add_subparsers(title="commands")
+switch.add_command(subparser)
+
+
 args = parser.parse_args()
 args.func(args)
diff --git a/tools/nfs-sysfs/switch.py b/tools/nfs-sysfs/switch.py
new file mode 100644
index 000000000000..afb6963a0a1f
--- /dev/null
+++ b/tools/nfs-sysfs/switch.py
@@ -0,0 +1,35 @@
+import sysfs
+import xprt
+
+class XprtSwitch:
+    def __init__(self, path):
+        self.path = path
+        self.id = int(str(path).rsplit("-", 1)[1])
+
+        self.xprts = [ xprt.Xprt(p) for p in self.path.iterdir() if p.is_dir() ]
+        self.xprts.sort()
+
+        self.__dict__.update(sysfs.read_info_file(path / "xprt_switch_info"))
+
+    def __lt__(self, rhs):
+        return self.path < rhs.path
+
+    def __str__(self):
+        line = "switch %s: num_xprts %s, num_active %s, queue_len %s" % \
+                (self.id, self.num_xprts, self.num_active, self.queue_len)
+        for x in self.xprts:
+            line += "\n	%s" % x.small_str()
+        return line
+
+
+def list_xprt_switches(args):
+    switches = [ XprtSwitch(f) for f in (sysfs.SUNRPC / "xprt-switches").iterdir() ]
+    switches.sort()
+    for xs in switches:
+        if args.id == None or xs.id == args.id[0]:
+            print(xs)
+
+def add_command(subparser):
+    parser = subparser.add_parser("xprt-switch", help="Commands for xprt switches")
+    parser.add_argument("--id", metavar="ID", nargs=1, type=int, help="Id of a specific xprt-switch to show")
+    parser.set_defaults(func=list_xprt_switches)
diff --git a/tools/nfs-sysfs/sysfs.py b/tools/nfs-sysfs/sysfs.py
index 0b358f57bb28..32dcf74438de 100644
--- a/tools/nfs-sysfs/sysfs.py
+++ b/tools/nfs-sysfs/sysfs.py
@@ -16,3 +16,13 @@ SUNRPC = pathlib.Path(MOUNT) / "kernel" / "sunrpc"
 if not SUNRPC.is_dir():
     print("ERROR: sysfs does not have sunrpc directory")
     sys.exit(1)
+
+
+def read_info_file(path):
+    res = dict()
+    with open(path) as info:
+        for line in info:
+            if "=" in line:
+                (key, val) = line.strip().split("=")
+                res[key] = int(val)
+    return res
diff --git a/tools/nfs-sysfs/xprt.py b/tools/nfs-sysfs/xprt.py
new file mode 100644
index 000000000000..d37537771c1d
--- /dev/null
+++ b/tools/nfs-sysfs/xprt.py
@@ -0,0 +1,12 @@
+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()
+
+    def __lt__(self, rhs):
+        return self.id < rhs.id
+
+    def small_str(self):
+        return "xprt %s: %s, %s" % (self.id, self.type, self.dstaddr)
-- 
2.32.0


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

* [RFC PATCH 3/6] nfs-sysfs.py: Add a command for printing individual xprts
  2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 1/6] nfs-sysfs: Add an nfs-sysfs.py tool schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 2/6] nfs-sysfs.py: Add a command for printing xprt switch information schumaker.anna
@ 2021-06-08 17:46 ` schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 4/6] nfs-sysfs.py: Add a command for printing rpc-client information schumaker.anna
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: schumaker.anna @ 2021-06-08 17:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Anna.Schumaker

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

This shows more detailed information than what is presented with xprt
switches.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 tools/nfs-sysfs/nfs-sysfs.py |  2 ++
 tools/nfs-sysfs/xprt.py      | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

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..b95fb2d48829 100644
--- a/tools/nfs-sysfs/xprt.py
+++ b/tools/nfs-sysfs/xprt.py
@@ -1,3 +1,5 @@
+import sysfs
+
 class Xprt:
     def __init__(self, path):
         self.path = path
@@ -5,8 +7,34 @@ class Xprt:
         self.type = str(path).rsplit("-", 2)[2]
         self.dstaddr = open(path / "dstaddr", '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):
+        line = "xprt %s: %s, %s, state <%s>, num_reqs %s" % \
+                (self.id, self.type, self.dstaddr, self.state, self.num_reqs)
+        line += "\n	cur_cong %s, cong_win %s, min_num_slots %s, max_num_slots %s" % \
+                (self.cur_cong, self.cong_win, self.min_num_slots, self.max_num_slots)
+        line += "\n	binding_q_len %s, sending_q_len %s, pending_q_len %s, backlog_q_len %s" % \
+                (self.binding_q_len, self.sending_q_len, self.pending_q_len, self.backlog_q_len)
+        return line
+
     def small_str(self):
         return "xprt %s: %s, %s" % (self.id, self.type, self.dstaddr)
+
+
+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


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

* [RFC PATCH 4/6] nfs-sysfs.py: Add a command for printing rpc-client information
  2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
                   ` (2 preceding siblings ...)
  2021-06-08 17:46 ` [RFC PATCH 3/6] nfs-sysfs.py: Add a command for printing individual xprts schumaker.anna
@ 2021-06-08 17:46 ` schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 5/6] nfs-sysfs.py: Add a command for changing xprt dstaddr schumaker.anna
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: schumaker.anna @ 2021-06-08 17:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Anna.Schumaker

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>
---
 tools/nfs-sysfs/client.py    | 27 +++++++++++++++++++++++++++
 tools/nfs-sysfs/nfs-sysfs.py |  2 ++
 tools/nfs-sysfs/switch.py    |  7 ++++---
 3 files changed, 33 insertions(+), 3 deletions(-)
 create mode 100644 tools/nfs-sysfs/client.py

diff --git a/tools/nfs-sysfs/client.py b/tools/nfs-sysfs/client.py
new file mode 100644
index 000000000000..5192cc226aed
--- /dev/null
+++ b/tools/nfs-sysfs/client.py
@@ -0,0 +1,27 @@
+import sysfs
+import switch
+
+class RpcClient:
+    def __init__(self, path):
+        self.path = path
+        self.id = int(str(path).rsplit("-", 1)[1])
+        self.switch = switch.XprtSwitch(path / (path / "switch").readlink(), sep=",")
+
+    def __lt__(self, rhs):
+        return self.id < rhs.id
+
+    def __str__(self):
+        return "client %s: %s" % (self.id, self.switch)
+
+
+def list_rpc_clients(args):
+    clients = [ RpcClient(f) for f in (sysfs.SUNRPC / "rpc-clients").iterdir() ]
+    clients.sort()
+    for client in clients:
+        if args.id == None or client.id == args.id[0]:
+            print(client)
+
+def add_command(subparser):
+    parser = subparser.add_parser("rpc-client", help="Commands for rpc clients")
+    parser.add_argument("--id", metavar="ID", nargs=1, type=int, help="Id of a specific client to show")
+    parser.set_defaults(func=list_rpc_clients)
diff --git a/tools/nfs-sysfs/nfs-sysfs.py b/tools/nfs-sysfs/nfs-sysfs.py
index dfad6ac08fa0..e2172cdfa4c1 100755
--- a/tools/nfs-sysfs/nfs-sysfs.py
+++ b/tools/nfs-sysfs/nfs-sysfs.py
@@ -10,9 +10,11 @@ def show_small_help(args):
 parser.set_defaults(func=show_small_help)
 
 
+import client
 import switch
 import xprt
 subparser = parser.add_subparsers(title="commands")
+client.add_command(subparser)
 switch.add_command(subparser)
 xprt.add_command(subparser)
 
diff --git a/tools/nfs-sysfs/switch.py b/tools/nfs-sysfs/switch.py
index afb6963a0a1f..5384f970235c 100644
--- a/tools/nfs-sysfs/switch.py
+++ b/tools/nfs-sysfs/switch.py
@@ -2,9 +2,10 @@ import sysfs
 import xprt
 
 class XprtSwitch:
-    def __init__(self, path):
+    def __init__(self, path, sep=":"):
         self.path = path
         self.id = int(str(path).rsplit("-", 1)[1])
+        self.sep = sep
 
         self.xprts = [ xprt.Xprt(p) for p in self.path.iterdir() if p.is_dir() ]
         self.xprts.sort()
@@ -15,8 +16,8 @@ class XprtSwitch:
         return self.path < rhs.path
 
     def __str__(self):
-        line = "switch %s: num_xprts %s, num_active %s, queue_len %s" % \
-                (self.id, self.num_xprts, self.num_active, self.queue_len)
+        line = "switch %s%s num_xprts %s, num_active %s, queue_len %s" % \
+                (self.id, self.sep, self.num_xprts, self.num_active, self.queue_len)
         for x in self.xprts:
             line += "\n	%s" % x.small_str()
         return line
-- 
2.32.0


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

* [RFC PATCH 5/6] nfs-sysfs.py: Add a command for changing xprt dstaddr
  2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
                   ` (3 preceding siblings ...)
  2021-06-08 17:46 ` [RFC PATCH 4/6] nfs-sysfs.py: Add a command for printing rpc-client information schumaker.anna
@ 2021-06-08 17:46 ` schumaker.anna
  2021-06-08 17:46 ` [RFC PATCH 6/6] nfs-sysfs.py: Add a command for changing xprt-switch dstaddrs schumaker.anna
  2021-06-14 13:19 ` [RFC PATCH 0/6] Add a tool for using the new sysfs files Steve Dickson
  6 siblings, 0 replies; 9+ messages in thread
From: schumaker.anna @ 2021-06-08 17:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Anna.Schumaker

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

Using the socket module for dns resolution

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 tools/nfs-sysfs/xprt.py | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/tools/nfs-sysfs/xprt.py b/tools/nfs-sysfs/xprt.py
index b95fb2d48829..167e5fa69df7 100644
--- a/tools/nfs-sysfs/xprt.py
+++ b/tools/nfs-sysfs/xprt.py
@@ -1,3 +1,4 @@
+import socket
 import sysfs
 
 class Xprt:
@@ -26,6 +27,12 @@ class Xprt:
     def small_str(self):
         return "xprt %s: %s, %s" % (self.id, self.type, self.dstaddr)
 
+    def set_dstaddr(self, newaddr):
+        resolved = socket.gethostbyname(newaddr)
+        with open(self.path / "dstaddr", 'w') as f:
+            f.write(resolved)
+        self.dstaddr = open(self.path / "dstaddr", 'r').readline().strip()
+
 
 def list_xprts(args):
     xprts = [ Xprt(f) for f in (sysfs.SUNRPC / "xprt-switches").glob("**/xprt-*") ]
@@ -34,7 +41,28 @@ def list_xprts(args):
         if args.id == None or xprt.id == args.id[0]:
             print(xprt)
 
+def get_xprt(id):
+    xprts = [ Xprt(f) for f in (sysfs.SUNRPC / "xprt-switches").glob("**/xprt-*") ]
+    for xprt in xprts:
+        if xprt.id == id:
+            return xprt
+
+def set_xprt_property(args):
+    xprt = get_xprt(args.id[0])
+    try:
+        if args.dstaddr != None:
+            xprt.set_dstaddr(args.dstaddr[0])
+        print(xprt)
+    except Exception as e:
+        print(e)
+
 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)
+
+    subparser = parser.add_subparsers()
+    parser = subparser.add_parser("set", help="Set an xprt property")
+    parser.add_argument("--id", metavar="ID", nargs=1, type=int, required=True, help="Id of a specific xprt to modify")
+    parser.add_argument("--dstaddr", metavar="dstaddr", nargs=1, type=str, help="New dstaddr to set")
+    parser.set_defaults(func=set_xprt_property)
-- 
2.32.0


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

* [RFC PATCH 6/6] nfs-sysfs.py: Add a command for changing xprt-switch dstaddrs
  2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
                   ` (4 preceding siblings ...)
  2021-06-08 17:46 ` [RFC PATCH 5/6] nfs-sysfs.py: Add a command for changing xprt dstaddr schumaker.anna
@ 2021-06-08 17:46 ` schumaker.anna
  2021-06-14 13:19 ` [RFC PATCH 0/6] Add a tool for using the new sysfs files Steve Dickson
  6 siblings, 0 replies; 9+ messages in thread
From: schumaker.anna @ 2021-06-08 17:46 UTC (permalink / raw)
  To: linux-nfs; +Cc: Anna.Schumaker

From: Anna Schumaker <Anna.Schumaker@Netapp.com>

This is basically the same as for xprts, but it iterates through all
xprts attached to the switch to apply the new address.

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 tools/nfs-sysfs/switch.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/tools/nfs-sysfs/switch.py b/tools/nfs-sysfs/switch.py
index 5384f970235c..859b82e07895 100644
--- a/tools/nfs-sysfs/switch.py
+++ b/tools/nfs-sysfs/switch.py
@@ -30,7 +30,22 @@ def list_xprt_switches(args):
         if args.id == None or xs.id == args.id[0]:
             print(xs)
 
+def set_xprt_switch_property(args):
+    switch = XprtSwitch(sysfs.SUNRPC / "xprt-switches" / f"switch-{args.id[0]}")
+    try:
+        for xprt in switch.xprts:
+            xprt.set_dstaddr(args.dstaddr[0])
+        print(switch)
+    except Exception as e:
+        print(e)
+
 def add_command(subparser):
     parser = subparser.add_parser("xprt-switch", help="Commands for xprt switches")
     parser.add_argument("--id", metavar="ID", nargs=1, type=int, help="Id of a specific xprt-switch to show")
     parser.set_defaults(func=list_xprt_switches)
+
+    subparser = parser.add_subparsers()
+    parser = subparser.add_parser("set", help="Set an xprt switch property")
+    parser.add_argument("--id", metavar="ID", nargs=1, type=int, required=True, help="Id of an xprt-switch to modify")
+    parser.add_argument("--dstaddr", metavar="dstaddr", nargs=1, type=str, help="New dstaddr to set")
+    parser.set_defaults(func=set_xprt_switch_property)
-- 
2.32.0


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

* Re: [RFC PATCH 0/6] Add a tool for using the new sysfs files
  2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
                   ` (5 preceding siblings ...)
  2021-06-08 17:46 ` [RFC PATCH 6/6] nfs-sysfs.py: Add a command for changing xprt-switch dstaddrs schumaker.anna
@ 2021-06-14 13:19 ` Steve Dickson
  2021-06-14 13:42   ` Anna Schumaker
  6 siblings, 1 reply; 9+ messages in thread
From: Steve Dickson @ 2021-06-14 13:19 UTC (permalink / raw)
  To: schumaker.anna, linux-nfs; +Cc: Anna.Schumaker



On 6/8/21 1:46 PM, schumaker.anna@gmail.com wrote:
> From: Anna Schumaker <Anna.Schumaker@Netapp.com>
> 
> These patches implement a tool that can be used to read and write the
> sysfs files, with subcommands! They need Olga's most recent patches to
> run.
> 
> The following subcommands are implemented:
>    nfs-sysfs.py rpc-client
>    nfs-sysfs.py xprt
>    nfs-sysfs.py xprt set
>    nfs-sysfs.py xprt-switch
>    nfs-sysfs.py xprt-switch set
> 
> So you can print out information about every xprt-switch with:
> 	anna@client % ./nfs-sysfs.py xprt-switch
> 	switch 0: num_xprts 1, num_active 1, queue_len 0
> 		xprt 0: local, /var/run/gssproxy.sock
> 	switch 1: num_xprts 1, num_active 1, queue_len 0
> 		xprt 1: local, /var/run/rpcbind.sock
> 	switch 2: num_xprts 4, num_active 4, queue_len 0
> 		xprt 2: tcp, 192.168.111.188
> 		xprt 3: tcp, 192.168.111.188
> 		xprt 5: tcp, 192.168.111.188
> 		xprt 6: tcp, 192.168.111.188
> 	switch 3: num_xprts 1, num_active 1, queue_len 0
> 		xprt 7: tcp, 192.168.111.1
> 	switch 4: num_xprts 1, num_active 1, queue_len 0
> 		xprt 4: tcp, 192.168.111.188
> 
> And information about each xprt:
> 	anna@client % ./nfs-sysfs.py xprt
> 	xprt 0: local, /var/run/gssproxy.sock, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	xprt 1: local, /var/run/rpcbind.sock, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	xprt 2: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	xprt 3: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	xprt 4: tcp, 192.168.111.188, state <BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	xprt 5: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	xprt 6: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	xprt 7: tcp, 192.168.111.1, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 
> You can use the `set` subcommand to change the dstaddr of individual xprts:
> 	anna@client % ./nfs-sysfs.py xprt --id 2
> 	xprt 2: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 	anna@client % sudo ./nfs-sysfs.py xprt set --id 2 --dstaddr server2.nowheycreamery.vm
> 	xprt 2: tcp, 192.168.111.186, state <CONNECTED,BOUND>, num_reqs 2
> 		cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> 		binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> 
> Or for changing the dstaddr of all xprts attached to a switch:
> 	anna@client % ./nfs-sysfs.py xprt-switch --id 2
> 	switch 2: num_xprts 4, num_active 4, queue_len 0
> 		xprt 2: tcp, 192.168.111.188
> 		xprt 3: tcp, 192.168.111.188
> 		xprt 5: tcp, 192.168.111.188
> 		xprt 6: tcp, 192.168.111.188
> 	anna@client % sudo ./nfs-sysfs.py xprt-switch set --id 2 --dstaddr server2.nowheycreamery.vm
> 	switch 2: num_xprts 4, num_active 4, queue_len 0
> 		xprt 2: tcp, 192.168.111.186
> 		xprt 3: tcp, 192.168.111.186
> 		xprt 5: tcp, 192.168.111.186
> 		xprt 6: tcp, 192.168.111.186
> 
> 
> I'm sure this needs lots of polish before it's ready for inclusion,
> along with needing a Makefile so it can be installed (I've just been
> running it out of the nfs-utils/tools/nfs-sysfs/ directory). But it's
> still a start, and I wanted to post it before going on New Baby Leave
> Part 2 (June 12 - July 11).
> 
> What does everybody think?
The first thing that popped in my was is where is the man page,
but this being a developers tool, maybe one is not needed?? (ala pynfs).
Although if its going to be installed from nfs-utils, it would
be nice to have a man page.

The second thing was I was thinking... it would be good if
we could run this command on a kernel dump... to see what was
going on when things crashed...

Nice work!

steved.

> Anna
> 
> 
> Anna Schumaker (6):
>    nfs-sysfs: Add an nfs-sysfs.py tool
>    nfs-sysfs.py: Add a command for printing xprt switch information
>    nfs-sysfs.py: Add a command for printing individual xprts
>    nfs-sysfs.py: Add a command for printing rpc-client information
>    nfs-sysfs.py: Add a command for changing xprt dstaddr
>    nfs-sysfs.py: Add a command for changing xprt-switch dstaddrs
> 
>   tools/nfs-sysfs/client.py    | 27 ++++++++++++++
>   tools/nfs-sysfs/nfs-sysfs.py | 23 ++++++++++++
>   tools/nfs-sysfs/switch.py    | 51 +++++++++++++++++++++++++++
>   tools/nfs-sysfs/sysfs.py     | 28 +++++++++++++++
>   tools/nfs-sysfs/xprt.py      | 68 ++++++++++++++++++++++++++++++++++++
>   5 files changed, 197 insertions(+)
>   create mode 100644 tools/nfs-sysfs/client.py
>   create mode 100755 tools/nfs-sysfs/nfs-sysfs.py
>   create mode 100644 tools/nfs-sysfs/switch.py
>   create mode 100644 tools/nfs-sysfs/sysfs.py
>   create mode 100644 tools/nfs-sysfs/xprt.py
> 


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

* Re: [RFC PATCH 0/6] Add a tool for using the new sysfs files
  2021-06-14 13:19 ` [RFC PATCH 0/6] Add a tool for using the new sysfs files Steve Dickson
@ 2021-06-14 13:42   ` Anna Schumaker
  0 siblings, 0 replies; 9+ messages in thread
From: Anna Schumaker @ 2021-06-14 13:42 UTC (permalink / raw)
  To: Steve Dickson; +Cc: Linux NFS Mailing List

Hi Steve,

On Mon, Jun 14, 2021 at 9:16 AM Steve Dickson <steved@redhat.com> wrote:
>
>
>
> On 6/8/21 1:46 PM, schumaker.anna@gmail.com wrote:
> > From: Anna Schumaker <Anna.Schumaker@Netapp.com>
> >
> > These patches implement a tool that can be used to read and write the
> > sysfs files, with subcommands! They need Olga's most recent patches to
> > run.
> >
> > The following subcommands are implemented:
> >    nfs-sysfs.py rpc-client
> >    nfs-sysfs.py xprt
> >    nfs-sysfs.py xprt set
> >    nfs-sysfs.py xprt-switch
> >    nfs-sysfs.py xprt-switch set
> >
> > So you can print out information about every xprt-switch with:
> >       anna@client % ./nfs-sysfs.py xprt-switch
> >       switch 0: num_xprts 1, num_active 1, queue_len 0
> >               xprt 0: local, /var/run/gssproxy.sock
> >       switch 1: num_xprts 1, num_active 1, queue_len 0
> >               xprt 1: local, /var/run/rpcbind.sock
> >       switch 2: num_xprts 4, num_active 4, queue_len 0
> >               xprt 2: tcp, 192.168.111.188
> >               xprt 3: tcp, 192.168.111.188
> >               xprt 5: tcp, 192.168.111.188
> >               xprt 6: tcp, 192.168.111.188
> >       switch 3: num_xprts 1, num_active 1, queue_len 0
> >               xprt 7: tcp, 192.168.111.1
> >       switch 4: num_xprts 1, num_active 1, queue_len 0
> >               xprt 4: tcp, 192.168.111.188
> >
> > And information about each xprt:
> >       anna@client % ./nfs-sysfs.py xprt
> >       xprt 0: local, /var/run/gssproxy.sock, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       xprt 1: local, /var/run/rpcbind.sock, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       xprt 2: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       xprt 3: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       xprt 4: tcp, 192.168.111.188, state <BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       xprt 5: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       xprt 6: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       xprt 7: tcp, 192.168.111.1, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >
> > You can use the `set` subcommand to change the dstaddr of individual xprts:
> >       anna@client % ./nfs-sysfs.py xprt --id 2
> >       xprt 2: tcp, 192.168.111.188, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >       anna@client % sudo ./nfs-sysfs.py xprt set --id 2 --dstaddr server2.nowheycreamery.vm
> >       xprt 2: tcp, 192.168.111.186, state <CONNECTED,BOUND>, num_reqs 2
> >               cur_cong 0, cong_win 256, min_num_slots 2, max_num_slots 65536
> >               binding_q_len 0, sending_q_len 0, pending_q_len 0, backlog_q_len 0
> >
> > Or for changing the dstaddr of all xprts attached to a switch:
> >       anna@client % ./nfs-sysfs.py xprt-switch --id 2
> >       switch 2: num_xprts 4, num_active 4, queue_len 0
> >               xprt 2: tcp, 192.168.111.188
> >               xprt 3: tcp, 192.168.111.188
> >               xprt 5: tcp, 192.168.111.188
> >               xprt 6: tcp, 192.168.111.188
> >       anna@client % sudo ./nfs-sysfs.py xprt-switch set --id 2 --dstaddr server2.nowheycreamery.vm
> >       switch 2: num_xprts 4, num_active 4, queue_len 0
> >               xprt 2: tcp, 192.168.111.186
> >               xprt 3: tcp, 192.168.111.186
> >               xprt 5: tcp, 192.168.111.186
> >               xprt 6: tcp, 192.168.111.186
> >
> >
> > I'm sure this needs lots of polish before it's ready for inclusion,
> > along with needing a Makefile so it can be installed (I've just been
> > running it out of the nfs-utils/tools/nfs-sysfs/ directory). But it's
> > still a start, and I wanted to post it before going on New Baby Leave
> > Part 2 (June 12 - July 11).
> >
> > What does everybody think?
> The first thing that popped in my was is where is the man page,
> but this being a developers tool, maybe one is not needed?? (ala pynfs).
> Although if its going to be installed from nfs-utils, it would
> be nice to have a man page.

Yeah, I was expecting to write a man page at some point before a
non-RFC submission, since commands and options might change after
hearing feedback from everyone.
>
> The second thing was I was thinking... it would be good if
> we could run this command on a kernel dump... to see what was
> going on when things crashed...

That would be useful, but I'm having trouble conceptualizing how that
would work since the contents of each file are generated by the kernel
when the files are read. If there is a way to do it, then the tool
could definitely be expanded to add it in!

>
> Nice work!

Thanks!
Anna
>
> steved.
>
> > Anna
> >
> >
> > Anna Schumaker (6):
> >    nfs-sysfs: Add an nfs-sysfs.py tool
> >    nfs-sysfs.py: Add a command for printing xprt switch information
> >    nfs-sysfs.py: Add a command for printing individual xprts
> >    nfs-sysfs.py: Add a command for printing rpc-client information
> >    nfs-sysfs.py: Add a command for changing xprt dstaddr
> >    nfs-sysfs.py: Add a command for changing xprt-switch dstaddrs
> >
> >   tools/nfs-sysfs/client.py    | 27 ++++++++++++++
> >   tools/nfs-sysfs/nfs-sysfs.py | 23 ++++++++++++
> >   tools/nfs-sysfs/switch.py    | 51 +++++++++++++++++++++++++++
> >   tools/nfs-sysfs/sysfs.py     | 28 +++++++++++++++
> >   tools/nfs-sysfs/xprt.py      | 68 ++++++++++++++++++++++++++++++++++++
> >   5 files changed, 197 insertions(+)
> >   create mode 100644 tools/nfs-sysfs/client.py
> >   create mode 100755 tools/nfs-sysfs/nfs-sysfs.py
> >   create mode 100644 tools/nfs-sysfs/switch.py
> >   create mode 100644 tools/nfs-sysfs/sysfs.py
> >   create mode 100644 tools/nfs-sysfs/xprt.py
> >
>

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

end of thread, other threads:[~2021-06-14 13:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-08 17:46 [RFC PATCH 0/6] Add a tool for using the new sysfs files schumaker.anna
2021-06-08 17:46 ` [RFC PATCH 1/6] nfs-sysfs: Add an nfs-sysfs.py tool schumaker.anna
2021-06-08 17:46 ` [RFC PATCH 2/6] nfs-sysfs.py: Add a command for printing xprt switch information schumaker.anna
2021-06-08 17:46 ` [RFC PATCH 3/6] nfs-sysfs.py: Add a command for printing individual xprts schumaker.anna
2021-06-08 17:46 ` [RFC PATCH 4/6] nfs-sysfs.py: Add a command for printing rpc-client information schumaker.anna
2021-06-08 17:46 ` [RFC PATCH 5/6] nfs-sysfs.py: Add a command for changing xprt dstaddr schumaker.anna
2021-06-08 17:46 ` [RFC PATCH 6/6] nfs-sysfs.py: Add a command for changing xprt-switch dstaddrs schumaker.anna
2021-06-14 13:19 ` [RFC PATCH 0/6] Add a tool for using the new sysfs files Steve Dickson
2021-06-14 13:42   ` Anna Schumaker

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.