Tal Nisan has uploaded a new change for review.

Change subject: core: Set image format correctly when creating template image 
on block domain
......................................................................

core: Set image format correctly when creating template image on block domain

When creating a template from a VM with a disk on an NFS domain without
snapshots (Raw+Sparse) on a block domain, the copy operation will fail
since this image configuration is not supported on block domains, this
patch causes the format to be changed from raw to cow in this situations
to avoid that problem

Change-Id: Icfa0843d3cad69682f6030ed47ec1699c106447a
Signed-off-by: Tal Nisan <tni...@redhat.com>
Bug-Url: https://bugzilla.redhat.com/1128776
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateImageTemplateCommand.java
1 file changed, 27 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/35/31635/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateImageTemplateCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateImageTemplateCommand.java
index a0d5537..6e6c212 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateImageTemplateCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateImageTemplateCommand.java
@@ -16,6 +16,9 @@
 import org.ovirt.engine.core.common.businessentities.CopyVolumeType;
 import org.ovirt.engine.core.common.businessentities.DiskImage;
 import org.ovirt.engine.core.common.businessentities.DiskImageDynamic;
+import org.ovirt.engine.core.common.businessentities.StorageDomainStatic;
+import org.ovirt.engine.core.common.businessentities.VolumeFormat;
+import org.ovirt.engine.core.common.businessentities.VolumeType;
 import org.ovirt.engine.core.common.vdscommands.CopyImageVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.common.vdscommands.VDSReturnValue;
@@ -53,13 +56,15 @@
 
         Guid taskId = getAsyncTaskId();
 
+        VolumeFormat targetFormat = 
getTargetVolumeFormat(newImage.getVolumeFormat(), newImage.getVolumeType(),
+                getParameters().getDestinationStorageDomainId());
+
         VDSReturnValue vdsReturnValue = runVdsCommand(VDSCommandType.CopyImage,
                 new CopyImageVDSCommandParameters(storagePoolId, 
getParameters().getStorageDomainId(),
                                 getParameters().getVmId(), imageGroupId, 
snapshotId, destinationImageGroupID,
                                 getDestinationImageId(), 
StringUtils.defaultString(newImage.getDescription()), getParameters()
-                                        .getDestinationStorageDomainId(), 
CopyVolumeType.SharedVol, newImage
-                                        .getVolumeFormat(), 
newImage.getVolumeType(), getDiskImage()
-                                        .isWipeAfterDelete(), false));
+                                        .getDestinationStorageDomainId(), 
CopyVolumeType.SharedVol, targetFormat,
+                                        newImage.getVolumeType(), 
getDiskImage().isWipeAfterDelete(), false));
 
         getReturnValue().getInternalVdsmTaskIdList().add(
                 createTask(taskId,
@@ -94,6 +99,25 @@
     }
 
     /**
+     * Since we are supporting copy/move operations between different storage 
families (file/block) we have to
+     * predetermine the volume format according to the destination storage 
type, for block domains we cannot use sparse
+     * combined with raw so we will change the raw to cow in that case, file 
domains will have the original format
+     * retained
+     *
+     * TODO: Extract method and unite with getVolumeFormatForDomain() in 
CopyImageGroupCommand
+     */
+    private VolumeFormat getTargetVolumeFormat(VolumeFormat volumeFormat, 
VolumeType volumeType, Guid storageDomainId) {
+        if (volumeFormat == VolumeFormat.RAW && volumeType == 
VolumeType.Sparse) { //
+            StorageDomainStatic destDomain = 
getStorageDomainStaticDAO().get(storageDomainId);
+            if (destDomain.getStorageType().isBlockDomain()) {
+                return VolumeFormat.COW;
+            }
+        }
+
+        return volumeFormat;
+    }
+
+    /**
      * Fill the volume information from the image ancestor (if available, if 
not then from the father image).
      *
      * @param disk


-- 
To view, visit http://gerrit.ovirt.org/31635
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icfa0843d3cad69682f6030ed47ec1699c106447a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tal Nisan <tni...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to