From 3224e38bb6b3287ca253cbafb460a150544d5818 Mon Sep 17 00:00:00 2001 From: Michal Suchanek Date: Fri, 2 Oct 2020 11:05:23 +0200 Subject: [PATCH] basic/virt: Detect PowerVM hypervisor Currently systemd-detect-virt fails to detect running under PowerVM. Add code to detect PowerVM based on code in util-linux. Signed-off-by: Michal Suchanek --- man/systemd-detect-virt.xml | 7 ++++++- man/systemd.unit.xml | 1 + src/basic/virt.c | 6 ++++++ src/basic/virt.h | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/man/systemd-detect-virt.xml b/man/systemd-detect-virt.xml index 9c66fa7afa..36c4602d69 100644 --- a/man/systemd-detect-virt.xml +++ b/man/systemd-detect-virt.xml @@ -62,7 +62,7 @@ - VM + VM qemu QEMU software virtualization, without KVM @@ -92,6 +92,11 @@ Oracle VM VirtualBox (historically marketed by innotek and Sun Microsystems), for legacy and KVM hypervisor + + powervm + IBM PowerVM hypervisor - comes as firmware with some IBM POWER servers + + xen Xen hypervisor (only domU, not dom0) diff --git a/man/systemd.unit.xml b/man/systemd.unit.xml index 1ab6e2b0b9..a845bc23b2 100644 --- a/man/systemd.unit.xml +++ b/man/systemd.unit.xml @@ -1160,6 +1160,7 @@ vmware, microsoft, oracle, + powervm, xen, bochs, uml, diff --git a/src/basic/virt.c b/src/basic/virt.c index 80128cb3aa..bb908847f5 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -93,6 +93,11 @@ static int detect_vm_device_tree(void) { _cleanup_closedir_ DIR *dir = NULL; struct dirent *dent; + if (access("/proc/device-tree/ibm,partition-name", F_OK) == 0 && + access("/proc/device-tree/hmc-managed?", F_OK) == 0 && + access("/proc/device-tree/chosen/qemu,graphic-width", F_OK) != 0) + return VIRTUALIZATION_POWERVM; + dir = opendir("/proc/device-tree"); if (!dir) { if (errno == ENOENT) { @@ -679,6 +684,7 @@ static const char *const virtualization_table[_VIRTUALIZATION_MAX] = { [VIRTUALIZATION_BHYVE] = "bhyve", [VIRTUALIZATION_QNX] = "qnx", [VIRTUALIZATION_ACRN] = "acrn", + [VIRTUALIZATION_POWERVM] = "powervm", [VIRTUALIZATION_VM_OTHER] = "vm-other", [VIRTUALIZATION_SYSTEMD_NSPAWN] = "systemd-nspawn", diff --git a/src/basic/virt.h b/src/basic/virt.h index 18aa5eff15..2f7f7203d2 100644 --- a/src/basic/virt.h +++ b/src/basic/virt.h @@ -22,6 +22,7 @@ enum { VIRTUALIZATION_BHYVE, VIRTUALIZATION_QNX, VIRTUALIZATION_ACRN, + VIRTUALIZATION_POWERVM, VIRTUALIZATION_VM_OTHER, VIRTUALIZATION_VM_LAST = VIRTUALIZATION_VM_OTHER,