Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Nov 2012 19:24:58 -0500 (EST)
From:      Rick Macklem <rmacklem@uoguelph.ca>
To:        "freebsd-fs@freebsd.org" <freebsd-fs@freebsd.org>
Subject:   testing/review of a patch that adds "nfsstat -m" to dump NFS mount options
Message-ID:  <585500992.392200.1352939098529.JavaMail.root@erie.cs.uoguelph.ca>
In-Reply-To: <1960242840.392195.1352939094946.JavaMail.root@erie.cs.uoguelph.ca>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Hi,

I've attached a pair of patches:
  nfsstat-m.patch - applies to nfsstat to add a "-m" options
  nfsstat-dumpmnt.patch - applies to the kernel to support the above

"nfsstat -m" dumps out the options actually being used by new NFS
client mounts.

Feel free to test and/or review them.

Thanks, rick

[-- Attachment #2 --]
--- usr.bin/nfsstat/nfsstat.c.sav	2012-11-14 08:34:02.000000000 -0500
+++ usr.bin/nfsstat/nfsstat.c	2012-11-14 18:09:01.000000000 -0500
@@ -107,14 +107,36 @@ main(int argc, char **argv)
 	int ch;
 	char *memf, *nlistf;
 	char errbuf[_POSIX2_LINE_MAX];
+	int mntlen, i;
+	char buf[1024];
+	struct statfs *mntbuf;
+	struct nfscl_dumpmntopts dumpmntopts;
 
 	interval = 0;
 	memf = nlistf = NULL;
-	while ((ch = getopt(argc, argv, "cesWM:N:ow:z")) != -1)
+	while ((ch = getopt(argc, argv, "cesWM:mN:ow:z")) != -1)
 		switch(ch) {
 		case 'M':
 			memf = optarg;
 			break;
+		case 'm':
+			/* Display mount options for NFS mount points. */
+			mntlen = getmntinfo(&mntbuf, MNT_NOWAIT);
+			for (i = 0; i < mntlen; i++) {
+				if (strcmp(mntbuf->f_fstypename, "nfs") == 0) {
+					dumpmntopts.ndmnt_fname =
+					    mntbuf->f_mntonname;
+					dumpmntopts.ndmnt_buf = buf;
+					dumpmntopts.ndmnt_blen = sizeof(buf);
+					if (nfssvc(NFSSVC_DUMPMNTOPTS,
+					    &dumpmntopts) >= 0)
+						printf("%s on %s\n%s\n",
+						    mntbuf->f_mntfromname,
+						    mntbuf->f_mntonname, buf);
+				}
+				mntbuf++;
+			}
+			exit(0);
 		case 'N':
 			nlistf = optarg;
 			break;
@@ -646,7 +668,7 @@ void
 usage(void)
 {
 	(void)fprintf(stderr,
-	    "usage: nfsstat [-ceoszW] [-M core] [-N system] [-w wait]\n");
+	    "usage: nfsstat [-ceomszW] [-M core] [-N system] [-w wait]\n");
 	exit(1);
 }
 
--- usr.bin/nfsstat/nfsstat.1.sav	2012-11-14 18:04:32.000000000 -0500
+++ usr.bin/nfsstat/nfsstat.1	2012-11-14 18:07:53.000000000 -0500
@@ -28,7 +28,7 @@
 .\"     From: @(#)nfsstat.1	8.1 (Berkeley) 6/6/93
 .\" $FreeBSD: stable/9/usr.bin/nfsstat/nfsstat.1 221491 2011-05-05 10:17:08Z ru $
 .\"
-.Dd May 4, 2011
+.Dd November 14, 2012
 .Dt NFSSTAT 1
 .Os
 .Sh NAME
@@ -38,7 +38,7 @@
 statistics
 .Sh SYNOPSIS
 .Nm
-.Op Fl ceoszW
+.Op Fl ceomszW
 .Op Fl M Ar core
 .Op Fl N Ar system
 .Op Fl w Ar wait
@@ -69,6 +69,11 @@ Extract the name list from the specified
 Report statistics for the old NFS client and/or server.
 Without this
 option statistics for the new NFS client and/or server will be reported.
+.It Fl m
+Report the mount options for all new NFS client mounts.
+This option overrides all others and
+.Nm
+will exit after completing the report.
 .It Fl s
 Only display server side statistics.
 .It Fl W

[-- Attachment #3 --]
--- nfs/nfssvc.h.sav2	2012-11-13 10:04:06.000000000 -0500
+++ nfs/nfssvc.h	2012-11-14 17:48:25.000000000 -0500
@@ -68,5 +68,13 @@
 #define	NFSSVC_ZEROSRVSTATS	0x02000000	/* modifier for GETSTATS */
 #define	NFSSVC_SUSPENDNFSD	0x04000000
 #define	NFSSVC_RESUMENFSD	0x08000000
+#define	NFSSVC_DUMPMNTOPTS	0x10000000
+
+/* Argument structure for NFSSVC_DUMPMNTOPTS. */
+struct nfscl_dumpmntopts {
+	char	*ndmnt_fname;		/* File Name */
+	size_t	ndmnt_blen;		/* Size of buffer */
+	void	*ndmnt_buf;		/* and the buffer */
+};
 
 #endif /* _NFS_NFSSVC_H */
--- nfs/nfs_nfssvc.c.sav2	2012-11-13 10:02:30.000000000 -0500
+++ nfs/nfs_nfssvc.c	2012-11-13 10:03:57.000000000 -0500
@@ -91,8 +91,8 @@ sys_nfssvc(struct thread *td, struct nfs
 	if ((uap->flag & (NFSSVC_ADDSOCK | NFSSVC_OLDNFSD | NFSSVC_NFSD)) &&
 	    nfsd_call_nfsserver != NULL)
 		error = (*nfsd_call_nfsserver)(td, uap);
-	else if ((uap->flag & (NFSSVC_CBADDSOCK | NFSSVC_NFSCBD)) &&
-	    nfsd_call_nfscl != NULL)
+	else if ((uap->flag & (NFSSVC_CBADDSOCK | NFSSVC_NFSCBD |
+	    NFSSVC_DUMPMNTOPTS)) && nfsd_call_nfscl != NULL)
 		error = (*nfsd_call_nfscl)(td, uap);
 	else if ((uap->flag & (NFSSVC_IDNAME | NFSSVC_GETSTATS |
 	    NFSSVC_GSSDADDPORT | NFSSVC_GSSDADDFIRST | NFSSVC_GSSDDELETEALL |
--- fs/nfs/nfs_var.h.sav2	2012-11-13 10:11:20.000000000 -0500
+++ fs/nfs/nfs_var.h	2012-11-13 10:11:55.000000000 -0500
@@ -313,6 +313,7 @@ void nfsd_init(void);
 int nfsd_checkrootexp(struct nfsrv_descript *);
 
 /* nfs_clvfsops.c */
+void nfscl_retopts(struct nfsmount *, char *, size_t);
 
 /* nfs_commonport.c */
 int nfsrv_checksockseqnum(struct socket *, tcp_seq);
--- fs/nfsclient/nfs_clport.c.sav2	2012-11-13 10:05:00.000000000 -0500
+++ fs/nfsclient/nfs_clport.c	2012-11-14 09:05:28.000000000 -0500
@@ -1232,6 +1232,9 @@ nfssvc_nfscl(struct thread *td, struct n
 	struct nfscbd_args nfscbdarg;
 	struct nfsd_nfscbd_args nfscbdarg2;
 	int error;
+	struct nameidata nd;
+	struct nfscl_dumpmntopts dumpmntopts;
+	char *buf;
 
 	if (uap->flag & NFSSVC_CBADDSOCK) {
 		error = copyin(uap->argp, (caddr_t)&nfscbdarg, sizeof(nfscbdarg));
@@ -1264,6 +1267,28 @@ nfssvc_nfscl(struct thread *td, struct n
 		if (error)
 			return (error);
 		error = nfscbd_nfsd(td, &nfscbdarg2);
+	} else if (uap->flag & NFSSVC_DUMPMNTOPTS) {
+		error = copyin(uap->argp, &dumpmntopts, sizeof(dumpmntopts));
+		if (error == 0 && (dumpmntopts.ndmnt_blen < 256 ||
+		    dumpmntopts.ndmnt_blen > 1024))
+			error = EPERM;
+		if (error == 0)
+			error = nfsrv_lookupfilename(&nd,
+			    dumpmntopts.ndmnt_fname, td);
+		if (error == 0 && strcmp(nd.ni_vp->v_mount->mnt_vfc->vfc_name,
+		    "nfs") != 0) {
+			vput(nd.ni_vp);
+			error = EPERM;
+		}
+		if (error == 0) {
+			buf = malloc(dumpmntopts.ndmnt_blen, M_TEMP, M_WAITOK);
+			nfscl_retopts(VFSTONFS(nd.ni_vp->v_mount), buf,
+			    dumpmntopts.ndmnt_blen);
+			vput(nd.ni_vp);
+			error = copyout(buf, dumpmntopts.ndmnt_buf,
+			    dumpmntopts.ndmnt_blen);
+			free(buf, M_TEMP);
+		}
 	} else {
 		error = EINVAL;
 	}
--- fs/nfsclient/nfs_clvfsops.c.sav2	2012-09-28 19:02:32.000000000 -0400
+++ fs/nfsclient/nfs_clvfsops.c	2012-11-14 18:02:26.000000000 -0500
@@ -1628,3 +1628,105 @@ nfs_getnlminfo(struct vnode *vp, uint8_t
 	}
 }
 
+/*
+ * This function prints out an option name, based on the conditional
+ * argument.
+ */
+static __inline void nfscl_printopt(struct nfsmount *nmp, int testval,
+    char *opt, char **buf, size_t *blen)
+{
+	int len;
+
+	if (testval != 0 && *blen > strlen(opt)) {
+		len = snprintf(*buf, *blen, "%s", opt);
+		if (len != strlen(opt))
+			printf("EEK!!\n");
+		*buf += len;
+		*blen -= len;
+	}
+}
+
+/*
+ * This function printf out an options integer value.
+ */
+static __inline void nfscl_printoptval(struct nfsmount *nmp, int optval,
+    char *opt, char **buf, size_t *blen)
+{
+	int len;
+
+	if (*blen > strlen(opt) + 1) {
+		/* Could result in truncated output string. */
+		len = snprintf(*buf, *blen, "%s=%d", opt, optval);
+		if (len < *blen) {
+			*buf += len;
+			*blen -= len;
+		}
+	}
+}
+
+/*
+ * Load the option flags and values into the buffer.
+ */
+void nfscl_retopts(struct nfsmount *nmp, char *buffer, size_t buflen)
+{
+	char *buf;
+	size_t blen;
+
+	buf = buffer;
+	blen = buflen;
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NFSV4) != 0, "nfsv4", &buf,
+	    &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NFSV3) != 0, "nfsv3", &buf,
+	    &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4)) == 0,
+	    "nfsv2", &buf, &blen);
+	nfscl_printopt(nmp, nmp->nm_sotype == SOCK_STREAM, ",tcp", &buf, &blen);
+	nfscl_printopt(nmp, nmp->nm_sotype != SOCK_STREAM, ",udp", &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_RESVPORT) != 0, ",resvport",
+	    &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOCONN) != 0, ",noconn",
+	    &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_SOFT) == 0, ",hard", &buf,
+	    &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_SOFT) != 0, ",soft", &buf,
+	    &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_INT) != 0, ",intr", &buf,
+	    &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOCTO) == 0, ",cto", &buf,
+	    &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOCTO) != 0, ",nocto", &buf,
+	    &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOLOCKD) == 0, ",lockd",
+	    &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_NOLOCKD) != 0, ",nolockd",
+	    &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_RDIRPLUS) != 0, ",rdirplus",
+	    &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & NFSMNT_KERB) == 0, ",sec=sys",
+	    &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_KERB | NFSMNT_INTEGRITY |
+	    NFSMNT_PRIVACY)) == NFSMNT_KERB, ",sec=krb5", &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_KERB | NFSMNT_INTEGRITY |
+	    NFSMNT_PRIVACY)) == (NFSMNT_KERB | NFSMNT_INTEGRITY), ",sec=krb5i",
+	    &buf, &blen);
+	nfscl_printopt(nmp, (nmp->nm_flag & (NFSMNT_KERB | NFSMNT_INTEGRITY |
+	    NFSMNT_PRIVACY)) == (NFSMNT_KERB | NFSMNT_PRIVACY), ",sec=krb5p",
+	    &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_acdirmin, ",acdirmin", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_acdirmax, ",acdirmax", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_acregmin, ",acregmin", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_acregmax, ",acregmax", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_nametimeo, ",nametimeo", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_negnametimeo, ",negnametimeo", &buf,
+	    &blen);
+	nfscl_printoptval(nmp, nmp->nm_rsize, ",rsize", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_wsize, ",wsize", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_readdirsize, ",readdirsize", &buf,
+	    &blen);
+	nfscl_printoptval(nmp, nmp->nm_readahead, ",readahead", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_wcommitsize, ",wcommitsize", &buf,
+	    &blen);
+	nfscl_printoptval(nmp, nmp->nm_timeo, ",timeout", &buf, &blen);
+	nfscl_printoptval(nmp, nmp->nm_retry, ",retrans", &buf, &blen);
+}
+

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?585500992.392200.1352939098529.JavaMail.root>