Skip to contentSkip to conversation

Live migration for VMs with QEMU backed local storage

RFC PATCH Superseded Bruno Alvisio 4 participants 9 messages Jun 23, 2017 – Jun 29, 2017

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Live migration for VMs with QEMU backed local storage

This patch is the first attempt on adding live migration of instances with local storage to Xen. This patch just handles very restricted case of fully virtualized HVMs. The code uses the "drive-mirror" capability provided by QEMU. A new "-l" option is introduced to "xl migrate" command. If provided, the local disk should be mirrored during the migration process. If the option is set, during the VM creation a qemu NBD server is started on the destination. After the instance is suspended on the source, the QMP "disk-mirror" command is issued to mirror the disk to destination. Once the mirroring job is complete, the migration process continues as before. Finally, the NBD server is stopped after the instance is successfully resumed on the destination node.

A major problem with this patch is that the mirroring of the disk is performed only after the memory stream is completed and the VM is suspended on the source; thus the instance is frozen for a long period of time. The reason this happens is that the QEMU process (needed for the disk mirroring) is started on the destination node only after the memory copying is completed. One possibility I was considering to solve this issue (if it is decided that this capability should be used): Could a "helper" QEMU process be started on the destination node at the beginning of the migration sequence with the sole purpose of handling the disk mirroring and kill it at the end of the migration sequence?

From the suggestions given by Konrad Wilk and Paul Durrant the preferred approach would be to handle the mirroring of disks by QEMU instead of directly being handled directly by, for example, blkback. It would be very helpful for me to have a mental map of all the scenarios that can be encountered regarding local disk (Xen could start supporting live migration of certain types of local disks). This are the ones I can think of:
- Fully Virtualized HVM: QEMU emulation
- blkback
- blktap / blktap2

I have included TODOs in the code. I am sending this patch as is because I first wanted to get an initial feedback if this is the path the should be pursued. Any suggestions and ideas on this patch or on how to make a more generic solution would be really appreciated.

---
 tools/libxl/libxl.h                  |  16 ++++-
 tools/libxl/libxl_create.c           |  87 +++++++++++++++++++++++++-
 tools/libxl/libxl_internal.h         |  16 +++++
 tools/libxl/libxl_qmp.c              | 115 ++++++++++++++++++++++++++++++++++-
 tools/ocaml/libs/xl/xenlight_stubs.c |   2 +-
 tools/xl/xl.h                        |   1 +
 tools/xl/xl_migrate.c                |  79 +++++++++++++++++++++---
 tools/xl/xl_vmcontrol.c              |   2 +-
 8 files changed, 303 insertions(+), 15 deletions(-)
tools/libxl/libxl.h +14 -2
index cf8687a..81fb2dc 100644
@@ -1294,6 +1294,15 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,
                     xentoollog_logger *lg);
 int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */);
 
+int libxl__drive_mirror(libxl_ctx *ctx, int domid, const char* device, const char* target, const char* format) LIBXL_EXTERNAL_CALLERS_ONLY;
+
+int libxl__query_block_jobs(libxl_ctx *ctx, int domid, bool *is_ready) LIBXL_EXTERNAL_CALLERS_ONLY;
+
+int libxl__query_block(libxl_ctx *ctx, int domid, char *device_names) LIBXL_EXTERNAL_CALLERS_ONLY;
+
+int libxl__nbd_server_stop(libxl_ctx *ctx, int domid) LIBXL_EXTERNAL_CALLERS_ONLY;
+
+
 /* domain related functions */
 
 /* If the result is ERROR_ABORTED, the domain may or may not exist
@@ -1307,7 +1316,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 copy_local_disks,
                                 const libxl_domain_restore_params *params,
                                 const libxl_asyncop_how *ao_how,
                                 const libxl_asyncprogress_how *aop_console_how)
@@ -1348,7 +1357,7 @@ static inline int libxl_domain_create_restore_0x040400(
     LIBXL_EXTERNAL_CALLERS_ONLY
 {
     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
@@ -1387,6 +1396,9 @@ int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd,
 #define LIBXL_SUSPEND_DEBUG 1
 #define LIBXL_SUSPEND_LIVE 2
 
+#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
  *   must support this.
tools/libxl/libxl_create.c +84 -3

128 lines not on this page · raw message

tools/libxl/libxl_internal.h +16 -0
index afe6652..938481a 100644
@@ -1835,6 +1835,21 @@ _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);
+
 /* 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 */
@@ -3695,6 +3710,7 @@ struct libxl__domain_create_state {
     int restore_fd, libxc_fd;
     int restore_fdfl; /* original flags of restore_fd */
     int send_back_fd;
+    int copy_local_disks;
     libxl_domain_restore_params restore_params;
     uint32_t domid_soft_reset;
     libxl__domain_create_cb *callback;
tools/libxl/libxl_qmp.c +114 -1

127 lines not on this page · raw message

tools/ocaml/libs/xl/xenlight_stubs.c +1 -1
index 98b52b9..8791175 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);
tools/xl/xl.h +1 -0
index aa95b77..dcdb80d 100644
@@ -35,6 +35,7 @@ struct domain_create {
     int daemonize;
     int monitor; /* handle guest reboots etc */
     int paused;
+    int copy_local_disks;
     int dryrun;
     int quiet;
     int vnc;
tools/xl/xl_migrate.c +72 -7

178 lines not on this page · raw message

tools/xl/xl_vmcontrol.c +1 -1
index 89c2b25..5ffbfb7 100644
@@ -882,7 +882,7 @@ start:
 
         ret = libxl_domain_create_restore(ctx, &d_config,
                                           &domid, restore_fd,
-                                          send_back_fd, &params,
+                                          send_back_fd, dom_info->copy_local_disks, &params,
                                           0, autoconnect_console_how);
 
         libxl_domain_restore_params_dispose(&params);
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 10 lines · Bruno Alvisio

This patch is the first attempt on adding live migration of instances with local storage to Xen. This patch just handles very restricted case of fully virtualized HVMs. The code uses the "drive-mirror" capability provided by QEMU. A new "-l" option is introduced to "xl migrate" command. If provided, the local disk should be mirrored during the migration process. If the option is set, during the VM creation a qemu NBD server is started on the destination. After the instance is suspended on the source, the QMP "disk-mirror" command is issued to mirror the disk to destination. Once the mirroring job is complete, the migration process continues as before. Finally, the NBD server is stopped after the instance is successfully resumed on the destination node.

Since I'm not familiar with all this, can this "driver-mirror" QEMU capability handle the migration of disk while being actively used?

Quoted 10 lines

A major problem with this patch is that the mirroring of the disk is performed only after the memory stream is completed and the VM is suspended on the source; thus the instance is frozen for a long period of time. The reason this happens is that the QEMU process (needed for the disk mirroring) is started on the destination node only after the memory copying is completed. One possibility I was considering to solve this issue (if it is decided that this capability should be used): Could a "helper" QEMU process be started on the destination node at the beginning of the migration sequence with the sole purpose of handling the disk mirroring and kill it at the end of the migration sequence?

Quoted 7 lines

From the suggestions given by Konrad Wilk and Paul Durrant the preferred approach would be to handle the mirroring of disks by QEMU instead of directly being handled directly by, for example, blkback. It would be very helpful for me to have a mental map of all the scenarios that can be encountered regarding local disk (Xen could start supporting live migration of certain types of local disks). This are the ones I can think of:
- Fully Virtualized HVM: QEMU emulation

PV domains can also use the QEMU PV disk backend, so it should be feasible to handle this migration for all guest types just using QEMU.

Quoted 1 line

- blkback

TBH, I don't think such feature should be added to blkback. It's too complex to be implemented inside of the kernel itself.

There are options already available to perform block device duplication at the block level itself in Linux like DRDB [0] and IMHO this is what should be used in conjunction with blkback.

Remember that at the end of day the Unix philosophy has always been to implement simple tools that solve specific problems, and then glue them together in order to solve more complex problems.

In that line of thought, why not simply use iSCSI or similar in order to share the disk with all the hosts?

Quoted 1 line

- blktap / blktap2

This is deprecated and no longer present in upstream kernels, I don't think it's worth looking into it.

Roger.

[0] http://docs.linbit.com/

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

#2 lore raw
Quoted 33 lines · Roger Pau Monné
Quoted 10 lines · Bruno Alvisio

This patch is the first attempt on adding live migration of instances with local storage to Xen. This patch just handles very restricted case of fully virtualized HVMs. The code uses the "drive-mirror" capability provided by QEMU. A new "-l" option is introduced to "xl migrate" command. If provided, the local disk should be mirrored during the migration process. If the option is set, during the VM creation a qemu NBD server is started on the destination. After the instance is suspended on the source, the QMP "disk-mirror" command is issued to mirror the disk to destination. Once the mirroring job is complete, the migration process continues as before. Finally, the NBD server is stopped after the instance is successfully resumed on the destination node.

Since I'm not familiar with all this, can this "driver-mirror" QEMU capability handle the migration of disk while being actively used?

Quoted 10 lines

A major problem with this patch is that the mirroring of the disk is performed only after the memory stream is completed and the VM is suspended on the source; thus the instance is frozen for a long period of time. The reason this happens is that the QEMU process (needed for the disk mirroring) is started on the destination node only after the memory copying is completed. One possibility I was considering to solve this issue (if it is decided that this capability should be used): Could a "helper" QEMU process be started on the destination node at the beginning of the migration sequence with the sole purpose of handling the disk mirroring and kill it at the end of the migration sequence?

Quoted 7 lines

From the suggestions given by Konrad Wilk and Paul Durrant the preferred approach would be to handle the mirroring of disks by QEMU instead of directly being handled directly by, for example, blkback. It would be very helpful for me to have a mental map of all the scenarios that can be encountered regarding local disk (Xen could start supporting live migration of certain types of local disks). This are the ones I can think of:
- Fully Virtualized HVM: QEMU emulation

Quoted 8 lines

PV domains can also use the QEMU PV disk backend, so it should be feasible to handle this migration for all guest types just using QEMU.

Quoted 1 line

- blkback

TBH, I don't think such feature should be added to blkback. It's too complex to be implemented inside of the kernel itself.

In theory if blktap just exposed a dirty bitmap, like Xen does for the memory, the "smarts" of copying over the dirty blocks could be done in the toolstack.

But I think probably the best thing to do to start with would simply say that disk migration is only available with a qdisk backend.

Quoted 10 lines

There are options already available to perform block device duplication at the block level itself in Linux like DRDB [0] and IMHO this is what should be used in conjunction with blkback.

Remember that at the end of day the Unix philosophy has always been to implement simple tools that solve specific problems, and then glue them together in order to solve more complex problems.

In that line of thought, why not simply use iSCSI or similar in order to share the disk with all the hosts?

Well iSCSI can be complicated to set up, and it means your disk data goes over a network rather than simply staying on your local disk. Obviously if people anticipate doing large amounts of migration, then it's worth the effort to set up DRBD or iSCSI. But having the option to do occasional migrates without having to do through that overhead is still something worth having. Given that qemu already has a disk mirroring function, it's probably worth pursuing.

-George

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

#3 lore raw

Thank you for the information and feedback. The scenarios to handle are:
1. QEMU emulation
2. blkback.
3. qdisk.

Quoted 1 line

From the previous e-mails, there is an agreement that no functionality (or

maybe minimal) should be added to blkback.
@Roger Pau Monné: Yes, "drive-mirror" feature handles disks that being actively written. As George Dunlap mentioned, I was thinking of scenarios where iSCSI or DRBD are not set up and only occasional migrations are needed.

TODO for me: I will start looking at the qdisk back and see how can I leverage the disk mirroring feature already provided by QEMU.

Thanks,

Bruno

Quoted 90 lines · George Dunlap
Quoted 2 lines · Roger Pau Monné
Quoted 1 line · Bruno Alvisio

This patch is the first attempt on adding live migration of instances

with local

Quoted 2 lines
Quoted 2 lines

storage to Xen. This patch just handles very restricted case of fully virtualized HVMs. The code uses the "drive-mirror" capability provided

by QEMU.

Quoted 1 line
Quoted 1 line

A new "-l" option is introduced to "xl migrate" command. If provided,

the local

Quoted 1 line
Quoted 1 line

disk should be mirrored during the migration process. If the option is

set,

Quoted 1 line
Quoted 1 line

during the VM creation a qemu NBD server is started on the destination.

After

Quoted 1 line
Quoted 1 line

the instance is suspended on the source, the QMP "disk-mirror" command

is issued

Quoted 1 line
Quoted 1 line

to mirror the disk to destination. Once the mirroring job is complete,

the

Quoted 1 line
Quoted 1 line

migration process continues as before. Finally, the NBD server is

stopped after

Quoted 6 lines
Quoted 1 line

the instance is successfully resumed on the destination node.

Since I'm not familiar with all this, can this "driver-mirror" QEMU capability handle the migration of disk while being actively used?

Quoted 1 line

A major problem with this patch is that the mirroring of the disk is

performed

Quoted 1 line
Quoted 1 line

only after the memory stream is completed and the VM is suspended on

the source;

Quoted 1 line
Quoted 1 line

thus the instance is frozen for a long period of time. The reason this

happens

Quoted 1 line
Quoted 1 line

is that the QEMU process (needed for the disk mirroring) is started on

the

Quoted 1 line
Quoted 1 line

destination node only after the memory copying is completed. One

possibility I

Quoted 1 line
Quoted 1 line

was considering to solve this issue (if it is decided that this

capability

Quoted 1 line
Quoted 1 line

should be used): Could a "helper" QEMU process be started on the

destination

Quoted 2 lines
Quoted 2 lines

node at the beginning of the migration sequence with the sole purpose of handling the disk mirroring and kill it at the end of the migration

sequence?

Quoted 3 lines
Quoted 3 lines

From the suggestions given by Konrad Wilk and Paul Durrant the preferred approach would be to handle the mirroring of disks by QEMU instead of

directly

Quoted 1 line
Quoted 1 line

being handled directly by, for example, blkback. It would be very

helpful for me

Quoted 1 line
Quoted 1 line

to have a mental map of all the scenarios that can be encountered

regarding

Quoted 1 line
Quoted 1 line

local disk (Xen could start supporting live migration of certain types

of local

Quoted 11 lines
Quoted 2 lines

disks). This are the ones I can think of:
- Fully Virtualized HVM: QEMU emulation

PV domains can also use the QEMU PV disk backend, so it should be feasible to handle this migration for all guest types just using QEMU.

Quoted 1 line

- blkback

TBH, I don't think such feature should be added to blkback. It's too complex to be implemented inside of the kernel itself.

In theory if blktap just exposed a dirty bitmap, like Xen does for the memory, the "smarts" of copying over the dirty blocks could be done in the toolstack.

But I think probably the best thing to do to start with would simply say that disk migration is only available with a qdisk backend.

Quoted 10 lines

There are options already available to perform block device duplication at the block level itself in Linux like DRDB [0] and IMHO this is what should be used in conjunction with blkback.

Remember that at the end of day the Unix philosophy has always been to implement simple tools that solve specific problems, and then glue them together in order to solve more complex problems.

In that line of thought, why not simply use iSCSI or similar in order to share the disk with all the hosts?

Well iSCSI can be complicated to set up, and it means your disk data goes over a network rather than simply staying on your local disk. Obviously if people anticipate doing large amounts of migration, then it's worth the effort to set up DRBD or iSCSI. But having the option to do occasional migrates without having to do through that overhead is still something worth having. Given that qemu already has a disk mirroring function, it's probably worth pursuing.

Quoted 2 lines

-George

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

#4 lore raw
In reply to Bruno Alvisio
Quoted 11 lines · Bruno Alvisio

This patch is the first attempt on adding live migration of instances with local storage to Xen. This patch just handles very restricted case of fully virtualized HVMs. The code uses the "drive-mirror" capability provided by QEMU. A new "-l" option is introduced to "xl migrate" command. If provided, the local disk should be mirrored during the migration process. If the option is set, during the VM creation a qemu NBD server is started on the destination. After the instance is suspended on the source, the QMP "disk-mirror" command is issued to mirror the disk to destination. Once the mirroring job is complete, the migration process continues as before. Finally, the NBD server is stopped after the instance is successfully resumed on the destination node.

Quoted 10 lines

A major problem with this patch is that the mirroring of the disk is performed only after the memory stream is completed and the VM is suspended on the source; thus the instance is frozen for a long period of time. The reason this happens is that the QEMU process (needed for the disk mirroring) is started on the destination node only after the memory copying is completed. One possibility I was considering to solve this issue (if it is decided that this capability should be used): Could a "helper" QEMU process be started on the destination node at the beginning of the migration sequence with the sole purpose of handling the disk mirroring and kill it at the end of the migration sequence?

In theory we could, but I am very cautious about this. I _think_ we can change the timing QEMU is started. It can be started earlier, but take precaution that it shouldn't resume the guest.

In any case, start with the simple setup first.

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

#5 lore raw

Thanks Wei. Currently it is started after the memory is streamed from source to destination (for migration) and the booting functions are completed.I was going to ask to the list if there is a specific reason the QEMU process needs to be started at that point.

Also, if the start point of the QEMU process is moved to an earlier part of the domain creation process, how can I run a basic set of tests to validate that I am not breaking any functionality and causing a regression?

Thanks,

Bruno

Quoted 36 lines · Wei Liu
Quoted 1 line · Bruno Alvisio

This patch is the first attempt on adding live migration of instances

with local

Quoted 2 lines

storage to Xen. This patch just handles very restricted case of fully virtualized HVMs. The code uses the "drive-mirror" capability provided

by QEMU.

Quoted 1 line

A new "-l" option is introduced to "xl migrate" command. If provided,

the local

Quoted 1 line

disk should be mirrored during the migration process. If the option is

set,

Quoted 1 line

during the VM creation a qemu NBD server is started on the destination.

After

Quoted 1 line

the instance is suspended on the source, the QMP "disk-mirror" command

is issued

Quoted 1 line

to mirror the disk to destination. Once the mirroring job is complete,

the

Quoted 1 line

migration process continues as before. Finally, the NBD server is

stopped after

Quoted 3 lines

the instance is successfully resumed on the destination node.

A major problem with this patch is that the mirroring of the disk is

performed

Quoted 1 line

only after the memory stream is completed and the VM is suspended on the

source;

Quoted 1 line

thus the instance is frozen for a long period of time. The reason this

happens

Quoted 1 line

is that the QEMU process (needed for the disk mirroring) is started on

the

Quoted 1 line

destination node only after the memory copying is completed. One

possibility I

Quoted 1 line

was considering to solve this issue (if it is decided that this

capability

Quoted 1 line

should be used): Could a "helper" QEMU process be started on the

destination

Quoted 2 lines

node at the beginning of the migration sequence with the sole purpose of handling the disk mirroring and kill it at the end of the migration

Quoted 9 lines

sequence?

Quoted 1 line

In theory we could, but I am very cautious about this. I _think_ we can change the timing QEMU is started. It can be started earlier, but take precaution that it shouldn't resume the guest.

In any case, start with the simple setup first.

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

#6 lore raw
Quoted 4 lines · Bruno Alvisio

Thanks Wei. Currently it is started after the memory is streamed from source to destination (for migration) and the booting functions are completed.I was going to ask to the list if there is a specific reason the QEMU process needs to be started at that point.

I _think_ it is because we don't want QEMU to touch guest memory / state too early. Note I haven't checked the code. Do ask on the list if you aren't sure.

Quoted 5 lines

Also, if the start point of the QEMU process is moved to an earlier part of the domain creation process, how can I run a basic set of tests to validate that I am not breaking any functionality and causing a regression?

Doing some local migration tests as a starter.

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

#7 lore raw
Quoted 9 lines · Wei Liu
Quoted 4 lines · Bruno Alvisio

Thanks Wei. Currently it is started after the memory is streamed from source to destination (for migration) and the booting functions are completed.I was going to ask to the list if there is a specific reason the QEMU process needs to be started at that point.

I _think_ it is because we don't want QEMU to touch guest memory / state too early. Note I haven't checked the code. Do ask on the list if you aren't sure.

I would have thought that's because you need the QEMU state, and that's not saved until the guest on the other end is paused (ie:
rather at the end of the memory copy).

Roger

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

#8 lore raw
Quoted 7 lines · Roger Pau Monné
Quoted 6 lines · Wei Liu
Quoted 4 lines · Bruno Alvisio

Thanks Wei. Currently it is started after the memory is streamed from source to destination (for migration) and the booting functions are completed.I was going to ask to the list if there is a specific reason the QEMU process needs to be started at that point.

Quoted 8 lines
Quoted 3 lines

I _think_ it is because we don't want QEMU to touch guest memory / state too early. Note I haven't checked the code. Do ask on the list if you aren't sure.

I would have thought that's because you need the QEMU state, and that's not saved until the guest on the other end is paused (ie:
rather at the end of the memory copy).

This is also a plausible cause. This can also be worked around I think. The principle is same -- start QEMU first and load state later. But then this begs the question how you can handle the mirroring and state transfer concurrently.

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