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

[Xen-devel] [PATCH v11 14/17] libxl: convert libxl_device_vkb_add to an async operation



Split libxl_device_vkb_add into libxl__device_vkb_add (to be used
inside already running ao's), and make libxl_device_vkb_add a stub to
call libxl__device_vkb_add.

Changes since v9:

 * Fixed Ocaml bindings.

 * Don't abort if num_vkbs > 0.

Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxx>
---
 tools/libxl/libxl.c                  |   26 +++++++++++++++++++-------
 tools/libxl/libxl.h                  |    3 ++-
 tools/libxl/libxl_create.c           |   18 ++++++++++--------
 tools/libxl/libxl_device.c           |    2 ++
 tools/libxl/libxl_dm.c               |    9 ++++-----
 tools/libxl/libxl_internal.h         |    9 +++++++++
 tools/ocaml/libs/xl/xenlight_stubs.c |    2 +-
 7 files changed, 47 insertions(+), 22 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index ec07b8d..de36f43 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2837,12 +2837,13 @@ static int libxl__device_from_vkb(libxl__gc *gc, 
uint32_t domid,
     return 0;
 }
 
-int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb)
+void libxl__device_vkb_add(libxl__egc *egc, uint32_t domid,
+                           libxl_device_vkb *vkb, libxl__ao_device *aodev)
 {
-    GC_INIT(ctx);
+    STATE_AO_GC(aodev->ao);
     flexarray_t *front;
     flexarray_t *back;
-    libxl__device device;
+    libxl__device *device;
     int rc;
 
     rc = libxl__device_vkb_setdefault(gc, vkb);
@@ -2859,7 +2860,8 @@ int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, 
libxl_device_vkb *vkb)
         goto out_free;
     }
 
-    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_free;
 
     flexarray_append(back, "frontend-id");
@@ -2876,16 +2878,22 @@ int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t 
domid, libxl_device_vkb *vkb)
     flexarray_append(front, "state");
     flexarray_append(front, libxl__sprintf(gc, "%d", 1));
 
-    libxl__device_generic_add(gc, XBT_NULL, &device,
+    libxl__device_generic_add(gc, XBT_NULL, device,
                              libxl__xs_kvs_of_flexarray(gc, back, back->count),
                              libxl__xs_kvs_of_flexarray(gc, front, 
front->count));
+
+    aodev->dev = device;
+    aodev->action = DEVICE_CONNECT;
+    libxl__wait_device_connection(egc, aodev);
+
     rc = 0;
 out_free:
     flexarray_free(back);
     flexarray_free(front);
 out:
-    GC_FREE;
-    return rc;
+    aodev->rc = rc;
+    if (rc) aodev->callback(egc, aodev);
+    return;
 }
 
 
/******************************************************************************/
@@ -3052,6 +3060,7 @@ DEFINE_DEVICE_REMOVE(vfb, destroy, 1)
 /* The following functions are defined:
  * libxl_device_disk_add
  * libxl_device_nic_add
+ * libxl_device_vkb_add
  */
 
 #define DEFINE_DEVICE_ADD(type)                                         \
@@ -3078,6 +3087,9 @@ DEFINE_DEVICE_ADD(disk)
 /* nic */
 DEFINE_DEVICE_ADD(nic)
 
+/* vkb */
+DEFINE_DEVICE_ADD(vkb)
+
 #undef DEFINE_DEVICE_ADD
 
 
/******************************************************************************/
diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h
index d548090..84d4efd 100644
--- a/tools/libxl/libxl.h
+++ b/tools/libxl/libxl.h
@@ -710,7 +710,8 @@ int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid,
                               libxl_device_nic *nic, libxl_nicinfo *nicinfo);
 
 /* Keyboard */
-int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb 
*vkb);
+int libxl_device_vkb_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vkb *vkb,
+                         const libxl_asyncop_how *ao_how);
 int libxl_device_vkb_remove(libxl_ctx *ctx, uint32_t domid,
                             libxl_device_vkb *vkb,
                             const libxl_asyncop_how *ao_how);
diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index fc112ce..28b6101 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -907,10 +907,18 @@ static void domcreate_rebuild_done(libxl__egc *egc,
 
     store_libxl_entry(gc, domid, &d_config->b_info);
 
-    dcs->aodevs.size = d_config->num_disks;
+    if (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM && !d_config->num_vkbs) 
{
+        d_config->vkbs = libxl__zalloc(NOGC, sizeof(*d_config->vkbs));
+        libxl_device_vkb_init(&d_config->vkbs[0]);
+        d_config->num_vkbs = 1;
+    }
+
+    dcs->aodevs.size = d_config->num_disks + d_config->num_vkbs;
     dcs->aodevs.callback = domcreate_launch_dm;
     libxl__prepare_ao_devices(ao, &dcs->aodevs);
     libxl__add_disks(egc, ao, domid, 0, d_config, &dcs->aodevs);
+    libxl__add_vkbs(egc, ao, domid, d_config->num_disks, d_config,
+                    &dcs->aodevs);
 
     return;
 
@@ -933,7 +941,7 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__ao_devices *aodevs,
     libxl_ctx *const ctx = CTX;
 
     if (ret) {
-        LOG(ERROR, "unable to add disk devices");
+        LOG(ERROR, "unable to add misc devices");
         goto error_out;
     }
     for (i = 0; i < d_config->num_nics; i++) {
@@ -947,7 +955,6 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__ao_devices *aodevs,
     case LIBXL_DOMAIN_TYPE_HVM:
     {
         libxl__device_console console;
-        libxl_device_vkb vkb;
 
         ret = init_console_info(&console, 0);
         if ( ret )
@@ -955,10 +962,6 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__ao_devices *aodevs,
         libxl__device_console_add(gc, domid, &console, state);
         libxl__device_console_dispose(&console);
 
-        libxl_device_vkb_init(&vkb);
-        libxl_device_vkb_add(ctx, domid, &vkb);
-        libxl_device_vkb_dispose(&vkb);
-
         dcs->dmss.dm.guest_domid = domid;
         if (libxl_defbool_val(d_config->b_info.device_model_stubdomain))
             libxl__spawn_stub_dm(egc, &dcs->dmss);
@@ -973,7 +976,6 @@ static void domcreate_launch_dm(libxl__egc *egc, 
libxl__ao_devices *aodevs,
 
         for (i = 0; i < d_config->num_vfbs; i++) {
             libxl_device_vfb_add(ctx, domid, &d_config->vfbs[i]);
-            libxl_device_vkb_add(ctx, domid, &d_config->vkbs[i]);
         }
 
         ret = init_console_info(&console, 0);
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index cd51677..c851565 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -482,6 +482,7 @@ void libxl__ao_devices_callback(libxl__egc *egc, 
libxl__ao_device *aodev)
  * The following functions are defined:
  * libxl__add_disks
  * libxl__add_nics
+ * libxl__add_vkbs
  */
 
 #define DEFINE_DEVICES_ADD(type)                                               
\
@@ -501,6 +502,7 @@ void libxl__ao_devices_callback(libxl__egc *egc, 
libxl__ao_device *aodev)
 
 DEFINE_DEVICES_ADD(disk)
 DEFINE_DEVICES_ADD(nic)
+DEFINE_DEVICES_ADD(vkb)
 
 #undef DEFINE_DEVICES_ADD
 
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 4b0ea7e..c37a07f 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -862,10 +862,12 @@ retry_transaction:
         if (errno == EAGAIN)
             goto retry_transaction;
 
-    sdss->aodevs.size = dm_config->num_disks;
+    sdss->aodevs.size = dm_config->num_disks + dm_config->num_vkbs;
     sdss->aodevs.callback = spawn_stub_launch_dm;
     libxl__prepare_ao_devices(ao, &sdss->aodevs);
     libxl__add_disks(egc, ao, dm_domid, 0, dm_config, &sdss->aodevs);
+    libxl__add_vkbs(egc, ao, dm_domid, dm_config->num_disks, dm_config,
+                    &sdss->aodevs);
 
     free(args);
     return;
@@ -895,7 +897,7 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
     uint32_t dm_domid = sdss->pvqemu.guest_domid;
 
     if (ret) {
-        LOG(ERROR, "error connecting disk devices");
+        LOG(ERROR, "error connecting misc devices");
         goto out;
      }
 
@@ -909,9 +911,6 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
     ret = libxl_device_vfb_add(ctx, dm_domid, &dm_config->vfbs[0]);
     if (ret)
         goto out;
-    ret = libxl_device_vkb_add(ctx, dm_domid, &dm_config->vkbs[0]);
-    if (ret)
-        goto out;
 
     if (guest_config->b_info.u.hvm.serial)
         num_console++;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index be6ca49..d1a6ced 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1909,6 +1909,11 @@ _hidden void libxl__device_nic_add(libxl__egc *egc, 
uint32_t domid,
                                    libxl_device_nic *nic,
                                    libxl__ao_device *aodev);
 
+/* AO operation to connect a vkb device */
+_hidden void libxl__device_vkb_add(libxl__egc *egc, uint32_t domid,
+                                   libxl_device_vkb *vkb,
+                                   libxl__ao_device *aodev);
+
 /* Waits for the passed device to reach state XenbusStateInitWait.
  * This is not really useful by itself, but is important when executing
  * hotplug scripts, since we need to be sure the device is in the correct
@@ -2329,6 +2334,10 @@ _hidden void libxl__add_nics(libxl__egc *egc, libxl__ao 
*ao, uint32_t domid,
                              int start, libxl_domain_config *d_config,
                              libxl__ao_devices *aodevs);
 
+_hidden void libxl__add_vkbs(libxl__egc *egc, libxl__ao *ao, uint32_t domid,
+                             int start, libxl_domain_config *d_config,
+                             libxl__ao_devices *aodevs);
+
 /*----- device model creation -----*/
 
 /* First layer; wraps libxl__spawn_spawn. */
diff --git a/tools/ocaml/libs/xl/xenlight_stubs.c 
b/tools/ocaml/libs/xl/xenlight_stubs.c
index 0e9c65e..3d2493b 100644
--- a/tools/ocaml/libs/xl/xenlight_stubs.c
+++ b/tools/ocaml/libs/xl/xenlight_stubs.c
@@ -315,7 +315,7 @@ value stub_xl_device_vkb_add(value info, value domid)
        device_vkb_val(&gc, &lg, &c_info, info);
 
        INIT_CTX();
-       ret = libxl_device_vkb_add(ctx, Int_val(domid), &c_info);
+       ret = libxl_device_vkb_add(ctx, Int_val(domid), &c_info, 0);
        if (ret != 0)
                failwith_xl("vkb_add", &lg);
        FREE_CTX();
-- 
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®.