This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new 6786c24138b kvm: fix backup volume snapshot fails on RBD storage 
(#6790)
6786c24138b is described below

commit 6786c24138b903115f1922f03ccf4025e6bb1313
Author: Wei Zhou <[email protected]>
AuthorDate: Sat Oct 8 08:25:33 2022 +0200

    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.
---
 .../apache/cloudstack/utils/qemu/QemuImageOptions.java   | 16 ++++++++++++----
 .../cloudstack/utils/qemu/QemuImageOptionsTest.java      |  4 ++--
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git 
a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImageOptions.java
 
b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImageOptions.java
index 4e2c1c4bc69..f9a2e4ba652 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImageOptions.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImageOptions.java
@@ -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};
diff --git 
a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImageOptionsTest.java
 
b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImageOptionsTest.java
index 2b56b69d1c5..644c49543aa 100644
--- 
a/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImageOptionsTest.java
+++ 
b/plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImageOptionsTest.java
@@ -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)} }
         });

Reply via email to