Migration on QEMU upstream
cover Migration on QEMU upstream
Hi all,
This patch series introduce migration with QEMU upstream.
A patch series for QEMU will be sent later meant to "fix" the default behavior of QEMU during save/restore.
There is two new QMP commands implemented:
- getfd: This give a file descriptor to QEMU through the unix socket.
- migration: This ask QEMU to save its states in a fd previously sent.
In order to call "getfd", an alternative qmp_send have been implemented in libxl.
Regards,
Anthony PERARD (3):
libxl_qmp: Cut qmp_send function.
libxl_qmp: Command migrate.
libxl: Introduce migrate with the new QEMU.
tools/libxl/libxl_dm.c | 6 +- tools/libxl/libxl_dom.c | 28 +++++++- tools/libxl/libxl_internal.h | 2 + tools/libxl/libxl_qmp.c | 161 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 176 insertions(+), 21 deletions(-)
Signature · 1 line
Anthony PERARD
PATCH 1/3 libxl_qmp: Cut qmp_send function.
This patch prepare for the next patch, that will introduce an alternative send function.
--- tools/libxl/libxl_qmp.c | 56 +++++++++++++++++++++++++++++++--------------- 1 files changed, 38 insertions(+), 18 deletions(-)
tools/libxl/libxl_qmp.c +38 -18
@@ -446,13 +446,14 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)return rc; } -static int qmp_send (libxl__qmp_handler *qmp, -const char *cmd,libxl_key_value_list *args, -qmp_callback_t callback,void *opaque, -qmp_request_context *context) +static char *qmp_send_prepare (libxl__gc *gc,libxl__qmp_handler *qmp, +const char *cmd,libxl_key_value_list *args, +qmp_callback_t callback,void *opaque, +qmp_request_context *context) {yajl_gen_config conf = {0 ,NULL }; -const unsigned char *buf; +const unsigned char *buf =NULL ; +char *ret =NULL ;unsigned int len =0 ;yajl_gen_status s;yajl_gen hand;
@@ -460,7 +461,7 @@ static int qmp_send(libxl__qmp_handler *qmp, hand =yajl_gen_alloc (&conf,NULL );if (!hand) { -return -1 ; +return NULL ; }yajl_gen_map_open (hand);
@@ -479,14 +480,14 @@ static int qmp_send(libxl__qmp_handler *qmp,if (s) {LIBXL__LOG (qmp->ctx,LIBXL__LOG_ERROR ,"Failed to generate a qmp command" ); -return -1 ; + goto out; } elm =malloc (sizeof (callback_id_pair));if (elm ==NULL ) {LIBXL__LOG_ERRNO (qmp->ctx,LIBXL__LOG_ERROR ,"Failed to allocate a QMP callback" ); - goto error; + goto out; } elm->id = qmp->last_id_used; elm->callback = callback;
@@ -494,22 +495,41 @@ static int qmp_send(libxl__qmp_handler *qmp, elm->context = context;SIMPLEQ_INSERT_TAIL (&qmp->callback_list, elm, next); + ret =libxl__strndup (gc, (const char *)buf, len); +LIBXL__LOG (qmp->ctx,LIBXL__LOG_DEBUG ,"next qmp command: '%s'" , buf); -if (libxl_write_exactly (qmp->ctx, qmp->qmp_fd, buf, len, +out: +yajl_gen_free (hand); +return ret; +} + +static int qmp_send (libxl__qmp_handler *qmp, +const char *cmd,libxl_key_value_list *args, +qmp_callback_t callback,void *opaque, +qmp_request_context *context) +{ +char *buf =NULL ; +int rc =-1 ; +libxl__gc gc =LIBXL_INIT_GC (qmp->ctx); + + buf =qmp_send_prepare (&gc, qmp, cmd, args, callback, opaque, context); + +if (buf ==NULL ) { + goto out; + } + +if (libxl_write_exactly (qmp->ctx, qmp->qmp_fd, buf,strlen (buf),"QMP command" ,"QMP socket" )) - goto error; + goto out;if (libxl_write_exactly (qmp->ctx, qmp->qmp_fd,"\r\n" ,2 ,"CRLF" ,"QMP socket" )) - goto error; + goto out; -yajl_gen_free (hand); - -return qmp->last_id_used; - -error: -yajl_gen_free (hand); -return -1 ; + rc = qmp->last_id_used; +out: +libxl__free_all (&gc); +return rc; } static int qmp_synchronous_send(libxl__qmp_handler *qmp, const char *cmd,
Signature · 1 line
Anthony PERARD
PATCH 2/3 libxl_qmp: Command migrate.
In reply to Anthony PERARDThis command works in two steps. First, a fd is sent to QEMU through the QMP socket. And then, the second command "migrate" use the fd previously sent to ask QEMU to save its states.
This come with an alternative qmp_send function that can send a fd.
--- tools/libxl/libxl_internal.h | 2 + tools/libxl/libxl_qmp.c | 109 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.h +2 -0
@@ -528,6 +528,8 @@ _hidden int libxl__qmp_query_serial(libxl__qmp_handler *qmp); _hidden int libxl__qmp_pci_add(libxl__gc *gc, int d, libxl_device_pci *pcidev); _hidden int libxl__qmp_pci_del(libxl__gc *gc, int domid,libxl_device_pci *pcidev); +/* Save current QEMU state into fd. */ +_hidden int libxl__qmp_migrate(libxl__gc *gc, int domid, int fd);/* close and free the QMP handler */ _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);/* remove the socket file, if the file has already been removed,
tools/libxl/libxl_qmp.c +109 -0
121 lines not on this page · raw message
Signature · 1 line
Anthony PERARD
PATCH 3/3 libxl: Introduce migrate with the new QEMU.
In reply to Anthony PERARD--- tools/libxl/libxl_dm.c | 6 ++++-- tools/libxl/libxl_dom.c | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-)
tools/libxl/libxl_dm.c +4 -2
@@ -408,8 +408,10 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, } }if (info->saved_state) { -flexarray_append (dm_args,"-loadvm" ); -flexarray_append (dm_args, info->saved_state); +/* This file descriptor is meant to be used by QEMU */ +int migration_fd =open (info->saved_state,O_RDONLY ); +flexarray_append (dm_args,"-incoming" ); +flexarray_append (dm_args,libxl__sprintf (gc,"fd:%d" , migration_fd)); }for (i =0 ; info->extra && info->extra[i] !=NULL ; i++)flexarray_append (dm_args, info->extra[i]);
tools/libxl/libxl_dom.c +25 -3
@@ -595,9 +595,31 @@ int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd)struct stat st;uint32_t qemu_state_len; -LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Saving device model state to %s" , filename); -libxl__xs_write (gc,XBT_NULL ,libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , domid),"save" ); -libxl__wait_for_device_model (gc, domid,"paused" ,NULL ,NULL ,NULL ); +switch (libxl__device_model_version_running (gc, domid)) { +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : { +char *path =NULL ; +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG , +"Saving device model state to %s" , filename); + path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , + domid); +libxl__xs_write (gc,XBT_NULL , path,"save" ); +libxl__wait_for_device_model (gc, domid,"paused" ,NULL ,NULL ,NULL ); +break ; + } +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : + fd2 =open (filename,O_WRONLY |O_CREAT |O_TRUNC ); +if (fd2 <0 ) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR , +"Unable to create a QEMU save file\n" ); +return ERROR_FAIL ; + } +/* Save DM state into fd2 */ +if (libxl__qmp_migrate (gc, domid, fd2)) +return ERROR_FAIL ; +break ; +default : +return ERROR_INVAL ; + }if (stat (filename, &st) <0 ) {
Signature · 1 line
Anthony PERARD
Re: [PATCH 3/3] libxl: Introduce migrate with the new QEMU.
tools/libxl/libxl_dom.c int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd) · line 610
Quoted 2 lines · Anthony PERARD
tools/libxl/libxl_dom.c +2
-0+case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : + fd2 =open (filename,O_WRONLY |O_CREAT |O_TRUNC );
I havent checked wether automated testing caught this, but:
In function 'open',
inlined from 'libxl__domain_save_device_model' at libxl_dom.c:630:/usr/include/bits/fcntl2.h:51: error: call to '__open_missing_mode' declared with attribute error: open with O_CREAT in second argument needs 3 arguments make[3]: *** [libxl_dom.o] Error 1
Olaf
Re: [PATCH 3/3] libxl: Introduce migrate with the new QEMU.
Quoted 11 lines · Olaf Hering
tools/libxl/libxl_dom.c int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd) · line 610
Quoted 2 lines · Anthony PERARD
tools/libxl/libxl_dom.c +2
-0+case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : + fd2 =open (filename,O_WRONLY |O_CREAT |O_TRUNC );I havent checked wether automated testing caught this, but:
In function 'open',
inlined from 'libxl__domain_save_device_model' at libxl_dom.c:630:/usr/include/bits/fcntl2.h:51: error: call to '__open_missing_mode' declared with attribute error: open withO_CREATin second argument needs 3 arguments make[3]: *** [libxl_dom.o] Error 1
Was a fix for this ever posted?
Ian.
Re: [PATCH 3/3] libxl: Introduce migrate with the new QEMU.
Quoted 6 lines · Ian Campbell
Quoted 5 lines · Olaf Hering
Quoted 2 lines · Anthony PERARD
+ case
LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN:
+ fd2 =open(filename, O_WRONLY | O_CREAT | O_TRUNC);
Quoted 8 lines
Quoted 6 lines
I havent checked wether automated testing caught this, but:
In function 'open',
inlined from 'libxl__domain_save_device_model' at libxl_dom.c:630:/usr/include/bits/fcntl2.h:51: error: call to '__open_missing_mode' declared with attribute error: open withO_CREATin second argument needs 3 arguments make[3]: *** [libxl_dom.o] Error 1Was a fix for this ever posted?
I don't think so. I will do one.
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel
Quoted 9 lines · Anthony PERARD
Hi all,
This patch series introduce migration with QEMU upstream.
A patch series for QEMU will be sent later meant to "fix" the default behavior of QEMU during save/restore.
There is two new QMP commands implemented:
- getfd: This give a file descriptor to QEMU through the unix socket.
This sounds more like a setfd command.
Quoted 1 line
- migration: This ask QEMU to save its states in a fd previously sent.
Why can the fd not be included in this message directly? How is a given {s,g}etfd call associated with the migration command? What happens if some other command also wants to receive an fd in the future?
I presume that a bunch of this will become more obvious when the qemu side is posted, there's a qemu protocol spec in that right?
Quoted 2 lines
In order to call "getfd", an alternative
qmp_sendhave been implemented in libxl.
You could also have added optional msg_control{len} parameters to the existing command. I don't know if that is better though.
Ian.
Quoted 15 lines
Regards,
Anthony PERARD (3):
libxl_qmp: Cutqmp_sendfunction.
libxl_qmp: Command migrate.
libxl: Introduce migrate with the new QEMU.tools/libxl/libxl_dm.c | 6 +- tools/libxl/libxl_dom.c | 28 +++++++- tools/libxl/libxl_internal.h | 2 + tools/libxl/libxl_qmp.c | 161 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 176 insertions(+), 21 deletions(-)
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Anthony PERARD
Hi all,
This patch series introduce migration with QEMU upstream.
Quoted 7 lines
Quoted 5 lines
A patch series for QEMU will be sent later meant to "fix" the default behavior of QEMU during save/restore.
There is two new QMP commands implemented:
- getfd: This give a file descriptor to QEMU through the unix socket.This sounds more like a setfd command.
Well, it's the name of the QMP command. I just respect the "convention" I have in the rest of the file that is /(libxl__)?qmp_(?<command_name>.+)/
Quoted 3 lines
Quoted 1 line
- migration: This ask QEMU to save its states in a fd previously sent.
Why can the fd not be included in this message directly?
The migrate command only accept "fd:namedfd" as output (among other way). And to have a named fd, we have to call "getfd" fist. But here, I do both with one call from the wild.
Quoted 1 line
How is a given {s,g}etfd call associated with the migration command?
libxl__qmp_migrate will call a static function qmp_getfd(fd, "migration-fd")
Quoted 1 line
What happens if some other command also wants to receive an fd in the future?
The futur command can just call the qmp_getfd function, or we can export qmp_getfd.
Quoted 2 lines
I presume that a bunch of this will become more obvious when the qemu side is posted, there's a qemu protocol spec in that right?
Mmh, not really, there is nothing to had in QEMU side. getfd and migrate are both QMP command. You can look in the file qmp-commands.hx in QEMU for the command migrate and getfd; and look in the file docs/migration.txt to know wich "Types of migration" QEMU use.
The QEMU patch series I'm about to send is just a "fix" for the Xen case:
- do not save the RAM.
- at restore time, do not try to "allocate" (populate_physmap) memory
that should already be allocated, and access to the right guest address in case this one have been "moved" (true for the VideoRAM) ("moved" using add_to_physmap).
Quoted 5 lines
Quoted 2 lines
In order to call "getfd", an alternative
qmp_sendhave been implemented in libxl.You could also have added optional msg_control{len} parameters to the existing command. I don't know if that is better though.
Well, this will be an extra parameter that will be used in only one case (I think). And this parameter will be a bit obscure. So, probably both are good. Also, the code that prepare the message (string) to be sent is in a separate function now, so both qmp_send and qmp_send_fd do not have anything in common (almost).
Thanks,
Signature · 6 lines
Anthony PERARD _______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel
On Thu, 2011-11-24 at 12:09 +0000, Anthony PERARD wrote:
[...]
Quoted 4 lines
Mmh, not really, there is nothing to had in QEMU side. getfd and migrate are both QMP command. You can look in the file qmp-commands.hx in QEMU for the command migrate and getfd; and look in the file
docs/migration.txtto know wich "Types of migration" QEMU use.
Oh, I didn't realise these were all existing qmp commands, I assumed a patch adding them was forthcoming. You can ignore most of what I said then...
Quoted 22 lines
The QEMU patch series I'm about to send is just a "fix" for the Xen case:
- do not save the RAM.
- at restore time, do not try to "allocate" (populate_physmap) memory
that should already be allocated, and access to the right guest address in case this one have been "moved" (true for the VideoRAM) ("moved" usingadd_to_physmap).Quoted 5 lines
Quoted 2 lines
In order to call "getfd", an alternative
qmp_sendhave been implemented in libxl.You could also have added optional msg_control{len} parameters to the existing command. I don't know if that is better though.
Well, this will be an extra parameter that will be used in only one case (I think). And this parameter will be a bit obscure. So, probably both are good. Also, the code that prepare the message (string) to be sent is in a separate function now, so both
qmp_sendandqmp_send_fddo not have anything in common (almost).Thanks,
Anthony PERARD writes ("[Xen-devel] [PATCH 0/3] Migration on QEMU upstream"):
Quoted 1 line
This patch series introduce migration with QEMU upstream.