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

Use shared lock on disks for dependent VMs #178

Merged
merged 2 commits into from
Jun 24, 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 @@ -299,14 +299,10 @@ protected void tearDownImage(Guid vdsId, Guid backupId) {
boolean tearDownFailed = false;

if (getTransferBackend() == ImageTransferBackend.FILE) {
if (!Guid.Empty.equals(image.getImageTemplateId())) {
LockInfo lockInfo =
lockManager.getLockInfo(getImage().getImageTemplateId() + LockingGroup.TEMPLATE.toString());
if (isTemplateBeingUsed(image)) {
log.info("Transfer '{}': The template image is being used, skipping teardown", getCommandId());

if (lockInfo != null) {
log.info("The template image is used for image transfer '{}', skipping teardown", getCommandId());
return;
}
return;
}

VDSReturnValue teardownImageVdsRetVal = runVdsCommand(VDSCommandType.TeardownImage,
Expand All @@ -326,6 +322,18 @@ protected void tearDownImage(Guid vdsId, Guid backupId) {
}
}

private boolean isTemplateBeingUsed(DiskImage image) {
if (!Guid.Empty.equals(image.getImageTemplateId())) {
LockInfo lockInfo =
lockManager.getLockInfo(getDiskImage().getImageTemplateId() + LockingGroup.TEMPLATE.toString());
if (lockInfo != null) {
return true;
}
}

return false;
}

private boolean stopNbdServer(Guid vdsId) {
NbdServerVDSParameters nbdServerVDSParameters = new NbdServerVDSParameters(vdsId);
nbdServerVDSParameters.setServerId(getCommandId());
Expand Down Expand Up @@ -436,12 +444,18 @@ protected Map<String, Pair<String, String>> getSharedLocks() {
// StartVmBackup should handle locks
return locks;
}

if (!Guid.isNullOrEmpty(getParameters().getImageId()) && getDiskImage() != null) {
List<VM> vms = vmDao.getVmsListForDisk(getDiskImage().getId(), true);
vms.forEach(vm -> locks.put(vm.getId().toString(),
LockMessagesMatchUtil.makeLockingPair(LockingGroup.VM, getDiskIsBeingTransferredLockMessage())));
}

if (getDiskImage() != null && getParameters().getTransferType() == TransferType.Download) {
locks.put(getDiskImage().getId().toString(),
LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK, EngineMessage.ACTION_TYPE_FAILED_DISK_IS_LOCKED));
}

return locks;
}

Expand All @@ -458,7 +472,8 @@ protected Map<String, Pair<String, String>> getExclusiveLocks() {
// StartVmBackup should handle locks
return locks;
}
if (getDiskImage() != null) {

if (getDiskImage() != null && getParameters().getTransferType() == TransferType.Upload) {
locks.put(getDiskImage().getId().toString(),
LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK, getDiskIsBeingTransferredLockMessage()));
}
Expand Down