Skip to content

Commit 0aa422f

Browse files
committed
Added s390x Arch support for KVM
Signed-off-by: Niyam Siwach <[email protected]> Signed-off-by: Himanshu Mishra <[email protected]>
1 parent 4ac4d9c commit 0aa422f

File tree

7 files changed

+42
-19
lines changed

7 files changed

+42
-19
lines changed

agent/conf/agent.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ hypervisor.type=kvm
209209
# the management server would send.
210210
# In case of arm64 (aarch64), this will change the machine type to 'virt' and
211211
# adds a SCSI and a USB controller in the domain xml.
212-
# Possible values: x86_64 | aarch64
212+
# Possible values: x86_64 | aarch64 | s390x
213213
# If null (default), defaults to the VM's OS architecture
214214
#guest.cpu.arch=
215215

agent/src/main/java/com/cloud/agent/properties/AgentProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public class AgentProperties{
383383
/**
384384
* This param will set the CPU architecture for the domain to override what the management server would send.<br>
385385
* In case of arm64 (aarch64), this will change the machine type to 'virt' and add a SCSI and a USB controller in the domain XML.<br>
386-
* Possible values: x86_64 | aarch64 <br>
386+
* Possible values: x86_64 | aarch64 | s390x <br>
387387
* Data type: String.<br>
388388
* Default value: <code>null</code> (will set use the architecture of the VM's OS).
389389
*/

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
247247
/**
248248
* Machine type.
249249
*/
250-
private static final String PC = "pc";
251-
private static final String VIRT = "virt";
250+
private static final String PC = ("s390x".equals(System.getProperty("os.arch"))) ? "s390-ccw-virtio" : "pc";
251+
private static final String VIRT = ("s390x".equals(System.getProperty("os.arch"))) ? "s390-ccw-virtio" : "virt";
252252

253253
/**
254254
* Possible devices to add to VM.
@@ -305,6 +305,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
305305
* Constant that defines ARM64 (aarch64) guest architectures.
306306
*/
307307
private static final String AARCH64 = "aarch64";
308+
/**
309+
* Constant that defines IBM Z Arch (s390x) guest architectures.
310+
*/
311+
private static final String S390X = "s390x";
308312

309313
public static final String RESIZE_NOTIFY_ONLY = "NOTIFYONLY";
310314
public static final String BASEPATH = "/usr/share/cloudstack-common/vms/";
@@ -1796,7 +1800,8 @@ private String matchPifFileInDirectory(final String bridgeName) {
17961800
"^dummy",
17971801
"^lo",
17981802
"^p\\d+p\\d+",
1799-
"^vni"
1803+
"^vni",
1804+
"^enc"
18001805
};
18011806

18021807
/**
@@ -2642,12 +2647,15 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
26422647
}
26432648

26442649
devices.addDevice(createChannelDef(vmTO));
2645-
devices.addDevice(createWatchDogDef());
2650+
if (!isGuestS390x()) {
2651+
devices.addDevice(createWatchDogDef());
2652+
}
26462653
devices.addDevice(createVideoDef(vmTO));
26472654
devices.addDevice(createConsoleDef());
26482655
devices.addDevice(createGraphicDef(vmTO));
2649-
devices.addDevice(createTabletInputDef());
2650-
2656+
if (!isGuestS390x()) {
2657+
devices.addDevice(createTabletInputDef());
2658+
}
26512659
if (isGuestAarch64()) {
26522660
createArm64UsbDef(devices);
26532661
}
@@ -2754,7 +2762,9 @@ protected FeaturesDef createFeaturesDef(Map<String, String> customParams, boolea
27542762
FeaturesDef features = new FeaturesDef();
27552763
features.addFeatures(PAE);
27562764
features.addFeatures(APIC);
2757-
features.addFeatures(ACPI);
2765+
if (!"s390x".equals(System.getProperty("os.arch"))) {
2766+
features.addFeatures(ACPI);
2767+
}
27582768
if (isUefiEnabled && isSecureBoot) {
27592769
features.addFeatures(SMM);
27602770
}
@@ -2846,6 +2856,10 @@ private boolean isGuestAarch64() {
28462856
return AARCH64.equals(guestCpuArch);
28472857
}
28482858

2859+
private boolean isGuestS390x() {
2860+
return S390X.equals(guestCpuArch);
2861+
}
2862+
28492863
/**
28502864
* Creates a guest definition from a VM specification.
28512865
*/
@@ -2856,7 +2870,7 @@ protected GuestDef createGuestFromSpec(VirtualMachineTO vmTO, LibvirtVMDef vm, S
28562870
guest.setManufacturer(vmTO.getMetadataManufacturer());
28572871
guest.setProduct(vmTO.getMetadataProductName());
28582872
guest.setGuestArch(guestCpuArch != null ? guestCpuArch : vmTO.getArch());
2859-
guest.setMachineType(isGuestAarch64() ? VIRT : PC);
2873+
guest.setMachineType((isGuestAarch64() || isGuestS390x()) ? VIRT : PC);
28602874
guest.setBootType(GuestDef.BootType.BIOS);
28612875
if (MapUtils.isNotEmpty(customParams)) {
28622876
if (customParams.containsKey(GuestDef.BootType.UEFI.toString())) {
@@ -2870,7 +2884,9 @@ protected GuestDef createGuestFromSpec(VirtualMachineTO vmTO, LibvirtVMDef vm, S
28702884
guest.setIothreads(customParams.containsKey(VmDetailConstants.IOTHREADS));
28712885
}
28722886
guest.setUuid(uuid);
2873-
guest.setBootOrder(GuestDef.BootOrder.CDROM);
2887+
if(!isGuestS390x()) {
2888+
guest.setBootOrder(GuestDef.BootOrder.CDROM);
2889+
}
28742890
guest.setBootOrder(GuestDef.BootOrder.HARDISK);
28752891
return guest;
28762892
}
@@ -3110,7 +3126,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
31103126
final DiskDef.DiskType diskType = getDiskType(physicalDisk);
31113127
disk.defISODisk(volPath, devId, isUefiEnabled, diskType);
31123128

3113-
if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
3129+
if (guestCpuArch != null && (guestCpuArch.equals("aarch64") || guestCpuArch.equals("s390x"))) {
31143130
disk.setBusType(DiskDef.DiskBus.SCSI);
31153131
}
31163132
} else {
@@ -3208,7 +3224,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
32083224
if (vmSpec.getType() != VirtualMachine.Type.User) {
32093225
final DiskDef iso = new DiskDef();
32103226
iso.defISODisk(sysvmISOPath, DiskDef.DiskType.FILE);
3211-
if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
3227+
if (guestCpuArch != null && (guestCpuArch.equals("aarch64") || guestCpuArch.equals("s390x"))) {
32123228
iso.setBusType(DiskDef.DiskBus.SCSI);
32133229
}
32143230
vm.getDevices().addDevice(iso);
@@ -4276,7 +4292,7 @@ private DiskDef.DiskBus getGuestDiskModel(final String platformEmulator, boolean
42764292
return DiskDef.DiskBus.VIRTIO;
42774293
} else if (isUefiEnabled && StringUtils.startsWithAny(platformEmulator, "Windows", "Other")) {
42784294
return DiskDef.DiskBus.SATA;
4279-
} else if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
4295+
} else if (guestCpuArch != null && (guestCpuArch.equals("aarch64") || guestCpuArch.equals("s390x"))) {
42804296
return DiskDef.DiskBus.SCSI;
42814297
} else {
42824298
return DiskDef.DiskBus.IDE;

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,9 @@ public String toString() {
248248
guestDef.append("<boot dev='" + bo + "'/>\n");
249249
}
250250
}
251-
guestDef.append("<smbios mode='sysinfo'/>\n");
251+
if (!(_arch != null && _arch.equals("s390x"))) {
252+
guestDef.append("<smbios mode='sysinfo'/>\n");
253+
}
252254
guestDef.append("</os>\n");
253255
if (iothreads) {
254256
guestDef.append(String.format("<iothreads>%s</iothreads>", NUMBER_OF_IOTHREADS));
@@ -580,7 +582,7 @@ public String toString() {
580582
}
581583
}
582584

583-
if (_emulator != null && _emulator.endsWith("aarch64")) {
585+
if (_emulator != null && (_emulator.endsWith("aarch64") || _emulator.endsWith("s390x"))) {
584586
devicesBuilder.append("<controller type='pci' model='pcie-root'/>\n");
585587
for (int i = 0; i < 32; i++) {
586588
devicesBuilder.append("<controller type='pci' model='pcie-root-port'/>\n");
@@ -1652,7 +1654,7 @@ public String getContent() {
16521654
if (_scriptPath != null) {
16531655
netBuilder.append("<script path='" + _scriptPath + "'/>\n");
16541656
}
1655-
if (_pxeDisable) {
1657+
if (_pxeDisable && !"s390x".equals(System.getProperty("os.arch"))) {
16561658
netBuilder.append("<rom bar='off' file=''/>");
16571659
}
16581660
if (_virtualPortType != null) {

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ private static long getCpuSpeedFromCommandLscpu() {
137137
try {
138138
LOGGER.info("Fetching CPU speed from command \"lscpu\".");
139139
String command = "lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'";
140+
if("s390x".equals(System.getProperty("os.arch"))) {
141+
command = "lscpu | grep 'CPU dynamic MHz' | cut -d ':' -f 2 | tr -d ' ' | awk '{printf \"%.1f\\n\", $1 / 1000}'";
142+
}
140143
String result = Script.runSimpleBashScript(command);
141144
long speed = (long) (Float.parseFloat(result) * 1000);
142145
LOGGER.info(String.format("Command [%s] resulted in the value [%s] for CPU speed.", command, speed));

plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public void testCreateGuestFromSpecWithoutCustomParam() {
401401
VirtualMachineTO to = createDefaultVM(false);
402402
LibvirtVMDef vm = new LibvirtVMDef();
403403
GuestDef guestDef = libvirtComputingResourceSpy.createGuestFromSpec(to, vm, to.getUuid(), null);
404-
verifySysInfo(guestDef, "smbios", to.getUuid(), "pc");
404+
verifySysInfo(guestDef, "smbios", to.getUuid(), "s390x".equals(System.getProperty("os.arch")) ? "s390-ccw-virtio" : "pc");
405405
Assert.assertEquals(GuestDef.BootType.BIOS, guestDef.getBootType());
406406
Assert.assertNull(guestDef.getBootMode());
407407
}
@@ -826,7 +826,7 @@ private void verifyOsBoot(Document domainDoc) {
826826
}
827827

828828
private void verifyOsType(Document domainDoc) {
829-
assertXpath(domainDoc, "/domain/os/type/@machine", "pc");
829+
assertXpath(domainDoc, "/domain/os/type/@machine", "s390x".equals(System.getProperty("os.arch")) ? "s390-ccw-virtio" : "pc");
830830
assertXpath(domainDoc, "/domain/os/type/text()", "hvm");
831831
}
832832

server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,8 @@ protected VirtualMachineTO toVirtualMachineTO(VirtualMachineProfile vmProfile) {
309309

310310
if (vmProfile.getTemplate().getBits() == 32) {
311311
to.setArch("i686");
312+
} else if("s390x".equals(System.getProperty("os.arch"))) {
313+
to.setArch("s390x");
312314
} else {
313315
to.setArch("x86_64");
314316
}

0 commit comments

Comments
 (0)