From: Andrew Cooper Subject: [PATCH v2 07/27] tools/libxl: Extra management APIs for the save helper Date: Thu, 9 Jul 2015 19:26:33 +0100 Message-ID: <1436466413-25867-8-git-send-email-andrew.cooper3@citrix.com> References: <1436466413-25867-1-git-send-email-andrew.cooper3@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1436466413-25867-1-git-send-email-andrew.cooper3@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Xen-devel Cc: Andrew Cooper , Ian Jackson , Ian Campbell , Wei Liu List-Id: xen-devel@lists.xenproject.org With migration v2, there are several moving parts needing to be juggled at once. This requires the error handling logic to be able to query the state of each moving part, possibly before they have been started, and be able to cancel them. Signed-off-by: Andrew Cooper CC: Ian Campbell CC: Ian Jackson CC: Wei Liu --- Since v1: * Add an _init() function which allows _inuse() to be safe to call even before the save helper has started. --- tools/libxl/libxl_internal.h | 9 +++++++++ tools/libxl/libxl_save_callout.c | 17 ++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 588cfb8..4bd6ea1 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3272,6 +3272,15 @@ _hidden void libxl__xc_domain_restore(libxl__egc *egc, _hidden void libxl__xc_domain_restore_done(libxl__egc *egc, void *dcs_void, int rc, int retval, int errnoval); +_hidden void libxl__save_helper_init(libxl__save_helper_state *shs); +_hidden void libxl__save_helper_abort(libxl__egc *egc, + libxl__save_helper_state *shs); + +static inline bool libxl__save_helper_inuse(const libxl__save_helper_state *shs) +{ + return libxl__ev_child_inuse(&shs->child); +} + /* Each time the dm needs to be saved, we must call suspend and then save */ _hidden int libxl__domain_suspend_device_model(libxl__gc *gc, libxl__domain_suspend_state *dss); diff --git a/tools/libxl/libxl_save_callout.c b/tools/libxl/libxl_save_callout.c index 1136b79..cd18cd2 100644 --- a/tools/libxl/libxl_save_callout.c +++ b/tools/libxl/libxl_save_callout.c @@ -146,6 +146,13 @@ void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc, shs->egc = 0; } +void libxl__save_helper_init(libxl__save_helper_state *shs) +{ + libxl__ao_abortable_init(&shs->abrt); + libxl__ev_fd_init(&shs->readable); + libxl__ev_child_init(&shs->child); +} + /*----- helper execution -----*/ static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs, @@ -167,9 +174,7 @@ static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs, shs->rc = 0; shs->completed = 0; shs->pipes[0] = shs->pipes[1] = 0; - libxl__ao_abortable_init(&shs->abrt); - libxl__ev_fd_init(&shs->readable); - libxl__ev_child_init(&shs->child); + libxl__save_helper_init(shs); shs->abrt.ao = shs->ao; shs->abrt.callback = helper_stop; @@ -279,6 +284,12 @@ static void helper_stop(libxl__egc *egc, libxl__ao_abortable *abrt, int rc) libxl__kill(gc, shs->child.pid, SIGTERM, "save/restore helper"); } +void libxl__save_helper_abort(libxl__egc *egc, + libxl__save_helper_state *shs) +{ + helper_stop(egc, &shs->abrt, ERROR_FAIL); +} + static void helper_stdout_readable(libxl__egc *egc, libxl__ev_fd *ev, int fd, short events, short revents) { -- 1.7.10.4