virt: use /proc/xen as indicator for a Xen domain (#6442, #6662) (#7555)

The file /proc/xen/capabilities is only available if xenfs is mounted.

With a classic xenlinux based kernel that file is available
unconditionally. But with a modern pvops based kernel, xenfs must be
mounted before the "capabilities" may appear. xenfs is mounted very late
via .services files provided by the Xen toolstack. Other units may be
scheduled before xenfs is mounted, which will confuse the detection of
VIRTUALIZATION_XEN.

In all Xen enabled kernels, and if that kernel is actually running on
the Xen hypervisor, the "/proc/xen" directory is the reliable indicator
that this instance runs in a "Xen guest".

Adjust the code to check for /proc/xen instead of
/proc/xen/capabilities.

Fixes commit 3f61278b5 ("basic: Bugfix Detect XEN Dom0 as no virtualization")
This commit is contained in:
Olaf Hering 2017-12-06 19:59:30 +01:00 committed by Lennart Poettering
parent c7a54cd67b
commit 87dc723ae0
1 changed files with 8 additions and 9 deletions

View File

@ -219,13 +219,13 @@ 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");
The presence of /proc/xen indicates some form of a Xen domain */
if (access("/proc/xen", F_OK) < 0) {
log_debug("Virtualization XEN not found, /proc/xen does not exist");
return VIRTUALIZATION_NONE;
}
log_debug("Virtualization XEN found (/proc/xen/capabilities exists)");
log_debug("Virtualization XEN found (/proc/xen exists)");
return VIRTUALIZATION_XEN;
}
@ -357,11 +357,10 @@ int detect_vm(void) {
}
/* x86 xen will most likely be detected by cpuid. If not (most likely
* because we're not an x86 guest), then we should try the xen capabilities
* file next. If that's not found, then we check for the high-level
* hypervisor sysfs file:
*
* https://bugs.freedesktop.org/show_bug.cgi?id=77271 */
* because we're not an x86 guest), then we should try the /proc/xen
* directory next. If that's not found, then we check for the high-level
* hypervisor sysfs file.
*/
r = detect_vm_xen();
if (r < 0)