[PATCH 1/1] mountstats: division by zero error on new mount when 0==rpcsends

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

 



For https://bugzilla.linux-nfs.org/show_bug.cgi?id=367

When rpcsends is 0 this is the error seen when mounstats is run on a
NFSv4.2 mount:

> sudo umount /fsx ; sudo mount /fsx ; mountstats /fsx
...
RPC statistics:
  0 RPC requests sent, 0 RPC replies received (0 XIDs not found)

SERVER_CAPS:
Traceback (most recent call last):
  File "mountstats.py.orig", line 1134, in <module>
    res = main()
  File "mountstats.py.orig", line 1123, in main
    return args.func(args)
  File "mountstats.py.orig", line 863, in mountstats_command
    print_mountstats(stats, args.nfs_only, args.rpc_only, args.raw,
args.xprt_only)
  File "mountstats.py.orig", line 825, in print_mountstats
    stats.display_rpc_op_stats()
  File "mountstats.py.orig", line 486, in display_rpc_op_stats
    (count, ((count * 100) / sends)), end=' ')
ZeroDivisionError: division by zero

Fixed with:

diff --git a/tools/mountstats/mountstats.py b/tools/mountstats/mountstats.py
index 23876fc..8e129c8 100755
--- a/tools/mountstats/mountstats.py
+++ b/tools/mountstats/mountstats.py
@@ -482,8 +482,11 @@ class DeviceData:
             count = stats[1]
             if count != 0:
                 print('%s:' % stats[0])
+                ops_pcnt = 0
+                if sends != 0:
+                    ops_pcnt = (count * 100) / sends
                 print('\t%d ops (%d%%)' % \
-                    (count, ((count * 100) / sends)), end=' ')
+                    (count, ops_pcnt), end=' ')
                 retrans = stats[2] - count
                 if retrans != 0:
                     print('\t%d retrans (%d%%)' % (retrans, ((retrans
* 100) / count)), end=' ')



[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