Skip to contentSkip to conversation

rpcctl: Use the correct function for setting xprts offline and online

PATCH In review Anna Schumaker 2 participants 4 messages May 19, 2022 – May 26, 2022

Subsystems (2)
lore
Share & tools
lore

Anna Schumaker

author maintainer
#0 lore raw

PATCH v2 1/2 rpcctl: Use the correct function for setting xprts offline and online

From: Anna Schumaker <[email protected]>

Otherwise the tool will tell us:
'Namespace' object has no attribute 'set_state'

---
 tools/rpcctl/rpcctl.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/rpcctl/rpcctl.py +1 -1
index b8df556b682c..2a69eacd3103 100755
@@ -142,7 +142,7 @@ class Xprt:
                 xprt.set_state("offline")
                 xprt.set_state("remove")
             else:
-                args.set_state(args.property)
+                xprt.set_state(args.property)
         print(xprt)
 
 
Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH v2 2/2 rpcctl: Print a message if the user tries to modify a main xprt

From: Anna Schumaker <[email protected]>

'main' xprts cannot be set offline or removed, so print a helpful error message in this case instead of a cryptic 'invalid argument' message.

---
 tools/rpcctl/rpcctl.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
tools/rpcctl/rpcctl.py +9 -2
index 2a69eacd3103..d2110ad6de93 100755
@@ -90,10 +90,18 @@ class Xprt:
         self.dstaddr = write_addr_file(self.path / "dstaddr", newaddr)
 
     def set_state(self, state):
+        if self.info.get("main_xprt"):
+            raise Exception(f"Main xprts cannot be set {state}")
         with open(self.path / "xprt_state", 'w') as f:
             f.write(state)
         self.read_state()
 
+    def remove(self):
+        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):
         parser = subparser.add_parser("xprt", help="Commands for individual xprts")
         parser.set_defaults(func=Xprt.show, xprt=None)
@@ -139,8 +147,7 @@ class Xprt:
             if args.property == "dstaddr":
                 xprt.set_dstaddr(socket.gethostbyname(args.newaddr[0]))
             elif args.property == "remove":
-                xprt.set_state("offline")
-                xprt.set_state("remove")
+                xprt.remove()
             else:
                 xprt.set_state(args.property)
         print(xprt)
Signature · 1 line
2.36.1
#2 lore raw

Re: [PATCH v2 2/2] rpcctl: Print a message if the user tries to modify a main xprt

Quoted 6 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

'main' xprts cannot be set offline or removed, so print a helpful error message in this case instead of a cryptic 'invalid argument' message.

Committed... (tag: nfs-utils-2-6-2-rc5)

steved

Quoted 37 lines
---
  tools/rpcctl/rpcctl.py | 11 +++++++++--
  1 file changed, 9 insertions(+), 2 deletions(-)
tools/rpcctl/rpcctl.py +9 -2
index 2a69eacd3103..d2110ad6de93 100755
@@ -90,10 +90,18 @@ class Xprt:
          self.dstaddr = write_addr_file(self.path / "dstaddr", newaddr)
 
      def set_state(self, state):
+        if self.info.get("main_xprt"):
+            raise Exception(f"Main xprts cannot be set {state}")
          with open(self.path / "xprt_state", 'w') as f:
              f.write(state)
          self.read_state()
 
+    def remove(self):
+        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):
          parser = subparser.add_parser("xprt", help="Commands for individual xprts")
          parser.set_defaults(func=Xprt.show, xprt=None)
@@ -139,8 +147,7 @@ class Xprt:
              if args.property == "dstaddr":
                  xprt.set_dstaddr(socket.gethostbyname(args.newaddr[0]))
              elif args.property == "remove":
-                xprt.set_state("offline")
-                xprt.set_state("remove")
+                xprt.remove()
              else:
                  xprt.set_state(args.property)
          print(xprt)
#3 lore raw
In reply to Anna Schumaker
Quoted 6 lines · Anna Schumaker

From: Anna Schumaker <[email protected]>

Otherwise the tool will tell us:
'Namespace' object has no attribute 'set_state'

Committed... (tag: nfs-utils-2-6-2-rc5)

steved.

Quoted 17 lines
---
  tools/rpcctl/rpcctl.py | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/rpcctl/rpcctl.py +1 -1
index b8df556b682c..2a69eacd3103 100755
@@ -142,7 +142,7 @@ class Xprt:
                  xprt.set_state("offline")
                  xprt.set_state("remove")
              else:
-                args.set_state(args.property)
+                xprt.set_state(args.property)
          print(xprt)