Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent/conf/agent.properties
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ hypervisor.type=kvm
# the management server would send.
# In case of arm64 (aarch64), this will change the machine type to 'virt' and
# adds a SCSI and a USB controller in the domain xml.
# Possible values: x86_64 | aarch64
# Possible values: x86_64 | aarch64 | s390x
# If null (default), defaults to the VM's OS architecture
#guest.cpu.arch=

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public class AgentProperties{
/**
* This param will set the CPU architecture for the domain to override what the management server would send.<br>
* 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>
* Possible values: x86_64 | aarch64 <br>
* Possible values: x86_64 | aarch64 | s390x <br>
* Data type: String.<br>
* Default value: <code>null</code> (will set use the architecture of the VM's OS).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
/**
* Machine type.
*/
private static final String PC = "pc";
private static final String VIRT = "virt";
private static final String PC = ("s390x".equals(System.getProperty("os.arch"))) ? "s390-ccw-virtio" : "pc";
private static final String VIRT = ("s390x".equals(System.getProperty("os.arch"))) ? "s390-ccw-virtio" : "virt";

/**
* Possible devices to add to VM.
Expand Down Expand Up @@ -305,6 +305,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
* Constant that defines ARM64 (aarch64) guest architectures.
*/
private static final String AARCH64 = "aarch64";
/**
* Constant that defines IBM Z Arch (s390x) guest architectures.
*/
private static final String S390X = "s390x";

public static final String RESIZE_NOTIFY_ONLY = "NOTIFYONLY";
public static final String BASEPATH = "/usr/share/cloudstack-common/vms/";
Expand Down Expand Up @@ -1796,7 +1800,8 @@ private String matchPifFileInDirectory(final String bridgeName) {
"^dummy",
"^lo",
"^p\\d+p\\d+",
"^vni"
"^vni",
"^enc"
};

/**
Expand Down Expand Up @@ -2642,12 +2647,15 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
}

devices.addDevice(createChannelDef(vmTO));
devices.addDevice(createWatchDogDef());
if (!isGuestS390x()) {
devices.addDevice(createWatchDogDef());
}
devices.addDevice(createVideoDef(vmTO));
devices.addDevice(createConsoleDef());
devices.addDevice(createGraphicDef(vmTO));
devices.addDevice(createTabletInputDef());

if (!isGuestS390x()) {
devices.addDevice(createTabletInputDef());
}
if (isGuestAarch64()) {
createArm64UsbDef(devices);
}
Expand Down Expand Up @@ -2754,7 +2762,9 @@ protected FeaturesDef createFeaturesDef(Map<String, String> customParams, boolea
FeaturesDef features = new FeaturesDef();
features.addFeatures(PAE);
features.addFeatures(APIC);
features.addFeatures(ACPI);
if (!"s390x".equals(System.getProperty("os.arch"))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be better to create a method like

    private boolean isHostS390x() {
        return S390X.equals(System.getProperty("os.arch");
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reused existing isGuestS390x() method for this.

features.addFeatures(ACPI);
}
if (isUefiEnabled && isSecureBoot) {
features.addFeatures(SMM);
}
Expand Down Expand Up @@ -2846,6 +2856,10 @@ private boolean isGuestAarch64() {
return AARCH64.equals(guestCpuArch);
}

private boolean isGuestS390x() {
return S390X.equals(guestCpuArch);
}

/**
* Creates a guest definition from a VM specification.
*/
Expand All @@ -2856,7 +2870,7 @@ protected GuestDef createGuestFromSpec(VirtualMachineTO vmTO, LibvirtVMDef vm, S
guest.setManufacturer(vmTO.getMetadataManufacturer());
guest.setProduct(vmTO.getMetadataProductName());
guest.setGuestArch(guestCpuArch != null ? guestCpuArch : vmTO.getArch());
guest.setMachineType(isGuestAarch64() ? VIRT : PC);
guest.setMachineType((isGuestAarch64() || isGuestS390x()) ? VIRT : PC);
guest.setBootType(GuestDef.BootType.BIOS);
if (MapUtils.isNotEmpty(customParams)) {
if (customParams.containsKey(GuestDef.BootType.UEFI.toString())) {
Expand All @@ -2870,7 +2884,9 @@ protected GuestDef createGuestFromSpec(VirtualMachineTO vmTO, LibvirtVMDef vm, S
guest.setIothreads(customParams.containsKey(VmDetailConstants.IOTHREADS));
}
guest.setUuid(uuid);
guest.setBootOrder(GuestDef.BootOrder.CDROM);
if(!isGuestS390x()) {
guest.setBootOrder(GuestDef.BootOrder.CDROM);
}
guest.setBootOrder(GuestDef.BootOrder.HARDISK);
return guest;
}
Expand Down Expand Up @@ -3110,7 +3126,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
final DiskDef.DiskType diskType = getDiskType(physicalDisk);
disk.defISODisk(volPath, devId, isUefiEnabled, diskType);

if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
if (guestCpuArch != null && (guestCpuArch.equals("aarch64") || guestCpuArch.equals("s390x"))) {
disk.setBusType(DiskDef.DiskBus.SCSI);
}
} else {
Expand Down Expand Up @@ -3208,7 +3224,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
if (vmSpec.getType() != VirtualMachine.Type.User) {
final DiskDef iso = new DiskDef();
iso.defISODisk(sysvmISOPath, DiskDef.DiskType.FILE);
if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
if (guestCpuArch != null && (guestCpuArch.equals("aarch64") || guestCpuArch.equals("s390x"))) {
iso.setBusType(DiskDef.DiskBus.SCSI);
}
vm.getDevices().addDevice(iso);
Expand Down Expand Up @@ -4276,7 +4292,7 @@ private DiskDef.DiskBus getGuestDiskModel(final String platformEmulator, boolean
return DiskDef.DiskBus.VIRTIO;
} else if (isUefiEnabled && StringUtils.startsWithAny(platformEmulator, "Windows", "Other")) {
return DiskDef.DiskBus.SATA;
} else if (guestCpuArch != null && guestCpuArch.equals("aarch64")) {
} else if (guestCpuArch != null && (guestCpuArch.equals("aarch64") || guestCpuArch.equals("s390x"))) {
return DiskDef.DiskBus.SCSI;
} else {
return DiskDef.DiskBus.IDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ public String toString() {
guestDef.append("<boot dev='" + bo + "'/>\n");
}
}
guestDef.append("<smbios mode='sysinfo'/>\n");
if (!(_arch != null && _arch.equals("s390x"))) {
guestDef.append("<smbios mode='sysinfo'/>\n");
}
guestDef.append("</os>\n");
if (iothreads) {
guestDef.append(String.format("<iothreads>%s</iothreads>", NUMBER_OF_IOTHREADS));
Expand Down Expand Up @@ -580,7 +582,7 @@ public String toString() {
}
}

if (_emulator != null && _emulator.endsWith("aarch64")) {
if (_emulator != null && (_emulator.endsWith("aarch64") || _emulator.endsWith("s390x"))) {
devicesBuilder.append("<controller type='pci' model='pcie-root'/>\n");
for (int i = 0; i < 32; i++) {
devicesBuilder.append("<controller type='pci' model='pcie-root-port'/>\n");
Expand Down Expand Up @@ -1652,7 +1654,7 @@ public String getContent() {
if (_scriptPath != null) {
netBuilder.append("<script path='" + _scriptPath + "'/>\n");
}
if (_pxeDisable) {
if (_pxeDisable && !"s390x".equals(System.getProperty("os.arch"))) {
netBuilder.append("<rom bar='off' file=''/>");
}
if (_virtualPortType != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
try {
LOGGER.info("Fetching CPU speed from command \"lscpu\".");
String command = "lscpu | grep -i 'Model name' | head -n 1 | egrep -o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'";
if("s390x".equals(System.getProperty("os.arch"))) {
command = "lscpu | grep 'CPU dynamic MHz' | cut -d ':' -f 2 | tr -d ' ' | awk '{printf \"%.1f\\n\", $1 / 1000}'";

Check warning on line 141 in plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L141 was not covered by tests
}
String result = Script.runSimpleBashScript(command);
long speed = (long) (Float.parseFloat(result) * 1000);
LOGGER.info(String.format("Command [%s] resulted in the value [%s] for CPU speed.", command, speed));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ public void testCreateGuestFromSpecWithoutCustomParam() {
VirtualMachineTO to = createDefaultVM(false);
LibvirtVMDef vm = new LibvirtVMDef();
GuestDef guestDef = libvirtComputingResourceSpy.createGuestFromSpec(to, vm, to.getUuid(), null);
verifySysInfo(guestDef, "smbios", to.getUuid(), "pc");
verifySysInfo(guestDef, "smbios", to.getUuid(), "s390x".equals(System.getProperty("os.arch")) ? "s390-ccw-virtio" : "pc");
Assert.assertEquals(GuestDef.BootType.BIOS, guestDef.getBootType());
Assert.assertNull(guestDef.getBootMode());
}
Expand Down Expand Up @@ -826,7 +826,7 @@ private void verifyOsBoot(Document domainDoc) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@

if (vmProfile.getTemplate().getBits() == 32) {
to.setArch("i686");
} else if("s390x".equals(System.getProperty("os.arch"))) {
to.setArch("s390x");

Check warning on line 313 in server/src/main/java/com/cloud/hypervisor/HypervisorGuruBase.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L313 was not covered by tests
} else {
to.setArch("x86_64");
}
Expand Down