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
This commit is contained in:
bouyer 2010-08-04 12:34:00 +00:00
parent 316bc64cb8
commit f5a8179a2f

View File

@ -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 @@ dkwedge_begindetach(struct dkwedge_softc *sc, int flags)
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 @@ dkwedge_detach(device_t self, int flags)
/* 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 @@ dklastclose(struct dkwedge_softc *sc)
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 @@ dkclose(dev_t dev, int flags, int fmt, struct lwp *l)
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_dk.dk_openlock);
return (error);