libxl: subprocess handling
v7 cover libxl: subprocess handling
This has now been tested and appears to work for me.
Changes since v6 are bugfixes, comments from the list addressed, and three new patches (marked with "*" below).
01/24 libxl: handle POLLERR, POLLHUP, POLLNVAL properly 02/24 libxl: support multiple libxl__ev_fds for the same fd 03/24 libxl: event API: new facilities for waiting for subprocesses
* 04/24 autoconf: trim the configure script; use autoheader 05/24 autoconf: New test for openpty et al.
06/24 libxl: provide libxl__remove_file et al.
07/24 libxl: Introduce libxl__sendmsg_fds and libxl__recvmsg_fds 08/24 libxl: Clean up setdefault in do_domain_create 09/24 libxl: provide libxl__datacopier_*
10/24 libxl: provide libxl__openpty_*
11/24 libxl: ao: Convert libxl_run_bootloader
12/24 libxl: make libxl_create_logfile const-correct 13/24 libxl: log bootloader output
14/24 libxl: Allow AO_GC and EGC_GC even if not used 15/24 libxl: remove ctx->waitpid_instead
16/24 libxl: change some structures to unit arrays
17/24 libxl: ao: convert libxl__spawn_*
18/24 libxl: make libxl_create run bootloader via callback 19/24 libxl: provide progress reporting for long-running operations 20/24 libxl: remove malloc failure handling from NEW_EVENT 21/24 libxl: convert console callback to libxl_asyncprogress_how
* 22/24 libxl: clarify definition of "slow" operation
* 23/24 libxl: child processes cleanups
* 24/24 libxl: aborting bootloader invocation when domain dies
PATCH v7 1/24 libxl: handle POLLERR, POLLHUP, POLLNVAL properly
Pass POLLERR and POLLHUP to fd callbacks, as is necessary. Crash on POLLNVAL since that means our fds are messed up.
Document the behaviour (including the fact that poll sometimes sets POLLHUP or POLLERR even if only POLLIN was requested.
Fix the one current fd callback to do something with POLLERR|POLLHUP.
--- tools/libxl/libxl_event.c | 7 ++++++- tools/libxl/libxl_internal.h | 5 +++++ 2 files changed, 11 insertions(+), 1 deletions(-)
tools/libxl/libxl_event.c +6 -1
@@ -335,6 +335,9 @@ static void watchfd_callback(libxl__egc *egc, libxl__ev_fd *ev, {EGC_GC ; +if (revents & (POLLERR |POLLHUP )) +LIBXL__EVENT_DISASTER (egc,"unexpected poll event on watch fd" ,0 ,0 ); +for (;;) {char **event =xs_check_watch (CTX ->xsh);if (!event) {
@@ -739,7 +742,9 @@ static int afterpoll_check_fd(libxl__poller *poller,/* again, stale slot entry */ return 0 ; -int revents = fds[slot].revents & events; +assert (!(fds[slot].revents &POLLNVAL )); + +int revents = fds[slot].revents & (events |POLLERR |POLLHUP );/* we mask in case requested events have changed */ return revents;
tools/libxl/libxl_internal.h +5 -0
@@ -127,6 +127,11 @@ void libxl__alloc_failed(libxl_ctx *, const char *func,typedef struct libxl__ev_fd libxl__ev_fd ;typedef void libxl__ev_fd_callback (libxl__egc *egc,libxl__ev_fd *ev,int fd,short events,short revents); +/* Note that revents may contain POLLERR or POLLHUP regardless of +* events; otherwise revents contains only bits in events. Contrary +* to the documentation for poll(2), POLLERR and POLLHUP can occur +* even if only POLLIN was set in events. (POLLNVAL is a fatal +* error and will cause libxl event machinery to fail an assertion.) */ struct libxl__ev_fd {/* caller should include this in their own struct */ /* read-only for caller, who may read only when registered: */
Signature · 1 line
1.7.2.5
PATCH v7 2/24 libxl: support multiple libxl__ev_fds for the same fd
In reply to Ian JacksonWe need a slightly more sophisticated data structure to allow this, where we record the slot not just for each fd but also for each (fd,eventbit) where eventbit is POLLIN, POLLPRI, POLLOUT.
Document the new relaxed restriction.
Changes since v6:
* Fix typo
--- tools/libxl/libxl_event.c | 62 +++++++++++++++++++++++------------------ tools/libxl/libxl_internal.h | 10 +++++-- 2 files changed, 42 insertions(+), 30 deletions(-)
tools/libxl/libxl_event.c +35 -27
@@ -635,10 +635,11 @@ static int beforepoll_internal(libxl__gc *gc, libxl__poller *poller,/* -* In order to be able to efficiently find the libxl__ev_fd -* for a struct poll during _afterpoll, we maintain a shadow -* data structure in CTX->fd_beforepolled: each slot in -* the fds array corresponds to a slot in fd_beforepolled. +* In order to be able to efficiently find the libxl__ev_fd for a +* struct poll during _afterpoll, we maintain a shadow data +* structure in CTX->fd_rindices: each fd corresponds to a slot in +* fd_rindices, and each element in the rindices is three indices +* into the fd array (for POLLIN, POLLPRI and POLLOUT). */ if (*nfds_io) {
@@ -659,14 +660,16 @@ static int beforepoll_internal(libxl__gc *gc, libxl__poller *poller, });/* make sure our array is as big as *nfds_io */ -if (poller->fd_rindex_allocd < maxfd) { -assert (maxfd <INT_MAX /sizeof (int ) /2 ); -int *newarray =realloc (poller->fd_rindex,sizeof (int ) * maxfd); -if (!newarray) { rc =ERROR_NOMEM ; goto out; } -memset (newarray + poller->fd_rindex_allocd,0 , -sizeof (int ) * (maxfd - poller->fd_rindex_allocd)); - poller->fd_rindex = newarray; - poller->fd_rindex_allocd = maxfd; +if (poller->fd_rindices_allocd < maxfd) { +assert (ARRAY_SIZE_OK (poller->fd_rindices, maxfd)); + poller->fd_rindices = +libxl__realloc (0 , poller->fd_rindices, + maxfd *sizeof (*poller->fd_rindices)); +memset (poller->fd_rindices + poller->fd_rindices_allocd, +0 , + (maxfd - poller->fd_rindices_allocd) + *sizeof (*poller->fd_rindices)); + poller->fd_rindices_allocd = maxfd; } }
@@ -677,8 +680,10 @@ static int beforepoll_internal(libxl__gc *gc, libxl__poller *poller, fds[used].fd = req_fd; fds[used].events = req_events; fds[used].revents =0 ; -assert (req_fd < poller->fd_rindex_allocd); - poller->fd_rindex[req_fd] = used; +assert (req_fd < poller->fd_rindices_allocd); +if (req_events &POLLIN ) poller->fd_rindices[req_fd][0 ] = used; +if (req_events &POLLPRI ) poller->fd_rindices[req_fd][1 ] = used; +if (req_events &POLLOUT ) poller->fd_rindices[req_fd][2 ] = used; } used++; });
@@ -706,7 +711,6 @@ static int beforepoll_internal(libxl__gc *gc, libxl__poller *poller, *timeout_upd = our_timeout; } - out:return rc; }
@@ -728,24 +732,28 @@ static int afterpoll_check_fd(libxl__poller *poller, int fd, int events)/* returns mask of events which were requested and occurred */ { -if (fd >= poller->fd_rindex_allocd) +if (fd >= poller->fd_rindices_allocd)/* added after we went into poll, have to try again */ return 0 ; -int slot = poller->fd_rindex[fd]; +int i, revents =0 ; +for (i=0 ; i<3 ; i++) { +int slot = poller->fd_rindices[fd][i]; -if (slot >= nfds) -/* stale slot entry; again, added afterwards */ -return 0 ; +if (slot >= nfds) +/* stale slot entry; again, added afterwards */ +continue ; -if (fds[slot].fd != fd) -/* again, stale slot entry */ -return 0 ; +if (fds[slot].fd != fd) +/* again, stale slot entry */ +continue ; -assert (!(fds[slot].revents &POLLNVAL )); +assert (!(fds[slot].revents &POLLNVAL )); + revents |= fds[slot].revents; + } -int revents = fds[slot].revents & (events |POLLERR |POLLHUP );/* we mask in case requested events have changed */ + revents &= (events |POLLERR |POLLHUP );return revents; }
@@ -1009,7 +1017,7 @@ int libxl__poller_init(libxl_ctx *ctx, libxl__poller *p) {int r, rc; p->fd_polls =0 ; - p->fd_rindex =0 ; + p->fd_rindices =0 ; r =pipe (p->wakeup_pipe);if (r) {
@@ -1036,7 +1044,7 @@ void libxl__poller_dispose(libxl__poller *p)if (p->wakeup_pipe[1 ] >0 )close (p->wakeup_pipe[1 ]);if (p->wakeup_pipe[0 ] >0 )close (p->wakeup_pipe[0 ]);free (p->fd_polls); -free (p->fd_rindex); +free (p->fd_rindices); }libxl__poller *libxl__poller_get (libxl_ctx *ctx)
tools/libxl/libxl_internal.h +7 -3
@@ -131,7 +131,11 @@ typedef void libxl__ev_fd_callback(libxl__egc *egc, libxl__ev_fd *ev,* events; otherwise revents contains only bits in events. Contrary * to the documentation for poll(2), POLLERR and POLLHUP can occur * even if only POLLIN was set in events. (POLLNVAL is a fatal -* error and will cause libxl event machinery to fail an assertion.) */ +* error and will cause libxl event machinery to fail an assertion.) +* +* It is not permitted to listen for the same or overlapping events +* on the same fd using multiple different libxl__ev_fd's. +*/ struct libxl__ev_fd {/* caller should include this in their own struct */ /* read-only for caller, who may read only when registered: */
@@ -257,8 +261,8 @@ struct libxl__poller {struct pollfd *fd_polls;int fd_polls_allocd; -int fd_rindex_allocd; -int *fd_rindex;/* see libxl_osevent_beforepoll */ +int fd_rindices_allocd; +int (*fd_rindices)[3 ];/* see libxl_osevent_beforepoll */ int wakeup_pipe[2 ];/* 0 means no fd allocated */ };
Signature · 1 line
1.7.2.5
PATCH v7 3/24 libxl: event API: new facilities for waiting for subprocesses
In reply to Ian JacksonThe current arrangements in libxl for spawning subprocesses have two key problems: (i) they make unwarranted (and largely undocumented) assumptions about the caller's use of subprocesses, (ii) they aren't integrated into the event system and can't be made asynchronous etc.
So replace them with a new set of facilities.
Primarily, from the point of view of code inside libxl, this is libxl__ev_child_fork which is both (a) a version of fork() and (b) an event source which generates a callback when the child dies.
Quoted 1 line
From the point of view of the application, we fully document our use
of SIGCHLD. The application can tell us whether it wants to own SIGCHLD or not; if it does, it has to tell us about deaths of our children.
Currently there are no callers in libxl which use these facilities. All code in libxl which forks needs to be converted and libxl_fork needse to be be abolished.
--- tools/libxl/libxl.c | 17 +++- tools/libxl/libxl.h | 1 + tools/libxl/libxl_event.c | 53 +++++++-- tools/libxl/libxl_event.h | 147 +++++++++++++++++++++++- tools/libxl/libxl_fork.c | 255 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 62 ++++++++++- 6 files changed, 515 insertions(+), 20 deletions(-)
tools/libxl/libxl.c +16 -1
@@ -39,7 +39,7 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,memset (ctx,0 ,sizeof (libxl_ctx)); ctx->lg = lg; -/* First initialise pointers (cannot fail) */ +/* First initialise pointers etc. (cannot fail) */ LIBXL_TAILQ_INIT (&ctx->occurred);
@@ -58,6 +58,11 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,LIBXL_TAILQ_INIT (&ctx->death_list);libxl__ev_xswatch_init (&ctx->death_watch); + ctx->childproc_hooks = &libxl__childproc_default_hooks; + ctx->childproc_user =0 ; + + ctx->sigchld_selfpipe[0 ] =-1 ; +/* The mutex is special because we can't idempotently destroy it */ if (libxl__init_recursive_mutex (ctx, &ctx->lock) <0 ) {
@@ -160,6 +165,16 @@ int libxl_ctx_free(libxl_ctx *ctx)discard_events (&ctx->occurred); +/* If we have outstanding children, then the application inherits +* them; we wish the application good luck with understanding +* this if and when it reaps them. */ +libxl__sigchld_removehandler (ctx); + +if (ctx->sigchld_selfpipe[0 ] >=0 ) { +close (ctx->sigchld_selfpipe[0 ]); +close (ctx->sigchld_selfpipe[1 ]); + } +pthread_mutex_destroy (&ctx->lock);GC_FREE ;
tools/libxl/libxl.h +1 -0
@@ -380,6 +380,7 @@ enum {ERROR_NOT_READY =-11 ,ERROR_OSEVENT_REG_FAIL =-12 ,ERROR_BUFFERFULL =-13 , + ERROR_UNKNOWN_CHILD = -14, };
tools/libxl/libxl_event.c +42 -11
85 lines not on this page · raw message
tools/libxl/libxl_event.h +142 -5
159 lines not on this page · raw message
tools/libxl/libxl_fork.c +255 -0
279 lines not on this page · raw message
tools/libxl/libxl_internal.h +59 -3
87 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v7 4/24 autoconf: trim the configure script; use autoheader
In reply to Ian JacksonRemove a lot of unnecessary tests. Specifically, we no longer test for standard POSIX facilities which we expect to be provided everywhere and which we don't in any case have any alternative for.
Switch to generating config.h.in with autoheader.
--- autogen.sh | 1 + tools/config.h.in | 73 +- tools/configure | 8604 +++++++++++++++++----------------------------------- tools/configure.ac | 61 +- 4 files changed, 2872 insertions(+), 5867 deletions(-)
autogen.sh +1 -0
@@ -1,3 +1,4 @@ #!/bin/sh -e cd tools autoconf +autoheader
tools/config.h.in +59 -14
78 lines not on this page · raw message
tools/configure +2866 -5850
2,918 lines not on this page · raw message
tools/configure.ac +2 -59
61 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 7 lines
1.7.2.5 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Part of the diff is not shown here. View the raw message.
Re: [PATCH 04/24] autoconf: trim the configure script; use autoheader
Quoted 3 lines · Ian Jackson
Remove a lot of unnecessary tests. Specifically, we no longer test for standard POSIX facilities which we expect to be provided everywhere and which we don't in any case have any alternative for.
A good rule of thumb might be that if it isn't provided by "apt-get install build-essential" (or the common set of stuff from the equivalent meta-packages across common distros) then configure should check for it in the interest of providing a useful upfront error message?
tools/configure.ac AC_SUBST(libext2fs) · line 135
Quoted 7 lines
Switch to generating config.h.in with autoheader.
tools/configure.ac +0
-1@@ -132,7 +127,7 @@ AC_SUBST(libext2fs) AC_CHECK_LIB([gcrypt], [gcry_md_hash_buffer], [libgcrypt="y"], [libgcrypt="n"]) AC_SUBST(libgcrypt) AX_CHECK_PTHREAD -AC_CHECK_LIB([rt], [clock_gettime])
-lrt is always available? -l<one-or-two-letters> libraries seem to be the ones which tend to differ across platforms, despite being standardised...
Review AC_SUBST(libext2fs) · line 130
Quoted 1 line
(quoted diff) +1
-0+AX_CHECK_PTYFUNCS
You don't actually add this until the next patch.
Ian.
Re: [PATCH 04/24] autoconf: trim the configure script; use autoheader
Ian Campbell writes ("Re: [Xen-devel] [PATCH 04/24] autoconf: trim the configure script; use autoheader"):
Quoted 9 lines · Ian Jackson
Quoted 3 lines
Remove a lot of unnecessary tests. Specifically, we no longer test for standard POSIX facilities which we expect to be provided everywhere and which we don't in any case have any alternative for.
A good rule of thumb might be that if it isn't provided by "apt-get install build-essential" (or the common set of stuff from the equivalent meta-packages across common distros) then configure should check for it in the interest of providing a useful upfront error message?
Yes, I think so.
Quoted 11 lines
tools/configure.ac AC_SUBST(libext2fs) · line 135
Quoted 7 lines
Switch to generating config.h.in with autoheader.
tools/configure.ac +0
-1@@ -132,7 +127,7 @@ AC_SUBST(libext2fs) AC_CHECK_LIB([gcrypt], [gcry_md_hash_buffer], [libgcrypt="y"], [libgcrypt="n"]) AC_SUBST(libgcrypt) AX_CHECK_PTHREAD -AC_CHECK_LIB([rt], [clock_gettime])-lrt is always available? -l<one-or-two-letters> libraries seem to be the ones which tend to differ across platforms, despite being standardised...
The current configure script throws away the result of this test, so it is definitely useless. The effect in configure is to perhaps add -lrt to LIBS but we do not export configure's LIBS to every tools build.
Quoted 3 lines
Review AC_SUBST(libext2fs) · line 130
Quoted 1 line
(quoted diff) +1
-0+AX_CHECK_PTYFUNCSYou don't actually add this until the next patch.
Oops.
Ian.
Re: [PATCH 04/24] autoconf: trim the configure script; use autoheader
Quoted 25 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH 04/24] autoconf: trim the configure script; use autoheader"):
Quoted 9 lines · Ian Jackson
Quoted 3 lines
Remove a lot of unnecessary tests. Specifically, we no longer test for standard POSIX facilities which we expect to be provided everywhere and which we don't in any case have any alternative for.
A good rule of thumb might be that if it isn't provided by "apt-get install build-essential" (or the common set of stuff from the equivalent meta-packages across common distros) then configure should check for it in the interest of providing a useful upfront error message?
Yes, I think so.
Quoted 11 lines
tools/configure.ac AC_SUBST(libext2fs) · line 135
Quoted 7 lines
Switch to generating config.h.in with autoheader.
tools/configure.ac +0
-1@@ -132,7 +127,7 @@ AC_SUBST(libext2fs) AC_CHECK_LIB([gcrypt], [gcry_md_hash_buffer], [libgcrypt="y"], [libgcrypt="n"]) AC_SUBST(libgcrypt) AX_CHECK_PTHREAD -AC_CHECK_LIB([rt], [clock_gettime])-lrt is always available? -l<one-or-two-letters> libraries seem to be the ones which tend to differ across platforms, despite being standardised...
Quoted 4 lines
The current configure script throws away the result of this test, so it is definitely useless. The effect in configure is to perhaps add -lrt to LIBS but we do not export configure's LIBS to every tools build.
It aborts if -lrt isn't available though, doesn't it?
Quoted 7 lines
Quoted 3 lines
Review AC_SUBST(libext2fs) · line 130
Quoted 1 line
(quoted diff) +1
-0+AX_CHECK_PTYFUNCSYou don't actually add this until the next patch.
Oops.
Ian.
Re: [PATCH 04/24] autoconf: trim the configure script; use autoheader
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH 04/24] autoconf: trim the configure script; use autoheader"):
Quoted 9 lines · Ian Jackson
Quoted 3 lines
Remove a lot of unnecessary tests. Specifically, we no longer test for standard POSIX facilities which we expect to be provided everywhere and which we don't in any case have any alternative for.
A good rule of thumb might be that if it isn't provided by "apt-get install build-essential" (or the common set of stuff from the equivalent meta-packages across common distros) then configure should check for it in the interest of providing a useful upfront error message?
Yes, I think so.
Quoted 11 lines
Quoted 7 lines
Switch to generating config.h.in with autoheader.
tools/configure.ac +0
-0@@ -132,7 +127,7 @@ AC_SUBST(libext2fs) AC_CHECK_LIB([gcrypt], [gcry_md_hash_buffer], [libgcrypt="y"], [libgcrypt="n"]) AC_SUBST(libgcrypt)
AX_CHECK_PTHREAD
-AC_CHECK_LIB([rt], [clock_gettime])-lrt is always available? -l<one-or-two-letters> libraries seem to be the ones which tend to differ across platforms, despite being standardised...
Quoted 6 lines
Quoted 4 lines
The current configure script throws away the result of this test, so it is definitely useless. The effect in configure is to perhaps add -lrt to LIBS but we do not export configure's LIBS to every tools build.
It aborts if -lrt isn't available though, doesn't it?
This is useless as-is, it adds -lrt to LIBS (which we don't use), and defines HAVE_LIBRT (but doesn't abort if not found).
Quoted 17 lines
From a quick grep I've realized that
tools/consoleuses "-lrt", so maybe we should enforce this and abort if not found.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
+AX_CHECK_PTYFUNCS
You don't actually add this until the next patch.
Oops.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v7 5/24 autoconf: New test for openpty et al.
In reply to Ian JacksonWe may need to #include <libutil.h>, and/or link with -lutil, to use openpty, login_tty, and the like. Provide INCLUDE_LIBUTIL_H (preprocessor constant, not always defined) and PTYFUNCS_LIBS (makefile variable).
We link libxl against PTYFUNCS_LIBS (which comes from autoconf) rather than UTIL_LIBS, and #include <libutil.h> where appropriate.
Changes since v6:
* Put failure macro call in correct place so it might actually happen.
* Try both with -lutil and without.
* Patch now contains update for config.h.in.
--- config/Tools.mk.in | 2 + tools/config.h.in | 3 ++ tools/configure | 62 +++++++++++++++++++++++++++++++++++++++- tools/configure.ac | 1 + tools/libxl/Makefile | 2 +- tools/libxl/libxl_bootloader.c | 4 ++ tools/m4/ptyfuncs.m4 | 28 ++++++++++++++++++ 7 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 tools/m4/ptyfuncs.m4
config/Tools.mk.in +2 -0
@@ -30,6 +30,8 @@ PTHREAD_CFLAGS := @PTHREAD_CFLAGS@ PTHREAD_LDFLAGS := @PTHREAD_LDFLAGS@ PTHREAD_LIBS := @PTHREAD_LIBS@ +PTYFUNCS_LIBS := @PTYFUNCS_LIBS@ + # Download GIT repositories via HTTP or GIT's own protocol? # GIT's protocol is faster and more robust, when it works at all (firewalls # may block it). We make it the default, but if your GIT repository downloads
tools/config.h.in +3 -0
@@ -42,6 +42,9 @@ /* Define curses header to use */ #undef INCLUDE_CURSES_H +/* libutil header file name */ +#undef INCLUDE_LIBUTIL_H + /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT
tools/configure +61 -1
80 lines not on this page · raw message
tools/configure.ac +1 -0
@@ -32,6 +32,7 @@ m4_include([m4/uuid.m4]) m4_include([m4/pkg.m4]) m4_include([m4/curses.m4]) m4_include([m4/pthread.m4]) +m4_include([m4/ptyfuncs.m4]) # Enable/disable options AX_ARG_DEFAULT_DISABLE([githttp], [Download GIT repositories via HTTP])
tools/libxl/Makefile +1 -1
@@ -20,7 +20,7 @@ LIBUUID_LIBS += -luuid endif LIBXL_LIBS = -LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(UTIL_LIBS) $(LIBUUID_LIBS) +LIBXL_LIBS = $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenstore) $(LDLIBS_libblktapctl) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) CFLAGS += $(PTHREAD_CFLAGS) LDFLAGS += $(PTHREAD_LDFLAGS)
tools/libxl/libxl_bootloader.c +4 -0
@@ -16,6 +16,10 @@#include <termios.h> +#ifdef INCLUDE_LIBUTIL_H +#include INCLUDE_LIBUTIL_H +#endif +#include "libxl_internal.h" #define XENCONSOLED_BUF_SIZE 16
tools/m4/ptyfuncs.m4 new file +28 -0
@@ -0,0 +1,28 @@ +AC_DEFUN([AX_CHECK_PTYFUNCS], [ + AC_CHECK_HEADER([libutil.h],[ + AC_DEFINE([INCLUDE_LIBUTIL_H],[<libutil.h>],[libutil header file name]) + ]) + AC_CACHE_CHECK([for openpty et al], [ax_cv_ptyfuncs_libs], [ + for ax_cv_ptyfuncs_libs in -lutil "" NOT_FOUND; do + if test "x$ax_cv_ptyfuncs_libs" = "xNOT_FOUND"; then + AC_MSG_FAILURE([Unable to find library for openpty and login_tty]) + fi + AX_SAVEVAR_SAVE(LIBS) + LIBS="$LIBS $ax_cv_ptyfuncs_libs" + AC_LINK_IFELSE([ +#ifdef INCLUDE_LIBUTIL_H +#include INCLUDE_LIBUTIL_H +#endif +int main(void) { + openpty(0,0,0,0,0); + login_tty(0); +} +],[ + break + ],[]) + AX_SAVEVAR_RESTORE(LIBS) + done + ]) + PTYFUNCS_LIBS="$ax_cv_ptyfuncs_libs" + AC_SUBST(PTYFUNCS_LIBS) +])
Signature · 1 line
1.7.2.5
Re: [PATCH 05/24] autoconf: New test for openpty et al.
[...]
tools/configure $as_echo "$ax_cv_pthread_flags" >&6; } · line 6243
Quoted 5 lines
tools/configure +4
-1-AX_CHECK_PTYFUNCS + + ac_fn_c_check_header_mongrel "$LINENO" "libutil.h" "ac_cv_header_libutil_h" "$ac_includes_default" +if test "x$ac_cv_header_libutil_h" = x""yes; then : +
...
That's the error from the previous patch.
Assuming that's fixed in the obvious way:
PATCH v7 6/24 libxl: provide libxl__remove_file et al.
In reply to Ian JacksonThese utility functions cope with EINTR AND ENOENT, do error logging, and we provide a recursive version to delete whole directory trees.
--- tools/libxl/libxl_internal.h | 7 ++++ tools/libxl/libxl_utils.c | 79 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 0 deletions(-)
tools/libxl/libxl_internal.h +7 -0
@@ -442,6 +442,13 @@ _hidden char *libxl__strndup(libxl__gc *gc_opt, const char *c, size_t n);* string. (similar to a gc'd dirname(3)). */ _hidden char *libxl__dirname(libxl__gc *gc_opt, const char *s); +/* Each of these logs errors and returns a libxl error code. +* They do not mind if path is already removed. +* For _file, path must not be a directory; for _directory it must be. */ +_hidden int libxl__remove_file(libxl__gc *gc, const char *path); +_hidden int libxl__remove_directory(libxl__gc *gc, const char *path); +_hidden int libxl__remove_file_or_directory(libxl__gc *gc, const char *path); + _hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length); _hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
tools/libxl/libxl_utils.c +79 -0
85 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v7 7/24 libxl: Introduce libxl__sendmsg_fds and libxl__recvmsg_fds
In reply to Ian JacksonWe will want to reuse the fd-sending code, so break it out into its own function, and provide the corresponding sending function.
--- tools/libxl/libxl_internal.h | 11 ++++ tools/libxl/libxl_qmp.c | 31 ++----------- tools/libxl/libxl_utils.c | 104 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 27 deletions(-)
tools/libxl/libxl_internal.h +11 -0
@@ -1128,6 +1128,17 @@ _hidden void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid); _hidden int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,const libxl_domain_config *guest_config); +/* on failure, logs */ +int libxl__sendmsg_fds (libxl__gc *gc,int carrier, +const void *data,size_t datalen, +int nfds,const int fds[],const char *what); + +/* Insists on receiving exactly nfds and datalen. On failure, logs +* and leaves *fds untouched. */ +int libxl__recvmsg_fds (libxl__gc *gc,int carrier, +void *databuf,size_t datalen, +int nfds,int fds[],const char *what); +/* from libxl_json */ #include <yajl/yajl_gen.h>
tools/libxl/libxl_qmp.c +4 -27
@@ -544,38 +544,15 @@ static int qmp_send_fd(libxl__gc *gc, libxl__qmp_handler *qmp,qmp_request_context *context, int fd) { -struct msghdr msg = {0 }; -struct cmsghdr *cmsg; -char control[CMSG_SPACE (sizeof (fd))]; -struct iovec iov; char *buf = NULL; +int rc; buf =qmp_send_prepare (gc, qmp,"getfd" , args, callback, opaque, context); -/* Response data */ - iov.iov_base = buf; - iov.iov_len =strlen (buf); - -/* compose the message */ - msg.msg_iov = &iov; - msg.msg_iovlen =1 ; - msg.msg_control = control; - msg.msg_controllen =sizeof (control); - -/* attach open fd */ - cmsg =CMSG_FIRSTHDR (&msg); - cmsg->cmsg_level =SOL_SOCKET ; - cmsg->cmsg_type =SCM_RIGHTS ; - cmsg->cmsg_len =CMSG_LEN (sizeof (fd)); - *(int *)CMSG_DATA (cmsg) = fd; - - msg.msg_controllen = cmsg->cmsg_len; + rc =libxl__sendmsg_fds (gc, qmp->qmp_fd, buf,strlen (buf),1 , &fd, +"QMP message to QEMU" ); +if (rc)return rc; -if (sendmsg (qmp->qmp_fd, &msg,0 ) <0 ) { -LIBXL__LOG_ERRNO (qmp->ctx,LIBXL__LOG_ERROR , -"Failed to send a QMP message to QEMU." ); -return ERROR_FAIL ; - }if (libxl_write_exactly (qmp->ctx, qmp->qmp_fd,"\r\n" ,2 ,"CRLF" ,"QMP socket" )) {return ERROR_FAIL ;
tools/libxl/libxl_utils.c +104 -0
110 lines not on this page · raw message
Signature · 1 line
1.7.2.5
PATCH v7 8/24 libxl: Clean up setdefault in do_domain_create
In reply to Ian Jacksondo_domain_create called libxl__domain_create_info_setdefault twice.
--- tools/libxl/libxl_create.c | 3 --- 1 files changed, 0 insertions(+), 3 deletions(-)
tools/libxl/libxl_create.c +0 -3
@@ -552,9 +552,6 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, ret =libxl__domain_create_info_setdefault (gc, &d_config->c_info);if (ret) goto error_out; - ret =libxl__domain_create_info_setdefault (gc, &d_config->c_info); -if (ret) goto error_out; - ret =libxl__domain_make (gc, &d_config->c_info, &domid);if (ret) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"cannot make domain: %d" , ret);
Signature · 1 line
1.7.2.5
PATCH v7 9/24 libxl: provide libxl__datacopier_*
In reply to Ian JacksonGeneral facility for ao operations to shovel data between fds.
This will be used by the bootloader machinery.
Changes since v6
* assert that the ao is non-null on _init.
--- tools/libxl/Makefile | 3 +- tools/libxl/libxl_aoutils.c | 189 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 40 +++++++++ 3 files changed, 231 insertions(+), 1 deletions(-) create mode 100644 tools/libxl/libxl_aoutils.c
tools/libxl/Makefile +2 -1
@@ -52,7 +52,8 @@ LIBXL_LIBS += -lyajl LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \ - libxl_internal.o libxl_utils.o libxl_uuid.o libxl_json.o \ + libxl_internal.o libxl_utils.o libxl_uuid.o \ + libxl_json.o libxl_aoutils.o \ libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o
tools/libxl/libxl_aoutils.c new file +189 -0
189 lines not on this page · raw message
tools/libxl/libxl_internal.h +40 -0
@@ -833,6 +833,7 @@ _hidden int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds,*/ _hidden int libxl__try_phy_backend(mode_t st_mode); +/* from libxl_pci */ _hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting);
@@ -1458,6 +1459,45 @@ int libxl__carefd_close(libxl__carefd*);int libxl__carefd_fd (const libxl__carefd *); +/*----- datacopier: copies data from one fd to another -----*/ + +typedef struct libxl__datacopier_state libxl__datacopier_state ; +typedef struct libxl__datacopier_buf libxl__datacopier_buf ; + +/* onwrite==1 means failure happened when writing, logged, errnoval is valid +* onwrite==0 means failure happened when reading +* errnoval==0 means we got eof and all data was written +* errnoval!=0 means we had a read error, logged +* onwrite==-1 means some other internal failure, errnoval not valid, logged +* in all cases copier is killed before calling this callback */ +typedef void libxl__datacopier_callback (libxl__egc *egc, +libxl__datacopier_state *dc,int onwrite,int errnoval); + +struct libxl__datacopier_buf { +/* private to datacopier */ +LIBXL_TAILQ_ENTRY (libxl__datacopier_buf) entry; +int used; +char buf[1000 ]; +}; + +struct libxl__datacopier_state { +/* caller must fill these in, and they must all remain valid */ +libxl__ao *ao; +int readfd, writefd; +ssize_t maxsz; +const char *copywhat, *readwhat, *writewhat;/* for error msgs */ +libxl__datacopier_callback *callback; +/* remaining fields are private to datacopier */ +libxl__ev_fd toread, towrite; +ssize_t used; + LIBXL_TAILQ_HEAD(libxl__datacopier_bufs, libxl__datacopier_buf) bufs; +}; + +_hidden void libxl__datacopier_init(libxl__datacopier_state *dc); +_hidden void libxl__datacopier_kill(libxl__datacopier_state *dc); +_hidden int libxl__datacopier_start(libxl__datacopier_state *dc); + +/* * Convenience macros. */
Signature · 1 line
1.7.2.5
Re: [PATCH 09/24] libxl: provide libxl__datacopier_*
Quoted 5 lines · Ian Jackson
General facility for ao operations to shovel data between fds.
This will be used by the bootloader machinery.
Signed-off-by Ian Jackson <[email protected]>
Quoted 285 lines
Changes since v6
* assert that the ao is non-null on_init.--- tools/libxl/Makefile | 3 +- tools/libxl/libxl_aoutils.c | 189 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 40 +++++++++ 3 files changed, 231 insertions(+), 1 deletions(-) create mode 100644 tools/libxl/libxl_aoutils.ctools/libxl/Makefile +2
-1@@ -52,7 +52,8 @@ LIBXL_LIBS += -lyajl LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \ - libxl_internal.o libxl_utils.o libxl_uuid.o libxl_json.o \ + libxl_internal.o libxl_utils.o libxl_uuid.o \ + libxl_json.o libxl_aoutils.o \ libxl_qmp.o libxl_event.o libxl_fork.o $(LIBXL_OBJS-y) LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.otools/libxl/libxl_aoutils.c new file +189
-0@@ -0,0 +1,189 @@ +/* +* Copyright (C) 2010 Citrix Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License as published +* by the Free Software Foundation; version 2.1 only. with the special +* exception on linking described in file LICENSE. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License for more details. +*/ + +#include "libxl_osdeps.h" /* must come before any other headers */ + +#include "libxl_internal.h" + +/*----- data copier -----*/ + +void libxl__datacopier_init (libxl__datacopier_state *dc) +{ +assert (dc->ao); +libxl__ev_fd_init (&dc->toread); +libxl__ev_fd_init (&dc->towrite); +LIBXL_TAILQ_INIT (&dc->bufs); +} + +void libxl__datacopier_kill (libxl__datacopier_state *dc) +{ +STATE_AO_GC (dc->ao); +libxl__datacopier_buf *buf, *tbuf; + +libxl__ev_fd_deregister (gc, &dc->toread); +libxl__ev_fd_deregister (gc, &dc->towrite); + LIBXL_TAILQ_FOREACH_SAFE(buf, &dc->bufs, entry, tbuf) +free (buf); +LIBXL_TAILQ_INIT (&dc->bufs); +} + +static void datacopier_callback (libxl__egc *egc,libxl__datacopier_state *dc, +int onwrite,int errnoval) +{ +libxl__datacopier_kill (dc); + dc->callback (egc, dc, onwrite, errnoval); +} + +static void datacopier_writable (libxl__egc *egc,libxl__ev_fd *ev, +int fd,short events,short revents); + +static void datacopier_check_state (libxl__egc *egc,libxl__datacopier_state *dc) +{ +STATE_AO_GC (dc->ao); +int rc; + +if (dc->used) { +if (!libxl__ev_fd_isregistered (&dc->towrite)) { + rc =libxl__ev_fd_register (gc, &dc->towrite, datacopier_writable, + dc->writefd,POLLOUT ); +if (rc) { +LOG (ERROR ,"unable to establish write event on %s" +" during copy of %s" , dc->writewhat, dc->copywhat); +datacopier_callback (egc, dc,-1 ,0 ); +return ; + } + } + }else if (!libxl__ev_fd_isregistered (&dc->toread)) { +/* we have had eof */ +datacopier_callback (egc, dc,0 ,0 ); +return ; + }else { +/* nothing buffered, but still reading */ +libxl__ev_fd_deregister (gc, &dc->towrite); + } +} + +static void datacopier_readable (libxl__egc *egc,libxl__ev_fd *ev, +int fd,short events,short revents) { +libxl__datacopier_state *dc =CONTAINER_OF (ev, *dc, toread); +STATE_AO_GC (dc->ao); + +if (revents & ~POLLIN ) { +LOG (ERROR ,"unexpected poll event 0x%x (should be POLLIN)" +" on %s during copy of %s" , revents, dc->readwhat, dc->copywhat); +datacopier_callback (egc, dc,-1 ,0 ); +return ; + } +assert (revents &POLLIN ); +for (;;) { +while (dc->used >= dc->maxsz) { +libxl__datacopier_buf *rm =LIBXL_TAILQ_FIRST (&dc->bufs); + dc->used -= rm->used; +assert (dc->used >=0 ); +LIBXL_TAILQ_REMOVE (&dc->bufs, rm, entry); +free (rm); + } + +libxl__datacopier_buf *buf = +LIBXL_TAILQ_LAST (&dc->bufs, libxl__datacopier_bufs); +if (!buf || buf->used >=sizeof (buf->buf)) { + buf =malloc (sizeof (*buf)); +if (!buf)libxl__alloc_failed (CTX , __func__,1 ,sizeof (*buf)); + buf->used =0 ; +LIBXL_TAILQ_INSERT_TAIL (&dc->bufs, buf, entry); + } +int r =read (ev->fd, + buf->buf + buf->used, +sizeof (buf->buf) - buf->used); +if (r <0 ) { +if (errno ==EINTR )continue ; +if (errno ==EWOULDBLOCK )break ; +LOGE (ERROR ,"error reading %s during copy of %s" , + dc->readwhat, dc->copywhat); +datacopier_callback (egc, dc,0 , errno); +return ; + } +if (r ==0 ) { +libxl__ev_fd_deregister (gc, &dc->toread); +break ; + } + buf->used += r; + dc->used += r; +assert (buf->used <=sizeof (buf->buf)); + } +datacopier_check_state (egc, dc); +} + +static void datacopier_writable (libxl__egc *egc,libxl__ev_fd *ev, +int fd,short events,short revents) { +libxl__datacopier_state *dc =CONTAINER_OF (ev, *dc, towrite); +STATE_AO_GC (dc->ao); + +if (revents & ~POLLOUT ) { +LOG (ERROR ,"unexpected poll event 0x%x (should be POLLOUT)" +" on %s during copy of %s" , revents, dc->writewhat, dc->copywhat); +datacopier_callback (egc, dc,-1 ,0 ); +return ; + } +assert (revents &POLLOUT ); +for (;;) { +libxl__datacopier_buf *buf =LIBXL_TAILQ_FIRST (&dc->bufs); +if (!buf) +break ; +if (!buf->used) { +LIBXL_TAILQ_REMOVE (&dc->bufs, buf, entry); +free (buf); +continue ; + } +int r =write (ev->fd, buf->buf, buf->used); +if (r <0 ) { +if (errno ==EINTR )continue ; +if (errno ==EWOULDBLOCK )break ; +LOGE (ERROR ,"error writing to %s during copy of %s" , + dc->writewhat, dc->copywhat); +datacopier_callback (egc, dc,1 , errno); +return ; + } +assert (r >0 ); +assert (r <= buf->used); + buf->used -= r; + dc->used -= r; +assert (dc->used >=0 ); +memmove (buf->buf, buf->buf+r, buf->used); + } +datacopier_check_state (egc, dc); +} + +int libxl__datacopier_start (libxl__datacopier_state *dc) +{ +int rc; +STATE_AO_GC (dc->ao); + +libxl__datacopier_init (dc); + + rc =libxl__ev_fd_register (gc, &dc->toread, datacopier_readable, + dc->readfd,POLLIN ); +if (rc) goto out; + + rc =libxl__ev_fd_register (gc, &dc->towrite, datacopier_writable, + dc->writefd,POLLOUT ); +if (rc) goto out; + +return 0 ; + + out: +libxl__datacopier_kill (dc); +return rc; +} +tools/libxl/libxl_internal.h +40
-1@@ -833,6 +833,7 @@ _hidden int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds,*/ _hidden int libxl__try_phy_backend(mode_t st_mode); +/* from libxl_pci */ _hidden int libxl__device_pci_add(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int starting);@@ -1458,6 +1459,45 @@ int libxl__carefd_close(libxl__carefd*);int libxl__carefd_fd (const libxl__carefd *); +/*----- datacopier: copies data from one fd to another -----*/ + +typedef struct libxl__datacopier_state libxl__datacopier_state ; +typedef struct libxl__datacopier_buf libxl__datacopier_buf ; + +/* onwrite==1 means failure happened when writing, logged, errnoval is valid +* onwrite==0 means failure happened when reading +* errnoval==0 means we got eof and all data was written +* errnoval!=0 means we had a read error, logged +* onwrite==-1 means some other internal failure, errnoval not valid, logged +* in all cases copier is killed before calling this callback */ +typedef void libxl__datacopier_callback (libxl__egc *egc, +libxl__datacopier_state *dc,int onwrite,int errnoval); + +struct libxl__datacopier_buf { +/* private to datacopier */ +LIBXL_TAILQ_ENTRY (libxl__datacopier_buf) entry; +int used; +char buf[1000 ]; +}; + +struct libxl__datacopier_state { +/* caller must fill these in, and they must all remain valid */ +libxl__ao *ao; +int readfd, writefd; +ssize_t maxsz; +const char *copywhat, *readwhat, *writewhat;/* for error msgs */ +libxl__datacopier_callback *callback; +/* remaining fields are private to datacopier */ +libxl__ev_fd toread, towrite; +ssize_t used; + LIBXL_TAILQ_HEAD(libxl__datacopier_bufs, libxl__datacopier_buf) bufs; +}; + +_hidden void libxl__datacopier_init(libxl__datacopier_state *dc); +_hidden void libxl__datacopier_kill(libxl__datacopier_state *dc); +_hidden int libxl__datacopier_start(libxl__datacopier_state *dc); + +/* * Convenience macros. */ --1.7.2.5
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v7 10/24 libxl: provide libxl__openpty_*
In reply to Ian JacksonGeneral facility for ao operations to open ptys.
This will be used by the bootloader machinery.
--- tools/libxl/libxl_aoutils.c | 127 ++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 36 ++++++++++++ 2 files changed, 163 insertions(+), 0 deletions(-)
tools/libxl/libxl_aoutils.c +127 -0
@@ -187,3 +187,130 @@ int libxl__datacopier_start(libxl__datacopier_state *dc)return rc; } +/*----- openpty -----*/ + +/* implementation */ + +static void openpty_cleanup (libxl__openpty_state *op) +{ +int i; + +for (i=0 ; i<op->count; i++) { +libxl__openpty_result *res = &op->results[i]; +libxl__carefd_close (res->master); res->master =0 ; +libxl__carefd_close (res->slave); res->slave =0 ; + } +} + +static void openpty_exited (libxl__egc *egc,libxl__ev_child *child, +pid_t pid,int status) { +libxl__openpty_state *op =CONTAINER_OF (child, *op, child); +STATE_AO_GC (op->ao); + +if (status) { +/* Perhaps the child gave us the fds and then exited nonzero. +* Well that would be odd but we don't really care. */ +libxl_report_child_exitstatus (CTX , op->rc ?LIBXL__LOG_ERROR + :LIBXL__LOG_WARNING , +"openpty child" , pid, status); + } +if (op->rc) +openpty_cleanup (op); + op->callback (egc, op); +} + +int libxl__openptys (libxl__openpty_state *op, +const struct termios *termp, +const struct winsize *winp) { +/* +* This is completely crazy. openpty calls grantpt which the spec +* says may fork, and may not be called with a SIGCHLD handler. +* Now our application may have a SIGCHLD handler so that's bad. +* We could perhaps block it but we'd need to block it on all +* threads. This is just Too Hard. +* +* So instead, we run openpty in a child process. That child +* process then of course has only our own thread and our own +* signal handlers. We pass the fds back. +* +* Since our only current caller actually wants two ptys, we +* support calling openpty multiple times for a single fork. +*/ +STATE_AO_GC (op->ao); +int count = op->count; +int r, i, rc, sockets[2 ], ptyfds[count][2 ]; +libxl__carefd *for_child =0 ; +pid_t pid =-1 ; + +for (i=0 ; i<count; i++) { + ptyfds[i][0 ] = ptyfds[i][1 ] =-1 ; +libxl__openpty_result *res = &op->results[i]; +assert (!res->master); +assert (!res->slave); + } + sockets[0 ] = sockets[1 ] =-1 ;/* 0 is for us, 1 for our child */ + +libxl__carefd_begin (); + r =socketpair (AF_UNIX ,SOCK_STREAM ,0 , sockets); +if (r) { sockets[0 ] = sockets[1 ] =-1 ; } + for_child =libxl__carefd_opened (CTX , sockets[1 ]); +if (r) {LOGE (ERROR ,"socketpair failed" ); rc =ERROR_FAIL ; goto out; } + + pid =libxl__ev_child_fork (gc, &op->child, openpty_exited); +if (pid ==-1 ) { + rc =ERROR_FAIL ; + goto out; + } + +if (!pid) { +/* child */ +close (sockets[0 ]); +signal (SIGCHLD ,SIG_DFL ); + +for (i=0 ; i<count; i++) { + r =openpty (&ptyfds[i][0 ], &ptyfds[i][1 ],NULL , termp, winp); +if (r) {LOGE (ERROR ,"openpty failed" );_exit (-1 ); } + } + rc =libxl__sendmsg_fds (gc, sockets[1 ],"" ,1 , +2 *count, &ptyfds[0 ][0 ],"ptys" ); +if (rc) {LOGE (ERROR ,"sendmsg to parent failed" );_exit (-1 ); } +_exit (0 ); + } + +libxl__carefd_close (for_child); + for_child =0 ; + +/* this should be fast so do it synchronously */ + +libxl__carefd_begin (); +char buf[1 ]; + rc =libxl__recvmsg_fds (gc, sockets[0 ], buf,1 , +2 *count, &ptyfds[0 ][0 ],"ptys" ); +if (!rc) { +for (i=0 ; i<count; i++) { +libxl__openpty_result *res = &op->results[i]; + res->master =libxl__carefd_record (CTX , ptyfds[i][0 ]); + res->slave =libxl__carefd_record (CTX , ptyfds[i][1 ]); + } + } +/* now the pty fds are in the carefds, if they were ever open */ +libxl__carefd_unlock (); +if (rc) + goto out; + + rc =0 ; + + out: +if (sockets[0 ] >=0 )close (sockets[0 ]); +libxl__carefd_close (for_child); +if (libxl__ev_child_inuse (&op->child)) { + op->rc = rc; +/* we will get a callback when the child dies */ +return 0 ; + } + +assert (rc); +openpty_cleanup (op); +return rc; +} +
tools/libxl/libxl_internal.h +36 -0
@@ -1498,6 +1498,42 @@ _hidden void libxl__datacopier_kill(libxl__datacopier_state *dc); _hidden int libxl__datacopier_start(libxl__datacopier_state *dc); +/*----- openpty -----*/ + +/* +* opens count (>0) ptys like count calls to openpty, and then +* calls back. On entry, all op[].master and op[].slave must be +* 0. On callback, either rc==0 and master and slave are non-0, +* or rc is a libxl error and they are both 0. If libxl__openpty +* returns non-0 no callback will happen and everything is left +* cleaned up. +*/ + +typedef struct libxl__openpty_state libxl__openpty_state ; +typedef struct libxl__openpty_result libxl__openpty_result ; +typedef void libxl__openpty_callback (libxl__egc *egc,libxl__openpty_state *op); + +struct libxl__openpty_state { +/* caller must fill these in, and they must all remain valid */ +libxl__ao *ao; +libxl__openpty_callback *callback; +int count; +libxl__openpty_result *results;/* actual size is count, out parameter */ +/* public, result, caller may only read in callback */ +int rc; +/* private for implementation */ +libxl__ev_child child; +}; + +struct libxl__openpty_result { +libxl__carefd *master, *slave; +}; + +int libxl__openptys (libxl__openpty_state *op, +const struct termios *termp, +const struct winsize *winp); + +/* * Convenience macros. */
Signature · 1 line
1.7.2.5
PATCH v7 11/24 libxl: ao: Convert libxl_run_bootloader
In reply to Ian JacksonConvert libxl_run_bootloader to an ao_how-taking function.
It's implemented in terms of libxl__bootloader_run, which can be used internally. The resulting code is pretty much a rewrite.
Significant changes include:
- We direct the bootloader's results to a file, not a pipe. This makes it simpler to deal with as we don't have to read it concurrently along with everything else.
- We now issue a warning if we find unexpected statements in the bootloader results.
- The arrangements for buffering of bootloader input and output are completely changed. Now we have a fixed limit of 64k on output, and 4k on input, and discard the oldest data when this overflows (which it shouldn't). There is no timeout any more.
Changes since v6:
* Use libxl__ev_child_inuse rather than testing pid directly.
* Fix a code style error.
* Properly initialise the sub-operations' aos in _init.
* Bugfixes.
--- tools/libxl/libxl.c | 4 + tools/libxl/libxl.h | 3 +- tools/libxl/libxl_bootloader.c | 713 +++++++++++++++++++++------------------- tools/libxl/libxl_create.c | 8 +- tools/libxl/libxl_internal.h | 34 ++ 5 files changed, 419 insertions(+), 343 deletions(-)
tools/libxl/libxl.c +4 -0
@@ -1748,6 +1748,10 @@ int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk)* For other device types assume that the blktap2 process is * needed by the soon to be started domain and do nothing. */ +/* +* FIXME +* This appears to leak the disk in failure paths +*/ return 0 ; }
tools/libxl/libxl.h +2 -1
@@ -494,7 +494,8 @@ int libxl_get_max_cpus(libxl_ctx *ctx);int libxl_run_bootloader (libxl_ctx *ctx,libxl_domain_build_info *info,libxl_device_disk *disk, -uint32_t domid); +uint32_t domid, +libxl_asyncop_how *ao_how);/* 0 means ERROR_ENOMEM, which we have logged */
tools/libxl/libxl_bootloader.c +373 -340
832 lines not on this page · raw message
tools/libxl/libxl_create.c +6 -2
@@ -572,8 +572,12 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,if (ret) goto error_out; } -if ( restore_fd <0 ) { - ret =libxl_run_bootloader (ctx, &d_config->b_info, d_config->num_disks >0 ? &d_config->disks[0 ] :NULL , domid); +libxl_device_disk *bootdisk = + d_config->num_disks >0 ? &d_config->disks[0 ] :NULL ; + +if (restore_fd <0 && bootdisk) { + ret =libxl_run_bootloader (ctx, &d_config->b_info, bootdisk, domid, +0 /* fixme-ao */ );if (ret) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"failed to run bootloader: %d" , ret);
tools/libxl/libxl_internal.h +34 -0
@@ -42,6 +42,7 @@#include <sys/time.h> #include <sys/types.h> #include <sys/wait.h> +#include <sys/socket.h> #include <xs.h> #include <xenctrl.h>
@@ -449,6 +450,7 @@ _hidden int libxl__remove_file(libxl__gc *gc, const char *path); _hidden int libxl__remove_directory(libxl__gc *gc, const char *path); _hidden int libxl__remove_file_or_directory(libxl__gc *gc, const char *path); + _hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length); _hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
@@ -1534,6 +1536,38 @@ int libxl__openptys(libxl__openpty_state *op, const struct winsize *winp); +/*----- bootloader -----*/ + +typedef struct libxl__bootloader_state libxl__bootloader_state ; +typedef void libxl__run_bootloader_callback (libxl__egc *, +libxl__bootloader_state *,int rc); + +struct libxl__bootloader_state { +/* caller must fill these in, and they must all remain valid */ +libxl__ao *ao; +libxl__run_bootloader_callback *callback; +libxl_domain_build_info *info;/* u.pv.{kernel,ramdisk,cmdline} updated */ +libxl_device_disk *disk; +uint32_t domid; +/* private to libxl__run_bootloader */ +char *outputpath, *outputdir; +char *diskpath;/* not from gc, represents actually attached disk */ +libxl__openpty_state openpty; +libxl__openpty_result ptys[2 ];/* [0] is for bootloader */ +libxl__ev_child child; +int nargs, argsspace; +const char **args; +libxl__datacopier_state keystrokes, display; +int rc; +}; + +_hidden void libxl__bootloader_init(libxl__bootloader_state *bl); + +/* Will definitely call st->callback, perhaps reentrantly. +* If callback is passed rc==0, will have updated st->info appropriately */ +_hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st); + +/* * Convenience macros. */
Signature · 1 line
1.7.2.5
PATCH v7 12/24 libxl: make libxl_create_logfile const-correct
In reply to Ian Jackson--- tools/libxl/libxl_utils.c | 2 +- tools/libxl/libxl_utils.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_utils.c +1 -1
@@ -193,7 +193,7 @@ static int logrename(libxl__gc *gc, const char *old, const char *new)return 0 ; } -int libxl_create_logfile (libxl_ctx *ctx,char *name,char **full_name) +int libxl_create_logfile (libxl_ctx *ctx,const char *name,char **full_name) {GC_INIT (ctx);struct stat stat_buf;
tools/libxl/libxl_utils.h +1 -1
@@ -26,7 +26,7 @@ int libxl_name_to_cpupoolid(libxl_ctx *ctx, const char *name, uint32_t *poolid);char *libxl_cpupoolid_to_name (libxl_ctx *ctx,uint32_t poolid);int libxl_get_stubdom_id (libxl_ctx *ctx,int guest_domid);int libxl_is_stubdom (libxl_ctx *ctx,uint32_t domid,uint32_t *target_domid); -int libxl_create_logfile (libxl_ctx *ctx,char *name,char **full_name); +int libxl_create_logfile (libxl_ctx *ctx,const char *name,char **full_name);int libxl_string_to_backend (libxl_ctx *ctx,char *s,libxl_disk_backend *backend); int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
Signature · 1 line
1.7.2.5
PATCH v7 13/24 libxl: log bootloader output
In reply to Ian JacksonThis involves adding a new log feature to libxl__datacopier, and then using it.
If the bootloader exits nonzero we print the log filename in a log message from libxl.
--- tools/libxl/libxl_aoutils.c | 10 ++++++++++ tools/libxl/libxl_bootloader.c | 24 ++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 3 ++- 3 files changed, 36 insertions(+), 1 deletions(-)
tools/libxl/libxl_aoutils.c +10 -0
@@ -118,6 +118,16 @@ static void datacopier_readable(libxl__egc *egc, libxl__ev_fd *ev,libxl__ev_fd_deregister (gc, &dc->toread);break ; } +if (dc->log) { +int wrote =fwrite (buf->buf + buf->used,1 , r, dc->log); +if (wrote != r) { +assert (ferror (dc->log)); +assert (errno); +LOGE (ERROR ,"error logging %s" , dc->copywhat); +datacopier_callback (egc, dc,0 , errno); +return ; + } + } buf->used += r; dc->used += r;assert (buf->used <=sizeof (buf->buf));
tools/libxl/libxl_bootloader.c +24 -0
@@ -236,6 +236,10 @@ static void bootloader_cleanup(libxl__egc *egc, libxl__bootloader_state *bl)libxl__carefd_close (bl->ptys[i].master);libxl__carefd_close (bl->ptys[i].slave); } +if (bl->display.log) { +fclose (bl->display.log); + bl->display.log =NULL ; + } }static void bootloader_setpaths (libxl__gc *gc,libxl__bootloader_state *bl)
@@ -258,6 +262,8 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl) {STATE_AO_GC (bl->ao);libxl_domain_build_info *info = bl->info; +uint32_t domid = bl->domid; +char *logfile_tmp =NULL ;int rc, r;libxl__bootloader_init (bl);
@@ -269,6 +275,22 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl)bootloader_setpaths (gc, bl); +const char *logfile_leaf =GCSPRINTF ("bootloader.%" PRIu32, domid); + rc =libxl_create_logfile (CTX , logfile_leaf, &logfile_tmp); +if (rc) goto out; + +/* Transfer ownership of log filename to bl and the gc */ + bl->logfile = logfile_tmp; +libxl__ptr_add (gc, logfile_tmp); + logfile_tmp =NULL ; + + bl->display.log =fopen (bl->logfile,"a" ); +if (!bl->display.log) { +LOGE (ERROR ,"failed to create bootloader logfile %s" , bl->logfile); + rc =ERROR_FAIL ; + goto out; + } +for (;;) { r =mkdir (bl->outputdir,0600 );if (!r)break ;
@@ -308,6 +330,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl) out:assert (rc); out_ok: +free (logfile_tmp);bootloader_callback (egc, bl, rc); }
@@ -465,6 +488,7 @@ static void bootloader_finished(libxl__egc *egc, libxl__ev_child *child,libxl__datacopier_kill (&bl->display);if (status) { +LOG (ERROR ,"bootloader failed - consult logfile %s" , bl->logfile);libxl_report_child_exitstatus (CTX ,XTL_ERROR ,"bootloader" , pid, status); rc =ERROR_FAIL ;
tools/libxl/libxl_internal.h +2 -1
@@ -1488,6 +1488,7 @@ struct libxl__datacopier_state {int readfd, writefd;ssize_t maxsz;const char *copywhat, *readwhat, *writewhat;/* for error msgs */ +FILE *log;/* gets a copy of everything */ libxl__datacopier_callback *callback;/* remaining fields are private to datacopier */ libxl__ev_fd toread, towrite;
@@ -1550,7 +1551,7 @@ struct libxl__bootloader_state {libxl_device_disk *disk;uint32_t domid;/* private to libxl__run_bootloader */ -char *outputpath, *outputdir; +char *outputpath, *outputdir, *logfile;char *diskpath;/* not from gc, represents actually attached disk */ libxl__openpty_state openpty;libxl__openpty_result ptys[2 ];/* [0] is for bootloader */
Signature · 1 line
1.7.2.5
PATCH v7 14/24 libxl: Allow AO_GC and EGC_GC even if not used
In reply to Ian JacksonMark the gc produced by AO_GC and EGC_GC with the gcc feature __attribute__((unused)). This allows the use of EGC_INIT and STATE_AO_GC by functions which do actually use the gc.
This is convenient because those functions might want to use the ao or egc, rather than the gc; and also because it means that functions which morally ought to be fishing any gc they use out of an egc or state structure can be written do so regardless of whether the gc is actually used right then.
--- tools/libxl/libxl_internal.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
tools/libxl/libxl_internal.h +2 -2
@@ -1280,7 +1280,7 @@ libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);/* useful for all functions which take an egc: */ #define EGC_GC \ - libxl__gc *const gc = &egc->gc + libxl__gc *const gc __attribute__((unused)) = &egc->gc/* egc initialisation and destruction: */
@@ -1383,7 +1383,7 @@ _hidden void libxl__egc_cleanup(libxl__egc *egc); })#define AO_GC \ - libxl__gc *const gc = &ao->gc + libxl__gc *const gc __attribute__((unused)) = &ao->gc#define STATE_AO_GC (op_ao) \ libxl__ao *const ao = (op_ao); \
Signature · 1 line
1.7.2.5
PATCH v7 15/24 libxl: remove ctx->waitpid_instead
In reply to Ian JacksonRemove this obsolete hook. Callers inside libxl which create and reap children should use the mechanisms provided by the event system.
--- tools/libxl/libxl_exec.c | 12 +++--------- tools/libxl/libxl_internal.h | 3 --- 2 files changed, 3 insertions(+), 12 deletions(-)
tools/libxl/libxl_exec.c +3 -9
@@ -19,11 +19,6 @@#include "libxl_internal.h" -static int call_waitpid (pid_t (*waitpid_cb)(pid_t ,int *,int ),pid_t pid,int *status,int options) -{ -return (waitpid_cb) ?waitpid_cb (pid, status, options) :waitpid (pid, status, options); -} -static void check_open_fds (const char *what) {const char *env_debug;
@@ -344,7 +339,7 @@ int libxl__spawn_spawn(libxl__gc *gc,if (!for_spawn)_exit (0 );/* just detach then */ - got =call_waitpid (ctx->waitpid_instead, child, &status,0 ); + got =waitpid (child, &status,0 );assert (got == child); rc = (WIFEXITED(status) ? WEXITSTATUS(status) :
@@ -404,7 +399,7 @@ int libxl__spawn_detach(libxl__gc *gc, (unsigned long)for_spawn->intermediate);abort ();/* things are very wrong */ } - got =call_waitpid (ctx->waitpid_instead, for_spawn->intermediate, &status,0 ); + got =waitpid (for_spawn->intermediate, &status,0 );assert (got == for_spawn->intermediate);if (!(WIFSIGNALED (status) &&WTERMSIG (status) ==SIGKILL )) {report_spawn_intermediate_status (gc, for_spawn, status);
@@ -421,14 +416,13 @@ int libxl__spawn_detach(libxl__gc *gc,int libxl__spawn_check (libxl__gc *gc,libxl__spawn_starting *for_spawn) { -libxl_ctx *ctx =libxl__gc_owner (gc);pid_t got;int status;if (!for_spawn)return 0 ;assert (for_spawn->intermediate); - got =call_waitpid (ctx->waitpid_instead, for_spawn->intermediate, &status,WNOHANG ); + got =waitpid (for_spawn->intermediate, &status,WNOHANG );if (!got)return 0 ;assert (got == for_spawn->intermediate);
tools/libxl/libxl_internal.h +0 -3
@@ -334,9 +334,6 @@ struct libxl__ctx {int sigchld_selfpipe[2 ];/* [0]==-1 means handler not installed */ LIBXL_LIST_HEAD(, libxl__ev_child) children; -/* This is obsolete and must be removed: */ -int (*waitpid_instead)(pid_t pid,int *status,int flags); -libxl_version_info version_info; };
Signature · 1 line
1.7.2.5
Re: [PATCH 15/24] libxl: remove ctx->waitpid_instead
Quoted 2 lines · Ian Jackson
Remove this obsolete hook. Callers inside libxl which create and reap children should use the mechanisms provided by the event system.
The hook is unused which is good because otherwise I would have asked for this patch to go after the patches to make the users use those mechanisms. As it is removing the hook makes no semantic difference to anyone.
Quoted 1 line
Signed-off-by Ian Jackson <[email protected]>
Quoted 69 lines
--- tools/libxl/libxl_exec.c | 12 +++--------- tools/libxl/libxl_internal.h | 3 --- 2 files changed, 3 insertions(+), 12 deletions(-)tools/libxl/libxl_exec.c +3
-9@@ -19,11 +19,6 @@#include "libxl_internal.h" -static int call_waitpid (pid_t (*waitpid_cb)(pid_t ,int *,int ),pid_t pid,int *status,int options) -{ -return (waitpid_cb) ?waitpid_cb (pid, status, options) :waitpid (pid, status, options); -} -static void check_open_fds (const char *what) {const char *env_debug;@@ -344,7 +339,7 @@ int libxl__spawn_spawn(libxl__gc *gc,if (!for_spawn)_exit (0 );/* just detach then */ - got =call_waitpid (ctx->waitpid_instead, child, &status,0 ); + got =waitpid (child, &status,0 );assert (got == child); rc = (WIFEXITED(status) ? WEXITSTATUS(status) :@@ -404,7 +399,7 @@ int libxl__spawn_detach(libxl__gc *gc, (unsigned long)for_spawn->intermediate);abort ();/* things are very wrong */ } - got =call_waitpid (ctx->waitpid_instead, for_spawn->intermediate, &status,0 ); + got =waitpid (for_spawn->intermediate, &status,0 );assert (got == for_spawn->intermediate);if (!(WIFSIGNALED (status) &&WTERMSIG (status) ==SIGKILL )) {report_spawn_intermediate_status (gc, for_spawn, status);@@ -421,14 +416,13 @@ int libxl__spawn_detach(libxl__gc *gc,int libxl__spawn_check (libxl__gc *gc,libxl__spawn_starting *for_spawn) { -libxl_ctx *ctx =libxl__gc_owner (gc);pid_t got;int status;if (!for_spawn)return 0 ;assert (for_spawn->intermediate); - got =call_waitpid (ctx->waitpid_instead, for_spawn->intermediate, &status,WNOHANG ); + got =waitpid (for_spawn->intermediate, &status,WNOHANG );if (!got)return 0 ;assert (got == for_spawn->intermediate);tools/libxl/libxl_internal.h +0
-3@@ -334,9 +334,6 @@ struct libxl__ctx {int sigchld_selfpipe[2 ];/* [0]==-1 means handler not installed */ LIBXL_LIST_HEAD(, libxl__ev_child) children; -/* This is obsolete and must be removed: */ -int (*waitpid_instead)(pid_t pid,int *status,int flags); -libxl_version_info version_info; };
Re: [PATCH 15/24] libxl: remove ctx->waitpid_instead
Ian Campbell writes ("Re: [Xen-devel] [PATCH 15/24] libxl: remove ctx->waitpid_instead"):
Quoted 8 lines · Ian Jackson
Quoted 2 lines
Remove this obsolete hook. Callers inside libxl which create and reap children should use the mechanisms provided by the event system.
The hook is unused which is good because otherwise I would have asked for this patch to go after the patches to make the users use those mechanisms. As it is removing the hook makes no semantic difference to anyone.
Yes. I'll add a note about that to the commit message.
Ian.
PATCH v7 16/24 libxl: change some structures to unit arrays
In reply to Ian JacksonIn the next patch these variables will turn into actual pointers.
To clarify that patch, prepare the ground by changing these variables from "struct foo var" to "struct foo var[1]". This enables accesses to them and their members to be made as if they were pointers.
No functional change.
--- tools/libxl/libxl_create.c | 18 +++++----- tools/libxl/libxl_dm.c | 84 ++++++++++++++++++++++---------------------- 2 files changed, 51 insertions(+), 51 deletions(-)
tools/libxl/libxl_create.c +9 -9
@@ -543,7 +543,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, {libxl_ctx *ctx =libxl__gc_owner (gc);libxl__spawner_starting *dm_starting =0 ; -libxl__domain_build_state state; +libxl__domain_build_state state[1 ];uint32_t domid;int i, ret;
@@ -585,12 +585,12 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, } } -memset (&state,0 ,sizeof (state)); +memset (state,0 ,sizeof (*state));if ( restore_fd >=0 ) { - ret =domain_restore (gc, &d_config->b_info, domid, restore_fd, &state); + ret =domain_restore (gc, &d_config->b_info, domid, restore_fd, state); }else { - ret =libxl__domain_build (gc, &d_config->b_info, domid, &state); + ret =libxl__domain_build (gc, &d_config->b_info, domid, state); }if (ret) {
@@ -628,7 +628,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, ret =init_console_info (&console,0 );if ( ret ) goto error_out; -libxl__device_console_add (gc, domid, &console, &state); +libxl__device_console_add (gc, domid, &console, state);libxl__device_console_dispose (&console);libxl_device_vkb_init (&vkb);
@@ -636,7 +636,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,libxl_device_vkb_dispose (&vkb); ret =libxl__create_device_model (gc, domid, d_config, - &state, &dm_starting); + state, &dm_starting);if (ret <0 ) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"failed to create device model: %d" , ret);
@@ -665,11 +665,11 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,if (need_qemu) console.consback =LIBXL__CONSOLE_BACKEND_IOEMU ; -libxl__device_console_add (gc, domid, &console, &state); +libxl__device_console_add (gc, domid, &console, state);libxl__device_console_dispose (&console);if (need_qemu) { -libxl__create_xenpv_qemu (gc, domid, d_config, &state, &dm_starting); +libxl__create_xenpv_qemu (gc, domid, d_config, state, &dm_starting); }break ; }
@@ -683,7 +683,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {libxl__qmp_initializations (gc, domid, d_config); } - ret =libxl__confirm_device_model_startup (gc, &state, dm_starting); + ret =libxl__confirm_device_model_startup (gc, state, dm_starting);if (ret <0 ) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"device model did not start: %d" , ret);
tools/libxl/libxl_dm.c +42 -42
144 lines not on this page · raw message
Signature · 1 line
1.7.2.5
Re: [PATCH 16/24] libxl: change some structures to unit arrays
Quoted 7 lines · Ian Jackson
In the next patch these variables will turn into actual pointers.
To clarify that patch, prepare the ground by changing these variables from "struct foo var" to "struct foo var[1]". This enables accesses to them and their members to be made as if they were pointers.
No functional change.
Therefore only quickly skimmed and:
Quoted 237 lines
Signed-off-by Ian Jackson <[email protected]>--- tools/libxl/libxl_create.c | 18 +++++----- tools/libxl/libxl_dm.c | 84 ++++++++++++++++++++++---------------------- 2 files changed, 51 insertions(+), 51 deletions(-)tools/libxl/libxl_create.c +9
-9@@ -543,7 +543,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, {libxl_ctx *ctx =libxl__gc_owner (gc);libxl__spawner_starting *dm_starting =0 ; -libxl__domain_build_state state; +libxl__domain_build_state state[1 ];uint32_t domid;int i, ret;@@ -585,12 +585,12 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, } } -memset (&state,0 ,sizeof (state)); +memset (state,0 ,sizeof (*state));if ( restore_fd >=0 ) { - ret =domain_restore (gc, &d_config->b_info, domid, restore_fd, &state); + ret =domain_restore (gc, &d_config->b_info, domid, restore_fd, state); }else { - ret =libxl__domain_build (gc, &d_config->b_info, domid, &state); + ret =libxl__domain_build (gc, &d_config->b_info, domid, state); }if (ret) {@@ -628,7 +628,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, ret =init_console_info (&console,0 );if ( ret ) goto error_out; -libxl__device_console_add (gc, domid, &console, &state); +libxl__device_console_add (gc, domid, &console, state);libxl__device_console_dispose (&console);libxl_device_vkb_init (&vkb);@@ -636,7 +636,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,libxl_device_vkb_dispose (&vkb); ret =libxl__create_device_model (gc, domid, d_config, - &state, &dm_starting); + state, &dm_starting);if (ret <0 ) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"failed to create device model: %d" , ret);@@ -665,11 +665,11 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,if (need_qemu) console.consback =LIBXL__CONSOLE_BACKEND_IOEMU ; -libxl__device_console_add (gc, domid, &console, &state); +libxl__device_console_add (gc, domid, &console, state);libxl__device_console_dispose (&console);if (need_qemu) { -libxl__create_xenpv_qemu (gc, domid, d_config, &state, &dm_starting); +libxl__create_xenpv_qemu (gc, domid, d_config, state, &dm_starting); }break ; }@@ -683,7 +683,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {libxl__qmp_initializations (gc, domid, d_config); } - ret =libxl__confirm_device_model_startup (gc, &state, dm_starting); + ret =libxl__confirm_device_model_startup (gc, state, dm_starting);if (ret <0 ) {LIBXL__LOG (ctx,LIBXL__LOG_ERROR ,"device model did not start: %d" , ret);tools/libxl/libxl_dm.c +42
-43@@ -676,10 +676,10 @@ static int libxl__create_stubdom(libxl__gc *gc,libxl_ctx *ctx =libxl__gc_owner (gc);int i, num_console =STUBDOM_SPECIAL_CONSOLES , ret;libxl__device_console *console; -libxl_domain_config dm_config; +libxl_domain_config dm_config[1 ];libxl_device_vfb vfb;libxl_device_vkb vkb; -libxl__domain_build_state stubdom_state; +libxl__domain_build_state stubdom_state[1 ];uint32_t dm_domid;char **args;struct xs_permissions perm[2 ];@@ -692,58 +692,58 @@ static int libxl__create_stubdom(libxl__gc *gc, goto out; } -libxl_domain_create_info_init (&dm_config.c_info); - dm_config.c_info.type =LIBXL_DOMAIN_TYPE_PV ; - dm_config.c_info.name =libxl__sprintf (gc,"%s-dm" , +libxl_domain_create_info_init (&dm_config->c_info); + dm_config->c_info.type =LIBXL_DOMAIN_TYPE_PV ; + dm_config->c_info.name =libxl__sprintf (gc,"%s-dm" ,libxl__domid_to_name (gc, guest_domid)); - dm_config.c_info.ssidref = guest_config->b_info.device_model_ssidref; + dm_config->c_info.ssidref = guest_config->b_info.device_model_ssidref; -libxl_uuid_generate (&dm_config.c_info.uuid); +libxl_uuid_generate (&dm_config->c_info.uuid); -libxl_domain_build_info_init (&dm_config.b_info); -libxl_domain_build_info_init_type (&dm_config.b_info,LIBXL_DOMAIN_TYPE_PV ); +libxl_domain_build_info_init (&dm_config->b_info); +libxl_domain_build_info_init_type (&dm_config->b_info,LIBXL_DOMAIN_TYPE_PV ); - dm_config.b_info.max_vcpus =1 ; - dm_config.b_info.max_memkb =32 *1024 ; - dm_config.b_info.target_memkb = dm_config.b_info.max_memkb; + dm_config->b_info.max_vcpus =1 ; + dm_config->b_info.max_memkb =32 *1024 ; + dm_config->b_info.target_memkb = dm_config->b_info.max_memkb; - dm_config.b_info.u.pv.kernel.path =libxl__abs_path (gc,"ioemu-stubdom.gz" , + dm_config->b_info.u.pv.kernel.path =libxl__abs_path (gc,"ioemu-stubdom.gz" ,libxl_xenfirmwaredir_path ()); - dm_config.b_info.u.pv.cmdline =libxl__sprintf (gc," -d %d" , guest_domid); - dm_config.b_info.u.pv.ramdisk.path ="" ; - dm_config.b_info.u.pv.features ="" ; + dm_config->b_info.u.pv.cmdline =libxl__sprintf (gc," -d %d" , guest_domid); + dm_config->b_info.u.pv.ramdisk.path ="" ; + dm_config->b_info.u.pv.features ="" ; - dm_config.b_info.device_model_version = + dm_config->b_info.device_model_version = guest_config->b_info.device_model_version; - dm_config.b_info.device_model = + dm_config->b_info.device_model = guest_config->b_info.device_model; - dm_config.b_info.extra = guest_config->b_info.extra; - dm_config.b_info.extra_pv = guest_config->b_info.extra_pv; - dm_config.b_info.extra_hvm = guest_config->b_info.extra_hvm; + dm_config->b_info.extra = guest_config->b_info.extra; + dm_config->b_info.extra_pv = guest_config->b_info.extra_pv; + dm_config->b_info.extra_hvm = guest_config->b_info.extra_hvm; - dm_config.disks = guest_config->disks; - dm_config.num_disks = guest_config->num_disks; + dm_config->disks = guest_config->disks; + dm_config->num_disks = guest_config->num_disks; - dm_config.vifs = guest_config->vifs; - dm_config.num_vifs = guest_config->num_vifs; + dm_config->vifs = guest_config->vifs; + dm_config->num_vifs = guest_config->num_vifs; - ret =libxl__domain_create_info_setdefault (gc, &dm_config.c_info); + ret =libxl__domain_create_info_setdefault (gc, &dm_config->c_info);if (ret) goto out; - ret =libxl__domain_build_info_setdefault (gc, &dm_config.b_info); + ret =libxl__domain_build_info_setdefault (gc, &dm_config->b_info);if (ret) goto out;libxl__vfb_and_vkb_from_hvm_guest_config (gc, guest_config, &vfb, &vkb); - dm_config.vfbs = &vfb; - dm_config.num_vfbs =1 ; - dm_config.vkbs = &vkb; - dm_config.num_vkbs =1 ; + dm_config->vfbs = &vfb; + dm_config->num_vfbs =1 ; + dm_config->vkbs = &vkb; + dm_config->num_vkbs =1 ;/* fixme: this function can leak the stubdom if it fails */ dm_domid =0 ; - ret =libxl__domain_make (gc, &dm_config.c_info, &dm_domid); + ret =libxl__domain_make (gc, &dm_config->c_info, &dm_domid);if (ret) goto out; - ret =libxl__domain_build (gc, &dm_config.b_info, dm_domid, &stubdom_state); + ret =libxl__domain_build (gc, &dm_config->b_info, dm_domid, stubdom_state);if (ret) goto out;@@ -788,20 +788,20 @@ retry_transaction:if (errno ==EAGAIN ) goto retry_transaction; -for (i =0 ; i < dm_config.num_disks; i++) { - ret =libxl_device_disk_add (ctx, dm_domid, &dm_config.disks[i]); +for (i =0 ; i < dm_config->num_disks; i++) { + ret =libxl_device_disk_add (ctx, dm_domid, &dm_config->disks[i]);if (ret) goto out_free; } -for (i =0 ; i < dm_config.num_vifs; i++) { - ret =libxl_device_nic_add (ctx, dm_domid, &dm_config.vifs[i]); +for (i =0 ; i < dm_config->num_vifs; i++) { + ret =libxl_device_nic_add (ctx, dm_domid, &dm_config->vifs[i]);if (ret) goto out_free; } - ret =libxl_device_vfb_add (ctx, dm_domid, &dm_config.vfbs[0 ]); + ret =libxl_device_vfb_add (ctx, dm_domid, &dm_config->vfbs[0 ]);if (ret) goto out_free; - ret =libxl_device_vkb_add (ctx, dm_domid, &dm_config.vkbs[0 ]); + ret =libxl_device_vkb_add (ctx, dm_domid, &dm_config->vkbs[0 ]);if (ret) goto out_free;@@ -845,14 +845,14 @@ retry_transaction:break ; } ret =libxl__device_console_add (gc, dm_domid, &console[i], - i ==STUBDOM_CONSOLE_LOGGING ? &stubdom_state :NULL ); + i ==STUBDOM_CONSOLE_LOGGING ? stubdom_state :NULL );if (ret) goto out_free; }if (libxl__create_xenpv_qemu (gc, dm_domid, - &dm_config, - &stubdom_state, + dm_config, + stubdom_state, &dm_starting) <0 ) { ret =ERROR_FAIL ; goto out_free; --1.7.2.5
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
PATCH v7 17/24 libxl: ao: convert libxl__spawn_*
In reply to Ian Jacksonlibxl__spawn_spawn becomes a callback-style asynchronous function. The implementation is now in terms of libxl__ev_* including libxl_ev_child.
All the callers need to be updated. This includes the device model spawning functions libxl__create_device_model and libxl__create_stubdom; these are replaced with libxl__spawn_local_dm and libxl__spawn_stubdom. libxl__confirm_device_model_startup is abolished; instead the dm spawner calls back.
(The choice of which kind of device model to create is lifted out of what used to be libxl__create_device_model, because that function was indirectly recursive. Recursive callback-style operations are clumsy because they require a pointer indirection for the nested states.)
Waiting for proper device model startup it is no longer notionally optional. Previously the code appeared to tolerate this by passing NULL for various libxl__spawner_starting* parameters to device model spawners. However, this was not used anywhere.
Conversely, the "for_spawn" parameter to libxl__wait_for_offspring is no longer supported. It remains as an unused formal parameter to avoid updating, in this patch, all the call sites which pass NULL. libxl__wait_for_offspring is in any case itself an obsolete function, so this wrinkle will go away when its callers are updated to use the event system. Consequently libxl__spawn_check is also abolished.
The "console ready" callback also remains unchanged in this patch. The API for this needs to be reviewed in the context of the event series and its reentrancy restrictions documented.
Thus their callers need to be updated. These are the domain creation functions libxl_domain_create_new and _restore. These functions now take ao_hows, and have a private state structure.
However domain creation remains not completely converted to the event mechanism; in particular it runs the outward-facing function libxl_run_bootloader with a NULL ao_how, which is quite wrong. As it happens in the current code this is not a bug because none of the rest of the functionality surrounding the bootloader call will mind if the event loop is reentered in the middle of its execution.
The file-scope function libxl__set_fd_flag which was used by the previous spawn arrangements becomes unused and is removed; other places in libxl can use libxl_fd_set_nonblock and libxl_fd_set_cloexec, which of course remain.
--- tools/libxl/libxl.h | 14 ++- tools/libxl/libxl_create.c | 198 +++++++++++++++++++----- tools/libxl/libxl_dm.c | 219 +++++++++++++++----------- tools/libxl/libxl_exec.c | 354 +++++++++++++++++++++--------------------- tools/libxl/libxl_internal.h | 286 +++++++++++++++++++++++----------- tools/libxl/xl_cmdimpl.c | 6 +- 6 files changed, 677 insertions(+), 400 deletions(-)
tools/libxl/libxl.h +12 -2
@@ -465,8 +465,18 @@ int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */);/* domain related functions */ typedef int (*libxl_console_ready )(libxl_ctx *ctx,uint32_t domid,void *priv); -int libxl_domain_create_new (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid); -int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid,int restore_fd); +/* fixme-ao Need to review this API. If we keep it, the reentrancy +* properties need to be documented but they may turn out to be too +* awkward */ + +int libxl_domain_create_new (libxl_ctx *ctx,libxl_domain_config *d_config, +libxl_console_ready cb,void *priv,uint32_t *domid, +const libxl_asyncop_how *ao_how); +int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config, +libxl_console_ready cb,void *priv, +uint32_t *domid,int restore_fd, +const libxl_asyncop_how *ao_how); +void 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);
tools/libxl/libxl_create.c +156 -42
263 lines not on this page · raw message
tools/libxl/libxl_dm.c +130 -89
312 lines not on this page · raw message
tools/libxl/libxl_exec.c +178 -176
441 lines not on this page · raw message
tools/libxl/libxl_internal.h +198 -88
335 lines not on this page · raw message
tools/libxl/xl_cmdimpl.c +3 -3
@@ -1668,8 +1668,8 @@ start:if ( restore_file ) { ret =libxl_domain_create_restore (ctx, &d_config, - cb, &child_console_pid, - &domid, restore_fd); + cb, &child_console_pid, + &domid, restore_fd,0 );/* * On subsequent reboot etc we should create the domain, not * restore/migrate-receive it again.
@@ -1677,7 +1677,7 @@ start: restore_file =NULL ; }else { ret =libxl_domain_create_new (ctx, &d_config, - cb, &child_console_pid, &domid); + cb, &child_console_pid, &domid,0 ); }if ( ret ) goto error_out;
Signature · 1 line
1.7.2.5
Re: [PATCH 17/24] libxl: ao: convert libxl__spawn_*
Neither this patch nor the rest of the series seems to handle the long running nature of xc_domain_restore, is that expected at this stage?
We discussed a similar thing in the context of xc_domain_save, and I expect the required scaffolding (bumping an op over into a thread) will be the same on both sides?
Quoted 48 lines · Ian Jackson
libxl__spawn_spawnbecomes a callback-style asynchronous function. The implementation is now in terms of libxl__ev_* includinglibxl_ev_child.All the callers need to be updated. This includes the device model spawning functions
libxl__create_device_modelandlibxl__create_stubdom; these are replaced withlibxl__spawn_local_dmandlibxl__spawn_stubdom.libxl__confirm_device_model_startupis abolished; instead the dm spawner calls back.(The choice of which kind of device model to create is lifted out of what used to be
libxl__create_device_model, because that function was indirectly recursive. Recursive callback-style operations are clumsy because they require a pointer indirection for the nested states.)Waiting for proper device model startup it is no longer notionally optional. Previously the code appeared to tolerate this by passing NULL for various libxl__spawner_starting* parameters to device model spawners. However, this was not used anywhere.
Conversely, the "
for_spawn" parameter tolibxl__wait_for_offspringis no longer supported. It remains as an unused formal parameter to avoid updating, in this patch, all the call sites which pass NULL.libxl__wait_for_offspringis in any case itself an obsolete function, so this wrinkle will go away when its callers are updated to use the event system. Consequentlylibxl__spawn_checkis also abolished.The "console ready" callback also remains unchanged in this patch. The API for this needs to be reviewed in the context of the event series and its reentrancy restrictions documented.
Thus their callers need to be updated. These are the domain creation functions
libxl_domain_create_newand_restore. These functions now takeao_hows, and have a private state structure.However domain creation remains not completely converted to the event mechanism; in particular it runs the outward-facing function
libxl_run_bootloaderwith a NULLao_how, which is quite wrong. As it happens in the current code this is not a bug because none of the rest of the functionality surrounding the bootloader call will mind if the event loop is reentered in the middle of its execution.The file-scope function
libxl__set_fd_flagwhich was used by the previous spawn arrangements becomes unused and is removed; other places in libxl can uselibxl_fd_set_nonblockandlibxl_fd_set_cloexec, which of course remain.Signed-off-by Ian Jackson <[email protected]>
Quoted 8 lines
--- tools/libxl/libxl.h | 14 ++- tools/libxl/libxl_create.c | 198 +++++++++++++++++++----- tools/libxl/libxl_dm.c | 219 +++++++++++++++----------- tools/libxl/libxl_exec.c | 354 +++++++++++++++++++++--------------------- tools/libxl/libxl_internal.h | 286 +++++++++++++++++++++++----------- tools/libxl/xl_cmdimpl.c | 6 +- 6 files changed, 677 insertions(+), 400 deletions(-)
(nb: I actually skipped ahead and reviewed the libxl_internal.h change first so I could read the docs, if only diff could be taught such things ;-))
tools/libxl/libxl.h int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */); · line 470
Quoted 13 lines
tools/libxl/libxl.h +3
-2@@ -465,8 +465,18 @@ int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */);/* domain related functions */ typedef int (*libxl_console_ready )(libxl_ctx *ctx,uint32_t domid,void *priv); -int libxl_domain_create_new (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid); -int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid,int restore_fd); +/* fixme-ao Need to review this API. If we keep it, the reentrancy +* properties need to be documented but they may turn out to be too +* awkward */
The reentrancy concerns here relate to the "cb" or to something else?
[...]
Quoted 5 lines
tools/libxl/libxl_create.c +0
-0@@ -537,16 +537,40 @@ static int store_libxl_entry(libxl__gc *gc, uint32_t domid,
[...]
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, · line 670
Quoted 6 lines
tools/libxl/libxl_create.c +1
-0@@ -635,13 +667,13 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,libxl_device_vkb_add (ctx, domid, &vkb);libxl_device_vkb_dispose (&vkb); + dcs->dmss.guest_domid = domid;
dcs->dmss is part of a union with dcs->sdss. I'd rather this was done inside the if once we've committed to one or the other, IYSWIM.
Actually the hunk above (which I've trimmed already, sorry) also initialised dmss unconditionally.
(does sdss really not need guest_domid somewhere too? odd)
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 677
Quoted 7 lines
tools/libxl/libxl_create.c +6
-0+if (libxl_defbool_val (d_config->b_info.device_model_stubdomain)) +libxl__spawn_stubdom (egc, &dcs->sdss); +else +libxl__spawn_local_dm (egc, &dcs->dmss); +return ; +break ;
return then break? I think the break is redundant.
Quoted 14 lines
} case LIBXL_DOMAIN_TYPE_PV:tools/libxl/libxl_create.c +3
-1@@ -669,7 +701,9 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,libxl__device_console_dispose (&console);if (need_qemu) { -libxl__create_xenpv_qemu (gc, domid, d_config, state, &dm_starting); + dcs->dmss.guest_domid = domid; +libxl__spawn_local_dm (egc, &dcs->dmss); +return ; }break ; }
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 716
Quoted 6 lines
tools/libxl/libxl_create.c +2
-1@@ -678,17 +712,41 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, goto error_out; } -if (dm_starting) { +assert (!dcs->dmss.guest_domid); +domcreate_devmodel_started (egc, &dcs->dmss,0 );
This is actually logically the "else" of the preceding need_qemu if, since all the other paths return before they get here. I spent quite a while figuring out why the problem with the "return; break;" I mentioned above was an extra break and not the return. Might be clearer to have this in the else?
Quoted 11 lines
tools/libxl/libxl_create.c +11
-0+return ; + + error_out: +assert (ret); +domcreate_complete (egc, dcs, ret); +} + +static void domcreate_devmodel_started (libxl__egc *egc, +libxl__dm_spawn_state *dmss, +int ret) +{
[...]
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 791
Quoted 6 lines
tools/libxl/libxl_create.c +4
-1+} -return ret; +static void domcreate_complete (libxl__egc *egc, +libxl__domain_create_state *dcs, +int rc) {
{ should be on the next line.
Quoted 16 lines
tools/libxl/libxl_create.c +16
-0+STATE_AO_GC (dcs->ao); + +if (rc) { +if (dcs->guest_domid) { +int rc2 =libxl_domain_destroy (CTX , dcs->guest_domid); +if (rc2) +LOG (ERROR ,"unable to destroy domain %d following" +" failed creation" , dcs->guest_domid); + } + dcs->guest_domid =-1 ; + } + dcs->callback (egc, dcs, rc, dcs->guest_domid); +} + +/*----- application-facing domain creation interface -----*/ +
[...]
Quoted 27 lines
tools/libxl/libxl_dm.c +6
-7@@ -667,24 +667,28 @@ retry_transaction:return 0 ; } -static int libxl__create_stubdom (libxl__gc *gc, -int guest_domid, -libxl_domain_config *guest_config, -libxl__domain_build_state *d_state, -libxl__spawner_starting **starting_r) +static void spawn_stubdom_pvqemu_cb (libxl__egc *egc, +libxl__dm_spawn_state *stubdom_dmss, +int rc); + +void libxl__spawn_stubdom (libxl__egc *egc,libxl__stubdom_spawn_state *sdss) { +STATE_AO_GC (sdss->stubdom.spawn.ao);libxl_ctx *ctx =libxl__gc_owner (gc);int i, num_console =STUBDOM_SPECIAL_CONSOLES , ret;libxl__device_console *console; -libxl_domain_config dm_config[1 ];libxl_device_vfb vfb;libxl_device_vkb vkb; -libxl__domain_build_state stubdom_state[1 ];
tools/libxl/libxl_dm.c retry_transaction: · line 689
Quoted 10 lines
tools/libxl/libxl_dm.c +5
-2-uint32_t dm_domid;char **args;struct xs_permissions perm[2 ];xs_transaction_t t; -libxl__spawner_starting *dm_starting =0 ; + +/* convenience aliases */ +libxl_domain_config *dm_config = &sdss->stubdom_config; +libxl_domain_config *guest_config = sdss->stubdom.guest_config; +int guest_domid = sdss->stubdom.guest_domid;
const? Just in case someone tries to modify it? (maybe there are similar cases in some of the previous blocks like this, I didn't notice).
[...]
Quoted 4 lines
tools/libxl/libxl_exec.c +0
-0
[...]
Quoted 1 line
+/*----- spawn implementation -----*/
[...]
Quoted 7 lines
tools/libxl/libxl_exec.c +4
-0+int libxl__spawn_spawn (libxl__egc *egc,libxl__spawn_state *ss) { +STATE_AO_GC (ss->ao); +int r; +pid_t child;int status, rc;
tools/libxl/libxl_exec.c again: · line 292
Quoted 10 lines
tools/libxl/libxl_exec.c +9
-0+libxl__spawn_init (ss); + ss->ssd =libxl__zalloc (0 ,sizeof (*ss->ssd)); +libxl__ev_child_init (&ss->ssd->mid); + + rc =libxl__ev_time_register_rel (gc, &ss->timeout, + spawn_timeout, ss->timeout_ms); +if (rc) goto out_err; + rc =libxl__ev_xswatch_register (gc, &ss->xswatch, + spawn_watch_event, ss->xspath);
IIRC xspath is optional, does libxl__ev_xswatch_register DTWT with NULL?
Quoted 9 lines
tools/libxl/libxl_exec.c +6
-0+if (rc) goto out_err; + +pid_t middle =libxl__ev_child_fork (gc, &ss->ssd->mid, spawn_middle_death); +if (middle ==-1 ) { rc =ERROR_FAIL ; goto out_err; } + +if (middle) {/* parent */ return 1 ; }
[...]
Quoted 7 lines
tools/libxl/libxl_internal.h +0
-0@@ -840,75 +840,197 @@ _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, libxl_device_pci *pcidev, int num);
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 849
Quoted 10 lines
tools/libxl/libxl_internal.h +7
-1_hidden int libxl__device_pci_destroy_all(libxl__gc *gc, uint32_t domid); -/* xl_exec */ +/* +*----- spawn ----- +* +* Higher-level double-fork and separate detach eg as for device models +* +* Each libxl__spawn_state is in one of the conventional states +* Undefined, Idle, Active
Conventional here means "as per event generation" I assume.
[...]
Quoted 5 lines
tools/libxl/libxl_internal.h +0
-4/* -* libxl__spawn_spawn - Create a new process -* gc: allocation pool -* for_spawn: malloc'd pointer to libxl__spawn_starting (optional) -* what: string describing the spawned process
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 869
Quoted 10 lines
tools/libxl/libxl_internal.h +8
-2-* intermediate_hook: helper to record pid, such as libxl_spawner_record_pid -* hook_data: data to pass to the hook function +* libxl__spawn_spawn - Create a new process which will become daemonic +* Forks twice, to allow the child to detach entirely from the parent. +* +* We call the two generated processes the "middle child" (result of +* the first fork) and the "inner child" (result of the second fork +* which takes place in the middle child). +* +* The inner child must soon exit or exec. If must also soon exit or
It?
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 877
Quoted 8 lines
tools/libxl/libxl_internal.h +8
-0+* notify the parent of its successful startup by writing to the +* xenstore path xspath (or by other means). xspath may be 0 to +* indicate that only other means are being used. +* +* The user (in the parent) will be called back (confirm_cb) every +* time that xenstore path is modified. +* +* In both children, the ctx is not fully useable: gc and logging
usable
(apparently, I'm not convinced actually)
Quoted 15 lines
tools/libxl/libxl_internal.h +15
-0+* operations are OK, but operations on Xen and xenstore are not. +* (The restrictions are the same as those which apply to children +* made with libxl__ev_child_fork.) +* +* midproc_cb will be called in the middle child, with the pid of the +* inner child; this could for example record the pid. midproc_cb +* should be fast, and should return. It will be called (reentrantly) +* within libxl__spawn_init. +* +* failure_cb will be called in the parent on failure of the +* intermediate or final child; an error message will have been +* logged. +* +* confirm_cb and failure_cb will not be called reentrantly from +* within libxl__spawn_spawn.
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 900
Quoted 10 lines
tools/libxl/libxl_internal.h +4
-2+* +* what: string describing the spawned process, used for logging * * Logs errors. A copy of "what" is taken. * Return values: -* < 0 error, for_spawn need not be detached -* +1 caller is the parent, must call detach on *for_spawn eventually +* < 0 error, *spawn is now Idle and need not be detached +* +1 caller is the parent, *spawn is Active and must eventually be detached * 0 caller is now the inner child, should probably call libxl__exec
... or libxl_postfork_child_noexec.
Quoted 10 lines
tools/libxl/libxl_internal.h +3
-6-* Caller, may pass 0 for for_spawn, in which case no need to detach. +* +* The spawn state must be Undefined or Idle on entry. */ -_hidden int libxl__spawn_spawn(libxl__gc *gc, -libxl__spawn_starting *for_spawn, -const char *what, -void (*intermediate_hook)(void *for_spawn,pid_t innerchild), -void *hook_data); +_hidden int libxl__spawn_spawn(libxl__egc *egc, libxl__spawn_state *spawn);
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 911
Quoted 10 lines
tools/libxl/libxl_internal.h +5
-3/* -* libxl_spawner_record_pid - Record given pid in xenstore -* for_spawn: malloc'd pointer to libxl__spawn_starting (optional) -* innerchild: pid of the child +* libxl__spawn_detach - Detaches the daemonic child. +* +* Works by killing the intermediate process from spawn_spawn. +* After this function returns, failures of either child are no +* longer repaorted via failure_cb.
reported
[...]
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 1001
Quoted 3 lines
tools/libxl/libxl_internal.h +3
-0+/*----- device model creation -----*/ + +/* First layer; wraps libxl__spawn_spawn. */
The use of "First" here is terrifying to me as a reviewer ;-P
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 1009
Quoted 8 lines
tools/libxl/libxl_internal.h +8
-0+ +typedef struct libxl__dm_spawn_state libxl__dm_spawn_state ; + +typedef void libxl__dm_spawn_cb (libxl__egc *egc,libxl__dm_spawn_state *, +int rc/* if !0, error was logged */ ); + +struct libxl__dm_spawn_state { +/* mixed - ao must be initialised by user; rest is private: */
I see no ao here, you mean spawn.ao?
Quoted 7 lines
tools/libxl/libxl_internal.h +7
-0+libxl__spawn_state spawn; +/* filled in by user, must remain valid: */ +uint32_t guest_domid;/* domain being served */ +libxl_domain_config *guest_config; +libxl__domain_build_state *build_state;/* relates to guest_domid */ +libxl__dm_spawn_cb *callback; +};
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid,
Quoted 10 lines
tools/libxl/libxl_internal.h +8
-0+ +_hidden void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state*); + +/* Stubdoms. */ + +typedef struct { + /* mixed - user must fill in public parts only: */ + libxl__dm_spawn_state stubdom; /* will always remain the first member */
why? If you are playing casting tricks then you could use CONTAINER_OF.
tools/libxl/libxl_internal.h _hidden int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, · line 1033
Quoted 9 lines
tools/libxl/libxl_internal.h +9
-0+libxl__dm_spawn_cb *callback;/* called as callback(,&sdss->stubdom,) */ +/* private to libxl__spawn_stubdom: */ +libxl_domain_config stubdom_config; +libxl__domain_build_state stubdom_state; +libxl__dm_spawn_state pvqemu; +} libxl__stubdom_spawn_state; + +_hidden void libxl__spawn_stubdom(libxl__egc *egc, libxl__stubdom_spawn_state*); +
Ah, I see now what local_dm meant, it's the non-stubdom DM.
stubdom is a bit of an overloaded term (we have grub stubdoms, xenstore stubdoms etc too). stub_dm would be better.
Quoted 4 lines
tools/libxl/libxl_internal.h +0
-0/* * libxl__wait_for_offspring - Wait for child state @@ -941,31 +1063,6 @@ _hidden int libxl__wait_for_offspring(libxl__gc *gc,
[...]
Quoted 23 lines
tools/libxl/libxl_internal.h +19
-0@@ -1566,6 +1650,32 @@ _hidden void libxl__bootloader_init(libxl__bootloader_state *bl); _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st); +/*----- Domain creation -----*/ + +typedef struct libxl__domain_create_state libxl__domain_create_state ; + +typedef void libxl__domain_create_cb (libxl__egc *egc, +libxl__domain_create_state *, +int rc,uint32_t domid); + +struct libxl__domain_create_state { +/* filled in by user */ +libxl__ao *ao; +libxl_domain_config *guest_config; +int restore_fd; +libxl_console_ready console_cb; +void *console_cb_priv; +libxl__domain_create_cb *callback; +/* private to domain_create */ +int guest_domid; +libxl__domain_build_state build_state;
tools/libxl/libxl_internal.h _hidden void libxl__bootloader_init(libxl__bootloader_state *bl); · line 1681
Quoted 10 lines
tools/libxl/libxl_internal.h +7
-0+union { +libxl__dm_spawn_state dmss; +libxl__stubdom_spawn_state sdss; + }; +}; + +/* * Convenience macros. */
Right, back to the top to start on the implementation...
Re: [PATCH 17/24] libxl: ao: convert libxl__spawn_*
Thanks for the review.
Ian Campbell writes ("Re: [Xen-devel] [PATCH 17/24] libxl: ao: convert libxl__spawn_*"):
Quoted 2 lines
Neither this patch nor the rest of the series seems to handle the long running nature of
xc_domain_restore, is that expected at this stage?
This is a thorny problem.
Quoted 3 lines
We discussed a similar thing in the context of
xc_domain_save, and I expect the required scaffolding (bumping an op over into a thread) will be the same on both sides?
Yes.
The thread's activities will have to be severely restricted but I think that will be doable.
We should consider another alternative: spawning a copy of xc_save, like xend does.
Quoted 8 lines · Ian Jackson
Quoted 3 lines
libxl__spawn_spawnbecomes a callback-style asynchronous function. The implementation is now in terms of libxl__ev_* includinglibxl_ev_child.(nb: I actually skipped ahead and reviewed the
libxl_internal.hchange first so I could read the docs, if only diff could be taught such things ;-))
Quite.
Quoted 8 lines
tools/libxl/libxl.h int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */); · line 470
Quoted 6 lines
typedef int (*libxl_console_ready)(libxl_ctx *ctx,
uint32_tdomid, void *priv);tools/libxl/libxl.h +3
-2-int libxl_domain_create_new (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid); -int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid,int restore_fd); +/* fixme-ao Need to review this API. If we keep it, the reentrancy +* properties need to be documented but they may turn out to be too +* awkward */ The reentrancy concerns here relate to the "cb" or to something else?
To the cb. This is in fact fixed later in the series.
Quoted 11 lines
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, · line 670
Quoted 7 lines
tools/libxl/libxl_create.c +1
-0@@ -635,13 +667,13 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,libxl_device_vkb_add (ctx, domid, &vkb);libxl_device_vkb_dispose (&vkb); + dcs->dmss.guest_domid = domid;
dcs->dmssis part of a union withdcs->sdss. I'd rather this was done inside the if once we've committed to one or the other, IYSWIM.
Quoted 4 lines
Actually the hunk above (which I've trimmed already, sorry) also initialised dmss unconditionally.
(does sdss really not need
guest_domidsomewhere too? odd)
libxl__stubdom_spawn_state is a struct containing a libxl__dm_spawn_state ("stubdom") as its first member. So the sdss's domid is in sdss.stubdom.guest_domid, and because stubdom is first this is the same as dmss->guest_domid.
Maybe this needs a bigger comment ?
Quoted 5 lines
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 677
Quoted 3 lines
tools/libxl/libxl_create.c +2
-0+return ; +break ;return then break? I think the break is redundant.
Yes.
Quoted 9 lines
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 716
Quoted 3 lines
tools/libxl/libxl_create.c +2
-1-if (dm_starting) { +assert (!dcs->dmss.guest_domid); +domcreate_devmodel_started (egc, &dcs->dmss,0 );This is actually logically the "else" of the preceding
need_qemuif, since all the other paths return before they get here. I spent quite a while figuring out why the problem with the "return; break;" I mentioned above was an extra break and not the return. Might be clearer to have this in the else?
Yes, good idea.
Quoted 5 lines
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config, · line 791
Quoted 3 lines
tools/libxl/libxl_create.c +3
-0+static void domcreate_complete (libxl__egc *egc, +libxl__domain_create_state *dcs, +int rc) {{ should be on the next line.
Will fix.
Quoted 7 lines
tools/libxl/libxl_create.c
Quoted 4 lines
tools/libxl/libxl_create.c +4
-0+/* convenience aliases */ +libxl_domain_config *dm_config = &sdss->stubdom_config; +libxl_domain_config *guest_config = sdss->stubdom.guest_config; +int guest_domid = sdss->stubdom.guest_domid;const? Just in case someone tries to modify it? (maybe there are similar cases in some of the previous blocks like this, I didn't notice).
OK. (Yes, there are a couple of other similar blocks.)
Quoted 4 lines
tools/libxl/libxl_create.c
Quoted 2 lines
tools/libxl/libxl_create.c +2
-0+ rc =libxl__ev_xswatch_register (gc, &ss->xswatch, + spawn_watch_event, ss->xspath);IIRC xspath is optional, does
libxl__ev_xswatch_registerDTWT with NULL?
No, it would crash.
xspath is no longer optional. There can be no correct callers who don't arrange to be notified by their demonic child that it has started up, and the only current callers use xenstore for this.
Quoted 10 lines
tools/libxl/libxl_create.c
Quoted 8 lines
tools/libxl/libxl_create.c +7
-1-/* xl_exec */ +/* +*----- spawn ----- +* +* Higher-level double-fork and separate detach eg as for device models +* +* Each libxl__spawn_state is in one of the conventional states +* Undefined, Idle, Active Conventional here means "as per event generation" I assume.
Yes.
Quoted 3 lines
Quoted 1 line
+ * The inner child must soon exit or exec. If must also soon exit or
It?
Yes.
Quoted 5 lines
Quoted 1 line
+ * In both children, the ctx is not fully useable: gc and logging
usable
(apparently, I'm not convinced actually)
I always think "useable" is better but the rest of the code uses "usable" elsewhere so I guess here should too.
Quoted 3 lines
Quoted 1 line
+ * longer repaorted via
failure_cb.reported
Will fix.
Quoted 7 lines
[...]
tools/libxl/libxl_create.c
Quoted 3 lines
tools/libxl/libxl_create.c +3
-0+/*----- device model creation -----*/ + +/* First layer; wraps libxl__spawn_spawn. */ The use of "First" here is terrifying to me as a reviewer ;-P
Sorry ...
Quoted 4 lines
tools/libxl/libxl_create.c
Quoted 2 lines
tools/libxl/libxl_create.c +2
-0+struct libxl__dm_spawn_state { +/* mixed - ao must be initialised by user; rest is private: */ I see no ao here, you mean spawn.ao?
Yes. I have clarified this.
Quoted 7 lines
tools/libxl/libxl_create.c
Quoted 5 lines
tools/libxl/libxl_create.c +5
-0+/* Stubdoms. */ + +typedef struct { + /* mixed - user must fill in public parts only: */ + libxl__dm_spawn_state stubdom; /* will always remain the first member */why? If you are playing casting tricks then you could use
CONTAINER_OF.
See above.
Quoted 7 lines
tools/libxl/libxl_create.c
Quoted 2 lines
tools/libxl/libxl_create.c +2
-0+_hidden void libxl__spawn_stubdom(libxl__egc *egc, libxl__stubdom_spawn_state*); +Ah, I see now what
local_dmmeant, it's the non-stubdom DM.stubdom is a bit of an overloaded term (we have grub stubdoms, xenstore stubdoms etc too).
stub_dmwould be better.
Do you think I should s/stubdom/stubdm/ or something ?
Quoted 5 lines
Quoted 3 lines
/*
* Convenience macros.
*/Right, back to the top to start on the implementation...
There's no requirement to quote the patch in the order it appeared. You can rearrange in your email...
Ian.
Re: [PATCH 17/24] libxl: ao: convert libxl__spawn_*
Quoted 12 lines · Ian Jackson
Thanks for the review.
Ian Campbell writes ("Re: [Xen-devel] [PATCH 17/24] libxl: ao: convert libxl__spawn_*"):
Quoted 2 lines
Neither this patch nor the rest of the series seems to handle the long running nature of
xc_domain_restore, is that expected at this stage?This is a thorny problem.
Quoted 3 lines
We discussed a similar thing in the context of
xc_domain_save, and I expect the required scaffolding (bumping an op over into a thread) will be the same on both sides?
Quoted 7 lines
Yes.
The thread's activities will have to be severely restricted but I think that will be doable.
We should consider another alternative: spawning a copy of
xc_save, like xend does.
I wondered about that too. Does it make things like error handling or reporting any more difficult?
Quoted 10 lines
Quoted 8 lines
tools/libxl/libxl.h int libxl_ctx_free(libxl_ctx *ctx /* 0 is OK */); · line 470
Quoted 6 lines
typedef int (*libxl_console_ready)(libxl_ctx *ctx,
uint32_tdomid, void *priv);tools/libxl/libxl.h +3
-2-int libxl_domain_create_new (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid); -int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config,libxl_console_ready cb,void *priv,uint32_t *domid,int restore_fd); +/* fixme-ao Need to review this API. If we keep it, the reentrancy +* properties need to be documented but they may turn out to be too +* awkward */ The reentrancy concerns here relate to the "cb" or to something else?
To the cb. This is in fact fixed later in the series.
Great!
Quoted 14 lines
Quoted 14 lines
tools/libxl/libxl_create.c static int do_domain_create(libxl__gc *gc, · line 670
Quoted 7 lines
tools/libxl/libxl_create.c +1
-0@@ -635,13 +667,13 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,libxl_device_vkb_add (ctx, domid, &vkb);libxl_device_vkb_dispose (&vkb); + dcs->dmss.guest_domid = domid;
dcs->dmssis part of a union withdcs->sdss. I'd rather this was done inside the if once we've committed to one or the other, IYSWIM.Actually the hunk above (which I've trimmed already, sorry) also initialised dmss unconditionally.
Quoted 8 lines
Quoted 1 line
(does sdss really not need
guest_domidsomewhere too? odd)
libxl__stubdom_spawn_stateis a struct containing alibxl__dm_spawn_state("stubdom") as its first member. So the sdss's domid is in sdss.stubdom.guest_domid, and because stubdom is first this is the same asdmss->guest_domid.Maybe this needs a bigger comment ?
At the very least, yes.
Does combining thing in a union in this way really make some other bit of code look substantially better? Not having the union and having a shared libxl__dm_spawn_state in the parent struct seems more straight forward at least from here.
Quoted 8 lines
Quoted 4 lines
tools/libxl/libxl_create.c
Quoted 2 lines
tools/libxl/libxl_create.c +2
-0+ rc =libxl__ev_xswatch_register (gc, &ss->xswatch, + spawn_watch_event, ss->xspath);IIRC xspath is optional, does
libxl__ev_xswatch_registerDTWT with NULL?No, it would crash.
xspath is no longer optional.
So this comment on libxl__spawn_spawn is wrong?
Quoted 8 lines
+ * The inner child must soon exit or exec. If must also soon exit or
+ * notify the parent of its successful startup by writing to the
+ * xenstore path xspath (or by other means). xspath may be 0 to
+ * indicate that only other means are being used.There can be no correct callers who
don't arrange to be notified by their demonic child that it has started up, and the only current callers use xenstore for this.
Given that the callers and the code agree and the comment disagrees I think you could just nuke that comment (or replace it with one requiring non-NULL).
Quoted 15 lines
Quoted 7 lines
tools/libxl/libxl_create.c
Quoted 5 lines
tools/libxl/libxl_create.c +5
-0+/* Stubdoms. */ + +typedef struct { + /* mixed - user must fill in public parts only: */ + libxl__dm_spawn_state stubdom; /* will always remain the first member */why? If you are playing casting tricks then you could use
CONTAINER_OF.See above.
Quoted 5 lines
tools/libxl/libxl_create.c
Quoted 2 lines
tools/libxl/libxl_create.c +2
-0+_hidden void libxl__spawn_stubdom(libxl__egc *egc, libxl__stubdom_spawn_state*); +Ah, I see now what
local_dmmeant, it's the non-stubdom DM.
Quoted 4 lines
Quoted 2 lines
stubdom is a bit of an overloaded term (we have grub stubdoms, xenstore stubdoms etc too).
stub_dmwould be better.Do you think I should s/stubdom/stubdm/ or something ?
yes, or stub_dm for consistency with local_dm. I'd like to eradicate the bare use of the term "stubdom" since it can mean several things (admittedly not really in this context). I suspect I am fighting against the tide here though...
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
/*
* Convenience macros.
*/Right, back to the top to start on the implementation...
There's no requirement to quote the patch in the order it appeared. You can rearrange in your email...
Yeah, I was just lazy ;-)
Ian.
Re: [PATCH 17/24] libxl: ao: convert libxl__spawn_*
Ian Campbell writes ("Re: [Xen-devel] [PATCH 17/24] libxl: ao: convert libxl__spawn_*"):
Quoted 6 lines · Ian Jackson
Quoted 2 lines
We should consider another alternative: spawning a copy of
xc_save, like xend does.I wondered about that too. Does it make things like error handling or reporting any more difficult?
With threading it's quite tricky. I think it would be rude to call even the application's logging callbacks on a private thread. Certainly we can't easily propagate errors from that private thread. We would have to arrange somehow to transfer the results to one of the application's threads, to avoid possibly calling back to the application on our private thread (which is a big no-no because it might subject a non-multithreaded application to reentrancy). And even with all that there are vexed problems like the possibility of generating an application-wide SIGPIPE on the migration fd.
So I think it would make it easier, now that we have all the machinery in place, to spawn a separate process. That process should exec, even if the thing exec'd is a utility mostly using libxl, firstly to save memory (in case we're talking about a huge toolstack daemon) and also so we don't have to worry about nonconsensually generating long-running non-execing forks of the application (which would require us to provide a callback mirror of the postfork noexec downcall).
Quoted 5 lines
Quoted 5 lines
libxl__stubdom_spawn_stateis a struct containing alibxl__dm_spawn_state("stubdom") as its first member. So the sdss's domid is in sdss.stubdom.guest_domid, and because stubdom is first this is the same asdmss->guest_domid.
Quoted 8 lines
Quoted 1 line
Maybe this needs a bigger comment ?
At the very least, yes.
Does combining thing in a union in this way really make some other bit of code look substantially better? Not having the union and having a shared
libxl__dm_spawn_statein the parent struct seems more straight forward at least from here.
I will see if there is a better way to do this, perhaps without the union. And try to add more comments.
Quoted 7 lines
Quoted 1 line
xspath is no longer optional.
So this comment on
libxl__spawn_spawnis wrong?Quoted 4 lines
+ * The inner child must soon exit or exec. If must also soon exit or
+ * notify the parent of its successful startup by writing to the
+ * xenstore path xspath (or by other means). xspath may be 0 to
+ * indicate that only other means are being used.
Yes. It's out of date. We don't have any processes which do this other than with xenstore. If we introduce them we can make xspath maybe be 0. I've deleted the erroneous comment (and fixed the preceding sentence).
Quoted 6 lines
Quoted 1 line
Do you think I should s/stubdom/stubdm/ or something ?
yes, or
stub_dmfor consistency withlocal_dm. I'd like to eradicate the bare use of the term "stubdom" since it can mean several things (admittedly not really in this context). I suspect I am fighting against the tide here though...
I see your point and will see what I can do.
Ian.
Re: [PATCH 17/24] libxl: ao: convert libxl__spawn_*
Quoted 18 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH 17/24] libxl: ao: convert libxl__spawn_*"):
Quoted 6 lines · Ian Jackson
Quoted 2 lines
We should consider another alternative: spawning a copy of
xc_save, like xend does.I wondered about that too. Does it make things like error handling or reporting any more difficult?
With threading it's quite tricky. I think it would be rude to call even the application's logging callbacks on a private thread. Certainly we can't easily propagate errors from that private thread. We would have to arrange somehow to transfer the results to one of the application's threads, to avoid possibly calling back to the application on our private thread (which is a big no-no because it might subject a non-multithreaded application to reentrancy). And even with all that there are vexed problems like the possibility of generating an application-wide SIGPIPE on the migration fd.
Quoted 7 lines
So I think it would make it easier, now that we have all the machinery in place, to spawn a separate process. That process should exec, even if the thing exec'd is a utility mostly using libxl, firstly to save memory (in case we're talking about a huge toolstack daemon) and also so we don't have to worry about nonconsensually generating long-running non-execing forks of the application (which would require us to provide a callback mirror of the postfork noexec downcall).
This sounds sensible to me.
Ian.
Quoted 41 lines
Quoted 6 lines
Quoted 6 lines
libxl__stubdom_spawn_stateis a struct containing alibxl__dm_spawn_state("stubdom") as its first member. So the sdss's domid is in sdss.stubdom.guest_domid, and because stubdom is first this is the same asdmss->guest_domid.Quoted 8 lines
Quoted 1 line
Maybe this needs a bigger comment ?
At the very least, yes.
Does combining thing in a union in this way really make some other bit of code look substantially better? Not having the union and having a shared
libxl__dm_spawn_statein the parent struct seems more straight forward at least from here.I will see if there is a better way to do this, perhaps without the union. And try to add more comments.
Quoted 7 lines
Quoted 1 line
xspath is no longer optional.
So this comment on
libxl__spawn_spawnis wrong?Quoted 4 lines
+ * The inner child must soon exit or exec. If must also soon exit or
+ * notify the parent of its successful startup by writing to the
+ * xenstore path xspath (or by other means). xspath may be 0 to
+ * indicate that only other means are being used.Yes. It's out of date. We don't have any processes which do this other than with xenstore. If we introduce them we can make xspath maybe be 0. I've deleted the erroneous comment (and fixed the preceding sentence).
Quoted 6 lines
Quoted 1 line
Do you think I should s/stubdom/stubdm/ or something ?
yes, or
stub_dmfor consistency withlocal_dm. I'd like to eradicate the bare use of the term "stubdom" since it can mean several things (admittedly not really in this context). I suspect I am fighting against the tide here though...I see your point and will see what I can do.
Ian.
PATCH v7 18/24 libxl: make libxl_create run bootloader via callback
In reply to Ian JacksonChange initiate_domain_create to properly use libxl__bootloader_run rather than improperly calling libxl_run_bootloader with NULL ao_how.
Changes since v6:
* Bugfixes from testing.
--- tools/libxl/libxl_create.c | 52 ++++++++++++++++++++++++++++++++--------- tools/libxl/libxl_internal.h | 1 + 2 files changed, 41 insertions(+), 12 deletions(-)
tools/libxl/libxl_create.c +40 -12
@@ -550,6 +550,9 @@ static int store_libxl_entry(libxl__gc *gc, uint32_t domid,static void domcreate_devmodel_started (libxl__egc *egc,libxl__dm_spawn_state *dmss,int rc); +static void domcreate_bootloader_done (libxl__egc *egc, +libxl__bootloader_state *bl, +int rc);/* Our own function to clean up and call the user's callback. * The final call in the sequence. */
@@ -570,6 +573,7 @@ static void initiate_domain_create(libxl__egc *egc,int restore_fd = dcs->restore_fd;libxl_console_ready cb = dcs->console_cb;void *priv = dcs->console_cb_priv; +memset (&dcs->build_state,0 ,sizeof (dcs->build_state)); domid =0 ;
@@ -599,21 +603,44 @@ static void initiate_domain_create(libxl__egc *egc,if (ret) goto error_out; } + dcs->bl.ao = ao;libxl_device_disk *bootdisk = d_config->num_disks >0 ? &d_config->disks[0 ] :NULL ;if (restore_fd <0 && bootdisk) { - ret =libxl_run_bootloader (ctx, &d_config->b_info, bootdisk, domid, -0 /* fixme-ao */ ); -if (ret) { -LIBXL__LOG (ctx,LIBXL__LOG_ERROR , -"failed to run bootloader: %d" , ret); - goto error_out; - } + dcs->bl.callback = domcreate_bootloader_done; + dcs->bl.info = &d_config->b_info, + dcs->bl.disk = bootdisk; + dcs->bl.domid = dcs->guest_domid; + +libxl__bootloader_run (egc, &dcs->bl); + }else { +domcreate_bootloader_done (egc, &dcs->bl,0 ); } +return ; -memset (&dcs->build_state,0 ,sizeof (dcs->build_state)); +error_out: +assert (ret); +domcreate_complete (egc, dcs, ret); +} + +static void domcreate_bootloader_done (libxl__egc *egc, +libxl__bootloader_state *bl, +int ret) +{ +libxl__domain_create_state *dcs =CONTAINER_OF (bl, *dcs, bl); +STATE_AO_GC (bl->ao); +int i; + +/* convenience aliases */ +uint32_t domid = dcs->guest_domid; +libxl_domain_config *d_config = dcs->guest_config; +int restore_fd = dcs->restore_fd;libxl__domain_build_state *state = &dcs->build_state; +libxl_ctx *ctx =CTX ; + +if (ret) goto error_out; + dcs->dmss.spawn.ao = ao; dcs->dmss.guest_config = dcs->guest_config; dcs->dmss.build_state = &dcs->build_state;
@@ -764,12 +791,13 @@ static void domcreate_devmodel_started(libxl__egc *egc,if (d_config->c_info.type ==LIBXL_DOMAIN_TYPE_PV &&libxl_defbool_val (d_config->b_info.u.pv.e820_host)) { -int rc; - rc =libxl__e820_alloc (gc, domid, d_config); -if (rc) + ret =libxl__e820_alloc (gc, domid, d_config); +if (ret) {LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"Failed while collecting E820 with: %d (errno:%d)\n" , - rc, errno); + ret, errno); + goto error_out; + } } if ( cb && (d_config->c_info.type == LIBXL_DOMAIN_TYPE_HVM || (d_config->c_info.type == LIBXL_DOMAIN_TYPE_PV &&
tools/libxl/libxl_internal.h +1 -0
@@ -1669,6 +1669,7 @@ struct libxl__domain_create_state {/* private to domain_create */ int guest_domid;libxl__domain_build_state build_state; +libxl__bootloader_state bl;union {libxl__dm_spawn_state dmss;libxl__stubdom_spawn_state sdss;
Signature · 1 line
1.7.2.5
Re: [PATCH 18/24] libxl: make libxl_create run bootloader via callback
Quoted 4 lines · Ian Jackson
Change
initiate_domain_createto properly uselibxl__bootloader_runrather than improperly callinglibxl_run_bootloaderwith NULLao_how.Signed-off-by Ian Jackson <[email protected]>
[...]
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 640
Quoted 6 lines
tools/libxl/libxl_create.c +5
-0+/* convenience aliases */ +uint32_t domid = dcs->guest_domid; +libxl_domain_config *d_config = dcs->guest_config; +int restore_fd = dcs->restore_fd;libxl__domain_build_state *state = &dcs->build_state; +libxl_ctx *ctx =CTX ;
I commented on a previous patch about const in these blocks of "convenience aliases" and I think you were going to scope them all out, but since there has been a bit of a gap in my review of this series I might as well mention it again.
Ian.
Re: [PATCH 18/24] libxl: make libxl_create run bootloader via callback
Ian Campbell writes ("Re: [Xen-devel] [PATCH 18/24] libxl: make libxl_create run bootloader via callback"):
Quoted 7 lines · Ian Jackson
Quoted 4 lines
Change
initiate_domain_createto properly uselibxl__bootloader_runrather than improperly callinglibxl_run_bootloaderwith NULLao_how.Signed-off-by Ian Jackson <[email protected]>Acked-by Ian Campbell <[email protected]>
Thanks.
Quoted 8 lines
[...]
tools/libxl/libxl_create.c static void initiate_domain_create(libxl__egc *egc, · line 640
Quoted 6 lines
tools/libxl/libxl_create.c +5
-0+/* convenience aliases */ +uint32_t domid = dcs->guest_domid; +libxl_domain_config *d_config = dcs->guest_config; +int restore_fd = dcs->restore_fd;libxl__domain_build_state *state = &dcs->build_state; +libxl_ctx *ctx =CTX ;
Quoted 4 lines
I commented on a previous patch about const in these blocks of "convenience aliases" and I think you were going to scope them all out, but since there has been a bit of a gap in my review of this series I might as well mention it again.
I will arrange to constify them all.
Ian.
PATCH v7 19/24 libxl: provide progress reporting for long-running operations
In reply to Ian JacksonThis will be used for reporting, during domain creation, that the console is ready.
--- tools/libxl/libxl.h | 45 +++++++++++++++ tools/libxl/libxl_event.c | 122 ++++++++++++++++++++++++++++++++---------- tools/libxl/libxl_internal.h | 28 ++++++++++ 3 files changed, 167 insertions(+), 28 deletions(-)
tools/libxl/libxl.h +45 -0
@@ -435,6 +435,51 @@ typedef struct { } u; } libxl_asyncop_how; +/* +* Some more complex asynchronous operations can report intermediate +* progress. How this is to be reported is controlled, for each +* function, by a parameter +* libxl_asyncprogress_how *aop_FOO_how; +* for each kind of progress FOO supported by that function. Each +* such kind of progress is associated with an event type. +* +* The function description will document whether, when, and how +* many times, the intermediate progress will be reported, and +* what the corresponding event type(s) are. +* +* If aop_FOO_how==NULL, intermediate progress reports are discarded. +* +* If aop_FOO_how->callback==NULL, intermediate progress reports +* generate libxl events which can be obtained from libxl_event_wait +* or libxl_event_check. +* +* If aop_FOO_how->callback!=NULL, libxl will report intermediate +* progress by calling callback(ctx, &event, for_callback). +* +* The rules for these events are otherwise the same as those for +* ordinary events. The reentrancy and threading rules for the +* callback are the same as those for ao completion callbacks. +* +* Note that the callback, if provided, is responsible for freeing +* the event. +* +* If callbacks are requested, they will be made, and returned, before +* the long-running libxl operation is considered finished (so if the +* long-running libxl operation was invoked with ao_how==NULL then any +* callbacks will occur strictly before the long-running operation +* returns). However, the callbacks may occur on any thread. +* +* In general, otherwise, no promises are made about the relative +* order of callbacks in a multithreaded program. In particular +* different callbacks relating to the same long-running operation may +* be delivered out of order. +*/ + +typedef struct { +void (*callback)(libxl_ctx *ctx,libxl_event *,void *for_callback); +libxl_ev_user for_event;/* always used */ +void *for_callback;/* passed to callback */ +}libxl_asyncprogress_how ;#define LIBXL_VERSION 0
tools/libxl/libxl_event.c +94 -28
158 lines not on this page · raw message
tools/libxl/libxl_internal.h +28 -0
@@ -118,6 +118,7 @@ _hidden void libxl__log(libxl_ctx *ctx, xentoollog_level msglevel, int errnoval,typedef struct libxl__gc libxl__gc ;typedef struct libxl__egc libxl__egc ;typedef struct libxl__ao libxl__ao ; +typedef struct libxl__aop_occurred libxl__aop_occurred ;void libxl__alloc_failed (libxl_ctx *,const char *func,size_t nmemb,size_t size) __attribute__((noreturn));
@@ -372,6 +373,14 @@ struct libxl__egc {struct libxl__gc gc;struct libxl__event_list occurred_for_callback; LIBXL_TAILQ_HEAD(, libxl__ao) aos_for_callback; + LIBXL_TAILQ_HEAD(, libxl__aop_occurred) aops_for_callback; +}; + +struct libxl__aop_occurred { +LIBXL_TAILQ_ENTRY (libxl__aop_occurred) entry; +libxl__ao *ao; +libxl_event *ev; +const libxl_asyncprogress_how *how; };#define LIBXL__AO_MAGIC 0xA0FACE00ul
@@ -380,6 +389,7 @@ struct libxl__egc {struct libxl__ao {uint32_t magic;unsigned constructing:1 , in_initiator:1 , complete:1 , notified:1 ; +int progress_reports_outstanding;int rc;libxl__gc gc;libxl_asyncop_how how;
@@ -1369,6 +1379,7 @@ libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);LIBXL_INIT_GC ((egc).gc,ctx); \LIBXL_TAILQ_INIT (&(egc).occurred_for_callback); \LIBXL_TAILQ_INIT (&(egc).aos_for_callback); \ +LIBXL_TAILQ_INIT (&(egc).aops_for_callback); \ }while (0 ) _hidden void libxl__egc_cleanup(libxl__egc *egc);
@@ -1415,6 +1426,9 @@ _hidden void libxl__egc_cleanup(libxl__egc *egc);* pointer to the internal event generation request routines * libxl__evgen_FOO, so that at some point a CALLBACK will be * made when the operation is complete. +* - if the operation provides progress reports, the aop_how(s) +* must be copied into the per-operation structure using +* libxl__ao_progress_gethow. * * - If initiation is successful, the initiating function needs * to run libxl__ao_inprogress right before unlocking and
@@ -1424,6 +1438,10 @@ _hidden void libxl__egc_cleanup(libxl__egc *egc);* call libxl__ao_abort before unlocking and returning whatever * error code is appropriate (AO_ABORT macro). * +* - If the operation supports progress reports, it may generate +* suitable events with NEW_EVENT and report them with +* libxl__ao_progress_report (with the ctx locked). +* * - Later, some callback function, whose callback has been requested * directly or indirectly, should call libxl__ao_complete (with the * ctx locked, as it will generally already be in any event callback
@@ -1479,8 +1497,18 @@ _hidden int libxl__ao_inprogress(libxl__ao *ao); /* temporarily unlocks */ _hidden void libxl__ao_abort(libxl__ao *ao); _hidden void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc); +/* Can be called at any time. Use is essential for any aop user. */ +_hidden void libxl__ao_progress_gethow(libxl_asyncprogress_how *in_state, +const libxl_asyncprogress_how *from_app); + +/* Must be called with the ctx locked. Will fill in ev->for_user, +* so caller need not do that. */ +_hidden void libxl__ao_progress_report(libxl__egc *egc, libxl__ao *ao, +const libxl_asyncprogress_how *how,libxl_event *ev/* consumed */ ); +/* For use by ao machinery ONLY */ _hidden void libxl__ao__destroy(libxl_ctx*, libxl__ao *ao); +_hidden void libxl__ao_complete_check_progress_reports(libxl__egc*, libxl__ao*);/*
Signature · 1 line
1.7.2.5
Re: [PATCH 19/24] libxl: provide progress reporting for long-running operations
Quoted 2 lines · Ian Jackson
This will be used for reporting, during domain creation, that the console is ready.
I think of progress as being 1%, 2%, 3%...10% etc type stuff. I guess progress in the sense you mean here could be thought of as "milestones"?
Quoted 5 lines
tools/libxl/libxl_event.c +0
-0
tools/libxl/libxl_event.c static void egc_run_callbacks(libxl__egc *egc) · line 907
Quoted 9 lines
tools/libxl/libxl_event.c +1
-0@@ -899,12 +899,25 @@ static void egc_run_callbacks(libxl__egc *egc) {EGC_GC ;libxl_event *ev, *ev_tmp; +libxl__aop_occurred *aop, *aop_tmp; LIBXL_TAILQ_FOREACH_SAFE(ev, &egc->occurred_for_callback, link, ev_tmp) {LIBXL_TAILQ_REMOVE (&egc->occurred_for_callback, ev, link);CTX ->event_hooks->event_occurs (CTX ->event_hooks_user, ev); }
Are the BSD FOREACH_SAFE functions safe against manipulation from other threads?
I only ask because Stefano was surprised that this wasn't the case for the Linux macros, in that context "SAFE" just means you can delete the element in this thread (like you do here) but that if another thread is also manipulating the same list.
Quoting Dan in<20120420113557.GJ27101@mwanda>:
Quoted 7 lines
It's safe against deletion in the same thread. But not against deletion from another thread.
At the beginning of the loop it stores a pointer to the next element. If you delete the element you are on, no problem because you already have a pointer to the next one. But if another thread deletes the next element, now you have a pointer which is wrong.
By my reading these macros suffer from the same and therefore a bunch more locking is needed. I hope I'm mistaken...
Quoted 28 lines
tools/libxl/libxl_event.c +13
-0+ LIBXL_TAILQ_FOREACH_SAFE(aop, &egc->aops_for_callback, entry, aop_tmp) { +LIBXL_TAILQ_REMOVE (&egc->aops_for_callback, aop, entry); + aop->how->callback (CTX , aop->ev, aop->how->for_callback); + +CTX_LOCK ; + aop->ao->progress_reports_outstanding--; +libxl__ao_complete_check_progress_reports (egc, aop->ao); +CTX_UNLOCK ; + +free (aop); + } +libxl__ao *ao, *ao_tmp;LIBXL_TAILQ_FOREACH_SAFE (ao, &egc->aos_for_callback, entry_for_callback, ao_tmp) {@@ -1285,6 +1298,7 @@ void libxl__ao_abort(libxl__ao *ao)assert (ao->magic ==LIBXL__AO_MAGIC );assert (ao->in_initiator);assert (!ao->complete); +assert (!ao->progress_reports_outstanding);libxl__ao__destroy (CTX , ao); }@@ -1295,6 +1309,23 @@ void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc) ao->complete =1 ; ao->rc = rc;
tools/libxl/libxl_event.c void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc) · line 1321
Quoted 10 lines
tools/libxl/libxl_event.c +10
-0+libxl__ao_complete_check_progress_reports (egc, ao); +} + +void libxl__ao_complete_check_progress_reports (libxl__egc *egc,libxl__ao *ao) +{ +/* We don't consider an ao complete if it has any outstanding +* callbacks. These callbacks might be outstanding on other +* threads, queued up in the other threads' egc's. Those threads +* will, after making the callback, take out the lock again, +* decrememt progress_reports_outstanding, and call us again.
decrement
Quoted 33 lines
tools/libxl/libxl_event.c +22
-0+*/ + +assert (ao->progress_reports_outstanding >=0 ); + +if (!ao->complete || ao->progress_reports_outstanding) +return ; +if (ao->poller) {assert (ao->in_initiator);if (!ao->constructing)@@ -1316,34 +1347,6 @@ void libxl__ao_complete(libxl__egc *egc, libxl__ao *ao, int rc)libxl__ao__destroy (libxl__gc_owner (&egc->gc), ao); }@@ -1401,6 +1404,69 @@ int libxl__ao_inprogress(libxl__ao *ao) } +/* progress reporting */ + +/* The application indicates a desire to ignore events by passing NULL +* for how. But we want to copy *how. So we have this dummy function +* whose address is stored in callback if the app passed how==NULL. */ +static void dummy_asyncprogress_callback_ignore + (libxl_ctx *ctx,libxl_event *ev,void *for_callback) { } + +void libxl__ao_progress_gethow (libxl_asyncprogress_how *in_state, +const libxl_asyncprogress_how *from_app) { +if (from_app) + *in_state = *from_app; +else + in_state->callback = dummy_asyncprogress_callback_ignore; +}
tools/libxl/libxl_event.c int libxl__ao_inprogress(libxl__ao *ao) · line 1431
Quoted 10 lines
tools/libxl/libxl_event.c +10
-0+ +void libxl__ao_progress_report (libxl__egc *egc,libxl__ao *ao, +const libxl_asyncprogress_how *how,libxl_event *ev) +{ + ev->for_user = how->for_event; +if (how->callback == dummy_asyncprogress_callback_ignore) { +/* ignore */ + }else if (how->callback) { +libxl__aop_occurred *aop =libxl__zalloc (0 ,sizeof (*aop)); + ao->progress_reports_outstanding++;
Locking for this increment happens in the caller? (later: found the comment which confirms this now).
tools/libxl/libxl_event.c int libxl__ao_inprogress(libxl__ao *ao) · line 1442
Quoted 11 lines
tools/libxl/libxl_event.c +11
-0+ aop->ao = ao; + aop->ev = ev; + aop->how = how; + }else { +libxl__event_occurred (egc, ev); + } +} + + +libxl__ao *libxl__ao_create (libxl_ctx *ctx,uint32_t domid, +const libxl_asyncop_how *how)
AFAICT this function has just moved and not changed, right?
Quoted 20 lines
tools/libxl/libxl_event.c +20
-0+{ +libxl__ao *ao; + + ao =calloc (1 ,sizeof (*ao)); +if (!ao) goto out; + + ao->magic =LIBXL__AO_MAGIC ; + ao->constructing =1 ; + ao->in_initiator =1 ; + ao->poller =0 ; + ao->domid = domid; +LIBXL_INIT_GC (ao->gc, ctx); + +if (how) { + ao->how = *how; + }else { + ao->poller =libxl__poller_get (ctx); +if (!ao->poller) goto out; + } +return ao;
tools/libxl/libxl_event.c int libxl__ao_inprogress(libxl__ao *ao) · line 1472
Quoted 10 lines
tools/libxl/libxl_event.c +7
-0+ + out: +if (ao)libxl__ao__destroy (ctx, ao); +return NULL ; +} + +/* * Local variables: * mode: C
[...]
My only concern is about the locking of the list walks -- but if that is an issue it will also be there in existing code so I think it can all be fixed in one go later. Hence:
Re: [PATCH 19/24] libxl: provide progress reporting for long-running operations
Ian Campbell writes ("Re: [Xen-devel] [PATCH 19/24] libxl: provide progress reporting for long-running operations"):
Quoted 6 lines · Ian Jackson
Quoted 2 lines
This will be used for reporting, during domain creation, that the console is ready.
I think of progress as being 1%, 2%, 3%...10% etc type stuff. I guess progress in the sense you mean here could be thought of as "milestones"?
It might be used for either of those.
Quoted 2 lines
Quoted 2 lines
(quoted diff) +0
-0@@ -899,12 +899,25 @@ static void egc_run_callbacks(libxl__egc *egc) {
...
Quoted 7 lines
Quoted 4 lines
LIBXL_TAILQ_FOREACH_SAFE(ev, &egc->occurred_for_callback, link, ev_tmp) { LIBXL_TAILQ_REMOVE(&egc->occurred_for_callback, ev, link); CTX->event_hooks->event_occurs(CTX->event_hooks_user, ev); }Are the BSD
FOREACH_SAFEfunctions safe against manipulation from other threads?
No. That would mean they'd have to be some kind of RCU thing, which they are not.
Quoted 4 lines
I only ask because Stefano was surprised that this wasn't the case for the Linux macros, in that context "SAFE" just means you can delete the element in this thread (like you do here) but that if another thread is also manipulating the same list.
...
Quoted 2 lines
By my reading these macros suffer from the same and therefore a bunch more locking is needed. I hope I'm mistaken...
The lists in the egc are per-thread data structures. So that is safe. I started writing a reply which contained some proposed comments for clarifying this situation, and discovered an actual bug - the ao may be used reentrantly in a way that's not safe.
Please see the patch below, which I hope will clarify things. This will go into my series before this progress reporting patch. I will update the progress reporting patch with improved comments, but it's very similar so I think the intent should now be clear.
Quoted 3 lines
Quoted 1 line
+ * decrememt
progress_reports_outstanding, and call us again.decrement
Fixed.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+libxl__ao *libxl__ao_create(libxl_ctx *ctx, uint32_t domid, + const libxl_asyncop_how *how)AFAICT this function has just moved and not changed, right?
Yes, this is pointless code motion. Well actually it doesn't move but git-diff didn't manage to find it. I have shuffled things around to make these hunks go away.
Quoted 7 lines
[...]
My only concern is about the locking of the list walks -- but if that is an issue it will also be there in existing code so I think it can all be fixed in one go later. Hence:
Acked-by Ian Campbell <[email protected]>
You failed to spot that libxl__ao_progress_report doesn't ever add the generated aop to the aops_for_callback list :-). In general the callback-style interaction with libxl is very lightly tested. I expect the appearance of the first user (libvirt, probably) will mean we have to do some debugging.
Anyway, I'll not add your ack to this just yet. I'd rather wait until I've seen what you say about the comments below, and perhaps about the revised version.
I intend to repost the whole series today.
Ian.
From: Ian Jackson <[email protected]>
Subject: [PATCH] libxl: Fix an ao completion bug; document locking policy
Document the concurrent access policies for libxl__ao and libxl__egc, and their corresponding gcs.
Fix a violation of the policy:
If an ao was submitted and a callback requested, and while the initiating function was still running on the original thread, the ao is completed on another thread, the completing thread would improperly concurrently access the ao with the initiating thread.
--- tools/libxl/libxl_event.c | 7 +++++++ tools/libxl/libxl_internal.h | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletions(-)
tools/libxl/libxl_event.c +7 -0
@@ -897,6 +897,11 @@ void libxl__event_disaster(libxl__egc *egc, const char *msg, int errnoval,static void egc_run_callbacks (libxl__egc *egc) { +/* +* The callbacks must happen with the ctx unlocked. +* See the comment near #define EGC_GC in libxl_internal.h and +* those in the definitions of libxl__egc and libxl__ao. +*/ EGC_GC ;libxl_event *ev, *ev_tmp;
@@ -910,9 +915,11 @@ static void egc_run_callbacks(libxl__egc *egc) entry_for_callback, ao_tmp) {LIBXL_TAILQ_REMOVE (&egc->aos_for_callback, ao, entry_for_callback); ao->how.callback (CTX , ao->rc, ao->how.u.for_callback); +CTX_LOCK ; ao->notified =1 ;if (!ao->in_initiator)libxl__ao__destroy (CTX , ao); +CTX_UNLOCK ; } }
tools/libxl/libxl_internal.h +22 -1
@@ -368,7 +368,8 @@ struct libxl__gc { };struct libxl__egc { -/* for event-generating functions only */ +/* For event-generating functions only. +* The egc and its gc may be accessed only on the creating thread. */ struct libxl__gc gc;struct libxl__event_list occurred_for_callback; LIBXL_TAILQ_HEAD(, libxl__ao) aos_for_callback;
@@ -378,6 +379,20 @@ struct libxl__egc {#define LIBXL__AO_MAGIC_DESTROYED 0xA0DEAD00ulstruct libxl__ao { +/* +* An ao and its gc may be accessed only with the ctx lock held. +* +* Special exception: If an ao has been added to +* egc->aos_for_callback, the thread owning the egc may remove the +* ao from that list and make the callback without holding the +* lock. +* +* Corresponding restriction: An ao may be added only to one +* egc->aos_for_callback, once; rc and how must already have been +* set and may not be subsequently modified. (This restriction is +* easily and obviously met since the ao is queued for callback +* only in libxl__ao_complete.) +*/ uint32_t magic;unsigned constructing:1 , in_initiator:1 , complete:1 , notified:1 ;int rc;
@@ -1352,6 +1367,12 @@ libxl__device_model_version_running(libxl__gc *gc, uint32_t domid);* should in any case not find it necessary to call egc-creators from * within libxl. * +* The callbacks must all take place with the ctx unlocked because +* the application is entitled to reenter libxl from them. This +* would be bad not because the lock is not recursive (it is) but +* because the application might make blocking libxl calls which +* would hold the lock unreasonably long. +* * For the same reason libxl__egc_cleanup (or EGC_FREE) must be called * with the ctx *unlocked*. So the right pattern has the EGC_... * macro calls on the outside of the CTX_... ones.
Signature · 1 line
tg: (d9d64ad..) t/xen/xl.event.ao-threading-lock-fix (depends on: t/xen/xl.event.domain-create)
PATCH v7 20/24 libxl: remove malloc failure handling from NEW_EVENT
In reply to Ian JacksonChange to use libxl__zalloc, where allocation failure is fatal.
Also remove a spurious semicolon from the helper macro.
--- tools/libxl/libxl.c | 2 -- tools/libxl/libxl_event.c | 8 +------- tools/libxl/libxl_internal.h | 4 ++-- 3 files changed, 3 insertions(+), 11 deletions(-)
tools/libxl/libxl.c +0 -2
@@ -779,7 +779,6 @@ static void domain_death_occurred(libxl__egc *egc, *evg_upd = evg_next;libxl_event *ev =NEW_EVENT (egc,DOMAIN_DEATH , evg->domid); -if (!ev)return ;libxl__event_occurred (egc, ev);
@@ -866,7 +865,6 @@ static void domain_death_xswatch_callback(libxl__egc *egc, libxl__ev_xswatch *w,if (!evg->shutdown_reported && (got->flags & XEN_DOMINF_shutdown)) {libxl_event *ev =NEW_EVENT (egc,DOMAIN_SHUTDOWN , got->domain); -if (!ev) goto out;LIBXL__LOG (CTX ,LIBXL__LOG_DEBUG ," shutdown reporting" );
tools/libxl/libxl_event.c +1 -7
@@ -980,13 +980,7 @@ libxl_event *libxl__event_new(libxl__egc *egc, {libxl_event *ev; - ev =malloc (sizeof (*ev)); -if (!ev) { -LIBXL__EVENT_DISASTER (egc,"allocate new event" , errno, type); -return NULL ; - } - -memset (ev,0 ,sizeof (*ev)); + ev =libxl__zalloc (0 ,sizeof (*ev)); ev->type = type; ev->domid = domid;
tools/libxl/libxl_internal.h +2 -2
@@ -641,10 +641,10 @@ _hidden libxl_event *libxl__event_new(libxl__egc*, libxl_event_type, uint32_t domid);/* Convenience function. * Allocates a new libxl_event, fills in domid and type. -* If allocation fails, calls _disaster, and returns NULL. */ +* Cannot fail. */ #define NEW_EVENT (egc, type, domid) \ - libxl__event_new((egc), LIBXL_EVENT_TYPE_##type, (domid)); + libxl__event_new((egc), LIBXL_EVENT_TYPE_##type, (domid))/* Convenience macro. */ /*
Signature · 1 line
1.7.2.5
Re: [PATCH 20/24] libxl: remove malloc failure handling from NEW_EVENT
Quoted 5 lines · Ian Jackson
Change to use
libxl__zalloc, where allocation failure is fatal.Also remove a spurious semicolon from the helper macro.
Signed-off-by Ian Jackson <[email protected]>
PATCH v7 21/24 libxl: convert console callback to libxl_asyncprogress_how
In reply to Ian JacksonRemove the old console callback. (Its reentrancy properties were
troublesome: in principle, the event loop might be reentered during the callback, and the libxl__domain_create_state swept out from under the feet of the domain creation.)
As a side effect of the new code arrangements, the console callback for non-bootloader-using PV guests now occurs near the end of domain creation, in the same place as for HVM guests, rather than near the start.
The new arrangements should in principle mean that by the time the console is described as ready by the callback, the xenstore key is indeed ready. So in the future the timeout might be removed from the console client.
--- tools/libxl/libxl.h | 17 ++++++----- tools/libxl/libxl_bootloader.c | 3 ++ tools/libxl/libxl_create.c | 59 +++++++++++++++++++++++----------------- tools/libxl/libxl_internal.h | 6 +++- tools/libxl/libxl_types.idl | 2 + tools/libxl/xl_cmdimpl.c | 25 ++++++++++------- 6 files changed, 67 insertions(+), 45 deletions(-)
tools/libxl/libxl.h +9 -8
@@ -509,18 +509,19 @@ int libxl_ctx_alloc(libxl_ctx **pctx, int version,int libxl_ctx_free (libxl_ctx *ctx/* 0 is OK */ );/* domain related functions */ -typedef int (*libxl_console_ready )(libxl_ctx *ctx,uint32_t domid,void *priv); -/* fixme-ao Need to review this API. If we keep it, the reentrancy -* properties need to be documented but they may turn out to be too -* awkward */ int libxl_domain_create_new (libxl_ctx *ctx,libxl_domain_config *d_config, -libxl_console_ready cb,void *priv,uint32_t *domid, -const libxl_asyncop_how *ao_how); +uint32_t *domid, +const libxl_asyncop_how *ao_how, +const libxl_asyncprogress_how *aop_console_how);int libxl_domain_create_restore (libxl_ctx *ctx,libxl_domain_config *d_config, -libxl_console_ready cb,void *priv,uint32_t *domid,int restore_fd, -const libxl_asyncop_how *ao_how); +const libxl_asyncop_how *ao_how, +const libxl_asyncprogress_how *aop_console_how); +/* A progress report will be made via ao_console_how, of type +* domain_create_console_available, when the domain's primary +* console is available and can be connected to. +*/ void libxl_domain_config_dispose (libxl_domain_config *d_config); int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
tools/libxl/libxl_bootloader.c +3 -0
@@ -377,6 +377,9 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) goto out; } +if (bl->console_available) + bl->console_available (egc, bl); +int bootloader_master =libxl__carefd_fd (bl->ptys[0 ].master);int xenconsole_master =libxl__carefd_fd (bl->ptys[1 ].master);
tools/libxl/libxl_create.c +34 -25
131 lines not on this page · raw message
tools/libxl/libxl_internal.h +4 -2
@@ -1651,11 +1651,14 @@ int libxl__openptys(libxl__openpty_state *op,typedef struct libxl__bootloader_state libxl__bootloader_state ;typedef void libxl__run_bootloader_callback (libxl__egc *,libxl__bootloader_state *,int rc); +typedef void libxl__bootloader_console_callback (libxl__egc *, +libxl__bootloader_state *);struct libxl__bootloader_state {/* caller must fill these in, and they must all remain valid */ libxl__ao *ao;libxl__run_bootloader_callback *callback; +libxl__bootloader_console_callback *console_available;libxl_domain_build_info *info;/* u.pv.{kernel,ramdisk,cmdline} updated */ libxl_device_disk *disk;uint32_t domid;
@@ -1691,9 +1694,8 @@ struct libxl__domain_create_state {libxl__ao *ao;libxl_domain_config *guest_config;int restore_fd; -libxl_console_ready console_cb; -void *console_cb_priv;libxl__domain_create_cb *callback; +libxl_asyncprogress_how aop_console_how;/* private to domain_create */ int guest_domid;libxl__domain_build_state build_state;
tools/libxl/libxl_types.idl +2 -0
@@ -444,6 +444,7 @@ libxl_event_type = Enumeration("event_type", [ (2, "DOMAIN_DEATH"), (3, "DISK_EJECT"), (4, "OPERATION_COMPLETE"), + (5, "DOMAIN_CREATE_CONSOLE_AVAILABLE"), ]) libxl_ev_user = UInt(64)
@@ -469,4 +470,5 @@ libxl_event = Struct("event",[ ("operation_complete", Struct(None, [ ("rc", integer), ])), + ("domain_create_console_available", Struct(None, [])), ]))])
tools/libxl/xl_cmdimpl.c +15 -10
@@ -1430,16 +1430,18 @@ static int freemem(libxl_domain_build_info *b_info)return ERROR_NOMEM ; } -static int autoconnect_console (libxl_ctx *ctx,uint32_t domid,void *priv) +static void autoconnect_console (libxl_ctx *ctx,libxl_event *ev,void *priv) {pid_t *pid = priv; +libxl_event_free (ctx, ev); + *pid =fork ();if (*pid <0 ) {perror ("unable to fork xenconsole" ); -return ERROR_FAIL ; +return ; }else if (*pid >0 ) -return 0 ; +return ;postfork ();
@@ -1506,7 +1508,7 @@ static int create_domain(struct domain_create *dom_info)int config_len =0 ;int restore_fd =-1 ;int status =0 ; -libxl_console_ready cb; +const libxl_asyncprogress_how *autoconnect_console_how;pid_t child_console_pid =-1 ;struct save_file_header hdr;
@@ -1660,24 +1662,27 @@ start: goto error_out; } +libxl_asyncprogress_how autoconnect_console_how_buf;if ( dom_info->console_autoconnect ) { - cb = autoconnect_console; + autoconnect_console_how_buf.callback = autoconnect_console; + autoconnect_console_how_buf.for_callback = &child_console_pid; + autoconnect_console_how = &autoconnect_console_how_buf; }else { - cb =NULL ; + autoconnect_console_how =0 ; }if ( restore_file ) { ret =libxl_domain_create_restore (ctx, &d_config, - cb, &child_console_pid, - &domid, restore_fd,0 ); + &domid, restore_fd, +0 , autoconnect_console_how);/* * On subsequent reboot etc we should create the domain, not * restore/migrate-receive it again. */ restore_file =NULL ; }else { - ret =libxl_domain_create_new (ctx, &d_config, - cb, &child_console_pid, &domid,0 ); + ret =libxl_domain_create_new (ctx, &d_config, &domid, +0 , autoconnect_console_how); }if ( ret ) goto error_out;
Signature · 1 line
1.7.2.5
Re: [PATCH 21/24] libxl: convert console callback to libxl_asyncprogress_how
Quoted 10 lines · Ian Jackson
Remove the old console callback. (Its reentrancy properties were
troublesome: in principle, the event loop might be reentered during the callback, and thelibxl__domain_create_stateswept out from under the feet of the domain creation.)As a side effect of the new code arrangements, the console callback for non-bootloader-using PV guests now occurs near the end of domain creation, in the same place as for HVM guests, rather than near the start.
Quoted 7 lines
The new arrangements should in principle mean that by the time the console is described as ready by the callback, the xenstore key is indeed ready. So in the future the timeout might be removed from the console client.
Signed-off-by Ian Jackson <[email protected]>Cc Stefano Stabellini <[email protected]>
PATCH v7 22/24 libxl: clarify definition of "slow" operation
In reply to Ian JacksonUpdate the comment in libxl_internal.h to be clearer about which application-facing libxl operations need to take an ao_how.
--- tools/libxl/libxl_internal.h | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-)
tools/libxl/libxl_internal.h +23 -6
@@ -1399,17 +1399,34 @@ _hidden void libxl__egc_cleanup(libxl__egc *egc);/* * Machinery for asynchronous operations ("ao") * -* All "slow" functions (includes anything that might block on a -* guest or an external script) need to use the asynchronous -* operation ("ao") machinery. The function should take a parameter -* const libxl_asyncop_how *ao_how and must start with a call to -* AO_INITIATOR_ENTRY. These functions MAY NOT be called from -* inside libxl, because they can cause reentrancy callbacks. +* All "slow" functions (see below for the exact definition) need to +* use the asynchronous operation ("ao") machinery. The function +* should take a parameter const libxl_asyncop_how *ao_how and must +* start with a call to AO_INITIATOR_ENTRY. These functions MAY NOT +* be called from inside libxl, because they can cause reentrancy +* callbacks. * * For the same reason functions taking an ao_how may make themselves * an egc with EGC_INIT (and they will generally want to, to be able * to immediately complete an ao during its setup). * +* +* "Slow" functions includes any that might block on a guest or an +* external script. More broadly, it includes any operations which +* are sufficiently slow that an application might reasonably want to +* initiate them, and then carry on doing something else, while the +* operation completes. That is, a "fast" function must be fast +* enough that we do not mind blocking all other management operations +* on the same host while it completes. +* +* There are certain primitive functions which make a libxl operation +* necessarily "slow" for API reasons. These are: +* - awaiting xenstore watches (although read-modify-write xenstore +* transactions are OK for fast functions) +* - spawning subprocesses +* - anything with a timeout +* +* * Lifecycle of an ao: * * - Created by libxl__ao_create (or the AO_CREATE convenience macro).
Signature · 1 line
1.7.2.5
Re: [PATCH 22/24] libxl: clarify definition of "slow" operation
Quoted 5 lines · Ian Jackson
Update the comment in
libxl_internal.hto be clearer about which application-facing libxl operations need to take anao_how.Reported-by Dan Magenheimer <[email protected]>Signed-off-by Ian Jackson <[email protected]>
Quoted 49 lines
--- tools/libxl/libxl_internal.h | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-)tools/libxl/libxl_internal.h +23
-6@@ -1399,17 +1399,34 @@ _hidden void libxl__egc_cleanup(libxl__egc *egc);/* * Machinery for asynchronous operations ("ao") * -* All "slow" functions (includes anything that might block on a -* guest or an external script) need to use the asynchronous -* operation ("ao") machinery. The function should take a parameter -* const libxl_asyncop_how *ao_how and must start with a call to -* AO_INITIATOR_ENTRY. These functions MAY NOT be called from -* inside libxl, because they can cause reentrancy callbacks. +* All "slow" functions (see below for the exact definition) need to +* use the asynchronous operation ("ao") machinery. The function +* should take a parameter const libxl_asyncop_how *ao_how and must +* start with a call to AO_INITIATOR_ENTRY. These functions MAY NOT +* be called from inside libxl, because they can cause reentrancy +* callbacks. * * For the same reason functions taking an ao_how may make themselves * an egc with EGC_INIT (and they will generally want to, to be able * to immediately complete an ao during its setup). * +* +* "Slow" functions includes any that might block on a guest or an +* external script. More broadly, it includes any operations which +* are sufficiently slow that an application might reasonably want to +* initiate them, and then carry on doing something else, while the +* operation completes. That is, a "fast" function must be fast +* enough that we do not mind blocking all other management operations +* on the same host while it completes. +* +* There are certain primitive functions which make a libxl operation +* necessarily "slow" for API reasons. These are: +* - awaiting xenstore watches (although read-modify-write xenstore +* transactions are OK for fast functions) +* - spawning subprocesses +* - anything with a timeout +* +* * Lifecycle of an ao: * * - Created by libxl__ao_create (or the AO_CREATE convenience macro).
PATCH v7 23/24 libxl: child processes cleanups
In reply to Ian JacksonAbolish libxl_fork. Its only callers were in xl. Its functionality is now moved elsewhere, as follows:
* The "logging version of fork", which is what it was billed as, is now xl_fork, which also dies on failure.
* Closing the xenstore handle in the child is now done in libxl__ev_child_fork, which is the only remaining place where fork is called in libxl.
* We provide a new function libxl__ev_child_xenstore_reopen for in-libxl children to make the ctx useable for xenstore again.
* Consequently libxl__spawn_record_pid now no longer needs to mess about with its own xenstore handle. As a bonus it can now just use libxl__xs_write.
Also, since we have now converted all the forkers in libxl, we can always honour the fork_replacement childproc hook - so do so.
--- tools/libxl/libxl_exec.c | 35 ++++++++++++++++------------------- tools/libxl/libxl_fork.c | 25 ++++++++++++++++++++++++- tools/libxl/libxl_internal.h | 5 +++++ tools/libxl/libxl_utils.c | 21 --------------------- tools/libxl/libxl_utils.h | 3 +-- tools/libxl/xl.c | 12 ++++++++++++ tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 5 ++--- 8 files changed, 61 insertions(+), 46 deletions(-)
tools/libxl/libxl_exec.c +16 -19
@@ -127,34 +127,23 @@ void libxl_report_child_exitstatus(libxl_ctx *ctx, } } -int libxl__spawn_record_pid (libxl__gc *gc,libxl__spawn_state *spawn, -pid_t innerchild) +int libxl__spawn_record_pid (libxl__gc *gc,libxl__spawn_state *spawn,pid_t pid) { -struct xs_handle *xsh =NULL ; -const char *pid =NULL ; -int rc, xsok; +int r, rc; - pid =GCSPRINTF ("%d" , innerchild); + rc =libxl__ev_child_xenstore_reopen (gc, spawn->what); +if (rc) goto out; -/* we mustn't use the parent's handle in the child */ - xsh =xs_daemon_open (); -if (!xsh) { -LOGE (ERROR ,"write %s = %s: xenstore reopen failed" , - spawn->pidpath, pid); - rc =ERROR_FAIL ; goto out; - } - - xsok =xs_write (xsh,XBT_NULL , spawn->pidpath, pid,strlen (pid)); -if (!xsok) { + r =libxl__xs_write (gc,XBT_NULL , spawn->pidpath,"%d" , pid); +if (r) {LOGE (ERROR , -"write %s = %s: xenstore write failed" , spawn->pidpath, pid); +"write %s = %d: xenstore write failed" , spawn->pidpath, pid); rc =ERROR_FAIL ; goto out; } rc =0 ; out: -if (xsh)xs_daemon_close (xsh);return rc ?SIGTERM :0 ; }
@@ -302,7 +291,15 @@ int libxl__spawn_spawn(libxl__egc *egc, libxl__spawn_state *ss)/* we are now the middle process */ - child =fork (); +pid_t (*fork_replacement)(void *) = +CTX ->childproc_hooks + ?CTX ->childproc_hooks->fork_replacement + :0 ; + child = + fork_replacement + ?fork_replacement (CTX ->childproc_user) + :fork (); +if (child ==-1 )exit (255 );if (!child) {
tools/libxl/libxl_fork.c +24 -1
@@ -347,7 +347,12 @@ pid_t libxl__ev_child_fork(libxl__gc *gc, libxl__ev_child *ch,if (!pid) {/* woohoo! */ -return 0 ;/* Yes, CTX is left locked in the child. */ +if (CTX ->xsh) { +xs_daemon_destroy_postfork (CTX ->xsh); +CTX ->xsh =NULL ;/* turns mistakes into crashes */ + } +/* Yes, CTX is left locked in the child. */ +return 0 ; } ch->pid = pid;
@@ -395,6 +400,24 @@ const libxl_childproc_hooks libxl__childproc_default_hooks = { libxl_sigchld_owner_libxl, 0, 0 }; +int libxl__ev_child_xenstore_reopen (libxl__gc *gc,const char *what) { +int rc; + +assert (!CTX ->xsh); +CTX ->xsh =xs_daemon_open (); +if (!CTX ->xsh) { +LOGE (ERROR ,"%s: xenstore reopen failed" , what); + rc =ERROR_FAIL ; goto out; + } + +libxl_fd_set_cloexec (CTX ,xs_fileno (CTX ->xsh),1 ); + +return 0 ; + + out: +return rc; +} +/* * Local variables: * mode: C
tools/libxl/libxl_internal.h +5 -0
@@ -627,6 +627,11 @@ static inline void libxl__ev_child_init(libxl__ev_child *childw_out)static inline int libxl__ev_child_inuse (libxl__ev_child *childw_out) {return childw_out->pid >=0 ; } +/* Useable (only) in the child to once more make the ctx useable for +* xenstore operations. logs failure in the form "what: <error +* message>". */ +_hidden int libxl__ev_child_xenstore_reopen(libxl__gc *gc, const char *what); +/* * Other event-handling support provided by the libxl event core to
tools/libxl/libxl_utils.c +0 -21
@@ -444,27 +444,6 @@ int libxl__remove_directory(libxl__gc *gc, const char *dirpath)return rc; } -pid_t libxl_fork (libxl_ctx *ctx) -{ -pid_t pid; - - pid =fork (); -if (pid ==-1 ) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"fork failed" ); -return -1 ; - } - -if (!pid) { -if (ctx->xsh)xs_daemon_destroy_postfork (ctx->xsh); - ctx->xsh =0 ; -/* This ensures that anyone who forks but doesn't exec, -* and doesn't reinitialise the libxl_ctx, is OK. -* It also means they can safely call libxl_ctx_free. */ - } - -return pid; -} -int libxl_pipe (libxl_ctx *ctx,int pipes[2 ]) {if (pipe (pipes) <0 ) {
tools/libxl/libxl_utils.h +1 -2
@@ -47,9 +47,8 @@ int libxl_write_exactly(libxl_ctx *ctx, int fd, const void *data,* logged using filename (which is only used for logging) and what * (which may be 0). */ -pid_t libxl_fork (libxl_ctx *ctx);int libxl_pipe (libxl_ctx *ctx,int pipes[2 ]); -/* Just like fork(2), pipe(2), but log errors. */ +/* Just like pipe(2), but log errors. */ void libxl_report_child_exitstatus (libxl_ctx *ctx,xentoollog_level ,const char *what,pid_t pid,int status);
tools/libxl/xl.c +12 -0
@@ -105,6 +105,18 @@ void postfork(void) } } +pid_t xl_fork (libxl_ctx *ctx) { +pid_t pid; + + pid =fork (); +if (pid ==-1 ) { +perror ("fork failed" ); +exit (-1 ); + } + +return pid; +} +int main (int argc,char **argv) {int opt =0 ;
tools/libxl/xl.h +1 -0
@@ -105,6 +105,7 @@ struct cmd_spec *cmdtable_lookup(const char *s);extern libxl_ctx *ctx;extern xentoollog_logger_stdiostream *logger; +pid_t xl_fork (libxl_ctx *ctx);/* like fork, but prints and dies if it fails */ void postfork (void );/* global options */
tools/libxl/xl_cmdimpl.c +2 -3
@@ -1709,7 +1709,7 @@ start:pid_t child1, got_child;int nullfd; - child1 =libxl_fork (ctx); + child1 =xl_fork (ctx);if (child1) {printf ("Daemon running with PID %d\n" , child1);
@@ -2748,8 +2748,7 @@ static void migrate_domain(const char *domain_spec, const char *rune,MUST (libxl_pipe (ctx, sendpipe) );MUST (libxl_pipe (ctx, recvpipe) ); - child =libxl_fork (ctx); -if (child==-1 )exit (1 ); + child =xl_fork (ctx);if (!child) {dup2 (sendpipe[0 ],0 );
Signature · 1 line
1.7.2.5
Re: [PATCH 23/24] libxl: child processes cleanups
Quoted 40 lines · Ian Jackson
Abolish
libxl_fork. Its only callers were in xl. Its functionality is now moved elsewhere, as follows:* The "logging version of fork", which is what it was billed as, is now
xl_fork, which also dies on failure.* Closing the xenstore handle in the child is now done in
libxl__ev_child_fork, which is the only remaining place where fork is called in libxl.* We provide a new function
libxl__ev_child_xenstore_reopenfor in-libxl children to make the ctx useable for xenstore again.* Consequently
libxl__spawn_record_pidnow no longer needs to mess about with its own xenstore handle. As a bonus it can now just uselibxl__xs_write.Also, since we have now converted all the forkers in libxl, we can always honour the
fork_replacementchildproc hook - so do so.Signed-off-by Ian Jackson <[email protected]>--- tools/libxl/libxl_exec.c | 35 ++++++++++++++++------------------- tools/libxl/libxl_fork.c | 25 ++++++++++++++++++++++++- tools/libxl/libxl_internal.h | 5 +++++ tools/libxl/libxl_utils.c | 21 --------------------- tools/libxl/libxl_utils.h | 3 +-- tools/libxl/xl.c | 12 ++++++++++++ tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 5 ++--- 8 files changed, 61 insertions(+), 46 deletions(-)tools/libxl/libxl_exec.c +0
-0@@ -302,7 +291,15 @@ int libxl__spawn_spawn(libxl__egc *egc, libxl__spawn_state *ss)/* we are now the middle process */
tools/libxl/libxl_exec.c int libxl__spawn_spawn(libxl__egc *egc, libxl__spawn_state *ss) · line 301
Quoted 10 lines
tools/libxl/libxl_exec.c +8
-1- child =fork (); +pid_t (*fork_replacement)(void *) = +CTX ->childproc_hooks + ?CTX ->childproc_hooks->fork_replacement + :0 ; + child = + fork_replacement + ?fork_replacement (CTX ->childproc_user) + :fork ();
A helper function or macro would be useful here?
Quoted 9 lines
tools/libxl/libxl_exec.c +1
-0+if (child ==-1 )exit (255 );if (!child) {tools/libxl/libxl_internal.h +0
-0
tools/libxl/libxl_internal.h static inline void libxl__ev_child_init(libxl__ev_child *childw_out) · line 631
Quoted 5 lines
tools/libxl/libxl_internal.h +2
-0@@ -627,6 +627,11 @@ static inline void libxl__ev_child_init(libxl__ev_child *childw_out)static inline int libxl__ev_child_inuse (libxl__ev_child *childw_out) {return childw_out->pid >=0 ; } +/* Useable (only) in the child to once more make the ctx useable for +* xenstore operations.
Specifically "the child" is the middle child of a spawn? Otherwise the constraint must be something like "before any threads are created in the new process", or something like that?
Quoted 7 lines
tools/libxl/libxl_internal.h +3
-0logs failure in the form "what: <error + * message>". */ +_hidden int libxl__ev_child_xenstore_reopen(libxl__gc *gc, const char *what); +/* * Other event-handling support provided by the libxl event core to
Ian.
Re: [PATCH 23/24] libxl: child processes cleanups
Ian Campbell writes ("Re: [Xen-devel] [PATCH 23/24] libxl: child processes cleanups"):
Quoted 3 lines · Ian Jackson
Quoted 2 lines
Abolish
libxl_fork. Its only callers were in xl. Its functionality is now moved elsewhere, as follows:
...
Quoted 9 lines
Quoted 5 lines
static inline int
libxl__ev_child_inuse(libxl__ev_child *childw_out){ return childw_out->pid >= 0; }+/* Useable (only) in the child to once more make the ctx useable for
+ * xenstore operations.Specifically "the child" is the middle child of a spawn? Otherwise the constraint must be something like "before any threads are created in the new process", or something like that?
The fact that raw fork() may be used in the child created by libxl__ev_child_inuse isn't documented. It would be possible to document this but the set of restrictions on the behaviours of the middle child and any resulting grandchildren are rather complex.
I think it might be better to draw a veil over this and leave it as a special piece of knowledge implicit in the implementation of libxl__spawn_*.
In practice the use of _xenstore_reopen in the middle child is fine provided that the middle child doesn't then fork _and_ then use libxl's xenstore functions in both the middle child and the grandchild.
Ian.
Re: [PATCH 23/24] libxl: child processes cleanups
Quoted 15 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH 23/24] libxl: child processes cleanups"):
Quoted 3 lines · Ian Jackson
Quoted 2 lines
Abolish
libxl_fork. Its only callers were in xl. Its functionality is now moved elsewhere, as follows:...
Quoted 9 lines
Quoted 5 lines
static inline int
libxl__ev_child_inuse(libxl__ev_child *childw_out){ return childw_out->pid >= 0; }+/* Useable (only) in the child to once more make the ctx useable for
+ * xenstore operations.Specifically "the child" is the middle child of a spawn? Otherwise the constraint must be something like "before any threads are created in the new process", or something like that?
Quoted 8 lines
The fact that raw
fork()may be used in the child created bylibxl__ev_child_inuseisn't documented. It would be possible to document this but the set of restrictions on the behaviours of the middle child and any resulting grandchildren are rather complex.I think it might be better to draw a veil over this and leave it as a special piece of knowledge implicit in the implementation of libxl__spawn_*.
OK.
Quoted 6 lines
In practice the use of
_xenstore_reopenin the middle child is fine provided that the middle child doesn't then fork _and_ then use libxl's xenstore functions in both the middle child and the grandchild.Ian.
Ian Campbell
Acked-byRe: [PATCH 23/24] libxl: child processes cleanups
Quoted 21 lines · Ian Campbell
Quoted 20 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH 23/24] libxl: child processes cleanups"):
Quoted 3 lines · Ian Jackson
Quoted 2 lines
Abolish
libxl_fork. Its only callers were in xl. Its functionality is now moved elsewhere, as follows:...
Quoted 9 lines
Quoted 5 lines
static inline int
libxl__ev_child_inuse(libxl__ev_child *childw_out){ return childw_out->pid >= 0; }+/* Useable (only) in the child to once more make the ctx useable for
+ * xenstore operations.Specifically "the child" is the middle child of a spawn? Otherwise the constraint must be something like "before any threads are created in the new process", or something like that?
The fact that raw
fork()may be used in the child created bylibxl__ev_child_inuseisn't documented. It would be possible to document this but the set of restrictions on the behaviours of the middle child and any resulting grandchildren are rather complex.
Quoted 5 lines
Quoted 3 lines
I think it might be better to draw a veil over this and leave it as a special piece of knowledge implicit in the implementation of libxl__spawn_*.
OK.
Looking back at my review, my only other comment was just a suggestion which you can implenment if you want, which means that OK ->
Quoted 8 lines
Quoted 7 lines
In practice the use of
_xenstore_reopenin the middle child is fine provided that the middle child doesn't then fork _and_ then use libxl's xenstore functions in both the middle child and the grandchild.Ian.
Re: [PATCH 23/24] libxl: child processes cleanups
In reply to Ian CampbellIan Campbell writes ("Re: [Xen-devel] [PATCH 23/24] libxl: child processes cleanups"):
Quoted 11 lines · Ian Jackson
tools/libxl/libxl_exec.c int libxl__spawn_spawn(libxl__egc *egc, libxl__spawn_state *ss) · line 301
Quoted 9 lines
tools/libxl/libxl_exec.c +8
-1- child =fork (); +pid_t (*fork_replacement)(void *) = +CTX ->childproc_hooks + ?CTX ->childproc_hooks->fork_replacement + :0 ; + child = + fork_replacement + ?fork_replacement (CTX ->childproc_user) + :fork ();
Quoted 1 line
A helper function or macro would be useful here?
There is exactly one call site for this, since no-one else in libxl is allowed to call fork (except libxl__spawn_*, in the child as previously discussed, and there it doesn't want to use the hook).
If you think it would be clearer I'm happy to make it into a sub-function. But IMO libxl__ev_child_fork is already quite short so I don't see much point further splitting it up.
Ian.
Re: [PATCH 23/24] libxl: child processes cleanups
Quoted 14 lines · Ian Jackson
Ian Campbell writes ("Re: [Xen-devel] [PATCH 23/24] libxl: child processes cleanups"):
Quoted 11 lines · Ian Jackson
tools/libxl/libxl_exec.c int libxl__spawn_spawn(libxl__egc *egc, libxl__spawn_state *ss) · line 301
Quoted 9 lines
tools/libxl/libxl_exec.c +8
-1- child =fork (); +pid_t (*fork_replacement)(void *) = +CTX ->childproc_hooks + ?CTX ->childproc_hooks->fork_replacement + :0 ; + child = + fork_replacement + ?fork_replacement (CTX ->childproc_user) + :fork ();Quoted 1 line
A helper function or macro would be useful here?
Quoted 7 lines
There is exactly one call site for this, since no-one else in libxl is allowed to call fork (except libxl__spawn_*, in the child as previously discussed, and there it doesn't want to use the hook).
If you think it would be clearer I'm happy to make it into a sub-function. But IMO
libxl__ev_child_forkis already quite short so I don't see much point further splitting it up.
I guess I was just a bit slow on the parse of these two statements which made me think a function might have a name which helped me, but your explanation about it being the only possible callsite makes sense so I think you can leave it as is.
Ian.
PATCH v7 24/24 libxl: aborting bootloader invocation when domain dioes
In reply to Ian JacksonCancel the bootloader (specifically, by sending it a signal) if the domain is seen to disappear from xenstore.
We use a new utility event source libxl__domaindeathcheck which provides a convenient wrapper for the xenstore watch.
--- tools/libxl/libxl_bootloader.c | 43 ++++++++++++++++++++++++++++++--------- tools/libxl/libxl_event.c | 31 ++++++++++++++++++++++++++++ tools/libxl/libxl_internal.h | 29 ++++++++++++++++++++++++++- 3 files changed, 92 insertions(+), 11 deletions(-)
tools/libxl/libxl_bootloader.c +33 -10
@@ -31,6 +31,7 @@ static void bootloader_keystrokes_copyfail(libxl__egc *egc, libxl__datacopier_state *dc, int onwrite, int errnoval);static void bootloader_display_copyfail (libxl__egc *egc,libxl__datacopier_state *dc,int onwrite,int errnoval); +static void bootloader_domaindeath (libxl__egc *,libxl__domaindeathcheck *dc);static void bootloader_finished (libxl__egc *egc,libxl__ev_child *child,pid_t pid,int status);
@@ -213,6 +214,7 @@ void libxl__bootloader_init(libxl__bootloader_state *bl) bl->ptys[0 ].master = bl->ptys[0 ].slave =0 ; bl->ptys[1 ].master = bl->ptys[1 ].slave =0 ;libxl__ev_child_init (&bl->child); +libxl__domaindeathcheck_init (&bl->deathcheck); bl->keystrokes.ao = bl->ao;libxl__datacopier_init (&bl->keystrokes); bl->display.ao = bl->ao;libxl__datacopier_init (&bl->display); }
@@ -230,6 +232,7 @@ static void bootloader_cleanup(libxl__egc *egc, libxl__bootloader_state *bl)free (bl->diskpath); bl->diskpath =0 ; } +libxl__domaindeathcheck_stop (gc,&bl->deathcheck);libxl__datacopier_kill (&bl->keystrokes);libxl__datacopier_kill (&bl->display);for (i=0 ; i<2 ; i++) {
@@ -256,6 +259,23 @@ static void bootloader_callback(libxl__egc *egc, libxl__bootloader_state *bl, bl->callback (egc, bl, rc); } +/* might be called at any time, provided it's init'd */ +static void bootloader_abort (libxl__egc *egc, +libxl__bootloader_state *bl,int rc) +{ +STATE_AO_GC (bl->ao); +int r; + +libxl__datacopier_kill (&bl->keystrokes); +libxl__datacopier_kill (&bl->display); +if (libxl__ev_child_inuse (&bl->child)) { + r =kill (bl->child.pid,SIGTERM ); +if (r)LOGE (WARN ,"after failure, failed to kill bootloader [%lu]" , + (unsigned long )bl->child.pid); + } + bl->rc = rc; +} +/*----- main flow of control -----*/ void libxl__bootloader_run (libxl__egc *egc,libxl__bootloader_state *bl)
@@ -377,6 +397,12 @@ static void bootloader_gotptys(libxl__egc *egc, libxl__openpty_state *op) goto out; } + bl->deathcheck.what ="stopping bootloader" ; + bl->deathcheck.domid = bl->domid; + bl->deathcheck.callback = bootloader_domaindeath; + rc =libxl__domaindeathcheck_start (gc, &bl->deathcheck); +if (rc) goto out; +if (bl->console_available) bl->console_available (egc, bl);
@@ -454,18 +480,9 @@ static void bootloader_copyfail(libxl__egc *egc, const char *which, libxl__bootloader_state *bl, int onwrite, int errnoval) { STATE_AO_GC(bl->ao); -int r; -if (!onwrite && !errnoval)LOG (ERROR ,"unexpected eof copying %s" , which); -libxl__datacopier_kill (&bl->keystrokes); -libxl__datacopier_kill (&bl->display); -if (libxl__ev_child_inuse (&bl->child)) { - r =kill (bl->child.pid,SIGTERM ); -if (r)LOGE (WARN ,"after failure, failed to kill bootloader [%lu]" , - (unsigned long )bl->child.pid); - } - bl->rc =ERROR_FAIL ; +bootloader_abort (egc, bl,ERROR_FAIL ); }static void bootloader_keystrokes_copyfail (libxl__egc *egc,libxl__datacopier_state *dc,int onwrite,int errnoval)
@@ -480,6 +497,12 @@ static void bootloader_display_copyfail(libxl__egc *egc,bootloader_copyfail (egc,"bootloader output" , bl, onwrite, errnoval); } +static void bootloader_domaindeath (libxl__egc *egc,libxl__domaindeathcheck *dc) +{ +libxl__bootloader_state *bl =CONTAINER_OF (dc, *bl, deathcheck); +bootloader_abort (egc, bl,ERROR_FAIL ); +} +static void bootloader_finished (libxl__egc *egc,libxl__ev_child *child,pid_t pid,int status) {
tools/libxl/libxl_event.c +31 -0
@@ -585,6 +585,37 @@ int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds, }/* +* domain death/destruction +*/ + +static void domaindeathcheck_callback (libxl__egc *egc,libxl__ev_xswatch *w, +const char *watch_path,const char *event_path) +{ +libxl__domaindeathcheck *dc =CONTAINER_OF (w, *dc, watch); +EGC_GC ; +const char *p =libxl__xs_read (gc,XBT_NULL , watch_path); +if (p)return ; + +if (errno!=ENOENT ) { +LIBXL__EVENT_DISASTER (egc,"failed to read xenstore" +" for domain deatch check" , errno,0 ); +return ; + } + +LOG (ERROR ,"%s: domain %" PRIu32" removed (%s no longer in xenstore)" , + dc->what, dc->domid, watch_path); + dc->callback (egc, dc); +} + +int libxl__domaindeathcheck_start (libxl__gc *gc, +libxl__domaindeathcheck *dc) +{ +const char *path =GCSPRINTF ("/local/domain/%" PRIu32, dc->domid); +return libxl__ev_xswatch_register (gc, &dc->watch, + domaindeathcheck_callback, path); +} + +/* * osevent poll */
tools/libxl/libxl_internal.h +28 -1
@@ -837,6 +837,33 @@ _hidden int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds,const char *state_path, int state, int milliseconds); +/* +* libxl__ev_domaindeathcheck_register - arranges to call back (once) +* if the domain is destroyed. If the domain dies, we log a message +* of the form "<what>: <explanation of the situation, including the domid>". +*/ + +typedef struct libxl__domaindeathcheck libxl__domaindeathcheck ; +typedef void libxl___domaindeathcheck_callback (libxl__egc *egc, +libxl__domaindeathcheck *); + +struct libxl__domaindeathcheck { +/* must be filled in by caller, and remain valid: */ +const char *what; +uint32_t domid; +libxl___domaindeathcheck_callback *callback; +/* private */ +libxl__ev_xswatch watch; +}; + +_hidden int libxl__domaindeathcheck_start(libxl__gc *gc, +libxl__domaindeathcheck *dc); + +static inline void libxl__domaindeathcheck_init + (libxl__domaindeathcheck *dc) {libxl__ev_xswatch_init (&dc->watch); } +static inline void libxl__domaindeathcheck_stop (libxl__gc *gc, +libxl__domaindeathcheck *dc) {libxl__ev_xswatch_deregister (gc,&dc->watch); } +/* * libxl__try_phy_backend - Check if there's support for the passed
@@ -1690,6 +1717,7 @@ struct libxl__bootloader_state {libxl__openpty_state openpty;libxl__openpty_result ptys[2 ];/* [0] is for bootloader */ libxl__ev_child child; +libxl__domaindeathcheck deathcheck;int nargs, argsspace;const char **args;libxl__datacopier_state keystrokes, display;
@@ -1702,7 +1730,6 @@ _hidden void libxl__bootloader_init(libxl__bootloader_state *bl);* If callback is passed rc==0, will have updated st->info appropriately */ _hidden void libxl__bootloader_run(libxl__egc*, libxl__bootloader_state *st); -/*----- Domain creation -----*/ typedef struct libxl__domain_create_state libxl__domain_create_state ;
Signature · 1 line
1.7.2.5
Re: [PATCH 24/24] libxl: aborting bootloader invocation when domain dioes
Quoted 12 lines
tools/libxl/libxl_event.c +4
-0@@ -585,6 +585,37 @@ int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds, }/* +* domain death/destruction +*/ + +static void domaindeathcheck_callback(libxl__egc *egc, libxl__ev_xswatch *w,
tools/libxl/libxl_event.c int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds, · line 601
Quoted 10 lines
tools/libxl/libxl_event.c +10
-0+ const char *watch_path, const char *event_path) +{ + libxl__domaindeathcheck *dc = CONTAINER_OF(w, *dc, watch); +EGC_GC ; +const char *p =libxl__xs_read (gc,XBT_NULL , watch_path); +if (p)return ; + +if (errno!=ENOENT ) { +LIBXL__EVENT_DISASTER (egc,"failed to read xenstore" +" for domain deatch check" , errno,0 );
detach
Quoted 4 lines
tools/libxl/libxl_event.c +4
-0+return ; + } + + LOG(ERROR,"%s: domain %"PRIu32" removed (%s no longer in xenstore)",
tools/libxl/libxl_event.c int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds, · line 615
Quoted 10 lines
tools/libxl/libxl_event.c +10
-0+ dc->what, dc->domid, watch_path); + dc->callback (egc, dc); +} + +int libxl__domaindeathcheck_start (libxl__gc *gc, +libxl__domaindeathcheck *dc) +{ +const char *path =GCSPRINTF ("/local/domain/%" PRIu32, dc->domid); +return libxl__ev_xswatch_register (gc, &dc->watch, + domaindeathcheck_callback, path);
So we are watching for the toolstack (possibly the same one as we are running in) to destroy the domain and therefore nuke the xs directory -- does that actually work?
Specifically in the case of xl running the bootloader -- is xl in any position to handle a domain death during domain build? Isn't it doing the create synchronously?
(note, I'm not actually 100% sure what might be wrong with this, it just strikes me as odd...)
Wouldn't using the @releaseDomain watch be more reliable?
Ian.
Re: [PATCH 24/24] libxl: aborting bootloader invocation when domain dioes
Ian Campbell writes ("Re: [Xen-devel] [PATCH 24/24] libxl: aborting bootloader invocation when domain dioes"):
Quoted 4 lines
tools/libxl/libxl_event.c int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds, · line 601
Quoted 2 lines
tools/libxl/libxl_event.c +2
-0+LIBXL__EVENT_DISASTER (egc,"failed to read xenstore" +" for domain deatch check" , errno,0 );detach
Fixed.
Quoted 10 lines
tools/libxl/libxl_event.c int libxl__ev_devstate_wait(libxl__gc *gc, libxl__ev_devstate *ds, · line 615
Quoted 6 lines
tools/libxl/libxl_event.c +6
-0+int libxl__domaindeathcheck_start (libxl__gc *gc, +libxl__domaindeathcheck *dc) +{ +const char *path =GCSPRINTF ("/local/domain/%" PRIu32, dc->domid); +return libxl__ev_xswatch_register (gc, &dc->watch, + domaindeathcheck_callback, path);So we are watching for the toolstack (possibly the same one as we are running in) to destroy the domain and therefore nuke the xs directory -- does that actually work?
Yes. And, yes.
Quoted 3 lines
Specifically in the case of xl running the bootloader -- is xl in any position to handle a domain death during domain build? Isn't it doing the create synchronously?
The copy of xl which is trying to create the domain is indeed not capable of initiating destruction. But another copy of xl might destroy the domain.
In my tests I found that if one runs, in one window, "xl create -c", and then when that command is sat at the bootloader prompt (which might be indefinitely), runs "xl destroy <name of guest>", before my patch the xl create continues to sit and wait for the bootloader. (If the bootloader is then told to continue, the xl create will of course bomb out since its domain has vanished.)
This is bad not just because it is poor UX, but also because after "xl destroy" it ought to be possible to run "xl create" without any difficulty - however the bootloader from the previous incarnation still has the disk open. It's also bad because it leaks the bootloader until the bootloader times out (which might be indefinitely).
After applying my patch, running "xl destroy" while the create is waiting for the bootloader causes the creation to be immediately aborted, as one would hope.
Quoted 1 line
Wouldn't using the @releaseDomain watch be more reliable?
It would be more complicated. We don't have a general internal-facing facility for "has this domain been destroyed", and turning @releaseDomain watch events into information about specific domains is complicated because the @releaseDomain event doesn't contain the domid.
And it is not necessary because, if the domain is destroyed then either (a) the entries in xenstore have already been deleted, in which case the test here works or (b) they have not in which case something has gone very badly wrong and we are going to leak those xenstore entries, in which case trying to avoid leaking other stuff seems futile.
Ian.
Ian Campbell
Acked-byRe: [PATCH 24/24] libxl: aborting bootloader invocation when domain dioes
Quoted 6 lines · Ian Jackson
if the domain is destroyed then
either (a) the entries in xenstore have already been deleted, in which case the test here works or (b) they have not in which case something has gone very badly wrong and we are going to leak those xenstore entries, in which case trying to avoid leaking other stuff seems futile.
I'm convinced. Maybe write that in a comment?
Re: [PATCH 24/24] libxl: aborting bootloader invocation when domain dioes
Ian Campbell writes ("Re: [Xen-devel] [PATCH 24/24] libxl: aborting bootloader invocation when domain dioes"):
Quoted 9 lines · Ian Jackson
Quoted 6 lines
if the domain is destroyed then
either (a) the entries in xenstore have already been deleted, in which case the test here works or (b) they have not in which case something has gone very badly wrong and we are going to leak those xenstore entries, in which case trying to avoid leaking other stuff seems futile.I'm convinced. Maybe write that in a comment?
Good idea, willdo.
Quoted 1 line
Acked-by Ian Campbell <[email protected]>
Ta.
Ian.