From patchwork Fri Aug 5 17:41:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9265649 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5BAA660754 for ; Fri, 5 Aug 2016 17:43:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 516DF2842E for ; Fri, 5 Aug 2016 17:43:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4646428457; Fri, 5 Aug 2016 17:43:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D5D372842E for ; Fri, 5 Aug 2016 17:43:41 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVj7t-0001Vt-Ar; Fri, 05 Aug 2016 17:41:41 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVj7s-0001Uq-6Z for xen-devel@lists.xenproject.org; Fri, 05 Aug 2016 17:41:40 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 10/E3-05127-3DFC4A75; Fri, 05 Aug 2016 17:41:39 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupnkeJIrShJLcpLzFFi42JxWrohUvfS+SX hBgvmGlp83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBkf7t1hK5glU9Ex/QBLA+MjkS5GTg4JAX+J lxu3sIHYbALKEj87e8FsEQE9iaYDzxlBbGaBMomf/buYQWxhAWuJMy1dYHEWARWJlpafLCA2r 4CzxLvrjSwQM+Ukzh//CVTPwcEp4CJx+DIXSFgIqKRr0jNmCFtBomP6MSaIVkGJkzOfsECskp A4+OIFWKuEALfE3277CYx8s5BUzUJStYCRaRWjRnFqUVlqka6RmV5SUWZ6RkluYmaOrqGBqV5 uanFxYnpqTmJSsV5yfu4mRmBA1TMwMO5gvD3Z7xCjJAeTkiiv2r4l4UJ8SfkplRmJxRnxRaU5 qcWHGGU4OJQkeM+eA8oJFqWmp1akZeYAQxsmLcHBoyTCexskzVtckJhbnJkOkTrFqCglzpsCk hAASWSU5sG1weLpEqOslDAvIwMDgxBPQWpRbmYJqvwrRnEORiVh3ocgU3gy80rgpr8CWswEtP ijFdjikkSElFQDo8z3JKHfBe9eCM0+VqKkN0WoOcEhqFLryKqOnDl/DYW3Vd0N3x3++/ac6sV /De6xmXzdaV/w5N6dI1s5S/NX6ci3bjxuetS7L5bnHv/axZ2Cb9oW+wRm7zF9fPvIfKEH9o6u u0oPin7LqTcT7HsvHtO/On/bmpyAQ49SvjguP6/n465daWjaosRSnJFoqMVcVJwIAIBtCc2iA gAA X-Env-Sender: prvs=018563909=wei.liu2@citrix.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1470418896!51527285!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 37322 invoked from network); 5 Aug 2016 17:41:38 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-5.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 5 Aug 2016 17:41:38 -0000 X-IronPort-AV: E=Sophos;i="5.28,474,1464652800"; d="scan'208";a="370613667" From: Wei Liu To: Xen-devel Date: Fri, 5 Aug 2016 18:41:34 +0100 Message-ID: <1470418894-11358-7-git-send-email-wei.liu2@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1470418894-11358-1-git-send-email-wei.liu2@citrix.com> References: <1470418894-11358-1-git-send-email-wei.liu2@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Cc: Andrew Cooper , Ian Jackson , Wei Liu Subject: [Xen-devel] [PATCH v2 6/6] xl: use xenconsole startup protocol X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP If user asks xl to automatically connect to console when creating a guest, use the new startup protocol before trying to unpause domain so that we don't lose any console output. Signed-off-by: Wei Liu Acked-by: Ian Jackson --- v2: properly handle read(2) errors --- tools/libxl/xl_cmdimpl.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index 180fc8d..92002dc 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -2728,6 +2728,7 @@ static void autoconnect_console(libxl_ctx *ctx_ignored, libxl_event *ev, void *priv) { uint32_t bldomid = ev->domid; + int notify_fd = *(int*)priv; /* write end of the notification pipe */ libxl_event_free(ctx, ev); @@ -2740,7 +2741,7 @@ static void autoconnect_console(libxl_ctx *ctx_ignored, postfork(); sleep(1); - libxl_primary_console_exec(ctx, bldomid); + libxl_primary_console_exec(ctx, bldomid, notify_fd); /* Do not return. xl continued in child process */ perror("xl: unable to exec console client"); _exit(1); @@ -2810,6 +2811,7 @@ static int create_domain(struct domain_create *dom_info) int restore_fd_to_close = -1; int send_back_fd = -1; const libxl_asyncprogress_how *autoconnect_console_how; + int notify_pipe[2] = { -1, -1 }; struct save_file_header hdr; uint32_t domid_soft_reset = INVALID_DOMID; @@ -2997,7 +2999,15 @@ start: libxl_asyncprogress_how autoconnect_console_how_buf; if ( dom_info->console_autoconnect ) { + if (libxl_pipe(ctx, notify_pipe)) { + fprintf(stderr, + "Failed to create console notification pipe, errno %d\n", + errno); + ret = ERROR_FAIL; + goto error_out; + } autoconnect_console_how_buf.callback = autoconnect_console; + autoconnect_console_how_buf.for_callback = ¬ify_pipe[1]; autoconnect_console_how = &autoconnect_console_how_buf; }else{ autoconnect_console_how = 0; @@ -3047,6 +3057,33 @@ start: restore_fd_to_close = -1; } + if (autoconnect_console_how) { + char buf[1]; + int r; + + /* Try to get notification from xenconsole. Just move on if + * error occurs -- it's only minor annoyance if console + * doesn't show up. + */ + do { + r = read(notify_pipe[0], buf, 1); + } while (r == -1 && errno == EINTR); + + if (r == -1) + fprintf(stderr, + "Failed to get notification from xenconsole: %s\n", + strerror(errno)); + else if (r == 0) + fprintf(stderr, "Got EOF from xenconsole notification fd\n"); + else if (r == 1 && buf[0] != 0x00) + fprintf(stderr, "Got unexpected response from xenconsole: %x\n", + buf[0]); + + close(notify_pipe[0]); + close(notify_pipe[1]); + notify_pipe[0] = notify_pipe[1] = -1; + } + if (!paused) libxl_domain_unpause(ctx, domid); @@ -3754,9 +3791,9 @@ int main_console(int argc, char **argv) domid = find_domain(argv[optind]); if (!type) - libxl_primary_console_exec(ctx, domid); + libxl_primary_console_exec(ctx, domid, -1); else - libxl_console_exec(ctx, domid, num, type); + libxl_console_exec(ctx, domid, num, type, -1); fprintf(stderr, "Unable to attach console\n"); return EXIT_FAILURE; }