mirror of https://github.com/apache/cloudstack.git
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.
This commit is contained in:
parent
eb26ca1f95
commit
6786c24138
|
|
@ -18,7 +18,9 @@ package org.apache.cloudstack.utils.qemu;
|
|||
|
||||
import com.google.common.base.Joiner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
|
|
@ -27,6 +29,10 @@ public class QemuImageOptions {
|
|||
private static final String FILENAME_PARAM_KEY = "file.filename";
|
||||
private static final String LUKS_KEY_SECRET_PARAM_KEY = "key-secret";
|
||||
private static final String QCOW2_KEY_SECRET_PARAM_KEY = "encrypt.key-secret";
|
||||
private static final String DRIVER = "driver";
|
||||
|
||||
private QemuImg.PhysicalDiskFormat format;
|
||||
private static final List<QemuImg.PhysicalDiskFormat> DISK_FORMATS_THAT_SUPPORT_OPTION_IMAGE_OPTS = Arrays.asList(QemuImg.PhysicalDiskFormat.QCOW2, QemuImg.PhysicalDiskFormat.LUKS);
|
||||
|
||||
public QemuImageOptions(String filePath) {
|
||||
params.put(FILENAME_PARAM_KEY, filePath);
|
||||
|
|
@ -55,14 +61,13 @@ public class QemuImageOptions {
|
|||
params.put(LUKS_KEY_SECRET_PARAM_KEY, secretName);
|
||||
}
|
||||
}
|
||||
if (format != null) {
|
||||
params.put("driver", format.toString());
|
||||
}
|
||||
setFormat(format);
|
||||
}
|
||||
|
||||
public void setFormat(QemuImg.PhysicalDiskFormat format) {
|
||||
if (format != null) {
|
||||
params.put("driver", format.toString());
|
||||
params.put(DRIVER, format.toString());
|
||||
this.format = format;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -71,6 +76,9 @@ public class QemuImageOptions {
|
|||
* @return array of strings representing command flag and value (--image-opts)
|
||||
*/
|
||||
public String[] toCommandFlag() {
|
||||
if (format == null || !DISK_FORMATS_THAT_SUPPORT_OPTION_IMAGE_OPTS.contains(format)) {
|
||||
return new String[] { params.get(FILENAME_PARAM_KEY) };
|
||||
}
|
||||
Map<String, String> sorted = new TreeMap<>(params);
|
||||
String paramString = Joiner.on(",").withKeyValueSeparator("=").join(sorted);
|
||||
return new String[] {"--image-opts", paramString};
|
||||
|
|
|
|||
|
|
@ -33,9 +33,9 @@ public class QemuImageOptionsTest {
|
|||
String imagePath = "/path/to/file";
|
||||
String secretName = "secretname";
|
||||
return Arrays.asList(new Object[][] {
|
||||
{ null, imagePath, null, new String[]{"--image-opts","file.filename=/path/to/file"} },
|
||||
{ null, imagePath, null, new String[]{ imagePath } },
|
||||
{ QemuImg.PhysicalDiskFormat.QCOW2, imagePath, null, new String[]{"--image-opts",String.format("driver=qcow2,file.filename=%s", imagePath)} },
|
||||
{ QemuImg.PhysicalDiskFormat.RAW, imagePath, secretName, new String[]{"--image-opts",String.format("driver=raw,file.filename=%s", imagePath)} },
|
||||
{ QemuImg.PhysicalDiskFormat.RAW, imagePath, secretName, new String[]{ imagePath } },
|
||||
{ QemuImg.PhysicalDiskFormat.QCOW2, imagePath, secretName, new String[]{"--image-opts", String.format("driver=qcow2,encrypt.key-secret=%s,file.filename=%s", secretName, imagePath)} },
|
||||
{ QemuImg.PhysicalDiskFormat.LUKS, imagePath, secretName, new String[]{"--image-opts", String.format("driver=luks,file.filename=%s,key-secret=%s", imagePath, secretName)} }
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue