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

[Xen-devel] [PATCH v3 4/7] libxl: chain prepare and attach in libxl_device_disk_add



Chaining the prepare and attach functions in the public
libxl_device_disk_add allows libxl to keep the same public API while
allowing hotplug scripts v2 to be used.

libxl takes care of detecting the hotplug version of the script and
executing the necessary actions.

Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxx>
---
Changes since v1:
 * Remove public _prepare/_unprepare functions and do all the logic
   inside libxl_device_disk_add, this prevents an API change.
---
 tools/libxl/libxl.c |   37 +++++++++++++++++++++++++++++++++----
 1 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 444e039..32e2696 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2307,6 +2307,39 @@ void libxl__device_disk_add(libxl__egc *egc, uint32_t 
domid,
     device_disk_add(egc, domid, disk, aodev, NULL, NULL);
 }
 
+/* Callbacks for device_disk_add */
+
+static void device_disk_add_prepared(libxl__egc *, libxl__ao_device *);
+
+int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid,
+                          libxl_device_disk *disk,
+                          const libxl_asyncop_how *ao_how)
+{
+    AO_CREATE(ctx, domid, ao_how);
+    libxl__ao_device *aodev;
+
+    GCNEW(aodev);
+    libxl__prepare_ao_device(ao, aodev);
+    aodev->callback = device_disk_add_prepared;
+    aodev->disk = disk;
+    libxl__device_disk_prepare(egc, domid, disk, aodev);
+
+    return AO_INPROGRESS;
+}
+
+static void device_disk_add_prepared(libxl__egc *egc, libxl__ao_device *aodev)
+{
+    if (aodev->rc) {
+        device_addrm_aocomplete(egc, aodev);
+        return;
+    }
+
+    aodev->hotplug.num_exec = 0;
+    aodev->callback = device_addrm_aocomplete;
+    libxl__device_disk_add(egc, aodev->dev->domid, aodev->disk, aodev);
+    return;
+}
+
 static int libxl__device_disk_from_xs_be(libxl__gc *gc,
                                          const char *be_path,
                                          libxl_device_disk *disk)
@@ -3558,7 +3591,6 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
 /* Macro for defining device addition functions in a compact way */
 /* The following functions are defined:
- * libxl_device_disk_add
  * libxl_device_nic_add
  * libxl_device_vtpm_add
  */
@@ -3581,9 +3613,6 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1)
 
 /* Define alladd functions and undef the macro */
 
-/* disk */
-DEFINE_DEVICE_ADD(disk)
-
 /* nic */
 DEFINE_DEVICE_ADD(nic)
 
-- 
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.