Re: [PATCH] nfs-iostat: divide by zero with fresh mount

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 8/24/20 11:05 AM, Kenneth D'souza wrote:
> 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
> 
> Signed-off-by: Kenneth D'souza <kdsouza@xxxxxxxxxx>
Committed... (tag: nfs-utils-2-5-2-rc4)

steved.
> ---
>  tools/nfs-iostat/nfs-iostat.py | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/tools/nfs-iostat/nfs-iostat.py b/tools/nfs-iostat/nfs-iostat.py
> index 5556f692..0c6c6dda 100755
> --- a/tools/nfs-iostat/nfs-iostat.py
> +++ b/tools/nfs-iostat/nfs-iostat.py
> @@ -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):
> 




[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux