[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [RFC PATCH COLO v5 13/29] Update libxl_save_msgs_gen.pl to support return data from xl to xc
From: Wen Congyang <wency@xxxxxxxxxxxxxx> Currently, all callbacks return an integer value or void. We cannot return some data to xc via callback. Update libxl_save_msgs_gen.pl to support this case. Signed-off-by: Wen Congyang <wency@xxxxxxxxxxxxxx> --- tools/libxl/libxl_internal.h | 3 ++ tools/libxl/libxl_save_callout.c | 31 ++++++++++++++++++ tools/libxl/libxl_save_helper.c | 17 ++++++++++ tools/libxl/libxl_save_msgs_gen.pl | 65 ++++++++++++++++++++++++++++++++++---- 4 files changed, 109 insertions(+), 7 deletions(-) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index e12c7b5..7bfabd8 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3180,6 +3180,9 @@ _hidden void libxl__xc_domain_save_done(libxl__egc*, void *dss_void, * When they are ready to indicate completion, they call this. */ void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc, libxl__save_helper_state *shs, int return_value); +void libxl__xc_domain_saverestore_async_callback_done_with_data(libxl__egc *egc, + libxl__save_helper_state *shs, + const void *data, uint64_t size); _hidden void libxl__domain_suspend_common_switch_qemu_logdirty diff --git a/tools/libxl/libxl_save_callout.c b/tools/libxl/libxl_save_callout.c index 40b25e4..477e633 100644 --- a/tools/libxl/libxl_save_callout.c +++ b/tools/libxl/libxl_save_callout.c @@ -145,6 +145,15 @@ void libxl__xc_domain_saverestore_async_callback_done(libxl__egc *egc, shs->egc = 0; } +void libxl__xc_domain_saverestore_async_callback_done_with_data(libxl__egc *egc, + libxl__save_helper_state *shs, + const void *data, uint64_t size) +{ + shs->egc = egc; + libxl__srm_callout_sendreply_data(data, size, shs); + shs->egc = 0; +} + /*----- helper execution -----*/ static void run_helper(libxl__egc *egc, libxl__save_helper_state *shs, @@ -370,6 +379,28 @@ void libxl__srm_callout_sendreply(int r, void *user) helper_failed(egc, shs, ERROR_FAIL); } +void libxl__srm_callout_sendreply_data(const void *data, uint64_t size, void *user) +{ + libxl__save_helper_state *shs = user; + libxl__egc *egc = shs->egc; + STATE_AO_GC(shs->ao); + int errnoval; + + errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]), + &size, sizeof(size), shs->stdin_what, + "callback return data length"); + if (errnoval) + goto out; + + errnoval = libxl_write_exactly(CTX, libxl__carefd_fd(shs->pipes[0]), + data, size, shs->stdin_what, + "callback return data"); + +out: + if (errnoval) + helper_failed(egc, shs, ERROR_FAIL); +} + void libxl__srm_callout_callback_log(uint32_t level, uint32_t errnoval, const char *context, const char *formatted, void *user) { diff --git a/tools/libxl/libxl_save_helper.c b/tools/libxl/libxl_save_helper.c index 74826a1..44c5807 100644 --- a/tools/libxl/libxl_save_helper.c +++ b/tools/libxl/libxl_save_helper.c @@ -155,6 +155,23 @@ int helper_getreply(void *user) return v; } +uint8_t *helper_getreply_data(void *user) +{ + uint64_t size; + int r = read_exactly(0, &size, sizeof(size)); + uint8_t *data; + + if (r <= 0) + exit(-2); + + data = helper_allocbuf(size, user); + r = read_exactly(0, data, size); + if (r <= 0) + exit(-2); + + return data; +} + /*----- other callbacks -----*/ static int toolstack_save_fd; diff --git a/tools/libxl/libxl_save_msgs_gen.pl b/tools/libxl/libxl_save_msgs_gen.pl index 6b4b65e..41ee000 100755 --- a/tools/libxl/libxl_save_msgs_gen.pl +++ b/tools/libxl/libxl_save_msgs_gen.pl @@ -15,6 +15,7 @@ our @msgs = ( # and its null-ness needs to be passed through to the helper's xc # W - needs a return value; callback is synchronous # A - needs a return value; callback is asynchronous + # B - return value is an pointer [ 1, 'sr', "log", [qw(uint32_t level uint32_t errnoval STRING context @@ -99,23 +100,28 @@ our $libxl = "libxl__srm"; our $callback = "${libxl}_callout_callback"; our $receiveds = "${libxl}_callout_received"; our $sendreply = "${libxl}_callout_sendreply"; +our $sendreply_data = "${libxl}_callout_sendreply_data"; 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_data, 'callout', 'void', + "(const void *data, uint64_t size, void *user)"); our $helper = "helper"; our $encode = "${helper}_stub"; our $allocbuf = "${helper}_allocbuf"; our $transmit = "${helper}_transmitmsg"; our $getreply = "${helper}_getreply"; +our $getreply_data = "${helper}_getreply_data"; our $setcallbacks = "${helper}_setcallbacks"; f_decl($allocbuf, 'helper', 'unsigned char *', '(int len, void *user)'); f_decl($transmit, 'helper', 'void', '(unsigned char *msg_freed, int len, void *user)'); f_decl($getreply, 'helper', 'int', '(void *user)'); +f_decl($getreply_data, 'helper', 'uint8_t *', '(void *user)'); sub typeid ($) { my ($t) = @_; $t =~ s/\W/_/; return $t; }; @@ -259,12 +265,36 @@ foreach my $msginfo (@msgs) { $f_more_sr->(" case $msgnum: { /* $name */\n"); if ($flags =~ m/W/) { - $f_more_sr->(" int r;\n"); + if ($flags =~ m/B/) { + $f_more_sr->(" uint8_t *data;\n". + " uint64_t size;\n"); + } else { + $f_more_sr->(" int r;\n"); + } } - my $c_rtype_helper = $flags =~ m/[WA]/ ? 'int' : 'void'; - my $c_rtype_callout = $flags =~ m/W/ ? 'int' : 'void'; + my $c_rtype_helper; + if ($flags =~ m/[WA]/) { + if ($flags =~ m/B/) { + $c_rtype_helper = 'uint8_t *' + } else { + $c_rtype_helper = 'int' + } + } else { + $c_rtype_helper = 'void'; + } + my $c_rtype_callout; + if ($flags =~ m/W/) { + if ($flags =~ m/B/) { + $c_rtype_callout = 'uint8_t *'; + } else { + $c_rtype_callout = 'int'; + } + } else { + $c_rtype_callout = 'void'; + } my $c_decl = '('; + my $c_helper_decl = ''; my $c_callback_args = ''; f_more("${encode}_$name", @@ -305,7 +335,15 @@ END_ALWAYS f_more("${encode}_$name", " ${typeid}_put(buf, &len, $c_args);\n"); } $f_more_sr->($c_recv); + $c_helper_decl = $c_decl; + if ($flags =~ m/W/ and $flags =~ m/B/) { + $c_decl .= "uint64_t *size, " + } $c_decl .= "void *user)"; + $c_helper_decl .= "void *user)"; + if ($flags =~ m/W/ and $flags =~ m/B/) { + $c_callback_args .= "&size, " + } $c_callback_args .= "user"; $f_more_sr->(" if (msg != endmsg) return 0;\n"); @@ -326,10 +364,12 @@ END_ALWAYS my $c_make_callback = "$c_callback($c_callback_args)"; if ($flags !~ m/W/) { $f_more_sr->(" $c_make_callback;\n"); + } elsif ($flags =~ m/B/) { + $f_more_sr->(" data = $c_make_callback;\n". + " $sendreply_data(data, size, user);\n"); } else { $f_more_sr->(" r = $c_make_callback;\n". " $sendreply(r, user);\n"); - f_decl($sendreply, 'callout', 'void', '(int r, void *user)'); } if ($flags =~ m/x/) { my $c_v = "(1u<<$msgnum)"; @@ -340,7 +380,7 @@ END_ALWAYS } $f_more_sr->(" return 1;\n }\n\n"); f_decl("${callback}_$name", 'callout', $c_rtype_callout, $c_decl); - f_decl("${encode}_$name", 'helper', $c_rtype_helper, $c_decl); + f_decl("${encode}_$name", 'helper', $c_rtype_helper, $c_helper_decl); f_more("${encode}_$name", " if (buf) break; buf = ${helper}_allocbuf(len, user); @@ -352,12 +392,23 @@ END_ALWAYS ${transmit}(buf, len, user); "); if ($flags =~ m/[WA]/) { - f_more("${encode}_$name", - (<<END_ALWAYS.($debug ? <<END_DEBUG : '').<<END_ALWAYS)); + if ($flags =~ m/B/) { + f_more("${encode}_$name", + (<<END_ALWAYS.($debug ? <<END_DEBUG : ''))); + uint8_t *r = ${helper}_getreply_data(user); +END_ALWAYS + fprintf(stderr,"libxl-save-helper: $name got reply data\\n"); +END_DEBUG + } else { + f_more("${encode}_$name", + (<<END_ALWAYS.($debug ? <<END_DEBUG : ''))); int r = ${helper}_getreply(user); END_ALWAYS fprintf(stderr,"libxl-save-helper: $name got reply %d\\n",r); END_DEBUG + } + + f_more("${encode}_$name", (<<END_ALWAYS)); return r; END_ALWAYS } -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |