Skip to contentSkip to conversation

nfsiostat/mountstats: handle KeyError in compare_iostats()

PATCH In review Kenneth D'souza 2 participants 2 messages Jul 8, 2020 – Jul 17, 2020

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

PATCH 1/1 nfsiostat/mountstats: handle KeyError in compare_iostats()

This will prevent a backtrace like this from occurring if nfsiostat is run with <interval> <count>, eg: nfsiostat 1 3
This issue can occur if old_stats.__rpc_data['ops'] keys are not up to date with result.__rpc_data['ops'].
I belive this issue can also affect mountstats due to similar code, hence fix it too.

nfsiostat:217:compare_iostats:KeyError: 'NULL'

Traceback (most recent call last):
File "/usr/sbin/nfsiostat", line 649, in <module>
iostat_command(prog)
File "/usr/sbin/nfsiostat", line 617, in iostat_command
print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
File "/usr/sbin/nfsiostat", line 468, in print_iostat_summary
diff_stats[device] = stats[device].compare_iostats(old_stats)
File "/usr/sbin/nfsiostat", line 217, in compare_iostats

    difference, self.__rpc_data[op], old_stats.__rpc_data[op]))

KeyError: 'NULL'

---
 tools/mountstats/mountstats.py | 5 ++++-
 tools/nfs-iostat/nfs-iostat.py | 7 +++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
tools/mountstats/mountstats.py +4 -1
index 014f38a3..1054f698 100755
@@ -560,7 +560,10 @@ class DeviceData:
         # the reference to them.  so we build new lists here
         # for the result object.
         for op in result.__rpc_data['ops']:
-            result.__rpc_data[op] = list(map(difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            try:
+                result.__rpc_data[op] = list(map(difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            except KeyError:
+                continue
 
         # update the remaining keys
         if protocol == 'udp':
tools/nfs-iostat/nfs-iostat.py +5 -2
index b7e98a2a..5556f692 100755
@@ -213,8 +213,11 @@ class DeviceData:
         # the reference to them.  so we build new lists here
         # for the result object.
         for op in result.__rpc_data['ops']:
-            result.__rpc_data[op] = list(map(
-                difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            try:
+                result.__rpc_data[op] = list(map(
+                    difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            except KeyError:
+                continue
 
         # update the remaining keys we care about
         result.__rpc_data['rpcsends'] -= old_stats.__rpc_data['rpcsends']
Signature · 1 line
2.21.1
#1 lore raw
Quoted 17 lines · Kenneth D'souza

This will prevent a backtrace like this from occurring if nfsiostat is run with <interval> <count>, eg: nfsiostat 1 3
This issue can occur if old_stats.__rpc_data['ops'] keys are not up to date with result.__rpc_data['ops'].
I belive this issue can also affect mountstats due to similar code, hence fix it too.

nfsiostat:217:compare_iostats:KeyError: 'NULL'

Traceback (most recent call last):
File "/usr/sbin/nfsiostat", line 649, in <module>
iostat_command(prog)
File "/usr/sbin/nfsiostat", line 617, in iostat_command
print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
File "/usr/sbin/nfsiostat", line 468, in print_iostat_summary
diff_stats[device] = stats[device].compare_iostats(old_stats)
File "/usr/sbin/nfsiostat", line 217, in compare_iostats

Quoted 4 lines
    difference, self.__rpc_data[op], old_stats.__rpc_data[op]))

KeyError: 'NULL'

Committed... (tag: nfs-utils-2-5-2-rc2

steved.

Quoted 40 lines
---
 tools/mountstats/mountstats.py | 5 ++++-
 tools/nfs-iostat/nfs-iostat.py | 7 +++++--
 2 files changed, 9 insertions(+), 3 deletions(-)
tools/mountstats/mountstats.py +4 -1
index 014f38a3..1054f698 100755
@@ -560,7 +560,10 @@ class DeviceData:
         # the reference to them.  so we build new lists here
         # for the result object.
         for op in result.__rpc_data['ops']:
-            result.__rpc_data[op] = list(map(difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            try:
+                result.__rpc_data[op] = list(map(difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            except KeyError:
+                continue
 
         # update the remaining keys
         if protocol == 'udp':
tools/nfs-iostat/nfs-iostat.py +5 -2
index b7e98a2a..5556f692 100755
@@ -213,8 +213,11 @@ class DeviceData:
         # the reference to them.  so we build new lists here
         # for the result object.
         for op in result.__rpc_data['ops']:
-            result.__rpc_data[op] = list(map(
-                difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            try:
+                result.__rpc_data[op] = list(map(
+                    difference, self.__rpc_data[op], old_stats.__rpc_data[op]))
+            except KeyError:
+                continue
 
         # update the remaining keys we care about
         result.__rpc_data['rpcsends'] -= old_stats.__rpc_data['rpcsends']