From owner-dev-commits-src-branches@freebsd.org Sun Apr 11 22:26:52 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 061A95E1115; Sun, 11 Apr 2021 22:26:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FJRLM6mBVz4hQL; Sun, 11 Apr 2021 22:26:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DAC523ACA; Sun, 11 Apr 2021 22:26:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 13BMQpOP020822; Sun, 11 Apr 2021 22:26:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 13BMQpkb020821; Sun, 11 Apr 2021 22:26:51 GMT (envelope-from git) Date: Sun, 11 Apr 2021 22:26:51 GMT Message-Id: <202104112226.13BMQpkb020821@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Rick Macklem Subject: git: 431a136f423b - stable/13 - nfsv4 client: fix forced dismount when sleeping in the renew thread MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: rmacklem X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 431a136f423b7487fab33ea8d431af4f67b7e226 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Apr 2021 22:26:52 -0000 The branch stable/13 has been updated by rmacklem: URL: https://cgit.FreeBSD.org/src/commit/?id=431a136f423b7487fab33ea8d431af4f67b7e226 commit 431a136f423b7487fab33ea8d431af4f67b7e226 Author: Rick Macklem AuthorDate: 2021-03-23 20:04:37 +0000 Commit: Rick Macklem CommitDate: 2021-04-11 22:23:23 +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 227d82a5f7f3..4e3abf82c96a 100644 --- a/sys/fs/nfsclient/nfs_clstate.c +++ b/sys/fs/nfsclient/nfs_clstate.c @@ -2550,10 +2550,12 @@ nfscl_renewthread(struct nfsclclient *clp, NFSPROC_T *p) struct nfsclrecalllayout *recallp; struct nfsclds *dsp; bool retok; + struct mount *mp; cred = newnfs_getcred(); NFSLOCKCLSTATE(); clp->nfsc_flags |= NFSCLFLAGS_HASTHREAD; + mp = clp->nfsc_nmp->nm_mountp; NFSUNLOCKCLSTATE(); for(;;) { newnfs_setroot(cred); @@ -2652,14 +2654,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; } @@ -2739,9 +2745,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. */ @@ -2850,6 +2858,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();