Arik Hadas has uploaded a new change for review.

Change subject: core: restore memory from snapshot on run vm
......................................................................

core: restore memory from snapshot on run vm

If we're going to run a VM which is not suspended and its active
snapshot contains memory, we set the memory volume that the active
snapshot points to as the initial memory state of the VM.

Change-Id: Iee1e4149db44d690726f00d366562df07eb5cacd
Bug-Url: https://bugzilla.redhat.com/960931
Signed-off-by: Arik Hadas <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CreateVmVDSCommandParameters.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/CreateVmVDSCommand.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
4 files changed, 50 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/80/15680/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 f13a983..1706e50 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
@@ -37,6 +37,7 @@
 import org.ovirt.engine.core.common.businessentities.Entities;
 import org.ovirt.engine.core.common.businessentities.ImageFileType;
 import org.ovirt.engine.core.common.businessentities.RepoFileMetaData;
+import org.ovirt.engine.core.common.businessentities.Snapshot;
 import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
 import org.ovirt.engine.core.common.businessentities.StorageDomain;
 import org.ovirt.engine.core.common.businessentities.StorageDomainStatus;
@@ -82,6 +83,8 @@
     private boolean mResume;
     private boolean _isVmRunningStateless;
     private boolean isFailedStatlessSnapshot;
+    /** Indicates whether restoration of memory from snapshot is supported for 
the VM */
+    private boolean memorySnapshotSupported;
 
     protected RunVmCommand(Guid commandId) {
         super(commandId);
@@ -129,6 +132,10 @@
 
             // set vm disks
             VmHandler.updateDisksForVm(getVm(), 
getDiskDao().getAllForVm(getVm().getId()));
+
+            if (getVm().getStatus() != VMStatus.Suspended) {
+                memorySnapshotSupported = 
FeatureSupported.memorySnapshot(getVm().getVdsGroupCompatibilityVersion());
+            }
         }
     }
 
@@ -444,11 +451,29 @@
     }
 
     /**
-     * Initial the parameters for the VDSM command for VM creation
+     * Initial the parameters for the VDSM command of VM creation
      * @return the VDS create VM parameters
      */
     protected CreateVmVDSCommandParameters initVdsCreateVmParams() {
-        return new CreateVmVDSCommandParameters(getVdsId(), getVm());
+        VM vmToBeCreated = getVm();
+
+        if (vmToBeCreated.getStatus() == VMStatus.Suspended) {
+            return new CreateVmVDSCommandParameters(getVdsId(), vmToBeCreated);
+        }
+
+        if (!memorySnapshotSupported) {
+            vmToBeCreated.setHibernationVolHandle(StringUtils.EMPTY);
+            return new CreateVmVDSCommandParameters(getVdsId(), vmToBeCreated);
+        }
+
+        // otherwise, use the memory that is saved on the active snapshot 
(might be empty)
+        Snapshot activeSnapshotOfVmToBeCreated =
+                getDbFacade().getSnapshotDao().get(vmToBeCreated.getId(), 
SnapshotType.ACTIVE);
+        
vmToBeCreated.setHibernationVolHandle(activeSnapshotOfVmToBeCreated.getMemoryVolume());
+        CreateVmVDSCommandParameters parameters =
+                new CreateVmVDSCommandParameters(getVdsId(), vmToBeCreated);
+        parameters.setClearHibernationVolumes(true);
+        return parameters;
     }
 
     @Override
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CreateVmVDSCommandParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CreateVmVDSCommandParameters.java
index 2247b86..0581667 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CreateVmVDSCommandParameters.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/vdscommands/CreateVmVDSCommandParameters.java
@@ -5,20 +5,21 @@
 import org.ovirt.engine.core.compat.Guid;
 
 public class CreateVmVDSCommandParameters extends VdsAndVmIDVDSParametersBase {
-    public CreateVmVDSCommandParameters(Guid vdsId, VM vm) {
-        super(vdsId, vm.getId());
-        _vm = vm;
-    }
 
-    private VM _vm;
-
+    private VM vm;
     private SysPrepParams sysPrepParams;
-
-    public VM getVm() {
-        return _vm;
-    }
+    private boolean clearHibernationVolumes;
 
     public CreateVmVDSCommandParameters() {
+    }
+
+    public CreateVmVDSCommandParameters(Guid vdsId, VM vm) {
+        super(vdsId, vm.getId());
+        this.vm = vm;
+    }
+
+    public VM getVm() {
+        return vm;
     }
 
     @Override
@@ -33,4 +34,12 @@
     public void setSysPrepParams(SysPrepParams sysPrepParams) {
         this.sysPrepParams = sysPrepParams;
     }
+
+    public boolean isClearHibernationVolumes() {
+        return clearHibernationVolumes;
+    }
+
+    public void setClearHibernationVolumes(boolean clearHibernationVolumes) {
+        this.clearHibernationVolumes = clearHibernationVolumes;
+    }
 }
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 26db456..84ce73e 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
@@ -71,6 +71,9 @@
                                         public Object runInTransaction() {
                                             HandleVdsInformation();
                                             vm.setRunOnVds(getVdsId());
+                                            if 
(getParameters().isClearHibernationVolumes()) {
+                                                
vm.setHibernationVolHandle(StringUtils.EMPTY);
+                                            }
                                             
DbFacade.getInstance().getVmDynamicDao().update(vm.getDynamicData());
                                             return null;
                                         }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
index 71f6a21..cc5a848 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilderBase.java
@@ -16,7 +16,6 @@
 import org.ovirt.engine.core.common.businessentities.Disk;
 import org.ovirt.engine.core.common.businessentities.DisplayType;
 import org.ovirt.engine.core.common.businessentities.VM;
-import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmBase;
 import org.ovirt.engine.core.common.businessentities.VmType;
 import 
org.ovirt.engine.core.common.businessentities.comparators.DiskImageByDiskAliasComparator;
@@ -94,8 +93,7 @@
         }
         createInfo.put(VdsProperties.niceLevel,
                 String.valueOf(vm.getNiceLevel()));
-        if (vm.getStatus() == VMStatus.Suspended
-                && !StringUtils.isEmpty(vm.getHibernationVolHandle())) {
+        if (!StringUtils.isEmpty(vm.getHibernationVolHandle())) {
             createInfo.put(VdsProperties.hiberVolHandle,
                     vm.getHibernationVolHandle());
         }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iee1e4149db44d690726f00d366562df07eb5cacd
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