Skip to content

Commit 7fa150f

Browse files
committed
linstor: escape dashes in the LVM volume group name of snapshot paths
Device-mapper doubles every dash in both the volume group and the logical volume name. getSnapshotPath only escaped the resource and snapshot name, so on a VG like "linstor_pool-lvm-thin" the computed /dev/mapper path did not exist and backing up a snapshot to secondary storage failed with "qemu-img: Could not open". Fixes apache#14011 (cherry picked from commit 9df44ce)
1 parent 5c85f20 commit 7fa150f

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,10 @@ public static String getSnapshotPath(com.linbit.linstor.api.model.StoragePool sp
287287
switch (sp.getProviderKind()) {
288288
case LVM: // thick LVM snapshot LVs use the same naming scheme as thin
289289
case LVM_THIN:
290+
// device-mapper doubles every dash in the VG and LV name, so the VG part needs escaping too
291+
final String vgName = backingPool.split("/")[0];
290292
path = String.format("/dev/mapper/%s-%s_%s_%s",
291-
backingPool.split("/")[0], rscName.replace("-", "--"), suffix, snapshotName.replace("-", "--"));
293+
vgName.replace("-", "--"), rscName.replace("-", "--"), suffix, snapshotName.replace("-", "--"));
292294
break;
293295
case ZFS:
294296
case ZFS_THIN:

‎plugins/storage/volume/linstor/src/test/java/org/apache/cloudstack/storage/datastore/util/LinstorUtilTest.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ public void testGetSnapshotPath() {
126126
String snapPath = LinstorUtil.getSnapshotPath(spLVM, "cs-cb32532a-dd8f-47e0-a81c-8a75573d3545", "cs-6c6b4e95");
127127
Assert.assertEquals(
128128
"/dev/mapper/shared-cs--cb32532a--dd8f--47e0--a81c--8a75573d3545_00000_cs--6c6b4e95", snapPath);
129+
130+
// dashes in the volume group name must be escaped as well (GH issue #14011)
131+
StoragePool spLVMThin = new StoragePool();
132+
Properties lvmThinProps = new Properties();
133+
lvmThinProps.put("StorDriver/StorPoolName", "linstor_pool-lvm-thin/thin");
134+
spLVMThin.setProps(lvmThinProps);
135+
spLVMThin.setProviderKind(ProviderKind.LVM_THIN);
136+
String thinSnapPath = LinstorUtil.getSnapshotPath(spLVMThin,
137+
"cs-12fc4055-3985-4025-8eb5-d6fd53effe37", "cs-d7aea646-5f40-46a2-b9dc-77e41ea29336");
138+
Assert.assertEquals(
139+
"/dev/mapper/linstor_pool--lvm--thin-cs--12fc4055--3985--4025--8eb5--d6fd53effe37_00000_cs--d7aea646--5f40--46a2--b9dc--77e41ea29336",
140+
thinSnapPath);
129141
}
130142

131143
{

0 commit comments

Comments
 (0)