linux-nfs.vger.kernel.org archive mirror
 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 v2 2/2] rpcctl: Print a message if the user tries to modify a main xprt
Date: Thu, 19 May 2022 11:47:27 -0400	[thread overview]
Message-ID: <20220519154727.3577715-2-anna@kernel.org> (raw)
In-Reply-To: <20220519154727.3577715-1-anna@kernel.org>

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

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

Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
---
 tools/rpcctl/rpcctl.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/tools/rpcctl/rpcctl.py b/tools/rpcctl/rpcctl.py
index 2a69eacd3103..d2110ad6de93 100755
--- a/tools/rpcctl/rpcctl.py
+++ b/tools/rpcctl/rpcctl.py
@@ -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)
-- 
2.36.1


  reply	other threads:[~2022-05-19 15:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-19 15:47 [PATCH v2 1/2] rpcctl: Use the correct function for setting xprts offline and online Anna Schumaker
2022-05-19 15:47 ` Anna Schumaker [this message]
2022-05-26 17:34   ` [PATCH v2 2/2] rpcctl: Print a message if the user tries to modify a main xprt Steve Dickson
2022-05-26 17:34 ` [PATCH v2 1/2] rpcctl: Use the correct function for setting xprts offline and online Steve Dickson

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=20220519154727.3577715-2-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;
as well as URLs for NNTP newsgroup(s).