Arik Hadas has uploaded a new change for review.

Change subject: core: refactoring memory removal from active snapshot
......................................................................

core: refactoring memory removal from active snapshot

Remove the caching of the memory on the active snapshot which is no
longer needed.

Change-Id: Ib9e50accbad7810ade1e27ea60fa53e93cd9f3be
Signed-off-by: Arik Hadas <aha...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/CreateVmVDSCommand.java
2 files changed, 14 insertions(+), 21 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/65/37065/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
index 1298e69..0680429 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
@@ -100,8 +100,6 @@
     private RunVmFlow cachedFlow;
     /** Note: this field should not be used directly, use {@link 
#isStatelessSnapshotExistsForVm()} instead */
     private Boolean cachedStatelessSnapshotExistsForVm;
-    /** Cache the memory volume which is stored in the active snapshot of the 
VM */
-    private String cachedMemoryVolumeFromSnapshot;
     /** Indicates whether there is a possibility that the active snapshot's 
memory was already restored */
     private boolean memoryFromSnapshotUsed;
 
@@ -146,19 +144,20 @@
         }
 
         if (getFlow() == RunVmFlow.RESUME_HIBERNATE) {
-            cachedMemoryVolumeFromSnapshot = 
getActiveSnapshot().getMemoryVolume();
-            return cachedMemoryVolumeFromSnapshot;
+             return getActiveSnapshot().getMemoryVolume();
         }
 
-        if (cachedMemoryVolumeFromSnapshot == null) {
-            boolean archSupportSnapshot = 
FeatureSupported.isMemorySnapshotSupportedByArchitecture(
-                    getVm().getClusterArch(),
-                    getVm().getVdsGroupCompatibilityVersion());
-            cachedMemoryVolumeFromSnapshot = archSupportSnapshot && 
FeatureSupported.memorySnapshot(getVm().getVdsGroupCompatibilityVersion()) ?
-                    getActiveSnapshot().getMemoryVolume() : StringUtils.EMPTY;
+        if (!FeatureSupported.isMemorySnapshotSupportedByArchitecture(
+                getVm().getClusterArch(),
+                getVm().getVdsGroupCompatibilityVersion())) {
+            return StringUtils.EMPTY;
         }
 
-        return cachedMemoryVolumeFromSnapshot;
+        if 
(!FeatureSupported.memorySnapshot(getVm().getVdsGroupCompatibilityVersion())) {
+            return StringUtils.EMPTY;
+        }
+
+        return getActiveSnapshot().getMemoryVolume();
     }
 
     /**
@@ -1046,13 +1045,14 @@
     }
 
     private void removeMemoryFromActiveSnapshot() {
-        if (StringUtils.isEmpty(cachedMemoryVolumeFromSnapshot)) {
+        String memory = getActiveSnapshot().getMemoryVolume();
+        if (StringUtils.isEmpty(memory)) {
             return;
         }
 
         // If the active snapshot is the only one that points to the memory 
volume we can remove it
-        if 
(getSnapshotDAO().getNumOfSnapshotsByMemory(cachedMemoryVolumeFromSnapshot) == 
1) {
-            removeMemoryVolumes(cachedMemoryVolumeFromSnapshot, 
getActionType(), true);
+        if (getSnapshotDAO().getNumOfSnapshotsByMemory(memory) == 1) {
+            removeMemoryVolumes(memory, getActionType(), true);
         }
         getSnapshotDAO().removeMemoryFromActiveSnapshot(getVmId());
     }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/CreateVmVDSCommand.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/CreateVmVDSCommand.java
index 4f81347..b7b6101 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/CreateVmVDSCommand.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/CreateVmVDSCommand.java
@@ -30,10 +30,6 @@
     protected void executeVmCommand() {
         final VM vm = getParameters().getVm();
         vm.setLastStartTime(new Date());
-        // if the VM is not suspended, it means that if there is 'hibernation 
volume'
-        // set, it is actually memory from snapshot, thus it should be cleared 
right
-        // after the VM started
-        final boolean clearHibernationVolume = vm.getStatus() != 
VMStatus.Suspended;
         if (canExecute() && 
ResourceManager.getInstance().AddAsyncRunningVm(vm.getId())) {
             CreateVDSCommand<?> command = null;
             try {
@@ -45,9 +41,6 @@
                     vm.setStopReason(null);
                     vm.setInitialized(true);
                     vm.setRunOnVds(getParameters().getVdsId());
-                    if (clearHibernationVolume) {
-                        
DbFacade.getInstance().getSnapshotDao().removeMemoryFromActiveSnapshot(vm.getId());
-                    }
                     vmManager.update(vm.getDynamicData());
                 } else {
                     handleCommandResult(command);


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

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

Reply via email to