Roy Golan has uploaded a new change for review.

Change subject: core: remove unmanaged devices on down VM event
......................................................................

core: remove unmanaged devices on down VM event

unmanaged devices where being removed only by direct stop/shutdown
commands. This patch will move this treatment to be fired by the
eventListener onProcressStopVm so even when a guest VM is shuting down
by its OS function, without th engine, unmanaged devices will be removed

Change-Id: I6593b9cb36fecc87f9b9af574d61300d55d6ad62
Bug-Url: https://bugzilla.redhat.com/846696
Signed-off-by: Roy Golan <rgo...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
3 files changed, 49 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/56/9756/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
index 82148fe..fb28d39 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/StopVmCommandBase.java
@@ -15,7 +15,6 @@
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
-import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.common.vdscommands.DestroyVmVDSCommandParameters;
 import 
org.ovirt.engine.core.common.vdscommands.UpdateVmDynamicDataVDSCommandParameters;
@@ -95,33 +94,6 @@
             setSucceeded(stopSuspendedVm());
         } else {
             super.executeVmCommand();
-        }
-        removeStatelessVmUnmanagedDevices();
-    }
-
-    private void removeStatelessVmUnmanagedDevices() {
-        if (getSucceeded() && (getVm().getis_stateless() ||  isRunOnce())) {
-            // remove all unmanaged devices of a stateless VM
-
-            final List<VmDevice> vmDevices =
-                    DbFacade.getInstance()
-                            .getVmDeviceDao()
-                            .getUnmanagedDevicesByVmId(getVm().getId());
-
-            TransactionSupport.executeInNewTransaction(new 
TransactionMethod<Void>() {
-
-                @Override
-                public Void runInTransaction() {
-                    for (VmDevice device : vmDevices) {
-                        // do not remove device if appears in white list
-                        if (! 
VmDeviceCommonUtils.isInWhiteList(device.getType(), device.getDevice())) {
-                            
DbFacade.getInstance().getVmDeviceDao().remove(device.getId());
-                        }
-                    }
-                    return null;
-                }
-
-            });
         }
     }
 
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
index 0fe80e0..a094496 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VdsEventListener.java
@@ -92,6 +92,7 @@
     @Override
     public void processOnVmStop(Guid vmId) {
         VmPoolHandler.ProcessVmPoolOnStopVm(vmId, null);
+        VmHandler.removeStatelessVmUnmanagedDevices(vmId);
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
index c66b040..f7d8560 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/VmHandler.java
@@ -17,6 +17,7 @@
 import org.ovirt.engine.core.common.businessentities.VM;
 import org.ovirt.engine.core.common.businessentities.VMStatus;
 import org.ovirt.engine.core.common.businessentities.VmBase;
+import org.ovirt.engine.core.common.businessentities.VmDevice;
 import org.ovirt.engine.core.common.businessentities.VmDynamic;
 import org.ovirt.engine.core.common.businessentities.VmNetworkInterface;
 import org.ovirt.engine.core.common.businessentities.VmOsType;
@@ -25,6 +26,8 @@
 import org.ovirt.engine.core.common.config.ConfigValues;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
+import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.common.utils.VmValidationUtils;
 import 
org.ovirt.engine.core.common.vdscommands.SetVmStatusVDSCommandParameters;
 import org.ovirt.engine.core.common.vdscommands.VDSCommandType;
@@ -453,6 +456,51 @@
         }
     }
 
+    /**
+     * remove VMs unmanaged devices that are created during run-once or 
stateless run.
+     * @param vmId
+     */
+    public static void removeStatelessVmUnmanagedDevices(Guid vmId) {
+        VM vm = DbFacade.getInstance().getVmDao().get(vmId);
+
+        if (vm != null && vm.getis_stateless() || isRunOnce(vmId)) {
+
+            final List<VmDevice> vmDevices =
+                    DbFacade.getInstance()
+                            .getVmDeviceDao()
+                            .getUnmanagedDevicesByVmId(vmId);
+
+            for (VmDevice device : vmDevices) {
+                // do not remove device if appears in white list
+                if (!VmDeviceCommonUtils.isInWhiteList(device.getType(), 
device.getDevice())) {
+                    
DbFacade.getInstance().getVmDeviceDao().remove(device.getId());
+                }
+            }
+        }
+    }
+
+    /**
+     * This method checks if we are stopping a VM that was started by run-once 
In such case we will may have 2 devices,
+     * one managed and one unmanaged for CD or Floppy This is not supported 
currently by libvirt that allows only one
+     * CD/Floppy This code should be removed if libvirt will support in future 
multiple CD/Floppy
+     */
+    private static boolean isRunOnce(Guid vmId) {
+        List<VmDevice> cdList =
+                DbFacade.getInstance()
+                        .getVmDeviceDao()
+                        .getVmDeviceByVmIdTypeAndDevice(vmId,
+                                VmDeviceType.DISK.getName(),
+                                VmDeviceType.CDROM.getName());
+        List<VmDevice> floppyList =
+                DbFacade.getInstance()
+                        .getVmDeviceDao()
+                        .getVmDeviceByVmIdTypeAndDevice(vmId,
+                                VmDeviceType.DISK.getName(),
+                                VmDeviceType.FLOPPY.getName());
+
+        return (cdList.size() > 1 || floppyList.size() > 1);
+    }
+
     private static final Log log = LogFactory.getLog(VmHandler.class);
 
 }


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6593b9cb36fecc87f9b9af574d61300d55d6ad62
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Roy Golan <rgo...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to