--- geom_vinum_events.c.old Tue Apr 3 19:08:32 2007 +++ geom_vinum_events.c Tue Apr 3 18:57:22 2007 @@ -103,22 +103,20 @@ d = gv_find_drive(sc, hdr->label.name); if (d == NULL) { d = g_malloc(sizeof(*d), M_WAITOK | M_ZERO); - d->consumer = cp; - d->hdr = hdr; strncpy(d->name, hdr->label.name, GV_MAXDRIVENAME); strncpy(d->device, pp->name, GV_MAXDRIVENAME); - gv_create_drive(sc, d); } else if (d->flags & GV_DRIVE_REFERENCED) { - d->consumer = cp; - d->hdr = hdr; strncpy(d->device, pp->name, GV_MAXDRIVENAME); d->flags &= ~GV_DRIVE_REFERENCED; - gv_create_drive(sc, d); } else { printf("DEBUG: drive '%s' is already known\n", d->name); g_free(hdr); goto failed; } + /* Add the consumer and header to the new drive. */ + d->consumer = cp; + d->hdr = hdr; + gv_create_drive(sc, d); buf = g_read_data(cp, GV_CFG_OFFSET, GV_CFG_LEN, NULL); if (buf == NULL) { @@ -206,11 +204,13 @@ /* * Don't forget that gv_is_newer wants a "real" drive at the beginning * of the list, so, just to be safe, we shuffle around. - * XXX: d2 == NULL */ LIST_REMOVE(d, drive); d2 = LIST_FIRST(&sc->drives); - LIST_INSERT_AFTER(d2, d, drive); + if (d2 == NULL) + LIST_INSERT_HEAD(&sc->drives, d, drive); + else + LIST_INSERT_AFTER(d2, d, drive); } /* @@ -227,6 +227,8 @@ struct gv_hdr *hdr; struct gv_freelist *fl; + KASSERT(d != NULL, ("gv_create_drive: NULL d")); + gp = sc->geom; pp = NULL; @@ -272,12 +274,14 @@ * If this was just a "referenced" drive, we're almost finished, but * insert this drive not on the head of the drives list, as * gv_drive_is_newer() expects a "real" drive from LIST_FIRST(). - * XXX: d2 == NULL */ if (d->flags & GV_DRIVE_REFERENCED) { snprintf(d->device, GV_MAXDRIVENAME, "???"); d2 = LIST_FIRST(&sc->drives); - LIST_INSERT_AFTER(d2, d, drive); + if (d2 == NULL) + LIST_INSERT_HEAD(&sc->drives, d, drive); + else + LIST_INSERT_AFTER(d2, d, drive); return; } @@ -340,6 +344,10 @@ void gv_create_volume(struct gv_softc *sc, struct gv_volume *v) { + + KASSERT(v != NULL, ("gv_create_volume: NULL v")); + + v->plexcount = 0; v->vinumconf = sc; LIST_INIT(&v->plexes); LIST_INSERT_HEAD(&sc->volumes, v, volume); @@ -350,6 +358,8 @@ { struct gv_volume *v; + KASSERT(p != NULL, ("gv_create_plex: NULL p")); + /* Find the volume this plex should be attached to. */ v = gv_find_vol(sc, p->volume); if (v == NULL) { @@ -380,6 +390,8 @@ struct gv_sd *s2; struct gv_drive *d; + KASSERT(s != NULL, ("gv_create_sd: NULL s")); + /* Find the drive where this subdisk should be put on. */ d = gv_find_drive(sc, s->drive); if (d == NULL) { @@ -437,21 +449,7 @@ */ if (!(p->flags & GV_PLEX_NEWBORN)) return; - LIST_FOREACH_SAFE(s, &p->subdisks, in_plex, s2) { - if (s->drive_sc) - LIST_REMOVE(s, from_drive); - p->sdcount--; - LIST_REMOVE(s, in_plex); - LIST_REMOVE(s, sd); - gv_free_sd(s); - g_free(s); - } - if (p->vol_sc != NULL) { - LIST_REMOVE(p, in_volume); - p->vol_sc->plexcount--; - } - LIST_REMOVE(p, plex); - g_free(p); + gv_rm_plex(sc, p); return; } s->flags |= GV_SD_NEWBORN;