Frank Kobzik has uploaded a new change for review.

Change subject: core: prevent running vms when rng is not supported
......................................................................

core: prevent running vms when rng is not supported

This patch prevents vms with active rng device to run when rng device is
not required by cluster and supported by host. This situation could
possibly happen when admin deselects required rng sources on cluster
level, but there are already vms with rng (with such source) created in
the cluster.

Change-Id: Ia67a0a9b2a000670d60e3cc362c93023ddf69f38
Signed-off-by: Frantisek Kobzik <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
1 file changed, 35 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/96/28796/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
index 935e2a1..06f904a 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/RunVmCommand.java
@@ -52,6 +52,7 @@
 import org.ovirt.engine.core.common.businessentities.VmDeviceId;
 import org.ovirt.engine.core.common.businessentities.VmPool;
 import org.ovirt.engine.core.common.businessentities.VmPoolType;
+import org.ovirt.engine.core.common.businessentities.VmRngDevice;
 import org.ovirt.engine.core.common.businessentities.network.Network;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
@@ -842,9 +843,43 @@
             getVm().setVmPayload(getParameters().getVmPayload());
         }
 
+        VdcBllMessages rngDeviceProblemMessage = checkRngDevice();
+        if (rngDeviceProblemMessage != null) {
+           return failCanDoAction(rngDeviceProblemMessage);
+        }
+
         return true;
     }
 
+
+    /**
+     * Checks whether rng device of vm is required by cluster and also 
supported by host.
+     *
+     * For vm with rng device activated, the device must be both supported by 
host and required by cluster.
+     *
+     * @return
+     * - null if vm rng device is both supported by host and required by 
cluster,
+     * - problem message for failCanDoAction otherwise.
+     */
+    private VdcBllMessages checkRngDevice() {
+        List<VmDevice> rngDevs =
+                getVmDeviceDao().getVmDeviceByVmIdTypeAndDevice(getVmId(), 
VmDeviceGeneralType.RNG, VmDeviceType.VIRTIO.getName());
+
+        if (!rngDevs.isEmpty()) {
+            VmRngDevice rngDev = new VmRngDevice(rngDevs.get(0));
+
+            if 
(!getVdsGroup().getRequiredRngSources().contains(rngDev.getSource())) {
+                return 
VdcBllMessages.ACTION_TYPE_FAILED_RNG_SOURCE_NOT_SUPPORTED;
+            }
+
+            if 
(!getVds().getSupportedRngSources().contains(rngDev.getSource())) {
+                return 
VdcBllMessages.ACTION_TYPE_FAILED_RNG_SOURCE_NOT_SUPPORTED; // todo different 
error message or rely on required sources only. active host in cluster with 
given sources must report them
+            }
+        }
+
+        return null;
+    }
+
     @Override
     protected List<Class<?>> getValidationGroups() {
         addValidationGroup(StartEntity.class);


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

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

Reply via email to