Skip to contentSkip to conversation

mountstats: handle KeyError in accumulate_iostats()

PATCH In review Scott Mayhew 2 participants 4 messages Dec 10, 2015 – Dec 12, 2015

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

PATCH v2 1/2 mountstats: handle KeyError in accumulate_iostats()

This will prevent a backtrace like this from occurring in 'mountstats nfsstat' if a new NFSv4 operation is added to the kernel but not to the Nfsv4ops list in mountstats.py:

Traceback (most recent call last):
File "/sbin/mountstats", line 988, in <module>
res = main()
File "/sbin/mountstats", line 977, in main
return args.func(args)
File "/sbin/mountstats", line 792, in nfsstat_command
v4stats.accumulate_iostats(acc_stats)
File "/sbin/mountstats", line 566, in accumulate_iostats

    self.__rpc_data[op] = list(map(add, self.__rpc_data[op],

new_stats.__rpc_data[op]))
KeyError: 'SEEK'

---
 tools/mountstats/mountstats.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +4 -1
index 011bb42..1e2811f 100644
@@ -563,7 +563,10 @@ class DeviceData:
         for the nfsstat command.
         """
         for op in new_stats.__rpc_data['ops']:
-            self.__rpc_data[op] = list(map(add, self.__rpc_data[op], new_stats.__rpc_data[op]))
+            try:
+                self.__rpc_data[op] = list(map(add, self.__rpc_data[op], new_stats.__rpc_data[op]))
+            except KeyError:
+                continue
 
     def __print_rpc_op_stats(self, op, sample_time):
         """Print generic stats for one RPC op
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 2/2 mountstats: add missing v4.2 operations

---
 tools/mountstats/mountstats.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +8 -1
index 1e2811f..4ca4bc4 100644
@@ -150,6 +150,8 @@ Nfsv3ops = [
     'COMMIT'
 ]
 
+# This list should be kept in-sync with the NFSPROC4_CLNT_* enum in
+# include/linux/nfs4.h in the kernel.
 Nfsv4ops = [
     'NULL',
     'READ',
@@ -204,7 +206,12 @@ Nfsv4ops = [
     'FREE_STATEID',
     'GETDEVICELIST',
     'BIND_CONN_TO_SESSION',
-    'DESTROY_CLIENTID'
+    'DESTROY_CLIENTID',
+    'SEEK',
+    'ALLOCATE',
+    'DEALLOCATE',
+    'LAYOUTSTATS',
+    'CLONE'
 ]
 
 class DeviceData:
Signature · 1 line
2.4.3
#2 lore raw

Re: [nfs-utils PATCH v2 2/2] mountstats: add missing v4.2 operations

Quoted 1 line · Scott Mayhew

Committed...

steved.

Quoted 32 lines
---
 tools/mountstats/mountstats.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +8 -1
index 1e2811f..4ca4bc4 100644
@@ -150,6 +150,8 @@ Nfsv3ops = [
     'COMMIT'
 ]
 
+# This list should be kept in-sync with the NFSPROC4_CLNT_* enum in
+# include/linux/nfs4.h in the kernel.
 Nfsv4ops = [
     'NULL',
     'READ',
@@ -204,7 +206,12 @@ Nfsv4ops = [
     'FREE_STATEID',
     'GETDEVICELIST',
     'BIND_CONN_TO_SESSION',
-    'DESTROY_CLIENTID'
+    'DESTROY_CLIENTID',
+    'SEEK',
+    'ALLOCATE',
+    'DEALLOCATE',
+    'LAYOUTSTATS',
+    'CLONE'
 ]
 
 class DeviceData:
#3 lore raw
In reply to Scott Mayhew
Quoted 12 lines · Scott Mayhew

This will prevent a backtrace like this from occurring in 'mountstats nfsstat' if a new NFSv4 operation is added to the kernel but not to the Nfsv4ops list in mountstats.py:

Traceback (most recent call last):
File "/sbin/mountstats", line 988, in <module>
res = main()
File "/sbin/mountstats", line 977, in main
return args.func(args)
File "/sbin/mountstats", line 792, in nfsstat_command
v4stats.accumulate_iostats(acc_stats)
File "/sbin/mountstats", line 566, in accumulate_iostats

Quoted 5 lines
    self.__rpc_data[op] = list(map(add, self.__rpc_data[op],

new_stats.__rpc_data[op]))
KeyError: 'SEEK'

Committed...

steved.

Quoted 21 lines
---
 tools/mountstats/mountstats.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +4 -1
index 011bb42..1e2811f 100644
@@ -563,7 +563,10 @@ class DeviceData:
         for the nfsstat command.
         """
         for op in new_stats.__rpc_data['ops']:
-            self.__rpc_data[op] = list(map(add, self.__rpc_data[op], new_stats.__rpc_data[op]))
+            try:
+                self.__rpc_data[op] = list(map(add, self.__rpc_data[op], new_stats.__rpc_data[op]))
+            except KeyError:
+                continue
 
     def __print_rpc_op_stats(self, op, sample_time):
         """Print generic stats for one RPC op