From c27d6695c17e88383587eb0bc8663d0fd8604413 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 24 Oct 2024 19:43:10 +0200 Subject: [PATCH] lv: add lv_set_vg To keep vg->lv_names up-to-date also for merge & split, add function lv_set_vg() the will update also radix tree reference for a VG. --- lib/metadata/lv.c | 16 ++++++++++++++++ lib/metadata/lv.h | 1 + tools/vgmerge.c | 3 ++- tools/vgsplit.c | 3 ++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c index 25f406d1d..3a3081d13 100644 --- a/lib/metadata/lv.c +++ b/lib/metadata/lv.c @@ -1601,6 +1601,22 @@ int lv_set_name(struct logical_volume *lv, const char *lv_name) return 1; } +int lv_set_vg(struct logical_volume *lv, struct volume_group *vg) +{ + const char *lv_name; + + if (lv->vg != vg) { + lv_name = lv->name; + if (!lv_set_name(lv, NULL)) + return_0; /* drop from existing VG radix_tree */ + lv->vg = vg; + if (!lv_set_name(lv, lv_name)) + return_0; + } + + return 1; +} + static char *_time_dup(struct cmd_context *cmd, struct dm_pool *mem, time_t ts, int iso_mode) { diff --git a/lib/metadata/lv.h b/lib/metadata/lv.h index 89a4a2dbd..b64bc8cb6 100644 --- a/lib/metadata/lv.h +++ b/lib/metadata/lv.h @@ -154,6 +154,7 @@ char *lvseg_kernel_discards_dup(struct dm_pool *mem, const struct lv_segment *se int lv_set_creation(struct logical_volume *lv, const char *hostname, uint64_t timestamp); int lv_set_name(struct logical_volume *lv, const char *lv_name); +int lv_set_vg(struct logical_volume *lv, struct volume_group *vg); int lv_active_change(struct cmd_context *cmd, struct logical_volume *lv, enum activation_change activate); diff --git a/tools/vgmerge.c b/tools/vgmerge.c index 4ed4a8f0b..18f6777f8 100644 --- a/tools/vgmerge.c +++ b/tools/vgmerge.c @@ -156,7 +156,8 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to, } dm_list_iterate_items(lvl1, &vg_from->lvs) { - lvl1->lv->vg = vg_to; + if (!lv_set_vg(lvl1->lv, vg_to)) + goto_bad; lvl1->lv->lvid.id[0] = lvl1->lv->vg->id; } diff --git a/tools/vgsplit.c b/tools/vgsplit.c index 2f2b89b06..bc0e131cf 100644 --- a/tools/vgsplit.c +++ b/tools/vgsplit.c @@ -49,7 +49,8 @@ static int _lv_tree_move(struct dm_list *lvh, *lvht = dm_list_next(lvh, lvh); dm_list_move(&vg_to->lvs, lvh); - lv->vg = vg_to; + if (!lv_set_vg(lv, vg_to)) + return_0; lv->lvid.id[0] = lv->vg->id; if (seg)