Be sure to not destroy device twice. This is not possible in theory, but

with this change there is even no theoretical race.

MFC after:	2 weeks
This commit is contained in:
pjd 2006-04-28 11:47:28 +00:00
parent 64fbab4133
commit f430b234fb

View File

@ -539,13 +539,11 @@ g_mirror_destroy_device(struct g_mirror_softc *sc)
}
}
callout_drain(&sc->sc_callout);
gp->softc = NULL;
g_topology_lock();
LIST_FOREACH_SAFE(cp, &sc->sc_sync.ds_geom->consumer, consumer, tmpcp) {
g_mirror_disconnect_consumer(sc, cp);
}
sc->sc_sync.ds_geom->softc = NULL;
g_wither_geom(sc->sc_sync.ds_geom, ENXIO);
G_MIRROR_DEBUG(0, "Device %s destroyed.", gp->name);
g_wither_geom(gp, ENXIO);
@ -1660,6 +1658,8 @@ g_mirror_can_destroy(struct g_mirror_softc *sc)
g_topology_assert();
gp = sc->sc_geom;
if (gp->softc == NULL)
return (1);
LIST_FOREACH(cp, &gp->consumer, consumer) {
if (g_mirror_is_busy(sc, cp))
return (0);
@ -1689,6 +1689,8 @@ g_mirror_try_destroy(struct g_mirror_softc *sc)
g_topology_unlock();
return (0);
}
sc->sc_geom->softc = NULL;
sc->sc_sync.ds_geom->softc = NULL;
if ((sc->sc_flags & G_MIRROR_DEVICE_FLAG_WAIT) != 0) {
g_topology_unlock();
G_MIRROR_DEBUG(4, "%s: Waking up %p.", __func__,
@ -2886,6 +2888,15 @@ g_mirror_destroy(struct g_mirror_softc *sc, int how)
}
}
g_topology_lock();
if (sc->sc_geom->softc == NULL) {
g_topology_unlock();
return (0);
}
sc->sc_geom->softc = NULL;
sc->sc_sync.ds_geom->softc = NULL;
g_topology_unlock();
sc->sc_flags |= G_MIRROR_DEVICE_FLAG_DESTROY;
sc->sc_flags |= G_MIRROR_DEVICE_FLAG_WAIT;
G_MIRROR_DEBUG(4, "%s: Waking up %p.", __func__, sc);