linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stig <thatsafunnyname@gmail.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH 1/1] mountstats: division by zero error on new mount when 0==rpcsends
Date: Wed, 22 Sep 2021 16:44:00 +0100	[thread overview]
Message-ID: <CAD9POpJSfbBYVgupAFxie_N6g2BQAUZ-qWV=tZFMHMJMmdqoYw@mail.gmail.com> (raw)

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=' ')

             reply	other threads:[~2021-09-22 15:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-22 15:44 Stig [this message]
2021-09-23 16:39 ` [PATCH 1/1] mountstats: division by zero error on new mount when 0==rpcsends Steve Dickson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAD9POpJSfbBYVgupAFxie_N6g2BQAUZ-qWV=tZFMHMJMmdqoYw@mail.gmail.com' \
    --to=thatsafunnyname@gmail.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).