Index: sys/geom/geom_dev.c =================================================================== --- sys/geom/geom_dev.c +++ sys/geom/geom_dev.c @@ -346,7 +346,7 @@ cp->private = sc; cp->flags |= G_CF_DIRECT_SEND | G_CF_DIRECT_RECEIVE; error = g_attach(cp, pp); - KASSERT(error == 0, + KASSERT(error == 0 || error == ENXIO, ("g_dev_taste(%s) failed to g_attach, err=%d", pp->name, error)); make_dev_args_init(&args); Index: sys/geom/geom_subr.c =================================================================== --- sys/geom/geom_subr.c +++ sys/geom/geom_subr.c @@ -896,6 +896,8 @@ G_VALID_PROVIDER(pp); g_trace(G_T_TOPOLOGY, "g_attach(%p, %p)", cp, pp); KASSERT(cp->provider == NULL, ("attach but attached")); + if ((pp->flags & (G_PF_ORPHAN | G_PF_WITHER)) != 0) + return (ENXIO); cp->provider = pp; cp->flags &= ~G_CF_ORPHAN; LIST_INSERT_HEAD(&pp->consumers, cp, consumers); Index: sys/geom/geom_vfs.c =================================================================== --- sys/geom/geom_vfs.c +++ sys/geom/geom_vfs.c @@ -260,7 +260,11 @@ sc->sc_bo = bo; gp->softc = sc; cp = g_new_consumer(gp); - g_attach(cp, pp); + error = g_attach(cp, pp); + if (error) { + g_wither_geom(gp, ENXIO); + return (error); + } error = g_access(cp, 1, wr, wr); if (error) { g_wither_geom(gp, ENXIO); Index: sys/geom/mountver/g_mountver.c =================================================================== --- sys/geom/mountver/g_mountver.c +++ sys/geom/mountver/g_mountver.c @@ -586,7 +586,12 @@ return (NULL); cp = LIST_FIRST(&gp->consumer); - g_attach(cp, pp); + error = g_attach(cp, pp); + if (error != 0) { + G_MOUNTVER_DEBUG(0, "Cannot attach to %s; error = %d.", pp->name, error); + return (NULL); + } + error = g_mountver_ident_matches(gp); if (error != 0) { g_detach(cp);