Arik Hadas has uploaded a new change for review. Change subject: core: [WIP] remove memory image on remove snapshot ......................................................................
core: [WIP] remove memory image on remove snapshot If the snapshot contains memory, remove the memory state image when removing the snapshot. Change-Id: I88a707457b3b1565a887e141d18d9d08a2dbcc69 Signed-off-by: Arik Hadas <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java 1 file changed, 88 insertions(+), 25 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/87/14687/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java index 5ffdd25..0ea475d 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RemoveSnapshotCommand.java @@ -23,6 +23,7 @@ import org.ovirt.engine.core.common.action.RemoveSnapshotParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.action.VdcReturnValueBase; +import org.ovirt.engine.core.common.businessentities.Disk; import org.ovirt.engine.core.common.businessentities.DiskImage; import org.ovirt.engine.core.common.businessentities.Snapshot; import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus; @@ -32,10 +33,15 @@ import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.locks.LockingGroup; import org.ovirt.engine.core.common.utils.Pair; +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.dal.VdcBllMessages; import org.ovirt.engine.core.dao.SnapshotDao; import org.ovirt.engine.core.utils.collections.MultiValueMapUtils; +import org.ovirt.engine.core.utils.linq.LinqUtils; +import org.ovirt.engine.core.utils.linq.Predicate; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @@ -88,47 +94,80 @@ throw new VdcBLLException(VdcBllErrors.IRS_IMAGE_STATUS_ILLEGAL); } - // If the VM hasn't got any images - simply remove the snapshot. + final Snapshot snapshot = getSnapshotDao().get(getParameters().getSnapshotId()); + + boolean snapshotHasImages = hasImages(); + boolean snapshotHasMemory = snapshot.getMemoryVolume().isEmpty(); + + // If the VM hasn't got any images and memory - simply remove the snapshot. // No need for locking, VDSM tasks, and all that jazz. - if (!hasImages()) { + if (!snapshotHasImages && !snapshotHasMemory) { getSnapshotDao().remove(getParameters().getSnapshotId()); setSucceeded(true); return; } - TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { - - @Override - public Void runInTransaction() { - Snapshot snapshot = getSnapshotDao().get(getParameters().getSnapshotId()); - getCompensationContext().snapshotEntityStatus(snapshot, snapshot.getStatus()); - getSnapshotDao().updateStatus( - getParameters().getSnapshotId(), SnapshotStatus.LOCKED); - getCompensationContext().stateChanged(); - return null; - } - }); + lockSnapshot(snapshot); freeLock(); getParameters().setEntityId(getVmId()); + if (snapshotHasImages) { + removeImages(); + } + + if (snapshotHasMemory) { + removeMemory(snapshot); + } + + setSucceeded(true); + } + + private void removeMemory(final Snapshot snapshot) { + String[] strings = snapshot.getMemoryVolume().split(","); + Guid[] guids = new Guid[strings.length]; + for (int i=0; i<strings.length; ++i) { + guids[i]= new Guid(strings[i]); + } + // 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(getDiskDao().getAllForVm(getVm().getId()), + new Predicate<Disk>() { + @Override + public boolean eval(Disk disk) { + return disk.isWipeAfterDelete(); + } + }).size() > 0; + + // delete first image + // the next 'DeleteImageGroup' command should also take care of the + // image removal: + VDSReturnValue vdsRetValue1 = runVdsCommand( + VDSCommandType.DeleteImageGroup, + new DeleteImageGroupVDSCommandParameters(guids[1], guids[0], guids[2], + postZero, false, getVm().getVdsGroupCompatibilityVersion().toString())); + + if (!vdsRetValue1.getSucceeded()) { + // TODO + } + else { + Guid guid1 = + createTask(vdsRetValue1.getCreationInfo(), VdcActionType.RemoveImage, VdcObjectType.Storage, guids[0]); + getReturnValue().getTaskIdList().add(guid1); + } + } + + private void removeImages() { for (final DiskImage source : getSourceImages()) { - // The following line is ok because we have tested in the - // candoaction that the vm + // The following line is ok because we have tested in the candoaction that the vm // is not a template and the vm is not in preview mode and that // this is not the active snapshot. DiskImage dest = getDiskImageDao().getAllSnapshotsForParent(source.getImageId()).get(0); - ImagesContainterParametersBase tempVar = new ImagesContainterParametersBase(source.getImageId(), - getVmId()); - tempVar.setDestinationImageId(dest.getImageId()); - tempVar.setEntityId(getParameters().getEntityId()); - tempVar.setParentParameters(getParameters()); - tempVar.setParentCommand(getActionType()); - ImagesContainterParametersBase p = tempVar; VdcReturnValueBase vdcReturnValue = getBackend().runInternalAction( VdcActionType.RemoveSnapshotSingleDisk, - p, + buildRemoveSnapshotSingleDiskParameters(source, dest), ExecutionHandler.createDefaultContexForTasks(getExecutionContext())); if (vdcReturnValue != null && vdcReturnValue.getInternalTaskIdList() != null) { @@ -140,7 +179,31 @@ quotasToRemoveFromCache.add(dest.getQuotaId()); QuotaManager.getInstance().removeQuotaFromCache(getStoragePoolId().getValue(), quotasToRemoveFromCache); } - setSucceeded(true); + } + + private void lockSnapshot(final Snapshot snapshot) { + TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { + + @Override + public Void runInTransaction() { + getCompensationContext().snapshotEntityStatus(snapshot, snapshot.getStatus()); + getSnapshotDao().updateStatus( + getParameters().getSnapshotId(), SnapshotStatus.LOCKED); + getCompensationContext().stateChanged(); + return null; + } + }); + } + + private ImagesContainterParametersBase buildRemoveSnapshotSingleDiskParameters(final DiskImage source, + DiskImage dest) { + ImagesContainterParametersBase parameters = + new ImagesContainterParametersBase(source.getImageId(), getVmId()); + parameters.setDestinationImageId(dest.getImageId()); + parameters.setEntityId(getParameters().getEntityId()); + parameters.setParentParameters(getParameters()); + parameters.setParentCommand(getActionType()); + return parameters; } @Override -- To view, visit http://gerrit.ovirt.org/14687 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I88a707457b3b1565a887e141d18d9d08a2dbcc69 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
