Arik Hadas has uploaded a new change for review. Change subject: core: introduce command that removes hibernation volumes ......................................................................
core: introduce command that removes hibernation volumes Add RemoveVmHibernationVolumesCommand which removes the hibernation volumes of the VM with the given id. This method basically do what VmCommand#removeMemoryVolumes method do and it is another step towards removing that method from VmCommand class. Change-Id: I425060c820e03f5818600fa119a70199d1a67840 Signed-off-by: Arik Hadas <aha...@redhat.com> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmHibernationVolumesCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java A backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/RemoveVmHibernationVolumesParameters.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java 5 files changed, 175 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/92/17692/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmHibernationVolumesCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmHibernationVolumesCommand.java new file mode 100644 index 0000000..a2f5bea --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveVmHibernationVolumesCommand.java @@ -0,0 +1,100 @@ +package org.ovirt.engine.core.bll; + +import java.util.Collections; +import java.util.List; + +import org.ovirt.engine.core.bll.utils.PermissionSubject; +import org.ovirt.engine.core.common.RemoveVmHibernationVolumesParameters; +import org.ovirt.engine.core.common.VdcObjectType; +import org.ovirt.engine.core.common.asynctasks.AsyncTaskType; +import org.ovirt.engine.core.common.businessentities.Disk; +import org.ovirt.engine.core.common.vdscommands.DeleteImageGroupVDSCommandParameters; +import org.ovirt.engine.core.common.vdscommands.VDSCommandType; +import org.ovirt.engine.core.common.vdscommands.VDSReturnValue; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.utils.GuidUtils; +import org.ovirt.engine.core.utils.linq.LinqUtils; +import org.ovirt.engine.core.utils.linq.Predicate; + +@NonTransactiveCommandAttribute +public class RemoveVmHibernationVolumesCommand<T extends RemoveVmHibernationVolumesParameters> extends CommandBase<T> { + + public static final String DELETE_PRIMARY_IMAGE_TASK_KEY = "DELETE_PRIMARY_IMAGE_TASK_KEY"; + public static final String DELETE_SECONDARY_IMAGES_TASK_KEY = "DELETE_SECONDARY_IMAGES_TASK_KEY"; + + public RemoveVmHibernationVolumesCommand(T parameters) { + super(parameters); + setVmId(parameters.getVmId()); + } + + protected RemoveVmHibernationVolumesCommand(Guid commandId) { + super(commandId); + } + + @Override + protected void executeCommand() { + setSucceeded(removeMemoryVolumes(getVm().getHibernationVolHandle())); + } + + @Override + protected AsyncTaskType getTaskType() { + return AsyncTaskType.deleteImage; + } + + protected boolean removeMemoryVolumes(String memVols) { + // this is temp code until it will be implemented in SPM + List<Guid> guids = GuidUtils.getGuidListFromString(memVols); + + if (guids.size() == 6) { + // get all vm disks in order to check post zero - if one of the + // disks is marked with wipe_after_delete + boolean postZero = + LinqUtils.filter(getDbFacade().getDiskDao().getAllForVm(getVm().getId()), + new Predicate<Disk>() { + @Override + public boolean eval(Disk disk) { + return disk.isWipeAfterDelete(); + } + }).size() > 0; + + Guid taskId1 = persistAsyncTaskPlaceHolder(getParameters().getParentCommand(), DELETE_PRIMARY_IMAGE_TASK_KEY); + + // delete first image + // the next 'DeleteImageGroup' command should also take care of the image removal: + VDSReturnValue vdsRetValue = runVdsCommand( + VDSCommandType.DeleteImageGroup, + new DeleteImageGroupVDSCommandParameters(guids.get(1), + guids.get(0), guids.get(2), postZero, false)); + + if (!vdsRetValue.getSucceeded()) { + return false; + } + + Guid guid1 = + createTask(taskId1, vdsRetValue.getCreationInfo(), getParameters().getParentCommand(), VdcObjectType.Storage, guids.get(0)); + getTaskIdList().add(guid1); + + Guid taskId2 = persistAsyncTaskPlaceHolder(getParameters().getParentCommand(), DELETE_SECONDARY_IMAGES_TASK_KEY); + // delete second image + // the next 'DeleteImageGroup' command should also take care of the image removal: + vdsRetValue = runVdsCommand( + VDSCommandType.DeleteImageGroup, + new DeleteImageGroupVDSCommandParameters(guids.get(1), + guids.get(0), guids.get(4), postZero, false)); + + if (!vdsRetValue.getSucceeded()) { + return false; + } + + Guid guid2 = createTask(taskId2, vdsRetValue.getCreationInfo(), getParameters().getParentCommand()); + getTaskIdList().add(guid2); + } + + return true; + } + + @Override + public List<PermissionSubject> getPermissionCheckSubjects() { + return Collections.emptyList(); + } +} diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java index 45fcb80..8ea327b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommandBase.java @@ -18,6 +18,9 @@ import org.ovirt.engine.core.bll.scheduling.RunVmDelayer; import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator; import org.ovirt.engine.core.bll.storage.StorageHelperDirector; +import org.ovirt.engine.core.common.RemoveVmHibernationVolumesParameters; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.action.VdcReturnValueBase; import org.ovirt.engine.core.common.action.VmOperationParameterBase; import org.ovirt.engine.core.common.businessentities.IVdsAsyncCommand; import org.ovirt.engine.core.common.businessentities.LUNs; @@ -161,8 +164,10 @@ if (getVm().getLastVdsRunOn() == null || !getVm().getLastVdsRunOn().equals(getCurrentVdsId())) { getVm().setLastVdsRunOn(getCurrentVdsId()); } + if (StringUtils.isNotEmpty(getVm().getHibernationVolHandle())) { - removeMemoryVolumes(getVm().getHibernationVolHandle(), getActionType(), true); + removeVmHibernationVolumes(); + // In order to prevent a race where VdsUpdateRuntimeInfo saves the Vm Dynamic as UP prior to execution of // this method (which is a part of the cached VM command, // so the state this method is aware to is RESTORING, in case of RunVmCommand after the VM got suspended. @@ -177,6 +182,22 @@ } } + private void removeVmHibernationVolumes() { + RemoveVmHibernationVolumesParameters removeVmHibernationVolumesParameters = new RemoveVmHibernationVolumesParameters(getVmId()); + removeVmHibernationVolumesParameters.setParentCommand(getActionType()); + removeVmHibernationVolumesParameters.setEntityInfo(getParameters().getEntityInfo()); + removeVmHibernationVolumesParameters.setParentParameters(getParameters()); + + VdcReturnValueBase vdcRetValue = getBackend().runInternalAction( + VdcActionType.RemoveVmHibernationVolumes, + removeVmHibernationVolumesParameters, + ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); + + for (Guid taskId : vdcRetValue.getInternalVdsmTaskIdList()) { + AsyncTaskManager.getInstance().StartPollingTask(taskId); + } + } + /** * notify other hosts on a failed attempt to run a Vm in a non blocking matter * to avoid deadlock where other host's VdsManagers lock is taken and is awaiting the current vds lock. diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java index fa90ef5..843034d 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java @@ -4,13 +4,17 @@ import java.util.List; import org.apache.commons.lang.StringUtils; +import org.ovirt.engine.core.bll.job.ExecutionHandler; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; import org.ovirt.engine.core.bll.quota.QuotaVdsDependent; import org.ovirt.engine.core.bll.quota.QuotaVdsGroupConsumptionParameter; import org.ovirt.engine.core.bll.utils.PermissionSubject; +import org.ovirt.engine.core.common.RemoveVmHibernationVolumesParameters; import org.ovirt.engine.core.common.VdcObjectType; +import org.ovirt.engine.core.common.action.VdcActionType; +import org.ovirt.engine.core.common.action.VdcReturnValueBase; import org.ovirt.engine.core.common.action.VmOperationParameterBase; import org.ovirt.engine.core.common.asynctasks.EntityInfo; import org.ovirt.engine.core.common.businessentities.DiskImage; @@ -107,8 +111,8 @@ if (getVm().getStatus() != VMStatus.ImageLocked) { // Set the VM to image locked to decrease race condition. updateVmStatus(VMStatus.ImageLocked); - if (StringUtils.isNotEmpty(getVm().getHibernationVolHandle()) - && removeMemoryVolumes(getVm().getHibernationVolHandle(), getActionType(), false)) { + + if (removeVmHibernationVolumes()) { returnVal = true; } else { updateVmStatus(vmStatus); @@ -117,6 +121,28 @@ return returnVal; } + private boolean removeVmHibernationVolumes() { + if (StringUtils.isEmpty(getVm().getHibernationVolHandle())) { + return false; + } + + RemoveVmHibernationVolumesParameters parameters = new RemoveVmHibernationVolumesParameters(getVmId()); + parameters.setParentCommand(getActionType()); + parameters.setEntityInfo(getParameters().getEntityInfo()); + parameters.setParentParameters(getParameters()); + + VdcReturnValueBase vdcRetValue = getBackend().runInternalAction( + VdcActionType.RemoveVmHibernationVolumes, + parameters, + ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); + + if (vdcRetValue.getSucceeded()) { + getReturnValue().getVdsmTaskIdList().addAll(vdcRetValue.getInternalVdsmTaskIdList()); + } + + return vdcRetValue.getSucceeded(); + } + private void updateVmStatus(VMStatus newStatus) { TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/RemoveVmHibernationVolumesParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/RemoveVmHibernationVolumesParameters.java new file mode 100644 index 0000000..420e3bf --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/RemoveVmHibernationVolumesParameters.java @@ -0,0 +1,24 @@ +package org.ovirt.engine.core.common; + +import org.ovirt.engine.core.common.action.VdcActionParametersBase; +import org.ovirt.engine.core.compat.Guid; + + +public class RemoveVmHibernationVolumesParameters extends VdcActionParametersBase { + private Guid vmId = Guid.Empty; + + public RemoveVmHibernationVolumesParameters(Guid vmId) { + this.vmId = vmId; + } + + public RemoveVmHibernationVolumesParameters() { + } + + public void setVmId(Guid vmId) { + this.vmId = vmId; + } + + public Guid getVmId() { + return vmId; + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java index 6604f57..7d224e8 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java @@ -114,6 +114,7 @@ RemoveDisk(230, QuotaDependency.STORAGE), MoveImageGroup(231, QuotaDependency.STORAGE), GetDiskAlignment(232, QuotaDependency.NONE), + RemoveVmHibernationVolumes(233, QuotaDependency.NONE), // VmPoolCommands AddVmPool(301, QuotaDependency.NONE), AddVmPoolWithVms(304, ActionGroup.CREATE_VM_POOL, QuotaDependency.BOTH), -- To view, visit http://gerrit.ovirt.org/17692 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I425060c820e03f5818600fa119a70199d1a67840 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