From a243137af2073d22d4fc581771aeb8a5330031fc Mon Sep 17 00:00:00 2001 From: ae Date: Fri, 18 May 2012 09:19:07 +0000 Subject: Introduce new device flag G_MIRROR_DEVICE_FLAG_TASTING. It should protect geom from destroying while it is tasting. PR: kern/154860 Reviewed by: pjd MFC after: 1 week --- sys/geom/mirror/g_mirror.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'sys/geom/mirror/g_mirror.c') diff --git a/sys/geom/mirror/g_mirror.c b/sys/geom/mirror/g_mirror.c index 1eb46de..fc33db2 100644 --- a/sys/geom/mirror/g_mirror.c +++ b/sys/geom/mirror/g_mirror.c @@ -1693,6 +1693,8 @@ g_mirror_can_destroy(struct g_mirror_softc *sc) gp = sc->sc_geom; if (gp->softc == NULL) return (1); + if ((sc->sc_flags & G_MIRROR_DEVICE_FLAG_TASTING) != 0) + return (0); LIST_FOREACH(cp, &gp->consumer, consumer) { if (g_mirror_is_busy(sc, cp)) return (0); @@ -3054,6 +3056,7 @@ g_mirror_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) G_MIRROR_DEBUG(1, "Adding disk %s to %s.", pp->name, gp->name); g_topology_unlock(); sx_xlock(&sc->sc_lock); + sc->sc_flags |= G_MIRROR_DEVICE_FLAG_TASTING; error = g_mirror_add_disk(sc, pp, &md); if (error != 0) { G_MIRROR_DEBUG(0, "Cannot add disk %s to %s (error=%d).", @@ -3066,6 +3069,12 @@ g_mirror_taste(struct g_class *mp, struct g_provider *pp, int flags __unused) } gp = NULL; } + sc->sc_flags &= ~G_MIRROR_DEVICE_FLAG_TASTING; + if ((sc->sc_flags & G_MIRROR_DEVICE_FLAG_DESTROY) != 0) { + g_mirror_destroy(sc, G_MIRROR_DESTROY_HARD); + g_topology_lock(); + return (NULL); + } sx_xunlock(&sc->sc_lock); g_topology_lock(); return (gp); -- cgit v1.1