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

[Xen-devel] [PATCH 19 of 32 RFC] libxl: move "saved_state" to libxl__domain_build_state



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1326384100 0
# Node ID c7160a835d3c01b6317551faac90bee4f5b4601c
# Parent  ff41e5fc0f12450cd836ce1466c0c51ab685e04b
libxl: move "saved_state" to libxl__domain_build_state.

This is internal to the library and need not be exposed to the user.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r ff41e5fc0f12 -r c7160a835d3c tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Thu Jan 12 15:57:08 2012 +0000
+++ b/tools/libxl/libxl_create.c        Thu Jan 12 16:01:40 2012 +0000
@@ -281,9 +281,8 @@ static int domain_restore(libxl__gc *gc,
     if (ret)
         goto out;
 
-    dm_info->saved_state = NULL;
     if (info->type == LIBXL_DOMAIN_TYPE_HVM) {
-        ret = asprintf(&dm_info->saved_state,
+        ret = asprintf(&state->saved_state,
                        XC_DEVICE_MODEL_RESTORE_FILE".%d", domid);
         ret = (ret < 0) ? ERROR_FAIL : 0;
     }
@@ -499,13 +498,11 @@ static int do_domain_create(libxl__gc *g
         }
     }
 
+    memset(&state, 0, sizeof(state));
+
     if ( restore_fd >= 0 ) {
         ret = domain_restore(gc, &d_config->b_info, domid, restore_fd, &state, 
dm_info);
     } else {
-        if (dm_info->saved_state) {
-            free(dm_info->saved_state);
-            dm_info->saved_state = NULL;
-        }
         ret = libxl__domain_build(gc, &d_config->b_info, dm_info, domid, 
&state);
     }
 
@@ -555,7 +552,7 @@ static int do_domain_create(libxl__gc *g
 
         dm_info->domid = domid;
         ret = libxl__create_device_model(gc, d_config, dm_info,
-                                        &dm_starting);
+                                         &state, &dm_starting);
         if (ret < 0) {
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
                        "failed to create device model: %d", ret);
@@ -592,8 +589,8 @@ static int do_domain_create(libxl__gc *g
             /* only copy those useful configs */
             memset((void*)&xenpv_dm_info, 0, sizeof(libxl_device_model_info));
 
-            libxl__create_xenpv_qemu(gc, domid,
-                                     d_config, &xenpv_dm_info, &dm_starting);
+            libxl__create_xenpv_qemu(gc, domid, d_config,
+                                     &xenpv_dm_info, &state, &dm_starting);
         }
         break;
     }
@@ -607,7 +604,7 @@ static int do_domain_create(libxl__gc *g
             == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
             libxl__qmp_initializations(ctx, domid);
         }
-        ret = libxl__confirm_device_model_startup(gc, dm_info, dm_starting);
+        ret = libxl__confirm_device_model_startup(gc, &state, dm_starting);
         if (ret < 0) {
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
                        "device model did not start: %d", ret);
diff -r ff41e5fc0f12 -r c7160a835d3c tools/libxl/libxl_dm.c
--- a/tools/libxl/libxl_dm.c    Thu Jan 12 15:57:08 2012 +0000
+++ b/tools/libxl/libxl_dm.c    Thu Jan 12 16:01:40 2012 +0000
@@ -119,7 +119,8 @@ static const char *dm_keymap(const libxl
 static char ** libxl__build_device_model_args_old(libxl__gc *gc,
                                         const char *dm,
                                         const libxl_domain_config 
*guest_config,
-                                        const libxl_device_model_info *info)
+                                        const libxl_device_model_info *info,
+                                        const libxl__domain_build_state *state)
 {
     const libxl_domain_create_info *c_info = &guest_config->c_info;
     const libxl_domain_build_info *b_info = &guest_config->b_info;
@@ -256,8 +257,8 @@ static char ** libxl__build_device_model
             flexarray_append(dm_args, "-nographic");
     }
 
-    if (info->saved_state) {
-        flexarray_vappend(dm_args, "-loadvm", info->saved_state, NULL);
+    if (state->saved_state) {
+        flexarray_vappend(dm_args, "-loadvm", state->saved_state, NULL);
     }
     for (i = 0; b_info->extra && b_info->extra[i] != NULL; i++)
         flexarray_append(dm_args, b_info->extra[i]);
@@ -329,7 +330,8 @@ static char *dm_spice_options(libxl__gc 
 static char ** libxl__build_device_model_args_new(libxl__gc *gc,
                                         const char *dm,
                                         const libxl_domain_config 
*guest_config,
-                                        const libxl_device_model_info *info)
+                                        const libxl_device_model_info *info,
+                                        const libxl__domain_build_state *state)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     const libxl_domain_create_info *c_info = &guest_config->c_info;
@@ -497,9 +499,9 @@ static char ** libxl__build_device_model
         }
     }
 
-    if (info->saved_state) {
+    if (state->saved_state) {
         /* This file descriptor is meant to be used by QEMU */
-        int migration_fd = open(info->saved_state, O_RDONLY);
+        int migration_fd = open(state->saved_state, O_RDONLY);
         flexarray_append(dm_args, "-incoming");
         flexarray_append(dm_args, libxl__sprintf(gc, "fd:%d", migration_fd));
     }
@@ -589,15 +591,16 @@ static char ** libxl__build_device_model
 static char ** libxl__build_device_model_args(libxl__gc *gc,
                                         const char *dm,
                                         const libxl_domain_config 
*guest_config,
-                                        const libxl_device_model_info *info)
+                                        const libxl_device_model_info *info,
+                                        const libxl__domain_build_state *state)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
 
     switch (guest_config->b_info.device_model_version) {
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL:
-        return libxl__build_device_model_args_old(gc, dm, guest_config, info);
+        return libxl__build_device_model_args_old(gc, dm, guest_config, info, 
state);
     case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
-        return libxl__build_device_model_args_new(gc, dm, guest_config, info);
+        return libxl__build_device_model_args_new(gc, dm, guest_config, info, 
state);
     default:
         LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "unknown device model version 
%d",
                          guest_config->b_info.device_model_version);
@@ -680,6 +683,7 @@ retry_transaction:
 static int libxl__create_stubdom(libxl__gc *gc,
                                  libxl_domain_config *guest_config,
                                  libxl_device_model_info *info,
+                                 libxl__domain_build_state *d_state,
                                  libxl__spawner_starting **starting_r)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -688,7 +692,7 @@ static int libxl__create_stubdom(libxl__
     libxl_domain_config dm_config;
     libxl_device_vfb vfb;
     libxl_device_vkb vkb;
-    libxl__domain_build_state state;
+    libxl__domain_build_state stubdom_state;
     uint32_t domid;
     char **args;
     struct xs_permissions perm[2];
@@ -746,12 +750,12 @@ static int libxl__create_stubdom(libxl__
     ret = libxl__domain_make(gc, &dm_config.c_info, &domid);
     if (ret)
         goto out;
-    ret = libxl__domain_build(gc, &dm_config.b_info, info, domid, &state);
+    ret = libxl__domain_build(gc, &dm_config.b_info, info, domid, 
&stubdom_state);
     if (ret)
         goto out;
 
     args = libxl__build_device_model_args(gc, "stubdom-dm",
-                                          guest_config, info);
+                                          guest_config, info, d_state);
     if (!args) {
         ret = ERROR_FAIL;
         goto out;
@@ -823,7 +827,8 @@ retry_transaction:
             char *filename;
             char *name;
             case STUBDOM_CONSOLE_LOGGING:
-                name = libxl__sprintf(gc, "qemu-dm-%s", 
libxl_domid_to_name(ctx, info->domid));
+                name = libxl__sprintf(gc, "qemu-dm-%s",
+                                      libxl_domid_to_name(ctx, info->domid));
                 libxl_create_logfile(ctx, name, &filename);
                 console[i].output = libxl__sprintf(gc, "file:%s", filename);
                 free(filename);
@@ -833,15 +838,16 @@ retry_transaction:
                                 libxl__device_model_savefile(gc, info->domid));
                 break;
             case STUBDOM_CONSOLE_RESTORE:
-                if (info->saved_state)
-                    console[i].output = libxl__sprintf(gc, "pipe:%s", 
info->saved_state);
+                if (d_state->saved_state)
+                    console[i].output =
+                        libxl__sprintf(gc, "pipe:%s", d_state->saved_state);
                 break;
             default:
                 console[i].output = "pty";
                 break;
         }
         ret = libxl__device_console_add(gc, domid, &console[i],
-                                    i == STUBDOM_CONSOLE_LOGGING ? &state : 
NULL);
+                        i == STUBDOM_CONSOLE_LOGGING ? &stubdom_state : NULL);
         if (ret)
             goto out_free;
     }
@@ -851,12 +857,12 @@ retry_transaction:
     if (libxl__create_xenpv_qemu(gc, domid,
                                  &dm_config,
                                  &xenpv_dm_info,
+                                 &stubdom_state,
                                  &dm_starting) < 0) {
         ret = ERROR_FAIL;
         goto out_free;
     }
-    if (libxl__confirm_device_model_startup(gc, &xenpv_dm_info,
-                                            dm_starting) < 0) {
+    if (libxl__confirm_device_model_startup(gc, d_state, dm_starting) < 0) {
         ret = ERROR_FAIL;
         goto out_free;
     }
@@ -881,6 +887,7 @@ out:
 int libxl__create_device_model(libxl__gc *gc,
                               libxl_domain_config *guest_config,
                               libxl_device_model_info *info,
+                              libxl__domain_build_state *state,
                               libxl__spawner_starting **starting_r)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -898,7 +905,7 @@ int libxl__create_device_model(libxl__gc
     const char *dm;
 
     if (b_info->device_model_stubdomain) {
-        rc = libxl__create_stubdom(gc, guest_config, info, starting_r);
+        rc = libxl__create_stubdom(gc, guest_config, info, state, starting_r);
         goto out;
     }
 
@@ -913,7 +920,7 @@ int libxl__create_device_model(libxl__gc
         rc = ERROR_FAIL;
         goto out;
     }
-    args = libxl__build_device_model_args(gc, dm, guest_config, info);
+    args = libxl__build_device_model_args(gc, dm, guest_config, info, state);
     if (!args) {
         rc = ERROR_FAIL;
         goto out;
@@ -994,10 +1001,9 @@ out:
 
 
 int libxl__confirm_device_model_startup(libxl__gc *gc,
-                                libxl_device_model_info *dm_info,
+                                libxl__domain_build_state *state,
                                 libxl__spawner_starting *starting)
 {
-    libxl_ctx *ctx = libxl__gc_owner(gc);
     char *path;
     int domid = starting->domid;
     int ret, ret2;
@@ -1005,11 +1011,11 @@ int libxl__confirm_device_model_startup(
     ret = libxl__spawn_confirm_offspring_startup(gc,
                                      LIBXL_DEVICE_MODEL_START_TIMEOUT,
                                      "Device Model", path, "running", 
starting);
-    if (dm_info->saved_state) {
-        ret2 = unlink(dm_info->saved_state);
-        if (ret2) LIBXL__LOG_ERRNO(ctx, XTL_ERROR,
+    if (state->saved_state) {
+        ret2 = unlink(state->saved_state);
+        if (ret2) LIBXL__LOG_ERRNO(CTX, XTL_ERROR,
                                    "failed to remove device-model state %s\n",
-                                   dm_info->saved_state);
+                                   state->saved_state);
         /* Do not clobber spawn_confirm error code with unlink error code. */
         if (!ret) ret = ret2;
     }
@@ -1120,10 +1126,11 @@ out:
 int libxl__create_xenpv_qemu(libxl__gc *gc, uint32_t domid,
                              libxl_domain_config *guest_config,
                              libxl_device_model_info *info,
+                             libxl__domain_build_state *state,
                              libxl__spawner_starting **starting_r)
 {
     libxl__build_xenpv_qemu_args(gc, domid, info);
-    libxl__create_device_model(gc, guest_config, info, starting_r);
+    libxl__create_device_model(gc, guest_config, info, state, starting_r);
     return 0;
 }
 
diff -r ff41e5fc0f12 -r c7160a835d3c tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Jan 12 15:57:08 2012 +0000
+++ b/tools/libxl/libxl_internal.h      Thu Jan 12 16:01:40 2012 +0000
@@ -220,6 +220,8 @@ typedef struct {
 
     uint32_t console_port;
     unsigned long console_mfn;
+
+    char *saved_state;
 } libxl__domain_build_state;
 
 _hidden int libxl__build_pre(libxl__gc *gc, uint32_t domid,
@@ -467,10 +469,12 @@ _hidden const char *libxl__domain_device
 _hidden int libxl__create_device_model(libxl__gc *gc,
                               libxl_domain_config *guest_config,
                               libxl_device_model_info *info,
+                              libxl__domain_build_state *state,
                               libxl__spawner_starting **starting_r);
 _hidden int libxl__create_xenpv_qemu(libxl__gc *gc, uint32_t domid,
                               libxl_domain_config *guest_config,
                               libxl_device_model_info *dm_info,
+                              libxl__domain_build_state *state,
                               libxl__spawner_starting **starting_r);
 _hidden int libxl__need_xenpv_qemu(libxl__gc *gc,
         int nr_consoles, libxl_device_console *consoles,
@@ -480,7 +484,7 @@ _hidden int libxl__need_xenpv_qemu(libxl
    * return pass *starting_r (which will be non-0) to
    * libxl__confirm_device_model_startup or libxl__detach_device_model. */
 _hidden int libxl__confirm_device_model_startup(libxl__gc *gc,
-                              libxl_device_model_info *dm_info,
+                              libxl__domain_build_state *state,
                               libxl__spawner_starting *starting);
 _hidden int libxl__detach_device_model(libxl__gc *gc, libxl__spawner_starting 
*starting);
 _hidden int libxl__wait_for_device_model(libxl__gc *gc,
diff -r ff41e5fc0f12 -r c7160a835d3c tools/libxl/libxl_types.idl
--- a/tools/libxl/libxl_types.idl       Thu Jan 12 15:57:08 2012 +0000
+++ b/tools/libxl/libxl_types.idl       Thu Jan 12 16:01:40 2012 +0000
@@ -269,8 +269,6 @@ libxl_domain_build_info = Struct("domain
 # Device Model Information
 libxl_device_model_info = Struct("device_model_info",[
     ("domid",            libxl_domid),
-    
-    ("saved_state",      string),
     ],
 )
 

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

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