diff options
author | ae <ae@FreeBSD.org> | 2012-03-29 06:37:02 +0000 |
---|---|---|
committer | ae <ae@FreeBSD.org> | 2012-03-29 06:37:02 +0000 |
commit | c98223227134e6935d581894b17a5727d70b5f53 (patch) | |
tree | 1cb9a6aedb309140bf31c9592d1ea729a3736bb6 /sys/geom | |
parent | 23518155679a4871e674f90a2e4ab7b9cd514a10 (diff) | |
download | FreeBSD-src-c98223227134e6935d581894b17a5727d70b5f53.zip FreeBSD-src-c98223227134e6935d581894b17a5727d70b5f53.tar.gz |
Do proper cleanup for the GPT case when an error occurs.
Diffstat (limited to 'sys/geom')
-rw-r--r-- | sys/geom/part/g_part_ldm.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/sys/geom/part/g_part_ldm.c b/sys/geom/part/g_part_ldm.c index 6f5939c..dfd1a91 100644 --- a/sys/geom/part/g_part_ldm.c +++ b/sys/geom/part/g_part_ldm.c @@ -1371,14 +1371,15 @@ g_part_ldm_read(struct g_part_table *basetable, struct g_consumer *cp) /* Read and parse LDM private headers. */ error = ldm_privhdr_check(&db, cp, table->is_gpt); if (error != 0) - return (error); + goto gpt_cleanup; basetable->gpt_first = table->is_gpt ? 0: db.ph.start; basetable->gpt_last = basetable->gpt_first + db.ph.size - 1; table->db_offset = db.ph.db_offset; /* Make additional checks for GPT */ if (table->is_gpt) { - if (ldm_gpt_check(&db, cp) != 0) - return (ENXIO); + error = ldm_gpt_check(&db, cp); + if (error != 0) + goto gpt_cleanup; /* * Now we should reset database offset to zero, because our * consumer cp is attached to the ms-ldm-metadata partition @@ -1389,12 +1390,25 @@ g_part_ldm_read(struct g_part_table *basetable, struct g_consumer *cp) /* Read and parse LDM TOC headers. */ error = ldm_tochdr_check(&db, cp); if (error != 0) - return (error); + goto gpt_cleanup; /* Read and parse LDM VMDB header. */ error = ldm_vmdbhdr_check(&db, cp); if (error != 0) - return (error); + goto gpt_cleanup; error = ldm_vmdb_parse(&db, cp); + /* + * For the GPT case we must detach and destroy + * second consumer before return. + */ +gpt_cleanup: + if (table->is_gpt) { + g_topology_lock(); + g_access(cp, -1, 0, 0); + g_detach(cp); + g_destroy_consumer(cp); + g_topology_unlock(); + cp = cp2; + } if (error != 0) return (error); /* Search current disk in the disk list. */ @@ -1408,15 +1422,6 @@ g_part_ldm_read(struct g_part_table *basetable, struct g_consumer *cp) ldm_vmdb_free(&db); return (ENXIO); } - if (table->is_gpt) { - /* Second consumer is no longer needed. */ - g_topology_lock(); - g_access(cp, -1, 0, 0); - g_detach(cp); - g_destroy_consumer(cp); - g_topology_unlock(); - cp = cp2; - } index = 1; LIST_FOREACH(vol, &db.volumes, entry) { LIST_FOREACH(comp, &vol->components, entry) { |