Make the code more obvious - when an error occurs in g_mirror_connect_disk(),
detach and destroy consumer before returning.
This commit is contained in:
parent
adbc064c96
commit
65028f364f
@ -375,24 +375,30 @@ g_mirror_kill_consumer(struct g_mirror_softc *sc, struct g_consumer *cp)
|
||||
static int
|
||||
g_mirror_connect_disk(struct g_mirror_disk *disk, struct g_provider *pp)
|
||||
{
|
||||
struct g_consumer *cp;
|
||||
int error;
|
||||
|
||||
g_topology_assert();
|
||||
KASSERT(disk->d_consumer == NULL,
|
||||
("Disk already connected (device %s).", disk->d_softc->sc_name));
|
||||
|
||||
disk->d_consumer = g_new_consumer(disk->d_softc->sc_geom);
|
||||
disk->d_consumer->private = disk;
|
||||
disk->d_consumer->index = 0;
|
||||
error = g_attach(disk->d_consumer, pp);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
error = g_access(disk->d_consumer, 1, 1, 1);
|
||||
cp = g_new_consumer(disk->d_softc->sc_geom);
|
||||
error = g_attach(cp, pp);
|
||||
if (error != 0) {
|
||||
g_destroy_consumer(cp);
|
||||
return (error);
|
||||
}
|
||||
error = g_access(cp, 1, 1, 1);
|
||||
if (error != 0) {
|
||||
g_detach(cp);
|
||||
g_destroy_consumer(cp);
|
||||
G_MIRROR_DEBUG(0, "Cannot open consumer %s (error=%d).",
|
||||
pp->name, error);
|
||||
return (error);
|
||||
}
|
||||
disk->d_consumer = cp;
|
||||
disk->d_consumer->private = disk;
|
||||
disk->d_consumer->index = 0;
|
||||
|
||||
G_MIRROR_DEBUG(2, "Disk %s connected.", g_mirror_get_diskname(disk));
|
||||
return (0);
|
||||
@ -453,10 +459,8 @@ g_mirror_init_disk(struct g_mirror_softc *sc, struct g_provider *pp,
|
||||
fail:
|
||||
if (errorp != NULL)
|
||||
*errorp = error;
|
||||
if (disk != NULL) {
|
||||
g_mirror_disconnect_consumer(sc, disk->d_consumer);
|
||||
if (disk != NULL)
|
||||
free(disk, M_MIRROR);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user