libxl: refactor suspend/resume code
PATCH v3 1/1 libxl: refactor suspend/resume code
This patch series refactors the suspend/resume code to minimize Remus specific code in libxl. There are a couple of trivial bug fixes too.
These patches depend on Stefano's "v4 libxl: save/restore qemu physmap"
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.xensource.com/xen-devel
PATCH v3 1/1 libxl: helper function to send commands to traditional qemu
# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1328251592 28800
# Node ID 340dd6a3f0dab2fcba83a68dea072e9d9af20182 # Parent 4612cca7fb7c06e83a205510f6c2e43d5f246582
libxl: helper function to send commands to traditional qemu
Introduce a helper function to send commands to traditional qemu. qemu_pci_add_xenstore, qemu_pci_remove_xenstore, libxl__domain_save_device_model and libxl_domain_unpause have been refactored to use this function.
tools/libxl/libxl.c +1 -1
@@ -517,7 +517,7 @@ int libxl_domain_unpause(libxl_ctx *ctx, path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/state" , domid); state =libxl__xs_read (gc,XBT_NULL , path);if (state !=NULL && !strcmp (state,"paused" )) { -libxl__xs_write (gc,XBT_NULL ,libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , domid),"continue" ); +libxl__qemu_traditional_cmd (gc, domid,"continue" );libxl__wait_for_device_model (gc, domid,"running" ,NULL ,NULL ,NULL ); }
tools/libxl/libxl_dom.c +10 -4
@@ -409,6 +409,15 @@ static int libxl__toolstack_restore(uintreturn 0 ; } +int libxl__qemu_traditional_cmd (libxl__gc *gc,uint32_t domid, +const char *cmd) +{ +char *path =NULL ; + path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , + domid); +return libxl__xs_write (gc,XBT_NULL , path,"%s" , cmd); +} + int libxl__domain_restore_common(libxl__gc *gc, uint32_t domid, libxl_domain_build_info *info, libxl__domain_build_state *state,
@@ -761,12 +770,9 @@ int libxl__domain_save_device_model(libxswitch (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__qemu_traditional_cmd (gc, domid,"save" );libxl__wait_for_device_model (gc, domid,"paused" ,NULL ,NULL ,NULL );break ; }
tools/libxl/libxl_internal.h +2 -0
@@ -263,6 +263,8 @@ _hidden int libxl__build_hvm(libxl__gc * libxl_device_model_info *dm_info, libxl__domain_build_state *state); +_hidden int libxl__qemu_traditional_cmd(libxl__gc *gc, uint32_t domid, +const char *cmd); _hidden int libxl__domain_rename(libxl__gc *gc, uint32_t domid,const char *old_name,const char *new_name,xs_transaction_t trans);
tools/libxl/libxl_pci.c +3 -5
@@ -602,9 +602,8 @@ static int qemu_pci_add_xenstore(libxl__libxl__xs_write (gc,XBT_NULL , path,PCI_BDF , pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); } - path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , - domid); -xs_write (ctx->xsh,XBT_NULL , path,"pci-ins" ,strlen ("pci-ins" )); + +libxl__qemu_traditional_cmd (gc, domid,"pci-ins" ); rc =libxl__wait_for_device_model (gc, domid,NULL ,NULL , pci_ins_check, state); path = libxl__sprintf(gc, "/local/domain/0/device-model/%d/parameter",
@@ -857,12 +856,11 @@ static int qemu_pci_remove_xenstore(libx path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/parameter" , domid);libxl__xs_write (gc,XBT_NULL , path,PCI_BDF , pcidev->domain, pcidev->bus, pcidev->dev, pcidev->func); - path =libxl__sprintf (gc,"/local/domain/0/device-model/%d/command" , domid);/* Remove all functions at once atomically by only signalling * device-model for function 0 */ if ( !force && (pcidev->vdevfn &0x7 ) ==0 ) { -xs_write (ctx->xsh,XBT_NULL , path,"pci-rem" ,strlen ("pci-rem" )); +libxl__qemu_traditional_cmd (gc, domid,"pci-rem" );if (libxl__wait_for_device_model (gc, domid,"pci-removed" ,NULL ,NULL ,NULL ) <0 ) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"Device Model didn't respond in time" );
PATCH v3 1/1 libxl: bugfix: create_domain() return to caller if !daemonize
In reply to [email protected]# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1328251593 28800
# Node ID 636da26c40d37b84a93b6a6c3881b2fccc768aa2 # Parent 340dd6a3f0dab2fcba83a68dea072e9d9af20182
libxl: bugfix: create_domain() return to caller if !daemonize
Currently the create_domain function does not honor the daemonize flag properly. It exits irrespective of the value of the flag. This patch fixes the issue.
tools/libxl/xl_cmdimpl.c +1 -1
@@ -1814,7 +1814,7 @@ waitpid_out:* If we have daemonized then do not return to the caller -- this has * already happened in the parent. */ -if ( !need_daemon ) +if ( daemonize && !need_daemon )exit (ret);return ret;
PATCH v3 1/1 libxl: QMP stop/resume & refactor QEMU suspend/resume/save
In reply to [email protected]# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1328251593 28800
# Node ID 329b3c94c618addb1e802cebc7fe23b12b432398 # Parent 636da26c40d37b84a93b6a6c3881b2fccc768aa2
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
@@ -488,6 +488,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;
@@ -517,7 +565,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)) {
@@ -595,7 +643,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; } }
@@ -604,6 +652,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,
@@ -768,23 +827,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
@@ -277,6 +277,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);
@@ -620,6 +622,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
@@ -802,6 +802,38 @@ out:return 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_ctx *ctx,uint32_t domid) {libxl__qmp_handler *qmp =NULL ;
PATCH v3 1/1 libxl: support suspend_cancel in domain_resume
In reply to [email protected]# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1328251593 28800
# Node ID f853c88f0230a2e9d2e1006a9cd220c4cd27e74d # Parent 329b3c94c618addb1e802cebc7fe23b12b432398
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
@@ -229,24 +229,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
@@ -268,7 +268,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
@@ -2751,7 +2751,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,1 );if (!rc)fprintf (stderr,"migration sender: Resumed OK.\n" );fprintf (stderr,"Migration failed due to problems at target.\n" );
@@ -2773,7 +2773,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,1 );exit (-ERROR_FAIL ); failed_badly:
PATCH v3 1/1 libxl: refactor migrate_domain and generalize migrate_receive
In reply to [email protected]# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1328251593 28800
# Node ID 62c4fd2fe9bbc2c283e3998d852317a48e9f9770 # Parent f853c88f0230a2e9d2e1006a9cd220c4cd27e74d
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
@@ -2531,6 +2531,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];
@@ -2616,53 +2653,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);
@@ -2675,6 +2676,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));
@@ -2798,7 +2827,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;
@@ -2810,7 +2840,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",
@@ -2822,7 +2852,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 ;
@@ -2836,13 +2866,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;
@@ -2861,7 +2891,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" );
@@ -2869,7 +2899,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 );
@@ -2887,7 +2917,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",
@@ -2983,7 +3013,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 ; }
PATCH v3 1/1 libxl: resume instead of unpause on xl save -c
In reply to [email protected]# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1328251593 28800
# Node ID c7abecc14cceb18140335ebe20faad826282cd1f # Parent 62c4fd2fe9bbc2c283e3998d852317a48e9f9770
libxl: resume instead of unpause on xl save -c
The guest is "suspended" via libxl_domain_suspend when taking a snapshot. So call libxl_domain_resume instead of libxl_domain_unpause, when taking a checkpoint of the domain (using xl save -c).
tools/libxl/xl_cmdimpl.c +1 -1
@@ -2524,7 +2524,7 @@ static int save_domain(const char *p, coclose (fd);if (checkpoint) -libxl_domain_unpause (ctx, domid); +libxl_domain_resume (ctx, domid,1 );else libxl_domain_destroy (ctx, domid);
Re: [PATCH 3 of 6 V3] libxl: QMP stop/resume & refactor QEMU suspend/resume/save
In reply to [email protected]Quoted 13 lines · On Fri, 2012-02-03 at 06:49 +0000, [email protected] wrote:
# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1328251593 28800
# Node ID329b3c94c618addb1e802cebc7fe23b12b432398# Parent636da26c40d37b84a93b6a6c3881b2fccc768aa2
libxl: QMP stop/resume & refactor QEMU suspend/resume/saveImplement QMP stop and resume functionality and split device model save into 3 parts:
suspend_dm(domid)
save_dm(domid, fd)
resume_dm(domid)
Quoted 3 lines
Integrate Device model suspend into
suspend_common_callbackSigned-off-by Shriram Rajagopalan <[email protected]>
Quoted 184 lines
diff -r
636da26c40d3-r329b3c94c618tools/libxl/libxl_dom.ctools/libxl/libxl_dom.c +61
-19@@ -488,6 +488,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;@@ -517,7 +565,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)) {@@ -595,7 +643,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; } }@@ -604,6 +652,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,@@ -768,23 +827,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" );diff -r
636da26c40d3-r329b3c94c618tools/libxl/libxl_internal.htools/libxl/libxl_internal.h +6
-0@@ -277,6 +277,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);@@ -620,6 +622,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 */ diff -r
636da26c40d3-r329b3c94c618tools/libxl/libxl_qmp.ctools/libxl/libxl_qmp.c +32
-0@@ -802,6 +802,38 @@ out:return 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_ctx *ctx,uint32_t domid) {libxl__qmp_handler *qmp =NULL ;
Re: [PATCH 4 of 6 V3] libxl: support suspend_cancel in domain_resume
In reply to [email protected]Quoted 75 lines · On Fri, 2012-02-03 at 06:50 +0000, [email protected] wrote:
# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1328251593 28800
# Node IDf853c88f0230a2e9d2e1006a9cd220c4cd27e74d# Parent329b3c94c618addb1e802cebc7fe23b12b432398
libxl: supportsuspend_cancelindomain_resumeAdd an extra parameter to
libxl_domain_resumeindicating if the caller wishes to use theSUSPEND_CANCELstyle resume instead of the normal resume.Signed-off-by Shriram Rajagopalan <[email protected]>diff -r
329b3c94c618-rf853c88f0230tools/libxl/libxl.ctools/libxl/libxl.c +13
-8@@ -229,24 +229,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",diff -r
329b3c94c618-rf853c88f0230tools/libxl/libxl.htools/libxl/libxl.h +6
-1@@ -268,7 +268,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);diff -r
329b3c94c618-rf853c88f0230tools/libxl/xl_cmdimpl.c
tools/libxl/xl_cmdimpl.c static void migrate_domain(const char *d · line 2754
Quoted 5 lines
tools/libxl/xl_cmdimpl.c +1
-1@@ -2751,7 +2751,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,1 );
Previously this code would have been equivalent to passing 0 not 1. It may be ok to change this but it should be separate. However I'm a bit dubious about changing it without adding some code to detect if the guest supports it. (I know libxl_domain_resume is currently broken for the non-cooperative suspend case but we shouldn't paper over that)
Ian.
Re: [PATCH 5 of 6 V3] libxl: refactor migrate_domain and generalize migrate_receive
In reply to [email protected]Quoted 7 lines · On Fri, 2012-02-03 at 06:50 +0000, [email protected] wrote:
# HG changeset patch
# User Shriram Rajagopalan <[email protected]>
# Date 1328251593 28800
# Node ID62c4fd2fe9bbc2c283e3998d852317a48e9f9770# Parentf853c88f0230a2e9d2e1006a9cd220c4cd27e74d
libxl: refactormigrate_domainand generalizemigrate_receive
Quoted 7 lines
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_receivegeneric (instead of resorting to stdin and stdout as the file descriptors for communication).Signed-off-by Shriram Rajagopalan <[email protected]>
Quoted 226 lines
diff -r
f853c88f0230-r62c4fd2fe9bbtools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c +84
-52@@ -2531,6 +2531,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];@@ -2616,53 +2653,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);@@ -2675,6 +2676,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));@@ -2798,7 +2827,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;@@ -2810,7 +2840,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",@@ -2822,7 +2852,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 ;@@ -2836,13 +2866,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;@@ -2861,7 +2891,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" );@@ -2869,7 +2899,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 );@@ -2887,7 +2917,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",@@ -2983,7 +3013,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 6 of 6 V3] libxl: resume instead of unpause on xl save -c
In reply to [email protected]Quoted 7 lines · On Fri, 2012-02-03 at 06:50 +0000, [email protected] wrote:
# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1328251593 28800
# Node IDc7abecc14cceb18140335ebe20faad826282cd1f# Parent62c4fd2fe9bbc2c283e3998d852317a48e9f9770
libxl: resume instead of unpause on xl save -c
Quoted 5 lines
The guest is "suspended" via
libxl_domain_suspendwhen taking a snapshot. So calllibxl_domain_resumeinstead oflibxl_domain_unpause, when taking a checkpoint of the domain (using xl save -c).Signed-off-by Shriram Rajagopalan <[email protected]>
Ideally we would confirm that the guest supported checkpointing before even attempting a "save -c" but lets assume for now that the user has confirmed by out-of-band means that this is the case.
Quoted 13 lines
diff -r
62c4fd2fe9bb-rc7abecc14ccetools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c +1
-1@@ -2524,7 +2524,7 @@ static int save_domain(const char *p, coclose (fd);if (checkpoint) -libxl_domain_unpause (ctx, domid); +libxl_domain_resume (ctx, domid,1 );else libxl_domain_destroy (ctx, domid);
Re: [PATCH 4 of 6 V3] libxl: support suspend_cancel in domain_resume
In reply to Ian CampbellQuoted 79 lines · Ian Campbell
Quoted 78 lines · On Fri, 2012-02-03 at 06:50 +0000, [email protected] wrote:
# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1328251593 28800
# Node IDf853c88f0230a2e9d2e1006a9cd220c4cd27e74d# Parent329b3c94c618addb1e802cebc7fe23b12b432398
libxl: supportsuspend_cancelindomain_resumeAdd an extra parameter to
libxl_domain_resumeindicating if the caller wishes to use theSUSPEND_CANCELstyle resume instead of the normal resume.Signed-off-by Shriram Rajagopalan <[email protected]>diff -r
329b3c94c618-rf853c88f0230tools/libxl/libxl.ctools/libxl/libxl.c +13
-8@@ -229,24 +229,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",diff -r
329b3c94c618-rf853c88f0230tools/libxl/libxl.htools/libxl/libxl.h +6
-1@@ -268,7 +268,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);diff -r
329b3c94c618-rf853c88f0230tools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c +0
-0@@ -2751,7 +2751,7 @@ static void migrate_domain(const char *dif (common_domname) {libxl_domain_rename (ctx, domid, away_domname, common_domname); }
Quoted 8 lines
tools/libxl/xl_cmdimpl.c static void migrate_domain(const char *d · line 2754
Quoted 2 lines
tools/libxl/xl_cmdimpl.c +1
-1- rc =libxl_domain_resume (ctx, domid); + rc =libxl_domain_resume (ctx, domid,1 );Previously this code would have been equivalent to passing 0 not 1. It may be ok to change this but it should be separate. However I'm a bit dubious about changing it without adding some code to detect if the guest supports it. (I know
libxl_domain_resumeis currently broken for the non-cooperative suspend case but we shouldn't paper over that)
BTW the rest of the patch looked fine. If those two 1s had been 0s I would have: Acked-by: Ian Campbell <[email protected]>
Ian.
Re: [PATCH 4 of 6 V3] libxl: support suspend_cancel in domain_resume
In reply to Ian CampbellQuoted 9 lines · Ian Campbell
Quoted 1 line · On Fri, 2012-02-03 at 06:50 +0000, [email protected] wrote:
#
Previously this code would have been equivalent to passing 0 not 1. It may be ok to change this but it should be separate.
However I'm a bit
dubious about changing it without adding some code to detect if the guest supports it.
It requires writing the suspend-cancel entry to xenstore on domain creation (if xen says that the guest supports it)
And then read this field once during initialization in checkpoint/Remus code.
I haven't properly investigated the domain create code path. Any pointers on where I should start ?
Quoted 2 lines
(I know
libxl_domain_resumeis currently broken for the non-cooperative suspend
It's broken in such a way that neither domain checkpoint or Remus work. I ll take up your comment on the previous version of the patch:
Add a new public (or internal) API libxl_domain_suspend_cancel
and make the checkpoint and Remus related code call this instead of the domain_resume.
Later, after adding the suspend-cancel xenstore entry creation patch, I can switch the code to using the above function with the cooperative flag.
Quoted 5 lines
case but we shouldn't paper over that)
Ian.
Re: [PATCH 4 of 6 V3] libxl: support suspend_cancel in domain_resume
Quoted 21 lines · Shriram Rajagopalan
Quoted 9 lines · Ian Campbell
Quoted 1 line · On Fri, 2012-02-03 at 06:50 +0000, [email protected] wrote:
#
Previously this code would have been equivalent to passing 0 not 1. It may be ok to change this but it should be separate.
However I'm a bit
dubious about changing it without adding some code to detect if the guest supports it.It requires writing the suspend-cancel entry to xenstore on domain creation (if xen says that the guest supports it)
And then read this field once during initialization in checkpoint/Remus code.
I haven't properly investigated the domain create code path. Any pointers on where I should start ?
Quoted 2 lines
(I know
libxl_domain_resumeis currently broken for the non-cooperative suspend
Quoted 6 lines
It's broken in such a way that neither domain checkpoint or Remus work. I ll take up your comment on the previous version of the patch:
Add a new public (or internal) APIlibxl_domain_suspend_canceland make the checkpoint and Remus related code call this instead of the
domain_resume.
I don't think there is any need for that unless you think that is actually a better API in its own right. Otherwise please just leave the semantics of the existing calls to libxl_domain_resume alone when you add the flag (i.e. pass 0 as the co-operative flag at all existing call sites, retaining the existing behaviour). Other than that your patch was fine.
Changing existing places to use co-operative resume without also validating that the guest supports it is wrong in the normal migration case and also masks a real bug in libxl_domain_resume which needs to be fixed (it's on my TODO list) not papered over by assuming that all guests know about cooperative resume.
If you need to make that argument conditional on Remus in subsequent patches then that is fine since Remus implies, at least to some degree, support for co-operative resume.
Ian.
Quoted 8 lines
Later, after adding the suspend-cancel xenstore entry creation patch, I can switch the code to using the above function with the cooperative flag.
Quoted 5 lines
case but we shouldn't paper over that)
Ian.
PATCH v4 1/1 libxl: support suspend_cancel in domain_resume
# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1328835221 28800
# Node ID 47366457a52076b78c5218c95b87c4ba7c9a723a # Parent 2fadbad1577ed4222dd2cf8931b79f514619eb0d
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
@@ -2802,7 +2802,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" );
@@ -2824,7 +2824,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:
Re: [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume
Quoted 7 lines · On Fri, 2012-02-10 at 01:31 +0000, [email protected] wrote:
# HG changeset patch
# User Shriram Rajagopalan <[email protected]> # Date 1328835221 28800
# Node ID47366457a52076b78c5218c95b87c4ba7c9a723a# Parent2fadbad1577ed4222dd2cf8931b79f514619eb0d
libxl: supportsuspend_cancelindomain_resume
Quoted 5 lines
Add an extra parameter to
libxl_domain_resumeindicating if the caller wishes to use theSUSPEND_CANCELstyle resume instead of the normal resume.Signed-off-by Shriram Rajagopalan <[email protected]>
Thanks
(although doesn't the libxl__domain_resume_device_model need to be in another patch to avoid bisection issues? i.e. in with the changes to the suspend/resume ordering to balance things there?)
Quoted 80 lines
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@@ -2802,7 +2802,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" );@@ -2824,7 +2824,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:
Re: [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume
In reply to [email protected][email protected] writes ("[Xen-devel] [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume"):
Quoted 1 line
libxl: support
suspend_cancelindomain_resume
I get this:
libxl.c: In function 'libxl_domain_resume':
libxl.c:315: error: implicit declaration of function 'libxl__domain_resume_device_model'
Did you compile this ? Did you test it ?
Thanks,
Ian.
Re: [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume
Quoted 4 lines · Ian Jackson
[email protected] writes ("[Xen-devel] [PATCH 4 of 6 V4] libxl: support
suspend_cancelindomain_resume"):Quoted 1 line
libxl: support
suspend_cancelindomain_resume
Quoted 9 lines
I get this:
libxl.c: In function 'libxl_domain_resume':
libxl.c:315: error: implicit declaration of function 'libxl__domain_resume_device_model'Did you compile this ? Did you test it ?
Yes I did.. Did you apply the previous patch in this series, that introduces the above (missing) function ?
As I mentioned in the introductory email, these patches also depend on Stefano's XC_SAVE_ID_TOOLSTACK patches.
01 Introduce a new save_id to save/restore toolstack specific extra 02 Read Qemu's physmap from xenstore and save it using toolstack_save. 03 Following the recent changes to upstream Qemu, the best monitor command
(removes qmp_migrate and introduces qmp_save)
Then my patches:
03 libxl: QMP stop/resume & refactor QEMU suspend/resume/save 04 libxl: support suspend_cancel in domain_resume
05 libxl: refactor migrate_domain and generalize migrate_receive 06 libxl: resume instead of unpause on xl save -c
01 libxl: Remus - suspend/postflush/commit callbacks 02 libxl: Remus - xl remus command
Currently, one of stefano's patches doesnt apply cleanly - the first one. It requires minor fix.
Barring that, all the other patches mentioned above apply cleanly.
Thanks,
Quoted 3 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume
Quoted 18 lines · Shriram Rajagopalan
Quoted 4 lines · Ian Jackson
[email protected] writes ("[Xen-devel] [PATCH 4 of 6 V4] libxl: support
suspend_cancelindomain_resume"):Quoted 1 line
libxl: support
suspend_cancelindomain_resumeQuoted 9 lines
I get this:
libxl.c: In function 'libxl_domain_resume':
libxl.c:315: error: implicit declaration of function 'libxl__domain_resume_device_model'Did you compile this ? Did you test it ?
Yes I did.. Did you apply the previous patch in this series, that introduces the above (missing) function ?
Quoted 9 lines
As I mentioned in the introductory email, these patches also depend on Stefano's
XC_SAVE_ID_TOOLSTACKpatches.01 Introduce a new
save_idto save/restore toolstack specific extra 02 Read Qemu's physmap from xenstore and save it usingtoolstack_save. 03 Following the recent changes to upstream Qemu, the best monitor command
(removesqmp_migrateand introducesqmp_save)
Stefano, you said a while ago, that the above patches were blocked on some qemu related acks.
Any updates ?
Quoted 10 lines
Then my patches:
03 libxl: QMP stop/resume & refactor QEMU suspend/resume/save 04 libxl: supportsuspend_cancelindomain_resume
05 libxl: refactormigrate_domainand generalizemigrate_receive06 libxl: resume instead of unpause on xl save -c01 libxl: Remus - suspend/postflush/commit callbacks 02 libxl: Remus - xl remus command
Quoted 10 lines
Currently, one of stefano's patches doesnt apply cleanly - the first one. It requires minor fix.
Barring that, all the other patches mentioned above apply cleanly.Thanks,
Quoted 3 lines
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume
In reply to Shriram RajagopalanQuoted 28 lines · Shriram Rajagopalan
On Mon, Feb 20, 2012 at 11:00 AM, Ian Jackson <[email protected]> wrote:
[email protected] writes ("[Xen-devel] [PATCH 4 of 6 V4] libxl: supportsuspend_cancelindomain_resume"):
> libxl: supportsuspend_cancelindomain_resumeI get this:
libxl.c: In function 'libxl_domain_resume':
libxl.c:315: error: implicit declaration of function 'libxl__domain_resume_device_model'Did you compile this ? Did you test it ?
Yes I did.. Did you apply the previous patch in this series, that introduces the above (missing) function ?
As I mentioned in the introductory email, these patches also depend on Stefano's
XC_SAVE_ID_TOOLSTACKpatches.01 Introduce a new
save_idto save/restore toolstack specific extra 02 Read Qemu's physmap from xenstore and save it usingtoolstack_save. 03 Following the recent changes to upstream Qemu, the best monitor command (removesqmp_migrateand introducesqmp_save)Then my patches:
03 libxl: QMP stop/resume & refactor QEMU suspend/resume/save 04 libxl: supportsuspend_cancelindomain_resume
05 libxl: refactormigrate_domainand generalizemigrate_receive06 libxl: resume instead of unpause on xl save -c
Quoted 6 lines
01 libxl: Remus - suspend/postflush/commit callbacks 02 libxl: Remus - xl remus command
Currently, one of stefano's patches doesnt apply cleanly - the first one. It requires minor fix. Barring that, all the other patches mentioned above apply cleanly.
I can rebase and resend if it is needed.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume
In reply to Shriram RajagopalanQuoted 18 lines · Shriram Rajagopalan
On Mon, Feb 20, 2012 at 12:02 PM, Shriram Rajagopalan <[email protected]> wrote:
On Mon, Feb 20, 2012 at 11:00 AM, Ian Jackson <[email protected]> wrote:
[email protected] writes ("[Xen-devel] [PATCH 4 of 6 V4] libxl: supportsuspend_cancelindomain_resume"):
> libxl: supportsuspend_cancelindomain_resumeI get this:
libxl.c: In function 'libxl_domain_resume':
libxl.c:315: error: implicit declaration of function 'libxl__domain_resume_device_model'Did you compile this ? Did you test it ?
Yes I did.. Did you apply the previous patch in this series, that introduces the above (missing) function ?
As I mentioned in the introductory email, these patches also depend on Stefano's
XC_SAVE_ID_TOOLSTACKpatches.
Quoted 8 lines
01 Introduce a new
save_idto save/restore toolstack specific extra 02 Read Qemu's physmap from xenstore and save it usingtoolstack_save. 03 Following the recent changes to upstream Qemu, the best monitor command (removesqmp_migrateand introducesqmp_save)Stefano, you said a while ago, that the above patches were blocked on some qemu related acks. Any updates ?
None unfortunately. I'll try to get an answer by the end of the week.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel
Re: [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume
In reply to Shriram RajagopalanShriram Rajagopalan writes ("Re: [Xen-devel] [PATCH 4 of 6 V4] libxl: support suspend_cancel in domain_resume"):
Quoted 1 line
As I mentioned in the introductory email, these patches also depend on Stefano's
XC_SAVE_ID_TOOLSTACKpatches.
Sorry, I didn't spot that.
Ian.