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 152159b  kvm: Add the source disk format for disk conversion/copy 
using 'qemu-img convert', when specified explicitly. (#5561)
152159b is described below

commit 152159b13ab4186d0f3c3cd4333cae7079a4b704
Author: sureshanaparti <[email protected]>
AuthorDate: Mon Oct 11 12:00:49 2021 +0530

    kvm: Add the source disk format for disk conversion/copy using 'qemu-img 
convert', when specified explicitly. (#5561)
    
    This PR adds the source disk format (in KVM) for disk conversion/copy using 
'qemu-img convert', when specified explicitly
    
    Fixes: #5516
---
 .../kvm/storage/ScaleIOStorageAdaptor.java         |  2 +-
 .../org/apache/cloudstack/utils/qemu/QemuImg.java  | 65 +++++++++++++++++++---
 2 files changed, 58 insertions(+), 9 deletions(-)

diff --git 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java
 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java
index d73568d..4103d76 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/ScaleIOStorageAdaptor.java
@@ -270,7 +270,7 @@ public class ScaleIOStorageAdaptor implements 
StorageAdaptor {
             destFile = new QemuImgFile(destDisk.getPath(), 
destDisk.getFormat());
 
             LOGGER.debug("Starting copy from source disk image " + 
srcFile.getFileName() + " to PowerFlex volume: " + destDisk.getPath());
-            qemu.convert(srcFile, destFile);
+            qemu.convert(srcFile, destFile, true);
             LOGGER.debug("Succesfully converted source disk image " + 
srcFile.getFileName() + " to PowerFlex volume: " + destDisk.getPath());
         }  catch (QemuImgException | LibvirtException e) {
             try {
diff --git 
a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
 
b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
index fb254af..7de09a3 100644
--- 
a/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
+++ 
b/plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java
@@ -225,7 +225,7 @@ public class QemuImg {
     /**
      * Convert a image from source to destination
      *
-     * This method calls 'qemu-img convert' and takes two objects
+     * This method calls 'qemu-img convert' and takes five objects
      * as an argument.
      *
      *
@@ -238,10 +238,12 @@ public class QemuImg {
      *            pairs which are passed on to qemu-img without validation.
      * @param snapshotName
      *            If it is provided, convertion uses it as parameter
+     * @param forceSourceFormat
+     *            If true, specifies the source format in the conversion cmd
      * @return void
      */
     public void convert(final QemuImgFile srcFile, final QemuImgFile destFile,
-                        final Map<String, String> options, final String 
snapshotName) throws QemuImgException, LibvirtException {
+                        final Map<String, String> options, final String 
snapshotName, final boolean forceSourceFormat) throws QemuImgException, 
LibvirtException {
         Script script = new Script(_qemuImgPath, timeout);
         if (StringUtils.isNotBlank(snapshotName)) {
             String qemuPath = Script.runSimpleBashScript(getQemuImgPathScript);
@@ -254,9 +256,12 @@ public class QemuImg {
             script.add("-U");
         }
 
-        // autodetect source format. Sometime int he future we may teach 
KVMPhysicalDisk about more formats, then we can explicitly pass them if 
necessary
-        //s.add("-f");
-        //s.add(srcFile.getFormat().toString());
+        // autodetect source format unless specified explicitly
+        if (forceSourceFormat) {
+            script.add("-f");
+            script.add(srcFile.getFormat().toString());
+        }
+
         script.add("-O");
         script.add(destFile.getFormat().toString());
 
@@ -272,8 +277,10 @@ public class QemuImg {
         }
 
         if (StringUtils.isNotBlank(snapshotName)) {
-            script.add("-f");
-            script.add(srcFile.getFormat().toString());
+            if (!forceSourceFormat) {
+                script.add("-f");
+                script.add(srcFile.getFormat().toString());
+            }
             script.add("-s");
             script.add(snapshotName);
         }
@@ -294,7 +301,7 @@ public class QemuImg {
     /**
      * Convert a image from source to destination
      *
-     * This method calls 'qemu-img convert' and takes two objects
+     * This method calls 'qemu-img convert' and takes four objects
      * as an argument.
      *
      *
@@ -302,8 +309,31 @@ public class QemuImg {
      *            The source file
      * @param destFile
      *            The destination file
+     * @param options
+     *            Options for the convert. Takes a Map<String, String> with 
key value
+     *            pairs which are passed on to qemu-img without validation.
+     * @param snapshotName
+     *            If it is provided, convertion uses it as parameter
      * @return void
      */
+    public void convert(final QemuImgFile srcFile, final QemuImgFile destFile,
+                        final Map<String, String> options, final String 
snapshotName) throws QemuImgException, LibvirtException {
+        this.convert(srcFile, destFile, options, snapshotName, false);
+    }
+
+        /**
+         * Convert a image from source to destination
+         *
+         * This method calls 'qemu-img convert' and takes two objects
+         * as an argument.
+         *
+         *
+         * @param srcFile
+         *            The source file
+         * @param destFile
+         *            The destination file
+         * @return void
+         */
     public void convert(final QemuImgFile srcFile, final QemuImgFile destFile) 
throws QemuImgException, LibvirtException {
         this.convert(srcFile, destFile, null, null);
     }
@@ -319,6 +349,25 @@ public class QemuImg {
      *            The source file
      * @param destFile
      *            The destination file
+     * @param forceSourceFormat
+     *            If true, specifies the source format in the conversion cmd
+     * @return void
+     */
+    public void convert(final QemuImgFile srcFile, final QemuImgFile destFile, 
final boolean forceSourceFormat) throws QemuImgException, LibvirtException {
+        this.convert(srcFile, destFile, null, null, forceSourceFormat);
+    }
+
+    /**
+     * Convert a image from source to destination
+     *
+     * This method calls 'qemu-img convert' and takes three objects
+     * as an argument.
+     *
+     *
+     * @param srcFile
+     *            The source file
+     * @param destFile
+     *            The destination file
      * @param snapshotName
      *            The snapshot name
      * @return void

Reply via email to