Skip to content

Commit 6786c24

Browse files
kvm: fix backup volume snapshot fails on RBD storage (#6790)
This PR fixes the issue that volume snapshot fails on RBD storage with the following error qemu-img: Could not open 'driver=raw,file.filename=rbd:cloudstack/test_wei.img:mon_host=10.0.32.254:auth_supported=cephx:id=cloudstack:key=AQDwHTNjjHXRKRAAJb+AToFr6x4a1AvKUc4Ksg==:rbd_default_format=2:client_mount_timeout=30': Could not open 'rbd:cloudstack/test_wei.img:mon_host=10.0.32.254:auth_supported=cephx:id=cloudstack:key=AQDwHTNjjHXRKRAAJb+AToFr6x4a1AvKUc4Ksg==:rbd_default_format=2:client_mount_timeout=30': No such file or directory However, it works without using image options Therefore, do not pass the image options if the image format is not QCOW2 and LUKS.
1 parent eb26ca1 commit 6786c24

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImageOptions.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919
import com.google.common.base.Joiner;
2020

21+
import java.util.Arrays;
2122
import java.util.HashMap;
23+
import java.util.List;
2224
import java.util.Map;
2325
import java.util.TreeMap;
2426

@@ -27,6 +29,10 @@ public class QemuImageOptions {
2729
private static final String FILENAME_PARAM_KEY = "file.filename";
2830
private static final String LUKS_KEY_SECRET_PARAM_KEY = "key-secret";
2931
private static final String QCOW2_KEY_SECRET_PARAM_KEY = "encrypt.key-secret";
32+
private static final String DRIVER = "driver";
33+
34+
private QemuImg.PhysicalDiskFormat format;
35+
private static final List<QemuImg.PhysicalDiskFormat> DISK_FORMATS_THAT_SUPPORT_OPTION_IMAGE_OPTS = Arrays.asList(QemuImg.PhysicalDiskFormat.QCOW2, QemuImg.PhysicalDiskFormat.LUKS);
3036

3137
public QemuImageOptions(String filePath) {
3238
params.put(FILENAME_PARAM_KEY, filePath);
@@ -55,14 +61,13 @@ public QemuImageOptions(QemuImg.PhysicalDiskFormat format, String filePath, Stri
5561
params.put(LUKS_KEY_SECRET_PARAM_KEY, secretName);
5662
}
5763
}
58-
if (format != null) {
59-
params.put("driver", format.toString());
60-
}
64+
setFormat(format);
6165
}
6266

6367
public void setFormat(QemuImg.PhysicalDiskFormat format) {
6468
if (format != null) {
65-
params.put("driver", format.toString());
69+
params.put(DRIVER, format.toString());
70+
this.format = format;
6671
}
6772
}
6873

@@ -71,6 +76,9 @@ public void setFormat(QemuImg.PhysicalDiskFormat format) {
7176
* @return array of strings representing command flag and value (--image-opts)
7277
*/
7378
public String[] toCommandFlag() {
79+
if (format == null || !DISK_FORMATS_THAT_SUPPORT_OPTION_IMAGE_OPTS.contains(format)) {
80+
return new String[] { params.get(FILENAME_PARAM_KEY) };
81+
}
7482
Map<String, String> sorted = new TreeMap<>(params);
7583
String paramString = Joiner.on(",").withKeyValueSeparator("=").join(sorted);
7684
return new String[] {"--image-opts", paramString};

plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImageOptionsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ public static Collection<Object[]> data() {
3333
String imagePath = "/path/to/file";
3434
String secretName = "secretname";
3535
return Arrays.asList(new Object[][] {
36-
{ null, imagePath, null, new String[]{"--image-opts","file.filename=/path/to/file"} },
36+
{ null, imagePath, null, new String[]{ imagePath } },
3737
{ QemuImg.PhysicalDiskFormat.QCOW2, imagePath, null, new String[]{"--image-opts",String.format("driver=qcow2,file.filename=%s", imagePath)} },
38-
{ QemuImg.PhysicalDiskFormat.RAW, imagePath, secretName, new String[]{"--image-opts",String.format("driver=raw,file.filename=%s", imagePath)} },
38+
{ QemuImg.PhysicalDiskFormat.RAW, imagePath, secretName, new String[]{ imagePath } },
3939
{ QemuImg.PhysicalDiskFormat.QCOW2, imagePath, secretName, new String[]{"--image-opts", String.format("driver=qcow2,encrypt.key-secret=%s,file.filename=%s", secretName, imagePath)} },
4040
{ QemuImg.PhysicalDiskFormat.LUKS, imagePath, secretName, new String[]{"--image-opts", String.format("driver=luks,file.filename=%s,key-secret=%s", imagePath, secretName)} }
4141
});

0 commit comments

Comments
 (0)