From owner-svn-src-all@FreeBSD.ORG Sat May 4 22:05:44 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 56B57429; Sat, 4 May 2013 22:05:44 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 38894266; Sat, 4 May 2013 22:05:44 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r44M5i6K067478; Sat, 4 May 2013 22:05:44 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r44M5hLR067470; Sat, 4 May 2013 22:05:43 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201305042205.r44M5hLR067470@svn.freebsd.org> From: Rick Macklem Date: Sat, 4 May 2013 22:05:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r250258 - in stable/9/sys: fs/nfsclient nfsclient X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 May 2013 22:05:44 -0000 Author: rmacklem Date: Sat May 4 22:05:43 2013 New Revision: 250258 URL: http://svnweb.freebsd.org/changeset/base/250258 Log: MFC: r249630 When an NFS unmount occurs, once vflush() writes the last dirty buffer for the last vnode on the mount back to the server, it returns. At that point, the code continues with the unmount, including freeing up the nfs specific part of the mount structure. It is possible that an nfsiod thread will try to check for an empty I/O queue in the nfs specific part of the mount structure after it has been free'd by the unmount. This patch avoids this problem by setting the iodmount entries for the mount back to NULL while holding the mutex in the unmount and checking the appropriate entry is non-NULL after acquiring the mutex in the nfsiod thread. Modified: stable/9/sys/fs/nfsclient/nfs_clnfsiod.c stable/9/sys/fs/nfsclient/nfs_clvfsops.c stable/9/sys/nfsclient/nfs_nfsiod.c stable/9/sys/nfsclient/nfs_vfsops.c Directory Properties: stable/9/sys/ (props changed) stable/9/sys/fs/ (props changed) Modified: stable/9/sys/fs/nfsclient/nfs_clnfsiod.c ============================================================================== --- stable/9/sys/fs/nfsclient/nfs_clnfsiod.c Sat May 4 21:56:39 2013 (r250257) +++ stable/9/sys/fs/nfsclient/nfs_clnfsiod.c Sat May 4 22:05:43 2013 (r250258) @@ -304,6 +304,14 @@ nfssvc_iod(void *instance) } mtx_lock(&ncl_iod_mutex); /* + * Make sure the nmp hasn't been dismounted as soon as + * ncl_doio() completes for the last buffer. + */ + nmp = ncl_iodmount[myiod]; + if (nmp == NULL) + break; + + /* * If there are more than one iod on this mount, then defect * so that the iods can be shared out fairly between the mounts */ Modified: stable/9/sys/fs/nfsclient/nfs_clvfsops.c ============================================================================== --- stable/9/sys/fs/nfsclient/nfs_clvfsops.c Sat May 4 21:56:39 2013 (r250257) +++ stable/9/sys/fs/nfsclient/nfs_clvfsops.c Sat May 4 22:05:43 2013 (r250258) @@ -80,6 +80,9 @@ extern int nfscl_ticks; extern struct timeval nfsboottime; extern struct nfsstats newnfsstats; extern int nfsrv_useacl; +extern enum nfsiod_state ncl_iodwant[NFS_MAXASYNCDAEMON]; +extern struct nfsmount *ncl_iodmount[NFS_MAXASYNCDAEMON]; +extern struct mtx ncl_iod_mutex; MALLOC_DEFINE(M_NEWNFSREQ, "newnfsclient_req", "New NFS request header"); MALLOC_DEFINE(M_NEWNFSMNT, "newnfsmnt", "New NFS mount struct"); @@ -1410,7 +1413,7 @@ nfs_unmount(struct mount *mp, int mntfla { struct thread *td; struct nfsmount *nmp; - int error, flags = 0, trycnt = 0; + int error, flags = 0, i, trycnt = 0; td = curthread; @@ -1445,6 +1448,14 @@ nfs_unmount(struct mount *mp, int mntfla */ if ((mntflags & MNT_FORCE) == 0) nfscl_umount(nmp, td); + /* Make sure no nfsiods are assigned to this mount. */ + mtx_lock(&ncl_iod_mutex); + for (i = 0; i < NFS_MAXASYNCDAEMON; i++) + if (ncl_iodmount[i] == nmp) { + ncl_iodwant[i] = NFSIOD_AVAILABLE; + ncl_iodmount[i] = NULL; + } + mtx_unlock(&ncl_iod_mutex); newnfs_disconnect(&nmp->nm_sockreq); crfree(nmp->nm_sockreq.nr_cred); FREE(nmp->nm_nam, M_SONAME); Modified: stable/9/sys/nfsclient/nfs_nfsiod.c ============================================================================== --- stable/9/sys/nfsclient/nfs_nfsiod.c Sat May 4 21:56:39 2013 (r250257) +++ stable/9/sys/nfsclient/nfs_nfsiod.c Sat May 4 22:05:43 2013 (r250258) @@ -308,6 +308,14 @@ nfssvc_iod(void *instance) mtx_unlock(&Giant); mtx_lock(&nfs_iod_mtx); /* + * Make sure the nmp hasn't been dismounted as soon as + * nfs_doio() completes for the last buffer. + */ + nmp = nfs_iodmount[myiod]; + if (nmp == NULL) + break; + + /* * If there are more than one iod on this mount, then defect * so that the iods can be shared out fairly between the mounts */ Modified: stable/9/sys/nfsclient/nfs_vfsops.c ============================================================================== --- stable/9/sys/nfsclient/nfs_vfsops.c Sat May 4 21:56:39 2013 (r250257) +++ stable/9/sys/nfsclient/nfs_vfsops.c Sat May 4 22:05:43 2013 (r250258) @@ -1362,7 +1362,7 @@ static int nfs_unmount(struct mount *mp, int mntflags) { struct nfsmount *nmp; - int error, flags = 0; + int error, flags = 0, i; if (mntflags & MNT_FORCE) flags |= FORCECLOSE; @@ -1387,6 +1387,14 @@ nfs_unmount(struct mount *mp, int mntfla /* * We are now committed to the unmount. */ + /* Make sure no nfsiods are assigned to this mount. */ + mtx_lock(&nfs_iod_mtx); + for (i = 0; i < NFS_MAXASYNCDAEMON; i++) + if (nfs_iodmount[i] == nmp) { + nfs_iodwant[i] = NFSIOD_AVAILABLE; + nfs_iodmount[i] = NULL; + } + mtx_unlock(&nfs_iod_mtx); nfs_disconnect(nmp); free(nmp->nm_nam, M_SONAME);