PERFORCE change 113330 for review

Todd Miller millert at FreeBSD.org
Mon Jan 22 15:43:44 UTC 2007


http://perforce.freebsd.org/chv.cgi?CH=113330

Change 113330 by millert at millert_macbook on 2007/01/22 15:42:30

	Minor reorg that takes into account that V_LABELED and
	V_LABEL are  mutually exclusive.  I also put a loop around
	the msleep() in  vnode_label() and vnode_label1() to make
	sure that V_LABEL has really been cleared when we wake up
	(vnode_relabel() already did this).

Affected files ...

.. //depot/projects/trustedbsd/sedarwin8/darwin/xnu/security/mac_vfs_subr.c#9 edit

Differences ...

==== //depot/projects/trustedbsd/sedarwin8/darwin/xnu/security/mac_vfs_subr.c#9 (text+ko) ====

@@ -36,14 +36,14 @@
 		return (ENOENT);
 	}
 
-	if ((vp->v_lflag & (VL_LABEL|VL_LABELED)) == 0) {
+	if ((vp->v_lflag & VL_LABEL) == 0) {
 		vp->v_lflag |= VL_LABEL;
 
 		/* Could sleep on disk I/O, drop lock. */
 		vnode_unlock(vp);
 		if (flags & VNODE_LABEL_CREATE)
 			error = mac_vnode_notify_create(vfs_context_ucred(ctx),
-							 mp, dvp, vp, cnp);
+			    mp, dvp, vp, cnp);
 		else
 			error = mac_vnode_label_associate(mp, vp, ctx);
 		vnode_lock(vp);
@@ -51,30 +51,32 @@
 		if ((error == 0) && (vp->v_flag & VNCACHEABLE))
 			vp->v_lflag |= VL_LABELED;
 		vp->v_lflag &= ~VL_LABEL;
+
 		if (vp->v_lflag & VL_LABELWAIT) {
 			vp->v_lflag &= ~VL_LABELWAIT;
 			wakeup(vp->v_label);
 		}
-	} else
-	if (vp->v_lflag & VL_LABEL) {
+		vnode_put_locked(vp);
+		vnode_unlock(vp);
+	} else {
 		struct timespec ts;
 
 		ts.tv_sec = 10;
 		ts.tv_nsec = 0;
 
-		vp->v_lflag |= VL_LABELWAIT;
-
-		error = msleep(vp->v_label, &vp->v_lock, PVFS|PDROP,
-				"vnode_label", &ts);
-		if (error == EWOULDBLOCK)
-			vprint("vnode label timeout", vp);
+		while (vp->v_lflag & VL_LABEL) {
+			vp->v_lflag |= VL_LABELWAIT;
+			error = msleep(vp->v_label, &vp->v_lock, PVFS|PDROP,
+			    "vnode_label", &ts);
+			if (error == EWOULDBLOCK) {
+				vprint("vnode label timeout", vp);
+				break;
+			}
+		}
 		/* XXX: what should be done if labeling failed (above)? */
 		vnode_put(vp);
-		return (error);
 	}
 
-	vnode_put_locked(vp);
-	vnode_unlock(vp);
 	return (error);
 }
 
@@ -90,11 +92,14 @@
 	struct vfs_context ctx;
 	int error;
 
+	if (vp->v_lflag & VL_LABELED)
+		return (0);
+
 	error = 0;
 	ctx.vc_proc = current_proc();
 	ctx.vc_ucred = kauth_cred_get();
 
-	if ((vp->v_lflag & (VL_LABEL|VL_LABELED)) == 0) {
+	if ((vp->v_lflag & VL_LABEL) == 0) {
 		vp->v_lflag |= VL_LABEL;
 
 		/* Could sleep on disk I/O, drop lock. */
@@ -109,11 +114,13 @@
 			vp->v_lflag &= ~VL_LABELWAIT;
 			wakeup(vp->v_label);
 		}
-	} else
-	/* Wait for other labeling to complete. */
-	if (vp->v_lflag & VL_LABEL) {
-		vp->v_lflag |= VL_LABELWAIT;
-		(void)msleep(vp->v_label, &vp->v_lock, PVFS, "vnode_label", 0);
+	} else {
+		/* Wait for any other labeling to complete. */
+		while (vp->v_lflag & VL_LABEL) {
+			vp->v_lflag |= VL_LABELWAIT;
+			(void)msleep(vp->v_label, &vp->v_lock, PVFS,
+			    "vnode_label1", 0);
+		}
 		/* XXX: what should be done if labeling failed (above)? */
 	}
 
@@ -132,7 +139,7 @@
 vnode_relabel(struct vnode *vp)
 {
 
-	/* Wait for other labeling to complete. */
+	/* Wait for any other labeling to complete. */
 	while (vp->v_lflag & VL_LABEL) {
 		vp->v_lflag |= VL_LABELWAIT;
 		(void)msleep(vp->v_label, &vp->v_lock, PVFS, "vnode_relabel", 0);


More information about the trustedbsd-cvs mailing list