[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] libxl: load on FreeBSD



The libxl tries to check if it's running in dom0 by parsing
/proc/xen/capabilities and if that fails it doesn't load.

There's no procfs interface in Xen on FreeBSD, so this check always
fails.

Instead of using procfs, check if /dev/xen/xenstored, that's enough to
check if we're running in dom0 in FreeBSD case.

--

The 'HYPERVISOR_CAPABILITIES' name could be misleading now, however, I'd
prefer to use a common variable to avoid duplicating of the file checking
code. Maybe it should be renamed to something like HYPERVISOR_CONTROL?
---
 src/libxl/libxl_driver.c | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 12be816..c848210 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -73,7 +73,11 @@ VIR_LOG_INIT("libxl.libxl_driver");
 #define LIBXL_CONFIG_FORMAT_XM "xen-xm"
 #define LIBXL_CONFIG_FORMAT_SEXPR "xen-sxpr"
 
-#define HYPERVISOR_CAPABILITIES "/proc/xen/capabilities"
+#ifdef __FreeBSD__
+# define HYPERVISOR_CAPABILITIES "/dev/xen/xenstored"
+#else
+# define HYPERVISOR_CAPABILITIES "/proc/xen/capabilities"
+#endif
 
 /* Number of Xen scheduler parameters */
 #define XEN_SCHED_CREDIT_NPARAM   2
@@ -427,8 +431,6 @@ static bool
 libxlDriverShouldLoad(bool privileged)
 {
     bool ret = false;
-    int status;
-    char *output = NULL;
 
     /* Don't load if non-root */
     if (!privileged) {
@@ -441,21 +443,28 @@ libxlDriverShouldLoad(bool privileged)
                  " does not exist");
         return ret;
     }
-    /*
-     * Don't load if not running on a Xen control domain (dom0). It is not
-     * sufficient to check for the file to exist as any guest can mount
-     * xenfs to /proc/xen.
-     */
-    status = virFileReadAll(HYPERVISOR_CAPABILITIES, 10, &output);
-    if (status >= 0)
-        status = strncmp(output, "control_d", 9);
-    VIR_FREE(output);
-    if (status) {
-        VIR_INFO("No Xen capabilities detected, probably not running "
-                 "in a Xen Dom0.  Disabling libxenlight driver");
+#if !defined(__FreeBSD__)
+    {
+        int status;
+        char *output = NULL;
 
-        return ret;
+        /*
+         * Don't load if not running on a Xen control domain (dom0). It is not
+         * sufficient to check for the file to exist as any guest can mount
+         * xenfs to /proc/xen.
+         */
+        status = virFileReadAll(HYPERVISOR_CAPABILITIES, 10, &output);
+        if (status >= 0)
+            status = strncmp(output, "control_d", 9);
+        VIR_FREE(output);
+        if (status) {
+            VIR_INFO("No Xen capabilities detected, probably not running "
+                     "in a Xen Dom0.  Disabling libxenlight driver");
+
+            return ret;
+        }
     }
+#endif
 
     /* Don't load if legacy xen toolstack (xend) is in use */
     if (virFileExists("/usr/sbin/xend")) {
-- 
2.3.7


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]