Skip to contentSkip to conversation

Live migration for VMs with QEMU backed local storage

RFC PATCH Superseded Bruno Alvisio 2 participants 10 messages Oct 18, 2017 – Oct 30, 2017 1 message not in the archive

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): rfc822msgid:[email protected]

#1 lore raw

v2 cover Live migration for VMs with QEMU backed local storage

I am reviving this thread about the migration of VMs with local storage. I have worked on a solution to be able to migrate VMs that use QEMU as the backend disk driver. I have adapted the migration flow and piggybacked on the “drive-mirroring” capability already provided by QEMU.

Overview
1. The “xl migrate” command has an additional “-q” flag. When provided the local storage of the VM is mirrored to the destination during the migration process.
2. Internally, the modification consists on adding a new libxl__stream_read_state struct to the libxl__domain_create_state structure and libxl__stream_read_state structure to the libxl__domain_save_state struct.
3. Migration flow can now be divided into three phases:
a. Phase One: Copies the necessary state to start a QEMU process on the destination. It is started with the “-incoming defer” option.
b. Phase Two: Disk is mirrored using the QEMU embedded NBD server.
c. Phase Three: Once the disk is completely mirrored, virtual RAM of the domain is live migrated to the destination. This phase most closely resembles to the current migration flow.
4. If the “-q” option is not provided the migration is equivalent to the current migration flow.

The new migration flow has follows the following major sequence of steps:
1. 1st stream copies the QEMU devices RAM from source to destination.
2. QEMU process is started on the destination with the option “-incoming defer”. (This creates the QEMU process but it doesn’t start running the main loop until “migrate incoming” command is executed)
3. “drive mirror” QMP command is executed so that the disk is mirrored to the destination node.
4. An event listener waits for the QMP BLOCK_JOB_READY event sent by QEMU which signals that the "disk mirror job" is complete.
5. 2nd Stream copies the virtual RAM from source to destination including QEMU state. At this point, the VM is suspended on source.
6. “migrate incoming” QMP command is executed on destination.
7. VM is restored in destination.

This is sample configuration file that I have used to test my branch:

name="tinycore"
disk=['/home/balvisio/tinycore.img,raw,xvda,w']
memory=128
builder='hvm'
vcpus=1
vfb = ['type=vnc']
vif= ['bridge=xenbr0']
boot='b'
acpi=1
device_model_version='qemu-xen'
serial='pty'
vnc=1
xen_platform_pci=0

Notes

1. Note that the configuration file uses "xen_platform_pci=0”. This is necessary so that the block device is seen by QEMU. Further modification should be made for the case "xen_platform_pci=1” if we still want to use NBD mirroring capability provided by QEMU.
2. The current branch has still many hardcoded values. Many of the can be easily removed:
a. Port used for disk mirroring (11000)
b. Name of the block devices. (ide0-hd0) Currently the branch only supports VM with on disk drive.
c. Live migration memory transfer: The pages transferred by libxc is hardcoded. Only a VM with 128 MB of memory is supported.

Here is a link to the branch in Github:
https://github.com/balvisio/xen/tree/feature/local_storage_migration

Any feedback/suggestion is appreciated.

Cheers,

Bruno

---
 tools/libxc/include/xenguest.h       |   6 +-
 tools/libxc/xc_nomigrate.c           |   6 +-
 tools/libxc/xc_sr_common.h           |   3 + 
 tools/libxc/xc_sr_restore.c          |  14 +-
 tools/libxc/xc_sr_save.c             | 117 +++++++++++++++-
 tools/libxc/xc_sr_save_x86_hvm.c     |   7 +-
 tools/libxc/xc_sr_stream_format.h    |   4 + 
 tools/libxl/libxl.h                  |  11 +-
 tools/libxl/libxl_create.c           | 189 +++++++++++++++++++++++--
 tools/libxl/libxl_dm.c               |  20 ++- 
 tools/libxl/libxl_dom_save.c         |  66 ++++++++-
 tools/libxl/libxl_domain.c           |   4 +-
 tools/libxl/libxl_internal.h         |  62 ++++++++-
 tools/libxl/libxl_qmp.c              | 261 +++++++++++++++++++++++++++++++++++
 tools/libxl/libxl_save_callout.c     |  30 ++--
 tools/libxl/libxl_save_helper.c      |  13 +-
 tools/libxl/libxl_stream_read.c      |  17 ++- 
 tools/libxl/libxl_stream_write.c     |  28 +++-
 tools/libxl/libxl_types.idl          |   6 + 
 tools/ocaml/libs/xl/xenlight_stubs.c |   4 +-
 tools/xl/xl.h                        |   1 + 
 tools/xl/xl_cmdtable.c               |   3 +-
 tools/xl/xl_migrate.c                |  36 +++--
 tools/xl/xl_saverestore.c            |   2 +-
 tools/xl/xl_vmcontrol.c              |   5 +-
 25 files changed, 845 insertions(+), 70 deletions(-)

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

RFC PATCH v2 1/8 Added QMP commands for adding NBD server and disk migration

---
 tools/libxl/libxl_internal.h |  18 +++++++
 tools/libxl/libxl_qmp.c      | 125 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 142 insertions(+), 1 deletion(-)
tools/libxl/libxl_internal.h +18 -0
index 7247509..1349a8f 100644
@@ -1835,6 +1835,24 @@ _hidden int libxl__qmp_nbd_server_add(libxl__gc *gc, int domid,
 /* Start replication */
 _hidden int libxl__qmp_start_replication(libxl__gc *gc, int domid,
                                          bool primary);
+
+/* Add a disk to NBD server */
+_hidden int libxl__qmp_nbd_server_add(libxl__gc *gc, int domid,
+                                       const char *disk);
+
+/* Mirror disk drive */
+_hidden int libxl__qmp_drive_mirror(libxl__gc *gc, int domid, const char* device,
+                                    const char* target, const char* format);
+
+/* Query block devices */
+_hidden int libxl__qmp_query_block(libxl__gc *gc, int domid, char *device_names);
+
+/* Query existing block jobs*/
+_hidden int libxl__qmp_query_block_jobs(libxl__gc *gc, int domid, bool *is_ready);
+
+/* Resume QEMU process started with -incoming defer */
+_hidden int libxl__qmp_migrate_incoming(libxl__gc *gc, int domid, const char* uri);
+
 /* Get replication error that occurs when the vm is running */
 _hidden int libxl__qmp_query_xen_replication_status(libxl__gc *gc, int domid);
 /* Do checkpoint */
tools/libxl/libxl_qmp.c +124 -1

137 lines not on this page · raw message

Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw

RFC PATCH v2 2/8 Modified xl stack to receieve mirror QEMU disk option

In reply to Bruno Alvisio
---
 tools/ocaml/libs/xl/xenlight_stubs.c |  4 +--
 tools/xl/xl.h                        |  1 +
 tools/xl/xl_migrate.c                | 47 +++++++++++++++++++++++++++++-------
 tools/xl/xl_saverestore.c            |  2 +-
 tools/xl/xl_vmcontrol.c              |  5 ++--
 5 files changed, 45 insertions(+), 14 deletions(-)
tools/ocaml/libs/xl/xenlight_stubs.c +2 -2
index 98b52b9..9e19009 100644
@@ -538,7 +538,7 @@ value stub_libxl_domain_create_restore(value ctx, value domain_config, value par
 
 	caml_enter_blocking_section();
 	ret = libxl_domain_create_restore(CTX, &c_dconfig, &c_domid, restore_fd,
-		-1, &c_params, ao_how, NULL);
+		-1, 0, &c_params, ao_how, NULL);
 	caml_leave_blocking_section();
 
 	free(ao_how);
@@ -611,7 +611,7 @@ value stub_libxl_domain_suspend(value ctx, value domid, value fd, value async, v
 	libxl_asyncop_how *ao_how = aohow_val(async);
 
 	caml_enter_blocking_section();
-	ret = libxl_domain_suspend(CTX, c_domid, c_fd, 0, ao_how);
+	ret = libxl_domain_suspend(CTX, c_domid, c_fd, 0, NULL, ao_how);
 	caml_leave_blocking_section();
 
 	free(ao_how);
tools/xl/xl.h +1 -0
index 01c2af6..070bac1 100644
@@ -35,6 +35,7 @@ struct domain_create {
     int daemonize;
     int monitor; /* handle guest reboots etc */
     int paused;
+    int mirror_qemu_disk;
     int dryrun;
     int quiet;
     int vnc;
tools/xl/xl_migrate.c +38 -9

139 lines not on this page · raw message

tools/xl/xl_saverestore.c +1 -1
index 9afeade..b1679ba 100644
@@ -141,7 +141,7 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
 
     save_domain_core_writeconfig(fd, filename, config_data, config_len);
 
-    int rc = libxl_domain_suspend(ctx, domid, fd, 0, NULL);
+    int rc = libxl_domain_suspend(ctx, domid, fd, 0, NULL, NULL);
     close(fd);
 
     if (rc < 0) {
tools/xl/xl_vmcontrol.c +3 -2
index 89c2b25..47ec546 100644
@@ -882,8 +882,9 @@ start:
 
         ret = libxl_domain_create_restore(ctx, &d_config,
                                           &domid, restore_fd,
-                                          send_back_fd, &params,
-                                          0, autoconnect_console_how);
+                                          send_back_fd,
+                                          dom_info->mirror_qemu_disks,
+                                          &params, 0, autoconnect_console_how);
 
         libxl_domain_restore_params_dispose(&params);
 
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#4 lore raw

RFC PATCH v2 3/8 Adapted libxl to handle migration of instance with qemu based disks

In reply to Bruno Alvisio
---
 tools/libxl/libxl.h              |  11 ++-
 tools/libxl/libxl_create.c       | 191 ++++++++++++++++++++++++++++++++++++---
 tools/libxl/libxl_dm.c           |  26 ++++--
 tools/libxl/libxl_dom_save.c     |  85 ++++++++++++++++-
 tools/libxl/libxl_domain.c       |   4 +-
 tools/libxl/libxl_internal.h     |  60 ++++++++++--
 tools/libxl/libxl_save_callout.c |  38 +++++---
 tools/libxl/libxl_save_helper.c  |   4 +-
 tools/libxl/libxl_stream_read.c  |  17 +++-
 tools/libxl/libxl_stream_write.c |  28 +++++-
 10 files changed, 406 insertions(+), 58 deletions(-)
tools/libxl/libxl.h +9 -2
index 91408b4..4022c37 100644
@@ -1333,7 +1333,7 @@ int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config,
                             LIBXL_EXTERNAL_CALLERS_ONLY;
 int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
                                 uint32_t *domid, int restore_fd,
-                                int send_back_fd,
+                                int send_back_fd, int mirror_qemu_disks,
                                 const libxl_domain_restore_params *params,
                                 const libxl_asyncop_how *ao_how,
                                 const libxl_asyncprogress_how *aop_console_how)
@@ -1373,8 +1373,9 @@ static inline int libxl_domain_create_restore_0x040400(
     const libxl_asyncprogress_how *aop_console_how)
     LIBXL_EXTERNAL_CALLERS_ONLY
 {
+    //TODO: balvisio: Review
     return libxl_domain_create_restore(ctx, d_config, domid, restore_fd,
-                                       -1, params, ao_how, aop_console_how);
+                                       -1, 0, params, ao_how, aop_console_how);
 }
 
 #define libxl_domain_create_restore libxl_domain_create_restore_0x040400
@@ -1408,10 +1409,16 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid,
 
 int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd,
                          int flags, /* LIBXL_SUSPEND_* */
+                         const char* hostname,
                          const libxl_asyncop_how *ao_how)
                          LIBXL_EXTERNAL_CALLERS_ONLY;
 #define LIBXL_SUSPEND_DEBUG 1
 #define LIBXL_SUSPEND_LIVE 2
+#define LIBXL_SUSPEND_MIRROR_QEMU_DISKS 4
+
+//TODO: balvisio: DO NOT HARD-CODE THIS PARAMS
+#define QEMU_DRIVE_MIRROR_PORT "11000"
+#define QEMU_DRIVE_MIRROR_DEVICE "ide0-hd0"
 
 /* @param suspend_cancel [from xenctrl.h:xc_domain_resume( @param fast )]
  *   If this parameter is true, use co-operative resume. The guest
tools/libxl/libxl_create.c +178 -13

308 lines not on this page · raw message

tools/libxl/libxl_dm.c +17 -9
index e0e6a99..ff6721d 100644
@@ -915,7 +915,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
                                         const libxl_domain_config *guest_config,
                                         char ***args, char ***envs,
                                         const libxl__domain_build_state *state,
-                                        int *dm_state_fd)
+                                        int *dm_state_fd, int mirror_qemu_disks)
 {
     const libxl_domain_create_info *c_info = &guest_config->c_info;
     const libxl_domain_build_info *b_info = &guest_config->b_info;
@@ -1396,12 +1396,18 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
         }
     }
 
-    if (state->saved_state) {
+    if (state->saved_state && !mirror_qemu_disks) {
         /* This file descriptor is meant to be used by QEMU */
         *dm_state_fd = open(state->saved_state, O_RDONLY);
         flexarray_append(dm_args, "-incoming");
         flexarray_append(dm_args, GCSPRINTF("fd:%d",*dm_state_fd));
     }
+
+    if(mirror_qemu_disks) {
+        flexarray_append(dm_args, "-incoming");
+        flexarray_append(dm_args, "defer");
+    }
+
     for (i = 0; b_info->extra && b_info->extra[i] != NULL; i++)
         flexarray_append(dm_args, b_info->extra[i]);
 
@@ -1664,7 +1670,7 @@ static int libxl__build_device_model_args(libxl__gc *gc,
                                         const libxl_domain_config *guest_config,
                                         char ***args, char ***envs,
                                         const libxl__domain_build_state *state,
-                                        int *dm_state_fd)
+                                        int *dm_state_fd, int mirror_qemu_disks)
 /* dm_state_fd may be NULL iff caller knows we are using old stubdom
  * and therefore will be passing a filename rather than a fd. */
 {
@@ -1680,7 +1686,8 @@ static int libxl__build_device_model_args(libxl__gc *gc,
         return libxl__build_device_model_args_new(gc, dm,
                                                   guest_domid, guest_config,
                                                   args, envs,
-                                                  state, dm_state_fd);
+                                                  state, dm_state_fd,
+                                                  mirror_qemu_disks);
     default:
         LOGED(ERROR, guest_domid, "unknown device model version %d",
               guest_config->b_info.device_model_version);
@@ -1897,7 +1904,7 @@ void libxl__spawn_stub_dm(libxl__egc *egc, libxl__stub_dm_spawn_state *sdss)
 
     ret = libxl__build_device_model_args(gc, "stubdom-dm", guest_domid,
                                          guest_config, &args, NULL,
-                                         d_state, NULL);
+                                         d_state, NULL, 0);
     if (ret) {
         ret = ERROR_FAIL;
         goto out;
@@ -2055,7 +2062,7 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
         /* If dom0 qemu not needed, do not launch it */
         spawn_stubdom_pvqemu_cb(egc, &sdss->pvqemu, 0);
     } else {
-        libxl__spawn_local_dm(egc, &sdss->pvqemu);
+        libxl__spawn_local_dm(egc, &sdss->pvqemu, 0);
     }
 
     return;
@@ -2160,7 +2167,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 mirror_qemu_disks)
 {
     /* convenience aliases */
     const int domid = dmss->guest_domid;
@@ -2200,7 +2208,7 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
     }
     rc = libxl__build_device_model_args(gc, dm, domid, guest_config,
                                           &args, &envs, state,
-                                          &dm_state_fd);
+                                          &dm_state_fd, mirror_qemu_disks);
     if (rc)
         goto out;
 
@@ -2330,7 +2338,7 @@ static void device_model_confirm(libxl__egc *egc, libxl__spawn_state *spawn,
     if (!xsdata)
         return;
 
-    if (strcmp(xsdata, "running"))
+    if (strcmp(xsdata, "running") && strcmp(xsdata, "inmigrate"))
         return;
 
     libxl__spawn_initiate_detach(gc, spawn);
tools/libxl/libxl_dom_save.c +82 -3

100 lines not on this page · raw message

tools/libxl/libxl_domain.c +3 -1
index 08eccd0..76c6d3d 100644
@@ -487,7 +487,7 @@ static void domain_suspend_cb(libxl__egc *egc,
 }
 
 int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags,
-                         const libxl_asyncop_how *ao_how)
+                         const char* hostname, const libxl_asyncop_how *ao_how)
 {
     AO_CREATE(ctx, domid, ao_how);
     int rc;
@@ -509,6 +509,8 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags,
     dss->type = type;
     dss->live = flags & LIBXL_SUSPEND_LIVE;
     dss->debug = flags & LIBXL_SUSPEND_DEBUG;
+    dss->mirror_qemu_disks = flags & LIBXL_SUSPEND_MIRROR_QEMU_DISKS;
+    dss->hostname = hostname;
     dss->checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_NONE;
 
     rc = libxl__fd_flags_modify_save(gc, dss->fd,
tools/libxl/libxl_internal.h +50 -10

137 lines not on this page · raw message

tools/libxl/libxl_save_callout.c +24 -14
index 891c669..290d91d 100644
@@ -43,7 +43,7 @@ static void helper_done(libxl__egc *egc, libxl__save_helper_state *shs);
 
 void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,
                               libxl__save_helper_state *shs,
-                              int hvm, int pae)
+                              int hvm, int pae, int mirror_qemu_disks)
 {
     STATE_AO_GC(dcs->ao);
 
@@ -63,16 +63,22 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,
         state->console_domid,
         hvm, pae,
         cbflags, dcs->restore_params.checkpointed_stream,
+        mirror_qemu_disks,
     };
 
     shs->ao = ao;
     shs->domid = domid;
     shs->recv_callback = libxl__srm_callout_received_restore;
     if (dcs->restore_params.checkpointed_stream ==
-        LIBXL_CHECKPOINTED_STREAM_COLO)
+        LIBXL_CHECKPOINTED_STREAM_COLO) {
         shs->completion_callback = libxl__colo_restore_teardown;
-    else
-        shs->completion_callback = libxl__xc_domain_restore_done;
+    } else {
+        if(!mirror_qemu_disks){
+            shs->completion_callback = libxl__xc_domain_restore_done;
+        } else {
+            shs->completion_callback = libxl__xc_hvm_params_restore_done;
+        }
+    }
     shs->caller_state = dcs;
     shs->need_results = 1;
 
@@ -81,7 +87,7 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,
 }
 
 void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_save_state *dss,
-                           libxl__save_helper_state *shs)
+                           libxl__save_helper_state *shs, int mirror_qemu_disks)
 {
     STATE_AO_GC(dss->ao);
 
@@ -90,13 +96,17 @@ void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_save_state *dss,
 
     const unsigned long argnums[] = {
         dss->domid, 0, 0, dss->xcflags, dss->hvm,
-        cbflags, dss->checkpointed_stream,
+        cbflags, dss->checkpointed_stream, mirror_qemu_disks,
     };
 
     shs->ao = ao;
     shs->domid = dss->domid;
     shs->recv_callback = libxl__srm_callout_received_save;
-    shs->completion_callback = libxl__xc_domain_save_done;
+    if(!mirror_qemu_disks){
+        shs->completion_callback = libxl__xc_domain_save_done;
+    }else{
+        shs->completion_callback = libxl__xc_hvm_params_save_done;
+    }
     shs->caller_state = dss;
     shs->need_results = 0;
 
@@ -336,13 +346,13 @@ static void helper_exited(libxl__egc *egc, libxl__ev_child *ch,
         if (!shs->rc)
             shs->rc = ERROR_FAIL;
     }
-
-    if (shs->need_results) {
-        if (!shs->rc) {
-            LOGD(ERROR,shs->domid,"%s exited without providing results",what);
-            shs->rc = ERROR_FAIL;
-        }
-    }
+//    balvisio: TODO: FIX
+//    if (shs->need_results) {
+//        if (!shs->rc) {
+//            LOGD(ERROR,shs->domid,"%s exited without providing results",what);
+//            shs->rc = ERROR_FAIL;
+//        }
+//    }
 
     if (!shs->completed) {
         if (!shs->rc) {
tools/libxl/libxl_save_helper.c +3 -1
index 1dece23..cfc9279 100644
@@ -257,6 +257,7 @@ int main(int argc, char **argv)
         int hvm =                           atoi(NEXTARG);
         unsigned cbflags =                  strtoul(NEXTARG,0,10);
         xc_migration_stream_t stream_type = strtoul(NEXTARG,0,10);
+        int mirror_qemu_disks =                   atoi(NEXTARG);
         assert(!*++argv);
 
         helper_setcallbacks_save(&helper_save_callbacks, cbflags);
@@ -266,7 +267,7 @@ int main(int argc, char **argv)
 
         r = xc_domain_save(xch, io_fd, dom, max_iters, max_factor, flags,
                            &helper_save_callbacks, hvm, stream_type,
-                           recv_fd);
+                           recv_fd, mirror_qemu_disks);
         complete(r);
 
     } else if (!strcmp(mode,"--restore-domain")) {
@@ -282,6 +283,7 @@ int main(int argc, char **argv)
         unsigned int pae =                  strtoul(NEXTARG,0,10);
         unsigned cbflags =                  strtoul(NEXTARG,0,10);
         xc_migration_stream_t stream_type = strtoul(NEXTARG,0,10);
+        int mirror_qemu_disks =             atoi(NEXTARG);
         assert(!*++argv);
 
         helper_setcallbacks_restore(&helper_restore_callbacks, cbflags);
tools/libxl/libxl_stream_read.c +16 -1
index 4838750..ea5ffd3 100644
@@ -561,6 +561,7 @@ static bool process_record(libxl__egc *egc,
 {
     STATE_AO_GC(stream->ao);
     libxl__domain_create_state *dcs = stream->dcs;
+    int create_mirror_qemu_disks = stream->dcs->mirror_qemu_disks;
     libxl__sr_record_buf *rec;
     libxl_sr_checkpoint_state *srcs;
     bool further_action_needed = false;
@@ -580,7 +581,9 @@ static bool process_record(libxl__egc *egc,
         break;
 
     case REC_TYPE_LIBXC_CONTEXT:
-        libxl__xc_domain_restore(egc, dcs, &stream->shs, 0, 0);
+        libxl__xc_domain_restore(egc, dcs, &stream->shs, 0, 0,
+                                 stream->mirror_qemu_disks +
+                                 create_mirror_qemu_disks);
         break;
 
     case REC_TYPE_EMULATOR_XENSTORE_DATA:
@@ -835,6 +838,18 @@ static void stream_done(libxl__egc *egc,
     }
 }
 
+void libxl__xc_mirror_disks_restore_done(libxl__egc *egc, void *dcs_void,
+                                       int rc, int retval, int errnoval)
+{
+    libxl__domain_create_state *dcs = dcs_void;
+    libxl__stream_read_state *stream = &dcs->srs_mirror_qemu_disks;
+    STATE_AO_GC(dcs->ao);
+
+    check_all_finished(egc, stream, rc);
+
+    stream_continue(egc, stream);
+}
+
 void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void,
                                    int rc, int retval, int errnoval)
 {
tools/libxl/libxl_stream_write.c +24 -4
index c96a6a2..ad312ed 100644
@@ -335,7 +335,24 @@ static void stream_header_done(libxl__egc *egc,
 static void libxc_header_done(libxl__egc *egc,
                               libxl__stream_write_state *stream)
 {
-    libxl__xc_domain_save(egc, stream->dss, &stream->shs);
+    int save_mirror_qemu_disks = stream->dss->local_disks;
+    libxl__xc_domain_save(egc, stream->dss, &stream->shs,
+                          save_mirror_qemu_disks + stream->mirror_qemu_disks);
+}
+
+void libxl__xc_mirror_disks_save_done(libxl__egc *egc, void *dss_void,
+                                    int rc, int retval, int errnoval)
+{
+    libxl__domain_save_state *dss = dss_void;
+    libxl__stream_write_state *stream = &dss->sws_mirror_qemu_disks;
+    STATE_AO_GC(dss->ao);
+
+    check_all_finished(egc, stream, rc);
+
+    if (stream->in_checkpoint)
+        write_checkpoint_end_record(egc, stream);
+    else
+        write_emulator_xenstore_record(egc, stream);
 }
 
 void libxl__xc_domain_save_done(libxl__egc *egc, void *dss_void,
@@ -429,9 +446,12 @@ static void emulator_xenstore_record_done(libxl__egc *egc,
 {
     libxl__domain_save_state *dss = stream->dss;
 
-    if (dss->type == LIBXL_DOMAIN_TYPE_HVM)
-        write_emulator_context_record(egc, stream);
-    else {
+    if (dss->type == LIBXL_DOMAIN_TYPE_HVM) {
+        if(!stream->mirror_qemu_disks)
+            write_emulator_context_record(egc, stream);
+        else
+            write_end_record(egc, stream);
+    } else {
         if (stream->in_checkpoint)
             write_checkpoint_end_record(egc, stream);
         else
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw

RFC PATCH v2 4/8 Remove stop NBD server command from xl

In reply to Bruno Alvisio
---
 tools/xl/xl_migrate.c | 11 -----------
 1 file changed, 11 deletions(-)
tools/xl/xl_migrate.c +0 -11
index fee726f..9f43d96 100644
@@ -427,17 +427,6 @@ static void migrate_receive(int debug, int daemonize, int monitor,
 
     fprintf(stderr, "migration target: Got permission, starting domain.\n");
 
-    if(mirror_qemu_disks){
-        fprintf(stderr, "migration target: Stopping NBD server\n");
-        rc = libxl__nbd_server_stop(ctx, domid);
-        if (rc){
-            rc = 0; //For now, mask the error if NBD server fails to stop
-            fprintf(stderr, "Failed to stop NBD server\n");
-        }else{
-            fprintf(stderr, "Stopped NBD server successfully\n");
-        }
-    }
-
     if (migration_domname) {
         rc = libxl_domain_rename(ctx, domid, migration_domname, common_domname);
         if (rc) goto perhaps_destroy_notify_rc;
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#6 lore raw

RFC PATCH v2 5/8 Improved migration flow syntax in libxl

In reply to Bruno Alvisio
---
 tools/libxl/libxl_create.c       |  5 +++--
 tools/libxl/libxl_dm.c           | 10 +++++-----
 tools/libxl/libxl_internal.h     |  4 ++--
 tools/libxl/libxl_save_callout.c | 41 +++++++++++++++++++++-------------------
 tools/libxl/libxl_save_helper.c  | 15 ++++++++++-----
 tools/libxl/libxl_types.idl      |  6 ++++++
 6 files changed, 48 insertions(+), 33 deletions(-)
tools/libxl/libxl_create.c +3 -2
index f10f2ce..6df2754 100644
@@ -1121,6 +1121,7 @@ static void domcreate_bootloader_done(libxl__egc *egc,
     dcs->sdss.dm.spawn.ao = ao;
     dcs->sdss.dm.guest_config = dcs->guest_config;
     dcs->sdss.dm.build_state = &dcs->build_state;
+    dcs->sdss.dm.mirror_qemu_disks = dcs->mirror_qemu_disks;
     if(!dcs->mirror_qemu_disks) {
         dcs->sdss.dm.callback = domcreate_devmodel_started;
         dcs->sdss.callback = domcreate_devmodel_started;
@@ -1518,7 +1519,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
         if (libxl_defbool_val(d_config->b_info.device_model_stubdomain))
             libxl__spawn_stub_dm(egc, &dcs->sdss);
         else
-            libxl__spawn_local_dm(egc, &dcs->sdss.dm, dcs->mirror_qemu_disks);
+            libxl__spawn_local_dm(egc, &dcs->sdss.dm);
 
         /*
          * Handle the domain's (and the related stubdomain's) access to
@@ -1550,7 +1551,7 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,
             goto error_out;
         if (ret) {
             dcs->sdss.dm.guest_domid = domid;
-            libxl__spawn_local_dm(egc, &dcs->sdss.dm, 0);
+            libxl__spawn_local_dm(egc, &dcs->sdss.dm);
             return;
         } else {
             assert(!dcs->sdss.dm.guest_domid);
tools/libxl/libxl_dm.c +5 -5
index ff6721d..001e14e 100644
@@ -1396,7 +1396,7 @@ static int libxl__build_device_model_args_new(libxl__gc *gc,
         }
     }
 
-    if (state->saved_state && !mirror_qemu_disks) {
+    if (state->saved_state) {
         /* This file descriptor is meant to be used by QEMU */
         *dm_state_fd = open(state->saved_state, O_RDONLY);
         flexarray_append(dm_args, "-incoming");
@@ -2062,7 +2062,7 @@ static void spawn_stub_launch_dm(libxl__egc *egc,
         /* If dom0 qemu not needed, do not launch it */
         spawn_stubdom_pvqemu_cb(egc, &sdss->pvqemu, 0);
     } else {
-        libxl__spawn_local_dm(egc, &sdss->pvqemu, 0);
+        libxl__spawn_local_dm(egc, &sdss->pvqemu);
     }
 
     return;
@@ -2167,8 +2167,7 @@ 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,
-                           int mirror_qemu_disks)
+void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
 {
     /* convenience aliases */
     const int domid = dmss->guest_domid;
@@ -2208,7 +2207,8 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss,
     }
     rc = libxl__build_device_model_args(gc, dm, domid, guest_config,
                                           &args, &envs, state,
-                                          &dm_state_fd, mirror_qemu_disks);
+                                          &dm_state_fd,
+                                          dmss->mirror_qemu_disks);
     if (rc)
         goto out;
 
tools/libxl/libxl_internal.h +2 -2
index 16a476f..30862c6 100644
@@ -3780,7 +3780,7 @@ _hidden void libxl__domain_save(libxl__egc *egc,
 _hidden void libxl__xc_domain_save(libxl__egc *egc,
                                    libxl__domain_save_state *dss,
                                    libxl__save_helper_state *shs,
-                                   int mirror_qemu_disks);
+                                   int migration_phase);
 /* If rc==0 then retval is the return value from xc_domain_save
  * and errnoval is the errno value it provided.
  * If rc!=0, retval and errnoval are undefined. */
@@ -3813,7 +3813,7 @@ _hidden int libxl__restore_emulator_xenstore_data
 _hidden void libxl__xc_domain_restore(libxl__egc *egc,
                                       libxl__domain_create_state *dcs,
                                       libxl__save_helper_state *shs,
-                                      int hvm, int pae, int mirror_qemu_disks);
+                                      int hvm, int pae, int migration_phase);
 /* If rc==0 then retval is the return value from xc_domain_save
  * and errnoval is the errno value it provided.
  * If rc!=0, retval and errnoval are undefined. */
tools/libxl/libxl_save_callout.c +22 -19

88 lines not on this page · raw message

tools/libxl/libxl_save_helper.c +10 -5
index cfc9279..9a57b28 100644
@@ -257,7 +257,7 @@ int main(int argc, char **argv)
         int hvm =                           atoi(NEXTARG);
         unsigned cbflags =                  strtoul(NEXTARG,0,10);
         xc_migration_stream_t stream_type = strtoul(NEXTARG,0,10);
-        int mirror_qemu_disks =                   atoi(NEXTARG);
+        int migration_phase =               atoi(NEXTARG);
         assert(!*++argv);
 
         helper_setcallbacks_save(&helper_save_callbacks, cbflags);
@@ -267,7 +267,7 @@ int main(int argc, char **argv)
 
         r = xc_domain_save(xch, io_fd, dom, max_iters, max_factor, flags,
                            &helper_save_callbacks, hvm, stream_type,
-                           recv_fd, mirror_qemu_disks);
+                           recv_fd, migration_phase);
         complete(r);
 
     } else if (!strcmp(mode,"--restore-domain")) {
@@ -283,7 +283,7 @@ int main(int argc, char **argv)
         unsigned int pae =                  strtoul(NEXTARG,0,10);
         unsigned cbflags =                  strtoul(NEXTARG,0,10);
         xc_migration_stream_t stream_type = strtoul(NEXTARG,0,10);
-        int mirror_qemu_disks =             atoi(NEXTARG);
+        int migration_phase =               atoi(NEXTARG);
         assert(!*++argv);
 
         helper_setcallbacks_restore(&helper_restore_callbacks, cbflags);
@@ -298,8 +298,13 @@ int main(int argc, char **argv)
                               store_domid, console_evtchn, &console_mfn,
                               console_domid, hvm, pae,
                               stream_type,
-                              &helper_restore_callbacks, send_back_fd);
-        helper_stub_restore_results(store_mfn,console_mfn,0);
+                              &helper_restore_callbacks, send_back_fd,
+                              migration_phase);
+
+        if (migration_phase == LIBXL_MIGRATION_PHASE_NON_LOCAL_DISK ||
+            migration_phase == LIBXL_MIGRATION_PHASE_MIRROR_DISK) {
+            helper_stub_restore_results(store_mfn,console_mfn,0);
+        }
         complete(r);
 
     } else {
tools/libxl/libxl_types.idl +6 -0
index 173d70a..de5f536 100644
@@ -240,6 +240,12 @@ libxl_checkpointed_stream = Enumeration("checkpointed_stream", [
     (2, "COLO"),
     ])
 
+libxl_stream_phase = Enumeration("migration_phase", [
+    (0, "NON_LOCAL_DISK"),
+    (1, "VIRTUAL_RAM"),
+    (2, "MIRROR_DISK"),
+    ])
+
 #
 # Complex libxl types
 #
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#7 lore raw

RFC PATCH v2 6/8 Adapted libxc for migration of local disk

In reply to Bruno Alvisio
---
 tools/libxc/include/xenguest.h    |   6 +-
 tools/libxc/xc_nomigrate.c        |   6 +-
 tools/libxc/xc_sr_common.h        |   3 +
 tools/libxc/xc_sr_restore.c       |  14 +++--
 tools/libxc/xc_sr_save.c          | 118 +++++++++++++++++++++++++++++++++++++-
 tools/libxc/xc_sr_save_x86_hvm.c  |   7 ++-
 tools/libxc/xc_sr_stream_format.h |   4 ++
 7 files changed, 144 insertions(+), 14 deletions(-)
tools/libxc/include/xenguest.h +4 -2
index 5cd8111..a6f52f1 100644
@@ -103,7 +103,8 @@ typedef enum {
 int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
                    uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
                    struct save_callbacks* callbacks, int hvm,
-                   xc_migration_stream_t stream_type, int recv_fd);
+                   xc_migration_stream_t stream_type, int recv_fd,
+                   int migration_phase);
 
 /* callbacks provided by xc_domain_restore */
 struct restore_callbacks {
@@ -168,7 +169,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
                       unsigned long *console_mfn, domid_t console_domid,
                       unsigned int hvm, unsigned int pae,
                       xc_migration_stream_t stream_type,
-                      struct restore_callbacks *callbacks, int send_back_fd);
+                      struct restore_callbacks *callbacks, int send_back_fd,
+                      int migration_phase);
 
 /**
  * This function will create a domain for a paravirtualized Linux
tools/libxc/xc_nomigrate.c +4 -2
index 317c8ce..c75411b 100644
@@ -23,7 +23,8 @@
 int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t max_iters,
                    uint32_t max_factor, uint32_t flags,
                    struct save_callbacks* callbacks, int hvm,
-                   xc_migration_stream_t stream_type, int recv_fd)
+                   xc_migration_stream_t stream_type, int recv_fd,
+                   int migration_phase)
 {
     errno = ENOSYS;
     return -1;
@@ -35,7 +36,8 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
                       unsigned long *console_mfn, domid_t console_domid,
                       unsigned int hvm, unsigned int pae,
                       xc_migration_stream_t stream_type,
-                      struct restore_callbacks *callbacks, int send_back_fd)
+                      struct restore_callbacks *callbacks, int send_back_fd,
+                      int migration_phase)
 {
     errno = ENOSYS;
     return -1;
tools/libxc/xc_sr_common.h +3 -0
index a83f22a..903f18a 100644
@@ -96,6 +96,8 @@ struct xc_sr_save_ops
      * after a successful save, or upon encountering an error.
      */
     int (*cleanup)(struct xc_sr_context *ctx);
+
+    int (*local_disks)(struct xc_sr_context *ctx);
 };
 
 
@@ -177,6 +179,7 @@ struct xc_sr_context
     xc_interface *xch;
     uint32_t domid;
     int fd;
+    int migration_phase;
 
     xc_dominfo_t dominfo;
 
tools/libxc/xc_sr_restore.c +9 -5
index a016678..13e6abc 100644
@@ -799,11 +799,13 @@ static int restore(struct xc_sr_context *ctx)
      * With Remus, if we reach here, there must be some error on primary,
      * failover from the last checkpoint state.
      */
-    rc = ctx->restore.ops.stream_complete(ctx);
-    if ( rc )
-        goto err;
+    if ( !ctx->migration_phase != MIGRATION_PHASE_MIRROR_DISK ) {
+        rc = ctx->restore.ops.stream_complete(ctx);
+        if ( rc )
+            goto err;
 
-    IPRINTF("Restore successful");
+        IPRINTF("Restore successful");
+    }
     goto done;
 
  err:
@@ -829,13 +831,15 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uint32_t dom,
                       unsigned long *console_gfn, domid_t console_domid,
                       unsigned int hvm, unsigned int pae,
                       xc_migration_stream_t stream_type,
-                      struct restore_callbacks *callbacks, int send_back_fd)
+                      struct restore_callbacks *callbacks, int send_back_fd,
+                      int migration_phase)
 {
     xen_pfn_t nr_pfns;
     struct xc_sr_context ctx =
         {
             .xch = xch,
             .fd = io_fd,
+            .migration_phase = migration_phase
         };
 
     /* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions. */
tools/libxc/xc_sr_save.c +115 -3

171 lines not on this page · raw message

tools/libxc/xc_sr_save_x86_hvm.c +5 -2
index e17bb59..e417da2 100644
@@ -157,7 +157,8 @@ static int x86_hvm_setup(struct xc_sr_context *ctx)
 
     ctx->save.p2m_size = nr_pfns;
 
-    if ( ctx->save.callbacks->switch_qemu_logdirty(
+    if ( ctx->migration_phase != MIGRATION_PHASE_MIRROR_DISK &&
+         ctx->save.callbacks->switch_qemu_logdirty(
              ctx->domid, 1, ctx->save.callbacks->data) )
     {
         PERROR("Couldn't enable qemu log-dirty mode");
@@ -214,7 +215,8 @@ static int x86_hvm_cleanup(struct xc_sr_context *ctx)
     xc_interface *xch = ctx->xch;
 
     /* If qemu successfully enabled logdirty mode, attempt to disable. */
-    if ( ctx->x86_hvm.save.qemu_enabled_logdirty &&
+    if ( ctx->migration_phase != MIGRATION_PHASE_MIRROR_DISK &&
+         ctx->x86_hvm.save.qemu_enabled_logdirty &&
          ctx->save.callbacks->switch_qemu_logdirty(
              ctx->domid, 0, ctx->save.callbacks->data) )
     {
@@ -235,6 +237,7 @@ struct xc_sr_save_ops save_ops_x86_hvm =
     .end_of_checkpoint   = x86_hvm_end_of_checkpoint,
     .check_vm_state      = x86_hvm_check_vm_state,
     .cleanup             = x86_hvm_cleanup,
+    .local_disks         = x86_hvm_end_of_checkpoint,
 };
 
 /*
tools/libxc/xc_sr_stream_format.h +4 -0
index 15ff1c7..1f0b274 100644
@@ -8,6 +8,10 @@
 
 #include <inttypes.h>
 
+#define MIGRATION_PHASE_NON_LOCAL_DISK 0
+#define MIGRATION_PHASE_VIRTUAL_RAM 1
+#define MIGRATION_PHASE_MIRROR_DISK 2
+
 /*
  * Image Header
  */
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#8 lore raw

RFC PATCH v2 7/8 Fixed bugs in the migration flow

In reply to Bruno Alvisio
---
 tools/libxc/xc_sr_save.c         |  1 -
 tools/libxl/libxl_create.c       | 15 ++++++++-------
 tools/libxl/libxl_dom_save.c     |  2 +-
 tools/libxl/libxl_domain.c       |  2 +-
 tools/libxl/libxl_internal.h     |  2 +-
 tools/libxl/libxl_save_callout.c |  5 +++--
 tools/libxl/libxl_stream_write.c |  2 +-
 tools/xl/xl.h                    |  2 +-
 tools/xl/xl_cmdtable.c           |  3 ++-
 tools/xl/xl_migrate.c            |  2 +-
 10 files changed, 19 insertions(+), 17 deletions(-)
tools/libxc/xc_sr_save.c +0 -1
index 181a0c8..f3e162f 100644
@@ -464,7 +464,6 @@ static int send_virtual_devices_and_params(struct xc_sr_context *ctx)
     uint64_t i = 0;
     int rc = 0;
 
-    fprintf(stderr, "BRUNO: SEND VIRTUAL DEVICES AND PARAMS\n");
     xc_set_progress_prefix(xch, "Frames");
 
     //FOR RTL AND VGA IN 128MB VM . Might change on size of VM
tools/libxl/libxl_create.c +8 -7
index 6df2754..0579671 100644
@@ -1055,24 +1055,24 @@ static void start_nbd_server(libxl__egc *egc, libxl__dm_spawn_state *dmss,
               * TODO: Assign port dynamically
               */
 
-            LOGD(DEBUG, "Starting NBD Server\n");
+            LOGD(DEBUG, domid, "Starting NBD Server\n");
             ret = libxl__qmp_nbd_server_start(gc, domid, "::", QEMU_DRIVE_MIRROR_PORT);
             if (ret) {
                 ret = ERROR_FAIL;
-                LOGD(ERROR, "Failed to start NBD Server\n");
+                LOGD(ERROR, domid, "Failed to start NBD Server\n");
                 goto skip_nbd;
             }else{
-                LOGD(INFO, "Started NBD Server Successfully\n");
+                LOGD(INFO, domid, "Started NBD Server Successfully\n");
             }
 
             ret = libxl__qmp_nbd_server_add(gc, domid, QEMU_DRIVE_MIRROR_DEVICE);
 
             if (ret) {
                 ret = ERROR_FAIL;
-                LOGD(ERROR, "Failed to add NBD Server\n");
+                LOGD(ERROR, domid, "Failed to add NBD Server\n");
                 goto skip_nbd;
             } else {
-                LOGD(INFO, "NBD Add Successful\n");
+                LOGD(INFO, domid, "NBD Add Successful\n");
             }
         }
 
@@ -1103,7 +1103,7 @@ static void domcreate_bootloader_done(libxl__egc *egc,
     libxl__srm_restore_autogen_callbacks *const callbacks =
         &dcs->srs.shs.callbacks.restore.a;
     libxl__srm_restore_autogen_callbacks *const callbacks_mirror_qemu_disks =
-        &dcs->srs_local_disks.shs.callbacks.restore.a;
+        &dcs->srs_mirror_qemu_disks.shs.callbacks.restore.a;
 
     if (rc) {
         domcreate_rebuild_done(egc, dcs, rc);
@@ -1252,6 +1252,7 @@ static void domcreate_stream_done(libxl__egc *egc,
 {
     libxl__domain_create_state *dcs = srs->dcs;
     STATE_AO_GC(dcs->ao);
+    int rc;
 
     const uint32_t domid = dcs->guest_domid;
     const char* uri;
@@ -1269,7 +1270,7 @@ static void domcreate_stream_done(libxl__egc *egc,
         }else{
             fprintf(stderr, "Stopped NBD server successfully\n");
         }
-        uri = GCSPRINTF("exec: /bin/cat %s", (&dcs->sdss.dm)->build_state->saved_state);
+        uri = GCSPRINTF("exec: /bin/cat %s", state_file);
         libxl__qmp_migrate_incoming(gc, domid, uri);
         domcreate_devmodel_started(egc, &dcs->sdss.dm, 0);
     }
tools/libxl/libxl_dom_save.c +1 -1
index a2730f5..ddfe2f8 100644
@@ -446,7 +446,7 @@ static void mirror_qemu_disks(libxl__egc *egc, libxl__stream_write_state *sws,
 start_mirror:
         LOGD(DEBUG, domid, "Sleeping for a bit so that source can start NBD\n");
         sleep(30);
-        LOGD(DEBUG, "Starting mirror-drive of device %s\n",
+        LOGD(DEBUG, domid, "Starting mirror-drive of device %s\n",
              QEMU_DRIVE_MIRROR_DEVICE);
         target = GCSPRINTF("nbd:%s:%s:exportname=%s", dss->hostname,
                            QEMU_DRIVE_MIRROR_PORT, QEMU_DRIVE_MIRROR_DEVICE);
tools/libxl/libxl_domain.c +1 -1
index 76c6d3d..9b512b9 100644
@@ -509,7 +509,7 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags,
     dss->type = type;
     dss->live = flags & LIBXL_SUSPEND_LIVE;
     dss->debug = flags & LIBXL_SUSPEND_DEBUG;
-    dss->mirror_qemu_disks = flags & LIBXL_SUSPEND_MIRROR_QEMU_DISKS;
+    dss->mirror_qemu_disks = (flags & LIBXL_SUSPEND_MIRROR_QEMU_DISKS) ? 1 : 0;
     dss->hostname = hostname;
     dss->checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_NONE;
 
tools/libxl/libxl_internal.h +1 -1
index 30862c6..d7b338b 100644
@@ -3759,7 +3759,7 @@ struct libxl__domain_create_state {
         /* If we're not doing stubdom, we use only dmss.dm,
          * for the non-stubdom device model. */
     libxl__stream_read_state srs;
-    libxl__stream_read_state srs_local_disks;
+    libxl__stream_read_state srs_mirror_qemu_disks;
     /* necessary if the domain creation failed and we have to destroy it */
     libxl__domain_destroy_state dds;
     libxl__multidev multidev;
tools/libxl/libxl_save_callout.c +3 -2
index 48f96d8..64c891a 100644
@@ -62,7 +62,8 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,
         state->store_domid, state->console_port,
         state->console_domid,
         hvm, pae,
-        cbflags, dcs->restore_params.checkpointed_stream
+        cbflags, dcs->restore_params.checkpointed_stream,
+        migration_phase,
     };
 
     shs->ao = ao;
@@ -74,7 +75,7 @@ void libxl__xc_domain_restore(libxl__egc *egc, libxl__domain_create_state *dcs,
     } else {
         if ( migration_phase != LIBXL_MIGRATION_PHASE_MIRROR_DISK ) {
             shs->completion_callback = libxl__xc_domain_restore_done;
-            if( local_disks == LIBXL_MIGRATION_PHASE_VIRTUAL_RAM )
+            if( migration_phase == LIBXL_MIGRATION_PHASE_VIRTUAL_RAM )
                 shs->need_results = 0;
             else
                 shs->need_results = 1;
tools/libxl/libxl_stream_write.c +1 -1
index ad312ed..f5269f4 100644
@@ -335,7 +335,7 @@ static void stream_header_done(libxl__egc *egc,
 static void libxc_header_done(libxl__egc *egc,
                               libxl__stream_write_state *stream)
 {
-    int save_mirror_qemu_disks = stream->dss->local_disks;
+    int save_mirror_qemu_disks = stream->dss->mirror_qemu_disks;
     libxl__xc_domain_save(egc, stream->dss, &stream->shs,
                           save_mirror_qemu_disks + stream->mirror_qemu_disks);
 }
tools/xl/xl.h +1 -1
index 070bac1..2bff52f 100644
@@ -35,7 +35,7 @@ struct domain_create {
     int daemonize;
     int monitor; /* handle guest reboots etc */
     int paused;
-    int mirror_qemu_disk;
+    int mirror_qemu_disks;
     int dryrun;
     int quiet;
     int vnc;
tools/xl/xl_cmdtable.c +2 -1
index 5cfc7e8..5fa5720 100644
@@ -165,7 +165,8 @@ struct cmd_spec cmd_table[] = {
       "-e              Do not wait in the background (on <host>) for the death\n"
       "                of the domain.\n"
       "--debug         Print huge (!) amount of debug during the migration process.\n"
-      "-p              Do not unpause domain after migrating it."
+      "-p              Do not unpause domain after migrating it.\n"
+      "-q              Migrate local disks (Copy all the storage)"
     },
     { "restore",
       &main_restore, 0, 1,
tools/xl/xl_migrate.c +1 -1
index 9f43d96..0a01cad 100644
@@ -610,7 +610,7 @@ int main_migrate(int argc, char **argv)
                   daemonize ? "" : " -e",
                   debug ? " -d" : "",
                   pause_after_migration ? " -p" : "",
-                  mirror_qemu_disks ? "-q" :"");
+                  mirror_qemu_disks ? " -q" : "");
     }
 
     migrate_domain(domid, rune, debug, config_filename, mirror_qemu_disks,
Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#9 lore raw

RFC PATCH v2 8/8 Added support to handle QMP events

In reply to Bruno Alvisio
---
 tools/libxl/libxl_dom_save.c |  71 ++++++++------------
 tools/libxl/libxl_qmp.c      | 150 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 170 insertions(+), 51 deletions(-)
tools/libxl/libxl_dom_save.c +26 -45
index ddfe2f8..d188dd2 100644
@@ -432,63 +432,44 @@ static void mirror_qemu_disks(libxl__egc *egc, libxl__stream_write_state *sws,
 {
     int counter = 20;
     char* target;
-    bool job_is_ready = false;
     libxl__domain_save_state *dss = sws->dss;
     const uint32_t domid = dss->domid;
     STATE_AO_GC(dss->ao);
 
-    if (dss->mirror_qemu_disks) {
+    if (rc)
+        goto err;
     /*
      * If the -q was provided, the drive-mirror job is started.
-     * TODO: Move the following code as part of the domain_suspend
      * TODO: The port should be sent by the destination.
-    */
-start_mirror:
-        LOGD(DEBUG, domid, "Sleeping for a bit so that source can start NBD\n");
-        sleep(30);
-        LOGD(DEBUG, domid, "Starting mirror-drive of device %s\n",
-             QEMU_DRIVE_MIRROR_DEVICE);
-        target = GCSPRINTF("nbd:%s:%s:exportname=%s", dss->hostname,
-                           QEMU_DRIVE_MIRROR_PORT, QEMU_DRIVE_MIRROR_DEVICE);
-        rc = libxl__qmp_drive_mirror(gc, dss->domid, QEMU_DRIVE_MIRROR_DEVICE,
+     */
+ start_mirror:
+    LOGD(DEBUG, domid, "Sleeping for a bit so that source can start NBD\n");
+    sleep(30);
+    LOGD(DEBUG, domid, "Starting mirror-drive of device %s\n",
+         QEMU_DRIVE_MIRROR_DEVICE);
+    target = GCSPRINTF("nbd:%s:%s:exportname=%s", dss->hostname,
+                       QEMU_DRIVE_MIRROR_PORT, QEMU_DRIVE_MIRROR_DEVICE);
+    rc = libxl__qmp_drive_mirror(gc, dss->domid, QEMU_DRIVE_MIRROR_DEVICE,
                                      target, "raw");
-        if (!rc) {
-            LOGD(INFO, domid, "Drive mirror command returned successfully\n");
+    if (!rc) {
+        LOGD(DEBUG, domid, "Drive mirror command returned successfully\n");
+    }else{
+        LOGD(ERROR, domid, "Sending drive mirror command failed\n");
+        if(counter > 0){
+            LOGD(INFO, domid, "Counter: %d. Sleeping for 10 sec and retry\n", counter);
+            sleep(10);
+            counter--;
+            goto start_mirror;
         }else{
-            LOGD(ERROR, domid, "Sending drive mirror command failed\n");
-            if(counter > 0){
-                LOGD(INFO, domid, "Counter: %d. Sleeping for 10 sec and retry\n", counter);
-                sleep(10);
-                counter--;
-                goto start_mirror;
-            }else{
-                goto cont;
-            }
-        }
-
-        /*
-         * Query job status until it is ready
-         * TODO: This code is just an inefficient busy wait. QMP sends an
-         * TODO: asynchronous message when mirroring job is completed. Consider
-         * TODO: adding the capability to handle asynchronous QMP messages (already done?)
-         */
-        while(!job_is_ready) {
-            LOGD(INFO, domid, "Checking for drive-mirror job");
-            rc = libxl__qmp_query_block_jobs(gc, dss->domid, &job_is_ready);
-            if(rc){
-                LOGD(ERROR, domid, "Checking block job failed\n");
-                goto cont;
-            }else{
-                LOGD(INFO, domid, "Checking block job succeeded\n");
-            }
-            if(!job_is_ready){
-                LOGD(INFO, domid, "Sleeping 5 sec\n");
-                sleep(5);
-            }
+            goto err;
         }
     }
-cont:
+
     libxl__stream_write_start(egc, &sws->dss->sws);
+    return;
+
+ err:
+   dss->callback(egc, dss, rc);
 }
 
 static void stream_done(libxl__egc *egc,
tools/libxl/libxl_qmp.c +144 -6

200 lines not on this page · raw message

Signature · 7 lines
2.3.2 (Apple Git-55)


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#10 lore raw
In reply to Bruno Alvisio

Also CC QEMU maintainers.

Is there any new QEMU patch required?

Quoted 44 lines · Bruno Alvisio

I am reviving this thread about the migration of VMs with local storage. I have worked on a solution to be able to migrate VMs that use QEMU as the backend disk driver. I have adapted the migration flow and piggybacked on the “drive-mirroring” capability already provided by QEMU.

Overview
1. The “xl migrate” command has an additional “-q” flag. When provided the local storage of the VM is mirrored to the destination during the migration process.
2. Internally, the modification consists on adding a new libxl__stream_read_state struct to the libxl__domain_create_state structure and libxl__stream_read_state structure to the libxl__domain_save_state struct.
3. Migration flow can now be divided into three phases:
a. Phase One: Copies the necessary state to start a QEMU process on the destination. It is started with the “-incoming defer” option.
b. Phase Two: Disk is mirrored using the QEMU embedded NBD server.
c. Phase Three: Once the disk is completely mirrored, virtual RAM of the domain is live migrated to the destination. This phase most closely resembles to the current migration flow.
4. If the “-q” option is not provided the migration is equivalent to the current migration flow.

The new migration flow has follows the following major sequence of steps:
1. 1st stream copies the QEMU devices RAM from source to destination.
2. QEMU process is started on the destination with the option “-incoming defer”. (This creates the QEMU process but it doesn’t start running the main loop until “migrate incoming” command is executed)
3. “drive mirror” QMP command is executed so that the disk is mirrored to the destination node.
4. An event listener waits for the QMP BLOCK_JOB_READY event sent by QEMU which signals that the "disk mirror job" is complete.
5. 2nd Stream copies the virtual RAM from source to destination including QEMU state. At this point, the VM is suspended on source.
6. “migrate incoming” QMP command is executed on destination.
7. VM is restored in destination.

This is sample configuration file that I have used to test my branch:

name="tinycore"
disk=['/home/balvisio/tinycore.img,raw,xvda,w']
memory=128
builder='hvm'
vcpus=1
vfb = ['type=vnc']
vif= ['bridge=xenbr0']
boot='b'
acpi=1
device_model_version='qemu-xen'
serial='pty'
vnc=1
xen_platform_pci=0

Notes

1. Note that the configuration file uses "xen_platform_pci=0”. This is necessary so that the block device is seen by QEMU. Further modification should be made for the case "xen_platform_pci=1” if we still want to use NBD mirroring capability provided by QEMU.
2. The current branch has still many hardcoded values. Many of the can be easily removed:
a. Port used for disk mirroring (11000)
b. Name of the block devices. (ide0-hd0) Currently the branch only supports VM with on disk drive.
c. Live migration memory transfer: The pages transferred by libxc is hardcoded. Only a VM with 128 MB of memory is supported.

Quoted 5 lines

Here is a link to the branch in Github:
https://github.com/balvisio/xen/tree/feature/local_storage_migration

Any feedback/suggestion is appreciated.

I haven't had time to review this series in detail, but I think the series could use some clean-up and improvement to the commit message. Please refer to

https://wiki.xenproject.org/wiki/Submitting_Xen_Project_Patches

Currently all patches are missing commit message explaining why the change is needed as well as your SoB. In case you're not aware, we also have the requirement each individual patch should build.

There are coding style issues in your patches, please refer to libxl/CODING_STYLE. The same style applies to xl, too.

Furthermore, patches should be cleaned up before posting -- I see a few debug printf's got added and removed, as well as a few TODOs with open questions. Preferably the open questions should be mentioned in the cover letter to catch attentions.

How this helps. Any more questions, feel free to ask.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel