Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/plugins/lvm/lvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1784,13 +1784,16 @@ BDLVMLVdata** bd_lvm_lvs (const gchar *vg_name, GError **error) {
JsonObject *lv_obj = json_array_get_object_element (lv_array, i);
BDLVMLVdata *lvdata = get_lv_data_from_json (lv_obj);
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. */
gboolean duplicate = FALSE;
for (gsize j = 0; j < lvs->len; j++) {
if (g_strcmp0 (((BDLVMLVdata *) g_ptr_array_index (lvs, j))->lv_name, lvdata->lv_name) == 0) {
BDLVMLVdata *other = (BDLVMLVdata *) g_ptr_array_index (lvs, j);
if (g_strcmp0 (other->vg_name, lvdata->vg_name) == 0 &&
g_strcmp0 (other->lv_name, lvdata->lv_name) == 0) {
bd_utils_log_format (BD_UTILS_LOG_DEBUG,
"Duplicate LV entry for '%s' found in lvs output",
lvdata->lv_name);
"Duplicate LV entry for '%s/%s' found in lvs output",
lvdata->vg_name, lvdata->lv_name);
bd_lvm_lvdata_free (lvdata);
duplicate = TRUE;
break;
Expand Down Expand Up @@ -1855,7 +1858,9 @@ BDLVMLVdata** bd_lvm_lvs_tree (const gchar *vg_name, GError **error) {
gboolean merged = FALSE;
for (gsize j = 0; j < lvs->len; j++) {
BDLVMLVdata *other = (BDLVMLVdata *) g_ptr_array_index (lvs, j);
if (g_strcmp0 (other->lv_name, lvdata->lv_name) == 0) {
/* Merge only segments of the same LV (same VG + LV name). */
if (g_strcmp0 (other->vg_name, lvdata->vg_name) == 0 &&
g_strcmp0 (other->lv_name, lvdata->lv_name) == 0) {
merge_lv_data (other, lvdata);
bd_lvm_lvdata_free (lvdata);
merged = TRUE;
Expand Down
28 changes: 28 additions & 0 deletions tests/_lvm_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,34 @@ 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"""

# cleanups run LIFO: remove LV, then VG, then leftover /dev node
self.addCleanup(shutil.rmtree, "/dev/testVG2", ignore_errors=True)
self.addCleanup(BlockDev.lvm_vgremove, "testVG2", None)
self.addCleanup(self._lvremove, "testVG2", "testLV")

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.assertCountEqual([lv.vg_name for lv in matching], ["testVG", "testVG2"])

def test_lvinfo_tree(self):
"""Verify that it's possible to gather info about LVs"""

Expand Down
Loading