From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 27/29] libxl: cancellation: Cancel libxc save/restore Date: Tue, 10 Feb 2015 20:10:14 +0000 Message-ID: <1423599016-32639-28-git-send-email-ian.jackson@eu.citrix.com> References: <1423599016-32639-1-git-send-email-ian.jackson@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1423599016-32639-1-git-send-email-ian.jackson@eu.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@lists.xensource.com Cc: Ian Jackson , Euan Harris List-Id: xen-devel@lists.xenproject.org Register the the save/restore helper interface with the cancellation machinery. When we are informed that save/restore should be cancelled, we make a note of the that in our rc variable, and send the helper a SIGTERM. It will die in due course. Signed-off-by: Ian Jackson --- v2: New in this version of the series. --- tools/libxl/libxl_internal.h | 1 + tools/libxl/libxl_save_callout.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index cfc0706..eb8e5f2 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -2639,6 +2639,7 @@ typedef struct libxl__save_helper_state { int rc; int completed; /* retval/errnoval valid iff completed */ int retval, errnoval; /* from xc_domain_save / xc_domain_restore */ + libxl__ao_cancellable cancel; libxl__carefd *pipes[2]; /* 0 = helper's stdin, 1 = helper's stdout */ libxl__ev_fd readable; libxl__ev_child child; diff --git a/tools/libxl/libxl_save_callout.c b/tools/libxl/libxl_save_callout.c index 1d584f1..d9fa0d2 100644 --- a/tools/libxl/libxl_save_callout.c +++ b/tools/libxl/libxl_save_callout.c @@ -32,6 +32,7 @@ static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs, const unsigned long *argnums, int num_argnums); static void helper_failed(libxl__egc*, libxl__save_helper_state *shs, int rc); +static void helper_cancel(libxl__egc *egc, libxl__ao_cancellable*, int rc); static void helper_stdout_readable(libxl__egc *egc, libxl__ev_fd *ev, int fd, short events, short revents); static void helper_exited(libxl__egc *egc, libxl__ev_child *ch, @@ -166,9 +167,15 @@ 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_cancellable_init(&shs->cancel); libxl__ev_fd_init(&shs->readable); libxl__ev_child_init(&shs->child); + shs->cancel.ao = shs->ao; + shs->cancel.callback = helper_cancel; + rc = libxl__ao_cancellable_register(&shs->cancel); + if (rc) goto out; + shs->stdin_what = GCSPRINTF("domain %"PRIu32" save/restore helper" " stdin pipe", domid); shs->stdout_what = GCSPRINTF("domain %"PRIu32" save/restore helper" @@ -262,6 +269,23 @@ static void helper_failed(libxl__egc *egc, libxl__save_helper_state *shs, sendsig(gc, shs, SIGKILL); } +static void helper_cancel(libxl__egc *egc, libxl__ao_cancellable *cancel, + int rc) +{ + libxl__save_helper_state *shs = CONTAINER_OF(cancel, *shs, cancel); + STATE_AO_GC(shs->ao); + + if (!libxl__ev_child_inuse(&shs->child)) { + helper_failed(egc, shs, rc); + return; + } + + if (!shs->rc) + shs->rc = rc; + + sendsig(gc, shs, SIGTERM); +} + static void helper_stdout_readable(libxl__egc *egc, libxl__ev_fd *ev, int fd, short events, short revents) { @@ -332,6 +356,7 @@ static void helper_done(libxl__egc *egc, libxl__save_helper_state *shs) { STATE_AO_GC(shs->ao); + libxl__ao_cancellable_deregister(&shs->cancel); libxl__ev_fd_deregister(gc, &shs->readable); libxl__carefd_close(shs->pipes[0]); shs->pipes[0] = 0; libxl__carefd_close(shs->pipes[1]); shs->pipes[1] = 0; -- 1.7.10.4