Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Jul 2002 13:31:05 -0700 (PDT)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 14630 for review
Message-ID:  <200207212031.g6LKV5qf004111@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=14630

Change 14630 by rwatson@rwatson_curry on 2002/07/21 13:30:48

	First pass at diff-reducing the lookup/namei code.  Since we've
	moved all the checks but one lookup and one readlink check out
	of this code, we can restore the original locking behavior.  Not
	quite down to minimal diffs with -current, and it's possible we
	might have to stick some of this back if I misunderstood why
	it was there, but it appears to work. :-)

Affected files ...

.. //depot/projects/trustedbsd/mac/sys/kern/vfs_lookup.c#17 edit

Differences ...

==== //depot/projects/trustedbsd/mac/sys/kern/vfs_lookup.c#17 (text+ko) ====

@@ -72,61 +72,7 @@
 }
 SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_SECOND, nameiinit, NULL)
 
-#ifdef MAC
 /*
- * Restore the status of whether the parent would be locked/referenced,
- * and then lock status of the target, after having overridden with.
- * Only called if any of (LOCKPARENT | LOCKLEAF) was not "on" previously.
- */
-static void
-nameirestoreparent(struct nameidata *ndp, u_long cn_flags, struct thread *td)
-{
-	const int vneq = ndp->ni_dvp == ndp->ni_vp; /*
-						     * For the CREATE case,
-						     * this also catches ni_vp
-						     * being NULL.
-						     */
-
-	KASSERT((cn_flags & (LOCKPARENT | LOCKLEAF)) != (LOCKPARENT | LOCKLEAF),
-	    ("nameirestoreparent botch"));
-
-	switch (cn_flags & (LOCKPARENT | WANTPARENT | LOCKLEAF)) {
-	/* If I added LOCKLEAF, just unlock the target if it's not equal. */
-	case LOCKPARENT:			/* CREATE, DELETE, RENAME */
-		/*
-		 * CREATE may or may not return a vnode in ni_vp: if it
-		 * cannot create one, it acts like a LOOKUP.
-		 */
-		if (!vneq && ndp->ni_vp != NULL)
-			VOP_UNLOCK(ndp->ni_vp, 0, td);
-		break;
-	/* I just added LOCKPARENT. */
-	case LOCKLEAF | WANTPARENT:		/* DELETE, RENAME */
-	case LOCKLEAF:
-		if (!vneq)
-			VOP_UNLOCK(ndp->ni_dvp, 0, td);
-		if ((cn_flags & WANTPARENT) == 0)
-			vrele(ndp->ni_dvp);
-		break;
-	/* I added both LOCKLEAF and LOCKPARENT */
-	case WANTPARENT:
-	case 0:
-		if (ndp->ni_vp != NULL)
-			VOP_UNLOCK(ndp->ni_vp, 0, td);
-		if (!vneq)
-			VOP_UNLOCK(ndp->ni_dvp, 0, td);
-		if ((cn_flags & WANTPARENT) == 0)
-			vrele(ndp->ni_dvp);
-		break;
-	default:
-		panic("nameirestoreparent: weird flags %#lx", cn_flags);
-	}
-	ndp->ni_cnd.cn_flags = (ndp->ni_cnd.cn_flags & ~(LOCKLEAF | LOCKPARENT
-	     | WANTPARENT)) | (cn_flags & (LOCKLEAF | LOCKPARENT | WANTPARENT));
-}
-#endif /* MAC */
-
-/*
  * Convert a pathname into a pointer to a locked inode.
  *
  * The FOLLOW flag is set when symbolic links are to be followed
@@ -154,10 +100,6 @@
 	register char *cp;		/* pointer into pathname argument */
 	register struct vnode *dp;	/* the directory we are searching */
 	struct iovec aiov;		/* uio for reading symbolic links */
-#ifdef MAC
-	u_long pflags;			/* saved cn_flags for replacing */
-	int lockoverride;	/* overridden parent/final lock via pflags */
-#endif /* MAC */
 	struct uio auio;
 	int error, linklen;
 	struct componentname *cnp = &ndp->ni_cnd;
@@ -231,26 +173,6 @@
 			VREF(dp);
 		}
 		ndp->ni_startdir = dp;
-#ifdef MAC
-		/*
-		 * Save the parent and leaf locked so that they may be
-		 * managed by MAC of this is the last component; restore
-		 * afterward.  Note that search permissions used by LOOKUP
-		 * are checked in lookup() itself, and RENAME checked by
-		 * rename() itself, so we only care about CREATE and DELETE.
-		 */
-		if (~cnp->cn_flags & (LOCKLEAF | LOCKPARENT) &&
-		    cnp->cn_nameiop == DELETE) {
-			pflags = cnp->cn_flags;
-			cnp->cn_flags = (pflags & ~WANTPARENT) |
-			    LOCKPARENT | LOCKLEAF;
-			lockoverride = 1;
-		} else {
-			/* Silence, knave! */
-			lockoverride = 0;
-			pflags = 0;
-		}
-#endif /* MAC */
 		error = lookup(ndp);
 		if (error) {
 			uma_zfree(namei_zone, cnp->cn_pnbuf);
@@ -260,42 +182,7 @@
 		 * Check for symbolic link
 		 */
 		if (cnp->cn_flags & ISSYMLINK) {
-#ifdef MAC
-			/* Don't check MAC operations on symlinks. */
-			if (lockoverride)
-				nameirestoreparent(ndp, pflags, td);
-#endif /* MAC */
 		} else {
-#ifdef MAC
-			struct ucred *cred = td->td_ucred;
-
-			/*
-			 * We know it's ISLASTCN, so do the MAC delete, rename,
-			 * or create check if appropriate.
-			 */
-			switch (cnp->cn_nameiop) {
-			case DELETE:
-				error = mac_cred_check_delete_vnode(cred,
-				    ndp->ni_dvp, ndp->ni_vp);
-				break;
-			default:
-				error = 0;
-			}
-			if (error) {
-				uma_zfree(namei_zone, cnp->cn_pnbuf);
-				if (ndp->ni_vp != NULL) {
-					if (ndp->ni_vp != ndp->ni_dvp)
-						vput(ndp->ni_vp);
-					else
-						vrele(ndp->ni_vp);
-					ndp->ni_vp = NULL;
-				}
-				vput(ndp->ni_dvp);
-				return (error);
-			}
-			if (lockoverride)
-				nameirestoreparent(ndp, pflags, td);
-#endif /* MAC */
 			if ((cnp->cn_flags & (SAVENAME | SAVESTART)) == 0)
 				uma_zfree(namei_zone, cnp->cn_pnbuf);
 			else

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




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