]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
nfsstat: fix a bug in diff_stats()
authordavid m. richter <richterd@citi.umich.edu>
Tue, 7 Aug 2007 23:53:00 +0000 (19:53 -0400)
committerNeil Brown <neilb@suse.de>
Thu, 9 Aug 2007 01:08:28 +0000 (11:08 +1000)
Fix a bug in diff_stats() that causes false-positives in
has_stats(), which can result in a bunch of zeros being displayed instead
of suppressed as intended.

Signed-off-by: David M. Richter <richterd@citi.umich.edu>
Signed-off-by: Neil Brown <neilb@suse.de>
utils/nfsstat/nfsstat.c

index eb6e45d2a7f11056bcec5105884f80ebd1cf17c4..1c44050e3e17ddfa9e93eed47ba757465b017bce 100644 (file)
@@ -671,16 +671,37 @@ copy_stats(struct statinfo *dest, struct statinfo *src)
 static void
 diff_stats(struct statinfo *new, struct statinfo *old)
 {
-       int i, j, is_srv, should_diff;
-
+       int i, j, is_srv, nodiff_first_index, should_diff;
+
+       /*
+        * Different stat types have different formats in the /proc
+        * files: for the proc2/3/4-type stats, the first entry has
+        * the total number of subsequent entries; one does not want
+        * to diff that first entry.  The other stat types aren't like
+        * this.  So, we diff a given entry if it's not of one of the
+        * procX types ("i" < 2 for clt, < 4 for srv), or if it's not
+        * the first entry ("j" > 0).
+        */
        is_srv = (new == srvinfo);
+       nodiff_first_index = 2 + (2 * is_srv);
+
        for (i = 0; old[i].tag; i++) {
                for (j = 0; j < new[i].nrvals; j++) {
-                       /* skip items in valptr that shouldn't be changed */
-                       should_diff = (i < (3 + is_srv) || j > 0);
+                       should_diff = (i < nodiff_first_index || j > 0);
                        if (should_diff)
                                new[i].valptr[j] -= old[i].valptr[j];
                }
+
+               /*
+                * Make sure that the "totals" entry (last value in
+                * each stat array) for the procX-type stats has the
+                * "numentries" entry's (first value in procX-type
+                * stat arrays) constant value added-back after the
+                * diff -- i.e., it should always be included in the
+                * total.
+                */
+               if (!strncmp("proc", new[i].tag, 4))
+                       new[i].valptr[new[i].nrvals - 1] += new[i].valptr[0];
        }
 }