libxl: QMP stop/resume & refactor QEMU suspend/resume/save
PATCH RESEND v5 1/1 libxl: QMP stop/resume & refactor QEMU suspend/resume/save
In reply to a message not in the archive# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1330534720 28800
# Node ID c6514dac062bdb033b94ab8f850006a4cb90efab # Parent 8b40decde52bd2e52897e78b5eddeef1509bbf4e
libxl: QMP stop/resume & refactor QEMU suspend/resume/save
Implement QMP stop and resume functionality and split device model save into 3 parts:
suspend_dm(domid)
save_dm(domid, fd)
resume_dm(domid)
Integrate Device model suspend into suspend_common_callback
tools/libxl/libxl_dom.c +61 -19
@@ -516,6 +516,54 @@ static int libxl__domain_suspend_common_return rc ?0 :1 ; } +int libxl__domain_suspend_device_model (libxl__gc *gc,uint32_t domid) +{ +libxl_ctx *ctx =libxl__gc_owner (gc); +int ret =0 ; +const char *filename =libxl__device_model_savefile (gc, domid); + +switch (libxl__device_model_version_running (gc, domid)) { +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : { +LIBXL__LOG (ctx,LIBXL__LOG_DEBUG , +"Saving device model state to %s" , filename); +libxl__qemu_traditional_cmd (gc, domid,"save" ); +libxl__wait_for_device_model (gc, domid,"paused" ,NULL ,NULL ,NULL ); +break ; + } +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : +if (libxl__qmp_stop (gc, domid)) +return ERROR_FAIL ; +/* Save DM state into filename */ + ret =libxl__qmp_save (gc, domid, filename); +if (ret) +unlink (filename); +break ; +default : +return ERROR_INVAL ; + } + +return ret; +} + +int libxl__domain_resume_device_model (libxl__gc *gc,uint32_t domid) +{ + +switch (libxl__device_model_version_running (gc, domid)) { +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : { +libxl__qemu_traditional_cmd (gc, domid,"continue" ); +libxl__wait_for_device_model (gc, domid,"running" ,NULL ,NULL ,NULL ); +break ; + } +case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : +if (libxl__qmp_resume (gc, domid)) +return ERROR_FAIL ; +default : +return ERROR_INVAL ; + } + +return 0 ; +} +static int libxl__domain_suspend_common_callback (void *data) {struct suspendinfo *si = data;
@@ -545,7 +593,7 @@ static int libxl__domain_suspend_common_return 0 ; } si->guest_responded =1 ; -return 1 ; + goto guest_suspended; }if (si->hvm && (!hvm_pvdrv || hvm_s_state)) {
@@ -623,7 +671,7 @@ static int libxl__domain_suspend_common_ shutdown_reason = (info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask;if (shutdown_reason == SHUTDOWN_suspend) {LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"guest has suspended" ); -return 1 ; + goto guest_suspended; } }
@@ -632,6 +680,17 @@ static int libxl__domain_suspend_common_LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"guest did not suspend" );return 0 ; + + guest_suspended: +if (si->hvm) { + ret =libxl__domain_suspend_device_model (si->gc, si->domid); +if (ret) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"libxl__domain_suspend_device_model failed ret=%d" , ret); +return 0 ; + } + } +return 1 ; } static int libxl__toolstack_save(uint32_t domid, uint8_t **buf,
@@ -796,23 +855,6 @@ int libxl__domain_save_device_model(libxstruct stat st;uint32_t qemu_state_len; -switch (libxl__device_model_version_running (gc, domid)) { -case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL : { -LIBXL__LOG (ctx,LIBXL__LOG_DEBUG , -"Saving device model state to %s" , filename); -libxl__qemu_traditional_cmd (gc, domid,"save" ); -libxl__wait_for_device_model (gc, domid,"paused" ,NULL ,NULL ,NULL ); -break ; - } -case LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN : - ret =libxl__qmp_save (gc, domid, (char *)filename); -if (ret) - goto out; -break ; -default : -return ERROR_INVAL ; - } -if (stat (filename, &st) <0 ) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"Unable to stat qemu save file\n" );
tools/libxl/libxl_internal.h +6 -0
@@ -633,6 +633,8 @@ _hidden int libxl__domain_suspend_commonlibxl_domain_type type, int live, int debug); _hidden const char *libxl__device_model_savefile(libxl__gc *gc, uint32_t domid); +_hidden int libxl__domain_suspend_device_model(libxl__gc *gc, uint32_t domid); +_hidden int libxl__domain_resume_device_model(libxl__gc *gc, uint32_t domid); _hidden int libxl__domain_save_device_model(libxl__gc *gc, uint32_t domid, int fd); _hidden void libxl__userdata_destroyall(libxl__gc *gc, uint32_t domid);
@@ -1004,6 +1006,10 @@ _hidden int libxl__qmp_query_serial(libx _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); +/* Suspend QEMU. */ +_hidden int libxl__qmp_stop(libxl__gc *gc, int domid); +/* Resume QEMU. */ +_hidden int libxl__qmp_resume(libxl__gc *gc, int domid);/* Save current QEMU state into fd. */ _hidden int libxl__qmp_save(libxl__gc *gc, int domid, const char *filename);/* close and free the QMP handler */
tools/libxl/libxl_qmp.c +32 -0
@@ -827,6 +827,38 @@ static int qmp_change(libxl__gc *gc, libreturn rc; } +int libxl__qmp_stop (libxl__gc *gc,int domid) +{ +libxl__qmp_handler *qmp =NULL ; +int rc =0 ; + + qmp =libxl__qmp_initialize (libxl__gc_owner (gc), domid); +if (!qmp) +return ERROR_FAIL ; + + rc =qmp_synchronous_send (qmp,"stop" ,NULL , +NULL ,NULL , qmp->timeout); + +libxl__qmp_close (qmp); +return rc; +} + +int libxl__qmp_resume (libxl__gc *gc,int domid) +{ +libxl__qmp_handler *qmp =NULL ; +int rc =0 ; + + qmp =libxl__qmp_initialize (libxl__gc_owner (gc), domid); +if (!qmp) +return ERROR_FAIL ; + + rc =qmp_synchronous_send (qmp,"cont" ,NULL , +NULL ,NULL , qmp->timeout); + +libxl__qmp_close (qmp); +return rc; +} +int libxl__qmp_initializations (libxl__gc *gc,uint32_t domid,const libxl_domain_config *guest_config) {
PATCH RESEND v5 1/1 libxl: support suspend_cancel in domain_resume
In reply to a message not in the archive# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1330534776 28800
# Node ID d2c0bd5c1b414465b1a370f89caceaa7ee6a8ba2 # Parent c6514dac062bdb033b94ab8f850006a4cb90efab
libxl: support suspend_cancel in domain_resume
Add an extra parameter to libxl_domain_resume indicating if the caller wishes to use the SUSPEND_CANCEL style resume instead of the normal resume.
tools/libxl/libxl.c +13 -8
@@ -298,24 +298,29 @@ int libxl_domain_rename(libxl_ctx *ctx,return rc; } -int libxl_domain_resume (libxl_ctx *ctx,uint32_t domid) +int libxl_domain_resume (libxl_ctx *ctx,uint32_t domid,int suspend_cancel) {GC_INIT (ctx);int rc =0 ; -if (LIBXL__DOMAIN_IS_TYPE (gc, domid,HVM )) { -LIBXL__LOG (ctx,LIBXL__LOG_DEBUG ,"Called domain_resume on " -"non-cooperative hvm domain %u" , domid); - rc =ERROR_NI ; - goto out; - } -if (xc_domain_resume (ctx->xch, domid,0 )) { +if (xc_domain_resume (ctx->xch, domid, suspend_cancel)) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"xc_domain_resume failed for domain %u" , domid); rc =ERROR_FAIL ; goto out; } + +if (LIBXL__DOMAIN_IS_TYPE (gc, domid,HVM )) { + rc =libxl__domain_resume_device_model (gc, domid); +if (rc) { +LIBXL__LOG (ctx,LIBXL__LOG_ERROR , +"failed to resume device model for domain %u:%d" , + domid, rc); + goto out; + } + } +if (!xs_resume_domain (ctx->xsh, domid)) { LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "xs_resume_domain failed for domain %u",
tools/libxl/libxl.h +6 -1
@@ -325,7 +325,12 @@ int libxl_domain_create_restore(libxl_ctvoid libxl_domain_config_dispose (libxl_domain_config *d_config);int libxl_domain_suspend (libxl_ctx *ctx,libxl_domain_suspend_info *info,uint32_t domid,int fd); -int libxl_domain_resume (libxl_ctx *ctx,uint32_t domid); + +/* @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. +*/ +int libxl_domain_resume (libxl_ctx *ctx,uint32_t domid,int suspend_cancel);int libxl_domain_shutdown (libxl_ctx *ctx,uint32_t domid);int libxl_domain_reboot (libxl_ctx *ctx,uint32_t domid);int libxl_domain_destroy (libxl_ctx *ctx,uint32_t domid);
tools/libxl/xl_cmdimpl.c +2 -2
@@ -2820,7 +2820,7 @@ static void migrate_domain(const char *dif (common_domname) {libxl_domain_rename (ctx, domid, away_domname, common_domname); } - rc =libxl_domain_resume (ctx, domid); + rc =libxl_domain_resume (ctx, domid,0 );if (!rc)fprintf (stderr,"migration sender: Resumed OK.\n" );fprintf (stderr,"Migration failed due to problems at target.\n" );
@@ -2842,7 +2842,7 @@ static void migrate_domain(const char *dclose (send_fd);migration_child_report (child, recv_fd);fprintf (stderr,"Migration failed, resuming at sender.\n" ); -libxl_domain_resume (ctx, domid); +libxl_domain_resume (ctx, domid,0 );exit (-ERROR_FAIL ); failed_badly:
PATCH RESEND v5 1/1 libxl: refactor migrate_domain and generalize migrate_receive
In reply to a message not in the archive# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1330534783 28800
# Node ID b3faa2880bd3d05d0d515287f21597ac830bd13e # Parent d2c0bd5c1b414465b1a370f89caceaa7ee6a8ba2
libxl: refactor migrate_domain and generalize migrate_receive
Refactor some tasks like establishing the migration channel, initial migration protocol exchange into separate functions, to facilitate re-use, when remus support is introduced. Also, make migrate_receive generic (instead of resorting to stdin and stdout as the file descriptors for communication).
tools/libxl/xl_cmdimpl.c +84 -52
@@ -2600,6 +2600,43 @@ static int save_domain(const char *p, coexit (0 ); } +static pid_t create_migration_child (const char *rune,int *send_fd, +int *recv_fd) +{ +int sendpipe[2 ], recvpipe[2 ]; +pid_t child =-1 ; + +if (!rune || !send_fd || !recv_fd) +return -1 ; + +MUST (libxl_pipe (ctx, sendpipe) ); +MUST (libxl_pipe (ctx, recvpipe) ); + + child =libxl_fork (ctx); +if (child==-1 )exit (1 ); + +if (!child) { +dup2 (sendpipe[0 ],0 ); +dup2 (recvpipe[1 ],1 ); +close (sendpipe[0 ]);close (sendpipe[1 ]); +close (recvpipe[0 ]);close (recvpipe[1 ]); +execlp ("sh" ,"sh" ,"-c" ,rune,(char *)0 ); +perror ("failed to exec sh" ); +exit (-1 ); + } + +close (sendpipe[0 ]); +close (recvpipe[1 ]); + *send_fd = sendpipe[1 ]; + *recv_fd = recvpipe[0 ]; + +/* if receiver dies, we get an error and can clean up +rather than just dying */ +signal (SIGPIPE ,SIG_IGN ); + +return child; +} +static int migrate_read_fixedmessage (int fd,const void *msg,int msgsz,const char *what,const char *rune) {char buf[msgsz];
@@ -2685,53 +2722,17 @@ static void migration_child_report(pid_t migration_child =0 ; } -static void migrate_domain (const char *domain_spec,const char *rune, -const char *override_config_file) +static void migrate_do_preamble (int send_fd,int recv_fd,pid_t child, +uint8_t *config_data,int config_len, +const char *rune) { -pid_t child =-1 ; -int rc; -int sendpipe[2 ], recvpipe[2 ]; -int send_fd, recv_fd; -libxl_domain_suspend_info suspinfo; -char *away_domname; -char rc_buf; -uint8_t *config_data; -int config_len; - -save_domain_core_begin (domain_spec, override_config_file, - &config_data, &config_len); - -if (!config_len) { -fprintf (stderr,"No config file stored for running domain and " -"none supplied - cannot migrate.\n" ); +int rc =0 ; + +if (send_fd <0 || recv_fd <0 ) { +fprintf (stderr,"migrate_do_preamble: invalid file descriptors\n" );exit (1 ); } -MUST (libxl_pipe (ctx, sendpipe) ); -MUST (libxl_pipe (ctx, recvpipe) ); - - child =libxl_fork (ctx); -if (child==-1 )exit (1 ); - -if (!child) { -dup2 (sendpipe[0 ],0 ); -dup2 (recvpipe[1 ],1 ); -close (sendpipe[0 ]);close (sendpipe[1 ]); -close (recvpipe[0 ]);close (recvpipe[1 ]); -execlp ("sh" ,"sh" ,"-c" ,rune,(char *)0 ); -perror ("failed to exec sh" ); -exit (-1 ); - } - -close (sendpipe[0 ]); -close (recvpipe[1 ]); - send_fd = sendpipe[1 ]; - recv_fd = recvpipe[0 ]; - -signal (SIGPIPE ,SIG_IGN ); -/* if receiver dies, we get an error and can clean up -rather than just dying */ - rc =migrate_read_fixedmessage (recv_fd, migrate_receiver_banner,sizeof (migrate_receiver_banner)-1 ,"banner" , rune);
@@ -2744,6 +2745,34 @@ static void migrate_domain(const char *dsave_domain_core_writeconfig (send_fd,"migration stream" , config_data, config_len); +} + +static void migrate_domain (const char *domain_spec,const char *rune, +const char *override_config_file) +{ +pid_t child =-1 ; +int rc; +int send_fd =-1 , recv_fd =-1 ; +libxl_domain_suspend_info suspinfo; +char *away_domname; +char rc_buf; +uint8_t *config_data; +int config_len; + +save_domain_core_begin (domain_spec, override_config_file, + &config_data, &config_len); + +if (!config_len) { +fprintf (stderr,"No config file stored for running domain and " +"none supplied - cannot migrate.\n" ); +exit (1 ); + } + + child =create_migration_child (rune, &send_fd, &recv_fd); + +migrate_do_preamble (send_fd, recv_fd, child, config_data, config_len, + rune); +xtl_stdiostream_adjust_flags (logger,XTL_STDIOSTREAM_HIDE_PROGRESS ,0 );memset (&suspinfo,0 ,sizeof (suspinfo));
@@ -2867,7 +2896,8 @@ static void core_dump_domain(const charif (rc) {fprintf (stderr,"core dump failed (rc=%d)\n" ,rc);exit (-1 ); } } -static void migrate_receive (int debug,int daemonize,int monitor) +static void migrate_receive (int debug,int daemonize,int monitor, +int send_fd,int recv_fd) {int rc, rc2;char rc_buf;
@@ -2879,7 +2909,7 @@ static void migrate_receive(int debug, ifprintf (stderr,"migration target: Ready to receive domain.\n" ); - CHK_ERRNO( libxl_write_exactly(ctx, 1, + CHK_ERRNO( libxl_write_exactly(ctx, send_fd, migrate_receiver_banner, sizeof(migrate_receiver_banner)-1, "migration ack stream",
@@ -2891,7 +2921,7 @@ static void migrate_receive(int debug, i dom_info.monitor = monitor; dom_info.paused =1 ; dom_info.restore_file ="incoming migration stream" ; - dom_info.migrate_fd =0 ;/* stdin */ + dom_info.migrate_fd = recv_fd; dom_info.migration_domname_r = &migration_domname; dom_info.no_incr_generationid =1 ;
@@ -2905,13 +2935,13 @@ static void migrate_receive(int debug, ifprintf (stderr,"migration target: Transfer complete," " requesting permission to start domain.\n" ); - rc =libxl_write_exactly (ctx,1 , + rc =libxl_write_exactly (ctx, send_fd, migrate_receiver_ready,sizeof (migrate_receiver_ready),"migration ack stream" ,"ready message" );if (rc)exit (-rc); - rc =migrate_read_fixedmessage (0 , migrate_permission_to_go, + rc =migrate_read_fixedmessage (recv_fd, migrate_permission_to_go,sizeof (migrate_permission_to_go),"GO message" ,0 );if (rc) goto perhaps_destroy_notify_rc;
@@ -2930,7 +2960,7 @@ static void migrate_receive(int debug, i rc =0 ; perhaps_destroy_notify_rc: - rc2 =libxl_write_exactly (ctx,1 , + rc2 =libxl_write_exactly (ctx, send_fd, migrate_report,sizeof (migrate_report),"migration ack stream" ,"success/failure report" );
@@ -2938,7 +2968,7 @@ static void migrate_receive(int debug, i rc_buf = -rc;assert (!!rc_buf == !!rc); - rc2 =libxl_write_exactly (ctx,1 , &rc_buf,1 , + rc2 =libxl_write_exactly (ctx, send_fd, &rc_buf,1 ,"migration ack stream" ,"success/failure code" );if (rc2)exit (-ERROR_BADFAIL );
@@ -2956,7 +2986,7 @@ static void migrate_receive(int debug, ifprintf (stderr,"migration target: Cleanup OK, granting sender" " permission to resume.\n" ); - rc2 = libxl_write_exactly(ctx, 1, + rc2 = libxl_write_exactly(ctx, send_fd, migrate_permission_to_go, sizeof(migrate_permission_to_go), "migration ack stream",
@@ -3052,7 +3082,9 @@ int main_migrate_receive(int argc, charhelp ("migrate-receive" );return 2 ; } -migrate_receive (debug, daemonize, monitor); +migrate_receive (debug, daemonize, monitor, +STDOUT_FILENO ,STDIN_FILENO ); +return 0 ; }
Re: [PATCH 0 of 3 RESEND V5] libxl: refactor suspend/resume code
In reply to a message not in the archiveSorry for the empty preamble. something got messed up and one of the patches also
didnt make it! Unfortunately, I forgot to include the last patch
"libxl: resume instead of unpause on xl save -c" in this series. (message id: [email protected] ) It remains the same.
Ian, could you please include that, when you commit this series ?
Intro message:
------
This patch series refactors the suspend/resume code to minimize Remus specific code in libxl. There are a couple of trivial bug fixes too.
Changes in V5:
This series is just a resend, rebasing the patches to the latest tip. It
depends on
Stefano's "V5: libxl: save/restore qemu physmap".
Changes in V4:
1. Incorporated Ian Campbell's comments on the suspend_cancel support patch.
Changes in V3:
1. rebase patches based on Stefano's patches
use qmp_save instead of qmp_migrate
2. check if qemu moves to "running" state after resuming the device model
3. Moved comments on the co-operative suspend to libxl.h
Changes in V2:
1. migrate code is refactored as save_config , create child, do_preamble instead of coaelscing them all into one single function.
2. More documentation for suspend_cancel parameter in domain_resume
3. Minor nits
shriram
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 0 of 3 RESEND V5] libxl: refactor suspend/resume code
Quoted 12 lines · Shriram Rajagopalan
Sorry for the empty preamble. something got messed up and one of the patches also didnt make it! Unfortunately, I forgot to include the last patch
"libxl: resume instead of unpause on xl save -c" in this series. (message id: [email protected] ) It remains the same.
Ian, could you please include that, when you commit this series ?
Intro message:
------
Quoted 7 lines
This patch series refactors the suspend/resume code to minimize Remus specific code in libxl. There are a couple of trivial bug fixes too.
Changes in V5:
This series is just a resend, rebasing the patches to the latest tip. It depends on Stefano's "V5: libxl: save/restore qemu physmap".
Small update: the promise of a soon review was reasserted. In any case be sure that your patch series is going to go in before the 4.2 freeze, one way or another.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH 0 of 3 RESEND V5] libxl: refactor suspend/resume code
In reply to Shriram RajagopalanShriram Rajagopalan writes ("Re: [Xen-devel] [PATCH 0 of 3 RESEND V5] libxl: refactor suspend/resume code"):
Quoted 2 lines
This series is just a resend, rebasing the patches to the latest tip. It depends on Stefano's "V5: libxl: save/restore qemu physmap".
Thanks.
It's unfortunate that this has been blocked so long. When it becomes unblocked (ie, when the qemu upstream part is in) I trust Stefano and you will remind me.
Ian.