From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Jackson Subject: [PATCH 2/3] libxl: save helper: transport errno with all callback return values Date: Mon, 22 Sep 2014 14:58:18 +0100 Message-ID: <1411394299-8584-2-git-send-email-ian.jackson@eu.citrix.com> References: <21536.10963.947982.42738@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21536.10963.947982.42738@mariner.uk.xensource.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: olaf@aepfle.de, Ian.Campbell@citrix.com, wency@cn.fujitsu.com, Ian Jackson , yunhong.jiang@intel.com, eddie.dong@intel.com, yanghy@cn.fujitsu.com, laijs@cn.fujitsu.com List-Id: xen-devel@lists.xenproject.org Whenever we plumb the return value from a callback, plumb through errno as well. libxl__xc_domain_saverestore_async_callback_done now assumes that its caller has set errno sensibly, although this is probably not true :-/. Signed-off-by: Ian Jackson --- tools/libxl/libxl_save_callout.c | 11 +++++++---- tools/libxl/libxl_save_msgs_gen.pl | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/libxl/libxl_save_callout.c b/tools/libxl/libxl_save_callout.c index 1c9f806..88b406b 100644 --- a/tools/libxl/libxl_save_callout.c +++ b/tools/libxl/libxl_save_callout.c @@ -138,10 +138,11 @@ void libxl__xc_domain_save(libxl__egc *egc, libxl__domain_suspend_state *dss) void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc, - libxl__save_helper_state *shs, int return_value) + libxl__save_helper_state *shs, + int return_value) { shs->egc = egc; - libxl__srm_callout_sendreply(return_value, shs); + libxl__srm_callout_sendreply(return_value, errno, shs); shs->egc = 0; } @@ -356,15 +357,16 @@ libxl__srm_callout_get_callbacks_restore(void *user) return &shs->callbacks.restore.a; } -void libxl__srm_callout_sendreply(int r, void *user) +void libxl__srm_callout_sendreply(int r, int savederrno, void *user) { libxl__save_helper_state *shs = user; libxl__egc *egc = shs->egc; STATE_AO_GC(shs->ao); int errnoval; + int data[2] = { r, savederrno }; errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]), - &r, sizeof(r), shs->stdin_what, + data, sizeof(data), shs->stdin_what, "callback return value"); if (errnoval) helper_failed(egc, shs, ERROR_FAIL); @@ -397,5 +399,6 @@ int libxl__srm_callout_callback_complete(int retval, int errnoval, shs->retval = retval; shs->errnoval = errnoval; libxl__ev_fd_deregister(gc, &shs->readable); + errno = 0; return 0; } diff --git a/tools/libxl/libxl_save_msgs_gen.pl b/tools/libxl/libxl_save_msgs_gen.pl index ddd13e5..3d89de9 100755 --- a/tools/libxl/libxl_save_msgs_gen.pl +++ b/tools/libxl/libxl_save_msgs_gen.pl @@ -66,6 +66,7 @@ foreach my $ah (qw(callout helper)) { #include #include #include +#include END_BOTH #include "libxl_internal.h" @@ -103,7 +104,7 @@ our $getcallbacks = "${libxl}_callout_get_callbacks"; our $enumcallbacks = "${libxl}_callout_enumcallbacks"; sub cbtype ($) { "${libxl}_".$_[0]."_autogen_callbacks"; }; -f_decl($sendreply, 'callout', 'void', "(int r, void *user)"); +f_decl($sendreply, 'callout', 'void', "(int r, int savederrno, void *user)"); our $helper = "helper"; our $encode = "${helper}_stub"; @@ -328,7 +329,7 @@ END_ALWAYS $f_more_sr->(" $c_make_callback;\n"); } else { $f_more_sr->(" r = $c_make_callback;\n". - " $sendreply(r, user);\n"); + " $sendreply(r, errno, user);\n"); } if ($flags =~ m/x/) { my $c_v = "(1u<<$msgnum)"; @@ -354,9 +355,12 @@ END_ALWAYS f_more("${encode}_$name", (<