Skip to content

Commit

Permalink
core: set vms that preview memory snapshots to suspended
Browse files Browse the repository at this point in the history
If the VMs are set to restore memory, we would now set them to
Suspended status so they'll be treated as VMs that were hibernated
(e.g., create next-run snapshots when their configuration changes)

Bug-Url: https://bugzilla.redhat.com/1257644
Signed-off-by: Arik Hadas <ahadas@redhat.com>
  • Loading branch information
ahadas committed Jul 5, 2022
1 parent 8a877b1 commit 556d2c7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.ovirt.engine.core.bll.memory.MemoryDisks;
import org.ovirt.engine.core.bll.memory.MemoryStorageHandler;
import org.ovirt.engine.core.bll.memory.MemoryUtils;
import org.ovirt.engine.core.bll.snapshots.SnapshotsValidator;
import org.ovirt.engine.core.bll.storage.disk.image.DisksFilter;
import org.ovirt.engine.core.bll.tasks.CommandCoordinatorUtil;
import org.ovirt.engine.core.bll.validator.VmValidator;
Expand Down Expand Up @@ -60,6 +61,8 @@ public class HibernateVmCommand<T extends VmOperationParameterBase> extends VmOp
private SnapshotDao snapshotDao;
@Inject
private CommandCoordinatorUtil commandCoordinatorUtil;
@Inject
protected SnapshotsValidator snapshotsValidator;

/**
* Constructor for command creation when compensation is applied on startup
Expand Down Expand Up @@ -231,6 +234,12 @@ protected boolean validate() {
return false;
}

// we block hibernating a vm in preview mode because there is a bug that
// would result in keeping the hibernation metadata volume
if (!validate(snapshotsValidator.vmNotInPreview(getVm().getId()))) {
return false;
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
import org.ovirt.engine.core.common.businessentities.SnapshotActionEnum;
import org.ovirt.engine.core.common.businessentities.VM;
import org.ovirt.engine.core.common.businessentities.VMStatus;
import org.ovirt.engine.core.common.businessentities.VmCheckpoint;
import org.ovirt.engine.core.common.businessentities.storage.CinderDisk;
import org.ovirt.engine.core.common.businessentities.storage.DiskImage;
Expand Down Expand Up @@ -142,13 +143,14 @@ public RestoreAllSnapshotsCommand(T parameters, CommandContext commandContext) {

@Override
protected LockProperties applyLockProperties(LockProperties lockProperties) {
return lockProperties.withScope(Scope.Execution);
return lockProperties.withScope(Scope.Command);
}

@Override
protected void executeVmCommand() {

if (!getImagesList().isEmpty()) {
// we can probably get rid of the following check getVm().getStatus() != VMStatus.Suspended
// and rely on memory locks instead of db locks but that requires more testing
if (!getImagesList().isEmpty() && getVm().getStatus() != VMStatus.Suspended) {
lockVmWithCompensationIfNeeded();
if (!isInternalExecution()) {
freeLock();
Expand Down Expand Up @@ -843,7 +845,7 @@ protected boolean validate() {
MultipleStorageDomainsValidator storageValidator = createStorageDomainValidator();
if (!validate(storageValidator.allDomainsExistAndActive()) ||
!performImagesChecks() ||
!validate(vmValidator.vmDown()) ||
!validate(vmValidator.validateVmStatusUsingMatrix(getActionType())) ||
!validate(storageValidator.isSupportedByManagedBlockStorageDomains(getActionType())) ||
// if the user choose to commit a snapshot the vm can't have disk snapshots attached to other vms.
getSnapshot().getType() == SnapshotType.REGULAR && !validate(vmValidator.vmNotHavingDeviceSnapshotsAttachedToOtherVms(false))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotStatus;
import org.ovirt.engine.core.common.businessentities.Snapshot.SnapshotType;
import org.ovirt.engine.core.common.businessentities.VM;
import org.ovirt.engine.core.common.businessentities.VMStatus;
import org.ovirt.engine.core.common.businessentities.VmDevice;
import org.ovirt.engine.core.common.businessentities.VmDeviceGeneralType;
import org.ovirt.engine.core.common.businessentities.VmDeviceId;
import org.ovirt.engine.core.common.businessentities.VmDynamic;
import org.ovirt.engine.core.common.businessentities.VmStatic;
import org.ovirt.engine.core.common.businessentities.VmTemplate;
import org.ovirt.engine.core.common.businessentities.aaa.DbUser;
Expand Down Expand Up @@ -455,7 +457,9 @@ public void attemptToRestoreVmConfigurationFromSnapshot(VM vm,
}

vm.setAppList(snapshot.getAppList());
vmDynamicDao.update(vm.getDynamicData());
VmDynamic vmDynamic = vm.getDynamicData();
vmDynamic.setStatus(withMemory ? VMStatus.Suspended : VMStatus.Down);
vmDynamicDao.update(vmDynamic);

List<DiskImage> imagesToExclude = diskImageDao.getAttachedDiskSnapshotsToVm(vm.getId(), Boolean.TRUE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public final class ActionUtils {
EnumSet.of(ActionType.HibernateVm, ActionType.RunVm,
ActionType.RunVmOnce, ActionType.AddVmTemplate, ActionType.RemoveVm,
ActionType.ExportVm, ActionType.ImportVm, ActionType.ChangeDisk,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.MigrateVm, ActionType.CancelMigrateVm,
ActionType.ExtendImageSize, ActionType.RebootVm, ActionType.ResetVm));
vmMatrix.put(
Expand All @@ -173,23 +173,23 @@ public final class ActionUtils {
ActionType.AddVmTemplate, ActionType.RemoveVm, ActionType.MigrateVm,
ActionType.ExportVm, ActionType.ImportVm,
ActionType.ChangeDisk, ActionType.AddVmInterface,
ActionType.UpdateVmInterface,
ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm,
ActionType.ExtendImageSize, ActionType.RebootVm, ActionType.ResetVm));
vmMatrix.put(
VMStatus.PoweringUp,
EnumSet.of(ActionType.HibernateVm, ActionType.RunVm,
ActionType.RunVmOnce, ActionType.AddVmTemplate, ActionType.RemoveVm,
ActionType.ExportVm, ActionType.ImportVm, ActionType.ChangeDisk,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm,
ActionType.ExtendImageSize));
vmMatrix.put(
VMStatus.RebootInProgress,
EnumSet.of(ActionType.HibernateVm, ActionType.RunVm,
ActionType.RunVmOnce, ActionType.AddVmTemplate, ActionType.RemoveVm,
ActionType.ExportVm, ActionType.ImportVm, ActionType.ChangeDisk,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm,
ActionType.ExtendImageSize, ActionType.RebootVm));
vmMatrix.put(
Expand All @@ -198,7 +198,7 @@ public final class ActionUtils {
ActionType.RunVmOnce, ActionType.AddVmTemplate, ActionType.RemoveVm,
ActionType.HibernateVm, ActionType.MigrateVm, ActionType.ExportVm,
ActionType.ImportVm, ActionType.ChangeDisk,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CreateSnapshotForVm,
ActionType.ExtendImageSize, ActionType.RebootVm, ActionType.ResetVm));
vmMatrix.put(
Expand All @@ -214,7 +214,7 @@ public final class ActionUtils {
EnumSet.of(ActionType.RemoveVm, ActionType.HibernateVm,
ActionType.AddVmTemplate, ActionType.RunVmOnce, ActionType.ExportVm,
ActionType.ImportVm, ActionType.ExtendImageSize,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm,
ActionType.RebootVm, ActionType.ResetVm));
vmMatrix.put(
Expand All @@ -224,7 +224,7 @@ public final class ActionUtils {
ActionType.HibernateVm, ActionType.MigrateVm, ActionType.RemoveVm,
ActionType.AddVmTemplate, ActionType.ExportVm,
ActionType.ImportVm, ActionType.ChangeDisk,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm,
ActionType.ExtendImageSize, ActionType.RebootVm, ActionType.ResetVm));
vmMatrix.put(
Expand All @@ -234,7 +234,7 @@ public final class ActionUtils {
ActionType.HibernateVm, ActionType.MigrateVm, ActionType.RemoveVm,
ActionType.AddVmTemplate, ActionType.ExportVm,
ActionType.ImportVm, ActionType.ChangeDisk,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm, ActionType.ExtendImageSize,
ActionType.RebootVm, ActionType.ResetVm));

Expand All @@ -257,6 +257,7 @@ public final class ActionUtils {
ActionType.ChangeDisk,
ActionType.AddVmInterface,
ActionType.UpdateVmInterface,
ActionType.RestoreAllSnapshots,
ActionType.CreateSnapshotForVm,
ActionType.RemoveVmInterface,
ActionType.CancelMigrateVm,
Expand All @@ -271,7 +272,7 @@ public final class ActionUtils {
ActionType.HibernateVm, ActionType.MigrateVm, ActionType.RemoveVm,
ActionType.AddVmTemplate, ActionType.ExportVm,
ActionType.ImportVm, ActionType.ChangeDisk, ActionType.CreateSnapshotForVm,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm, ActionType.ExtendImageSize,
ActionType.RebootVm, ActionType.ResetVm));
vmMatrix.put(
Expand All @@ -280,7 +281,7 @@ public final class ActionUtils {
ActionType.RunVmOnce, ActionType.HibernateVm, ActionType.MigrateVm,
ActionType.RemoveVm, ActionType.AddVmTemplate, ActionType.ExportVm,
ActionType.ImportVm, ActionType.ChangeDisk, ActionType.CreateSnapshotForVm,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm, ActionType.ExtendImageSize,
ActionType.RebootVm, ActionType.ResetVm));

Expand All @@ -291,7 +292,7 @@ public final class ActionUtils {
ActionType.HibernateVm, ActionType.MigrateVm, ActionType.RemoveVm,
ActionType.AddVmTemplate, ActionType.ExportVm,
ActionType.ImportVm, ActionType.ChangeDisk, ActionType.CreateSnapshotForVm,
ActionType.AddVmInterface, ActionType.UpdateVmInterface,
ActionType.AddVmInterface, ActionType.UpdateVmInterface, ActionType.RestoreAllSnapshots,
ActionType.RemoveVmInterface, ActionType.CancelMigrateVm, ActionType.ExtendImageSize,
ActionType.RebootVm, ActionType.ResetVm));
vmMatrix.put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,7 @@ public void updateActionAvailability() {
List<VM> vmList = vm != null ? Collections.singletonList(vm) : Collections.emptyList();

boolean isVmDown = vm != null && vm.getStatus() == VMStatus.Down;
boolean isVmDownOrSuspended = vm != null && vm.getStatus() == VMStatus.Down || vm.getStatus() == VMStatus.Suspended;
boolean isVmImageLocked = vm != null && vm.getStatus() == VMStatus.ImageLocked;
boolean isVmQualifiedForSnapshotMerge = vm != null && vm.getStatus().isQualifiedForSnapshotMerge();
boolean isPreviewing = getItems().stream().anyMatch(s -> s.getStatus() == SnapshotStatus.IN_PREVIEW);
Expand All @@ -856,8 +857,8 @@ public void updateActionAvailability() {
getNewCommand().setIsExecutionAllowed(!isPreviewing && !isLocked && !isVmImageLocked && !isStateless && isManaged);
getPreviewCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && isVmDown && !isStateless);
getCustomPreviewCommand().setIsExecutionAllowed(getPreviewCommand().getIsExecutionAllowed());
getCommitCommand().setIsExecutionAllowed(isPreviewing && isVmDown && !isStateless);
getUndoCommand().setIsExecutionAllowed(isPreviewing && isVmDown && !isStateless);
getCommitCommand().setIsExecutionAllowed(isPreviewing && isVmDownOrSuspended && !isStateless);
getUndoCommand().setIsExecutionAllowed(isPreviewing && isVmDownOrSuspended && !isStateless);
getRemoveCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing && !isStateless
&& isVmQualifiedForSnapshotMerge);
getCloneVmCommand().setIsExecutionAllowed(isSelected && !isLocked && !isPreviewing
Expand Down

0 comments on commit 556d2c7

Please sign in to comment.