Vered Volansky has uploaded a new change for review.

Change subject: core: ExportVMCommand storage allocation checks
......................................................................

core: ExportVMCommand storage allocation checks

This patch is a part of a series of patches, adding storage allocation
validations to the system when they're missing, and replacing old
verification usage with unified, new, correct and tested verification.
This patch did this for ExportVmCommand, using only existing
validations.

Change-Id: Ic65fdc7324babacda2d1d49dc7157f6799b922f2
Bug-Url: https://bugzilla.redhat.com/1053747
Signed-off-by: Vered Volansky <vvola...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
1 file changed, 23 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/32897/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
index 3604c5f..aeb1305 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ExportVmCommand.java
@@ -131,7 +131,6 @@
             }
         }
 
-
         // check that the images requested format are valid (COW+Sparse)
         if 
(!ImagesHandler.checkImagesConfiguration(getParameters().getStorageDomainId(),
                 disksForExport,
@@ -159,14 +158,11 @@
                     String.format("$storageDomainName %1$s", 
getStorageDomainName()));
         }
 
-        // get the snapshot that are going to be exported and have memory
+        // get the snapshots that are going to be exported and have memory
         snapshotsWithMemory = getSnapshotsToBeExportedWithMemory();
 
         // check destination storage have free space
-        int sizeInGB = (int) 
ImagesHandler.sumImagesTotalSizeWithSnapshotSize(disksForExport) + 
getTotalMemoryStatesSizeGb();
-        if (!doesStorageDomainhaveSpaceForRequest(getStorageDomain(), 
sizeInGB)) {
-            return false;
-        }
+        handleDestStorageDomain(disksForExport);
 
         SnapshotsValidator snapshotValidator = new SnapshotsValidator();
         if (!(checkVmInStorageDomain()
@@ -180,6 +176,27 @@
         }
 
         return true;
+    }
+
+    protected boolean handleDestStorageDomain(List<DiskImage> disksList) {
+        ensureDomainMap(disksList, getStorageDomainId());
+        List<DiskImage> dummiesDisksList = 
createDiskDummiesForSpaceValidations(disksList);
+        dummiesDisksList.addAll(getMemoryDisks());
+        return validateSpaceRequirements(dummiesDisksList);
+    }
+
+    private List<DiskImage> getMemoryDisks() {
+        int numOfSnapshots = snapshotsWithMemory.size();
+        long memorySize = numOfSnapshots * getVm().getTotalMemorySizeInBytes();
+        long metadataSize = numOfSnapshots * 
MemoryUtils.META_DATA_SIZE_IN_BYTES;
+        List<DiskImage> memoryDisksList = 
MemoryUtils.createDiskDummies(memorySize, metadataSize);
+
+        //Set target domain in memory disks
+        ArrayList<Guid> sdId = new 
ArrayList<Guid>(Collections.singletonList(getStorageDomainId()));
+        for (DiskImage diskImage : memoryDisksList) {
+            diskImage.setStorageIds(sdId);
+        }
+        return memoryDisksList;
     }
 
     private Collection<Snapshot> getSnapshotsToBeExportedWithMemory() {
@@ -196,15 +213,6 @@
             memory2snapshot.remove(StringUtils.EMPTY);
             return memory2snapshot.values();
         }
-    }
-
-    private int getTotalMemoryStatesSizeGb() {
-        long sizeInBytes = 0;
-        for (Snapshot snapshot : snapshotsWithMemory) {
-            VM vm = getVmFromSnapshot(snapshot);
-            sizeInBytes += vm.getTotalMemorySizeInBytes() + 
MemoryUtils.META_DATA_SIZE_IN_BYTES;
-        }
-        return (int) Math.ceil(1.0 * sizeInBytes / BYTES_IN_GB);
     }
 
     @Override


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

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

Reply via email to