Tal Nisan has uploaded a new change for review.

Change subject: core: Added lock to VM when hot plugging/unplugging disks 
(#844440)
......................................................................

core: Added lock to VM when hot plugging/unplugging disks (#844440)

https://bugzilla.redhat.com/844440

Added a lock to a VM when hot plugging/unplugging disks, this avoids
the possibility of taking a snapshot of a VM in the middle of a hot
plug/unplug of a disk

Change-Id: Ic6ec6996b265851c7c691e1a4e68cba246df322a
Signed-off-by: Tal Nisan <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
2 files changed, 17 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/7805/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
index cd20973..95fb10b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CreateAllSnapshotsFromVmCommand.java
@@ -237,14 +237,15 @@
                             checkVmIsDown(),
                             true, true, disksList);
         }
-
-        if (!result) {
-            addCanDoActionMessage(VdcBllMessages.VAR__ACTION__CREATE);
-            addCanDoActionMessage(VdcBllMessages.VAR__TYPE__SNAPSHOT);
-        }
         return result;
     }
 
+    @Override
+    protected void setActionMessageParameters() {
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__CREATE);
+        addCanDoActionMessage(VdcBllMessages.VAR__TYPE__SNAPSHOT);
+    }
+
     /**
      * @return Check for VM down only if DC level does not support live 
snapshots.
      */
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
index 64cf251..b574a05 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/HotPlugDiskToVmCommand.java
@@ -1,5 +1,8 @@
 package org.ovirt.engine.core.bll;
 
+import java.util.Collections;
+import java.util.Map;
+
 import org.ovirt.engine.core.bll.utils.VmDeviceUtils;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.HotPlugDiskToVmParameters;
@@ -7,6 +10,7 @@
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
+import org.ovirt.engine.core.common.locks.LockingGroup;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
 import org.ovirt.engine.core.dal.VdcBllMessages;
 import org.ovirt.engine.core.utils.transaction.TransactionMethod;
@@ -33,7 +37,8 @@
     @Override
     protected boolean canDoAction() {
         disk = getDiskDao().get(getParameters().getDiskId());
-        return isVmExist() && isVmUpOrDown() && isDiskExist(disk) && 
checkCanPerformPlugUnPlugDisk();
+        return isVmExist() && isVmUpOrDown() && isDiskExist(disk) && 
checkCanPerformPlugUnPlugDisk()
+                && acquireLockInternal();
     }
 
     private boolean checkCanPerformPlugUnPlugDisk() {
@@ -84,6 +89,11 @@
     }
 
     @Override
+    protected Map<String, String> getExclusiveLocks() {
+        return Collections.singletonMap(getVmId().toString(), 
LockingGroup.VM.name());
+    }
+
+    @Override
     public AuditLogType getAuditLogTypeValue() {
         return getSucceeded() ? AuditLogType.USER_HOTPLUG_DISK : 
AuditLogType.USER_FAILED_HOTPLUG_DISK;
     }


--
To view, visit http://gerrit.ovirt.org/7805
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic6ec6996b265851c7c691e1a4e68cba246df322a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Tal Nisan <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to