Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Jun 2021 00:51:54 GMT
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: aed98fa5acb1 - main - nfscl: Make NFSv4.0 client acquisition NFSv4.1/4.2 compatible
Message-ID:  <202106160051.15G0psYF064542@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=aed98fa5acb1a62bb79fc0e182b2151b239d6239

commit aed98fa5acb1a62bb79fc0e182b2151b239d6239
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2021-06-16 00:42:13 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2021-06-16 00:48:51 +0000

    nfscl: Make NFSv4.0 client acquisition NFSv4.1/4.2 compatible
    
    When the NFSv4.0 client was implemented, acquisition of a clientid
    via SetClientID/SetClientIDConfirm was done upon the first Open,
    since that was when it was needed.  NFSv4.1/4.2 acquires the clientid
    during mount (via ExchangeID/CreateSession), since the associated
    session is required during mount.
    
    This patch modifies the NFSv4.0 mount so that it acquires the
    clientid during mount.  This simplifies the code and makes it
    easy to implement "find the highest minor version supported by
    the NFSv4 server", which will be done for the default minorversion
    in a future commit.
    The "start_renewthread" argument for nfscl_getcl() is replaced
    by "tryminvers", which will be used by the aforementioned
    future commit.
    
    MFC after:      2 weeks
---
 sys/fs/nfs/nfs_var.h            |  2 +-
 sys/fs/nfsclient/nfs_clrpcops.c | 29 ++---------------------------
 sys/fs/nfsclient/nfs_clstate.c  | 19 ++++++-------------
 sys/fs/nfsclient/nfs_clvfsops.c |  8 ++++----
 4 files changed, 13 insertions(+), 45 deletions(-)

diff --git a/sys/fs/nfs/nfs_var.h b/sys/fs/nfs/nfs_var.h
index 9db8b92f44e7..5c474d97ad04 100644
--- a/sys/fs/nfs/nfs_var.h
+++ b/sys/fs/nfs/nfs_var.h
@@ -574,7 +574,7 @@ int nfscl_getstateid(vnode_t, u_int8_t *, int, u_int32_t, int, struct ucred *,
     NFSPROC_T *, nfsv4stateid_t *, void **);
 void nfscl_ownerrelease(struct nfsmount *, struct nfsclowner *, int, int, int);
 void nfscl_openrelease(struct nfsmount *, struct nfsclopen *, int, int);
-int nfscl_getcl(struct mount *, struct ucred *, NFSPROC_T *, int,
+int nfscl_getcl(struct mount *, struct ucred *, NFSPROC_T *, bool,
     struct nfsclclient **);
 struct nfsclclient *nfscl_findcl(struct nfsmount *);
 void nfscl_clientrelease(struct nfsclclient *);
diff --git a/sys/fs/nfsclient/nfs_clrpcops.c b/sys/fs/nfsclient/nfs_clrpcops.c
index 8cb1a2d81ff5..128afb33b9ef 100644
--- a/sys/fs/nfsclient/nfs_clrpcops.c
+++ b/sys/fs/nfsclient/nfs_clrpcops.c
@@ -936,12 +936,10 @@ nfsrpc_setclient(struct nfsmount *nmp, struct nfsclclient *clp, int reclaim,
 	u_int32_t *tl;
 	struct nfsrv_descript nfsd;
 	struct nfsrv_descript *nd = &nfsd;
-	nfsattrbit_t attrbits;
 	u_int8_t *cp = NULL, *cp2, addr[INET6_ADDRSTRLEN + 9];
 	u_short port;
 	int error, isinet6 = 0, callblen;
 	nfsquad_t confirm;
-	u_int32_t lease;
 	static u_int32_t rev = 0;
 	struct nfsclds *dsp, *odsp;
 	struct in6_addr a6;
@@ -1171,29 +1169,6 @@ nfsrpc_setclient(struct nfsmount *nmp, struct nfsclclient *clp, int reclaim,
 		return (error);
 	    m_freem(nd->nd_mrep);
 	    nd->nd_mrep = NULL;
-	    if (nd->nd_repstat == 0) {
-		nfscl_reqstart(nd, NFSPROC_GETATTR, nmp, nmp->nm_fh,
-		    nmp->nm_fhsize, NULL, NULL, 0, 0);
-		NFSZERO_ATTRBIT(&attrbits);
-		NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_LEASETIME);
-		(void) nfsrv_putattrbit(nd, &attrbits);
-		nd->nd_flag |= ND_USEGSSNAME;
-		error = newnfs_request(nd, nmp, NULL, &nmp->nm_sockreq, NULL, p,
-		    cred, NFS_PROG, NFS_VER4, NULL, 1, NULL, NULL);
-		if (error)
-		    return (error);
-		if (nd->nd_repstat == 0) {
-		    error = nfsv4_loadattr(nd, NULL, NULL, NULL, NULL, 0, NULL,
-			NULL, NULL, NULL, NULL, 0, NULL, &lease, NULL, p, cred);
-		    if (error)
-			goto nfsmout;
-		    clp->nfsc_renew = NFSCL_RENEW(lease);
-		    clp->nfsc_expire = NFSD_MONOSEC + clp->nfsc_renew;
-		    clp->nfsc_clientidrev++;
-		    if (clp->nfsc_clientidrev == 0)
-			clp->nfsc_clientidrev++;
-		}
-	    }
 	}
 	error = nd->nd_repstat;
 nfsmout:
@@ -3984,7 +3959,7 @@ nfsrpc_advlock(vnode_t vp, off_t size, int op, struct flock *fl,
 	do {
 	    nd->nd_repstat = 0;
 	    if (op == F_GETLK) {
-		error = nfscl_getcl(vp->v_mount, cred, p, 1, &clp);
+		error = nfscl_getcl(vp->v_mount, cred, p, false, &clp);
 		if (error)
 			return (error);
 		error = nfscl_lockt(vp, clp, off, len, fl, p, id, flags);
@@ -4001,7 +3976,7 @@ nfsrpc_advlock(vnode_t vp, off_t size, int op, struct flock *fl,
 		 * We must loop around for all lockowner cases.
 		 */
 		callcnt = 0;
-		error = nfscl_getcl(vp->v_mount, cred, p, 1, &clp);
+		error = nfscl_getcl(vp->v_mount, cred, p, false, &clp);
 		if (error)
 			return (error);
 		do {
diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c
index 0659e77289e9..fb90c80c69e7 100644
--- a/sys/fs/nfsclient/nfs_clstate.c
+++ b/sys/fs/nfsclient/nfs_clstate.c
@@ -246,7 +246,7 @@ nfscl_open(vnode_t vp, u_int8_t *nfhp, int fhlen, u_int32_t amode, int usedeleg,
 		fhlen - 1, M_NFSCLOPEN, M_WAITOK);
 	    nop->nfso_hash.le_prev = NULL;
 	}
-	ret = nfscl_getcl(vp->v_mount, cred, p, 1, &clp);
+	ret = nfscl_getcl(vp->v_mount, cred, p, false, &clp);
 	if (ret != 0) {
 		free(nowp, M_NFSCLOWNER);
 		if (nop != NULL)
@@ -823,13 +823,11 @@ nfscl_openrelease(struct nfsmount *nmp, struct nfsclopen *op, int error,
  * If the "cred" argument is NULL, a new clientid should not be created.
  * If the "p" argument is NULL, a SetClientID/SetClientIDConfirm cannot
  * be done.
- * The start_renewthread argument tells nfscl_getcl() to start a renew
- * thread if this creates a new clp.
  * It always clpp with a reference count on it, unless returning an error.
  */
 int
 nfscl_getcl(struct mount *mp, struct ucred *cred, NFSPROC_T *p,
-    int start_renewthread, struct nfsclclient **clpp)
+    bool tryminvers, struct nfsclclient **clpp)
 {
 	struct nfsclclient *clp;
 	struct nfsclclient *newclp = NULL;
@@ -888,15 +886,10 @@ nfscl_getcl(struct mount *mp, struct ucred *cred, NFSPROC_T *p,
 		LIST_INSERT_HEAD(&nfsclhead, clp, nfsc_list);
 		nmp->nm_clp = clp;
 		clp->nfsc_nmp = nmp;
-		NFSUNLOCKCLSTATE();
-		if (start_renewthread != 0)
-			nfscl_start_renewthread(clp);
 	} else {
-		NFSUNLOCKCLSTATE();
 		if (newclp != NULL)
 			free(newclp, M_NFSCLCLIENT);
 	}
-	NFSLOCKCLSTATE();
 	while ((clp->nfsc_flags & NFSCLFLAGS_HASCLIENTID) == 0 && !igotlock &&
 	    !NFSCL_FORCEDISM(mp))
 		igotlock = nfsv4_lock(&clp->nfsc_lock, 1, NULL,
@@ -1085,7 +1078,7 @@ nfscl_getbytelock(vnode_t vp, u_int64_t off, u_int64_t len,
 		if (recovery)
 			clp = rclp;
 		else
-			error = nfscl_getcl(vp->v_mount, cred, p, 1, &clp);
+			error = nfscl_getcl(vp->v_mount, cred, p, false, &clp);
 	}
 	if (error) {
 		free(nlp, M_NFSCLLOCKOWNER);
@@ -1416,7 +1409,7 @@ nfscl_checkwritelocked(vnode_t vp, struct flock *fl,
 		end = NFS64BITSSET;
 	}
 
-	error = nfscl_getcl(vp->v_mount, cred, p, 1, &clp);
+	error = nfscl_getcl(vp->v_mount, cred, p, false, &clp);
 	if (error)
 		return (1);
 	nfscl_filllockowner(id, own, flags);
@@ -3209,7 +3202,7 @@ nfscl_getclose(vnode_t vp, struct nfsclclient **clpp)
 	struct nfsfh *nfhp;
 	int error, notdecr;
 
-	error = nfscl_getcl(vp->v_mount, NULL, NULL, 1, &clp);
+	error = nfscl_getcl(vp->v_mount, NULL, NULL, false, &clp);
 	if (error)
 		return (error);
 	*clpp = clp;
@@ -3283,7 +3276,7 @@ nfscl_doclose(vnode_t vp, struct nfsclclient **clpp, NFSPROC_T *p)
 	struct nfsclrecalllayout *recallp;
 	int error;
 
-	error = nfscl_getcl(vp->v_mount, NULL, NULL, 1, &clp);
+	error = nfscl_getcl(vp->v_mount, NULL, NULL, false, &clp);
 	if (error)
 		return (error);
 	*clpp = clp;
diff --git a/sys/fs/nfsclient/nfs_clvfsops.c b/sys/fs/nfsclient/nfs_clvfsops.c
index 847bf72acf0c..9b81777177b3 100644
--- a/sys/fs/nfsclient/nfs_clvfsops.c
+++ b/sys/fs/nfsclient/nfs_clvfsops.c
@@ -1573,10 +1573,10 @@ mountnfs(struct nfs_args *argp, struct mount *mp, struct sockaddr *nam,
 
 	if ((error = newnfs_connect(nmp, &nmp->nm_sockreq, cred, td, 0, false)))
 		goto bad;
-	/* For NFSv4.1, get the clientid now. */
-	if (nmp->nm_minorvers > 0) {
+	/* For NFSv4, get the clientid now. */
+	if ((argp->flags & NFSMNT_NFSV4) != 0) {
 		NFSCL_DEBUG(3, "at getcl\n");
-		error = nfscl_getcl(mp, cred, td, 0, &clp);
+		error = nfscl_getcl(mp, cred, td, false, &clp);
 		NFSCL_DEBUG(3, "aft getcl=%d\n", error);
 		if (error != 0)
 			goto bad;
@@ -1646,7 +1646,7 @@ mountnfs(struct nfs_args *argp, struct mount *mp, struct sockaddr *nam,
 			lease = 60;
 		}
 		(void) nfscl_loadattrcache(vpp, &nfsva, NULL, NULL, 0, 1);
-		if (nmp->nm_minorvers > 0) {
+		if ((argp->flags & NFSMNT_NFSV4) != 0) {
 			NFSCL_DEBUG(3, "lease=%d\n", (int)lease);
 			NFSLOCKCLSTATE();
 			clp->nfsc_renew = NFSCL_RENEW(lease);



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