[Midnightbsd-cvs] src: usr.bin/nfsstat: sync with freebsd7

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Fri Mar 27 18:16:58 EDT 2009


Log Message:
-----------
sync with freebsd7

Modified Files:
--------------
    src/usr.bin/nfsstat:
        nfsstat.1 (r1.1.1.1 -> r1.2)
        nfsstat.c (r1.1.1.1 -> r1.2)

-------------- next part --------------
Index: nfsstat.1
===================================================================
RCS file: /home/cvs/src/usr.bin/nfsstat/nfsstat.1,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/nfsstat/nfsstat.1 -L usr.bin/nfsstat/nfsstat.1 -u -r1.1.1.1 -r1.2
--- usr.bin/nfsstat/nfsstat.1
+++ usr.bin/nfsstat/nfsstat.1
@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     From: @(#)nfsstat.1	8.1 (Berkeley) 6/6/93
-.\" $FreeBSD: src/usr.bin/nfsstat/nfsstat.1,v 1.13 2004/07/02 22:22:29 ru Exp $
+.\" $FreeBSD: src/usr.bin/nfsstat/nfsstat.1,v 1.14.2.1 2007/10/26 21:46:31 jhb Exp $
 .\"
-.Dd June 6, 1993
+.Dd October 18, 2007
 .Dt NFSSTAT 1
 .Os
 .Sh NAME
@@ -42,7 +42,7 @@
 statistics
 .Sh SYNOPSIS
 .Nm
-.Op Fl csW
+.Op Fl cszW
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Op Fl w Ar wait
@@ -54,9 +54,9 @@
 client and server activity.
 .Pp
 The options are as follows:
-.Bl -tag -width Ds
+.Bl -tag -width indent
 .It Fl c
-Only display client side statistics
+Only display client side statistics.
 .It Fl M
 Extract values associated with the name list from the specified core
 instead of the default
@@ -65,20 +65,26 @@
 Extract the name list from the specified system instead of the default
 .Pa /boot/kernel/kernel .
 .It Fl s
-Only display server side statistics
+Only display server side statistics.
 .It Fl W
 Use wide format with interval short summary.
 This option is especially
-useful when combined with -c or -s and a time delay.
+useful when combined with
+.Fl c
+or
+.Fl s
+and a time delay.
 .It Fl w
 Display a shorter summary of
 .Tn NFS
 activity for both the client and server at
 .Ar wait
 second intervals.
+.It Fl z
+Reset statistics after displaying them.
 .El
 .Sh FILES
-.Bl -tag -width /boot/kernel/kernel -compact
+.Bl -tag -width ".Pa /boot/kernel/kernel" -compact
 .It Pa /boot/kernel/kernel
 default kernel namelist
 .It Pa /dev/kmem
Index: nfsstat.c
===================================================================
RCS file: /home/cvs/src/usr.bin/nfsstat/nfsstat.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L usr.bin/nfsstat/nfsstat.c -L usr.bin/nfsstat/nfsstat.c -u -r1.1.1.1 -r1.2
--- usr.bin/nfsstat/nfsstat.c
+++ usr.bin/nfsstat/nfsstat.c
@@ -45,7 +45,7 @@
 static char sccsid[] = "@(#)nfsstat.c	8.2 (Berkeley) 3/31/95";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/usr.bin/nfsstat/nfsstat.c,v 1.21 2004/07/11 17:37:33 stefanf Exp $";
+  "$FreeBSD: src/usr.bin/nfsstat/nfsstat.c,v 1.21.18.1 2007/10/26 21:46:32 jhb Exp $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -81,6 +81,7 @@
 
 static int deadkernel = 0;
 static int widemode = 0;
+static int zflag = 0;
 
 void intpr(int, int);
 void printhdr(int, int);
@@ -92,9 +93,7 @@
 #define DELTA(field)	(nfsstats.field - lastst.field)
 
 int
-main(argc, argv)
-	int argc;
-	char **argv;
+main(int argc, char **argv)
 {
 	u_int interval;
 	int clientOnly = -1;
@@ -105,7 +104,7 @@
 
 	interval = 0;
 	memf = nlistf = NULL;
-	while ((ch = getopt(argc, argv, "csWM:N:w:")) != -1)
+	while ((ch = getopt(argc, argv, "csWM:N:w:z")) != -1)
 		switch(ch) {
 		case 'M':
 			memf = optarg;
@@ -129,6 +128,9 @@
 			if (clientOnly < 0)
 				clientOnly = 0;
 			break;
+		case 'z':
+			zflag = 1;
+			break;
 		case '?':
 		default:
 			usage();
@@ -171,30 +173,40 @@
  * for dead ones.
  */
 void
-readstats(stp, srvstp)
-	struct nfsstats **stp;
-	struct nfsrvstats **srvstp;
+readstats(struct nfsstats **stp, struct nfsrvstats **srvstp, int zero)
 {
+	union {
+		struct nfsstats client;
+		struct nfsrvstats server;
+	} zerostat;
 	size_t buflen;
 
 	if (deadkernel) {
-		if (kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value, *stp,
-			    sizeof(struct nfsstats)) < 0) {
+		if (*stp != NULL && kvm_read(kd, (u_long)nl[N_NFSSTAT].n_value,
+		    *stp, sizeof(struct nfsstats)) < 0) {
 			*stp = NULL;
 		}
-		if (kvm_read(kd, (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
-			    sizeof(struct nfsrvstats)) < 0) {
+		if (*srvstp != NULL && kvm_read(kd,
+		    (u_long)nl[N_NFSRVSTAT].n_value, *srvstp,
+		    sizeof(struct nfsrvstats)) < 0) {
 			*srvstp = NULL;
 		}
 	} else {
+		if (zero)
+			bzero(&zerostat, sizeof(zerostat));
 		buflen = sizeof(struct nfsstats);
-		if (sysctlbyname("vfs.nfs.nfsstats", *stp, &buflen,
-		    (void *)0, (size_t)0) < 0) {
+		if (*stp != NULL && sysctlbyname("vfs.nfs.nfsstats", *stp,
+		    &buflen, zero ? &zerostat : NULL, zero ? buflen : 0) < 0) {
+			if (errno != ENOENT)
+				err(1, "sysctl: vfs.nfs.nfsstats");
 			*stp = NULL;
 		}
 		buflen = sizeof(struct nfsrvstats);
-		if (sysctlbyname("vfs.nfsrv.nfsrvstats", *srvstp, &buflen,
-		    (void *)0, (size_t)0) < 0) {
+		if (*srvstp != NULL && sysctlbyname("vfs.nfsrv.nfsrvstats",
+		    *srvstp, &buflen, zero ? &zerostat : NULL,
+		    zero ? buflen : 0) < 0) {
+			if (errno != ENOENT)
+				err(1, "sysctl: vfs.nfsrv.nfsrvstats");
 			*srvstp = NULL;
 		}
 	}
@@ -209,10 +221,20 @@
 	struct nfsstats nfsstats, *nfsstatsp;
 	struct nfsrvstats nfsrvstats, *nfsrvstatsp;
 
-	nfsstatsp = &nfsstats;
-	nfsrvstatsp = &nfsrvstats;
+	/*
+	 * Only read the stats we are going to display to avoid zeroing
+	 * stats the user didn't request.
+	 */
+	if (clientOnly)
+		nfsstatsp = &nfsstats;
+	else
+		nfsstatsp = NULL;
+	if (serverOnly)
+		nfsrvstatsp = &nfsrvstats;
+	else
+		nfsrvstatsp = NULL;
 
-	readstats(&nfsstatsp, &nfsrvstatsp);
+	readstats(&nfsstatsp, &nfsrvstatsp, zflag);
 
 	if (clientOnly && !nfsstatsp) {
 		printf("Client not present!\n");
@@ -365,7 +387,7 @@
 
 	nfsstatsp = &lastst;
 	nfsrvstatsp = &lastsrvst;
-	readstats(&nfsstatsp, &nfsrvstatsp);
+	readstats(&nfsstatsp, &nfsrvstatsp, 0);
 	if (clientOnly && !nfsstatsp) {
 		printf("Client not present!\n");
 		clientOnly = 0;
@@ -379,7 +401,7 @@
 	for (;;) {
 		nfsstatsp = &nfsstats;
 		nfsrvstatsp = &nfsrvstats;
-		readstats(&nfsstatsp, &nfsrvstatsp);
+		readstats(&nfsstatsp, &nfsrvstatsp, 0);
 
 		if (--hdrcnt == 0) {
 			printhdr(clientOnly, serverOnly);
@@ -455,10 +477,10 @@
 }
 
 void
-usage()
+usage(void)
 {
 	(void)fprintf(stderr,
-	    "usage: nfsstat [-csW] [-M core] [-N system] [-w interval]\n");
+	    "usage: nfsstat [-cszW] [-M core] [-N system] [-w interval]\n");
 	exit(1);
 }
 


More information about the Midnightbsd-cvs mailing list