Re: [PATCH] libxl: load on FreeBSD

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

 



On Sat, May 23, 2015 at 09:15:08PM +0300, Roman Bogorodskiy wrote:
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?

You can just add new one, XENSTORED for example, and check whether at
least one exists, reading the file afterwards if it is the old one.
It might not be FreeBSD-specific.  What's your opinion?

---
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__)

if you're using ifdef upwards, then ifndef would look better here.
But that's just the tiniest thing ever.

+    {
+        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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]