#define NFSSVCSTAT "/proc/net/rpc/nfsd"
#define NFSCLTSTAT "/proc/net/rpc/nfs"
+#define MOUNTSFILE "/proc/mounts"
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
static statinfo *get_stat_info(const char *, struct statinfo *);
+static int mounts(const char *);
#define PRNT_CALLS 0x0001
#define PRNT_RPC 0x0002
int opt_all = 0,
opt_srv = 0,
opt_clt = 0,
+ srv_info = 0,
+ clt_info = 0,
opt_prt = 0;
int c;
- while ((c = getopt(argc, argv, "acno:rsz")) != -1) {
+ while ((c = getopt(argc, argv, "acmno:rsz")) != -1) {
switch (c) {
case 'a':
opt_all = 1;
fprintf(stderr, "nfsstat: zeroing of nfs statistics "
"not yet supported\n");
return 2;
+ case 'm':
+ return mounts(MOUNTSFILE);
}
}
"server.\n");
}
- if ((opt_srv && !parse_statfile(NFSSVCSTAT, svcinfo))
- || (opt_clt && !parse_statfile(NFSCLTSTAT, cltinfo)))
- return 2;
+ 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) {
if (opt_prt & PRNT_NET) {
* be a fatal error -- it usually means the module isn't loaded.
*/
if ((fp = fopen(name, "r")) == NULL) {
- fprintf(stderr, "Warning: %s: %m\n", name);
- return 1;
+ // fprintf(stderr, "Warning: %s: %m\n", name);
+ return 0;
}
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
fclose(fp);
return 1;
}
+
+static int
+mounts(const char *name)
+{
+ char buffer[4096], *next;
+ FILE *fp;
+
+ /* Being unable to read e.g. the nfsd stats file shouldn't
+ * be a fatal error -- it usually means the module isn't loaded.
+ */
+ if ((fp = fopen(name, "r")) == NULL) {
+ fprintf(stderr, "Warning: %s: %m\n", name);
+ return -1;
+ }
+
+ while (fgets(buffer, sizeof(buffer), fp) != NULL) {
+ char *line = buffer;
+ char *device, *mount, *type, *flags;
+
+ if ((next = strchr(line, '\n')) != NULL)
+ *next = '\0';
+
+ if (!(device = strtok(line, " \t")))
+ continue;
+
+ if (!(mount = strtok(NULL, " \t")))
+ continue;
+
+ if (!(type = strtok(NULL, " \t")))
+ continue;
+
+ if (strcmp(type, "nfs")) {
+ continue;
+ }
+
+ if (!(flags = strtok(NULL, " \t")))
+ continue;
+
+ printf("%s from %s\n", mount, device);
+ printf(" Flags:\t%s\n", flags);
+ printf("\n");
+
+ continue;
+ }
+
+ fclose(fp);
+ return 0;
+}