Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Aug 2019 05:36:42 +0000 (UTC)
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r351247 - in projects/nfsv42/sys/fs: nfs nfsserver
Message-ID:  <201908200536.x7K5ag6A029590@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rmacklem
Date: Tue Aug 20 05:36:41 2019
New Revision: 351247
URL: https://svnweb.freebsd.org/changeset/base/351247

Log:
  Add proxy support to the NFSv4.2 server Seek command so that it will
  work when a pNFS service is set up.

Modified:
  projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c
  projects/nfsv42/sys/fs/nfs/nfs_var.h
  projects/nfsv42/sys/fs/nfs/nfsport.h
  projects/nfsv42/sys/fs/nfs/nfsproto.h
  projects/nfsv42/sys/fs/nfsserver/nfs_nfsdport.c
  projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c

Modified: projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c
==============================================================================
--- projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c	Tue Aug 20 01:30:35 2019	(r351246)
+++ projects/nfsv42/sys/fs/nfs/nfs_commonsubs.c	Tue Aug 20 05:36:41 2019	(r351247)
@@ -206,7 +206,7 @@ static struct nfsrv_lughash	*nfsgroupnamehash;
  */
 static int nfs_bigreply[NFSV42_NPROCS] = { 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 };
+    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 /* local functions */
 static int nfsrv_skipace(struct nfsrv_descript *nd, int *acesizep);
@@ -284,6 +284,7 @@ static struct {
 	{ NFSV4OP_ALLOCATE, 2, "Allocate", 8, },
 	{ NFSV4OP_SAVEFH, 5, "Copy", 4, },
 	{ NFSV4OP_SEEK, 2, "Seek", 4, },
+	{ NFSV4OP_SEEK, 1, "SeekDS", 6, },
 };
 
 /*
@@ -292,7 +293,7 @@ static struct {
 static int nfs_bigrequest[NFSV42_NPROCS] = {
 	0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-	0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0
+	0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0
 };
 
 /*

Modified: projects/nfsv42/sys/fs/nfs/nfs_var.h
==============================================================================
--- projects/nfsv42/sys/fs/nfs/nfs_var.h	Tue Aug 20 01:30:35 2019	(r351246)
+++ projects/nfsv42/sys/fs/nfs/nfs_var.h	Tue Aug 20 05:36:41 2019	(r351247)
@@ -725,6 +725,8 @@ int nfsrv_dscreate(struct vnode *, struct vattr *, str
 int nfsrv_updatemdsattr(struct vnode *, struct nfsvattr *, NFSPROC_T *);
 void nfsrv_killrpcs(struct nfsmount *);
 int nfsrv_setacl(struct vnode *, NFSACL_T *, struct ucred *, NFSPROC_T *);
+int nfsvno_seek(struct vnode *, u_long, off_t *, int, bool *, struct ucred *,
+    NFSPROC_T *);
 
 /* nfs_commonkrpc.c */
 int newnfs_nmcancelreqs(struct nfsmount *);

Modified: projects/nfsv42/sys/fs/nfs/nfsport.h
==============================================================================
--- projects/nfsv42/sys/fs/nfs/nfsport.h	Tue Aug 20 01:30:35 2019	(r351246)
+++ projects/nfsv42/sys/fs/nfs/nfsport.h	Tue Aug 20 05:36:41 2019	(r351247)
@@ -398,11 +398,12 @@
 #define	NFSPROC_ALLOCATE	57
 #define	NFSPROC_COPY		58
 #define	NFSPROC_SEEK		59
+#define	NFSPROC_SEEKDS		60
 
 /*
  * Must be defined as one higher than the last NFSv4.2 Proc# above.
  */
-#define	NFSV42_NPROCS		60
+#define	NFSV42_NPROCS		61
 
 #endif	/* NFS_V3NPROCS */
 
@@ -431,7 +432,7 @@ struct nfsstatsv1 {
 	uint64_t	readlink_bios;
 	uint64_t	biocache_readdirs;
 	uint64_t	readdir_bios;
-	uint64_t	rpccnt[NFSV42_NPROCS + 9];
+	uint64_t	rpccnt[NFSV42_NPROCS + 8];
 	uint64_t	rpcretries;
 	uint64_t	srvrpccnt[NFSV42_NOPS + NFSV4OP_FAKENOPS];
 	uint64_t	srvrpc_errs;

Modified: projects/nfsv42/sys/fs/nfs/nfsproto.h
==============================================================================
--- projects/nfsv42/sys/fs/nfs/nfsproto.h	Tue Aug 20 01:30:35 2019	(r351246)
+++ projects/nfsv42/sys/fs/nfs/nfsproto.h	Tue Aug 20 05:36:41 2019	(r351247)
@@ -382,11 +382,12 @@
 #define	NFSPROC_ALLOCATE	57
 #define	NFSPROC_COPY		58
 #define	NFSPROC_SEEK		59
+#define	NFSPROC_SEEKDS		60
 
 /*
  * Must be defined as one higher than the last NFSv4.2 Proc# above.
  */
-#define	NFSV42_NPROCS		60
+#define	NFSV42_NPROCS		61
 
 #endif	/* NFS_V3NPROCS */
 

Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdport.c
==============================================================================
--- projects/nfsv42/sys/fs/nfsserver/nfs_nfsdport.c	Tue Aug 20 01:30:35 2019	(r351246)
+++ projects/nfsv42/sys/fs/nfsserver/nfs_nfsdport.c	Tue Aug 20 05:36:41 2019	(r351247)
@@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$");
  */
 
 #include <fs/nfs/nfsport.h>
+#include <sys/filio.h>
 #include <sys/hash.h>
 #include <sys/sysctl.h>
 #include <nlm/nlm_prot.h>
@@ -112,7 +113,7 @@ static void nfsrv_pnfsremove(struct vnode **, int, cha
     NFSPROC_T *);
 static int nfsrv_proxyds(struct nfsrv_descript *, struct vnode *, off_t, int,
     struct ucred *, struct thread *, int, struct mbuf **, char *,
-    struct mbuf **, struct nfsvattr *, struct acl *);
+    struct mbuf **, struct nfsvattr *, struct acl *, off_t *, int, bool *);
 static int nfsrv_setextattr(struct vnode *, struct nfsvattr *, NFSPROC_T *);
 static int nfsrv_readdsrpc(fhandle_t *, off_t, int, struct ucred *,
     NFSPROC_T *, struct nfsmount *, struct mbuf **, struct mbuf **);
@@ -125,6 +126,8 @@ static int nfsrv_setattrdsrpc(fhandle_t *, struct ucre
     struct vnode *, struct nfsmount **, int, struct nfsvattr *, int *);
 static int nfsrv_getattrdsrpc(fhandle_t *, struct ucred *, NFSPROC_T *,
     struct vnode *, struct nfsmount *, struct nfsvattr *);
+static int nfsrv_seekdsrpc(fhandle_t *, off_t *, int, bool *, struct ucred *,
+    NFSPROC_T *, struct nfsmount *);
 static int nfsrv_putfhname(fhandle_t *, char *);
 static int nfsrv_pnfslookupds(struct vnode *, struct vnode *,
     struct pnfsdsfile *, struct vnode **, NFSPROC_T *);
@@ -294,7 +297,8 @@ nfsvno_getattr(struct vnode *vp, struct nfsvattr *nvap
 	    NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_TIMEACCESS) ||
 	    NFSISSET_ATTRBIT(attrbitp, NFSATTRBIT_TIMEMODIFY))) {
 		error = nfsrv_proxyds(nd, vp, 0, 0, nd->nd_cred, p,
-		    NFSPROC_GETATTR, NULL, NULL, NULL, &na, NULL);
+		    NFSPROC_GETATTR, NULL, NULL, NULL, &na, NULL, NULL, 0,
+		    NULL);
 		if (error == 0)
 			gotattr = 1;
 	}
@@ -477,7 +481,7 @@ nfsvno_setattr(struct vnode *vp, struct nfsvattr *nvap
 	    nvap->na_vattr.va_mtime.tv_sec != VNOVAL)) {
 		/* For a pNFS server, set the attributes on the DS file. */
 		error = nfsrv_proxyds(NULL, vp, 0, 0, cred, p, NFSPROC_SETATTR,
-		    NULL, NULL, NULL, nvap, NULL);
+		    NULL, NULL, NULL, nvap, NULL, NULL, 0, NULL);
 		if (error == ENOENT)
 			error = 0;
 	}
@@ -796,7 +800,7 @@ nfsvno_read(struct vnode *vp, off_t off, int cnt, stru
 	 * there is no DS file to read.
 	 */
 	error = nfsrv_proxyds(NULL, vp, off, cnt, cred, p, NFSPROC_READDS, mpp,
-	    NULL, mpendp, NULL, NULL);
+	    NULL, mpendp, NULL, NULL, NULL, 0, NULL);
 	if (error != ENOENT)
 		return (error);
 
@@ -892,7 +896,7 @@ nfsvno_write(struct vnode *vp, off_t off, int retlen, 
 	 * there is no DS file to write.
 	 */
 	error = nfsrv_proxyds(NULL, vp, off, retlen, cred, p, NFSPROC_WRITEDS,
-	    &mp, cp, NULL, NULL, NULL);
+	    &mp, cp, NULL, NULL, NULL, NULL, 0, NULL);
 	if (error != ENOENT) {
 		*stable = NFSWRITE_FILESYNC;
 		return (error);
@@ -4378,7 +4382,7 @@ nfsrv_updatemdsattr(struct vnode *vp, struct nfsvattr 
 	/* Do this as root so that it won't fail with EACCES. */
 	tcred = newnfs_getcred();
 	error = nfsrv_proxyds(NULL, vp, 0, 0, tcred, p, NFSPROC_LAYOUTRETURN,
-	    NULL, NULL, NULL, nap, NULL);
+	    NULL, NULL, NULL, nap, NULL, NULL, 0, NULL);
 	NFSFREECRED(tcred);
 	return (error);
 }
@@ -4393,14 +4397,15 @@ nfsrv_dssetacl(struct vnode *vp, struct acl *aclp, str
 	int error;
 
 	error = nfsrv_proxyds(NULL, vp, 0, 0, cred, p, NFSPROC_SETACL,
-	    NULL, NULL, NULL, NULL, aclp);
+	    NULL, NULL, NULL, NULL, aclp, NULL, 0, NULL);
 	return (error);
 }
 
 static int
 nfsrv_proxyds(struct nfsrv_descript *nd, struct vnode *vp, off_t off, int cnt,
     struct ucred *cred, struct thread *p, int ioproc, struct mbuf **mpp,
-    char *cp, struct mbuf **mpp2, struct nfsvattr *nap, struct acl *aclp)
+    char *cp, struct mbuf **mpp2, struct nfsvattr *nap, struct acl *aclp,
+    off_t *offp, int content, bool *eofp)
 {
 	struct nfsmount *nmp[NFSDEV_MAXMIRRORS], *failnmp;
 	fhandle_t fh[NFSDEV_MAXMIRRORS];
@@ -4487,7 +4492,7 @@ tryagain:
 			origmircnt = mirrorcnt;
 		/*
 		 * If failpos is set to a mirror#, then that mirror has
-		 * failed and will be disabled. For Read and Getattr, the
+		 * failed and will be disabled. For Read, Getattr and Seek, the
 		 * function only tries one mirror, so if that mirror has
 		 * failed, it will need to be retried. As such, increment
 		 * tryitagain for these cases.
@@ -4520,7 +4525,20 @@ tryagain:
 		else if (ioproc == NFSPROC_SETACL)
 			error = nfsrv_setacldsrpc(fh, cred, p, vp, &nmp[0],
 			    mirrorcnt, aclp, &failpos);
-		else {
+		else if (ioproc == NFSPROC_SEEKDS) {
+			error = nfsrv_seekdsrpc(fh, offp, content, eofp, cred,
+			    p, nmp[0]);
+			if (nfsds_failerr(error) && mirrorcnt > 1) {
+				/*
+				 * Setting failpos will cause the mirror
+				 * to be disabled and then a retry of this
+				 * read is required.
+				 */
+				failpos = 0;
+				error = 0;
+				trycnt++;
+			}
+		} else {
 			error = nfsrv_getattrdsrpc(&fh[mirrorcnt - 1], cred, p,
 			    vp, nmp[mirrorcnt - 1], nap);
 			if (nfsds_failerr(error) && mirrorcnt > 1) {
@@ -5528,6 +5546,59 @@ nfsrv_getattrdsrpc(fhandle_t *fhp, struct ucred *cred,
 }
 
 /*
+ * Seek call to a DS.
+ */
+static int
+nfsrv_seekdsrpc(fhandle_t *fhp, off_t *offp, int content, bool *eofp,
+    struct ucred *cred, NFSPROC_T *p, struct nfsmount *nmp)
+{
+	uint32_t *tl;
+	struct nfsrv_descript *nd;
+	nfsv4stateid_t st;
+	int error;
+	
+	NFSD_DEBUG(4, "in nfsrv_seekdsrpc\n");
+	/*
+	 * Use a stateid where other is an alternating 01010 pattern and
+	 * seqid is 0xffffffff.  This value is not defined as special by
+	 * the RFC and is used by the FreeBSD NFS server to indicate an
+	 * MDS->DS proxy operation.
+	 */
+	st.other[0] = 0x55555555;
+	st.other[1] = 0x55555555;
+	st.other[2] = 0x55555555;
+	st.seqid = 0xffffffff;
+	nd = malloc(sizeof(*nd), M_TEMP, M_WAITOK | M_ZERO);
+	nfscl_reqstart(nd, NFSPROC_SEEKDS, nmp, (u_int8_t *)fhp,
+	    sizeof(fhandle_t), NULL, NULL, 0, 0);
+	nfsm_stateidtom(nd, &st, NFSSTATEID_PUTSTATEID);
+	NFSM_BUILD(tl, uint32_t *, NFSX_HYPER + NFSX_UNSIGNED);
+	txdr_hyper(*offp, tl); tl += 2;
+	*tl = txdr_unsigned(content);
+	error = newnfs_request(nd, nmp, NULL, &nmp->nm_sockreq, NULL, p, cred,
+	    NFS_PROG, NFS_VER4, NULL, 1, NULL, NULL);
+	if (error != 0) {
+		free(nd, M_TEMP);
+		return (error);
+	}
+	NFSD_DEBUG(4, "nfsrv_seekdsrpc: aft seekrpc=%d\n", nd->nd_repstat);
+	if (nd->nd_repstat == 0) {
+		NFSM_DISSECT(tl, uint32_t *, NFSX_UNSIGNED + NFSX_HYPER);
+		if (*tl++ == newnfs_true)
+			*eofp = true;
+		else
+			*eofp = false;
+		*offp = fxdr_hyper(tl);
+	} else
+		error = nd->nd_repstat;
+nfsmout:
+	m_freem(nd->nd_mrep);
+	free(nd, M_TEMP);
+	NFSD_DEBUG(4, "nfsrv_seekdsrpc error=%d\n", error);
+	return (error);
+}
+
+/*
  * Get the device id and file handle for a DS file.
  */
 int
@@ -5750,6 +5821,50 @@ nfsrv_setacl(struct vnode *vp, NFSACL_T *aclp, struct 
 	}
 
 out:
+	NFSEXITCODE(error);
+	return (error);
+}
+
+/*
+ * Seek vnode op call (actually it is a VOP_IOCTL()).
+ */
+int
+nfsvno_seek(struct vnode *vp, u_long cmd, off_t *offp, int content, bool *eofp,
+    struct ucred *cred, NFSPROC_T *p)
+{
+	struct vattr va;
+	int error, ret;
+
+	ASSERT_VOP_UNLOCKED(vp, "nfsvno_seek vp");
+	/*
+	 * Attempt to seek on a DS file. A return of ENOENT implies
+	 * there is no DS file to seek on.
+	 */
+	error = nfsrv_proxyds(NULL, vp, 0, 0, cred, p, NFSPROC_SEEKDS, NULL,
+	    NULL, NULL, NULL, NULL, offp, content, eofp);
+	if (error != ENOENT)
+		return (error);
+
+	/*
+	 * Do the VOP_IOCTL() call.  For the case where *offp == file_size,
+	 * VOP_IOCTL() will return ENXIO.  However, the correct reply for
+	 * NFSv4.2 is *eofp == true and no error return.
+	 * *eofp only needs to be set if returning error == 0.
+	 */
+	error = VOP_IOCTL(vp, cmd, offp, 0, cred, p);
+	if (error == 0)
+		*eofp = false;
+	else if (error == ENXIO) {
+		ret = vn_lock(vp, LK_SHARED);
+		if (ret == 0) {
+			ret = VOP_GETATTR(vp, &va, cred);
+			VOP_UNLOCK(vp, 0);
+		}
+		if (ret == 0 && *offp == va.va_size) {
+			*eofp = true;
+			error = 0;
+		}
+	}
 	NFSEXITCODE(error);
 	return (error);
 }

Modified: projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c
==============================================================================
--- projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c	Tue Aug 20 01:30:35 2019	(r351246)
+++ projects/nfsv42/sys/fs/nfsserver/nfs_nfsdserv.c	Tue Aug 20 05:36:41 2019	(r351247)
@@ -5416,15 +5416,12 @@ nfsrvd_seek(struct nfsrv_descript *nd, __unused int is
 	off_t off;
 	u_long cmd;
 	nfsattrbit_t attrbits;
+	bool eof;
 
 	if (nfs_rootfhset == 0 || nfsd_checkrootexp(nd) != 0) {
 		nd->nd_repstat = NFSERR_WRONGSEC;
 		goto nfsmout;
 	}
-	if (nfsrv_devidcnt > 0) {
-		nd->nd_repstat = NFSERR_NOTSUPP;
-		goto nfsmout;
-	}
 	NFSM_DISSECT(tl, uint32_t *, NFSX_STATEID + NFSX_HYPER + NFSX_UNSIGNED);
 	/* Ignore the stateid for now. */
 	tl += (NFSX_STATEID / NFSX_UNSIGNED);
@@ -5448,12 +5445,9 @@ nfsrvd_seek(struct nfsrv_descript *nd, __unused int is
 		/* Check permissions for the input file. */
 		NFSZERO_ATTRBIT(&attrbits);
 		NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_OWNER);
-		NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_SIZE);
 		nd->nd_repstat = nfsvno_getattr(vp, &at, nd, curthread, 1,
 		    &attrbits);
 	}
-	if (nd->nd_repstat == 0 && off > at.na_size)
-		nd->nd_repstat = NFSERR_NXIO;
 	if (nd->nd_repstat == 0 && (at.na_uid != nd->nd_cred->cr_uid ||
 	     NFSVNO_EXSTRICTACCESS(exp)))
 		nd->nd_repstat = nfsvno_accchk(vp, VREAD, nd->nd_cred, exp,
@@ -5462,26 +5456,13 @@ nfsrvd_seek(struct nfsrv_descript *nd, __unused int is
 	if (nd->nd_repstat != 0)
 		goto nfsmout;
 
-	if (off < at.na_size) {
-		NFSVOPUNLOCK(vp, 0);
-		nd->nd_repstat = VOP_IOCTL(vp, cmd, &off, 0, nd->nd_cred,
-		    curthread);
-		vrele(vp);
-		if (nd->nd_repstat == ENOTTY || nd->nd_repstat == ENXIO) {
-			/*
-			 * For FIOSEEKHOLE, find the "virtual hole" at EOF.
-			 * For FIOSEEKDATA, just return the offset in the
-			 * request unless the error is ENXIO.
-			 */
-			if (cmd == FIOSEEKHOLE || error == ENXIO)
-				off = at.na_size;
-			nd->nd_repstat = 0;
-		}
-	} else
-		vput(vp);
+	NFSVOPUNLOCK(vp, 0);
+	nd->nd_repstat = nfsvno_seek(vp, cmd, &off, content, &eof, nd->nd_cred,
+	    curthread);
+	vrele(vp);
 	if (nd->nd_repstat == 0) {
 		NFSM_BUILD(tl, uint32_t *, NFSX_UNSIGNED + NFSX_HYPER);
-		if (off == at.na_size)
+		if (eof)
 			*tl++ = newnfs_true;
 		else
 			*tl++ = newnfs_false;



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