Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Apr 2021 22:38:47 GMT
From:      Rick Macklem <rmacklem@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: e18f9de06121 - stable/12 - nfsv4 client: fix forced dismount when sleeping in the renew thread
Message-ID:  <202104112238.13BMclhQ034088@gitrepo.freebsd.org>

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

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

commit e18f9de0612137924951a0ec709eb36286bb3894
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2021-03-23 20:04:37 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2021-04-11 22:34:52 +0000

    nfsv4 client: fix forced dismount when sleeping in the renew thread
    
    During a recent NFSv4 testing event a test server caused a hang
    where "umount -N" failed.  The renew thread was sleeping on "nfsv4lck"
    and the "umount" was sleeping, waiting for the renew thread to
    terminate.
    
    This is the second of two patches that is hoped to fix the renew thread
    so that it will terminate when "umount -N" is done on the mount.
    
    This patch adds a 5second timeout on the msleep()s and checks for
    the forced dismount flag so that the renew thread will
    wake up and see the forced dismount flag.  Normally a wakeup()
    will occur in less than 5seconds, but if a premature return from
    msleep() does occur, it will simply loop around and msleep() again.
    The patch also adds the "mp" argument to nfsv4_lock() so that it
    will return when the forced dismount flag is set.
    
    While here, replace the nfsmsleep() wrapper that was used for portability
    with the actual msleep() call.
    
    (cherry picked from commit 82ee386c2afb42388804c1189751b83048953433)
---
 sys/fs/nfsclient/nfs_clstate.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/sys/fs/nfsclient/nfs_clstate.c b/sys/fs/nfsclient/nfs_clstate.c
index 79a18a12f91f..0cade3e4178a 100644
--- a/sys/fs/nfsclient/nfs_clstate.c
+++ b/sys/fs/nfsclient/nfs_clstate.c
@@ -2531,10 +2531,12 @@ nfscl_renewthread(struct nfsclclient *clp, NFSPROC_T *p)
 	struct nfscllayouthead rlh;
 	struct nfsclrecalllayout *recallp;
 	struct nfsclds *dsp;
+	struct mount *mp;
 
 	cred = newnfs_getcred();
 	NFSLOCKCLSTATE();
 	clp->nfsc_flags |= NFSCLFLAGS_HASTHREAD;
+	mp = clp->nfsc_nmp->nm_mountp;
 	NFSUNLOCKCLSTATE();
 	for(;;) {
 		newnfs_setroot(cred);
@@ -2631,14 +2633,18 @@ tryagain:
 				    }
 				    dp->nfsdl_rwlock.nfslock_lock |=
 					NFSV4LOCK_WANTED;
-				    (void) nfsmsleep(&dp->nfsdl_rwlock,
-					NFSCLSTATEMUTEXPTR, PZERO, "nfscld",
-					NULL);
+				    msleep(&dp->nfsdl_rwlock,
+					NFSCLSTATEMUTEXPTR, PVFS, "nfscld",
+					5 * hz);
+				    if (NFSCL_FORCEDISM(mp))
+					goto terminate;
 				    goto tryagain;
 				}
 				while (!igotlock) {
 				    igotlock = nfsv4_lock(&clp->nfsc_lock, 1,
-					&islept, NFSCLSTATEMUTEXPTR, NULL);
+					&islept, NFSCLSTATEMUTEXPTR, mp);
+				    if (igotlock == 0 && NFSCL_FORCEDISM(mp))
+					goto terminate;
 				    if (islept)
 					goto tryagain;
 				}
@@ -2718,9 +2724,11 @@ tryagain2:
 				     NFSV4LOCK_LOCK) != 0) {
 					lyp->nfsly_lock.nfslock_lock |=
 					    NFSV4LOCK_WANTED;
-					nfsmsleep(&lyp->nfsly_lock.nfslock_lock,
-					    NFSCLSTATEMUTEXPTR, PZERO, "nfslyp",
-					    NULL);
+					msleep(&lyp->nfsly_lock.nfslock_lock,
+					    NFSCLSTATEMUTEXPTR, PVFS, "nfslyp",
+					    5 * hz);
+					if (NFSCL_FORCEDISM(mp))
+					    goto terminate;
 					goto tryagain2;
 				}
 				/* Move the layout to the recall list. */
@@ -2829,6 +2837,7 @@ tryagain2:
 		if ((clp->nfsc_flags & NFSCLFLAGS_RECOVER) == 0)
 			(void)mtx_sleep(clp, NFSCLSTATEMUTEXPTR, PWAIT, "nfscl",
 			    hz);
+terminate:
 		if (clp->nfsc_flags & NFSCLFLAGS_UMOUNT) {
 			clp->nfsc_flags &= ~NFSCLFLAGS_HASTHREAD;
 			NFSUNLOCKCLSTATE();



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