Skip to contentSkip to conversation

nfs-iostat: divide by zero with fresh mount

PATCH In review Kenneth D'souza 2 participants 2 messages Aug 24, 2020 – Aug 31, 2020

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

PATCH 1/1 nfs-iostat: divide by zero with fresh mount

When an export is freshly mounted, /proc/self/mountstats displays age = 0. This causes nfs-iostat to divide by zero throwing an error.
When we have age = 0, other stats are greater than 0, so we'll set age = 1 and print the relevant stats.

This will prevent a backtrace like this from occurring if nfsiostat is run.

nfsiostat -s 1
Traceback (most recent call last):
File "/usr/sbin/nfsiostat", line 662, in <module>
iostat_command(prog)
File "/usr/sbin/nfsiostat", line 644, in iostat_command
print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
File "/usr/sbin/nfsiostat", line 490, in print_iostat_summary
devicelist.sort(key=lambda x: stats[x].ops(time), reverse=True)
File "/usr/sbin/nfsiostat", line 490, in <lambda>
devicelist.sort(key=lambda x: stats[x].ops(time), reverse=True)
File "/usr/sbin/nfsiostat", line 383, in ops
return (sends / sample_time)
ZeroDivisionError: float division by zero

---
 tools/nfs-iostat/nfs-iostat.py | 2 ++
 1 file changed, 2 insertions(+)
tools/nfs-iostat/nfs-iostat.py +2 -0
index 5556f692..0c6c6dda 100755
@@ -383,6 +383,8 @@ class DeviceData:
         sends = float(self.__rpc_data['rpcsends'])
         if sample_time == 0:
             sample_time = float(self.__nfs_data['age'])
+        if sample_time == 0:
+            sample_time = 1;
         return (sends / sample_time)
 
     def display_iostats(self, sample_time, which):
Signature · 1 line
2.21.3
#1 lore raw
Quoted 21 lines · Kenneth D'souza

When an export is freshly mounted, /proc/self/mountstats displays age = 0. This causes nfs-iostat to divide by zero throwing an error.
When we have age = 0, other stats are greater than 0, so we'll set age = 1 and print the relevant stats.

This will prevent a backtrace like this from occurring if nfsiostat is run.

nfsiostat -s 1
Traceback (most recent call last):
File "/usr/sbin/nfsiostat", line 662, in <module>
iostat_command(prog)
File "/usr/sbin/nfsiostat", line 644, in iostat_command
print_iostat_summary(old_mountstats, mountstats, devices, sample_time, options)
File "/usr/sbin/nfsiostat", line 490, in print_iostat_summary
devicelist.sort(key=lambda x: stats[x].ops(time), reverse=True)
File "/usr/sbin/nfsiostat", line 490, in <lambda>
devicelist.sort(key=lambda x: stats[x].ops(time), reverse=True)
File "/usr/sbin/nfsiostat", line 383, in ops
return (sends / sample_time)
ZeroDivisionError: float division by zero

Quoted 1 line

Committed... (tag: nfs-utils-2-5-2-rc4)

steved.

Quoted 18 lines
---
 tools/nfs-iostat/nfs-iostat.py | 2 ++
 1 file changed, 2 insertions(+)
tools/nfs-iostat/nfs-iostat.py +2 -0
index 5556f692..0c6c6dda 100755
@@ -383,6 +383,8 @@ class DeviceData:
         sends = float(self.__rpc_data['rpcsends'])
         if sample_time == 0:
             sample_time = float(self.__nfs_data['age'])
+        if sample_time == 0:
+            sample_time = 1;
         return (sends / sample_time)
 
     def display_iostats(self, sample_time, which):