From: david m. richter Date: Tue, 31 Jul 2007 21:39:11 +0000 (-0400) Subject: nfsstat: add get_stats() X-Git-Tag: nfs-utils-1-1-1~107 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=nfs-utils.git;a=commitdiff_plain;h=c68345148131ee53dea850a348d8420a18f79ca6;hp=8bccc43fca3c33a549532a230e090a83f3e49039 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 Signed-off-by: Neil Brown --- 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) {