]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
nfsstat: Remove some pointer comparisons against global statinfos.
authordavid m. richter <richterd@citi.umich.edu>
Mon, 13 Aug 2007 19:15:48 +0000 (15:15 -0400)
committerNeil Brown <neilb@suse.de>
Wed, 15 Aug 2007 23:10:38 +0000 (09:10 +1000)
Pass-in an "is_srv" arg instead of doing pointer comparisons
against the static statinfo arrays themselves.

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

index 6201f28df8646ab15cbe977ff6409ad7a9fa54f4..087d10234f7e0436be55859151ec281f1b5ae3e1 100644 (file)
@@ -162,9 +162,10 @@ static statinfo            *get_stat_info(const char *, struct statinfo *);
 
 static int             mounts(const char *);
 
 
 static int             mounts(const char *);
 
-static void            get_stats(const char *, statinfo *, int *, int, const char *);
+static void            get_stats(const char *, struct statinfo *, int *, int,
+                                       int);
 static int             has_stats(const unsigned int *);
 static int             has_stats(const unsigned int *);
-static void            diff_stats(statinfo *, statinfo *);
+static void            diff_stats(struct statinfo *, struct statinfo *, int);
 static void            unpause(int);
 
 static time_t          starttime;
 static void            unpause(int);
 
 static time_t          starttime;
@@ -353,9 +354,9 @@ main(int argc, char **argv)
        }
 
        if (opt_srv)
        }
 
        if (opt_srv)
-               get_stats(NFSSRVSTAT, serverinfo, &opt_srv, opt_clt, "Server");
+               get_stats(NFSSRVSTAT, serverinfo, &opt_srv, opt_clt, 1);
        if (opt_clt)
        if (opt_clt)
-               get_stats(NFSCLTSTAT, clientinfo, &opt_clt, opt_srv, "Client");
+               get_stats(NFSCLTSTAT, clientinfo, &opt_clt, opt_srv, 0);
 
        /* save stat snapshots; wait for signal; then diff current and saved stats */
        if (opt_sleep) {
 
        /* save stat snapshots; wait for signal; then diff current and saved stats */
        if (opt_sleep) {
@@ -367,12 +368,12 @@ main(int argc, char **argv)
                }
                pause();
                if (opt_srv) {
                }
                pause();
                if (opt_srv) {
-                       get_stats(NFSSRVSTAT, serverinfo_tmp, &opt_srv, opt_clt, "Server");
-                       diff_stats(serverinfo_tmp, serverinfo);
+                       get_stats(NFSSRVSTAT, serverinfo_tmp, &opt_srv, opt_clt, 1);
+                       diff_stats(serverinfo_tmp, serverinfo, 1);
                }
                if (opt_clt) {
                }
                if (opt_clt) {
-                       get_stats(NFSCLTSTAT, clientinfo_tmp, &opt_clt, opt_srv, "Client");
-                       diff_stats(clientinfo_tmp, clientinfo);
+                       get_stats(NFSCLTSTAT, clientinfo_tmp, &opt_clt, opt_srv, 0);
+                       diff_stats(clientinfo_tmp, clientinfo, 0);
                }
        }
 
                }
        }
 
@@ -634,8 +635,11 @@ mounts(const char *name)
 }
 
 static void
 }
 
 static void
-get_stats(const char *file, statinfo *info, int *opt, int other_opt, const char *label)
+get_stats(const char *file, struct statinfo *info, int *opt, int other_opt,
+               int is_srv)
 {
 {
+       const char *label = is_srv ? "Server" : "Client";
+
        if (!parse_statfile(file, info)) {
                if (!other_opt) {
                        fprintf(stderr, "Warning: No %s Stats (%s: %m). \n", label, file);
        if (!parse_statfile(file, info)) {
                if (!other_opt) {
                        fprintf(stderr, "Warning: No %s Stats (%s: %m). \n", label, file);
@@ -662,9 +666,9 @@ has_stats(const unsigned int *info)
  * and store the results back into 'new'
  */
 static void
  * and store the results back into 'new'
  */
 static void
-diff_stats(struct statinfo *new, struct statinfo *old)
+diff_stats(struct statinfo *new, struct statinfo *old, int is_srv)
 {
 {
-       int i, j, is_srv, nodiff_first_index, should_diff;
+       int i, j, nodiff_first_index, should_diff;
 
        /*
         * Different stat types have different formats in the /proc
 
        /*
         * Different stat types have different formats in the /proc
@@ -675,7 +679,6 @@ diff_stats(struct statinfo *new, struct statinfo *old)
         * procX types ("i" < 2 for clt, < 4 for srv), or if it's not
         * the first entry ("j" > 0).
         */
         * 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++) {
        nodiff_first_index = 2 + (2 * is_srv);
 
        for (i = 0; old[i].tag; i++) {