Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSM: fix locking on restart #670

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
import org.ovirt.engine.core.dao.StorageDomainDao;
import org.ovirt.engine.core.dao.StorageDomainStaticDao;
import org.ovirt.engine.core.dao.VmDao;
import org.ovirt.engine.core.utils.lock.EngineLock;
import org.ovirt.engine.core.utils.transaction.TransactionSupport;
import org.ovirt.engine.core.vdsbroker.ResourceManager;
import org.ovirt.engine.core.vdsbroker.builder.vminfo.VmInfoBuildUtils;
Expand Down Expand Up @@ -292,7 +293,8 @@ 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.
if (!lockManager.acquireLock(getLock()).isAcquired()) {
EngineLock removeSnapshotLock = createEngineLockForSnapshotRemove();
if (!lockManager.acquireLock(removeSnapshotLock).isAcquired()) {
ahadas marked this conversation as resolved.
Show resolved Hide resolved
log.info("Failed to acquire VM lock, will retry on the next polling cycle");
return true;
}
Expand Down Expand Up @@ -362,6 +364,17 @@ private void unlockDisk() {
imageDao.updateStatusOfImagesByImageGroupId(getParameters().getImageGroupID(), ImageStatus.OK);
}

private void releaseSnapshotLock() {
EngineLock removeSnapshotLock = createEngineLockForSnapshotRemove();
lockManager.releaseLock(removeSnapshotLock);
}

private EngineLock createEngineLockForSnapshotRemove() {
return new EngineLock(
getExclusiveLocksForSnapshotRemove(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is right, we don't need the disk lock, what we actually need is an exclusive lock on the VM and a shared lock is taken.

(To be clear, this was an existing problem introduced in mkemel@b5d5499)

getSharedLocksForSnapshotRemove());
}

private boolean isConsiderSuccessful() {
return getParameters().getLiveDiskMigrateStage() == LiveDiskMigrateStage.AUTO_GENERATED_SNAPSHOT_REMOVE_END;
}
Expand All @@ -371,6 +384,7 @@ protected void endSuccessfully() {
super.endSuccessfully();
updateImagesInfo();
unlockDisk();
releaseSnapshotLock();
setSucceeded(true);
}

Expand Down Expand Up @@ -740,13 +754,21 @@ public AuditLogType getAuditLogTypeValue() {

@Override
protected Map<String, Pair<String, String>> getExclusiveLocks() {
return Collections.emptyMap();
}

@Override
protected Map<String, Pair<String, String>> getSharedLocks() {
return Collections.emptyMap();
}

private Map<String, Pair<String, String>> getExclusiveLocksForSnapshotRemove() {
return Collections.singletonMap(getParameters().getImageGroupID().toString(),
LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK,
getDiskIsBeingMigratedMessage(getDiskImageByDiskId(getParameters().getImageGroupID()))));
}

@Override
protected Map<String, Pair<String, String>> getSharedLocks() {
private Map<String, Pair<String, String>> getSharedLocksForSnapshotRemove() {
return Collections.singletonMap(getVmId().toString(),
LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM, EngineMessage.ACTION_TYPE_FAILED_OBJECT_LOCKED));
}
Expand Down