From: david m. richter <richterd@citi.umich.edu>
Date: Tue, 31 Jul 2007 21:39:30 +0000 (-0400)
Subject: nfsstat: use macros to declare struct statinfo arrays
X-Git-Tag: nfs-utils-1-1-1~104
X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=01849ac100430ada0bf122c0be4cc78b550eb77c;p=nfs-utils.git

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>
---

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);