Skip to contentSkip to conversation

rpcctl: Various Improvements

PATCH In review Anna Schumaker 2 participants 6 messages Apr 29, 2025 – May 7, 2025

Subsystems (2)
lore
Share & tools
lore

Anna Schumaker

author maintainer
#0 lore raw

v3 cover rpcctl: Various Improvements

From: Anna Schumaker <[email protected]>

These patches depend on kernel patches that have been included in v6.15. They update the rpcctl tool to use the new sunrpc sysfs features, in a backwards compatible way that won't crash on older kernels.

v3:
* Rebase on top of the 2.8.3 release.

Thanks,
Anna

Anna Schumaker (4):
rpcctl: Rename {read,write}_addr_file()
rpcctl: Add support for the xprtsec sysfs attribute
rpcctl: Display new rpc_clnt sysfs attributes
rpcctl: Add support for rpcctl switch add-xprt

 tools/rpcctl/rpcctl.man |  4 ++++
 tools/rpcctl/rpcctl.py  | 50 ++++++++++++++++++++++++++++-------------
 2 files changed, 38 insertions(+), 16 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH v3 1/4 rpcctl: Rename {read,write}_addr_file()

From: Anna Schumaker <[email protected]>

There is nothing address specific about these functions, so name them something more generic so they can be reused.

---
 tools/rpcctl/rpcctl.py | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tools/rpcctl/rpcctl.py +9 -9
index 0221fbb68be1..654b2f60a894 100755
@@ -20,8 +20,8 @@ if not sunrpc.is_dir():
     sys.exit(1)
 
 
-def read_addr_file(path):
-    """Read an xprt address file."""
+def read_sysfs_file(path):
+    """Read a sysfs file."""
     try:
         with open(path, 'r') as f:
             return f.readline().strip()
@@ -29,11 +29,11 @@ def read_addr_file(path):
         return "(enoent)"
 
 
-def write_addr_file(path, newaddr):
-    """Write a new address to an xprt address file."""
+def write_sysfs_file(path, input):
+    """Write 'input' to a sysfs file."""
     with open(path, 'w') as f:
-        f.write(newaddr)
-    return read_addr_file(path)
+        f.write(input)
+    return read_sysfs_file(path)
 
 
 def read_info_file(path):
@@ -56,8 +56,8 @@ class Xprt:
         self.name = path.stem.rsplit("-", 1)[0]
         self.type = path.stem.split("-")[2]
         self.info = read_info_file(path / "xprt_info")
-        self.dstaddr = read_addr_file(path / "dstaddr")
-        self.srcaddr = read_addr_file(path / "srcaddr")
+        self.dstaddr = read_sysfs_file(path / "dstaddr")
+        self.srcaddr = read_sysfs_file(path / "srcaddr")
         self.read_state()
 
     def __lt__(self, rhs):
@@ -106,7 +106,7 @@ class Xprt:
 
     def set_dstaddr(self, newaddr):
         """Change the dstaddr of an xprt."""
-        self.dstaddr = write_addr_file(self.path / "dstaddr", newaddr)
+        self.dstaddr = write_sysfs_file(self.path / "dstaddr", newaddr)
 
     def set_state(self, state):
         """Change the state of an xprt."""
Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH v3 2/4 rpcctl: Add support for the xprtsec sysfs attribute

In reply to Anna Schumaker

From: Anna Schumaker <[email protected]>

This was recently added to the Linux kernel, so running rpcctl on kernels that don't have this attribute will print out "unknown" in its place instead.

---
 tools/rpcctl/rpcctl.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/rpcctl/rpcctl.py +5 -3
index 654b2f60a894..ce22e424b804 100755
@@ -20,13 +20,13 @@ if not sunrpc.is_dir():
     sys.exit(1)
 
 
-def read_sysfs_file(path):
+def read_sysfs_file(path, *, missing="enoent"):
     """Read a sysfs file."""
     try:
         with open(path, 'r') as f:
             return f.readline().strip()
     except FileNotFoundError:
-        return "(enoent)"
+        return f"({missing})"
 
 
 def write_sysfs_file(path, input):
@@ -58,6 +58,7 @@ class Xprt:
         self.info = read_info_file(path / "xprt_info")
         self.dstaddr = read_sysfs_file(path / "dstaddr")
         self.srcaddr = read_sysfs_file(path / "srcaddr")
+        self.xprtsec = read_sysfs_file(path / "xprtsec", missing="unknown")
         self.read_state()
 
     def __lt__(self, rhs):
@@ -67,7 +68,8 @@ class Xprt:
     def _xprt(self):
         main = ", main" if self.info.get("main_xprt") else ""
         return f"{self.name}: {self.type}, {self.dstaddr}, " \
-               f"port {self.info['dst_port']}, state <{self.state}>{main}"
+               f"port {self.info['dst_port']}, sec {self.xprtsec}, " \
+               f"state <{self.state}>{main}"
 
     def _src_reqs(self):
         return f"	Source: {self.srcaddr}, port {self.info['src_port']}, " \
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH v3 3/4 rpcctl: Display new rpc_clnt sysfs attributes

In reply to Anna Schumaker

From: Anna Schumaker <[email protected]>

This includes the rpc program name, rpc version, and maximum number of connections.

---
 tools/rpcctl/rpcctl.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
tools/rpcctl/rpcctl.py +10 -5
index ce22e424b804..130f245a64e8 100755
@@ -185,14 +185,13 @@ class Xprt:
 class XprtSwitch:
     """Represents a group of xprt connections."""
 
-    def __init__(self, path, sep=":"):
+    def __init__(self, path):
         """Read in xprt switch information from sysfs."""
         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):
         """Compare the name of two xprt switch instances."""
@@ -200,7 +199,7 @@ class XprtSwitch:
 
     def __str__(self):
         """Return a string representation of an xprt switch."""
-        switch = f"{self.name}{self.sep} " \
+        switch = f"{self.name}: " \
                  f"xprts {self.info['num_xprts']}, " \
                  f"active {self.info['num_active']}, " \
                  f"queue {self.info['queue_len']}"
@@ -258,7 +257,11 @@ class RpcClient:
         """Read in rpc client information from sysfs."""
         self.path = path
         self.name = path.stem
-        self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",")
+        self.switch = XprtSwitch(path / (path / "switch").readlink())
+        self.program = read_sysfs_file(path / "program", missing="unknown")
+        self.version = read_sysfs_file(path / "rpc_version", missing="unknown")
+        self.max_connect = read_sysfs_file(path / "max_connect",
+                                           missing="unknown")
 
     def __lt__(self, rhs):
         """Compare the name of two rpc client instances."""
@@ -266,7 +269,9 @@ class RpcClient:
 
     def __str__(self):
         """Return a string representation of an rpc client."""
-        return f"{self.name}: {self.switch}"
+        return f"{self.name}: {self.program}, rpc version {self.version}, " \
+               f"max_connect {self.max_connect}" \
+               f"\n  {' ' * len(self.name)}{self.switch}"
 
     def add_command(subparser):
         """Add parser options for the `rpcctl client` command."""
Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH v3 4/4 rpcctl: Add support for `rpcctl switch add-xprt`

In reply to Anna Schumaker

From: Anna Schumaker <[email protected]>

This is used to add an xprt to the switch at runtime.

---
 tools/rpcctl/rpcctl.man |  4 ++++
 tools/rpcctl/rpcctl.py  | 11 +++++++++++
 2 files changed, 15 insertions(+)
tools/rpcctl/rpcctl.man +4 -0
index b87ba0df41c0..2ee168c8f3c5 100644
@@ -12,6 +12,7 @@ rpcctl \- Displays SunRPC connection information
 .BR "rpcctl client show " "\fR[ \fB\-h \f| \fB\-\-help \fR] [ \fIXPRT \fR]"
 .P
 .BR "rpcctl switch" " \fR[ \fB\-h \fR| \fB\-\-help \fR] { \fBset \fR| \fBshow \fR}"
+.BR "rpcctl switch add-xprt" " \fR[ \fB\-h \fR| \fB\-\-help \fR] [ \fISWITCH \fR]"
 .BR "rpcctl switch set" " \fR[ \fB\-h \fR| \fB\-\-help \fR] \fISWITCH \fBdstaddr \fINEWADDR"
 .BR "rpcctl switch show" " \fR[ \fB\-h \fR| \fB\-\-help \fR] [ \fISWITCH \fR]"
 .P
@@ -29,6 +30,9 @@ Show detailed information about the RPC clients on this system.
 If \fICLIENT \fRwas provided, then only show information about a single RPC client.
 .P
 .SS rpcctl switch \fR- \fBCommands operating on groups of transports
+.IP "\fBadd-xprt \fISWITCH"
+Add an aditional transport to the \fISWITCH\fR.
+Note that the new transport will take its values from the "main" transport.
 .IP "\fBset \fISWITCH \fBdstaddr \fINEWADDR"
 Change the destination address of all transports in the \fISWITCH \fRto \fINEWADDR\fR.
 \fINEWADDR \fRcan be an IP address, DNS name, or anything else resolvable by \fBgethostbyname\fR(3).
tools/rpcctl/rpcctl.py +11 -0
index 130f245a64e8..29ae7d26f50e 100755
@@ -213,6 +213,12 @@ class XprtSwitch:
         parser.set_defaults(func=XprtSwitch.show, switch=None)
         subparser = parser.add_subparsers()
 
+        add = subparser.add_parser("add-xprt",
+                                   help="Add an xprt to the switch")
+        add.add_argument("switch", metavar="SWITCH", nargs=1,
+                         help="Name of a specific xprt switch to modify")
+        add.set_defaults(func=XprtSwitch.add_xprt)
+
         show = subparser.add_parser("show", help="Show xprt switches")
         show.add_argument("switch", metavar="SWITCH", nargs='?',
                           help="Name of a specific switch to show")
@@ -236,6 +242,11 @@ class XprtSwitch:
             return [XprtSwitch(xprt_switches / name)]
         return [XprtSwitch(f) for f in sorted(xprt_switches.iterdir())]
 
+    def add_xprt(args):
+        """Handle the `rpcctl switch add-xprt` command."""
+        for switch in XprtSwitch.get_by_name(args.switch[0]):
+            write_sysfs_file(switch.path / "add_xprt", "1")
+
     def show(args):
         """Handle the `rpcctl switch show` command."""
         for switch in XprtSwitch.get_by_name(args.switch):
Signature · 1 line
2.49.0
#5 lore raw
In reply to Anna Schumaker
Quoted 8 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

These patches depend on kernel patches that have been included in v6.15. They update the rpcctl tool to use the new sunrpc sysfs features, in a backwards compatible way that won't crash on older kernels.

v3:
* Rebase on top of the 2.8.3 release.

All patches have been committed... (tag: nfs-utils-2-8-4-rc1)

steved.

Quoted 14 lines

Thanks,
Anna

Anna Schumaker (4):
rpcctl: Rename {read,write}_addr_file()
rpcctl: Add support for the xprtsec sysfs attribute
rpcctl: Display new rpc_clnt sysfs attributes
rpcctl: Add support for rpcctl switch add-xprt

  tools/rpcctl/rpcctl.man |  4 ++++
  tools/rpcctl/rpcctl.py  | 50 ++++++++++++++++++++++++++++-------------
  2 files changed, 38 insertions(+), 16 deletions(-)