libxl: call hotplug scripts from xl for NetBSD
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 1 Aug 2012 11:46:47 +0000 (12:46 +0100)
committerRoger Pau Monne <roger.pau@citrix.com>
Wed, 1 Aug 2012 11:46:47 +0000 (12:46 +0100)
Add the missing NetBSD functions to call hotplug scripts, and disable
xenbackendd if libxl/disable_udev is not set.

Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Christoph Egger <Christoph.Egger@amd.com>
Committed-by: Ian Campbell <ian.campbell@citrix.com>
tools/libxl/libxl_netbsd.c
tools/xenbackendd/xenbackendd.c

index 28cdf21d73d39daada558bf60825ba0a64d18cec..95878334521cefd1d9662d69a7b8b8c403b85224 100644 (file)
@@ -32,10 +32,65 @@ char *libxl__devid_to_localdev(libxl__gc *gc, int devid)
 }
 
 /* Hotplug scripts caller functions */
+static int libxl__hotplug(libxl__gc *gc, libxl__device *dev, char ***args,
+                          libxl__device_action action)
+{
+    char *be_path = libxl__device_backend_path(gc, dev);
+    char *script;
+    int nr = 0, rc = 0, arraysize = 4;
+
+    script = libxl__xs_read(gc, XBT_NULL,
+                            GCSPRINTF("%s/%s", be_path, "script"));
+    if (!script) {
+        LOGEV(ERROR, errno, "unable to read script from %s", be_path);
+        rc = ERROR_FAIL;
+        goto out;
+    }
+
+    GCNEW_ARRAY(*args, arraysize);
+    (*args)[nr++] = script;
+    (*args)[nr++] = be_path;
+    (*args)[nr++] = GCSPRINTF("%d", action == DEVICE_CONNECT ?
+                                    XenbusStateInitWait : XenbusStateClosed);
+    (*args)[nr++] = NULL;
+    assert(nr == arraysize);
+
+out:
+    return rc;
+}
+
 int libxl__get_hotplug_script_info(libxl__gc *gc, libxl__device *dev,
                                    char ***args, char ***env,
                                    libxl__device_action action,
                                    int num_exec)
 {
-    return 0;
+    char *disable_udev = libxl__xs_read(gc, XBT_NULL, DISABLE_UDEV_PATH);
+    int rc;
+
+    /* Check if we have to run hotplug scripts */
+    if (!disable_udev || num_exec > 0) {
+        rc = 0;
+        goto out;
+    }
+
+    switch (dev->backend_kind) {
+    case LIBXL__DEVICE_KIND_VBD:
+    case LIBXL__DEVICE_KIND_VIF:
+        if (num_exec != 0) {
+            rc = 0;
+            goto out;
+        }
+        rc = libxl__hotplug(gc, dev, args, action);
+        if (!rc) rc = 1;
+        break;
+    default:
+        /* If no need to execute any hotplug scripts,
+         * call the callback manually
+         */
+        rc = 0;
+        break;
+    }
+
+out:
+    return rc;
 }
index 6b5bb8e75d41ca0ca375974b01565480e8178ea1..5381a2adefaaa53ff63f7fb60de32a21b7c16d59 100644 (file)
@@ -33,6 +33,7 @@
 #define DEVTYPE_UNKNOWN 0
 #define DEVTYPE_VIF 1
 #define DEVTYPE_VBD 2
+#define DISABLE_EXEC "libxl/disable_udev"
 
 #define DOMAIN_PATH "/local/domain/0"
 
@@ -149,7 +150,7 @@ main(int argc, char * const argv[])
        unsigned int num;
        char *s;
        int state;
-       char *sstate;
+       char *sstate, *sdisable;
        char *p;
        char buf[80];
        int type;
@@ -245,6 +246,10 @@ main(int argc, char * const argv[])
                        continue;
                }
 
+               sdisable = xs_read(xs, XBT_NULL, DISABLE_EXEC, 0);
+               if (sdisable)
+                       goto next1;
+
                if (strlen(vec[XS_WATCH_PATH]) < sizeof("state"))
                        goto next1;
 
@@ -314,6 +319,7 @@ next2:
                free(sstate);
 
 next1:
+               free(sdisable);
                free(vec);
        }