]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: Bugfix Detect XEN Dom0 as no virtualization 2639/head
authorStefan Schallenberg aka nafets227 <infos@nafets.de>
Tue, 16 Feb 2016 20:36:12 +0000 (21:36 +0100)
committerStefan Schallenberg aka nafets227 <infos@nafets.de>
Tue, 23 Feb 2016 21:32:16 +0000 (22:32 +0100)
When running in XEN Dom0 the virtualization check:
1) detect_xen returns HYPERVISOR_NONE so next checks are executed
2) /proc/sys/hypervisor detects a XEN hypervisor
   it is lacking the special Dom0 detection as in detect_xen

With this patch, at the end of all virtualization checks we double-check if running in XEN Dom0 or DomU.

src/basic/virt.c

index 8d25a7d2f4a31e1baa9a8bf116f25fdf804b66ec..e6c5a095a04205847f6a81f1fde48db34f1e2075 100644 (file)
@@ -210,6 +210,19 @@ static int detect_vm_dmi(void) {
 }
 
 static int detect_vm_xen(void) {
+        /* Check for Dom0 will be executed later in detect_vm_xen_dom0
+           Thats why we dont check the content of /proc/xen/capabilities here. */
+        if (access("/proc/xen/capabilities", F_OK) < 0) {
+                log_debug("Virtualization XEN not found, /proc/xen/capabilities does not exist");
+                return VIRTUALIZATION_NONE;
+        }
+
+        log_debug("Virtualization XEN found (/proc/xen/capabilities exists)");
+        return  VIRTUALIZATION_XEN;
+
+}
+
+static bool detect_vm_xen_dom0(void) {
         _cleanup_free_ char *domcap = NULL;
         char *cap, *i;
         int r;
@@ -217,7 +230,7 @@ static int detect_vm_xen(void) {
         r = read_one_line_file("/proc/xen/capabilities", &domcap);
         if (r == -ENOENT) {
                 log_debug("Virtualization XEN not found, /proc/xen/capabilities does not exist");
-                return VIRTUALIZATION_NONE;
+                return false;
         }
         if (r < 0)
                 return r;
@@ -226,14 +239,13 @@ static int detect_vm_xen(void) {
         while ((cap = strsep(&i, ",")))
                 if (streq(cap, "control_d"))
                         break;
-
         if (!cap) {
                 log_debug("Virtualization XEN DomU found (/proc/xen/capabilites)");
-                return VIRTUALIZATION_XEN;
+                return false;
         }
 
         log_debug("Virtualization XEN Dom0 ignored (/proc/xen/capabilities)");
-        return VIRTUALIZATION_NONE;
+        return true;
 }
 
 static int detect_vm_hypervisor(void) {
@@ -358,6 +370,12 @@ int detect_vm(void) {
                 return r;
 
 finish:
+        /* x86 xen Dom0 is detected as XEN in hypervisor and maybe others.
+         * In order to detect the Dom0 as not virtualization we need to
+         * double-check it */
+        if (r == VIRTUALIZATION_XEN && detect_vm_xen_dom0())
+                r = VIRTUALIZATION_NONE;
+
         cached_found = r;
         log_debug("Found VM virtualization %s", virtualization_to_string(r));
         return r;