biosdevname/biosdevname-dom0.patch

55 lines
1.4 KiB
Diff

---
src/bios_dev_name.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
Index: biosdevname-0.7.3/src/bios_dev_name.c
===================================================================
--- biosdevname-0.7.3.orig/src/bios_dev_name.c
+++ biosdevname-0.7.3/src/bios_dev_name.c
@@ -133,6 +133,33 @@ cpuid (u_int32_t eax, u_int32_t ecx)
}
/*
+ Starting with xen-4.7 cpuid will return with the hypervisor bit set
+ on AMD systems. This breaks biosdevname and network interface names.
+ Instead of relying on cpuid check for dom0 in xenfs.
+*/
+static int
+running_in_dom0(void)
+{
+ size_t len = 0;
+#ifdef __x86_64__
+ char buf[16];
+ FILE *f = fopen("/proc/xen/capabilities", "r");
+
+ if (!f)
+ return 0;
+ memset(buf, 0, sizeof(buf));
+ len = fread(&buf, 1, sizeof(buf) - 1, f);
+ fclose(f);
+ while(len && --len && len < sizeof(buf)) {
+ if (buf[len] == '\n')
+ buf[len] = '\0';
+ }
+ len = strcmp("control_d", buf) == 0;
+#endif
+ return len;
+}
+
+/*
Algorithm suggested by:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1009458
*/
@@ -144,7 +171,11 @@ running_in_virtual_machine (void)
ecx = cpuid (eax, ecx);
if (ecx & 0x80000000U)
+ {
+ if (running_in_dom0())
+ return 0;
return 1;
+ }
return 0;
}