From: Kevin Constantine Date: Tue, 22 Jun 2010 21:43:19 +0000 (-0400) Subject: nfs-iostat.py: divide by zero with fresh mount X-Git-Tag: nfs-utils-1-2-3-rc4 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=a8715bec8bd671135f20fc0422d2a9fc0993758a;p=nfs-utils.git nfs-iostat.py: divide by zero with fresh mount When an export is freshly mounted, /proc/self/mountstats displays age = 0. This causes nfs-iostat.py 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. Signed-off-by: Kevin Constantine Signed-off-by: Steve Dickson --- diff --git a/tools/nfs-iostat/nfs-iostat.py b/tools/nfs-iostat/nfs-iostat.py index 2d0b143..1207674 100644 --- a/tools/nfs-iostat/nfs-iostat.py +++ b/tools/nfs-iostat/nfs-iostat.py @@ -366,6 +366,12 @@ class DeviceData: sends = float(self.__rpc_data['rpcsends']) if sample_time == 0: sample_time = float(self.__nfs_data['age']) + # sample_time could still be zero if the export was just mounted. + # Set it to 1 to avoid divide by zero errors in this case since we'll + # likely still have relevant mount statistics to show. + # + if sample_time == 0: + sample_time = 1; if sends != 0: backlog = (float(self.__rpc_data['backlogutil']) / sends) / sample_time else: