Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Feb 2009 22:46:30 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-7@freebsd.org
Subject:   svn commit: r188738 - in stable/7/sys: . contrib/pf dev/ath/ath_hal dev/cxgb dev/hwpmc fs/procfs kern
Message-ID:  <200902172246.n1HMkUeQ029936@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Tue Feb 17 22:46:30 2009
New Revision: 188738
URL: http://svn.freebsd.org/changeset/base/188738

Log:
  MFC: Remove unnecessary locking around vn_fullpath().  This also includes
  closing some races between procfs' <pid>/file and execve(2) and using a
  shared vnode lock for the VOP_GETATTR() in the kern.proc.vmmap sysctl
  handler.

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/dev/ath/ath_hal/   (props changed)
  stable/7/sys/dev/cxgb/   (props changed)
  stable/7/sys/dev/hwpmc/hwpmc_mod.c
  stable/7/sys/fs/procfs/procfs.c
  stable/7/sys/fs/procfs/procfs_map.c
  stable/7/sys/kern/kern_descrip.c
  stable/7/sys/kern/kern_proc.c

Modified: stable/7/sys/dev/hwpmc/hwpmc_mod.c
==============================================================================
--- stable/7/sys/dev/hwpmc/hwpmc_mod.c	Tue Feb 17 22:25:19 2009	(r188737)
+++ stable/7/sys/dev/hwpmc/hwpmc_mod.c	Tue Feb 17 22:46:30 2009	(r188738)
@@ -669,9 +669,7 @@ pmc_getfilename(struct vnode *v, char **
 	td = curthread;
 	*fullpath = "unknown";
 	*freepath = NULL;
-	vn_lock(v, LK_CANRECURSE | LK_EXCLUSIVE | LK_RETRY, td);
 	vn_fullpath(td, v, fullpath, freepath);
-	VOP_UNLOCK(v, 0, td);
 }
 
 /*

Modified: stable/7/sys/fs/procfs/procfs.c
==============================================================================
--- stable/7/sys/fs/procfs/procfs.c	Tue Feb 17 22:25:19 2009	(r188737)
+++ stable/7/sys/fs/procfs/procfs.c	Tue Feb 17 22:46:30 2009	(r188738)
@@ -70,17 +70,13 @@ procfs_doprocfile(PFS_FILL_ARGS)
 	char *fullpath = "unknown";
 	char *freepath = NULL;
 	struct vnode *textvp;
-	int err;
 
+	PROC_LOCK(p);
 	textvp = p->p_textvp;
-	VI_LOCK(textvp);
-	vholdl(textvp);
-	err = vn_lock(textvp, LK_EXCLUSIVE | LK_INTERLOCK, td);
-	vdrop(textvp);
-	if (err)
-		return (err);
+	vhold(textvp);
+	PROC_UNLOCK(p);
 	vn_fullpath(td, textvp, &fullpath, &freepath);
-	VOP_UNLOCK(textvp, 0, td);
+	vdrop(textvp);
 	sbuf_printf(sb, "%s", fullpath);
 	if (freepath)
 		free(freepath, M_TEMP);

Modified: stable/7/sys/fs/procfs/procfs_map.c
==============================================================================
--- stable/7/sys/fs/procfs/procfs_map.c	Tue Feb 17 22:25:19 2009	(r188737)
+++ stable/7/sys/fs/procfs/procfs_map.c	Tue Feb 17 22:46:30 2009	(r188738)
@@ -190,10 +190,9 @@ procfs_doprocmap(PFS_FILL_ARGS)
 			shadow_count = obj->shadow_count;
 			VM_OBJECT_UNLOCK(obj);
 			if (vp != NULL) {
-				vfslocked = VFS_LOCK_GIANT(vp->v_mount);
-				vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
 				vn_fullpath(td, vp, &fullpath, &freepath);
-				vput(vp);
+				vfslocked = VFS_LOCK_GIANT(vp->v_mount);
+				vrele(vp);
 				VFS_UNLOCK_GIANT(vfslocked);
 			}
 		} else {

Modified: stable/7/sys/kern/kern_descrip.c
==============================================================================
--- stable/7/sys/kern/kern_descrip.c	Tue Feb 17 22:25:19 2009	(r188737)
+++ stable/7/sys/kern/kern_descrip.c	Tue Feb 17 22:46:30 2009	(r188738)
@@ -2836,10 +2836,9 @@ export_vnode_for_sysctl(struct vnode *vp
 	freepath = NULL;
 	fullpath = "-";
 	FILEDESC_SUNLOCK(fdp);
-	vfslocked = VFS_LOCK_GIANT(vp->v_mount);
-	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
 	vn_fullpath(curthread, vp, &fullpath, &freepath);
-	vput(vp);
+	vfslocked = VFS_LOCK_GIANT(vp->v_mount);
+	vrele(vp);
 	VFS_UNLOCK_GIANT(vfslocked);
 	strlcpy(kif->kf_path, fullpath, sizeof(kif->kf_path));
 	if (freepath != NULL)
@@ -3001,10 +3000,9 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER
 			freepath = NULL;
 			fullpath = "-";
 			FILEDESC_SUNLOCK(fdp);
-			vfslocked = VFS_LOCK_GIANT(vp->v_mount);
-			vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, curthread);
 			vn_fullpath(curthread, vp, &fullpath, &freepath);
-			vput(vp);
+			vfslocked = VFS_LOCK_GIANT(vp->v_mount);
+			vrele(vp);
 			VFS_UNLOCK_GIANT(vfslocked);
 			strlcpy(kif->kf_path, fullpath,
 			    sizeof(kif->kf_path));

Modified: stable/7/sys/kern/kern_proc.c
==============================================================================
--- stable/7/sys/kern/kern_proc.c	Tue Feb 17 22:25:19 2009	(r188737)
+++ stable/7/sys/kern/kern_proc.c	Tue Feb 17 22:46:30 2009	(r188738)
@@ -1475,12 +1475,11 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_A
 			kve->kve_shadow_count = obj->shadow_count;
 			VM_OBJECT_UNLOCK(obj);
 			if (vp != NULL) {
-				vfslocked = VFS_LOCK_GIANT(vp->v_mount);
-				vn_lock(vp, LK_EXCLUSIVE | LK_RETRY,
-				    curthread);
 				vn_fullpath(curthread, vp, &fullpath,
 				    &freepath);
 				cred = curthread->td_ucred;
+				vfslocked = VFS_LOCK_GIANT(vp->v_mount);
+				vn_lock(vp, LK_SHARED | LK_RETRY, curthread);
 				if (VOP_GETATTR(vp, &va, cred, curthread) == 0) {
 					kve->kve_fileid = va.va_fileid;
 					kve->kve_fsid = va.va_fsid;



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