PERFORCE change 103220 for review

John Birrell jb at FreeBSD.org
Sat Aug 5 02:58:32 UTC 2006


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

Change 103220 by jb at jb_freebsd2 on 2006/08/05 02:57:43

	Sync to current.

Affected files ...

.. //depot/projects/dtrace/src/sys/kern/kern_descrip.c#6 edit

Differences ...

==== //depot/projects/dtrace/src/sys/kern/kern_descrip.c#6 (text+ko) ====

@@ -359,33 +359,41 @@
 	struct vnode *vp;
 	u_int newmin;
 	int error, flg, tmp;
-	int giant_locked = 0;
+	int giant_locked;
+
+	/*
+	 * XXXRW: Some fcntl() calls require Giant -- others don't.  Try to
+	 * avoid grabbing Giant for calls we know don't need it.
+	 */
+	switch (cmd) {
+	case F_DUPFD:
+	case F_GETFD:
+	case F_SETFD:
+	case F_GETFL:
+		giant_locked = 0;
+		break;
+
+	default:
+		giant_locked = 1;
+		mtx_lock(&Giant);
+	}
 
 	error = 0;
 	flg = F_POSIX;
 	p = td->td_proc;
 	fdp = p->p_fd;
- retry:
 	FILEDESC_LOCK(fdp);
 	if ((unsigned)fd >= fdp->fd_nfiles ||
 	    (fp = fdp->fd_ofiles[fd]) == NULL) {
 		FILEDESC_UNLOCK(fdp);
-		if (giant_locked)
-			mtx_unlock(&Giant);
 		error = EBADF;
 		goto done2;
 	}
 	pop = &fdp->fd_ofileflags[fd];
 
-	if ((giant_locked == 0) &&  ((fp->f_ops->fo_flags & DFLAG_MPSAFE) == 0)) {
-		FILEDESC_UNLOCK(fdp);
-		mtx_lock(&Giant);
-		giant_locked = 1;
-		/* we may have lost a race */
-		goto retry;
-	} 
 	switch (cmd) {
 	case F_DUPFD:
+		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		FILEDESC_UNLOCK(fdp);
 		newmin = arg;
 		PROC_LOCK(p);
@@ -400,17 +408,20 @@
 		break;
 
 	case F_GETFD:
+		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		td->td_retval[0] = (*pop & UF_EXCLOSE) ? FD_CLOEXEC : 0;
 		FILEDESC_UNLOCK(fdp);
 		break;
 
 	case F_SETFD:
+		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		*pop = (*pop &~ UF_EXCLOSE) |
 		    (arg & FD_CLOEXEC ? UF_EXCLOSE : 0);
 		FILEDESC_UNLOCK(fdp);
 		break;
 
 	case F_GETFL:
+		/* mtx_assert(&Giant, MA_NOTOWNED); */
 		FILE_LOCK(fp);
 		td->td_retval[0] = OFLAGS(fp->f_flag);
 		FILE_UNLOCK(fp);
@@ -418,6 +429,7 @@
 		break;
 
 	case F_SETFL:
+		mtx_assert(&Giant, MA_OWNED);
 		FILE_LOCK(fp);
 		fhold_locked(fp);
 		fp->f_flag &= ~FCNTLFLAGS;
@@ -445,6 +457,7 @@
 		break;
 
 	case F_GETOWN:
+		mtx_assert(&Giant, MA_OWNED);
 		fhold(fp);
 		FILEDESC_UNLOCK(fdp);
 		error = fo_ioctl(fp, FIOGETOWN, &tmp, td->td_ucred, td);
@@ -454,6 +467,7 @@
 		break;
 
 	case F_SETOWN:
+		mtx_assert(&Giant, MA_OWNED);
 		fhold(fp);
 		FILEDESC_UNLOCK(fdp);
 		tmp = arg;
@@ -462,10 +476,12 @@
 		break;
 
 	case F_SETLKW:
+		mtx_assert(&Giant, MA_OWNED);
 		flg |= F_WAIT;
 		/* FALLTHROUGH F_SETLK */
 
 	case F_SETLK:
+		mtx_assert(&Giant, MA_OWNED);
 		if (fp->f_type != DTYPE_VNODE) {
 			FILEDESC_UNLOCK(fdp);
 			error = EBADF;
@@ -539,6 +555,7 @@
 		break;
 
 	case F_GETLK:
+		mtx_assert(&Giant, MA_OWNED);
 		if (fp->f_type != DTYPE_VNODE) {
 			FILEDESC_UNLOCK(fdp);
 			error = EBADF;
@@ -2492,7 +2509,7 @@
 	return (error);
 }
 
-SYSCTL_PROC(_kern, KERN_FILE, file, CTLTYPE_OPAQUE|CTLFLAG_RD|CTLFLAG_MPSAFE,
+SYSCTL_PROC(_kern, KERN_FILE, file, CTLTYPE_OPAQUE|CTLFLAG_RD,
     0, 0, sysctl_kern_file, "S,xfile", "Entire file table");
 
 #ifdef DDB


More information about the p4-projects mailing list