aboutsummaryrefslogtreecommitdiffstats
path: root/tools/libxl/libxl_device.c
diff options
context:
space:
mode:
authorRoger Pau Monne <roger.pau@citrix.com>2012-07-26 16:47:30 +0100
committerRoger Pau Monne <roger.pau@citrix.com>2012-07-26 16:47:30 +0100
commit962eb2acbb8af50f8cddc28ad4479fe9661ab65c (patch)
treee92990633073eb3d7c9ee42b7223919731c51188 /tools/libxl/libxl_device.c
parent6c80432517e30bfe178981b1939b17bea6e2f434 (diff)
downloadxen-962eb2acbb8af50f8cddc28ad4479fe9661ab65c.tar.gz
xen-962eb2acbb8af50f8cddc28ad4479fe9661ab65c.tar.bz2
xen-962eb2acbb8af50f8cddc28ad4479fe9661ab65c.zip
libxl: convert libxl_device_disk_add to an async op
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 later 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. Signed-off-by: Roger Pau Monne <roger.pau@citrix.com> Acked-by: Ian Jackson <ian.jackson@eu.citrix.com> [ ijc -- drop hunk modifying libxl_cdrom_insert which is not needed after 25670:3666e9712eaf "libxl: make libxl_cdrom_insert async" ] Committed-by: Ian Campbell <ian.campbell@citrix.com>
Diffstat (limited to 'tools/libxl/libxl_device.c')
-rw-r--r--tools/libxl/libxl_device.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 2429836046..835b4ad235 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -447,6 +447,37 @@ void libxl__ao_devices_callback(libxl__egc *egc, libxl__ao_device *aodev)
return;
}
+/******************************************************************************/
+
+/* Macro for defining the functions that will add a bunch of disks when
+ * inside an async op.
+ * This macro is added to prevent repetition of code.
+ *
+ * The following functions are defined:
+ * libxl__add_disks
+ */
+
+#define DEFINE_DEVICES_ADD(type) \
+ void libxl__add_##type##s(libxl__egc *egc, libxl__ao *ao, uint32_t domid, \
+ int start, libxl_domain_config *d_config, \
+ libxl__ao_devices *aodevs) \
+ { \
+ AO_GC; \
+ int i; \
+ int end = start + d_config->num_##type##s; \
+ for (i = start; i < end; i++) { \
+ aodevs->array[i].callback = libxl__ao_devices_callback; \
+ libxl__device_##type##_add(egc, domid, &d_config->type##s[i-start],\
+ &aodevs->array[i]); \
+ } \
+ }
+
+DEFINE_DEVICES_ADD(disk)
+
+#undef DEFINE_DEVICES_ADD
+
+/******************************************************************************/
+
int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
{
char *be_path = libxl__device_backend_path(gc, dev);
@@ -593,6 +624,52 @@ static void device_backend_cleanup(libxl__gc *gc,
static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev);
+void libxl__wait_device_connection(libxl__egc *egc, libxl__ao_device *aodev)
+{
+ STATE_AO_GC(aodev->ao);
+ char *be_path = libxl__device_backend_path(gc, aodev->dev);
+ char *state_path = libxl__sprintf(gc, "%s/state", be_path);
+ libxl_dominfo info;
+ uint32_t domid = aodev->dev->domid;
+ int rc = 0;
+
+ libxl_dominfo_init(&info);
+ rc = libxl_domain_info(CTX, &info, domid);
+ if (rc) {
+ LOG(ERROR, "unable to get info for domain %d", domid);
+ goto out;
+ }
+ if (QEMU_BACKEND(aodev->dev)) {
+ /*
+ * If Qemu is not running, there's no point in waiting for
+ * it to change the state of the device.
+ *
+ * If Qemu is running, it will set the state of the device to
+ * 4 directly, without waiting in state 2 for any hotplug execution.
+ */
+ device_hotplug_done(egc, aodev);
+ return;
+ }
+
+ rc = libxl__ev_devstate_wait(gc, &aodev->backend_ds,
+ device_backend_callback,
+ state_path, XenbusStateInitWait,
+ LIBXL_INIT_TIMEOUT * 1000);
+ if (rc) {
+ LOG(ERROR, "unable to initialize device %s", be_path);
+ goto out;
+ }
+
+ libxl_dominfo_dispose(&info);
+ return;
+
+out:
+ aodev->rc = rc;
+ libxl_dominfo_dispose(&info);
+ device_hotplug_done(egc, aodev);
+ return;
+}
+
void libxl__initiate_device_remove(libxl__egc *egc,
libxl__ao_device *aodev)
{