diff mbox series

[v2,1/9] nfs-sysfs: Add an nfs-sysfs.py tool

Message ID 20210806201739.472806-2-Anna.Schumaker@Netapp.com (mailing list archive)
State New, archived
Headers show
Series Add a tool for using the new sysfs files | expand

Commit Message

Anna Schumaker Aug. 6, 2021, 8:17 p.m. UTC
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>
---
 .gitignore                   |  2 ++
 tools/nfs-sysfs/nfs-sysfs.py | 13 +++++++++++++
 tools/nfs-sysfs/sysfs.py     | 18 ++++++++++++++++++
 3 files changed, 33 insertions(+)
 create mode 100755 tools/nfs-sysfs/nfs-sysfs.py
 create mode 100644 tools/nfs-sysfs/sysfs.py

Comments

Mora, Jorge Aug. 17, 2021, 4:57 p.m. UTC | #1
Hello Anna,

Comments are inline.

--Jorge

On 8/6/21, 2:17 PM, "Anna Schumaker on behalf of schumaker.anna@gmail.com" <schumakeranna@gmail.com on behalf of schumaker.anna@gmail.com> wrote:

    NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.




    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>
    ---
     .gitignore                   |  2 ++
     tools/nfs-sysfs/nfs-sysfs.py | 13 +++++++++++++
     tools/nfs-sysfs/sysfs.py     | 18 ++++++++++++++++++
     3 files changed, 33 insertions(+)
     create mode 100755 tools/nfs-sysfs/nfs-sysfs.py
     create mode 100644 tools/nfs-sysfs/sysfs.py

    diff --git a/.gitignore b/.gitignore
    index c89d1cd2583d..a476bd20bc3b 100644
    --- a/.gitignore
    +++ b/.gitignore
    @@ -84,3 +84,5 @@ systemd/rpc-gssd.service
     cscope.*
     # generic editor backup et al
     *~
    +# python bytecode
    +__pycache__
    diff --git a/tools/nfs-sysfs/nfs-sysfs.py b/tools/nfs-sysfs/nfs-sysfs.py
    new file mode 100755
    index 000000000000..8ff59ea9e81b
    --- /dev/null
    +++ b/tools/nfs-sysfs/nfs-sysfs.py
    @@ -0,0 +1,13 @@
    +#!/usr/bin/python
    +import argparse
    +import sysfs
    +
    +parser = argparse.ArgumentParser()
    +
    +def show_small_help(args):
    +    parser.print_usage()
    +    print("sunrpc dir:", sysfs.SUNRPC)
    +parser.set_defaults(func=show_small_help)
    +
    +args = parser.parse_args()
    +args.func(args)
    diff --git a/tools/nfs-sysfs/sysfs.py b/tools/nfs-sysfs/sysfs.py
    new file mode 100644
    index 000000000000..0b358f57bb28
    --- /dev/null
    +++ b/tools/nfs-sysfs/sysfs.py
    @@ -0,0 +1,18 @@
    +import pathlib
    +import sys
    +
    +MOUNT = None
    +with open("/proc/mounts", 'r') as f:
    +    for line in f:
JM: The following could select the wrong mount line.
    +        if "sysfs" in line:
JM: Match "sysfs" at the beginning of the line instead:
              if re.search(r"^sysfs\s", line):
    +            MOUNT = line.split()[1]
    +            break
    +
JM: The preferred way is to use "MOUNT is None", but this is just a guideline and it should work either way.
    +if MOUNT == None:
    +    print("ERROR: sysfs is not mounted")
    +    sys.exit(1)
    +
    +SUNRPC = pathlib.Path(MOUNT) / "kernel" / "sunrpc"
    +if not SUNRPC.is_dir():
    +    print("ERROR: sysfs does not have sunrpc directory")
    +    sys.exit(1)
    --
    2.32.0
Anna Schumaker Aug. 23, 2021, 9:41 p.m. UTC | #2
Hi Jorge,

On Tue, Aug 17, 2021 at 12:57 PM Mora, Jorge <Jorge.Mora@netapp.com> wrote:
>
> Hello Anna,
>
> Comments are inline.
>
> --Jorge
>
> On 8/6/21, 2:17 PM, "Anna Schumaker on behalf of schumaker.anna@gmail.com" <schumakeranna@gmail.com on behalf of schumaker.anna@gmail.com> wrote:
>
>     NetApp Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
>
>
>
>     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>
>     ---
>      .gitignore                   |  2 ++
>      tools/nfs-sysfs/nfs-sysfs.py | 13 +++++++++++++
>      tools/nfs-sysfs/sysfs.py     | 18 ++++++++++++++++++
>      3 files changed, 33 insertions(+)
>      create mode 100755 tools/nfs-sysfs/nfs-sysfs.py
>      create mode 100644 tools/nfs-sysfs/sysfs.py
>
>     diff --git a/.gitignore b/.gitignore
>     index c89d1cd2583d..a476bd20bc3b 100644
>     --- a/.gitignore
>     +++ b/.gitignore
>     @@ -84,3 +84,5 @@ systemd/rpc-gssd.service
>      cscope.*
>      # generic editor backup et al
>      *~
>     +# python bytecode
>     +__pycache__
>     diff --git a/tools/nfs-sysfs/nfs-sysfs.py b/tools/nfs-sysfs/nfs-sysfs.py
>     new file mode 100755
>     index 000000000000..8ff59ea9e81b
>     --- /dev/null
>     +++ b/tools/nfs-sysfs/nfs-sysfs.py
>     @@ -0,0 +1,13 @@
>     +#!/usr/bin/python
>     +import argparse
>     +import sysfs
>     +
>     +parser = argparse.ArgumentParser()
>     +
>     +def show_small_help(args):
>     +    parser.print_usage()
>     +    print("sunrpc dir:", sysfs.SUNRPC)
>     +parser.set_defaults(func=show_small_help)
>     +
>     +args = parser.parse_args()
>     +args.func(args)
>     diff --git a/tools/nfs-sysfs/sysfs.py b/tools/nfs-sysfs/sysfs.py
>     new file mode 100644
>     index 000000000000..0b358f57bb28
>     --- /dev/null
>     +++ b/tools/nfs-sysfs/sysfs.py
>     @@ -0,0 +1,18 @@
>     +import pathlib
>     +import sys
>     +
>     +MOUNT = None
>     +with open("/proc/mounts", 'r') as f:
>     +    for line in f:
> JM: The following could select the wrong mount line.
>     +        if "sysfs" in line:
> JM: Match "sysfs" at the beginning of the line instead:
>               if re.search(r"^sysfs\s", line):

On my system, the beginning of the line is "sys" and not "sysfs". Is
it called "sysfs" on yours? That might be something I need to account
for if it's different.

Anna

>     +            MOUNT = line.split()[1]
>     +            break
>     +
> JM: The preferred way is to use "MOUNT is None", but this is just a guideline and it should work either way.
>     +if MOUNT == None:
>     +    print("ERROR: sysfs is not mounted")
>     +    sys.exit(1)
>     +
>     +SUNRPC = pathlib.Path(MOUNT) / "kernel" / "sunrpc"
>     +if not SUNRPC.is_dir():
>     +    print("ERROR: sysfs does not have sunrpc directory")
>     +    sys.exit(1)
>     --
>     2.32.0
>
>
diff mbox series

Patch

diff --git a/.gitignore b/.gitignore
index c89d1cd2583d..a476bd20bc3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -84,3 +84,5 @@  systemd/rpc-gssd.service
 cscope.*
 # generic editor backup et al
 *~
+# python bytecode
+__pycache__
diff --git a/tools/nfs-sysfs/nfs-sysfs.py b/tools/nfs-sysfs/nfs-sysfs.py
new file mode 100755
index 000000000000..8ff59ea9e81b
--- /dev/null
+++ b/tools/nfs-sysfs/nfs-sysfs.py
@@ -0,0 +1,13 @@ 
+#!/usr/bin/python
+import argparse
+import sysfs
+
+parser = argparse.ArgumentParser()
+
+def show_small_help(args):
+    parser.print_usage()
+    print("sunrpc dir:", sysfs.SUNRPC)
+parser.set_defaults(func=show_small_help)
+
+args = parser.parse_args()
+args.func(args)
diff --git a/tools/nfs-sysfs/sysfs.py b/tools/nfs-sysfs/sysfs.py
new file mode 100644
index 000000000000..0b358f57bb28
--- /dev/null
+++ b/tools/nfs-sysfs/sysfs.py
@@ -0,0 +1,18 @@ 
+import pathlib
+import sys
+
+MOUNT = None
+with open("/proc/mounts", 'r') as f:
+    for line in f:
+        if "sysfs" in line:
+            MOUNT = line.split()[1]
+            break
+
+if MOUNT == None:
+    print("ERROR: sysfs is not mounted")
+    sys.exit(1)
+
+SUNRPC = pathlib.Path(MOUNT) / "kernel" / "sunrpc"
+if not SUNRPC.is_dir():
+    print("ERROR: sysfs does not have sunrpc directory")
+    sys.exit(1)