diff mbox

[11/28] libxl: emuids: Pass correct emuid to internal functions

Message ID 1450809903-3393-12-git-send-email-ian.jackson@eu.citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Jackson Dec. 22, 2015, 6:44 p.m. UTC
Provide EMUID_PV and use it appropriately.  We split our qemus into
two:

EMUID_DM does actual emulation.  EMUID_PV is for PV backends.  Most
places relate to emulation and can simply pass EMUID_DM.

Creation is a notable exception, where we pass the emuid as a new
parameter to the spawn functions.

There is no overall functional change, because the ultimate consumer,
libxl__device_model_xs_path, does not pay any attention to the
parameter yet, and because we still need to plumb the emuid through to
the qemu argument construction.

Also, domain destruction does not yet pass the right emuid.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com
---
v6: Largely rewritten, but in some sense (at least conceptually)
    based on a similar concept in v5.
---
 tools/libxl/libxl_create.c   |   11 ++++++-----
 tools/libxl/libxl_dm.c       |   16 +++++++++-------
 tools/libxl/libxl_internal.c |    3 +--
 tools/libxl/libxl_internal.h |   15 +++++++++++----
 4 files changed, 27 insertions(+), 18 deletions(-)
diff mbox

Patch

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 1af7066..41ece5a 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -1309,10 +1309,11 @@  static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         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);
-        else
-            libxl__spawn_local_dm(egc, &dcs->dmss.dm);
+        if (libxl_defbool_val(d_config->b_info.device_model_stubdomain)) {
+            libxl__spawn_stub_dm(egc, &dcs->dmss, EMUID_DM);
+        } else {
+            libxl__spawn_local_dm(egc, &dcs->dmss.dm, EMUID_DM);
+        }
 
         /*
          * Handle the domain's (and the related stubdomain's) access to
@@ -1348,7 +1349,7 @@  static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
 
         if (need_qemu) {
             dcs->dmss.dm.guest_domid = domid;
-            libxl__spawn_local_dm(egc, &dcs->dmss.dm);
+            libxl__spawn_local_dm(egc, &dcs->dmss.dm, EMUID_PV);
             return;
         } else {
             assert(!dcs->dmss.dm.guest_domid);
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 593f3e6..1e1dfa0 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -1434,7 +1434,8 @@  char *libxl__stub_dm_name(libxl__gc *gc, const char *guest_name)
     return GCSPRINTF("%s-dm", guest_name);
 }
 
-void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
+void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss,
+                          int emuid)
 {
     STATE_AO_GC(sdss->dm.spawn.ao);
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -1558,7 +1559,7 @@  void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
 retry_transaction:
     t = xs_transaction_start(ctx->xsh);
     const char *dmpath = libxl__device_model_xs_path(gc,
-            dm_domid, guest_domid, EMUID_DM, "");
+            dm_domid, guest_domid, emuid, "");
     xs_mkdir(ctx->xsh, t, dmpath);
     xs_set_permissions(ctx->xsh, t,
                        dmpath,
@@ -1668,7 +1669,7 @@  static void spawn_stub_launch_dm(libxl__egc *egc,
     sdss->pvqemu.build_state = &sdss->dm_state;
     sdss->pvqemu.callback = spawn_stubdom_pvqemu_cb;
 
-    libxl__spawn_local_dm(egc, &sdss->pvqemu);
+    libxl__spawn_local_dm(egc, &sdss->pvqemu, EMUID_PV);
 
     return;
 
@@ -1724,7 +1725,7 @@  static void stubdom_pvqemu_cb(libxl__egc *egc,
                                   dm_domid, sdss->dm.guest_domid);
     sdss->xswait.path =
         libxl__device_model_xs_path(gc, dm_domid, sdss->dm.guest_domid,
-                                    EMUID_DM, "/state");
+                                    EMUID_PV, "/state");
     sdss->xswait.timeout_ms = LIBXL_STUBDOM_START_TIMEOUT * 1000;
     sdss->xswait.callback = stubdom_xswait_cb;
     rc = libxl__xswait_start(gc, &sdss->xswait);
@@ -1771,7 +1772,8 @@  static void device_model_spawn_outcome(libxl__egc *egc,
                                        libxl__dm_spawn_state *dmss,
                                        int rc);
 
-void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
+void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss,
+                           int emuid)
 {
     /* convenience aliases */
     const int domid = dmss->guest_domid;
@@ -1832,7 +1834,7 @@  void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
     }
 
     path = libxl__device_model_xs_path(gc, LIBXL_TOOLSTACK_DOMID,
-                                       domid, EMUID_DM, "");
+                                       domid, emuid, "");
     xs_mkdir(ctx->xsh, XBT_NULL, path);
 
     if (b_info->type == LIBXL_DOMAIN_TYPE_HVM &&
@@ -1887,7 +1889,7 @@  retry_transaction:
 
     spawn->what = GCSPRINTF("domain %d device model", domid);
     spawn->xspath = libxl__device_model_xs_path(gc, LIBXL_TOOLSTACK_DOMID,
-                                                domid, EMUID_DM, "/state");
+                                                domid, emuid, "/state");
     spawn->timeout_ms = LIBXL_DEVICE_MODEL_START_TIMEOUT * 1000;
     spawn->pidpath = GCSPRINTF("%s/image/device-model-pid", dom_path);
     spawn->midproc_cb = libxl__spawn_record_pid;
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index ec93797..843fdbf 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -554,8 +554,7 @@  void libxl__update_domain_configuration(libxl__gc *gc,
 }
 
 char *libxl__device_model_xs_path(libxl__gc *gc, uint32_t dm_domid,
-                                  uint32_t domid,
-                                  struct dummy_qemu_emulator_id emuid,
+                                  uint32_t domid, int emuid,
                                   const char *format,  ...)
 {
     char *s, *fmt;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index ea56cda..71c1e17 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -1956,10 +1956,15 @@  _hidden int libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);
   /* Return the system-wide default device model */
 _hidden libxl_device_model_version libxl__default_device_model(libxl__gc *gc);
 
-static const struct dummy_qemu_emulator_id { int x; } EMUID_DM;
+enum {
+    EMUID_PV,
+    EMUID_DM,
+    /* NB stubdom and its PV service domain not recorded here */
+};
+
 _hidden char *libxl__device_model_xs_path(libxl__gc *gc,
         uint32_t dm_domid,
-        uint32_t domid, struct dummy_qemu_emulator_id,
+        uint32_t domid, int emuid,
         const char *format, ...) PRINTF_ATTRIBUTE(5, 6);
 
 /*
@@ -3399,7 +3404,8 @@  struct libxl__dm_spawn_state {
     libxl__dm_spawn_cb *callback;
 };
 
-_hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*);
+_hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*,
+                                   int emuid);
 
 /* Stubdom device models. */
 
@@ -3418,7 +3424,8 @@  typedef struct {
     libxl__xswait_state xswait;
 } libxl__stub_dm_spawn_state;
 
-_hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*);
+_hidden void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state*,
+                                  int emuid);
 
 _hidden char *libxl__stub_dm_name(libxl__gc *gc, const char * guest_name);