From 84cd4d3fcc1120e5ebc78e84b922a7944a953988 Mon Sep 17 00:00:00 2001 From: Vaibhav Bhope Date: Thu, 19 Nov 2026 14:44:13 +0530 Subject: [PATCH] lvm: Deduplicate LVs by VG+LV name, not LV name alone bd_lvm_lvs skipped multi-segment duplicates using only lv_name, which dropped same-named LVs from different VGs. Blivet then KeyErrors looking up thin pools such as vgold-tpool0 during Anaconda storage discovery. Co-authored-by: Cursor --- src/plugins/lvm.c | 10 +++++++--- tests/lvm_test.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/plugins/lvm.c b/src/plugins/lvm.c index a07db65bd..2f1296d40 100644 --- a/src/plugins/lvm.c +++ b/src/plugins/lvm.c @@ -1835,10 +1835,14 @@ BDLVMLVdata** bd_lvm_lvs (const gchar *vg_name, GError **error) { /* valid line, try to parse and record it */ lvdata = get_lv_data_from_table (table, TRUE); if (lvdata) { - /* ignore duplicate entries in lvs output, these are caused by multi segments LVs */ + /* ignore duplicate entries in lvs output, these are caused by multi segments LVs. + * Compare both VG and LV name so same-named LVs in different VGs are kept. */ for (gsize i = 0; i < lvs->len; i++) { - if (g_strcmp0 (((BDLVMLVdata *) g_ptr_array_index (lvs, i))->lv_name, lvdata->lv_name) == 0) { - g_debug ("Duplicate LV entry for '%s' found in lvs output", lvdata->lv_name); + BDLVMLVdata *other = (BDLVMLVdata *) g_ptr_array_index (lvs, i); + if (g_strcmp0 (other->vg_name, lvdata->vg_name) == 0 && + g_strcmp0 (other->lv_name, lvdata->lv_name) == 0) { + g_debug ("Duplicate LV entry for '%s/%s' found in lvs output", + lvdata->vg_name, lvdata->lv_name); bd_lvm_lvdata_free (lvdata); lvdata = NULL; break; diff --git a/tests/lvm_test.py b/tests/lvm_test.py index 7d6ee8caa..917a7e104 100644 --- a/tests/lvm_test.py +++ b/tests/lvm_test.py @@ -977,6 +977,42 @@ def test_lvs(self): lvs = BlockDev.lvm_lvs("testVG") self.assertEqual(len(lvs), 1) + def test_lvs_same_name_different_vgs(self): + """Verify system-wide lvs keeps same-named LVs from different VGs""" + + def _cleanup_testvg2(): + try: + BlockDev.lvm_lvremove("testVG2", "testLV", True, None) + except Exception: + pass + try: + BlockDev.lvm_vgremove("testVG2", None) + except Exception: + pass + shutil.rmtree("/dev/testVG2", ignore_errors=True) + + self.addCleanup(_cleanup_testvg2) + + succ = BlockDev.lvm_pvcreate(self.loop_dev, 0, 0, None) + self.assertTrue(succ) + succ = BlockDev.lvm_pvcreate(self.loop_dev2, 0, 0, None) + self.assertTrue(succ) + + succ = BlockDev.lvm_vgcreate("testVG", [self.loop_dev], 0, None) + self.assertTrue(succ) + succ = BlockDev.lvm_vgcreate("testVG2", [self.loop_dev2], 0, None) + self.assertTrue(succ) + + succ = BlockDev.lvm_lvcreate("testVG", "testLV", 10 * 1024**2) + self.assertTrue(succ) + succ = BlockDev.lvm_lvcreate("testVG2", "testLV", 10 * 1024**2) + self.assertTrue(succ) + + lvs = BlockDev.lvm_lvs(None) + matching = [lv for lv in lvs if lv.lv_name == "testLV" and lv.vg_name in ("testVG", "testVG2")] + self.assertEqual(len(matching), 2) + self.assertEqual(sorted(lv.vg_name for lv in matching), ["testVG", "testVG2"]) + class LvmTestLVsMultiSegment(LvmPVVGLVTestCase): def _clean_up(self): try: