summaryrefslogtreecommitdiffstats
path: root/utils/nfsstat
diff options
context:
space:
mode:
authordavid m. richter <richterd@citi.umich.edu>2007-07-31 17:39:11 -0400
committerNeil Brown <neilb@suse.de>2007-08-01 10:37:32 +1000
commitc68345148131ee53dea850a348d8420a18f79ca6 (patch)
tree91c126ddbd10e16300f29a4d9fb0ff17a6508c52 /utils/nfsstat
parent8bccc43fca3c33a549532a230e090a83f3e49039 (diff)
downloadnfs-utils-c68345148131ee53dea850a348d8420a18f79ca6.tar.gz
nfs-utils-c68345148131ee53dea850a348d8420a18f79ca6.tar.xz
nfs-utils-c68345148131ee53dea850a348d8420a18f79ca6.zip
nfsstat: add get_stats()
Share some of the existing statistics-gathering code by folding it into a function, get_stats(). Signed-off-by: David M. Richter <richterd@citi.umich.edu> Signed-off-by: Neil Brown <neilb@suse.de>
Diffstat (limited to 'utils/nfsstat')
-rw-r--r--utils/nfsstat/nfsstat.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/utils/nfsstat/nfsstat.c b/utils/nfsstat/nfsstat.c
index 7e822a7..619ce8b 100644
--- a/utils/nfsstat/nfsstat.c
+++ b/utils/nfsstat/nfsstat.c
@@ -149,6 +149,7 @@ static statinfo *get_stat_info(const char *, struct statinfo *);
static int mounts(const char *);
+static void get_stats(const char *, statinfo *, int *, int, const char *);
static int has_stats(const unsigned int *);
#define PRNT_CALLS 0x0001
@@ -217,8 +218,6 @@ main(int argc, char **argv)
int opt_all = 0,
opt_srv = 0,
opt_clt = 0,
- srv_info = 0,
- clt_info = 0,
opt_prt = 0;
int c;
char *progname;
@@ -313,25 +312,10 @@ main(int argc, char **argv)
"server.\n");
}
- if (opt_srv) {
- srv_info = parse_statfile(NFSSVCSTAT, svcinfo);
- if (srv_info == 0 && opt_clt == 0) {
- fprintf(stderr, "Warning: No Server Stats (%s: %m).\n", NFSSVCSTAT);
- return 2;
- }
- if (srv_info == 0)
- opt_srv = 0;
- }
-
- if (opt_clt) {
- clt_info = parse_statfile(NFSCLTSTAT, cltinfo);
- if (opt_srv == 0 && clt_info == 0) {
- fprintf(stderr, "Warning: No Client Stats (%s: %m).\n", NFSCLTSTAT);
- return 2;
- }
- if (clt_info == 0)
- opt_clt = 0;
- }
+ if (opt_srv)
+ get_stats(NFSSVCSTAT, svcinfo, &opt_srv, opt_clt, "Server");
+ if (opt_clt)
+ get_stats(NFSCLTSTAT, cltinfo, &opt_clt, opt_srv, "Client");
if (opt_srv) {
if (opt_prt & PRNT_NET) {
@@ -590,6 +574,18 @@ mounts(const char *name)
return 1;
}
+static void
+get_stats(const char *file, statinfo *info, int *opt, int other_opt, const char *label)
+{
+ if (!parse_statfile(file, info)) {
+ if (!other_opt) {
+ fprintf(stderr, "Warning: No %s Stats (%s: %m). \n", label, file);
+ exit(2);
+ }
+ *opt = 0;
+ }
+}
+
static int
has_stats(const unsigned int *info)
{