diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/lsm/LiveMigrateDiskCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/lsm/LiveMigrateDiskCommand.java index 38e714e4d24..f846c25136d 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/lsm/LiveMigrateDiskCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/lsm/LiveMigrateDiskCommand.java @@ -295,7 +295,7 @@ public boolean performNextOperation(int completedChildCount) { // at the end of CreateSnapshotForVm command called from the executeCommand() method. // Here the lock is acquired again and will be released when this command (LiveMigrateDisk) // finishes. - EngineLock removeSnapshotLock = createEngineLockForSnapshotRemove(); + EngineLock removeSnapshotLock = getEngineLockForSnapshotRemove(); if (!lockManager.acquireLock(removeSnapshotLock).isAcquired()) { log.info("Failed to acquire VM lock, will retry on the next polling cycle"); return true; @@ -378,6 +378,17 @@ private EngineLock createEngineLockForSnapshotRemove() { getSharedLocksForSnapshotRemove()); } + private EngineLock getEngineLockForSnapshotRemove() { + EngineLock lock = getLock(); + if (lock != null && !lock.getExclusiveLocks().isEmpty()) { + // In the generic scenario, use the lock created by the MigrateDiskCommand + return lock; + } + // This happens when the engine was restarted during active live disk migration. Use special lock to clean up + // temporary VM snapshot created by the migration + return createEngineLockForSnapshotRemove(); + } + private boolean isConsiderSuccessful() { return getParameters().getLiveDiskMigrateStage() == LiveDiskMigrateStage.AUTO_GENERATED_SNAPSHOT_REMOVE_END; }