1818
1919import static com .cloud .host .Host .HOST_INSTANCE_CONVERSION ;
2020import static com .cloud .host .Host .HOST_VOLUME_ENCRYPTION ;
21+ import static org .apache .cloudstack .utils .linux .KVMHostInfo .isHostS390x ;
2122
2223import java .io .BufferedReader ;
2324import java .io .File ;
@@ -244,11 +245,16 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
244245 private static final String LEGACY = "legacy" ;
245246 private static final String SECURE = "secure" ;
246247
248+ /**
249+ * Machine type for s390x architecture
250+ */
251+ private static final String S390X_VIRTIO_DEVICE = "s390-ccw-virtio" ;
252+
247253 /**
248254 * Machine type.
249255 */
250- private static final String PC = "pc" ;
251- private static final String VIRT = "virt" ;
256+ private static final String PC = isHostS390x () ? S390X_VIRTIO_DEVICE : "pc" ;
257+ private static final String VIRT = isHostS390x () ? S390X_VIRTIO_DEVICE : "virt" ;
252258
253259 /**
254260 * Possible devices to add to VM.
@@ -305,6 +311,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
305311 * Constant that defines ARM64 (aarch64) guest architectures.
306312 */
307313 private static final String AARCH64 = "aarch64" ;
314+ /**
315+ * Constant that defines IBM Z Arch (s390x) guest architectures.
316+ */
317+ private static final String S390X = "s390x" ;
308318
309319 public static final String RESIZE_NOTIFY_ONLY = "NOTIFYONLY" ;
310320 public static final String BASEPATH = "/usr/share/cloudstack-common/vms/" ;
@@ -1796,7 +1806,8 @@ private String matchPifFileInDirectory(final String bridgeName) {
17961806 "^dummy" ,
17971807 "^lo" ,
17981808 "^p\\ d+p\\ d+" ,
1799- "^vni"
1809+ "^vni" ,
1810+ "^enc"
18001811 };
18011812
18021813 /**
@@ -2642,12 +2653,15 @@ protected DevicesDef createDevicesDef(VirtualMachineTO vmTO, GuestDef guest, int
26422653 }
26432654
26442655 devices .addDevice (createChannelDef (vmTO ));
2645- devices .addDevice (createWatchDogDef ());
2656+ if (!isGuestS390x ()) {
2657+ devices .addDevice (createWatchDogDef ());
2658+ }
26462659 devices .addDevice (createVideoDef (vmTO ));
26472660 devices .addDevice (createConsoleDef ());
26482661 devices .addDevice (createGraphicDef (vmTO ));
2649- devices .addDevice (createTabletInputDef ());
2650-
2662+ if (!isGuestS390x ()) {
2663+ devices .addDevice (createTabletInputDef ());
2664+ }
26512665 if (isGuestAarch64 ()) {
26522666 createArm64UsbDef (devices );
26532667 }
@@ -2765,7 +2779,9 @@ protected FeaturesDef createFeaturesDef(Map<String, String> customParams, boolea
27652779 FeaturesDef features = new FeaturesDef ();
27662780 features .addFeatures (PAE );
27672781 features .addFeatures (APIC );
2768- features .addFeatures (ACPI );
2782+ if (!isHostS390x ()) {
2783+ features .addFeatures (ACPI );
2784+ }
27692785 if (isUefiEnabled && isSecureBoot ) {
27702786 features .addFeatures (SMM );
27712787 }
@@ -2857,6 +2873,10 @@ private boolean isGuestAarch64() {
28572873 return AARCH64 .equals (guestCpuArch );
28582874 }
28592875
2876+ private boolean isGuestS390x () {
2877+ return S390X .equals (guestCpuArch );
2878+ }
2879+
28602880 /**
28612881 * Creates a guest definition from a VM specification.
28622882 */
@@ -2867,7 +2887,7 @@ protected GuestDef createGuestFromSpec(VirtualMachineTO vmTO, LibvirtVMDef vm, S
28672887 guest .setManufacturer (vmTO .getMetadataManufacturer ());
28682888 guest .setProduct (vmTO .getMetadataProductName ());
28692889 guest .setGuestArch (guestCpuArch != null ? guestCpuArch : vmTO .getArch ());
2870- guest .setMachineType (isGuestAarch64 () ? VIRT : PC );
2890+ guest .setMachineType (( isGuestAarch64 () || isGuestS390x () ) ? VIRT : PC );
28712891 guest .setBootType (GuestDef .BootType .BIOS );
28722892 if (MapUtils .isNotEmpty (customParams )) {
28732893 if (customParams .containsKey (GuestDef .BootType .UEFI .toString ())) {
@@ -2881,7 +2901,9 @@ protected GuestDef createGuestFromSpec(VirtualMachineTO vmTO, LibvirtVMDef vm, S
28812901 guest .setIothreads (customParams .containsKey (VmDetailConstants .IOTHREADS ));
28822902 }
28832903 guest .setUuid (uuid );
2884- guest .setBootOrder (GuestDef .BootOrder .CDROM );
2904+ if (!isGuestS390x ()) {
2905+ guest .setBootOrder (GuestDef .BootOrder .CDROM );
2906+ }
28852907 guest .setBootOrder (GuestDef .BootOrder .HARDISK );
28862908 return guest ;
28872909 }
@@ -3122,7 +3144,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
31223144 final DiskDef .DiskType diskType = getDiskType (physicalDisk );
31233145 disk .defISODisk (volPath , devId , isUefiEnabled , diskType );
31243146
3125- if (guestCpuArch != null && guestCpuArch .equals ("aarch64" )) {
3147+ if (guestCpuArch != null && ( guestCpuArch .equals ("aarch64" ) || guestCpuArch . equals ( "s390x" ) )) {
31263148 disk .setBusType (DiskDef .DiskBus .SCSI );
31273149 }
31283150 } else {
@@ -3220,7 +3242,7 @@ public int compare(final DiskTO arg0, final DiskTO arg1) {
32203242 if (vmSpec .getType () != VirtualMachine .Type .User ) {
32213243 final DiskDef iso = new DiskDef ();
32223244 iso .defISODisk (sysvmISOPath , DiskDef .DiskType .FILE );
3223- if (guestCpuArch != null && guestCpuArch .equals ("aarch64" )) {
3245+ if (guestCpuArch != null && ( guestCpuArch .equals ("aarch64" ) || guestCpuArch . equals ( "s390x" ) )) {
32243246 iso .setBusType (DiskDef .DiskBus .SCSI );
32253247 }
32263248 vm .getDevices ().addDevice (iso );
@@ -4294,7 +4316,7 @@ private DiskDef.DiskBus getGuestDiskModel(final String platformEmulator, boolean
42944316 return DiskDef .DiskBus .VIRTIO ;
42954317 } else if (isUefiEnabled && StringUtils .startsWithAny (platformEmulator , "Windows" , "Other" )) {
42964318 return DiskDef .DiskBus .SATA ;
4297- } else if (guestCpuArch != null && guestCpuArch .equals ("aarch64" )) {
4319+ } else if (guestCpuArch != null && ( guestCpuArch .equals ("aarch64" ) || guestCpuArch . equals ( "s390x" ) )) {
42984320 return DiskDef .DiskBus .SCSI ;
42994321 } else {
43004322 return DiskDef .DiskBus .IDE ;
0 commit comments