Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 Jul 2007 15:54:14 GMT
From:      Roman Divacky <rdivacky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 123972 for review
Message-ID:  <200707231554.l6NFsEri080188@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=123972

Change 123972 by rdivacky@rdivacky_witten on 2007/07/23 15:53:18

	Fix some Giant leaks.
	
	Suggested by: kib

Affected files ...

.. //depot/projects/soc2007/rdivacky/linux_at/sys/kern/vfs_syscalls.c#50 edit

Differences ...

==== //depot/projects/soc2007/rdivacky/linux_at/sys/kern/vfs_syscalls.c#50 (text+ko) ====

@@ -1156,8 +1156,11 @@
 	td->td_retval[0] = indx;
 	return (0);
 out:
-	if (dvp)
+	if (dvp) {
+		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
+		VFS_UNLOCK_GIANT(vfslocked);
+	}
 	return (error);
 bad:
 	VFS_UNLOCK_GIANT(vfslocked);
@@ -1249,7 +1252,7 @@
 	int error;
 	int whiteout = 0;
 	struct nameidata nd;
-	int vfslocked;
+	int vfslocked, dvfslocked;
 
 	AUDIT_ARG(mode, mode);
 	AUDIT_ARG(dev, dev);
@@ -1273,9 +1276,9 @@
 	bwillwrite();
 restart:
 	if (dvp) {
-		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
-		VFS_UNLOCK_GIANT(vfslocked);
+		VFS_UNLOCK_GIANT(dvfslocked);
 		bwillwrite();
 	}
 	error = kern_get_at(td, fd, &dvp);
@@ -1284,8 +1287,11 @@
 	NDINIT_AT(&nd, CREATE, ((error) ? ATBADF : 0) | LOCKPARENT |
 	    SAVENAME | MPSAFE | AUDITVNODE1, pathseg, path, td, dvp);
 	if ((error = namei(&nd)) != 0) {
-		if (dvp)
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (error);
 	}
 	vfslocked = NDHASGIANT(&nd);
@@ -1298,8 +1304,11 @@
 			vput(nd.ni_dvp);
 		vrele(vp);
 		VFS_UNLOCK_GIANT(vfslocked);
-		if (dvp)
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (EEXIST);
 	} else {
 		VATTR_NULL(&vattr);
@@ -1332,8 +1341,11 @@
 		vput(nd.ni_dvp);
 		VFS_UNLOCK_GIANT(vfslocked);
 		if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) {
-			if (dvp)
+			if (dvp) {
+				dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 				vrele(dvp);
+				VFS_UNLOCK_GIANT(dvfslocked);
+			}
 			return (error);
 		}
 		goto restart;
@@ -1355,7 +1367,7 @@
 		}
 	}
 	if (dvp) {
-		int dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
 		VFS_UNLOCK_GIANT(dvfslocked);
 	}
@@ -1414,16 +1426,16 @@
 	struct vattr vattr;
 	int error;
 	struct nameidata nd;
-	int vfslocked;
+	int vfslocked, dvfslocked;
 	struct vnode *dvp = NULL;
 
 	AUDIT_ARG(mode, mode);
 	bwillwrite();
 restart:
 	if (dvp) {
-		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
-		VFS_UNLOCK_GIANT(vfslocked);
+		VFS_UNLOCK_GIANT(dvfslocked);
 		bwillwrite();
 	}
 	error = kern_get_at(td, fd, &dvp);
@@ -1432,8 +1444,11 @@
 	NDINIT_AT(&nd, CREATE, ((error) ? ATBADF : 0) | LOCKPARENT |
 	    SAVENAME | MPSAFE | AUDITVNODE1, pathseg, path, td, dvp);
 	if ((error = namei(&nd)) != 0) {
-		if (dvp)
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (error);
 	}
 	vfslocked = NDHASGIANT(&nd);
@@ -1445,8 +1460,11 @@
 			vput(nd.ni_dvp);
 		vrele(nd.ni_vp);
 		VFS_UNLOCK_GIANT(vfslocked);
-		if (dvp)
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (EEXIST);
 	}
 	if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
@@ -1454,8 +1472,11 @@
 		vput(nd.ni_dvp);
 		VFS_UNLOCK_GIANT(vfslocked);
 		if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) {
-			if (dvp)
+			if (dvp) {
+				dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 				vrele(dvp);
+				VFS_UNLOCK_GIANT(dvfslocked);
+			}
 			return (error);
 	}
 		goto restart;
@@ -1479,7 +1500,7 @@
 out:
 #endif
 	if (dvp) {
-		int dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
 		VFS_UNLOCK_GIANT(dvfslocked);
 	}
@@ -1730,7 +1751,7 @@
 	char *syspath;
 	int error;
 	struct nameidata nd;
-	int vfslocked;
+	int vfslocked, dvfslocked;
 	struct vnode *dvp = NULL;
 
 	if (segflg == UIO_SYSSPACE) {
@@ -1744,9 +1765,9 @@
 	bwillwrite();
 restart:
 	if (dvp) {
-		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
-		VFS_UNLOCK_GIANT(vfslocked);
+		VFS_UNLOCK_GIANT(dvfslocked);
 		bwillwrite();
 	}
 	error = kern_get_at(td, fd, &dvp);
@@ -1800,9 +1821,9 @@
 	VFS_UNLOCK_GIANT(vfslocked);
 out:
 	if (dvp) {
-		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
-		VFS_UNLOCK_GIANT(vfslocked);
+		VFS_UNLOCK_GIANT(dvfslocked);
 	}
 	if (segflg != UIO_SYSSPACE)
 		uma_zfree(namei_zone, syspath);
@@ -1918,14 +1939,14 @@
 	struct vnode *vp, *dvp = NULL;
 	int error;
 	struct nameidata nd;
-	int vfslocked;
+	int vfslocked, dvfslocked;
 
 	bwillwrite();
 restart:
 	if (dvp) {
-		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
-		VFS_UNLOCK_GIANT(vfslocked);
+		VFS_UNLOCK_GIANT(dvfslocked);
 		bwillwrite();
 	}
 	error = kern_get_at(td, fd, &dvp);
@@ -1934,8 +1955,11 @@
 	NDINIT_AT(&nd, DELETE, ((error) ? ATBADF : 0) | LOCKPARENT |
 	    LOCKLEAF | MPSAFE | AUDITVNODE1, pathseg, path, td, dvp);
 	if ((error = namei(&nd)) != 0) {
-		if (dvp)
-			vrele(dvp);		
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (error == EINVAL ? EPERM : error);
 	}
 	vfslocked = NDHASGIANT(&nd);
@@ -1962,8 +1986,11 @@
 			VFS_UNLOCK_GIANT(vfslocked);
 			if ((error = vn_start_write(NULL, &mp,
 			    V_XSLEEP | PCATCH)) != 0) {
-				if (dvp)
+				if (dvp) {
+					dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 					vrele(dvp);
+					VFS_UNLOCK_GIANT(dvfslocked);
+				}
 				return (error);
 			}
 			goto restart;
@@ -1984,7 +2011,7 @@
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 	vput(nd.ni_dvp);
 	if (dvp) {
-		int dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
 		VFS_UNLOCK_GIANT(dvfslocked);
 	}
@@ -3070,12 +3097,13 @@
 	NDINIT_AT(&nd, LOOKUP, NOFOLLOW | MPSAFE | AUDITVNODE1, pathseg,
 	    path, td, dvp);
 	if ((error = namei(&nd)) != 0)
-		return (error);
+		goto out;
 	vfslocked = NDHASGIANT(&nd);
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 	error = setfmode(td, nd.ni_vp, mode);
 	vrele(nd.ni_vp);
 	VFS_UNLOCK_GIANT(vfslocked);
+out:
 	if (dvp) {
 		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
@@ -4000,8 +4028,6 @@
 		vrele(fromnd.ni_startdir);
 	VFS_UNLOCK_GIANT(fvfslocked);
 	VFS_UNLOCK_GIANT(tvfslocked);
-	if (error == -1)
-		return (0);
 out2:
 	if (frdvp) {
 		fvfslocked = VFS_NEEDSGIANT(frdvp->v_mount); 
@@ -4013,6 +4039,9 @@
 		vrele(todvp);
 		VFS_UNLOCK_GIANT(tvfslocked);
 	}
+	/* Nothing to do, return success. */
+	if (error == -1)
+		return (0);
 	return (error);
 }
 
@@ -4065,15 +4094,15 @@
 	struct vattr vattr;
 	int error;
 	struct nameidata nd;
-	int vfslocked;
+	int vfslocked, dvfslocked;
 
 	AUDIT_ARG(mode, mode);
 	bwillwrite();
 restart:
 	if (dvp) {
-		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
-		VFS_UNLOCK_GIANT(vfslocked);
+		VFS_UNLOCK_GIANT(dvfslocked);
 		bwillwrite();
 	}
 	error = kern_get_at(td, fd, &dvp);
@@ -4083,8 +4112,11 @@
 	    SAVENAME | MPSAFE | AUDITVNODE1, segflg, path, td, dvp);
 	nd.ni_cnd.cn_flags |= WILLBEDIR;
 	if ((error = namei(&nd)) != 0) {
-		if (dvp)
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (error);
 	}
 	vfslocked = NDHASGIANT(&nd);
@@ -4102,8 +4134,11 @@
 			vput(nd.ni_dvp);
 		vrele(vp);
 		VFS_UNLOCK_GIANT(vfslocked);
-		if (dvp)
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (EEXIST);
 	}
 	if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) {
@@ -4111,8 +4146,11 @@
 		vput(nd.ni_dvp);
 		VFS_UNLOCK_GIANT(vfslocked);
 		if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) {
-			if (dvp)
+			if (dvp) {
+				dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 				vrele(dvp);
+				VFS_UNLOCK_GIANT(dvfslocked);
+			}
 			return (error);
 		}
 		goto restart;
@@ -4134,7 +4172,7 @@
 out:
 #endif
 	if (dvp) {
-		int dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
 		VFS_UNLOCK_GIANT(dvfslocked);
 	}
@@ -4179,14 +4217,14 @@
 	struct vnode *vp, *dvp = NULL;
 	int error;
 	struct nameidata nd;
-	int vfslocked;
+	int vfslocked, dvfslocked;
 
 	bwillwrite();
 restart:
 	if (dvp) {
-		vfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
-		VFS_UNLOCK_GIANT(vfslocked);
+		VFS_UNLOCK_GIANT(dvfslocked);
 		bwillwrite();
 	}
 	error = kern_get_at(td, fd, &dvp);
@@ -4194,8 +4232,14 @@
 		return (error);
 	NDINIT_AT(&nd, DELETE, ((error) ? ATBADF : 0) | LOCKPARENT |
 	    LOCKLEAF | MPSAFE | AUDITVNODE1, pathseg, path, td, dvp);
-	if ((error = namei(&nd)) != 0)
+	if ((error = namei(&nd)) != 0) {
+		if (dvp) {
+			dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+			vrele(dvp);
+			VFS_UNLOCK_GIANT(dvfslocked);
+		}
 		return (error);
+	}
 	vfslocked = NDHASGIANT(&nd);
 	vp = nd.ni_vp;
 	if (vp->v_type != VDIR) {
@@ -4230,8 +4274,14 @@
 		else
 			vput(nd.ni_dvp);
 		VFS_UNLOCK_GIANT(vfslocked);
-		if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0)
+		if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) {
+			if (dvp) {
+				dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+				vrele(dvp);
+				VFS_UNLOCK_GIANT(dvfslocked);
+			}
 			return (error);
+		}
 		goto restart;
 	}
 	VOP_LEASE(nd.ni_dvp, td, td->td_ucred, LEASE_WRITE);
@@ -4242,7 +4292,7 @@
 	NDFREE(&nd, NDF_ONLY_PNBUF);
 	vput(vp);
 	if (dvp) {
-		int dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
+		dvfslocked = VFS_NEEDSGIANT(dvp->v_mount); 
 		vrele(dvp);
 		VFS_UNLOCK_GIANT(dvfslocked);
 	}



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