Skip to content

Commit 9df44ce

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 #14011
1 parent 2b3cca6 commit 9df44ce

2 files changed

Lines changed: 17 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
@@ -204,8 +204,10 @@ public static String getSnapshotPath(com.linbit.linstor.api.model.StoragePool sp
204204
final String path;
205205
switch (sp.getProviderKind()) {
206206
case LVM_THIN:
207+
// device-mapper doubles every dash in the VG and LV name, so the VG part needs escaping too
208+
final String vgName = backingPool.split("/")[0];
207209
path = String.format("/dev/mapper/%s-%s_%s_%s",
208-
backingPool.split("/")[0], rscName.replace("-", "--"), suffix, snapshotName.replace("-", "--"));
210+
vgName.replace("-", "--"), rscName.replace("-", "--"), suffix, snapshotName.replace("-", "--"));
209211
break;
210212
case ZFS:
211213
case ZFS_THIN:

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ public void testGetSnapshotPath() {
103103
Assert.assertEquals("/dev/mapper/storage-cs--cb32532a--dd8f--47e0--a81c--8a75573d3545_00000_snap3", snapPath);
104104
}
105105

106+
{
107+
// dashes in the volume group name must be escaped as well (GH issue #14011)
108+
StoragePool spLVMThin = new StoragePool();
109+
Properties lvmThinProps = new Properties();
110+
lvmThinProps.put("StorDriver/StorPoolName", "linstor_pool-lvm-thin/thin");
111+
spLVMThin.setProps(lvmThinProps);
112+
spLVMThin.setProviderKind(ProviderKind.LVM_THIN);
113+
String snapPath = LinstorUtil.getSnapshotPath(spLVMThin,
114+
"cs-12fc4055-3985-4025-8eb5-d6fd53effe37", "cs-d7aea646-5f40-46a2-b9dc-77e41ea29336");
115+
Assert.assertEquals(
116+
"/dev/mapper/linstor_pool--lvm--thin-cs--12fc4055--3985--4025--8eb5--d6fd53effe37_00000_cs--d7aea646--5f40--46a2--b9dc--77e41ea29336",
117+
snapPath);
118+
}
119+
106120
{
107121
StoragePool spZFS = new StoragePool();
108122
Properties zfsProps = new Properties();

0 commit comments

Comments
 (0)