df98bb
From 48dacf8d30cd61b72939e9c3419acced4b2fde74 Mon Sep 17 00:00:00 2001
df98bb
From: Michal Suchanek <msuchanek@suse.de>
df98bb
Date: Fri, 2 Oct 2020 11:05:23 +0200
df98bb
Subject: [PATCH] basic/virt: Detect PowerVM hypervisor
df98bb
df98bb
Currently systemd-detect-virt fails to detect running under PowerVM.
df98bb
df98bb
Add code to detect PowerVM based on code in util-linux.
df98bb
df98bb
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
df98bb
(cherry picked from commit 3224e38bb6b3287ca253cbafb460a150544d5818)
df98bb
df98bb
Resolves: #1937989
df98bb
---
df98bb
 man/systemd-detect-virt.xml | 7 ++++++-
df98bb
 src/basic/virt.c            | 6 ++++++
df98bb
 src/basic/virt.h            | 1 +
df98bb
 3 files changed, 13 insertions(+), 1 deletion(-)
df98bb
df98bb
diff --git a/man/systemd-detect-virt.xml b/man/systemd-detect-virt.xml
df98bb
index c4763fd561..6beb2c2aa1 100644
df98bb
--- a/man/systemd-detect-virt.xml
df98bb
+++ b/man/systemd-detect-virt.xml
df98bb
@@ -65,7 +65,7 @@
df98bb
         
df98bb
         
df98bb
           <row>
df98bb
-            <entry valign="top" morerows="11">VM</entry>
df98bb
+            <entry valign="top" morerows="12">VM</entry>
df98bb
             <entry><varname>qemu</varname></entry>
df98bb
             <entry>QEMU software virtualization, without KVM</entry>
df98bb
           </row>
df98bb
@@ -95,6 +95,11 @@
df98bb
             <entry>Oracle VM VirtualBox (historically marketed by innotek and Sun Microsystems), for legacy and KVM hypervisor</entry>
df98bb
           </row>
df98bb
 
df98bb
+          <row>
df98bb
+            <entry><varname>powervm</varname></entry>
df98bb
+            <entry>IBM PowerVM hypervisor - comes as firmware with some IBM POWER servers</entry>
df98bb
+          </row>
df98bb
+
df98bb
           <row>
df98bb
             <entry><varname>xen</varname></entry>
df98bb
             <entry>Xen hypervisor (only domU, not dom0)</entry>
df98bb
diff --git a/src/basic/virt.c b/src/basic/virt.c
df98bb
index dfa1525219..0b88005ed6 100644
df98bb
--- a/src/basic/virt.c
df98bb
+++ b/src/basic/virt.c
df98bb
@@ -92,6 +92,11 @@ static int detect_vm_device_tree(void) {
df98bb
                 _cleanup_closedir_ DIR *dir = NULL;
df98bb
                 struct dirent *dent;
df98bb
 
df98bb
+                if (access("/proc/device-tree/ibm,partition-name", F_OK) == 0 &&
df98bb
+                    access("/proc/device-tree/hmc-managed?", F_OK) == 0 &&
df98bb
+                    access("/proc/device-tree/chosen/qemu,graphic-width", F_OK) != 0)
df98bb
+                        return VIRTUALIZATION_POWERVM;
df98bb
+
df98bb
                 dir = opendir("/proc/device-tree");
df98bb
                 if (!dir) {
df98bb
                         if (errno == ENOENT) {
df98bb
@@ -635,6 +640,7 @@ static const char *const virtualization_table[_VIRTUALIZATION_MAX] = {
df98bb
         [VIRTUALIZATION_PARALLELS] = "parallels",
df98bb
         [VIRTUALIZATION_BHYVE] = "bhyve",
df98bb
         [VIRTUALIZATION_QNX] = "qnx",
df98bb
+        [VIRTUALIZATION_POWERVM] = "powervm",
df98bb
         [VIRTUALIZATION_VM_OTHER] = "vm-other",
df98bb
 
df98bb
         [VIRTUALIZATION_SYSTEMD_NSPAWN] = "systemd-nspawn",
df98bb
diff --git a/src/basic/virt.h b/src/basic/virt.h
df98bb
index c4cf4bfeab..640b3ed779 100644
df98bb
--- a/src/basic/virt.h
df98bb
+++ b/src/basic/virt.h
df98bb
@@ -21,6 +21,7 @@ enum {
df98bb
         VIRTUALIZATION_PARALLELS,
df98bb
         VIRTUALIZATION_BHYVE,
df98bb
         VIRTUALIZATION_QNX,
df98bb
+        VIRTUALIZATION_POWERVM,
df98bb
         VIRTUALIZATION_VM_OTHER,
df98bb
         VIRTUALIZATION_VM_LAST = VIRTUALIZATION_VM_OTHER,
df98bb