Skip to contentSkip to conversation

mountstats/nfsiostat: when parsing the mountstats file, only keep the nfs mounts

PATCH In review Frank Sorenson 2 participants 3 messages Jan 22, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mountstats/nfsiostat: when parsing the mountstats file, only keep the nfs mounts

Don't store the mountstats if the fstype is not nfs

---
 tools/mountstats/mountstats.py | 18 +++++++++++++-----
 tools/nfs-iostat/nfs-iostat.py | 16 +++++++++++-----
 2 files changed, 24 insertions(+), 10 deletions(-)
tools/mountstats/mountstats.py +13 -5
index 8e129c83..326b35c3 100755
@@ -783,25 +783,33 @@ def parse_stats_file(f):
     """pop the contents of a mountstats file into a dictionary,
     keyed by mount point.  each value object is a list of the
     lines in the mountstats file corresponding to the mount
-    point named in the key.
+    point named in the key.  Only return nfs mounts.
     """
     ms_dict = dict()
     key = ''
+    fstype = ''
 
     f.seek(0)
     for line in f.readlines():
         words = line.split()
         if len(words) == 0:
+            fstype = ''
+            continue
+        if line.startswith("no device mounted"):
+            fstype = ''
             continue
         if words[0] == 'device':
+            if 'with fstype nfs' in line:
+                fstype = words[-2]
+            else:
+                fstype = words[-1]
+
             key = words[4]
             new = [ line.strip() ]
-        elif 'nfs' in words or 'nfs4' in words:
-            key = words[3]
-            new = [ line.strip() ]
         else:
             new += [ line.strip() ]
-        ms_dict[key] = new
+        if fstype in ('nfs', 'nfs4'):
+            ms_dict[key] = new
 
     return ms_dict
 
tools/nfs-iostat/nfs-iostat.py +11 -5
index 31587370..f97b23c0 100755
@@ -445,27 +445,33 @@ def parse_stats_file(filename):
     """pop the contents of a mountstats file into a dictionary,
     keyed by mount point.  each value object is a list of the
     lines in the mountstats file corresponding to the mount
-    point named in the key.
+    point named in the key.  Only return nfs mounts.
     """
     ms_dict = dict()
     key = ''
+    fstype = ''
 
     f = open(filename)
     for line in f.readlines():
         words = line.split()
         if len(words) == 0:
+            fstype = ''
             continue
         if line.startswith("no device mounted"):
+            fstype = ''
             continue
         if words[0] == 'device':
+            if 'with fstype nfs' in line:
+                fstype = words[-2]
+            else:
+                fstype = words[-1]
+
             key = words[4]
             new = [ line.strip() ]
-        elif 'nfs' in words or 'nfs4' in words:
-            key = words[3]
-            new = [ line.strip() ]
         else:
             new += [ line.strip() ]
-        ms_dict[key] = new
+        if fstype in ('nfs', 'nfs4'):
+            ms_dict[key] = new
     f.close
 
     return ms_dict
Signature · 1 line
2.47.1
#1 lore raw

Hi Frank -

Quoted 1 line · Frank Sorenson

Don't store the mountstats if the fstype is not nfs

The original intent of mountstats is to be agnostic to the file system type. The description must provide a reason why the proposed change needs to be made.

This patch doesn't provide a bug or email link either. There's no context we reviewers can use to help understand the purpose of this patch.

Generally, a patch description needs to explain, among other things, why the change is necessary. The diff already shows /what/ the patch is doing, thus a patch description typically does not need to repeat that.

Quoted 92 lines
---
  tools/mountstats/mountstats.py | 18 +++++++++++++-----
  tools/nfs-iostat/nfs-iostat.py | 16 +++++++++++-----
  2 files changed, 24 insertions(+), 10 deletions(-)
tools/mountstats/mountstats.py +13 -5
index 8e129c83..326b35c3 100755
@@ -783,25 +783,33 @@ def parse_stats_file(f):
      """pop the contents of a mountstats file into a dictionary,
      keyed by mount point.  each value object is a list of the
      lines in the mountstats file corresponding to the mount
-    point named in the key.
+    point named in the key.  Only return nfs mounts.
      """
      ms_dict = dict()
      key = ''
+    fstype = ''
 
      f.seek(0)
      for line in f.readlines():
          words = line.split()
          if len(words) == 0:
+            fstype = ''
+            continue
+        if line.startswith("no device mounted"):
+            fstype = ''
              continue
          if words[0] == 'device':
+            if 'with fstype nfs' in line:
+                fstype = words[-2]
+            else:
+                fstype = words[-1]
+
              key = words[4]
              new = [ line.strip() ]
-        elif 'nfs' in words or 'nfs4' in words:
-            key = words[3]
-            new = [ line.strip() ]
          else:
              new += [ line.strip() ]
-        ms_dict[key] = new
+        if fstype in ('nfs', 'nfs4'):
+            ms_dict[key] = new
 
      return ms_dict
 
tools/nfs-iostat/nfs-iostat.py +11 -5
index 31587370..f97b23c0 100755
@@ -445,27 +445,33 @@ def parse_stats_file(filename):
      """pop the contents of a mountstats file into a dictionary,
      keyed by mount point.  each value object is a list of the
      lines in the mountstats file corresponding to the mount
-    point named in the key.
+    point named in the key.  Only return nfs mounts.
      """
      ms_dict = dict()
      key = ''
+    fstype = ''
 
      f = open(filename)
      for line in f.readlines():
          words = line.split()
          if len(words) == 0:
+            fstype = ''
              continue
          if line.startswith("no device mounted"):
+            fstype = ''
              continue
          if words[0] == 'device':
+            if 'with fstype nfs' in line:
+                fstype = words[-2]
+            else:
+                fstype = words[-1]
+
              key = words[4]
              new = [ line.strip() ]
-        elif 'nfs' in words or 'nfs4' in words:
-            key = words[3]
-            new = [ line.strip() ]
          else:
              new += [ line.strip() ]
-        ms_dict[key] = new
+        if fstype in ('nfs', 'nfs4'):
+            ms_dict[key] = new
      f.close
 
      return ms_dict
Signature · 1 line
Chuck Lever
#2 lore raw
Quoted 6 lines · Chuck Lever

Hi Frank -

Quoted 1 line · Frank Sorenson

Don't store the mountstats if the fstype is not nfs

The original intent of mountstats is to be agnostic to the file system

Ah, I see.  Yes, this patch certainly would have taken things the opposite direction then.  Thank you for the correction.

This patch would have made fixing some nfs-related bugs easier ('mountstats iostat' crashes after unmount, and 'nfsiostat' crashes after new mount), but it doesn't directly fix either.  I'll re-evaluate my approach, and see if I can fix them without making them (at least mountstats) nfs-specific.

Quoted 10 lines

type. The description must provide a reason why the proposed change needs to be made.

This patch doesn't provide a bug or email link either. There's no context we reviewers can use to help understand the purpose of this patch.

Generally, a patch description needs to explain, among other things, why the change is necessary. The diff already shows /what/ the patch is doing, thus a patch description typically does not need to repeat that.

Understood; explain the problem leading to the need for the fix, instead.  I failed to do that.

There was a purpose, but I neglected to explain it.  In light of my misunderstanding of the intent of mountstats, it's not important at this point.

Sorry, I'll do better.

Frank

Quoted 90 lines
Quoted 88 lines

---
  tools/mountstats/mountstats.py | 18 +++++++++++++----- tools/nfs-iostat/nfs-iostat.py | 16 +++++++++++-----

  2 files changed, 24 insertions(+), 10 deletions(-)
tools/mountstats/mountstats.py +0 -0
index 8e129c83..326b35c3 100755
@@ -783,25 +783,33 @@ def parse_stats_file(f):
       """pop the contents of a mountstats file into a dictionary,

      keyed by mount point.  each value object is a list of the lines in the mountstats file corresponding to the mount
-    point named in the key.
+    point named in the key.  Only return nfs mounts.
      """
      ms_dict = dict()
      key = ''
+    fstype = ''
        f.seek(0)
      for line in f.readlines():
          words = line.split()
          if len(words) == 0:
+            fstype = ''
+            continue
+        if line.startswith("no device mounted"):
+            fstype = ''
              continue
          if words[0] == 'device':
+            if 'with fstype nfs' in line:
+                fstype = words[-2]
+            else:
+                fstype = words[-1]
+
              key = words[4]
              new = [ line.strip() ]
-        elif 'nfs' in words or 'nfs4' in words:
-            key = words[3]
-            new = [ line.strip() ]
          else:
              new += [ line.strip() ]
-        ms_dict[key] = new
+        if fstype in ('nfs', 'nfs4'):
+            ms_dict[key] = new
        return ms_dict
  diff --git a/tools/nfs-iostat/nfs-iostat.py b/tools/nfs-iostat/nfs-iostat.py index 31587370..f97b23c0 100755

tools/nfs-iostat/nfs-iostat.py +0 -0
@@ -445,27 +445,33 @@ def parse_stats_file(filename):
       """pop the contents of a mountstats file into a dictionary,

      keyed by mount point.  each value object is a list of the lines in the mountstats file corresponding to the mount -    point named in the key.
+    point named in the key.  Only return nfs mounts. """
      ms_dict = dict()
      key = ''
+    fstype = ''
        f = open(filename)
      for line in f.readlines():
          words = line.split()
          if len(words) == 0:
+            fstype = ''
              continue
          if line.startswith("no device mounted"):
+            fstype = ''
              continue
          if words[0] == 'device':
+            if 'with fstype nfs' in line:
+                fstype = words[-2]
+            else:
+                fstype = words[-1]
+
              key = words[4]
              new = [ line.strip() ]
-        elif 'nfs' in words or 'nfs4' in words:
-            key = words[3]
-            new = [ line.strip() ]
          else:
              new += [ line.strip() ]
-        ms_dict[key] = new
+        if fstype in ('nfs', 'nfs4'):
+            ms_dict[key] = new
      f.close
        return ms_dict

Signature · 4 lines
Frank Sorenson
[email protected]
Principal Software Maintenance Engineer, filesystems
Red Hat