summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavid m. richter <richterd@citi.umich.edu>2007-07-31 17:39:30 -0400
committerNeil Brown <neilb@suse.de>2007-08-01 10:37:32 +1000
commit01849ac100430ada0bf122c0be4cc78b550eb77c (patch)
tree864b1c2135358541fbc67f73c4bbee565fc0e7aa
parentc3a44b3c50d5bd2e5db2a785e28368faa5037d31 (diff)
downloadnfs-utils-01849ac100430ada0bf122c0be4cc78b550eb77c.tar.gz
nfs-utils-01849ac100430ada0bf122c0be4cc78b550eb77c.tar.xz
nfs-utils-01849ac100430ada0bf122c0be4cc78b550eb77c.zip
nfsstat: use macros to declare struct statinfo arrays
Use macros to build the arrays of struct statinfos. This will make adding the extra set of temporary variables needed by -D/--diff-stat much easier. Signed-off-by: David M. Richter <richterd@citi.umich.edu> Signed-off-by: Neil Brown <neilb@suse.de>
-rw-r--r--utils/nfsstat/nfsstat.c52
1 files changed, 30 insertions, 22 deletions
diff --git a/utils/nfsstat/nfsstat.c b/utils/nfsstat/nfsstat.c
index 0186fa5..8f05869 100644
--- a/utils/nfsstat/nfsstat.c
+++ b/utils/nfsstat/nfsstat.c
@@ -116,28 +116,36 @@ typedef struct statinfo {
unsigned int * valptr;
} statinfo;
-#define STRUCTSIZE(x) sizeof(x)/sizeof(*x)
-
-static statinfo srvinfo[] = {
- { "net", STRUCTSIZE(srvnetinfo), srvnetinfo },
- { "rpc", STRUCTSIZE(srvrpcinfo), srvrpcinfo },
- { "rc", STRUCTSIZE(srvrcinfo), srvrcinfo },
- { "fh", STRUCTSIZE(srvfhinfo), srvfhinfo },
- { "proc2", STRUCTSIZE(srvproc2info), srvproc2info },
- { "proc3", STRUCTSIZE(srvproc3info), srvproc3info },
- { "proc4", STRUCTSIZE(srvproc4info), srvproc4info },
- { "proc4ops", STRUCTSIZE(srvproc4opsinfo),srvproc4opsinfo},
- { NULL, 0, NULL }
-};
-
-static statinfo cltinfo[] = {
- { "net", STRUCTSIZE(cltnetinfo), cltnetinfo },
- { "rpc", STRUCTSIZE(cltrpcinfo), cltrpcinfo },
- { "proc2", STRUCTSIZE(cltproc2info), cltproc2info },
- { "proc3", STRUCTSIZE(cltproc3info), cltproc3info },
- { "proc4", STRUCTSIZE(cltproc4info), cltproc4info },
- { NULL, 0, NULL }
-};
+/*
+ * We now build the arrays of statinfos using macros, which will make it easier
+ * to add new variables for --diff-stat.
+ * e.g., SRV(net) expands into the struct statinfo: { "net", 5, srvnetinfo }
+ */
+#define ARRAYSIZE(x) sizeof(x)/sizeof(*x)
+#define STATINFO(k, t, s...) { #t, ARRAYSIZE(k##t##info##s), k##t##info##s }
+#define SRV(t, s...) STATINFO(srv, t, s)
+#define CLT(t, s...) STATINFO(clt, t, s)
+#define DECLARE_SRV(n, s...) static statinfo n##s[] = { \
+ SRV(net,s), \
+ SRV(rpc,s), \
+ SRV(rc,s), \
+ SRV(fh,s), \
+ SRV(proc2,s), \
+ SRV(proc3,s),\
+ SRV(proc4,s), \
+ SRV(proc4ops,s),\
+ { NULL, 0, NULL }\
+ }
+#define DECLARE_CLT(n, s...) static statinfo n##s[] = { \
+ CLT(net,s), \
+ CLT(rpc,s), \
+ CLT(proc2,s),\
+ CLT(proc3,s), \
+ CLT(proc4,s),\
+ { NULL, 0, NULL }\
+ }
+DECLARE_SRV(srvinfo);
+DECLARE_CLT(cltinfo);
static void print_numbers(const char *, unsigned int *,
unsigned int);