Skip to content

Commit

Permalink
core: only use a shared lock for thin template overlays
Browse files Browse the repository at this point in the history
When downloading a disk that is an overlay of a template, take only a
shared lock on the disk and skip the locked disk validation, this would
allow downloading disks of thin VMs without failing on the disk being
locked.

Bug-Url: Bug-Url: https://bugzilla.redhat.com/1879391
Signed-off-by: Benny Zlotnik <bzlotnik@redhat.com>
  • Loading branch information
bennyz committed Jun 19, 2022
1 parent a801422 commit 945fe00
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,28 @@ protected Map<String, Pair<String, String>> getSharedLocks() {
// StartVmBackup should handle locks
return locks;
}
if (!Guid.isNullOrEmpty(getParameters().getImageId()) && getDiskImage() != null) {

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

// Lock with a shared lock since we skip locking exclusively disks of thin VMs
if (isThinTemplate(getDiskImage())) {
locks.put(getDiskImage().getId().toString(),
LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK, EngineMessage.ACTION_TYPE_FAILED_DISK_IS_LOCKED));
}

return locks;
}

private boolean isThinTemplate(DiskImage diskImage) {
return !Guid.isNullOrEmpty(diskImage.getImageTemplateId());
}

private String getDiskIsBeingTransferredLockMessage() {
return new LockMessage(EngineMessage.ACTION_TYPE_FAILED_DISK_IS_BEING_TRANSFERRED)
.withOptional("DiskName", getDiskImage().getDiskAlias() != null ? getDiskImage().getDiskAlias() : "")
Expand All @@ -466,7 +479,9 @@ protected Map<String, Pair<String, String>> getExclusiveLocks() {
// StartVmBackup should handle locks
return locks;
}
if (getDiskImage() != null) {

// If the disk is a thin template overlay we only lock with a shared lock
if (getDiskImage() != null && !isThinTemplate(getDiskImage())) {
locks.put(getDiskImage().getId().toString(),
LockMessagesMatchUtil.makeLockingPair(LockingGroup.DISK, getDiskIsBeingTransferredLockMessage()));
}
Expand Down

0 comments on commit 945fe00

Please sign in to comment.