Vitor de Lima has uploaded a new change for review.

Change subject: core, engine: SCSI CD-ROM on PPC64 VMs
......................................................................

core, engine: SCSI CD-ROM on PPC64 VMs

This introduces the proper creation of the virtual CD device on
PPC64 VMs. This device must be attached to a SPAPR VSCSI controller,
since currently the SCSI CD doesn't work with the VirtIO SCSI controller.

Change-Id: Id4fefa225cb44f0e09a7a056e07b8393dda6819b
Signed-off-by: Vitor de Lima <[email protected]>
---
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
M 
backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImplTest.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategy.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategyFactory.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/PPC64Strategy.java
A 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/X86_64Strategy.java
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
M packaging/conf/osinfo-defaults.properties
9 files changed, 150 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/22/18622/1

diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
index d18c98c..071f3c8 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepository.java
@@ -113,6 +113,13 @@
     String getSoundDevice(int osId, Version version);
 
     /**
+     * @param osId
+     * @param version
+     * @return a specific Cd Interface for the given os.
+     */
+    String getCdInterface(int osId, Version version);
+
+    /**
      * early windows versions require a numeric identifier for sysprep to tell
      * the timezone. In later versions this was rectified and they use a 
universal name.
      * @param osId
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
index 3a2542f..7377301 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImpl.java
@@ -164,6 +164,11 @@
     }
 
     @Override
+    public String getCdInterface(int osId, Version version) {
+        return getValueByVersion(idToUnameLookup.get(osId), "cdInterface", 
version);
+    }
+
+    @Override
     public boolean isTimezoneValueInteger(int osId, Version version) {
         return getBoolean(getValueByVersion(idToUnameLookup.get(osId), 
"isTimezoneTypeInteger", version), false);
     }
diff --git 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImplTest.java
 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImplTest.java
index 2daee06..49a3ee6 100644
--- 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImplTest.java
+++ 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/osinfo/OsRepositoryImplTest.java
@@ -18,6 +18,7 @@
     public static final String PATH_TO_SYSPREP = "/path/to/sysprep";
     public static final String SOME_PRODUCT_KEY = "some-product-key";
     public static final String SOUND_DEVICE = "ac97";
+    public static final String CD_INTERFACE = "ide";
 
     @BeforeClass
     public static void setUp() throws Exception {
@@ -34,6 +35,7 @@
         preferences.node("/os/rhel7/sysprepPath").put("value", 
PATH_TO_SYSPREP);
         preferences.node("/os/rhel7/productKey").put("value", 
SOME_PRODUCT_KEY);
         preferences.node("/os/rhel7/devices/audio").put("value", SOUND_DEVICE);
+        preferences.node("/os/rhel7/devices/cdInterface").put("value", 
CD_INTERFACE);
         preferences.node("/os/rhel7/isTimezoneTypeInteger").put("value", 
"false");
         preferences.node("/os/bados/id").put("value", "666");
         preferences.node("/os/bados/derivedFrom").put("value", 
"nonExistingOs");
@@ -132,6 +134,11 @@
     }
 
     @Test
+    public void testGetCdInterface() throws Exception {
+        assertTrue(OsRepositoryImpl.INSTANCE.getCdInterface(777, 
null).equals(CD_INTERFACE));
+    }
+
+    @Test
     public void testIsTimezoneValueInteger() throws Exception {
         assertFalse(OsRepositoryImpl.INSTANCE.isTimezoneValueInteger(777, 
null));
     }
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategy.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategy.java
new file mode 100644
index 0000000..785833d
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategy.java
@@ -0,0 +1,15 @@
+package org.ovirt.engine.core.vdsbroker.archstrategy;
+
+import java.util.List;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.businessentities.ArchitectureType;
+
+public abstract class ArchStrategy {
+
+    public abstract ArchitectureType getArchitecture();
+
+    public abstract void createAdditionalControllers(List<Map<String, Object>> 
devices);
+
+    public abstract void addCdromAddress(Map<String, Object> cdromDevice);
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategyFactory.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategyFactory.java
new file mode 100644
index 0000000..11f17cd
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/ArchStrategyFactory.java
@@ -0,0 +1,21 @@
+package org.ovirt.engine.core.vdsbroker.archstrategy;
+
+import java.util.EnumMap;
+
+import org.ovirt.engine.core.common.businessentities.ArchitectureType;
+
+public class ArchStrategyFactory {
+
+    private static final EnumMap<ArchitectureType, ArchStrategy> 
architectureArchStrategyMap =
+            new EnumMap<ArchitectureType, 
ArchStrategy>(ArchitectureType.class);
+
+    static {
+        architectureArchStrategyMap.put(ArchitectureType.x86_64, new 
X86_64Strategy());
+        architectureArchStrategyMap.put(ArchitectureType.ppc64, new 
PPC64Strategy());
+    }
+
+    public static ArchStrategy getStrategy(ArchitectureType architecture) {
+
+        return architectureArchStrategyMap.get(architecture);
+    }
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/PPC64Strategy.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/PPC64Strategy.java
new file mode 100644
index 0000000..bfc037e
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/PPC64Strategy.java
@@ -0,0 +1,44 @@
+package org.ovirt.engine.core.vdsbroker.archstrategy;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.businessentities.ArchitectureType;
+import org.ovirt.engine.core.common.utils.VmDeviceType;
+import org.ovirt.engine.core.vdsbroker.vdsbroker.VdsProperties;
+
+public class PPC64Strategy extends ArchStrategy {
+
+    @Override
+    public ArchitectureType getArchitecture() {
+        return ArchitectureType.ppc64;
+    }
+
+    @Override
+    public void createAdditionalControllers(List<Map<String, Object>> devices) 
{
+        // This creates a SPAPR VSCSI controller, which is needed by the 
virtual
+        // SCSI CD-ROM on POWER guests
+        Map<String, Object> struct = new HashMap<String, Object>();
+        struct.put(VdsProperties.Type, VmDeviceType.CONTROLLER.getName());
+        struct.put(VdsProperties.Device, VdsProperties.Scsi);
+        struct.put(VdsProperties.Index, "1");
+
+        Map<String, String> spaprAddress = new HashMap<String, String>();
+
+        spaprAddress.put("type", "spapr-vio");
+
+        struct.put(VdsProperties.Address, spaprAddress);
+        devices.add(struct);
+    }
+
+    @Override
+    public void addCdromAddress(Map<String, Object> cdromDevice) {
+        Map<String, String> cdromAddress = new HashMap<String, String>();
+
+        cdromAddress.put("type", "drive");
+        cdromAddress.put("controller", "1");
+
+        cdromDevice.put(VdsProperties.Address, cdromAddress);
+    }
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/X86_64Strategy.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/X86_64Strategy.java
new file mode 100644
index 0000000..39044e4
--- /dev/null
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/archstrategy/X86_64Strategy.java
@@ -0,0 +1,24 @@
+package org.ovirt.engine.core.vdsbroker.archstrategy;
+
+import java.util.List;
+import java.util.Map;
+
+import org.ovirt.engine.core.common.businessentities.ArchitectureType;
+
+public class X86_64Strategy extends ArchStrategy {
+
+    @Override
+    public ArchitectureType getArchitecture() {
+        return ArchitectureType.x86_64;
+    }
+
+    @Override
+    public void createAdditionalControllers(List<Map<String, Object>> devices) 
{
+        // There are not any additional controllers necessary for the x86_64 
guests to work properly
+    }
+
+    @Override
+    public void addCdromAddress(Map<String, Object> cdromDevice) {
+        // The default CD-ROM address works fine for the x86_64 architecture
+    }
+}
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
index 22046b3..c15bc13 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/vdsbroker/VmInfoBuilder.java
@@ -28,11 +28,15 @@
 import org.ovirt.engine.core.common.businessentities.network.VmInterfaceType;
 import org.ovirt.engine.core.common.businessentities.network.VmNic;
 import org.ovirt.engine.core.common.businessentities.network.VnicProfile;
+import org.ovirt.engine.core.common.osinfo.OsRepository;
+import org.ovirt.engine.core.common.utils.SimpleDependecyInjector;
 import org.ovirt.engine.core.common.utils.VmDeviceCommonUtils;
 import org.ovirt.engine.core.common.utils.VmDeviceType;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.compat.Version;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.vdsbroker.archstrategy.ArchStrategy;
+import org.ovirt.engine.core.vdsbroker.archstrategy.ArchStrategyFactory;
 import org.ovirt.engine.core.vdsbroker.xmlrpc.XmlRpcStringUtils;
 
 @SuppressWarnings({"rawtypes", "unchecked"})
@@ -126,7 +130,7 @@
                             "",
                             null);
             struct = new HashMap<String, Object>();
-            addCdDetails(vmDevice, struct);
+            addCdDetails(vmDevice, struct, vm);
             addDevice(struct, vmDevice, "");
         }
         // check first if CD was given as a parameter
@@ -144,7 +148,7 @@
                             "",
                             null);
             struct = new HashMap<String, Object>();
-            addCdDetails(vmDevice, struct);
+            addCdDetails(vmDevice, struct, vm);
             addDevice(struct, vmDevice, vm.getCdPath());
         } else {
             // get vm device for this CD from DB
@@ -161,7 +165,7 @@
                 }
                 struct = new HashMap<String, Object>();
                 String cdPath = vm.getCdPath();
-                addCdDetails(vmDevice, struct);
+                addCdDetails(vmDevice, struct, vm);
                 addAddress(vmDevice, struct);
                 addDevice(struct, vmDevice, cdPath == null ? "" : cdPath);
             }
@@ -185,7 +189,7 @@
                             "",
                             null);
             Map<String, Object> struct = new HashMap<String, Object>();
-            addCdDetails(vmDevice, struct);
+            addCdDetails(vmDevice, struct, vm);
             addDevice(struct, vmDevice, "");
         }
         // check first if Floppy was given as a parameter
@@ -307,8 +311,13 @@
             struct.put(VdsProperties.Type, 
VmDeviceGeneralType.CONTROLLER.getValue());
             struct.put(VdsProperties.Device, VdsProperties.Scsi);
             struct.put(VdsProperties.Model, VdsProperties.VirtioScsi);
+            struct.put(VdsProperties.Index, "0");
             devices.add(struct);
         }
+
+        ArchStrategy archStrategy = 
ArchStrategyFactory.getStrategy(vm.getArchitecture());
+
+        archStrategy.createAdditionalControllers(devices);
     }
 
     @Override
@@ -494,7 +503,7 @@
                         "",
                         null);
         Map<String, Object> struct = new HashMap<String, Object>();
-        addCdDetails(vmDevice, struct);
+        addCdDetails(vmDevice, struct, vm);
         addDevice(struct, vmDevice, "");
     }
 
@@ -608,11 +617,20 @@
         struct.put(VdsProperties.Shareable, Boolean.FALSE.toString());
     }
 
-    private static void addCdDetails(VmDevice vmDevice, Map<String, Object> 
struct) {
+    private static void addCdDetails(VmDevice vmDevice, Map<String, Object> 
struct, VM vm) {
+        OsRepository osRepository = 
SimpleDependecyInjector.getInstance().get(OsRepository.class);
+
         struct.put(VdsProperties.Type, vmDevice.getType().getValue());
         struct.put(VdsProperties.Device, vmDevice.getDevice());
         struct.put(VdsProperties.Index, "2"); // IDE slot 2 is reserved by 
VDSM to CDROM
-        struct.put(VdsProperties.INTERFACE, VdsProperties.Ide);
+        struct.put(VdsProperties.INTERFACE,
+                osRepository.getCdInterface(vm.getOs(),
+                        vm.getVdsGroupCompatibilityVersion()));
+
+        ArchStrategy archStrategy = 
ArchStrategyFactory.getStrategy(vm.getArchitecture());
+
+        archStrategy.addCdromAddress(struct);
+
         struct.put(VdsProperties.ReadOnly, Boolean.TRUE.toString());
         struct.put(VdsProperties.Shareable, Boolean.FALSE.toString());
     }
diff --git a/packaging/conf/osinfo-defaults.properties 
b/packaging/conf/osinfo-defaults.properties
index ad1f898..a96b5f9 100644
--- a/packaging/conf/osinfo-defaults.properties
+++ b/packaging/conf/osinfo-defaults.properties
@@ -46,6 +46,7 @@
 os.other.resources.minimum.disksize.value = 1
 os.other.resources.minimum.numberOsCpus.value = 1
 os.other.spiceSupport.value = true
+os.other.cdInterface.value = ide
 
 os.other.devices.audio.value = ich6
 # See VmInterfaceType.java
@@ -65,6 +66,7 @@
 os.other_ppc64.resources.minimum.disksize.value = 1
 os.other_ppc64.resources.minimum.numberOsCpus.value = 1
 os.other_ppc64.spiceSupport.value = false
+os.other_ppc64.cdInterface.value = scsi
 os.other_ppc64.devices.audio.value = ich6
 os.other_ppc64.devices.network.value = rtl8139, pv
 os.other_ppc64.devices.diskInterfaces.value = VirtIO, VirtIO_SCSI


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

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

Reply via email to