Arik Hadas has uploaded a new change for review. Change subject: core: lock active snapshot during undo preview process ......................................................................
core: lock active snapshot during undo preview process This patch prevents scenarios in which commands that are dependent on the VM's snapshot are executing in parallel to undo preview command which is changing the active snapshot of the VM. The active snapshot of the VM is being locked when the async part of the RestoreAllSnapshots command begins, and will be changed to OK when the command ends. Change-Id: Id7a2064d5130a6fa49360a8ad8e9a1004fc44da2 Bug-Url: https://bugzilla.redhat.com/868648 Signed-off-by: Arik Hadas <aha...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java 2 files changed, 36 insertions(+), 3 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/45/10845/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java index 2a9336d..11bede6 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RestoreAllSnapshotsCommand.java @@ -7,8 +7,8 @@ import org.ovirt.engine.core.bll.job.ExecutionHandler; import org.ovirt.engine.core.bll.quota.QuotaConsumptionParameter; -import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; import org.ovirt.engine.core.bll.quota.QuotaStorageConsumptionParameter; +import org.ovirt.engine.core.bll.quota.QuotaStorageDependent; import org.ovirt.engine.core.bll.snapshots.SnapshotsManager; import org.ovirt.engine.core.bll.utils.PermissionSubject; import org.ovirt.engine.core.common.AuditLogType; @@ -225,7 +225,8 @@ targetSnapshot.getId(), getCompensationContext()); getSnapshotDao().remove(targetSnapshot.getId()); - snapshotsManager.addActiveSnapshot(targetSnapshot.getId(), getVm(), getCompensationContext()); + // add active snapshot with status locked, so that other commands that depend on the VM's snapshots won't run in parallel + snapshotsManager.addActiveSnapshot(targetSnapshot.getId(), getVm(), SnapshotStatus.LOCKED, getCompensationContext()); } /** @@ -369,4 +370,12 @@ return list; } + + @Override + protected void endVmCommand() { + super.endVmCommand(); + + // if we got here, the target snapshot exists for sure + getSnapshotDao().updateStatus(getParameters().getDstSnapshotId(), SnapshotStatus.OK); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java index adb3b05..a43eb98 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/snapshots/SnapshotsManager.java @@ -52,6 +52,7 @@ * Save an active snapshot for the VM, without saving the configuration.<br> * The snapshot is created in status {@link SnapshotStatus#OK} by default. * + * @see #addActiveSnapshot(Guid, VM, SnapshotStatus, CompensationContext) * @param snapshotId * The ID for the snapshot. * @param vm @@ -62,9 +63,32 @@ public Snapshot addActiveSnapshot(Guid snapshotId, VM vm, final CompensationContext compensationContext) { + return addActiveSnapshot(snapshotId, + vm, + SnapshotStatus.OK, + compensationContext); + } + + /** + * Save an active snapshot for the VM, without saving the configuration.<br> + * The snapshot is created with the given status {@link SnapshotStatus}. + * + * @param snapshotId + * The ID for the snapshot. + * @param vm + * The VM to save the snapshot for. + * @param snapshotStatus + * The initial status of the snapshot + * @param compensationContext + * Context for saving compensation details. + */ + public Snapshot addActiveSnapshot(Guid snapshotId, + VM vm, + SnapshotStatus snapshotStatus, + final CompensationContext compensationContext) { return addSnapshot(snapshotId, "Active VM", - SnapshotStatus.OK, + snapshotStatus, SnapshotType.ACTIVE, vm, false, -- To view, visit http://gerrit.ovirt.org/10845 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id7a2064d5130a6fa49360a8ad8e9a1004fc44da2 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