Message ID | 20220127194952.63033-2-Anna.Schumaker@Netapp.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add a tool for using the new sysfs files | expand |
On Thu, Jan 27, 2022 at 2:50 PM <schumaker.anna@gmail.com> wrote: > > 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> > -- > v7: Check entire line for "sysfs" instead of just the start of the line > --- > tools/rpcctl/rpcctl.py | 25 +++++++++++++++++++++++++ > 1 file changed, 25 insertions(+) > create mode 100755 tools/rpcctl/rpcctl.py > > diff --git a/tools/rpcctl/rpcctl.py b/tools/rpcctl/rpcctl.py > new file mode 100755 > index 000000000000..9737ac4a9740 > --- /dev/null > +++ b/tools/rpcctl/rpcctl.py > @@ -0,0 +1,25 @@ > +#!/usr/bin/python3 > +import argparse > +import pathlib > +import sys > + > +with open("/proc/mounts", 'r') as f: > + mount = [ line.split()[1] for line in f if "sysfs" in line ] > + if len(mount) == 0: > + print("ERROR: sysfs is not mounted") > + sys.exit(1) > + > +sunrpc = pathlib.Path(mount[0]) / "kernel" / "sunrpc" > +if not sunrpc.is_dir(): > + print("ERROR: sysfs does not have sunrpc directory") > + sys.exit(1) > + > +parser = argparse.ArgumentParser() > + > +def show_small_help(args): > + parser.print_usage() > + print("sunrpc dir:", sunrpc) > +parser.set_defaults(func=show_small_help) > + > +args = parser.parse_args() > +args.func(args) > -- > 2.35.0 > Might want to rework some of the directory related code to ensure you handle disappearing entries. Got Tracebacks (see below) while running a series of tests that would: - mount - run some IO - umount [root@dwysocha-fedora-node1 nfs-utils]# while true; do ./tools/rpcctl/rpcctl.py xprt; done | grep -B 5 -A 5 Traceback Traceback (most recent call last): File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> args.func(args) File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in list_all xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in <listcomp> xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] File "/usr/lib64/python3.10/pathlib.py", line 1032, in glob for p in selector.select_from(self): File "/usr/lib64/python3.10/pathlib.py", line 492, in _select_from for starting_point in self._iterate_directories(parent_path, is_dir, scandir): File "/usr/lib64/python3.10/pathlib.py", line 482, in _iterate_directories for p in self._iterate_directories(path, is_dir, scandir): File "/usr/lib64/python3.10/pathlib.py", line 471, in _iterate_directories with scandir(parent_path) as scandir_it: FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/sunrpc/xprt-switches/switch-4' Traceback (most recent call last): File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> args.func(args) File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in list_all xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in <listcomp> xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] File "/usr/lib64/python3.10/pathlib.py", line 1032, in glob for p in selector.select_from(self): File "/usr/lib64/python3.10/pathlib.py", line 492, in _select_from for starting_point in self._iterate_directories(parent_path, is_dir, scandir): File "/usr/lib64/python3.10/pathlib.py", line 482, in _iterate_directories for p in self._iterate_directories(path, is_dir, scandir): File "/usr/lib64/python3.10/pathlib.py", line 471, in _iterate_directories with scandir(parent_path) as scandir_it: FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/sunrpc/xprt-switches/switch-2' [root@dwysocha-fedora-node1 nfs-utils]# while true; do ./tools/rpcctl/rpcctl.py client; done | grep -B 10 -A 10 Traceback Traceback (most recent call last): File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> args.func(args) File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") File "/usr/lib64/python3.10/pathlib.py", line 1159, in readlink path = self._accessor.readlink(self) FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/sunrpc/rpc-clients/clnt-3/switch' Traceback (most recent call last): File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> args.func(args) File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") File "/usr/lib64/python3.10/pathlib.py", line 1159, in readlink path = self._accessor.readlink(self) FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/sunrpc/rpc-clients/clnt-7/switch' Traceback (most recent call last): File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> args.func(args) File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in __init__ self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in <listcomp> self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 49, in __init__ self.read_state() File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 81, in read_state self.state = ','.join(f.readline().split()[1:]) OSError: [Errno 19] No such device Traceback (most recent call last): File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> args.func(args) File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in __init__ self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in <listcomp> self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] File "/usr/lib64/python3.10/pathlib.py", line 1015, in iterdir for name in self._accessor.listdir(self): FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/sunrpc/rpc-clients/clnt-9/../../xprt-switches/switch-2' Traceback (most recent call last): File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> args.func(args) File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") File "/usr/lib64/python3.10/pathlib.py", line 1159, in readlink path = self._accessor.readlink(self) FileNotFoundError: [Errno 2] No such file or directory: '/sys/kernel/sunrpc/rpc-clients/clnt-5/switch' ^C
Hey Dave! On 2/1/22 10:57, David Wysochanski wrote: > On Thu, Jan 27, 2022 at 2:50 PM <schumaker.anna@gmail.com> wrote: > > Might want to rework some of the directory related code to ensure you > handle disappearing entries. Got Tracebacks (see below) while running > a series of tests that would: > - mount > - run some IO > - umount I guess I'm curious what your exception is... Shouldn't rpcctl fail after a umount or is your concern about how the command is failing? steved. > > > [root@dwysocha-fedora-node1 nfs-utils]# while true; do > ./tools/rpcctl/rpcctl.py xprt; done | grep -B 5 -A 5 Traceback > Traceback (most recent call last): > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> > args.func(args) > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in list_all > xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in <listcomp> > xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] > File "/usr/lib64/python3.10/pathlib.py", line 1032, in glob > for p in selector.select_from(self): > File "/usr/lib64/python3.10/pathlib.py", line 492, in _select_from > for starting_point in self._iterate_directories(parent_path, > is_dir, scandir): > File "/usr/lib64/python3.10/pathlib.py", line 482, in _iterate_directories > for p in self._iterate_directories(path, is_dir, scandir): > File "/usr/lib64/python3.10/pathlib.py", line 471, in _iterate_directories > with scandir(parent_path) as scandir_it: > FileNotFoundError: [Errno 2] No such file or directory: > '/sys/kernel/sunrpc/xprt-switches/switch-4' > Traceback (most recent call last): > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> > args.func(args) > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in list_all > xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 112, in <listcomp> > xprts = [ Xprt(f) for f in (sunrpc / "xprt-switches").glob("**/xprt-*") ] > File "/usr/lib64/python3.10/pathlib.py", line 1032, in glob > for p in selector.select_from(self): > File "/usr/lib64/python3.10/pathlib.py", line 492, in _select_from > for starting_point in self._iterate_directories(parent_path, > is_dir, scandir): > File "/usr/lib64/python3.10/pathlib.py", line 482, in _iterate_directories > for p in self._iterate_directories(path, is_dir, scandir): > File "/usr/lib64/python3.10/pathlib.py", line 471, in _iterate_directories > with scandir(parent_path) as scandir_it: > FileNotFoundError: [Errno 2] No such file or directory: > '/sys/kernel/sunrpc/xprt-switches/switch-2' > > > > > [root@dwysocha-fedora-node1 nfs-utils]# while true; do > ./tools/rpcctl/rpcctl.py client; done | grep -B 10 -A 10 Traceback > Traceback (most recent call last): > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> > args.func(args) > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ > self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") > File "/usr/lib64/python3.10/pathlib.py", line 1159, in readlink > path = self._accessor.readlink(self) > FileNotFoundError: [Errno 2] No such file or directory: > '/sys/kernel/sunrpc/rpc-clients/clnt-3/switch' > Traceback (most recent call last): > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> > args.func(args) > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ > self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") > File "/usr/lib64/python3.10/pathlib.py", line 1159, in readlink > path = self._accessor.readlink(self) > FileNotFoundError: [Errno 2] No such file or directory: > '/sys/kernel/sunrpc/rpc-clients/clnt-7/switch' > Traceback (most recent call last): > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> > args.func(args) > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ > self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in __init__ > self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in <listcomp> > self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 49, in __init__ > self.read_state() > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 81, in read_state > self.state = ','.join(f.readline().split()[1:]) > OSError: [Errno 19] No such device > Traceback (most recent call last): > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> > args.func(args) > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ > self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in __init__ > self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 148, in <listcomp> > self.xprts = [ Xprt(p) for p in self.path.iterdir() if p.is_dir() ] > File "/usr/lib64/python3.10/pathlib.py", line 1015, in iterdir > for name in self._accessor.listdir(self): > FileNotFoundError: [Errno 2] No such file or directory: > '/sys/kernel/sunrpc/rpc-clients/clnt-9/../../xprt-switches/switch-2' > Traceback (most recent call last): > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 230, in <module> > args.func(args) > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in list_all > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 209, in <listcomp> > clients = [ RpcClient(f) for f in (sunrpc / "rpc-clients").iterdir() ] > File "/mnt/build/nfs-utils/./tools/rpcctl/rpcctl.py", line 195, in __init__ > self.switch = XprtSwitch(path / (path / "switch").readlink(), sep=",") > File "/usr/lib64/python3.10/pathlib.py", line 1159, in readlink > path = self._accessor.readlink(self) > FileNotFoundError: [Errno 2] No such file or directory: > '/sys/kernel/sunrpc/rpc-clients/clnt-5/switch' > ^C >
diff --git a/tools/rpcctl/rpcctl.py b/tools/rpcctl/rpcctl.py new file mode 100755 index 000000000000..9737ac4a9740 --- /dev/null +++ b/tools/rpcctl/rpcctl.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 +import argparse +import pathlib +import sys + +with open("/proc/mounts", 'r') as f: + mount = [ line.split()[1] for line in f if "sysfs" in line ] + if len(mount) == 0: + print("ERROR: sysfs is not mounted") + sys.exit(1) + +sunrpc = pathlib.Path(mount[0]) / "kernel" / "sunrpc" +if not sunrpc.is_dir(): + print("ERROR: sysfs does not have sunrpc directory") + sys.exit(1) + +parser = argparse.ArgumentParser() + +def show_small_help(args): + parser.print_usage() + print("sunrpc dir:", sunrpc) +parser.set_defaults(func=show_small_help) + +args = parser.parse_args() +args.func(args)