--- geom_event.c.orig Sat Jan 10 22:00:13 2004 +++ geom_event.c Sun Jan 11 15:52:00 2004 @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -309,6 +310,13 @@ va_list ap; struct g_event *ep; int error; +#ifdef INVARIANTS + /* + * This variable is used for deadlock prevention when we're waiting here + * for function which is calling g_waitfor_event() function. + */ + static int waiting_for_function = 0; +#endif /* g_topology_assert_not(); */ KASSERT(flag == M_WAITOK || flag == M_NOWAIT, @@ -318,9 +326,14 @@ va_end(ap); if (error) return (error); + KASSERT(atomic_cmpset_int(&waiting_for_function, 0, 1) == 1, + ("wait-for-event request called recursively")); do tsleep(ep, PRIBIO, "g_waitfor_event", hz); while (!(ep->flag & EV_DONE)); +#ifdef INVARIANTS + atomic_store_rel_int(&waiting_for_function, 0); +#endif if (ep->flag & EV_CANCELED) error = EAGAIN; g_free(ep);