From c68345148131ee53dea850a348d8420a18f79ca6 Mon Sep 17 00:00:00 2001 From: "david m. richter" Date: Tue, 31 Jul 2007 17:39:11 -0400 Subject: [PATCH] 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 --- utils/nfsstat/nfsstat.c | 38 +++++++++++++++++--------------------- 1 file 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) { -- 2.39.5