Skip to contentSkip to conversation

execute hotplug scripts from libxl

PATCH Superseded Roger Pau Monne 3 participants 35 messages May 16, 2012 – Jun 11, 2012 Arm/actions semi architecture

v1 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

cover execute hotplug scripts from libxl

This series have been splitted in several patches, to make them easier to review. Also the amount of changes introduced is quite important, since apart from all the hotplug necessary functions and modifications, libxl_domain_destroy has been converted to an async op. This was necessary in order to have async operations during device removal.

Also, as an important change, disk and nics are added at different points for HVM and device model based guests, since we need the disk in order to start Qemu, but the nic hotplug scripts should be called at a later point, when Qemu has created the corresponding tap device.

[PATCH 01/13] libxl: pass env vars to libxl__exec [PATCH 02/13] libxl: fix libxl__xs_directory usage of transaction [PATCH 03/13] libxl: add libxl__xs_path_cleanup
[PATCH 04/13] libxl: move libxl_device_disk_add to libxl_device [PATCH 05/13] libxl: move libxl_device_nic_add to libxl_device [PATCH 06/13] libxl: cleanup libxl__device_{disk,nic}_add [PATCH 10/13] libxl: add option to choose who executes hotplug [PATCH 11/13] libxl: set nic type to VIF by default

All the changes above are bug fixes, code motion or helper functions, that will be used by the other patches in the list.

[PATCH 07/13] libxl: convert libxl_domain_destroy to an AO op [PATCH 08/13] libxl: convert libxl_device_disk_add to an async [PATCH 09/13] libxl: convert libxl_device_nic_add to an async [PATCH 12/13] libxl: call hotplug scripts for disk devices from [PATCH 13/13] libxl: call hotplug scripts for nic devices from libxl

This patches contain the meat, specially 07/13. The other ones become quite trivial once 07/13 is applied.

#1 lore raw

PATCH 1/13 libxl: pass env vars to libxl__exec

Add another parameter to libxl__exec call that contains the environment variables to use when performing the execvp call.

Changes since v4:

* Unify error checking.

Changes since v3:

* Use CTX instead of defining libxl_ctx *ctx.

* Error checking on setenv.

* Better comment on header for libxl__exec function.

* Added some const-correctness.

---
 tools/libxl/libxl.c            |    2 +-
 tools/libxl/libxl_bootloader.c |    4 ++--
 tools/libxl/libxl_dm.c         |    2 +-
 tools/libxl/libxl_exec.c       |   14 ++++++++++++--
 tools/libxl/libxl_internal.h   |   20 ++++++++++++++++++--
 5 files changed, 34 insertions(+), 8 deletions(-)
tools/libxl/libxl.c +1 -1
index 4d01cf8..2a09192 100644
@@ -1261,7 +1261,7 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)
         args[2] = "-autopass";
     }
 
-    libxl__exec(autopass_fd, -1, -1, args[0], args);
+    libxl__exec(gc, autopass_fd, -1, -1, args[0], args, NULL);
     abort();
 
  x_fail:
tools/libxl/libxl_bootloader.c +2 -2
index fb1302b..0021a7b 100644
@@ -359,6 +359,7 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
     libxl__bootloader_state *bl = CONTAINER_OF(op, *bl, openpty);
     STATE_AO_GC(bl->ao);
     int rc, r;
+    char *const env[] = { "TERM", "vt100", NULL };
 
     if (bl->openpty.rc) {
         rc = bl->openpty.rc;
@@ -452,8 +453,7 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op)
         /* child */
         r = login_tty(libxl__carefd_fd(bl->ptys[0].slave));
         if (r) { LOGE(ERROR, "login_tty failed"); exit(-1); }
-        setenv("TERM", "vt100", 1);
-        libxl__exec(-1, -1, -1, bl->args[0], (char**)bl->args);
+        libxl__exec(gc, -1, -1, -1, bl->args[0], (char **) bl->args, env);
         exit(-1);
     }
 
tools/libxl/libxl_dm.c +1 -1
index 4ad7d02..95fd0ac 100644
@@ -1015,7 +1015,7 @@ retry_transaction:
         goto out_close;
     if (!rc) { /* inner child */
         setsid();
-        libxl__exec(null, logfile_w, logfile_w, dm, args);
+        libxl__exec(gc, null, logfile_w, logfile_w, dm, args, NULL);
     }
 
     rc = 0;
tools/libxl/libxl_exec.c +12 -2
index b46b893..082bf44 100644
@@ -66,8 +66,8 @@ static void check_open_fds(const char *what)
     if (badness) abort();
 }
 
-void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0,
-                char **args)
+void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd, int stderrfd,
+                 const char *arg0, char *const args[], char *const env[])
      /* call this in the child */
 {
     if (stdinfd != -1)
@@ -90,8 +90,18 @@ void libxl__exec(int stdinfd, int stdoutfd, int stderrfd, const char *arg0,
     /* in case our caller set it to IGN.  subprocesses are entitled
      * to assume they got DFL. */
 
+    if (env != NULL) {
+        for (int i = 0; env[i] != NULL && env[i+1] != NULL; i += 2) {
+            if (setenv(env[i], env[i+1], 1) < 0) {
+                LOGEV(ERROR, errno, "setting env vars (%s = %s)",
+                                    env[i], env[i+1]);
+                goto out;
+            }
+        }
+    }
     execvp(arg0, args);
 
+out:
     fprintf(stderr, "libxl: cannot execute %s: %s\n", arg0, strerror(errno));
     _exit(-1);
 }
tools/libxl/libxl_internal.h +18 -2
index f71e76a..aaaf644 100644
@@ -1138,8 +1138,24 @@ _hidden int libxl__wait_for_offspring(libxl__gc *gc,
 
  /* low-level stuff, for synchronous subprocesses etc. */
 
-_hidden void libxl__exec(int stdinfd, int stdoutfd, int stderrfd,
-               const char *arg0, char **args); // logs errors, never returns
+/*
+ * env should be passed using the following format,
+ *
+ * env[0]: name of env variable
+ * env[1]: value of env variable
+ * env[n]: ...
+ *
+ * So it efectively becomes something like:
+ * export env[n]=env[n+1]
+ * (where n%2 = 0)
+ *
+ * The last entry of the array always has to be NULL.
+ *
+ * Logs errors, never returns.
+ */
+_hidden  void libxl__exec(libxl__gc *gc, int stdinfd, int stdoutfd,
+                          int stderrfd, const char *arg0, char *const args[],
+                          char *const env[]);
 
 /* from xl_create */
 
Signature · 1 line
1.7.7.5 (Apple Git-26)
Acked-by on v1 1/13
#2 lore raw

Re: [PATCH 01/13] libxl: pass env vars to libxl__exec

Roger Pau Monne writes ("[PATCH 01/13] libxl: pass env vars to libxl__exec"):

Quoted 2 lines

Add another parameter to libxl__exec call that contains the environment variables to use when performing the execvp call.

#3 lore raw

PATCH 2/13 libxl: fix libxl__xs_directory usage of transaction

In reply to Roger Pau Monne

libxl__xs_directory takes a transaction parameter, but completely ignores it, passing XBT_NULL unconditionally to xs_directory.

---
 tools/libxl/libxl_xshelp.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/libxl/libxl_xshelp.c +1 -1
index 3ea8d08..6ca1afe 100644
@@ -111,7 +111,7 @@ char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t,
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     char **ret = NULL;
-    ret = xs_directory(ctx->xsh, XBT_NULL, path, nb);
+    ret = xs_directory(ctx->xsh, t, path, nb);
     libxl__ptr_add(gc, ret);
     return ret;
 }
Signature · 1 line
1.7.7.5 (Apple Git-26)
Acked-by on v1 2/13
#4 lore raw

Re: [PATCH 02/13] libxl: fix libxl__xs_directory usage of transaction

Roger Pau Monne writes ("[PATCH 02/13] libxl: fix libxl__xs_directory usage of transaction"):

Quoted 2 lines

libxl__xs_directory takes a transaction parameter, but completely ignores it, passing XBT_NULL unconditionally to xs_directory.

#5 lore raw

PATCH 3/13 libxl: add libxl__xs_path_cleanup

In reply to Roger Pau Monne

Add a function which behaves like "xenstore-rm -t", and which will be used to clean xenstore after unplug since we will be no longer executing xen-hotplug-cleanup script, that used to do that for us.

Changes since v4:

* Caller must supply a transaction.

Changes since v3:

* Better error checking and function description.

Changes since v2:

* Moved the function to libxl_xshelp.c and added the prototype to libxl_internal.h.

---
 tools/libxl/libxl_internal.h |    8 ++++++++
 tools/libxl/libxl_xshelp.c   |   42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.h +8 -0
index aaaf644..ae5527b 100644
@@ -494,6 +494,14 @@ _hidden bool libxl__xs_mkdir(libxl__gc *gc, xs_transaction_t t,
 
 _hidden char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid);
 
+/*
+ * This is a recursive delete, from top to bottom. What this function does
+ * is remove empty folders that contained the deleted entry.
+ *
+ * It mimics xenstore-rm -t behaviour.
+ */
+_hidden int libxl__xs_path_cleanup(libxl__gc *gc, xs_transaction_t t,
+                                   char *user_path);
 
 /*
  * Event generation functions provided by the libxl event core to the
tools/libxl/libxl_xshelp.c +42 -0

48 lines not on this page · raw message

Signature · 1 line
1.7.7.5 (Apple Git-26)
#6 lore raw

Re: [PATCH 03/13] libxl: add libxl__xs_path_cleanup

Roger Pau Monne writes ("[PATCH 03/13] libxl: add libxl__xs_path_cleanup"):

Quoted 3 lines

Add a function which behaves like "xenstore-rm -t", and which will be used to clean xenstore after unplug since we will be no longer executing xen-hotplug-cleanup script, that used to do that for us.

...

tools/libxl/libxl_xshelp.c char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid) · line 147

Quoted 4 lines
tools/libxl/libxl_xshelp.c +4 -0
+    if (!user_path) {
+        LOGE(ERROR, "null path provided");
+        return ERROR_INVAL;
+    }

What is this for ? Why not just crash ?

tools/libxl/libxl_xshelp.c char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid) · line 151

Quoted 4 lines
tools/libxl/libxl_xshelp.c +4 -0
+    if (!t) {
+        LOGE(ERROR, "null transaction provided");
+        return ERROR_INVAL;
+    }

Likewise why not

       assert(t);

?

Quoted 4 lines
tools/libxl/libxl_xshelp.c +4 -0
+    path = libxl__strdup(gc, user_path);
+    if (!xs_rm(CTX->xsh, t, path)) {
+        rc = ERROR_FAIL;
+        goto out;

...

tools/libxl/libxl_xshelp.c char *libxl__xs_libxl_path(libxl__gc *gc, uint32_t domid) · line 177

Quoted 2 lines
tools/libxl/libxl_xshelp.c +2 -0
+out:
+    return rc;

This has the effect of discarding the errno value if anything fails. Perhaps this function should log on all errors ?

Ian.

#7 lore raw

PATCH 4/13 libxl: move libxl_device_disk_add to libxl_device

In reply to Roger Pau Monne

Move the code of this function to libxl_device.c so it can be made asyncronious later on the series. The static function libxl__device_from_disk also has to be moved to libxl_device and it is no longer static.

The code will be fixed in a latter patch, replacing libxl__sprintf, LIBXL_LOG* and lines > 80.

---
 tools/libxl/libxl.c          |  152 +---------------------------------------
 tools/libxl/libxl_device.c   |  159 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |    5 ++
 3 files changed, 166 insertions(+), 150 deletions(-)
tools/libxl/libxl.c +2 -150
index 2a09192..2d8abd0 100644
@@ -1281,161 +1281,13 @@ int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk)
     return rc;
 }
 
-static int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
-                                   libxl_device_disk *disk,
-                                   libxl__device *device)
-{
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    int devid;
-
-    devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
-    if (devid==-1) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
-               " virtual disk identifier %s", disk->vdev);
-        return ERROR_INVAL;
-    }
-
-    device->backend_domid = disk->backend_domid;
-    device->backend_devid = devid;
-
-    switch (disk->backend) {
-        case LIBXL_DISK_BACKEND_PHY:
-            device->backend_kind = LIBXL__DEVICE_KIND_VBD;
-            break;
-        case LIBXL_DISK_BACKEND_TAP:
-            device->backend_kind = LIBXL__DEVICE_KIND_VBD;
-            break;
-        case LIBXL_DISK_BACKEND_QDISK:
-            device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
-            break;
-        default:
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n",
-                       disk->backend);
-            return ERROR_INVAL;
-    }
-
-    device->domid = domid;
-    device->devid = devid;
-    device->kind  = LIBXL__DEVICE_KIND_VBD;
-
-    return 0;
-}
-
 int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
 {
     GC_INIT(ctx);
-    flexarray_t *front;
-    flexarray_t *back;
-    char *dev;
-    libxl__device device;
-    int major, minor, rc;
-
-    rc = libxl__device_disk_setdefault(gc, disk);
-    if (rc) goto out;
-
-    front = flexarray_make(16, 1);
-    if (!front) {
-        rc = ERROR_NOMEM;
-        goto out;
-    }
-    back = flexarray_make(16, 1);
-    if (!back) {
-        rc = ERROR_NOMEM;
-        goto out_free;
-    }
-
-    if (disk->script) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "External block scripts"
-                   " not yet supported, sorry");
-        rc = ERROR_INVAL;
-        goto out_free;
-    }
-
-    rc = libxl__device_from_disk(gc, domid, disk, &device);
-    if (rc != 0) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
-               " virtual disk identifier %s", disk->vdev);
-        goto out_free;
-    }
-
-    switch (disk->backend) {
-        case LIBXL_DISK_BACKEND_PHY:
-            dev = disk->pdev_path;
-    do_backend_phy:
-            libxl__device_physdisk_major_minor(dev, &major, &minor);
-            flexarray_append(back, "physical-device");
-            flexarray_append(back, libxl__sprintf(gc, "%x:%x", major, minor));
-
-            flexarray_append(back, "params");
-            flexarray_append(back, dev);
-
-            assert(device.backend_kind == LIBXL__DEVICE_KIND_VBD);
-            break;
-        case LIBXL_DISK_BACKEND_TAP:
-            dev = libxl__blktap_devpath(gc, disk->pdev_path, disk->format);
-            if (!dev) {
-                LOG(ERROR, "failed to get blktap devpath for %p\n",
-                    disk->pdev_path);
-                rc = ERROR_FAIL;
-                goto out_free;
-            }
-            flexarray_append(back, "tapdisk-params");
-            flexarray_append(back, libxl__sprintf(gc, "%s:%s",
-                libxl__device_disk_string_of_format(disk->format),
-                disk->pdev_path));
-
-            /* now create a phy device to export the device to the guest */
-            goto do_backend_phy;
-        case LIBXL_DISK_BACKEND_QDISK:
-            flexarray_append(back, "params");
-            flexarray_append(back, libxl__sprintf(gc, "%s:%s",
-                          libxl__device_disk_string_of_format(disk->format), disk->pdev_path));
-            assert(device.backend_kind == LIBXL__DEVICE_KIND_QDISK);
-            break;
-        default:
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n", disk->backend);
-            rc = ERROR_INVAL;
-            goto out_free;
-    }
-
-    flexarray_append(back, "frontend-id");
-    flexarray_append(back, libxl__sprintf(gc, "%d", domid));
-    flexarray_append(back, "online");
-    flexarray_append(back, "1");
-    flexarray_append(back, "removable");
-    flexarray_append(back, libxl__sprintf(gc, "%d", (disk->removable) ? 1 : 0));
-    flexarray_append(back, "bootable");
-    flexarray_append(back, libxl__sprintf(gc, "%d", 1));
-    flexarray_append(back, "state");
-    flexarray_append(back, libxl__sprintf(gc, "%d", 1));
-    flexarray_append(back, "dev");
-    flexarray_append(back, disk->vdev);
-    flexarray_append(back, "type");
-    flexarray_append(back, libxl__device_disk_string_of_backend(disk->backend));
-    flexarray_append(back, "mode");
-    flexarray_append(back, disk->readwrite ? "w" : "r");
-    flexarray_append(back, "device-type");
-    flexarray_append(back, disk->is_cdrom ? "cdrom" : "disk");
-
-    flexarray_append(front, "backend-id");
-    flexarray_append(front, libxl__sprintf(gc, "%d", disk->backend_domid));
-    flexarray_append(front, "state");
-    flexarray_append(front, libxl__sprintf(gc, "%d", 1));
-    flexarray_append(front, "virtual-device");
-    flexarray_append(front, libxl__sprintf(gc, "%d", device.devid));
-    flexarray_append(front, "device-type");
-    flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
-
-    libxl__device_generic_add(gc, &device,
-                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
-                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
+    int rc;
 
-    rc = 0;
+    rc = libxl__device_disk_add(gc, domid, disk);
 
-out_free:
-    flexarray_free(back);
-    flexarray_free(front);
-out:
     GC_FREE;
     return rc;
 }
tools/libxl/libxl_device.c +159 -0

165 lines not on this page · raw message

tools/libxl/libxl_internal.h +5 -0
index ae5527b..87c9366 100644
@@ -780,6 +780,11 @@ _hidden int libxl__domain_pvcontrol_write(libxl__gc *gc, xs_transaction_t t,
 _hidden char *libxl__device_disk_string_of_backend(libxl_disk_backend backend);
 _hidden char *libxl__device_disk_string_of_format(libxl_disk_format format);
 _hidden int libxl__device_disk_set_backend(libxl__gc*, libxl_device_disk*);
+_hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
+                                    libxl_device_disk *disk,
+                                    libxl__device *device);
+_hidden int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
+                                   libxl_device_disk *disk);
 
 _hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor);
 _hidden int libxl__device_disk_dev_number(const char *virtpath,
Signature · 1 line
1.7.7.5 (Apple Git-26)
#8 lore raw

PATCH 5/13 libxl: move libxl_device_nic_add to libxl_device

In reply to Roger Pau Monne

Move the code of this function to libxl_device.c so it can be made asyncronious later on the series. The static function libxl__device_from_nic also has to be moved to libxl_device and it is no longer static.

The code will be fixed in a latter patch, replacing libxl__sprintf, LIBXL_LOG* and lines > 80.

---
 tools/libxl/libxl.c          |  108 +---------------------------------------
 tools/libxl/libxl_device.c   |  113 ++++++++++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_internal.h |    6 ++
 3 files changed, 121 insertions(+), 106 deletions(-)
tools/libxl/libxl.c +2 -106
index 2d8abd0..d3b6a53 100644
@@ -1655,117 +1655,13 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
     return 0;
 }
 
-static int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_nic *nic,
-                                  libxl__device *device)
-{
-    device->backend_devid    = nic->devid;
-    device->backend_domid    = nic->backend_domid;
-    device->backend_kind     = LIBXL__DEVICE_KIND_VIF;
-    device->devid            = nic->devid;
-    device->domid            = domid;
-    device->kind             = LIBXL__DEVICE_KIND_VIF;
-
-    return 0;
-}
-
 int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic)
 {
     GC_INIT(ctx);
-    flexarray_t *front;
-    flexarray_t *back;
-    libxl__device device;
-    char *dompath, **l;
-    unsigned int nb, rc;
-
-    rc = libxl__device_nic_setdefault(gc, nic);
-    if (rc) goto out;
-
-    front = flexarray_make(16, 1);
-    if (!front) {
-        rc = ERROR_NOMEM;
-        goto out;
-    }
-    back = flexarray_make(16, 1);
-    if (!back) {
-        rc = ERROR_NOMEM;
-        goto out_free;
-    }
-
-    if (nic->devid == -1) {
-        if (!(dompath = libxl__xs_get_dompath(gc, domid))) {
-            rc = ERROR_FAIL;
-            goto out_free;
-        }
-        if (!(l = libxl__xs_directory(gc, XBT_NULL,
-                                     libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) {
-            nic->devid = 0;
-        } else {
-            nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
-        }
-    }
-
-    rc = libxl__device_from_nic(gc, domid, nic, &device);
-    if ( rc != 0 ) goto out_free;
-
-    flexarray_append(back, "frontend-id");
-    flexarray_append(back, libxl__sprintf(gc, "%d", domid));
-    flexarray_append(back, "online");
-    flexarray_append(back, "1");
-    flexarray_append(back, "state");
-    flexarray_append(back, libxl__sprintf(gc, "%d", 1));
-    if (nic->script) {
-        flexarray_append(back, "script");
-        flexarray_append(back, nic->script[0]=='/' ? nic->script
-                         : libxl__sprintf(gc, "%s/%s",
-                                          libxl__xen_script_dir_path(),
-                                          nic->script));
-    }
-
-    if (nic->ifname) {
-        flexarray_append(back, "vifname");
-        flexarray_append(back, nic->ifname);
-    }
-
-    flexarray_append(back, "mac");
-    flexarray_append(back,libxl__sprintf(gc,
-                                    LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
-    if (nic->ip) {
-        flexarray_append(back, "ip");
-        flexarray_append(back, libxl__strdup(gc, nic->ip));
-    }
-
-    if (nic->rate_interval_usecs > 0) {
-        flexarray_append(back, "rate");
-        flexarray_append(back, libxl__sprintf(gc, "%"PRIu64",%"PRIu32"",
-                            nic->rate_bytes_per_interval,
-                            nic->rate_interval_usecs));
-    }
-
-    flexarray_append(back, "bridge");
-    flexarray_append(back, libxl__strdup(gc, nic->bridge));
-    flexarray_append(back, "handle");
-    flexarray_append(back, libxl__sprintf(gc, "%d", nic->devid));
+    int rc;
 
-    flexarray_append(front, "backend-id");
-    flexarray_append(front, libxl__sprintf(gc, "%d", nic->backend_domid));
-    flexarray_append(front, "state");
-    flexarray_append(front, libxl__sprintf(gc, "%d", 1));
-    flexarray_append(front, "handle");
-    flexarray_append(front, libxl__sprintf(gc, "%d", nic->devid));
-    flexarray_append(front, "mac");
-    flexarray_append(front, libxl__sprintf(gc,
-                                    LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
-    libxl__device_generic_add(gc, &device,
-                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
-                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
+    rc = libxl__device_nic_add(gc, domid, nic);
 
-    /* FIXME: wait for plug */
-    rc = 0;
-out_free:
-    flexarray_free(back);
-    flexarray_free(front);
-out:
     GC_FREE;
     return rc;
 }
tools/libxl/libxl_device.c +113 -0

119 lines not on this page · raw message

tools/libxl/libxl_internal.h +6 -0
index 87c9366..0ddfe72 100644
@@ -786,6 +786,12 @@ _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
                                    libxl_device_disk *disk);
 
+_hidden int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
+                                   libxl_device_nic *nic,
+                                   libxl__device *device);
+_hidden int libxl__device_nic_add(libxl__gc *gc, uint32_t domid,
+                                  libxl_device_nic *nic);
+
 _hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor);
 _hidden int libxl__device_disk_dev_number(const char *virtpath,
                                           int *pdisk, int *ppartition);
Signature · 1 line
1.7.7.5 (Apple Git-26)
#9 lore raw

PATCH 6/13 libxl: cleanup libxl__device_{disk, nic}_add

In reply to Roger Pau Monne

Change libxl__sprintf for GCSPRINTF, LIBXL__LOG* for LOG and remove use of ctx variable in favour of the CTX constant.

---
 tools/libxl/libxl_device.c |  114 +++++++++++++++++++++-----------------------
 1 files changed, 55 insertions(+), 59 deletions(-)
tools/libxl/libxl_device.c +55 -59
index edc4ad1..1e34135 100644
@@ -253,13 +253,12 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
                             libxl_device_disk *disk,
                             libxl__device *device)
 {
-    libxl_ctx *ctx = libxl__gc_owner(gc);
     int devid;
 
     devid = libxl__device_disk_dev_number(disk->vdev, NULL, NULL);
     if (devid==-1) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
-               " virtual disk identifier %s", disk->vdev);
+        LOG(ERROR, "Invalid or unsupported virtual disk identifier %s",
+                   disk->vdev);
         return ERROR_INVAL;
     }
 
@@ -267,19 +266,18 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
     device->backend_devid = devid;
 
     switch (disk->backend) {
-        case LIBXL_DISK_BACKEND_PHY:
-            device->backend_kind = LIBXL__DEVICE_KIND_VBD;
-            break;
-        case LIBXL_DISK_BACKEND_TAP:
-            device->backend_kind = LIBXL__DEVICE_KIND_VBD;
-            break;
-        case LIBXL_DISK_BACKEND_QDISK:
-            device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
-            break;
-        default:
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n",
-                       disk->backend);
-            return ERROR_INVAL;
+    case LIBXL_DISK_BACKEND_PHY:
+        device->backend_kind = LIBXL__DEVICE_KIND_VBD;
+        break;
+    case LIBXL_DISK_BACKEND_TAP:
+        device->backend_kind = LIBXL__DEVICE_KIND_VBD;
+        break;
+    case LIBXL_DISK_BACKEND_QDISK:
+        device->backend_kind = LIBXL__DEVICE_KIND_QDISK;
+        break;
+    default:
+        LOG(ERROR, "unrecognized disk backend type: %d\n", disk->backend);
+        return ERROR_INVAL;
     }
 
     device->domid = domid;
@@ -292,10 +290,9 @@ int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
 int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
                            libxl_device_disk *disk)
 {
-    libxl_ctx *ctx = CTX;
     flexarray_t *front;
     flexarray_t *back;
-    char *dev;
+    char *dev, *format;
     libxl__device device;
     int major, minor, rc;
 
@@ -314,18 +311,18 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
     }
 
     if (disk->script) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "External block scripts"
-                   " not yet supported, sorry");
+        LOG(ERROR, "External block scripts not yet supported, sorry");
         rc = ERROR_INVAL;
         goto out_free;
     }
 
     rc = libxl__device_from_disk(gc, domid, disk, &device);
     if (rc != 0) {
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported"
-               " virtual disk identifier %s", disk->vdev);
+        LOG(ERROR, "Invalid or unsupported virtual disk identifier %s",
+                   disk->vdev);
         goto out_free;
     }
+    format = libxl__device_disk_string_of_format(disk->format);
 
     switch (disk->backend) {
         case LIBXL_DISK_BACKEND_PHY:
@@ -333,7 +330,7 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
     do_backend_phy:
             libxl__device_physdisk_major_minor(dev, &major, &minor);
             flexarray_append(back, "physical-device");
-            flexarray_append(back, libxl__sprintf(gc, "%x:%x", major, minor));
+            flexarray_append(back, GCSPRINTF("%x:%x", major, minor));
 
             flexarray_append(back, "params");
             flexarray_append(back, dev);
@@ -349,34 +346,31 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
                 goto out_free;
             }
             flexarray_append(back, "tapdisk-params");
-            flexarray_append(back, libxl__sprintf(gc, "%s:%s",
-                libxl__device_disk_string_of_format(disk->format),
-                disk->pdev_path));
+            flexarray_append(back, GCSPRINTF("%s:%s", format, disk->pdev_path));
 
             /* now create a phy device to export the device to the guest */
             goto do_backend_phy;
         case LIBXL_DISK_BACKEND_QDISK:
             flexarray_append(back, "params");
-            flexarray_append(back, libxl__sprintf(gc, "%s:%s",
-                          libxl__device_disk_string_of_format(disk->format), disk->pdev_path));
+            flexarray_append(back, GCSPRINTF("%s:%s", format, disk->pdev_path));
             assert(device.backend_kind == LIBXL__DEVICE_KIND_QDISK);
             break;
         default:
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend type: %d\n", disk->backend);
+            LOG(ERROR, "unrecognized disk backend type: %d\n", disk->backend);
             rc = ERROR_INVAL;
             goto out_free;
     }
 
     flexarray_append(back, "frontend-id");
-    flexarray_append(back, libxl__sprintf(gc, "%d", domid));
+    flexarray_append(back, GCSPRINTF("%d", domid));
     flexarray_append(back, "online");
     flexarray_append(back, "1");
     flexarray_append(back, "removable");
-    flexarray_append(back, libxl__sprintf(gc, "%d", (disk->removable) ? 1 : 0));
+    flexarray_append(back, GCSPRINTF("%d", (disk->removable) ? 1 : 0));
     flexarray_append(back, "bootable");
-    flexarray_append(back, libxl__sprintf(gc, "%d", 1));
+    flexarray_append(back, GCSPRINTF("%d", 1));
     flexarray_append(back, "state");
-    flexarray_append(back, libxl__sprintf(gc, "%d", 1));
+    flexarray_append(back, GCSPRINTF("%d", 1));
     flexarray_append(back, "dev");
     flexarray_append(back, disk->vdev);
     flexarray_append(back, "type");
@@ -387,17 +381,17 @@ int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
     flexarray_append(back, disk->is_cdrom ? "cdrom" : "disk");
 
     flexarray_append(front, "backend-id");
-    flexarray_append(front, libxl__sprintf(gc, "%d", disk->backend_domid));
+    flexarray_append(front, GCSPRINTF("%d", disk->backend_domid));
     flexarray_append(front, "state");
-    flexarray_append(front, libxl__sprintf(gc, "%d", 1));
+    flexarray_append(front, GCSPRINTF("%d", 1));
     flexarray_append(front, "virtual-device");
-    flexarray_append(front, libxl__sprintf(gc, "%d", device.devid));
+    flexarray_append(front, GCSPRINTF("%d", device.devid));
     flexarray_append(front, "device-type");
     flexarray_append(front, disk->is_cdrom ? "cdrom" : "disk");
 
     libxl__device_generic_add(gc, &device,
-                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
-                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
+                        libxl__xs_kvs_of_flexarray(gc, back, back->count),
+                        libxl__xs_kvs_of_flexarray(gc, front, front->count));
 
     rc = 0;
 
@@ -449,8 +443,10 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
             rc = ERROR_FAIL;
             goto out_free;
         }
-        if (!(l = libxl__xs_directory(gc, XBT_NULL,
-                                     libxl__sprintf(gc, "%s/device/vif", dompath), &nb))) {
+        l = libxl__xs_directory(gc, XBT_NULL, GCSPRINTF(
+                                                  "%s/device/vif", dompath),
+                                              &nb);
+        if (!l) {
             nic->devid = 0;
         } else {
             nic->devid = strtoul(l[nb - 1], NULL, 10) + 1;
@@ -461,17 +457,18 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
     if ( rc != 0 ) goto out_free;
 
     flexarray_append(back, "frontend-id");
-    flexarray_append(back, libxl__sprintf(gc, "%d", domid));
+    flexarray_append(back, GCSPRINTF("%d", domid));
     flexarray_append(back, "online");
     flexarray_append(back, "1");
     flexarray_append(back, "state");
-    flexarray_append(back, libxl__sprintf(gc, "%d", 1));
+    flexarray_append(back, GCSPRINTF("%d", 1));
     if (nic->script) {
         flexarray_append(back, "script");
-        flexarray_append(back, nic->script[0]=='/' ? nic->script
-                         : libxl__sprintf(gc, "%s/%s",
-                                          libxl__xen_script_dir_path(),
-                                          nic->script));
+        flexarray_append(back, nic->script[0]=='/' ?
+                                   nic->script :
+                                   GCSPRINTF("%s/%s",
+                                             libxl__xen_script_dir_path(),
+                                             nic->script));
     }
 
     if (nic->ifname) {
@@ -480,8 +477,7 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
     }
 
     flexarray_append(back, "mac");
-    flexarray_append(back,libxl__sprintf(gc,
-                                    LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
+    flexarray_append(back, GCSPRINTF(LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
     if (nic->ip) {
         flexarray_append(back, "ip");
         flexarray_append(back, libxl__strdup(gc, nic->ip));
@@ -489,28 +485,28 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
 
     if (nic->rate_interval_usecs > 0) {
         flexarray_append(back, "rate");
-        flexarray_append(back, libxl__sprintf(gc, "%"PRIu64",%"PRIu32"",
-                            nic->rate_bytes_per_interval,
-                            nic->rate_interval_usecs));
+        flexarray_append(back, GCSPRINTF("%"PRIu64",%"PRIu32"",
+                                         nic->rate_bytes_per_interval,
+                                         nic->rate_interval_usecs));
     }
 
     flexarray_append(back, "bridge");
     flexarray_append(back, libxl__strdup(gc, nic->bridge));
     flexarray_append(back, "handle");
-    flexarray_append(back, libxl__sprintf(gc, "%d", nic->devid));
+    flexarray_append(back, GCSPRINTF("%d", nic->devid));
 
     flexarray_append(front, "backend-id");
-    flexarray_append(front, libxl__sprintf(gc, "%d", nic->backend_domid));
+    flexarray_append(front, GCSPRINTF("%d", nic->backend_domid));
     flexarray_append(front, "state");
-    flexarray_append(front, libxl__sprintf(gc, "%d", 1));
+    flexarray_append(front, GCSPRINTF("%d", 1));
     flexarray_append(front, "handle");
-    flexarray_append(front, libxl__sprintf(gc, "%d", nic->devid));
+    flexarray_append(front, GCSPRINTF("%d", nic->devid));
     flexarray_append(front, "mac");
-    flexarray_append(front, libxl__sprintf(gc,
-                                    LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac)));
+    flexarray_append(front, GCSPRINTF(LIBXL_MAC_FMT,
+                                      LIBXL_MAC_BYTES(nic->mac)));
     libxl__device_generic_add(gc, &device,
-                             libxl__xs_kvs_of_flexarray(gc, back, back->count),
-                             libxl__xs_kvs_of_flexarray(gc, front, front->count));
+                        libxl__xs_kvs_of_flexarray(gc, back, back->count),
+                        libxl__xs_kvs_of_flexarray(gc, front, front->count));
 
     /* FIXME: wait for plug */
     rc = 0;
Signature · 1 line
1.7.7.5 (Apple Git-26)
#10 lore raw

Re: [PATCH 06/13] libxl: cleanup libxl__device_{disk, nic}_add

Roger Pau Monne writes ("[PATCH 06/13] libxl: cleanup libxl__device_{disk,nic}_add"):

Quoted 2 lines

Change libxl__sprintf for GCSPRINTF, LIBXL__LOG* for LOG and remove use of ctx variable in favour of the CTX constant.

Is this necessary to make things fit in subsequent patches ?

In general I approve of this kind of cleanup but I don't think now is the right time to be doing it...

Ian.

#11 lore raw

PATCH 7/13 libxl: convert libxl_domain_destroy to an AO op

In reply to Roger Pau Monne

This change introduces some new structures, and breaks the mutual dependency that libxl_domain_destroy and libxl__destroy_device_model had. This is done by checking if the domid passed to libxl_domain_destroy has a stubdom, and then having the bulk of the destroy machinery in a separate function (libxl__destroy_domid) that doesn't check for stubdom presence, since we check for it in the upper level function. The reason behind this change is the need to use structures for ao operations, and it was impossible to have two different self-referencing structs.

All uses of libxl_domain_destroy have been changed, and either replaced by the new libxl_domain_destroy ao function or by the internal libxl__domain_destroy that can be used inside an already running ao.

---
 tools/libxl/libxl.c               |  180 +++++++++++-----------
 tools/libxl/libxl.h               |    3 +-
 tools/libxl/libxl_create.c        |   30 +++-
 tools/libxl/libxl_device.c        |  308 ++++++++++++++++++++++++++++---------
 tools/libxl/libxl_dm.c            |   83 +++++-----
 tools/libxl/libxl_dom.c           |  170 ++++++++++++++++++++
 tools/libxl/libxl_internal.h      |  224 +++++++++++++++++++++------
 tools/libxl/xl_cmdimpl.c          |   12 +-
 tools/python/xen/lowlevel/xl/xl.c |    2 +-
 9 files changed, 752 insertions(+), 260 deletions(-)
tools/libxl/libxl.c +89 -91
index d3b6a53..dabe92b 100644
@@ -1070,80 +1070,34 @@ void libxl_evdisable_disk_eject(libxl_ctx *ctx, libxl_evgen_disk_eject *evg) {
     GC_FREE;
 }    
 
-int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid)
-{
-    GC_INIT(ctx);
-    char *dom_path;
-    char *vm_path;
-    char *pid;
-    int rc, dm_present;
-
-    rc = libxl_domain_info(ctx, NULL, domid);
-    switch(rc) {
-    case 0:
-        break;
-    case ERROR_INVAL:
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "non-existant domain %d", domid);
-    default:
-        return rc;
-    }
-
-    switch (libxl__domain_type(gc, domid)) {
-    case LIBXL_DOMAIN_TYPE_HVM:
-        dm_present = 1;
-        break;
-    case LIBXL_DOMAIN_TYPE_PV:
-        pid = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "/local/domain/%d/image/device-model-pid", domid));
-        dm_present = (pid != NULL);
-        break;
-    default:
-        abort();
-    }
-
-    dom_path = libxl__xs_get_dompath(gc, domid);
-    if (!dom_path) {
-        rc = ERROR_FAIL;
-        goto out;
-    }
+/* Callback for domain destruction */
 
-    if (libxl__device_pci_destroy_all(gc, domid) < 0)
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "pci shutdown failed for domid %d", domid);
-    rc = xc_domain_pause(ctx->xch, domid);
-    if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_pause failed for %d", domid);
-    }
-    if (dm_present) {
-        if (libxl__destroy_device_model(gc, domid) < 0)
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl__destroy_device_model failed for %d", domid);
+static void domain_destroy_cb(libxl__egc *, libxl__domain_destroy_state *, int);
 
-        libxl__qmp_cleanup(gc, domid);
-    }
-    if (libxl__devices_destroy(gc, domid) < 0)
-        LIBXL__LOG(ctx, LIBXL__LOG_ERROR, 
-                   "libxl__devices_destroy failed for %d", domid);
+int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
+                         const libxl_asyncop_how *ao_how)
+{
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__domain_destroy_state *dds;
 
-    vm_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/vm", dom_path));
-    if (vm_path)
-        if (!xs_rm(ctx->xsh, XBT_NULL, vm_path))
-            LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs_rm failed for %s", vm_path);
+    GCNEW(dds);
+    dds->ao = ao;
+    dds->domid = domid;
+    dds->callback = domain_destroy_cb;
+    libxl__domain_destroy(egc, dds);
 
-    if (!xs_rm(ctx->xsh, XBT_NULL, dom_path))
-        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs_rm failed for %s", dom_path);
+    return AO_INPROGRESS;
+}
 
-    xs_rm(ctx->xsh, XBT_NULL, libxl__xs_libxl_path(gc, domid));
+static void domain_destroy_cb(libxl__egc *egc, libxl__domain_destroy_state *dds,
+                              int rc)
+{
+    STATE_AO_GC(dds->ao);
 
-    libxl__userdata_destroyall(gc, domid);
+    if (rc)
+        LOG(ERROR, "destruction of domain %u failed", dds->domid);
 
-    rc = xc_domain_destroy(ctx->xch, domid);
-    if (rc < 0) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_destroy failed for %d", domid);
-        rc = ERROR_FAIL;
-        goto out;
-    }
-    rc = 0;
-out:
-    GC_FREE;
-    return rc;
+    libxl__ao_complete(egc, ao, rc);
 }
 
 int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num, libxl_console_type type)
@@ -1271,6 +1225,26 @@ int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)
 
 /******************************************************************************/
 
+/* generic callback for devices that only need to set ao_complete */
+static void libxl__device_cb(libxl__egc *egc, libxl__ao_device *aorm)
+{
+    STATE_AO_GC(aorm->ao);
+
+    if (aorm->rc) {
+        LOGE(ERROR, "unable to %s %s with id %u",
+                    aorm->action == DEVICE_CONNECT ? "add" : "remove",
+                    libxl__device_kind_to_string(aorm->dev->kind),
+                    aorm->dev->devid);
+        goto out;
+    }
+
+out:
+    libxl__ao_complete(egc, ao, aorm->rc);
+    return;
+}
+
+/******************************************************************************/
+
 int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk)
 {
     int rc;
@@ -1297,19 +1271,25 @@ int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
                              const libxl_asyncop_how *ao_how)
 {
     AO_CREATE(ctx, domid, ao_how);
-    libxl__device device;
+    libxl__device *device;
+    libxl__ao_device *aorm = 0;
     int rc;
 
-    rc = libxl__device_from_disk(gc, domid, disk, &device);
+    GCNEW(device);
+    rc = libxl__device_from_disk(gc, domid, disk, device);
     if (rc != 0) goto out;
 
-    rc = libxl__initiate_device_remove(egc, ao, &device);
-    if (rc) goto out;
+    GCNEW(aorm);
+    libxl__init_ao_device(aorm, ao, NULL);
+    aorm->action = DEVICE_DISCONNECT;
+    aorm->dev = device;
+    aorm->callback = libxl__device_cb;
 
-    return AO_INPROGRESS;
+    libxl__initiate_device_remove(egc, aorm);
 
 out:
-    return AO_ABORT(rc);
+    if (rc) return AO_ABORT(rc);
+    return AO_INPROGRESS;
 }
 
 int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid,
@@ -1671,19 +1651,25 @@ int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
                             const libxl_asyncop_how *ao_how)
 {
     AO_CREATE(ctx, domid, ao_how);
-    libxl__device device;
+    libxl__device *device;
+    libxl__ao_device *aorm = 0;
     int rc;
 
-    rc = libxl__device_from_nic(gc, domid, nic, &device);
+    GCNEW(device);
+    rc = libxl__device_from_nic(gc, domid, nic, device);
     if (rc != 0) goto out;
 
-    rc = libxl__initiate_device_remove(egc, ao, &device);
-    if (rc) goto out;
+    GCNEW(aorm);
+    libxl__init_ao_device(aorm, ao, NULL);
+    aorm->action = DEVICE_DISCONNECT;
+    aorm->dev = device;
+    aorm->callback = libxl__device_cb;
 
-    return AO_INPROGRESS;
+    libxl__initiate_device_remove(egc, aorm);
 
 out:
-    return AO_ABORT(rc);
+    if (rc) return AO_ABORT(rc);
+    return AO_INPROGRESS;
 }
 
 int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid,
@@ -2033,19 +2019,25 @@ int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid,
                             const libxl_asyncop_how *ao_how)
 {
     AO_CREATE(ctx, domid, ao_how);
-    libxl__device device;
+    libxl__device *device;
+    libxl__ao_device *aorm = 0;
     int rc;
 
-    rc = libxl__device_from_vkb(gc, domid, vkb, &device);
+    GCNEW(device);
+    rc = libxl__device_from_vkb(gc, domid, vkb, device);
     if (rc != 0) goto out;
 
-    rc = libxl__initiate_device_remove(egc, ao, &device);
-    if (rc) goto out;
+    GCNEW(aorm);
+    libxl__init_ao_device(aorm, ao, NULL);
+    aorm->action = DEVICE_DISCONNECT;
+    aorm->dev = device;
+    aorm->callback = libxl__device_cb;
 
-    return AO_INPROGRESS;
+    libxl__initiate_device_remove(egc, aorm);
 
 out:
-    return AO_ABORT(rc);
+    if (rc) return AO_ABORT(rc);
+    return AO_INPROGRESS;
 }
 
 int libxl_device_vkb_destroy(libxl_ctx *ctx, uint32_t domid,
@@ -2166,19 +2158,25 @@ int libxl_device_vfb_remove(libxl_ctx *ctx, uint32_t domid,
                             const libxl_asyncop_how *ao_how)
 {
     AO_CREATE(ctx, domid, ao_how);
-    libxl__device device;
+    libxl__device *device;
+    libxl__ao_device *aorm = 0;
     int rc;
 
-    rc = libxl__device_from_vfb(gc, domid, vfb, &device);
+    GCNEW(device);
+    rc = libxl__device_from_vfb(gc, domid, vfb, device);
     if (rc != 0) goto out;
 
-    rc = libxl__initiate_device_remove(egc, ao, &device);
-    if (rc) goto out;
+    GCNEW(aorm);
+    libxl__init_ao_device(aorm, ao, NULL);
+    aorm->action = DEVICE_DISCONNECT;
+    aorm->dev = device;
+    aorm->callback = libxl__device_cb;
 
-    return AO_INPROGRESS;
+    libxl__initiate_device_remove(egc, aorm);
 
 out:
-    return AO_ABORT(rc);
+    if (rc) return AO_ABORT(rc);
+    return AO_INPROGRESS;
 }
 
 int libxl_device_vfb_destroy(libxl_ctx *ctx, uint32_t domid,
tools/libxl/libxl.h +2 -1
index 979940a..2f4694e 100644
@@ -530,7 +530,8 @@ int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
 int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_shutdown(libxl_ctx *ctx, uint32_t domid);
 int libxl_domain_reboot(libxl_ctx *ctx, uint32_t domid);
-int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid);
+int libxl_domain_destroy(libxl_ctx *ctx, uint32_t domid,
+                         const libxl_asyncop_how *ao_how);
 int libxl_domain_preserve(libxl_ctx *ctx, uint32_t domid, libxl_domain_create_info *info, const char *name_suffix, libxl_uuid new_uuid);
 
 /* get max. number of cpus supported by hypervisor */
tools/libxl/libxl_create.c +26 -4
index 14721eb..bd8e6a6 100644
@@ -584,6 +584,13 @@ static void domcreate_complete(libxl__egc *egc,
                                libxl__domain_create_state *dcs,
                                int rc);
 
+/* If creation is not successful, this callback will be executed
+ * when domain destruction is finished */
+
+static void domcreate_destruction_cb(libxl__egc *egc,
+                                    libxl__domain_destroy_state *dds,
+                                    int rc);
+
 static void initiate_domain_create(libxl__egc *egc,
                                    libxl__domain_create_state *dcs)
 {
@@ -848,16 +855,31 @@ static void domcreate_complete(libxl__egc *egc,
 
     if (rc) {
         if (dcs->guest_domid) {
-            int rc2 = libxl_domain_destroy(CTX, dcs->guest_domid);
-            if (rc2)
-                LOG(ERROR, "unable to destroy domain %d following"
-                    " failed creation", dcs->guest_domid);
+            dcs->dds.ao = ao;
+            dcs->dds.domid = dcs->guest_domid;
+            dcs->dds.callback = domcreate_destruction_cb;
+            libxl__domain_destroy(egc, &dcs->dds);
+            return;
         }
         dcs->guest_domid = -1;
     }
     dcs->callback(egc, dcs, rc, dcs->guest_domid);
 }
 
+static void domcreate_destruction_cb(libxl__egc *egc,
+                                     libxl__domain_destroy_state *dds,
+                                     int rc)
+{
+    STATE_AO_GC(dds->ao);
+    libxl__domain_create_state *dcs = CONTAINER_OF(dds, *dcs, dds);
+
+    if (rc)
+        LOG(ERROR, "unable to destroy domain %u following failed creation",
+                   dds->domid);
+
+    dcs->callback(egc, dcs, rc, dcs->guest_domid);
+}
+
 /*----- application-facing domain creation interface -----*/
 
 typedef struct {
tools/libxl/libxl_device.c +238 -70

391 lines not on this page · raw message

tools/libxl/libxl_dm.c +41 -42

107 lines not on this page · raw message

tools/libxl/libxl_dom.c +170 -0

176 lines not on this page · raw message

tools/libxl/libxl_internal.h +179 -45

254 lines not on this page · raw message

tools/libxl/xl_cmdimpl.c +6 -6
index efaf3de..3c02b69 100644
@@ -1333,7 +1333,7 @@ static int handle_domain_death(libxl_ctx *ctx, uint32_t domid,
         /* fall-through */
     case LIBXL_ACTION_ON_SHUTDOWN_DESTROY:
         LOG("Domain %d needs to be cleaned up: destroying the domain", domid);
-        libxl_domain_destroy(ctx, domid);
+        libxl_domain_destroy(ctx, domid, 0);
         break;
 
     case LIBXL_ACTION_ON_SHUTDOWN_COREDUMP_DESTROY:
@@ -1899,7 +1899,7 @@ start:
 error_out:
     release_lock();
     if (libxl_domid_valid_guest(domid))
-        libxl_domain_destroy(ctx, domid);
+        libxl_domain_destroy(ctx, domid, 0);
 
 out:
     if (logfile != 2)
@@ -2390,7 +2390,7 @@ static void destroy_domain(const char *p)
         fprintf(stderr, "Cannot destroy privileged domain 0.\n\n");
         exit(-1);
     }
-    rc = libxl_domain_destroy(ctx, domid);
+    rc = libxl_domain_destroy(ctx, domid, 0);
     if (rc) { fprintf(stderr,"destroy failed (rc=%d)\n",rc); exit(-1); }
 }
 
@@ -2664,7 +2664,7 @@ static int save_domain(const char *p, const char *filename, int checkpoint,
     if (checkpoint)
         libxl_domain_unpause(ctx, domid);
     else
-        libxl_domain_destroy(ctx, domid);
+        libxl_domain_destroy(ctx, domid, 0);
 
     exit(0);
 }
@@ -2896,7 +2896,7 @@ static void migrate_domain(const char *domain_spec, const char *rune,
     }
 
     fprintf(stderr, "migration sender: Target reports successful startup.\n");
-    libxl_domain_destroy(ctx, domid); /* bang! */
+    libxl_domain_destroy(ctx, domid, 0); /* bang! */
     fprintf(stderr, "Migration successful.\n");
     exit(0);
 
@@ -3014,7 +3014,7 @@ static void migrate_receive(int debug, int daemonize, int monitor)
     if (rc) {
         fprintf(stderr, "migration target: Failure, destroying our copy.\n");
 
-        rc2 = libxl_domain_destroy(ctx, domid);
+        rc2 = libxl_domain_destroy(ctx, domid, 0);
         if (rc2) {
             fprintf(stderr, "migration target: Failed to destroy our copy"
                     " (code %d).\n", rc2);
tools/python/xen/lowlevel/xl/xl.c +1 -1
index c4f7c52..e144670 100644
@@ -447,7 +447,7 @@ static PyObject *pyxl_domain_destroy(XlObject *self, PyObject *args)
     int domid;
     if ( !PyArg_ParseTuple(args, "i", &domid) )
         return NULL;
-    if ( libxl_domain_destroy(self->ctx, domid) ) {
+    if ( libxl_domain_destroy(self->ctx, domid, 0) ) {
         PyErr_SetString(xl_error_obj, "cannot destroy domain");
         return NULL;
     }
Signature · 1 line
1.7.7.5 (Apple Git-26)
#12 lore raw

Re: [PATCH 07/13] libxl: convert libxl_domain_destroy to an AO op

Roger Pau Monne writes ("[PATCH 07/13] libxl: convert libxl_domain_destroy to an AO op"):

Quoted 10 lines

This change introduces some new structures, and breaks the mutual dependency that libxl_domain_destroy and libxl__destroy_device_model had. This is done by checking if the domid passed to libxl_domain_destroy has a stubdom, and then having the bulk of the destroy machinery in a separate function (libxl__destroy_domid) that doesn't check for stubdom presence, since we check for it in the upper level function. The reason behind this change is the need to use structures for ao operations, and it was impossible to have two different self-referencing structs.

Quoted 4 lines

All uses of libxl_domain_destroy have been changed, and either replaced by the new libxl_domain_destroy ao function or by the internal libxl__domain_destroy that can be used inside an already running ao.

Can you separate out the code motion into a separate patch ? As it is it's very difficult to review.

Also can you try to eliminate any code motion that's not strictly necessaray.

Thanks,
Ian.

#13 lore raw

Re: [PATCH 07/13] libxl: convert libxl_domain_destroy to an AO op

In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH 07/13] libxl: convert libxl_domain_destroy to an AO op"):

Quoted 4 lines
tools/libxl/libxl_internal.h +4 -0
+struct libxl__ao_device {
+    libxl__ao *ao;
+    /* State in which the device is */
+    libxl__device_state state;

tools/libxl/libxl_internal.h _hidden void libxl__bootloader_init(libxl__bootloader_state *bl); · line 1818

Quoted 10 lines
tools/libxl/libxl_internal.h +10 -0
+    /* action being performed */
+    libxl__device_action action;
+    libxl__device *dev;
+    int force;
+    libxl__device_callback *callback;
+    /* private for implementation */
+    int rc;
+    libxl__ev_devstate ds;
+    void *base;
+};

Perhaps this new functionality could be in a separate patch too ? I guess it won't share a great deal of code with the existing machinery.

Quoted 8 lines
tools/libxl/libxl_internal.h +8 -0
+/*----- device addition/removal -----*/
+
+/* During the init/destruction process, the device can be in several states:
+ *
+ * DEVICE_UNKNOWN: device in unknown state (default value when struct is
+ * initialized).
+ *
+ * DEVICE_WAIT_BACKEND: waiting for the backend to switch to XenbusStateInit or

tools/libxl/libxl_internal.h _hidden void libxl__bootloader_init(libxl__bootloader_state *bl); · line 1788

Quoted 10 lines
tools/libxl/libxl_internal.h +10 -0
+ * XenbusStateClosed.
+ *
+ * DEVICE_WAIT_HOTPLUG: waiting for hotplug script to finish execution.
+ *
+ * DEVICE_FINISHED: device is connected/disconnected.
+ */
+typedef enum {
+    DEVICE_ACTIVE,
+    DEVICE_FINISHED
+} libxl__device_state;

This enum doesn't seem to correspond to the comment. Also if it really is a two-state enum why not just have a boolean called "finished" ?

Ian.

#14 lore raw

PATCH 8/13 libxl: convert libxl_device_disk_add to an async operation

In reply to Roger Pau Monne

This patch converts libxl_device_disk_add to an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.

As usual, libxl_device_disk_add callers have been modified, and the internal function libxl__device_disk_add has been used if the call was inside an already running ao.

---
 tools/libxl/libxl.c          |   22 +++++++++-----
 tools/libxl/libxl.h          |    4 ++-
 tools/libxl/libxl_create.c   |   51 ++++++++++++++++++++++++++++----
 tools/libxl/libxl_device.c   |   66 ++++++++++++++++++++++++++++++++++++------
 tools/libxl/libxl_dm.c       |   62 +++++++++++++++++++++++++++++++--------
 tools/libxl/libxl_internal.h |   21 ++++++++++++-
 tools/libxl/xl_cmdimpl.c     |    2 +-
 7 files changed, 187 insertions(+), 41 deletions(-)
tools/libxl/libxl.c +14 -8
index dabe92b..5edfbdc 100644
@@ -1255,15 +1255,19 @@ int libxl__device_disk_setdefault(libxl__gc *gc, libxl_device_disk *disk)
     return rc;
 }
 
-int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
+int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
+                          libxl_device_disk *disk,
+                          const libxl_asyncop_how *ao_how)
 {
-    GC_INIT(ctx);
-    int rc;
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__ao_device *device;
 
-    rc = libxl__device_disk_add(gc, domid, disk);
+    GCNEW(device);
+    libxl__init_ao_device(device, ao, NULL);
+    device->callback = libxl__device_cb;
+    libxl__device_disk_add(egc, domid, disk, device);
 
-    GC_FREE;
-    return rc;
+    return AO_INPROGRESS;
 }
 
 int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
@@ -1508,11 +1512,13 @@ int libxl_cdrom_insert(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk)
     ret = 0;
 
     libxl_device_disk_remove(ctx, domid, disks + i, 0);
-    libxl_device_disk_add(ctx, domid, disk);
+    /* fixme-ao */
+    libxl_device_disk_add(ctx, domid, disk, 0);
     stubdomid = libxl_get_stubdom_id(ctx, domid);
     if (stubdomid) {
         libxl_device_disk_remove(ctx, stubdomid, disks + i, 0);
-        libxl_device_disk_add(ctx, stubdomid, disk);
+        /* fixme-ao */
+        libxl_device_disk_add(ctx, stubdomid, disk, 0);
     }
 out:
     for (i = 0; i < num; i++)
tools/libxl/libxl.h +3 -1
index 2f4694e..f76b2e6 100644
@@ -663,7 +663,9 @@ void libxl_vminfo_list_free(libxl_vminfo *list, int nr);
  */
 
 /* Disks */
-int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk);
+int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
+                          libxl_device_disk *disk,
+                          const libxl_asyncop_how *ao_how);
 int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid,
                              libxl_device_disk *disk,
                              const libxl_asyncop_how *ao_how);
tools/libxl/libxl_create.c +44 -7

65 lines not on this page · raw message

tools/libxl/libxl_device.c +57 -9

118 lines not on this page · raw message

tools/libxl/libxl_dm.c +49 -13

110 lines not on this page · raw message

tools/libxl/libxl_internal.h +19 -2
index e324da2..2500b86 100644
@@ -70,6 +70,7 @@
 #include "_libxl_types_internal.h"
 #include "_libxl_types_internal_json.h"
 
+#define LIBXL_INIT_TIMEOUT 10
 #define LIBXL_DESTROY_TIMEOUT 10
 #define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
 #define LIBXL_XENCONSOLE_LIMIT 1048576
@@ -783,8 +784,6 @@ _hidden int libxl__device_disk_set_backend(libxl__gc*, libxl_device_disk*);
 _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
                                     libxl_device_disk *disk,
                                     libxl__device *device);
-_hidden int libxl__device_disk_add(libxl__gc *gc, uint32_t domid,
-                                   libxl_device_disk *disk);
 
 _hidden int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
                                    libxl_device_nic *nic,
@@ -1817,6 +1816,18 @@ struct libxl__ao_device {
     void *base;
 };
 
+/* Internal AO operation to connect a disk device */
+_hidden void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
+                                    libxl_device_disk *disk,
+                                    libxl__ao_device *aorm);
+
+/* Arranges that dev will be added to the guest, and the
+ * hotplug scripts will be executed (if necessary). When
+ * this is done (or an error happens), the callback in
+ * aorm->callback will be called.
+ */
+_hidden void libxl__initiate_device_add(libxl__egc*, libxl__ao_device *aorm);
+
 /* Arranges that dev will be removed to the guest, and the
  * hotplug scripts will be executed (if necessary). When
  * this is done (or an error happens), the callback in
@@ -1941,6 +1952,9 @@ typedef struct {
     libxl__domain_build_state dm_state;
     libxl__dm_spawn_state pvqemu;
     libxl__destroy_domid_state dis;
+    /* used to store the state of devices being connected */
+    libxl__ao_device *devices;
+    int num_devices;
 } libxl__stub_dm_spawn_state;
 
 _hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*);
@@ -1969,6 +1983,9 @@ struct libxl__domain_create_state {
          * for the non-stubdom device model. */
     /* necessary if the domain creation failed and we have to destroy it */
     libxl__domain_destroy_state dds;
+    /* used to store the state of devices being connected */
+    libxl__ao_device *devices;
+    int num_devices;
 };
 
 
tools/libxl/xl_cmdimpl.c +1 -1
index 3c02b69..69ce45a 100644
@@ -5081,7 +5081,7 @@ int main_blockattach(int argc, char **argv)
         return 0;
     }
 
-    if (libxl_device_disk_add(ctx, fe_domid, &disk)) {
+    if (libxl_device_disk_add(ctx, fe_domid, &disk, 0)) {
         fprintf(stderr, "libxl_device_disk_add failed.\n");
     }
     return 0;
Signature · 1 line
1.7.7.5 (Apple Git-26)
#15 lore raw

Re: [PATCH 08/13] libxl: convert libxl_device_disk_add to an async operation

Roger Pau Monne writes ("[PATCH 08/13] libxl: convert libxl_device_disk_add to an async operation"):

tools/libxl/libxl_create.c static void domcreate_bootloader_done(libxl__egc *egc, · line 743

Quoted 11 lines
tools/libxl/libxl_create.c +11 -0
+static void domcreate_disk_connected(libxl__egc *egc, libxl__ao_device *aorm)
+{
+    STATE_AO_GC(aorm->ao);
+    libxl__domain_create_state *dcs = CONTAINER_OF(aorm->base, *dcs, devices)...
+    ret = libxl__ao_device_check_last(gc, aorm, dcs->devices,
+                                      dcs->num_devices, &last);
+    if (!last) return;
+    if (last && ret) {
+        LOGE(ERROR, "error connecting disk devices");
+        goto error_out;
+    }

This is a slightly odd way of putting it. The `if (last' part is always going to be true because we always return if !last.

Also, please can you use "rc" for libxl error codes rather than "ret". We should standardise on one name for this and all the recent new code uses "rc".

tools/libxl/libxl_create.c static void domcreate_bootloader_done(libxl__egc *egc, · line 753

Quoted 9 lines
tools/libxl/libxl_create.c +9 -0
+    /* We might be going to call libxl__spawn_local_dm, or _spawn_stub_dm.
+     * Fill in any field required by either, including both relevant
+     * callbacks (_spawn_stub_dm will overwrite our trespass if needed). */
+    dcs->dmss.dm.spawn.ao = ao;
+    dcs->dmss.dm.guest_config = dcs->guest_config;
+    dcs->dmss.dm.build_state = &dcs->build_state;
+    dcs->dmss.dm.callback = domcreate_devmodel_started;
+    dcs->dmss.callback = domcreate_devmodel_started;
+

I don't understand why this hunk appears here in this diff. Surely this patch should not need to change the initialisation of dcs->dmss ?

tools/libxl/libxl_dm.c

Quoted 4 lines
tools/libxl/libxl_dm.c +0 -0
index 4019309..2b63a15 100644

... int rc);

Quoted 5 lines
tools/libxl/libxl_dm.c +1 -0
@@ -800,22 +801,60 @@ retry_transaction:
         if (errno == EAGAIN)
             goto retry_transaction;
 
+    GCNEW_ARRAY(sdss->devices, dm_config->num_disks);

tools/libxl/libxl_dm.c retry_transaction: · line 811

Quoted 10 lines
tools/libxl/libxl_dm.c +6 -3
+    sdss->num_devices = dm_config->num_disks;
     for (i = 0; i < dm_config->num_disks; i++) {
-        ret = libxl_device_disk_add(ctx, dm_domid, &dm_config->disks[i]);
-        if (ret)
-            goto out_free;
+        libxl__init_ao_device(&sdss->devices[i], ao, &sdss->devices);
+        sdss->devices[i].callback = spawn_stub_disk_connected;
+        libxl__device_disk_add(egc, dm_domid, &dm_config->disks[i],
+                               &sdss->devices[i]);
+    }

We seem to have a couple of instances of this pattern. You have a helper function libxl__ao_device_check_last to check they're all done and fish out the rc value.

Perhaps there should be a small helper function to populate devices[] and call libxl__device_disk_add ?

Thanks,
Ian.

#16 lore raw

PATCH 9/13 libxl: convert libxl_device_nic_add to an async operation

In reply to Roger Pau Monne

This patch converts libxl_device_nic_add to an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.

Calls to libxl_device_nic_add have also been moved to occur after the device model has been launched, so when hotplug scripts are called from this functions the interfaces already exists.

As usual, libxl_device_nic_add callers have been modified, and the internal function libxl__device_disk_add has been used if the call was inside an already running ao.

---
 tools/libxl/libxl.c          |   15 +++++---
 tools/libxl/libxl.h          |    3 +-
 tools/libxl/libxl_create.c   |   73 ++++++++++++++++++++++++++++++++++++++----
 tools/libxl/libxl_device.c   |   23 ++++++++++---
 tools/libxl/libxl_dm.c       |   58 +++++++++++++++++++++++++++++++--
 tools/libxl/libxl_internal.h |    7 +++-
 tools/libxl/xl_cmdimpl.c     |    2 +-
 7 files changed, 155 insertions(+), 26 deletions(-)
tools/libxl/libxl.c +9 -6
index 5edfbdc..2490138 100644
@@ -1641,15 +1641,18 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
     return 0;
 }
 
-int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic)
+int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic,
+                         const libxl_asyncop_how *ao_how)
 {
-    GC_INIT(ctx);
-    int rc;
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__ao_device *device;
 
-    rc = libxl__device_nic_add(gc, domid, nic);
+    GCNEW(device);
+    libxl__init_ao_device(device, ao, NULL);
+    device->callback = libxl__device_cb;
+    libxl__device_nic_add(egc, domid, nic, device);
 
-    GC_FREE;
-    return rc;
+    return AO_INPROGRESS;
 }
 
 int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
tools/libxl/libxl.h +2 -1
index f76b2e6..fc8a1a1 100644
@@ -690,7 +690,8 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk);
 int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk);
 
 /* Network Interfaces */
-int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic);
+int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic,
+                         const libxl_asyncop_how *ao_how);
 int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid,
                             libxl_device_nic *nic,
                             const libxl_asyncop_how *ao_how);
tools/libxl/libxl_create.c +66 -7

91 lines not on this page · raw message

tools/libxl/libxl_device.c +17 -6
index 96e6ec4..6b0ce95 100644
@@ -467,11 +467,13 @@ int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
     return 0;
 }
 
-int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
+void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
+                           libxl_device_nic *nic, libxl__ao_device *aorm)
 {
+    STATE_AO_GC(aorm->ao);
     flexarray_t *front;
     flexarray_t *back;
-    libxl__device device;
+    libxl__device *device;
     char *dompath, **l;
     unsigned int nb, rc;
 
@@ -504,7 +506,8 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
         }
     }
 
-    rc = libxl__device_from_nic(gc, domid, nic, &device);
+    GCNEW(device);
+    rc = libxl__device_from_nic(gc, domid, nic, device);
     if ( rc != 0 ) goto out_free;
 
     flexarray_append(back, "frontend-id");
@@ -545,6 +548,9 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
     flexarray_append(back, libxl__strdup(gc, nic->bridge));
     flexarray_append(back, "handle");
     flexarray_append(back, GCSPRINTF("%d", nic->devid));
+    flexarray_append(back, "type");
+    flexarray_append(back, GCSPRINTF("%s",
+                                     libxl_nic_type_to_string(nic->nictype)));
 
     flexarray_append(front, "backend-id");
     flexarray_append(front, GCSPRINTF("%d", nic->backend_domid));
@@ -555,17 +561,22 @@ int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
     flexarray_append(front, "mac");
     flexarray_append(front, GCSPRINTF(LIBXL_MAC_FMT,
                                       LIBXL_MAC_BYTES(nic->mac)));
-    libxl__device_generic_add(gc, &device,
+    libxl__device_generic_add(gc, device,
                         libxl__xs_kvs_of_flexarray(gc, back, back->count),
                         libxl__xs_kvs_of_flexarray(gc, front, front->count));
 
-    /* FIXME: wait for plug */
+    aorm->dev = device;
+    aorm->action = DEVICE_CONNECT;
+    libxl__initiate_device_add(egc, aorm);
+
     rc = 0;
 out_free:
     flexarray_free(back);
     flexarray_free(front);
 out:
-    return rc;
+    aorm->rc = rc;
+    if (aorm->rc) aorm->callback(egc, aorm);
+    return;
 }
 
 int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor)
tools/libxl/libxl_dm.c +55 -3

79 lines not on this page · raw message

tools/libxl/libxl_internal.h +5 -2
index 2500b86..725975d 100644
@@ -788,8 +788,6 @@ _hidden int libxl__device_from_disk(libxl__gc *gc, uint32_t domid,
 _hidden int libxl__device_from_nic(libxl__gc *gc, uint32_t domid,
                                    libxl_device_nic *nic,
                                    libxl__device *device);
-_hidden int libxl__device_nic_add(libxl__gc *gc, uint32_t domid,
-                                  libxl_device_nic *nic);
 
 _hidden int libxl__device_physdisk_major_minor(const char *physpath, int *major, int *minor);
 _hidden int libxl__device_disk_dev_number(const char *virtpath,
@@ -1821,6 +1819,11 @@ _hidden void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
                                     libxl_device_disk *disk,
                                     libxl__ao_device *aorm);
 
+/* Internal AO operation to connect a nic device */
+_hidden void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
+                                   libxl_device_nic *nic,
+                                   libxl__ao_device *aorm);
+
 /* Arranges that dev will be added to the guest, and the
  * hotplug scripts will be executed (if necessary). When
  * this is done (or an error happens), the callback in
tools/libxl/xl_cmdimpl.c +1 -1
index 69ce45a..46af9fb 100644
@@ -4970,7 +4970,7 @@ int main_networkattach(int argc, char **argv)
         return 0;
     }
 
-    if (libxl_device_nic_add(ctx, domid, &nic)) {
+    if (libxl_device_nic_add(ctx, domid, &nic, 0)) {
         fprintf(stderr, "libxl_device_nic_add failed.\n");
         return 1;
     }
Signature · 1 line
1.7.7.5 (Apple Git-26)
#17 lore raw

Re: [PATCH 09/13] libxl: convert libxl_device_nic_add to an async operation

Roger Pau Monne writes ("[PATCH 09/13] libxl: convert libxl_device_nic_add to an async operation"):

Quoted 5 lines

This patch converts libxl_device_nic_add to an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.

Why do you serialise vif and vbd initialisation ? Would anything go wrong if you did them both at once ?

tools/libxl/libxl_create.c static void domcreate_devmodel_started(libxl__egc *egc, · line 866

Quoted 10 lines
tools/libxl/libxl_create.c +10 -0
+    /* Plug nic interfaces */
+    if (!ret && d_config->num_vifs > 0) {
+        /* Attach nics */
+        GCNEW_ARRAY(dcs->devices, d_config->num_vifs);
+        dcs->num_devices = d_config->num_vifs;
+        for (i = 0; i < d_config->num_vifs; i++) {
+            libxl__init_ao_device(&dcs->devices[i], ao, &dcs->devices);
+            dcs->devices[i].callback = domcreate_nics_connected;
+            libxl__device_nic_add(egc, domid, &d_config->vifs[i],
+                                  &dcs->devices[i]);

Ah this pattern again....

tools/libxl/libxl_device.c int libxl__device_from_nic(libxl__gc *gc, uint32_t domid, · line 476

Quoted 9 lines
tools/libxl/libxl_device.c +4 -2
-int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
+void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
+                           libxl_device_nic *nic, libxl__ao_device *aorm)
 {
+    STATE_AO_GC(aorm->ao);
     flexarray_t *front;
     flexarray_t *back;
-    libxl__device device;
+    libxl__device *device;

You might want to consider a pre-patch which changes this, and libxl__device_disk_add's, as follows:
- libxl__device device;
+ libxl__device device[1];

That would get rid of the noise from this patch. Up to you, though; because it's separated out textually doesn't make the diff unreadable like it is.

tools/libxl/libxl_dm.c static void spawn_stub_disk_connected(libxl__egc *egc, libxl__ao_device *aorm) · line 858

Quoted 12 lines
tools/libxl/libxl_dm.c +5 -3
@@ -845,9 +851,11 @@ static void spawn_stub_disk_connected(libxl__egc *egc, libxl__ao_device *aorm)
     }
 
     for (i = 0; i < dm_config->num_vifs; i++) {
-        ret = libxl_device_nic_add(ctx, dm_domid, &dm_config->vifs[i]);
-        if (ret)
-            goto out;
+        /* We have to init the nic here, because we still haven't
+         * called libxl_device_nic_add at this point, but qemu needs
+         * the nic information to be complete.
+         */
+        libxl__device_nic_setdefault(gc, &dm_config->vifs[i]);

This is really too much repetition now. Can we not have a common "add devices" function which is called once for the main domain and once for the stubdom ?

In the future we'll need that if we have more service domains, too.

Thanks,
Ian.

#18 lore raw

Re: [PATCH 09/13] libxl: convert libxl_device_nic_add to an async operation

Quoted 9 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH 09/13] libxl: convert libxl_device_nic_add to an async operation"):

Quoted 5 lines

This patch converts libxl_device_nic_add to an ao operation that waits for device backend to reach state XenbusStateInitWait and then marks the operation as completed. This is not really useful now, but will be used by latter patches that will launch hotplug scripts after we reached the desired xenbus state.

Why do you serialise vif and vbd initialisation ? Would anything go wrong if you did them both at once ?

disk needs to be added before Qemu is launched, on the other hand nics need to be added after qemu is launched, so we need to add them at different moments during the domain creation, it's a PITA.

Quoted 35 lines

tools/libxl/libxl_create.c static void domcreate_devmodel_started(libxl__egc *egc, · line 866

Quoted 10 lines
tools/libxl/libxl_create.c +10 -0
+    /* Plug nic interfaces */
+    if (!ret&&  d_config->num_vifs>  0) {
+        /* Attach nics */
+        GCNEW_ARRAY(dcs->devices, d_config->num_vifs);
+        dcs->num_devices = d_config->num_vifs;
+        for (i = 0; i<  d_config->num_vifs; i++) {
+            libxl__init_ao_device(&dcs->devices[i], ao,&dcs->devices);
+            dcs->devices[i].callback = domcreate_nics_connected;
+            libxl__device_nic_add(egc, domid,&d_config->vifs[i],
+&dcs->devices[i]);

Ah this pattern again....

tools/libxl/libxl_device.c int libxl__device_from_nic(libxl__gc *gc, uint32_t domid, · line 476

Quoted 9 lines
tools/libxl/libxl_device.c +4 -2
-int libxl__device_nic_add(libxl__gc *gc, uint32_t domid, libxl_device_nic *nic)
+void libxl__device_nic_add(libxl__egc *egc, uint32_t domid,
+                           libxl_device_nic *nic, libxl__ao_device *aorm)
  {
+    STATE_AO_GC(aorm->ao);
      flexarray_t *front;
      flexarray_t *back;
-    libxl__device device;
+    libxl__device *device;

You might want to consider a pre-patch which changes this, and libxl__device_disk_add's, as follows:
- libxl__device device;
+ libxl__device device[1];

That would get rid of the noise from this patch. Up to you, though; because it's separated out textually doesn't make the diff unreadable like it is.

Quoted 3 lines
(quoted diff) +0 -0
@@ -845,9 +851,11 @@ static void spawn_stub_disk_connected(libxl__egc *egc, libxl__ao_device *aorm)
      }
 
Quoted 13 lines

tools/libxl/libxl_dm.c static void spawn_stub_disk_connected(libxl__egc *egc, libxl__ao_device *aorm)

Quoted 9 lines
tools/libxl/libxl_dm.c +5 -3
      for (i = 0; i<  dm_config->num_vifs; i++) {
-        ret = libxl_device_nic_add(ctx, dm_domid,&dm_config->vifs[i]);
-        if (ret)
-            goto out;
+        /* We have to init the nic here, because we still haven't
+         * called libxl_device_nic_add at this point, but qemu needs
+         * the nic information to be complete.
+         */
+        libxl__device_nic_setdefault(gc,&dm_config->vifs[i]);

This is really too much repetition now. Can we not have a common "add devices" function which is called once for the main domain and once for the stubdom ?

I've added a functions that does the libxl_device_disk_add loop, and another one for the nics. Although this line you are quoting is not adding a nic, it is just filling the needed values so we can launch Qemu correctly.

Quoted 4 lines

In the future we'll need that if we have more service domains, too.

Thanks,
Ian.

#19 lore raw

Re: [PATCH 09/13] libxl: convert libxl_device_nic_add to an async operation

Roger Pau Monne writes ("Re: [PATCH 09/13] libxl: convert libxl_device_nic_add to an async operation"):

Quoted 7 lines
Quoted 2 lines · Ian Jackson

Why do you serialise vif and vbd initialisation ? Would anything go wrong if you did them both at once ?

disk needs to be added before Qemu is launched, on the other hand nics need to be added after qemu is launched, so we need to add them at different moments during the domain creation, it's a PITA.

Ah I didn't spot that. Right.

Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
      for (i = 0; i<  dm_config->num_vifs; i++) {
tools/libxl/libxl_dm.c +5 -3
-        ret = libxl_device_nic_add(ctx, dm_domid,&dm_config->vifs[i]);
-        if (ret)
-            goto out;
+        /* We have to init the nic here, because we still haven't
+         * called libxl_device_nic_add at this point, but qemu needs
+         * the nic information to be complete.
+         */
+        libxl__device_nic_setdefault(gc,&dm_config->vifs[i]);
Quoted 8 lines
Quoted 3 lines

This is really too much repetition now. Can we not have a common "add devices" function which is called once for the main domain and once for the stubdom ?

I've added a functions that does the libxl_device_disk_add loop, and another one for the nics. Although this line you are quoting is not adding a nic, it is just filling the needed values so we can launch Qemu correctly.

Right, OK. I guess making these two functions common would involve macros or a lot of void*'s, which you would rather avoid.

Ian.

#20 lore raw

PATCH 10/13 libxl: add option to choose who executes hotplug scripts

In reply to Roger Pau Monne

Add and option to xl.conf file to decide if hotplug scripts are executed from the toolstack (xl) or from udev as it used to be in the past.

This option is only introduced in this patch, but it has no effect since the code to call hotplug scripts from libxl is introduced in a latter patch.

This choice will be saved in "libxl/disable_udev", as specified in the DISABLE_UDEV_PATH constant.

---
 docs/man/xl.conf.pod.5       |    8 ++++++++
 tools/examples/xl.conf       |    5 +++++
 tools/libxl/libxl_create.c   |   25 ++++++++++++++++++++++++-
 tools/libxl/libxl_internal.h |    1 +
 tools/libxl/libxl_types.idl  |    1 +
 tools/libxl/xl.c             |    4 ++++
 tools/libxl/xl.h             |    1 +
 tools/libxl/xl_cmdimpl.c     |    1 +
 8 files changed, 45 insertions(+), 1 deletions(-)
docs/man/xl.conf.pod.5 +8 -0
index 8bd45ea..72825a0 100644
@@ -55,6 +55,14 @@ default.
 
 Default: C<1>
 
+=item B<run_hotplug_scripts=BOOLEAN>
+
+If disabled hotplug scripts will be called from udev, as it used to
+be in the previous releases. With the default option, hotplug scripts
+will be launched by xl directly.
+
+Default: C<1>
+
 =item B<lockfile="PATH">
 
 Sets the path to the lock file used by xl to serialise certain
tools/examples/xl.conf +5 -0
index 56d3b3b..75b00e0 100644
@@ -12,3 +12,8 @@
 
 # default output format used by "xl list -l"
 #output_format="json"
+
+# default option to run hotplug scripts from xl
+# if disabled the old behaviour will be used, and hotplug scripts will be
+# launched by udev.
+#run_hotplug_scripts=1
tools/libxl/libxl_create.c +24 -1
index 2134645..4520bc7 100644
@@ -398,7 +398,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_create_info *info,
                        uint32_t *domid)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
-    int flags, ret, rc;
+    int flags, ret, rc, nb_vm;
     char *uuid_string;
     char *dom_path, *vm_path, *libxl_path;
     struct xs_permissions roperm[2];
@@ -519,6 +519,29 @@ retry_transaction:
             libxl__sprintf(gc, "%s/hvmloader/generation-id-address", dom_path),
                         rwperm, ARRAY_SIZE(rwperm));
 
+    if (libxl_list_vm(ctx, &nb_vm) < 0) {
+        LOG(ERROR, "cannot get number of running guests");
+        rc = ERROR_FAIL;
+        goto out;
+    }
+    if (libxl_defbool_val(info->run_hotplug_scripts)) {
+        if (!libxl__xs_read(gc, t, DISABLE_UDEV_PATH) && (nb_vm - 1)) {
+            LOG(ERROR, "cannot change hotplug execution option once set, "
+                        "please shutdown all guests before changing it");
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        libxl__xs_write(gc, t, DISABLE_UDEV_PATH, "1");
+    } else {
+        if (libxl__xs_read(gc, t, DISABLE_UDEV_PATH) && (nb_vm - 1)) {
+            LOG(ERROR, "cannot change hotplug execution option once set, "
+                        "please shutdown all guests before changing it");
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        xs_rm(ctx->xsh, t, DISABLE_UDEV_PATH);
+    }
+
     xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/uuid", vm_path), uuid_string, strlen(uuid_string));
     xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/name", vm_path), info->name, strlen(info->name));
 
tools/libxl/libxl_internal.h +1 -0
index 725975d..7969a43 100644
@@ -86,6 +86,7 @@
 #define STUBDOM_CONSOLE_SERIAL 3
 #define STUBDOM_SPECIAL_CONSOLES 3
 #define TAP_DEVICE_SUFFIX "-emu"
+#define DISABLE_UDEV_PATH "libxl/disable_udev"
 
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 
tools/libxl/libxl_types.idl +1 -0
index 551e367..b1351de 100644
@@ -220,6 +220,7 @@ libxl_domain_create_info = Struct("domain_create_info",[
     ("xsdata",       libxl_key_value_list),
     ("platformdata", libxl_key_value_list),
     ("poolid",       uint32),
+    ("run_hotplug_scripts",libxl_defbool),
     ], dir=DIR_IN)
 
 MemKB = UInt(64, init_val = "LIBXL_MEMKB_DEFAULT")
tools/libxl/xl.c +4 -0
index d4db1f8..d992c32 100644
@@ -35,6 +35,7 @@
 xentoollog_logger_stdiostream *logger;
 int dryrun_only;
 int autoballoon = 1;
+libxl_defbool run_hotplug_scripts;
 char *lockfile;
 char *default_vifscript = NULL;
 char *default_bridge = NULL;
@@ -66,6 +67,9 @@ static void parse_global_config(const char *configfile,
     if (!xlu_cfg_get_long (config, "autoballoon", &l, 0))
         autoballoon = l;
 
+    libxl_defbool_setdefault(&run_hotplug_scripts, true);
+    xlu_cfg_get_defbool(config, "run_hotplug_scripts", &run_hotplug_scripts, 0);
+
     if (!xlu_cfg_get_string (config, "lockfile", &buf, 0))
         lockfile = strdup(buf);
     else {
tools/libxl/xl.h +1 -0
index 2b6714a..43d727a 100644
@@ -109,6 +109,7 @@ void postfork(void);
 
 /* global options */
 extern int autoballoon;
+extern libxl_defbool run_hotplug_scripts;
 extern int dryrun_only;
 extern char *lockfile;
 extern char *default_vifscript;
tools/libxl/xl_cmdimpl.c +1 -0
index 46af9fb..c13c48b 100644
@@ -562,6 +562,7 @@ static void parse_config_data(const char *configfile_filename_report,
         }
     }
 
+    c_info->run_hotplug_scripts = run_hotplug_scripts;
     c_info->type = LIBXL_DOMAIN_TYPE_PV;
     if (!xlu_cfg_get_string (config, "builder", &buf, 0) &&
         !strncmp(buf, "hvm", strlen(buf)))
Signature · 1 line
1.7.7.5 (Apple Git-26)
#21 lore raw

Re: [PATCH 10/13] libxl: add option to choose who executes hotplug scripts

Roger Pau Monne writes ("[PATCH 10/13] libxl: add option to choose who executes hotplug scripts"):

Quoted 3 lines

Add and option to xl.conf file to decide if hotplug scripts are executed from the toolstack (xl) or from udev as it used to be in the past.

...

Quoted 6 lines
tools/libxl/libxl_create.c +6 -0
+    if (libxl_defbool_val(info->run_hotplug_scripts)) {
+        if (!libxl__xs_read(gc, t, DISABLE_UDEV_PATH) && (nb_vm - 1)) {
+            LOG(ERROR, "cannot change hotplug execution option once set, "
+                        "please shutdown all guests before changing it");
+            rc = ERROR_FAIL;
+            goto out;

tools/libxl/libxl_create.c retry_transaction: · line 542

Quoted 10 lines
tools/libxl/libxl_create.c +10 -0
+        }
+        libxl__xs_write(gc, t, DISABLE_UDEV_PATH, "1");
+    } else {
+        if (libxl__xs_read(gc, t, DISABLE_UDEV_PATH) && (nb_vm - 1)) {
+            LOG(ERROR, "cannot change hotplug execution option once set, "
+                        "please shutdown all guests before changing it");
+            rc = ERROR_FAIL;
+            goto out;
+        }
+        xs_rm(ctx->xsh, t, DISABLE_UDEV_PATH);

How about

     int disable_wanted_now = something involving libxl__xs_read(....);
     if (disable_wanted_now !=
         libxl_defbool_val(info->run_hotplug_scripts) {
         LOG(ERROR,
         etc.
     }

?

Also you should check for the errno value from libxl__xs_read. ENOENT is fine but anything else should be a fatal error.

Ian.

#22 lore raw

PATCH 11/13 libxl: set nic type to VIF by default

In reply to Roger Pau Monne

Set the default value for nic interfaces to VIF, since it used to be IOEMU, even for PV guests.

---
 tools/libxl/libxl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/libxl/libxl.c +1 -1
index 2490138..631de15 100644
@@ -1637,7 +1637,7 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
                                   libxl__xen_script_dir_path()) < 0 )
         return ERROR_FAIL;
     if (!nic->nictype)
-        nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+        nic->nictype = LIBXL_NIC_TYPE_VIF;
     return 0;
 }
 
Signature · 1 line
1.7.7.5 (Apple Git-26)
#23 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Roger Pau Monne writes ("[PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 2 lines

Set the default value for nic interfaces to VIF, since it used to be IOEMU, even for PV guests.

How odd.

tools/libxl/libxl.c int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) · line 1640

Quoted 10 lines
tools/libxl/libxl.c +1 -1
index 2490138..631de15 100644
@@ -1637,7 +1637,7 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
                                   libxl__xen_script_dir_path()) < 0 )
         return ERROR_FAIL;
     if (!nic->nictype)
-        nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+        nic->nictype = LIBXL_NIC_TYPE_VIF;

But doesn't this set the default type to VIF even for HVM guests ?

Ian.

#24 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Quoted 6 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 2 lines

Set the default value for nic interfaces to VIF, since it used to be IOEMU, even for PV guests.

How odd.

Quoted 12 lines

tools/libxl/libxl.c int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) · line 1640

Quoted 10 lines
tools/libxl/libxl.c +1 -1
index 2490138..631de15 100644
@@ -1637,7 +1637,7 @@ int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic)
                                    libxl__xen_script_dir_path())<  0 )
          return ERROR_FAIL;
      if (!nic->nictype)
-        nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+        nic->nictype = LIBXL_NIC_TYPE_VIF;

But doesn't this set the default type to VIF even for HVM guests ?

Shouldn't HVM guests use the "ioemu" parameter if they want an emulated card? If no parameter is provided then the default type should be VIF, because there's no other way to specifically set the type to VIF.

#25 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Roger Pau Monne writes ("Re: [PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 10 lines
Quoted 5 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH 11/13] libxl: set nic type to VIF by default"):

tools/libxl/libxl.c int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) · line 1640

Quoted 2 lines
tools/libxl/libxl.c +1 -1
-        nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+        nic->nictype = LIBXL_NIC_TYPE_VIF;

But doesn't this set the default type to VIF even for HVM guests ?

Shouldn't HVM guests use the "ioemu" parameter if they want an emulated card? If no parameter is provided then the default type should be VIF, because there's no other way to specifically set the type to VIF.

Sorry. I seem to have failed to reply to this.

I'm a bit confused about all this, I confess. What does xend do ?

ATM it seems that this change would mean that a guest config file specified in the most obvious way wouldn't get an emulated nic at all. That can't be right, can it ?

Ian.

#26 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Quoted 12 lines · Ian Jackson

Roger Pau Monne writes ("Re: [PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 10 lines
Quoted 5 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH 11/13] libxl: set nic type to VIF by default"):

tools/libxl/libxl.c int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) · line 1640

Quoted 2 lines
tools/libxl/libxl.c +1 -1
-        nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+        nic->nictype = LIBXL_NIC_TYPE_VIF;

But doesn't this set the default type to VIF even for HVM guests ?

Shouldn't HVM guests use the "ioemu" parameter if they want an emulated card? If no parameter is provided then the default type should be VIF, because there's no other way to specifically set the type to VIF.

Quoted 7 lines

Sorry. I seem to have failed to reply to this.

I'm a bit confused about all this, I confess. What does xend do ?

ATM it seems that this change would mean that a guest config file specified in the most obvious way wouldn't get an emulated nic at all. That can't be right, can it ?

It's confusingly named.

IOEMU -> emulated only on HVM, meaningless on PV.
VIF -> both emulated and PV (on HVM) or just PV (on PV)

So a default of "VIF" is what you normally want.

Ian.

#27 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Ian Campbell writes ("Re: [Xen-devel] [PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 1 line · Ian Jackson

...

Quoted 6 lines
Quoted 5 lines

I'm a bit confused about all this, I confess. What does xend do ?

ATM it seems that this change would mean that a guest config file specified in the most obvious way wouldn't get an emulated nic at all. That can't be right, can it ?

Quoted 6 lines

It's confusingly named.

IOEMU -> emulated only on HVM, meaningless on PV.
VIF -> both emulated and PV (on HVM) or just PV (on PV)

So a default of "VIF" is what you normally want.

Oh!

Perhaps we could rename the enum values (and disrupt everyone's patches) to fix this before we call the API stable.

Ian.

#28 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Quoted 14 lines · Ian Jackson

Ian Campbell writes ("Re: [Xen-devel] [PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 1 line · Ian Jackson

...

Quoted 11 lines
Quoted 5 lines

I'm a bit confused about all this, I confess. What does xend do ?

ATM it seems that this change would mean that a guest config file specified in the most obvious way wouldn't get an emulated nic at all. That can't be right, can it ?

It's confusingly named.

IOEMU -> emulated only on HVM, meaningless on PV.
VIF -> both emulated and PV (on HVM) or just PV (on PV)

Quoted 6 lines
Quoted 1 line

So a default of "VIF" is what you normally want.

Oh!

Perhaps we could rename the enum values (and disrupt everyone's patches) to fix this before we call the API stable.

As a "Nice To Have", perhaps. The stable API rules we have set don't preclude us changing them later, we just have to provide a suitable compat define if LIBXL_API_VERSION is set to a relevant value.

What are some better names? IOEMU, VIF and HYBRID? Or DUAL?

Ian.

#29 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

In reply to Ian Campbell
Quoted 14 lines · Ian Campbell
Quoted 13 lines · Ian Jackson

Roger Pau Monne writes ("Re: [PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 8 lines
Quoted 4 lines · Ian Jackson

Roger Pau Monne writes ("[PATCH 11/13] libxl: set nic type to VIF by default"):

tools/libxl/libxl.c int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic) · line 1640

Quoted 2 lines
tools/libxl/libxl.c +1 -1
-        nic->nictype = LIBXL_NIC_TYPE_IOEMU;
+        nic->nictype = LIBXL_NIC_TYPE_VIF;

But doesn't this set the default type to VIF even for HVM guests ?

Shouldn't HVM guests use the "ioemu" parameter if they want an emulated card? If no parameter is provided then the default type should be VIF, because there's no other way to specifically set the type to VIF.

Sorry. I seem to have failed to reply to this.

I'm a bit confused about all this, I confess. What does xend do ?

Quoted 7 lines
Quoted 3 lines

ATM it seems that this change would mean that a guest config file specified in the most obvious way wouldn't get an emulated nic at all. That can't be right, can it ?

It's confusingly named.

IOEMU -> emulated only on HVM, meaningless on PV.

My understanding was that IOEMU meant both TAP and PV, and was only valid for HVM guests, and VIF meant PV only and was valid for both domain types?

I don't think this is right, this will mean VIF has a different meaning depending on the type of domain, which is quite annoying.

If this is right, I have to change my hotplug patches, but this will be a mess, because I have no way to tell if a domain is PV or HVM when plugging in the devices, so if VIF is passed for both PV or PV+TAP I will have no way of knowing that.

Should we create three different nic types? VIF (PV), IOEMU (TAP), HYBRID (PV+TAP)?

Quoted 6 lines

VIF -> both emulated and PV (on HVM) or just PV (on PV)

So a default of "VIF" is what you normally want.

Ian.

#30 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 4 lines

If this is right, I have to change my hotplug patches, but this will be a mess, because I have no way to tell if a domain is PV or HVM when plugging in the devices, so if VIF is passed for both PV or PV+TAP I will have no way of knowing that.

Hmmm.

Quoted 2 lines

Should we create three different nic types? VIF (PV), IOEMU (TAP), HYBRID (PV+TAP)?

I think this might be better. Or alternatively, always provide PV, and have a flag which says `do provide ioemu'.

I think it's very confusing if setting the type' to ioemu' rather than pv' means do provide pv but provide ioemu as well'.

Another way of looking at it is: if we wanted to provide some other interfaces (besides Xen PV and emulated PCI) in the future, would it be an alternative to PV or to PCI or something additional ?

Ian.

#31 lore raw

Re: [PATCH 11/13] libxl: set nic type to VIF by default

Quoted 6 lines · Ian Jackson

Roger Pau Monne writes ("Re: [Xen-devel] [PATCH 11/13] libxl: set nic type to VIF by default"):

Quoted 4 lines

If this is right, I have to change my hotplug patches, but this will be a mess, because I have no way to tell if a domain is PV or HVM when plugging in the devices, so if VIF is passed for both PV or PV+TAP I will have no way of knowing that.

Quoted 7 lines

Hmmm.

Quoted 2 lines

Should we create three different nic types? VIF (PV), IOEMU (TAP), HYBRID (PV+TAP)?

I think this might be better. Or alternatively, always provide PV, and have a flag which says `do provide ioemu'.

This looks reasonable given the current types of nic interfaces.

Quoted 7 lines

I think it's very confusing if setting the type' to ioemu' rather than pv' means do provide pv but provide ioemu as well'.

Another way of looking at it is: if we wanted to provide some other interfaces (besides Xen PV and emulated PCI) in the future, would it be an alternative to PV or to PCI or something additional ?

I have no idea, could someone shed some light on this?

#32 lore raw

PATCH 12/13 libxl: call hotplug scripts for disk devices from libxl

In reply to Roger Pau Monne

Since most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for disk devices, that should be called when the device is added or removed from a guest.

We will chain the launch of the disk hotplug scripts after the device_backend_callback callback, or directly from libxl__initiate_device_{add,remove} if the device is already in the desired state.

---
 tools/hotplug/Linux/xen-backend.rules     |    6 +-
 tools/hotplug/Linux/xen-hotplug-common.sh |    6 ++
 tools/libxl/Makefile                      |    3 +-
 tools/libxl/libxl_device.c                |   23 ++++-
 tools/libxl/libxl_hotplug.c               |   84 +++++++++++++++++++
 tools/libxl/libxl_internal.h              |   17 ++++
 tools/libxl/libxl_linux.c                 |  126 +++++++++++++++++++++++++++++
 7 files changed, 256 insertions(+), 9 deletions(-)
 create mode 100644 tools/libxl/libxl_hotplug.c
tools/hotplug/Linux/xen-backend.rules +3 -3
index 405387f..d55ff11 100644
@@ -1,11 +1,11 @@
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}"
-SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
+SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
 SUBSYSTEM=="xen", KERNEL=="blktap[0-9]*", NAME="xen/%k", MODE="0600"
 SUBSYSTEM=="blktap2", KERNEL=="blktap[0-9]*", NAME="xen/blktap-2/%k", MODE="0600"
tools/hotplug/Linux/xen-hotplug-common.sh +6 -0
index 8f6557d..4a7bc73 100644
@@ -15,6 +15,12 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
+# Hack to prevent the execution of hotplug scripts from udev if the domain
+# has been launched from libxl
+if [ -n "${UDEV_CALL}" ] && \
+   xenstore-read "libxl/disable_udev" >/dev/null 2>&1; then
+    exit 0
+fi
 
 dir=$(dirname "$0")
 . "$dir/hotplugpath.sh"
tools/libxl/Makefile +2 -1
index 5d9227e..9abadff 100644
@@ -66,7 +66,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
 			libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \
 			libxl_internal.o libxl_utils.o libxl_uuid.o \
 			libxl_json.o libxl_aoutils.o \
-			libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
+			libxl_qmp.o libxl_event.o libxl_fork.o libxl_hotplug.o \
+			$(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include $(XEN_ROOT)/tools/config.h
tools/libxl/libxl_device.c +18 -5
index 6b0ce95..0b7beb7 100644
@@ -380,6 +380,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
             flexarray_append(back, "params");
             flexarray_append(back, dev);
 
+            flexarray_append(back, "script");
+            flexarray_append(back, GCSPRINTF("%s/%s",
+                                             libxl__xen_script_dir_path(),
+                                             "block"));
+
             assert(device->backend_kind == LIBXL__DEVICE_KIND_VBD);
             break;
         case LIBXL_DISK_BACKEND_TAP:
@@ -393,6 +398,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t domid,
             flexarray_append(back, "tapdisk-params");
             flexarray_append(back, GCSPRINTF("%s:%s", format, disk->pdev_path));
 
+            flexarray_append(back, "script");
+            flexarray_append(back, GCSPRINTF("%s/%s",
+                                             libxl__xen_script_dir_path(),
+                                             "blktap"));
+
             /* now create a phy device to export the device to the guest */
             goto do_backend_phy;
         case LIBXL_DISK_BACKEND_QDISK:
@@ -760,7 +770,7 @@ out_fail:
 
 out_ok:
     assert(!rc);
-    aorm->callback(egc, aorm);
+    libxl__device_hotplug(egc, aorm);
     return;
 }
 
@@ -822,7 +832,7 @@ retry_transaction:
 
  out_ok:
     if (t) xs_transaction_end(ctx->xsh, t, 0);
-    aorm->callback(egc, aorm);
+    libxl__device_hotplug(egc, aorm);
     return;
 }
 
@@ -929,14 +939,17 @@ static void device_backend_callback(libxl__egc *egc, libxl__ev_devstate *ds,
     if (rc && aorm->action == DEVICE_CONNECT) {
         LOG(ERROR, "unable to connect device with path %s",
                    libxl__device_backend_path(gc, aorm->dev));
-        goto out;
+        goto error;
     } else if(rc) {
         LOG(DEBUG, "unable to disconnect device with path %s",
                    libxl__device_backend_path(gc, aorm->dev));
-        goto out;
+        goto error;
     }
 
-out:
+    libxl__device_hotplug(egc, aorm);
+    return;
+
+error:
     aorm->rc = rc;
     aorm->callback(egc, aorm);
     return;
tools/libxl/libxl_hotplug.c new file +84 -0

84 lines not on this page · raw message

tools/libxl/libxl_internal.h +17 -0
index 7969a43..5e2bac5 100644
@@ -72,6 +72,7 @@
 
 #define LIBXL_INIT_TIMEOUT 10
 #define LIBXL_DESTROY_TIMEOUT 10
+#define LIBXL_HOTPLUG_TIMEOUT 10
 #define LIBXL_DEVICE_MODEL_START_TIMEOUT 10
 #define LIBXL_XENCONSOLE_LIMIT 1048576
 #define LIBXL_XENCONSOLE_PROTOCOL "vt100"
@@ -1813,6 +1814,11 @@ struct libxl__ao_device {
     int rc;
     libxl__ev_devstate ds;
     void *base;
+    /* device hotplug execution */
+    pid_t pid;
+    char *what;
+    libxl__ev_time ev;
+    libxl__ev_child child;
 };
 
 /* Internal AO operation to connect a disk device */
@@ -1840,6 +1846,17 @@ _hidden void libxl__initiate_device_add(libxl__egc*, libxl__ao_device *aorm);
 _hidden void libxl__initiate_device_remove(libxl__egc *egc,
                                            libxl__ao_device *aorm);
 
+/*
+ * libxl__hotplug_launch is an internal function that should not be used
+ * directly, all hotplug script calls have to implement and use
+ * libxl__device_hotplug.
+ */
+_hidden void libxl__device_hotplug(libxl__egc *egc, libxl__ao_device *aorm);
+_hidden int libxl__hotplug_launch(libxl__gc *gc, libxl__ao_device *aorm,
+                                  const char *arg0, char *const args[],
+                                  char *const env[],
+                                  libxl__ev_child_callback *death);
+
 /*----- Domain destruction -----*/
 
 /* Domain destruction has been splitted in two functions:
tools/libxl/libxl_linux.c +126 -0

129 lines not on this page · raw message

Signature · 1 line
1.7.7.5 (Apple Git-26)
#33 lore raw

Re: [PATCH 12/13] libxl: call hotplug scripts for disk devices from libxl

Roger Pau Monne writes ("[PATCH 12/13] libxl: call hotplug scripts for disk devices from libxl"):

Quoted 78 lines

Since most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for disk devices, that should be called when the device is added or removed from a guest.

We will chain the launch of the disk hotplug scripts after the device_backend_callback callback, or directly from libxl__initiate_device_{add,remove} if the device is already in the desired state.

---
 tools/hotplug/Linux/xen-backend.rules     |    6 +-
 tools/hotplug/Linux/xen-hotplug-common.sh |    6 ++
 tools/libxl/Makefile                      |    3 +-
 tools/libxl/libxl_device.c                |   23 ++++-
 tools/libxl/libxl_hotplug.c               |   84 +++++++++++++++++++
 tools/libxl/libxl_internal.h              |   17 ++++
 tools/libxl/libxl_linux.c                 |  126 +++++++++++++++++++++++++++++
 7 files changed, 256 insertions(+), 9 deletions(-)
 create mode 100644 tools/libxl/libxl_hotplug.c
tools/hotplug/Linux/xen-backend.rules +3 -3
index 405387f..d55ff11 100644
@@ -1,11 +1,11 @@
-SUBSYSTEM=="xen-backend", KERNEL=="tap*", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vbd*", RUN+="/etc/xen/scripts/block $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/blktap $env{ACTION}"
+SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}"
-SUBSYSTEM=="xen-backend", ACTION=="remove", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
+SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
 SUBSYSTEM=="xen", KERNEL=="blktap[0-9]*", NAME="xen/%k", MODE="0600"
 SUBSYSTEM=="blktap2", KERNEL=="blktap[0-9]*", NAME="xen/blktap-2/%k", MODE="0600"
tools/hotplug/Linux/xen-hotplug-common.sh +6 -0
index 8f6557d..4a7bc73 100644
@@ -15,6 +15,12 @@
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
 
+# Hack to prevent the execution of hotplug scripts from udev if the domain
+# has been launched from libxl
+if [ -n "${UDEV_CALL}" ] && \
+   xenstore-read "libxl/disable_udev" >/dev/null 2>&1; then
+    exit 0
+fi
 
 dir=$(dirname "$0")
 . "$dir/hotplugpath.sh"
tools/libxl/Makefile +2 -1
index 5d9227e..9abadff 100644
@@ -66,7 +66,8 @@ LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \
                        libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \
                        libxl_internal.o libxl_utils.o libxl_uuid.o \
                        libxl_json.o libxl_aoutils.o \
-                       libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y)
+                       libxl_qmp.o libxl_event.o libxl_fork.o libxl_hotplug.o \
+                       $(LIBXL_OBJS-y)
 LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
 
 $(LIBXL_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenguest) $(CFLAGS_libxenstore) $(CFLAGS_libblktapctl) -include $(XEN_ROOT)/tools/config.h
tools/libxl/libxl_device.c +0 -0
index 6b0ce95..0b7beb7 100644

tools/libxl/libxl_device.c void libxl__device_disk_add(libxl__egc *egc, uint32_t dom> @@ -760,7 +770,7 @@ out_fail: · line 401

Quoted 5 lines
tools/libxl/libxl_device.c +1 -1
@@ -393,6 +398,11 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t dom> @@ -760,7 +770,7 @@ out_fail:
 
 out_ok:
     assert(!rc);
-    aorm->callback(egc, aorm);
+    libxl__device_hotplug(egc, aorm);

Where does the name "aorm" come from here ? It doesn't seem to involve removal.

tools/libxl/libxl_device.c void libxl__device_disk_add(libxl__egc *egc, uint32_t dom> @@ -760,7 +770,7 @@ out_fail: · line 402

Quoted 1 line
tools/libxl/libxl_device.c +1 -0
+int libxl__hotplug_launch(libxl__gc *gc, libxl__ao_device *aorm,

Ie shouldn't that be "aodev" or something ?

Quoted 14 lines
tools/libxl/libxl_device.c +14 -0
+/* Hotplug scripts helpers */
+
+static void cleanup(libxl__gc *gc, libxl__ao_device *aorm)
+{
+    if (!aorm) return;
+    libxl__ev_time_deregister(gc, &aorm->ev);
+}
+
+static void callback(libxl__egc *egc, libxl__ev_child *child,
+                                    pid_t pid, int status)
+{
+    libxl__ao_device *aorm = CONTAINER_OF(child, *aorm, child);
+    STATE_AO_GC(aorm->ao);
+

tools/libxl/libxl_device.c void libxl__device_disk_add(libxl__egc *egc, uint32_t dom> @@ -760,7 +770,7 @@ out_fail:

Quoted 10 lines
tools/libxl/libxl_device.c +10 -0
+    cleanup(gc, aorm);
+
+    if (status) {
+        libxl_report_child_exitstatus(CTX, aorm->rc ? LIBXL__LOG_ERROR
+                                                    : LIBXL__LOG_WARNING,
+                                      aorm->what, pid, status);
+        aorm->rc = ERROR_FAIL;
+    }
+    aorm->callback(egc, aorm);
+}

This structure where half of the event handling is in the common code and half of it is in libxl_linux.c is not really appropriate. It means that the hotplug event machinery is not all in the same place.

Can you make an interface to libxl_linux.c which is fully synchronous, so that libxl_linux.c simply says whether to run the script or not ?

Eg
libxl__get_hotplug_script_info(libxl__egc *, libxl__device *dev,

                                    char ***args, char ***env);

Ian.

#34 lore raw

PATCH 13/13 libxl: call hotplug scripts for nic devices from libxl

In reply to Roger Pau Monne

Since most of the needed work is already done in previous patches, this patch only contains the necessary code to call hotplug scripts for nic devices, that should be called when the device is added or removed from a guest.

Since the call to libxl__device_hotplug is already there, this patch only adds the necessary code to this function to handle the vif case, and the necessary modification in the udev rules.

---
 tools/hotplug/Linux/xen-backend.rules |    6 +-
 tools/libxl/libxl_internal.h          |    1 +
 tools/libxl/libxl_linux.c             |  130 ++++++++++++++++++++++++++++++++-
 3 files changed, 133 insertions(+), 4 deletions(-)
tools/hotplug/Linux/xen-backend.rules +3 -3
index d55ff11..c591a3f 100644
@@ -2,8 +2,8 @@ SUBSYSTEM=="xen-backend", KERNEL=="tap*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scr
 SUBSYSTEM=="xen-backend", KERNEL=="vbd*", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/block $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vtpm*", RUN+="/etc/xen/scripts/vtpm $env{ACTION}"
 SUBSYSTEM=="xen-backend", KERNEL=="vif2-*", RUN+="/etc/xen/scripts/vif2 $env{ACTION}"
-SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
-SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ENV{UDEV_CALL}="1", ACTION=="online", RUN+="/etc/xen/scripts/vif-setup online type_if=vif"
+SUBSYSTEM=="xen-backend", KERNEL=="vif-*", ENV{UDEV_CALL}="1", ACTION=="offline", RUN+="/etc/xen/scripts/vif-setup offline type_if=vif"
 SUBSYSTEM=="xen-backend", KERNEL=="vscsi*", RUN+="/etc/xen/scripts/vscsi $env{ACTION}"
 SUBSYSTEM=="xen-backend", ACTION=="remove", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/xen-hotplug-cleanup"
 KERNEL=="evtchn", NAME="xen/%k"
@@ -13,4 +13,4 @@ KERNEL=="blktap-control", NAME="xen/blktap-2/control", MODE="0600"
 KERNEL=="gntdev", NAME="xen/%k", MODE="0600"
 KERNEL=="pci_iomul", NAME="xen/%k", MODE="0600"
 KERNEL=="tapdev[a-z]*", NAME="xen/blktap-2/tapdev%m", MODE="0600"
-SUBSYSTEM=="net", KERNEL=="vif*-emu", ACTION=="add", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
+SUBSYSTEM=="net", KERNEL=="vif*-emu", ACTION=="add", ENV{UDEV_CALL}="1", RUN+="/etc/xen/scripts/vif-setup $env{ACTION} type_if=tap"
tools/libxl/libxl_internal.h +1 -0
index 5e2bac5..b5002db 100644
@@ -1817,6 +1817,7 @@ struct libxl__ao_device {
     /* device hotplug execution */
     pid_t pid;
     char *what;
+    int vif_executed;
     libxl__ev_time ev;
     libxl__ev_child child;
 };
tools/libxl/libxl_linux.c +129 -1

167 lines not on this page · raw message

Signature · 1 line
1.7.7.5 (Apple Git-26)