summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavid m. richter <richterd@citi.umich.edu>2007-07-31 17:39:02 -0400
committerNeil Brown <neilb@suse.de>2007-08-01 10:37:31 +1000
commit8bccc43fca3c33a549532a230e090a83f3e49039 (patch)
treeb2f0f5c3bc768a02c0fa3176c2067454dc4c4f1d
parent38145f5bceef1b3cf5ec44a752774f5bbccfbf4e (diff)
downloadnfs-utils-8bccc43fca3c33a549532a230e090a83f3e49039.tar.gz
nfs-utils-8bccc43fca3c33a549532a230e090a83f3e49039.tar.xz
nfs-utils-8bccc43fca3c33a549532a230e090a83f3e49039.zip
nfsstat: add has_stats()
To help readability, add has_stats() and use it when deciding whether to print. Signed-off-by: David M. Richter <richterd@citi.umich.edu> Signed-off-by: Neil Brown <neilb@suse.de>
-rw-r--r--utils/nfsstat/nfsstat.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/utils/nfsstat/nfsstat.c b/utils/nfsstat/nfsstat.c
index 436d407..7e822a7 100644
--- a/utils/nfsstat/nfsstat.c
+++ b/utils/nfsstat/nfsstat.c
@@ -149,6 +149,8 @@ static statinfo *get_stat_info(const char *, struct statinfo *);
static int mounts(const char *);
+static int has_stats(const unsigned int *);
+
#define PRNT_CALLS 0x0001
#define PRNT_RPC 0x0002
#define PRNT_NET 0x0004
@@ -383,17 +385,17 @@ main(int argc, char **argv)
printf("\n");
}
if (opt_prt & PRNT_CALLS) {
- if ((opt_prt & PRNT_V2) || ((opt_prt & PRNT_AUTO) && svcv2info[0] && svcv2info[svcv2info[0]+1] != svcv2info[0]))
+ if ((opt_prt & PRNT_V2) || ((opt_prt & PRNT_AUTO) && has_stats(svcv2info)))
print_callstats(
"Server nfs v2:\n",
nfsv2name, svcv2info + 1, sizeof(nfsv2name)/sizeof(char *)
);
- if ((opt_prt & PRNT_V3) || ((opt_prt & PRNT_AUTO) && svcv3info[0] && svcv3info[svcv3info[0]+1] != svcv3info[0]))
+ if ((opt_prt & PRNT_V3) || ((opt_prt & PRNT_AUTO) && has_stats(svcv3info)))
print_callstats(
"Server nfs v3:\n",
nfsv3name, svcv3info + 1, sizeof(nfsv3name)/sizeof(char *)
);
- if ((opt_prt & PRNT_V4) || ((opt_prt & PRNT_AUTO) && svcv4info[0] && svcv4info[svcv4info[0]+1] != svcv4info[0])) {
+ if ((opt_prt & PRNT_V4) || ((opt_prt & PRNT_AUTO) && has_stats(svcv4info))) {
print_callstats(
"Server nfs v4:\n",
nfssvrv4name, svcv4info + 1, sizeof(nfssvrv4name)/sizeof(char *)
@@ -424,17 +426,17 @@ main(int argc, char **argv)
printf("\n");
}
if (opt_prt & PRNT_CALLS) {
- if ((opt_prt & PRNT_V2) || ((opt_prt & PRNT_AUTO) && cltv2info[0] && cltv2info[cltv2info[0]+1] != cltv2info[0]))
+ if ((opt_prt & PRNT_V2) || ((opt_prt & PRNT_AUTO) && has_stats(cltv2info)))
print_callstats(
"Client nfs v2:\n",
nfsv2name, cltv2info + 1, sizeof(nfsv2name)/sizeof(char *)
);
- if ((opt_prt & PRNT_V3) || ((opt_prt & PRNT_AUTO) && cltv3info[0] && cltv3info[cltv3info[0]+1] != cltv3info[0]))
+ if ((opt_prt & PRNT_V3) || ((opt_prt & PRNT_AUTO) && has_stats(cltv3info)))
print_callstats(
"Client nfs v3:\n",
nfsv3name, cltv3info + 1, sizeof(nfsv3name)/sizeof(char *)
);
- if ((opt_prt & PRNT_V4) || ((opt_prt & PRNT_AUTO) && cltv4info[0] && cltv4info[cltv4info[0]+1] != cltv4info[0]))
+ if ((opt_prt & PRNT_V4) || ((opt_prt & PRNT_AUTO) && has_stats(cltv4info)))
print_callstats(
"Client nfs v4:\n",
nfscltv4name, cltv4info + 1, sizeof(nfscltv4name)/sizeof(char *)
@@ -587,3 +589,9 @@ mounts(const char *name)
fclose(fp);
return 1;
}
+
+static int
+has_stats(const unsigned int *info)
+{
+ return (info[0] && info[info[0] + 1] != info[0]);
+}