Arik Hadas has uploaded a new change for review.

Change subject: core: fix memory state removal on import vm rollback
......................................................................

core: fix memory state removal on import vm rollback

In case import vm operation fails, we rollback the changes and in
particular we remove the memory states of the imported vm from the
data domain.

This patch fix a problem that the memory state images were not removed
by modify the condition that determines if the memory state should be
removed in that case.

The memory states removal was also improved:
if there are no memory states in the snapshots of the imported vm,
the creation of MemoryImageRemover will be skipped.

Change-Id: I98b9908c5332ed66494cc56d826f95314f4f0fee
Signed-off-by: Arik Hadas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemoverOnDataDomain.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
3 files changed, 6 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/57/17057/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
index 74ee36e..226c3aa 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/ImportVmCommand.java
@@ -1059,9 +1059,9 @@
         setVm(null);
 
         if (getVm() != null) {
+            removeVmSnapshots(getVm());
             endActionOnAllImageGroups();
             removeVmNetworkInterfaces();
-            removeVmSnapshots(getVm());
             getVmDynamicDAO().remove(getVmId());
             getVmStatisticsDAO().remove(getVmId());
             getVmStaticDAO().remove(getVmId());
@@ -1076,7 +1076,9 @@
     private void removeVmSnapshots(VM vm) {
         Set<String> memoriesOfRemovedSnapshots =
                 snapshotsManager.removeSnapshots(vm.getId());
-        new MemoryImageRemoverOnDataDomain(vm, 
this).removeMemoryVolumes(memoriesOfRemovedSnapshots);
+        if (!memoriesOfRemovedSnapshots.isEmpty()) {
+            new MemoryImageRemoverOnDataDomain(vm, 
this).removeMemoryVolumes(memoriesOfRemovedSnapshots);
+        }
     }
 
     protected void removeVmNetworkInterfaces() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemoverOnDataDomain.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemoverOnDataDomain.java
index dd79e2b..67b7e38 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemoverOnDataDomain.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/memory/MemoryImageRemoverOnDataDomain.java
@@ -46,14 +46,10 @@
         return cachedPostZero;
     }
 
-    /**
-     * There is a one to many relation between memory volumes and snapshots, 
so memory
-     * volumes should be removed only if the only snapshot that points to them 
is removed
-     */
     @Override
     protected boolean isMemoryStateRemovable(String memoryVolume) {
         return !memoryVolume.isEmpty() &&
-                
getDbFacade().getSnapshotDao().getNumOfSnapshotsByMemory(memoryVolume) == 1;
+                
getDbFacade().getSnapshotDao().getNumOfSnapshotsByMemory(memoryVolume) == 0;
     }
 
     protected DbFacade getDbFacade() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
index 4f636c0..7142672 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java
@@ -267,6 +267,7 @@
             memoryVolumes.add(snapshot.getMemoryVolume());
             getSnapshotDao().remove(snapshot.getId());
         }
+        memoryVolumes.remove(StringUtils.EMPTY);
         return memoryVolumes;
     }
 


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98b9908c5332ed66494cc56d826f95314f4f0fee
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Arik Hadas <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to