Ian Campbell
2010-Oct-26 12:02 UTC
[Xen-devel] [PATCH] xl: support -w (wait) option in xl shutdown
# HG changeset patch # User Ian Campbell <ian.campbell@citrix.com> # Date 1288094528 -3600 # Node ID 29aeb30b8488e2a25d38dee16d88b6d9efa72c21 # Parent 1d07e53e60e5414919f76296500bc138ab971f9b xl: support -w (wait) option in xl shutdown improves compatibility with xm. Signed-off-by: Ian Campbell <ian.campbell@citrix.com> diff -r 1d07e53e60e5 -r 29aeb30b8488 tools/libxl/xl_cmdimpl.c --- a/tools/libxl/xl_cmdimpl.c Mon Oct 25 16:55:22 2010 +0100 +++ b/tools/libxl/xl_cmdimpl.c Tue Oct 26 13:02:08 2010 +0100 @@ -2396,12 +2396,47 @@ static void destroy_domain(char *p) if (rc) { fprintf(stderr,"destroy failed (rc=%d)\n.",rc); exit(-1); } } -static void shutdown_domain(char *p) -{ - int rc; +static void shutdown_domain(char *p, int wait) +{ + int rc; + find_domain(p); rc=libxl_domain_shutdown(&ctx, domid, 0); if (rc) { fprintf(stderr,"shutdown failed (rc=%d)\n.",rc);exit(-1); } + + if (wait) { + libxl_waiter waiter; + int fd; + + libxl_wait_for_domain_death(&ctx, domid, &waiter); + + libxl_get_wait_fd(&ctx, &fd); + + while (wait) { + fd_set rfds; + libxl_event event; + libxl_dominfo info; + + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + + if (!select(fd + 1, &rfds, NULL, NULL, NULL)) + continue; + + libxl_get_event(&ctx, &event); + + if (event.type == LIBXL_EVENT_DOMAIN_DEATH) { + if (libxl_event_get_domain_death_info(&ctx, domid, &event, &info) < 0) + continue; + + LOG("Domain %d is dead", domid); + wait = 0; + } + + libxl_free_event(&event); + } + libxl_free_waiter(&waiter); + } } static void reboot_domain(char *p) @@ -3221,13 +3256,17 @@ int main_shutdown(int argc, char **argv) int main_shutdown(int argc, char **argv) { int opt; - char *p; - - while ((opt = getopt(argc, argv, "h")) != -1) { + int wait = 0; + char *p; + + while ((opt = getopt(argc, argv, "hw")) != -1) { switch (opt) { case ''h'': help("shutdown"); return 0; + case ''w'': + wait = 1; + break; default: fprintf(stderr, "option not supported\n"); break; @@ -3240,7 +3279,7 @@ int main_shutdown(int argc, char **argv) p = argv[optind]; - shutdown_domain(p); + shutdown_domain(p, wait); return 0; } _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2010-Oct-28 11:17 UTC
Re: [Xen-devel] [PATCH] xl: support -w (wait) option in xl shutdown
Ian Campbell writes ("[Xen-devel] [PATCH] xl: support -w (wait) option in xl shutdown"):> # HG changeset patch > # User Ian Campbell <ian.campbell@citrix.com> > # Date 1288094528 -3600 > # Node ID 29aeb30b8488e2a25d38dee16d88b6d9efa72c21 > # Parent 1d07e53e60e5414919f76296500bc138ab971f9b > xl: support -w (wait) option in xl shutdown > > improves compatibility with xm.Marvellous, applied, thanks. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel