From 21ca3b1227df81b3feb36902e6b44cf2313a58f8 Mon Sep 17 00:00:00 2001 From: Alasdair Kergon Date: Thu, 19 May 2005 16:48:51 +0000 Subject: [PATCH] Fix vgmerge to handle duplicate LVIDs. --- WHATS_NEW | 1 + lib/metadata/metadata.c | 5 +---- tools/vgmerge.c | 27 +++++++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/WHATS_NEW b/WHATS_NEW index cd37ea511..6a8b2704b 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -1,5 +1,6 @@ Version 2.01.11 - ============================== + Fix vgmerge to handle duplicate LVIDs. Move archiver code from tools into library. vgscan/change/display/vgs automatically create metadata backups if needed. Merge cloned allocation functions. diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 2ee881531..60fc1ec69 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -626,14 +626,11 @@ struct lv_list *find_lv_in_vg(struct volume_group *vg, const char *lv_name) struct lv_list *find_lv_in_vg_by_lvid(struct volume_group *vg, const union lvid *lvid) { - struct list *lvh; struct lv_list *lvl; - list_iterate(lvh, &vg->lvs) { - lvl = list_item(lvh, struct lv_list); + list_iterate_items(lvl, &vg->lvs) if (!strncmp(lvl->lv->lvid.s, lvid->s, sizeof(*lvid))) return lvl; - } return NULL; } diff --git a/tools/vgmerge.c b/tools/vgmerge.c index 8be0a688e..00e6b94fb 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -140,6 +140,33 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, } vg_to->pv_count += vg_from->pv_count; + /* Fix up LVIDs */ + list_iterate_items(lvl1, &vg_to->lvs) { + union lvid *lvid1 = &lvl1->lv->lvid; + char uuid[64]; + + list_iterate_items(lvl2, &vg_from->lvs) { + union lvid *lvid2 = &lvl2->lv->lvid; + + if (id_equal(&lvid1->id[1], &lvid2->id[1])) { + if (!id_create(&lvid2->id[1])) { + log_error("Failed to generate new " + "random LVID for %s", + lvl2->lv->name); + goto error; + } + if (!id_write_format(&lvid2->id[1], uuid, + sizeof(uuid))) { + stack; + goto error; + } + + log_verbose("Changed LVID for %s to %s", + lvl2->lv->name, uuid); + } + } + } + while (!list_empty(&vg_from->lvs)) { struct list *lvh = vg_from->lvs.n;