public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Anna Schumaker <anna@kernel.org>
To: linux-nfs@vger.kernel.org, steved@redhat.com
Cc: anna@kernel.org
Subject: [PATCH nfs-utils v2 6/8] rpcctl: Add missing docstrings to the Xprt class
Date: Wed, 15 Jan 2025 15:20:33 -0500	[thread overview]
Message-ID: <20250115202035.112122-7-anna@kernel.org> (raw)
In-Reply-To: <20250115202035.112122-1-anna@kernel.org>

From: Anna Schumaker <anna.schumaker@oracle.com>

Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
---
 tools/rpcctl/rpcctl.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/tools/rpcctl/rpcctl.py b/tools/rpcctl/rpcctl.py
index 435f4be6623a..b8808787b51d 100755
--- a/tools/rpcctl/rpcctl.py
+++ b/tools/rpcctl/rpcctl.py
@@ -44,7 +44,10 @@ def read_info_file(path):
 
 
 class Xprt:
+    """Represents a single sunrpc connection."""
+
     def __init__(self, path):
+        """Read in xprt information from sysfs."""
         self.path = path
         self.name = path.stem.rsplit("-", 1)[0]
         self.type = path.stem.split("-")[2]
@@ -54,6 +57,7 @@ class Xprt:
         self.read_state()
 
     def __lt__(self, rhs):
+        """Compare the names of two xprt instances."""
         return self.name < rhs.name
 
     def _xprt(self):
@@ -79,24 +83,29 @@ class Xprt:
                f"tasks {self.info['tasks_queuelen']}"
 
     def __str__(self):
+        """Return a string representation of an xprt."""
         if not self.path.exists():
             return f"{self.name}: has been removed"
         return "\n".join([self._xprt(), self._src_reqs(),
                           self._cong_slots(), self._queues()])
 
     def read_state(self):
+        """Read in the xprt_state file."""
         if self.path.exists():
             with open(self.path / "xprt_state") as f:
                 self.state = ','.join(f.readline().split()[1:])
 
     def small_str(self):
+        """Return a short string summary of an xprt."""
         main = " [main]" if self.info.get("main_xprt") else ""
         return f"{self.name}: {self.type}, {self.dstaddr}{main}"
 
     def set_dstaddr(self, newaddr):
+        """Change the dstaddr of an xprt."""
         self.dstaddr = write_addr_file(self.path / "dstaddr", newaddr)
 
     def set_state(self, state):
+        """Change the state of an xprt."""
         if self.info.get("main_xprt"):
             raise Exception(f"Main xprts cannot be set {state}")
         with open(self.path / "xprt_state", 'w') as f:
@@ -104,12 +113,14 @@ class Xprt:
         self.read_state()
 
     def remove(self):
+        """Remove an xprt."""
         if self.info.get("main_xprt"):
             raise Exception("Main xprts cannot be removed")
         self.set_state("offline")
         self.set_state("remove")
 
     def add_command(subparser):
+        """Add parser options for the `rpcctl xprt` command."""
         parser = subparser.add_parser("xprt",
                                       help="Commands for individual xprts")
         parser.set_defaults(func=Xprt.show, xprt=None)
@@ -140,6 +151,7 @@ class Xprt:
         dstaddr.set_defaults(func=Xprt.set_property, property="dstaddr")
 
     def get_by_name(name):
+        """Find a (sorted) list of Xprts matching the given name."""
         glob = f"**/{name}-*" if name else "**/xprt-*"
         res = [Xprt(x) for x in (sunrpc / "xprt-switches").glob(glob)]
         if name and len(res) == 0:
@@ -148,10 +160,12 @@ class Xprt:
         return sorted(res)
 
     def show(args):
+        """Handle the `rpcctl xprt show` command."""
         for xprt in Xprt.get_by_name(args.xprt):
             print(xprt)
 
     def set_property(args):
+        """Handle the `rpcctl xprt set` command."""
         for xprt in Xprt.get_by_name(args.xprt[0]):
             if args.property == "dstaddr":
                 xprt.set_dstaddr(socket.gethostbyname(args.newaddr[0]))
-- 
2.48.1


  parent reply	other threads:[~2025-01-15 20:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-15 20:20 [PATCH nfs-utils v2 0/8] rpcctl: Flake8 cleanups Anna Schumaker
2025-01-15 20:20 ` [PATCH nfs-utils v2 1/8] Patch for broken libnfsimapd static and regex plugins Anna Schumaker
2025-01-15 20:20 ` [PATCH nfs-utils v2 2/8] rpcctl: Fix flake8 whitespace errors Anna Schumaker
2025-01-15 20:20 ` [PATCH nfs-utils v2 3/8] rpcctl: Fix flake8 line-too-long errors Anna Schumaker
2025-01-15 20:20 ` [PATCH nfs-utils v2 4/8] rpcctl: Fix flake8 bare exception error Anna Schumaker
2025-01-15 20:20 ` [PATCH nfs-utils v2 5/8] rpcctl: Fix flake8 ambiguous-variable-name error Anna Schumaker
2025-01-15 20:20 ` Anna Schumaker [this message]
2025-01-15 20:20 ` [PATCH nfs-utils v2 7/8] rpcctl: Add missing docstrings to the XprtSwitch class Anna Schumaker
2025-01-15 20:20 ` [PATCH nfs-utils v2 8/8] rpcctl: Add remaining missing docstrings Anna Schumaker

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=20250115202035.112122-7-anna@kernel.org \
    --to=anna@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=steved@redhat.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