From 8e76f1cefa385812b9d3e31763425ef47ea98298 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 23 Mar 2003 23:01:40 +0000 Subject: [PATCH] Introduce g_cancel_events() and use it a couple of places where it makes sense. --- sys/geom/geom_event.c | 22 ++++++++++++++++++++++ sys/geom/geom_int.h | 1 + sys/geom/geom_subr.c | 3 +++ 3 files changed, 26 insertions(+) diff --git a/sys/geom/geom_event.c b/sys/geom/geom_event.c index d726a0110304..5413a3429f3c 100644 --- a/sys/geom/geom_event.c +++ b/sys/geom/geom_event.c @@ -324,6 +324,28 @@ g_post_event(enum g_events ev, struct g_class *mp, struct g_geom *gp, struct g_p wakeup(&g_wait_event); } +void +g_cancel_event(struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp) +{ + struct g_event *ep, *epn; + + mtx_lock(&g_eventlock); + ep = TAILQ_FIRST(&g_events); + for (;ep != NULL;) { + epn = TAILQ_NEXT(ep, events); + if ( + (ep->class != NULL && ep->class == mp) || + (ep->geom != NULL && ep->geom == gp) || + (ep->provider != NULL && ep->provider == pp) || + (ep->consumer != NULL && ep->consumer == cp)) { + TAILQ_REMOVE(&g_events, ep, events); + g_free(ep); + } + ep = epn; + } + mtx_unlock(&g_eventlock); +} + int g_call_me(g_call_me_t *func, void *arg) { diff --git a/sys/geom/geom_int.h b/sys/geom/geom_int.h index b56895b3e712..26b3d7884be4 100644 --- a/sys/geom/geom_int.h +++ b/sys/geom/geom_int.h @@ -93,6 +93,7 @@ void g_conftxt(void *); /* geom_event.c */ void g_event_init(void); void g_post_event(enum g_events ev, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp); +void g_cancel_event(struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp); void g_run_events(void); void g_stall_events(void); void g_release_events(void); diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c index b5c1861edcc9..f047b59ca971 100644 --- a/sys/geom/geom_subr.c +++ b/sys/geom/geom_subr.c @@ -126,6 +126,7 @@ g_destroy_geom(struct g_geom *gp) KASSERT(LIST_EMPTY(&gp->provider), ("g_destroy_geom(%s) with provider(s) [%p]", gp->name, LIST_FIRST(&gp->consumer))); + g_cancel_event(NULL, gp, NULL, NULL); LIST_REMOVE(gp, geom); TAILQ_REMOVE(&geoms, gp, geoms); g_free(gp->name); @@ -162,6 +163,7 @@ g_destroy_consumer(struct g_consumer *cp) KASSERT (cp->acr == 0, ("g_destroy_consumer with acr")); KASSERT (cp->acw == 0, ("g_destroy_consumer with acw")); KASSERT (cp->ace == 0, ("g_destroy_consumer with ace")); + g_cancel_event(NULL, NULL, NULL, cp); LIST_REMOVE(cp, consumer); devstat_remove_entry(cp->stat); g_free(cp); @@ -216,6 +218,7 @@ g_destroy_provider(struct g_provider *pp) KASSERT (pp->acr == 0, ("g_destroy_provider with acr")); KASSERT (pp->acw == 0, ("g_destroy_provider with acw")); KASSERT (pp->acw == 0, ("g_destroy_provider with ace")); + g_cancel_event(NULL, NULL, pp, NULL); g_nproviders--; LIST_REMOVE(pp, provider); gp = pp->geom;