Tal Nisan has uploaded a new change for review. Change subject: core: Add lock to a disk in attach to VM command (#834888) ......................................................................
core: Add lock to a disk in attach to VM command (#834888) https://bugzilla.redhat.com/834888 Added lock to the disk entity when attaching a disk to a VM in case the disk is not sharable, also added a validation to the cando action in case when the disk is not sharable and already attached to another VM, for some reason this was not checked and the only thing blocking from attaching a non sharable disk to multiple VM was the UI Change-Id: Ib9e47fe370b230b4bd69f108954031cda3bba6a3 Signed-off-by: Tal Nisan <tni...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties M frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java M frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties M frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties 6 files changed, 21 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/37/7337/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java index bd97393..9383a5f 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AttachDiskToVmCommand.java @@ -1,7 +1,7 @@ package org.ovirt.engine.core.bll; import java.util.ArrayList; -import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -75,6 +75,10 @@ .getValue())) { retValue = false; addCanDoActionMessage(VdcBllMessages.ACTION_NOT_SUPPORTED_FOR_CLUSTER_POOL_LEVEL); + } + if (retValue && !disk.isShareable() && disk.getNumberOfVms() > 0) { + retValue = false; + addCanDoActionMessage(VdcBllMessages.ACTION_TYPE_FAILED_NOT_SHARABLE_DISK_ALREADY_ATTACHED); } if (retValue && isImageDisk && getStoragePoolIsoMapDao().get(new StoragePoolIsoMapId( ((DiskImage) disk).getstorage_ids().get(0), getVm().getstorage_pool_id())) == null) { @@ -158,10 +162,16 @@ @Override protected Map<String, String> getExclusiveLocks() { - if (disk.isBoot()) { - return Collections.singletonMap(getParameters().getVmId().toString(), LockingGroup.VM_DISK_BOOT.name()); + Map<String, String> locks = new HashMap<String, String>(); + if (!disk.isShareable()) { + locks.put(disk.getId().toString(), LockingGroup.DISK.name()); } - return null; + + if (disk.isBoot()) { + locks.put(getParameters().getVmId().toString(), LockingGroup.VM_DISK_BOOT.name()); + } + + return locks; } @Override diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java index f4735bd..fd72dbb 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/VdcBllMessages.java @@ -97,6 +97,7 @@ ACTION_TYPE_FAILED_EXCEEDED_MAX_IDE_SLOTS, ACTION_TYPE_FAILED_DISK_BOOT_IN_USE, ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED, + ACTION_TYPE_FAILED_NOT_SHARABLE_DISK_ALREADY_ATTACHED, ACTION_TYPE_FAILED_DISK_ALREADY_DETACHED, ACTION_TYPE_FAILED_ILLEGAL_DISK_OPERATION, ACTION_TYPE_FAILED_DISK_SPACE_LOW, diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties index b7f9a4a..146a033 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties @@ -262,6 +262,7 @@ ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED=Cannot ${action} ${type}. The disk is already attached to VM. ACTION_TYPE_FAILED_DISK_ALREADY_DETACHED=Cannot ${action} ${type}. The disk is already detached from VM. +ACTION_TYPE_FAILED_NOT_SHARABLE_DISK_ALREADY_ATTACHED=Cannot ${action} ${type}. The disk is not sharable and is already attached to a VM. ACTION_TYPE_FAILED_ILLEGAL_DISK_OPERATION=Cannot ${action} ${type}. Disk is Illegal. Illegal disks can only be deleted. ACTION_TYPE_FAILED_VM_MAX_RESOURCE_EXEEDED=Cannot ${action} ${type}. Maximum value for concurrently running VMs exceeded. ACTION_TYPE_FAILED_CPU_NOT_FOUND=Cannot ${action} ${type}. The chosen CPU is not supported. diff --git a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java index c5331a8..1359c17 100644 --- a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java +++ b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java @@ -718,6 +718,9 @@ @DefaultStringValue("Cannot ${action} ${type}. The disk is already detached from VM.") String ACTION_TYPE_FAILED_DISK_ALREADY_DETACHED(); + @DefaultStringValue("Cannot ${action} ${type}. The disk is not sharable and is already attached to a VM.") + String ACTION_TYPE_FAILED_NOT_SHARABLE_DISK_ALREADY_ATTACHED(); + @DefaultStringValue("Cannot ${action} ${type}. Maximum value for concurrently running VMs exceeded.") String ACTION_TYPE_FAILED_VM_MAX_RESOURCE_EXEEDED(); diff --git a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 7f71b58..9182f2d 100644 --- a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -261,6 +261,7 @@ ACTION_TYPE_FAILED_STOARGE_DOMAIN_IS_WRONG=Cannot ${action} ${type}. Provided wrong storage domain, which is not related to disk. ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED=Cannot ${action} ${type}. The disk is already attached to VM. ACTION_TYPE_FAILED_DISK_ALREADY_DETACHED=Cannot ${action} ${type}. The disk is already detached from VM. +ACTION_TYPE_FAILED_NOT_SHARABLE_DISK_ALREADY_ATTACHED=Cannot ${action} ${type}. The disk is not sharable and is already attached to a VM. ACTION_TYPE_FAILED_VM_MAX_RESOURCE_EXEEDED=Cannot ${action} ${type}. Maximum value for concurrently running VMs exceeded. ACTION_TYPE_FAILED_CPU_NOT_FOUND=Cannot ${action} ${type}. The chosen CPU is not supported. ACTION_TYPE_FAILED_EXCEEDED_MAX_PCI_SLOTS=Cannot ${action} ${type}. Maximum PCI devices exceeded. diff --git a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties index 3ce5492..164fdd4 100644 --- a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties +++ b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties @@ -257,6 +257,7 @@ ACTION_TYPE_FAILED_DISK_ALREADY_ATTACHED=Cannot ${action} ${type}. The disk is already attached to VM. ACTION_TYPE_FAILED_DISK_ALREADY_DETACHED=Cannot ${action} ${type}. The disk is already detached from VM. +ACTION_TYPE_FAILED_NOT_SHARABLE_DISK_ALREADY_ATTACHED=Cannot ${action} ${type}. The disk is not sharable and is already attached to a VM. ACTION_TYPE_FAILED_VM_MAX_RESOURCE_EXEEDED=Cannot ${action} ${type}. Maximum value for concurrently running VMs exceeded. ACTION_TYPE_FAILED_MISSED_STORAGES_FOR_SOME_DISKS=Cannot ${action} ${type}. Provided destination storage domains doesn't match for provided disks. ACTION_TYPE_FAILED_STOARGE_DOMAIN_IS_WRONG=Cannot ${action} ${type}. Provided wrong storage domain, which is not related to disk. -- To view, visit http://gerrit.ovirt.org/7337 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib9e47fe370b230b4bd69f108954031cda3bba6a3 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Tal Nisan <tni...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches