Module Name:    src
Committed By:   bouyer
Date:           Wed Aug  4 12:34:00 UTC 2010

Modified Files:
        src/sys/dev/dkwedge: dk.c

Log Message:
Make sure to release sc_parent->dk_rawlock before calling
vn_close(sc->sc_parent->dk_rawvp). Avoids a lockdebug panic:
error: mutex_destroy: assertion failed: !MUTEX_OWNED(mtx->mtx_owner) && 
!MUTEX_HAS_WAITERS(mtx)
when the parent is a raidframe device.
See also:
http://mail-index.netbsd.org/tech-kern/2010/07/27/msg008612.html


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/dkwedge/dk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/dkwedge/dk.c
diff -u src/sys/dev/dkwedge/dk.c:1.56 src/sys/dev/dkwedge/dk.c:1.57
--- src/sys/dev/dkwedge/dk.c:1.56	Thu Jun 24 13:03:08 2010
+++ src/sys/dev/dkwedge/dk.c	Wed Aug  4 12:34:00 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dk.c,v 1.56 2010/06/24 13:03:08 hannken Exp $	*/
+/*	$NetBSD: dk.c,v 1.57 2010/08/04 12:34:00 bouyer Exp $	*/
 
 /*-
  * Copyright (c) 2004, 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.56 2010/06/24 13:03:08 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dk.c,v 1.57 2010/08/04 12:34:00 bouyer Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_dkwedge.h"
@@ -511,14 +511,14 @@
 
 	rc = 0;
 	mutex_enter(&dk->dk_openlock);
-	mutex_enter(&sc->sc_parent->dk_rawlock);
 	if (dk->dk_openmask == 0)
 		;	/* nothing to do */
 	else if ((flags & DETACH_FORCE) == 0)
 		rc = EBUSY;
-	else
-		rc = dklastclose(sc);
-	mutex_exit(&sc->sc_parent->dk_rawlock);
+	else {
+		mutex_enter(&sc->sc_parent->dk_rawlock);
+		rc = dklastclose(sc); /* releases dk_rawlock */
+	}
 	mutex_exit(&dk->dk_openlock);
 
 	return rc;
@@ -577,17 +577,18 @@
 
 	/* Clean up the parent. */
 	mutex_enter(&sc->sc_dk.dk_openlock);
-	mutex_enter(&sc->sc_parent->dk_rawlock);
 	if (sc->sc_dk.dk_openmask) {
+		mutex_enter(&sc->sc_parent->dk_rawlock);
 		if (sc->sc_parent->dk_rawopens-- == 1) {
 			KASSERT(sc->sc_parent->dk_rawvp != NULL);
+			mutex_exit(&sc->sc_parent->dk_rawlock);
 			(void) vn_close(sc->sc_parent->dk_rawvp, FREAD | FWRITE,
 			    NOCRED);
 			sc->sc_parent->dk_rawvp = NULL;
-		}
+		} else
+			mutex_exit(&sc->sc_parent->dk_rawlock);
 		sc->sc_dk.dk_openmask = 0;
 	}
-	mutex_exit(&sc->sc_parent->dk_rawlock);
 	mutex_exit(&sc->sc_dk.dk_openlock);
 
 	/* Announce our departure. */
@@ -1050,10 +1051,12 @@
 
 	if (sc->sc_parent->dk_rawopens-- == 1) {
 		KASSERT(sc->sc_parent->dk_rawvp != NULL);
+		mutex_exit(&sc->sc_parent->dk_rawlock);
 		error = vn_close(sc->sc_parent->dk_rawvp,
 		    FREAD | FWRITE, NOCRED);
 		sc->sc_parent->dk_rawvp = NULL;
-	}
+	} else
+		mutex_exit(&sc->sc_parent->dk_rawlock);
 	return error;
 }
 
@@ -1081,9 +1084,10 @@
 	    sc->sc_dk.dk_copenmask | sc->sc_dk.dk_bopenmask;
 
 	if (sc->sc_dk.dk_openmask == 0)
-		error = dklastclose(sc);
+		error = dklastclose(sc); /* releases dk_rawlock */
+	else 
+		mutex_exit(&sc->sc_parent->dk_rawlock);
 
-	mutex_exit(&sc->sc_parent->dk_rawlock);
 	mutex_exit(&sc->sc_dk.dk_openlock);
 
 	return (error);

Reply via email to