From patchwork Thu Feb 20 13:31:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pawe=C5=82_Marczewski?= X-Patchwork-Id: 11394175 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA8D7138D for ; Thu, 20 Feb 2020 13:32:33 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 96FFA206E2 for ; Thu, 20 Feb 2020 13:32:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bL1uyXvt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96FFA206E2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=invisiblethingslab.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4lvN-0006At-7B; Thu, 20 Feb 2020 13:31:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4lvL-0006Ao-In for xen-devel@lists.xenproject.org; Thu, 20 Feb 2020 13:31:27 +0000 X-Inumbo-ID: 4b2ca388-53e5-11ea-bc8e-bc764e2007e4 Received: from wout2-smtp.messagingengine.com (unknown [64.147.123.25]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 4b2ca388-53e5-11ea-bc8e-bc764e2007e4; Thu, 20 Feb 2020 13:31:26 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 3AE6D345; Thu, 20 Feb 2020 08:31:25 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 20 Feb 2020 08:31:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=C3kfas FJBEmWBmF/TW0tPGH++9JtUjNI6fnqWsoklGs=; b=bL1uyXvt9+/ZoMVNSTlrGG ycY3aVqS1v9PypNHp+WOD1vyLZpinR5EvNQGsZaNudU3sWw3CAnBOMKKgScfh4DR Xpk+tvTdy4BEdrdmnYF3O/w3zJoRXl4BrWMlLCBlw3jSLPS9wB13zr+le97OMPfJ FjA+bX0KnGln+PLFsGWpQHoYs2gL+bNRyMSKcxoZ4lwmkF0a4sRo9UiiloQz+tIj NrSfawdNsnJTynwmjatwdHadEwGveEVnGZUuFLx6NSSX2TPjPUTs/c6JSNWKUoa6 fH3SY0Es89ZPyryJdXr7jYzwXK0wbx15S84DAll+1Xf3mXp4/srgotAJVP9oz1Cg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrkedvgdehfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefhvffufffkofggtgfgsehtkeertdertdejnecuhfhrohhmpefrrgifvghlucfo rghrtgiivgifshhkihcuoehprgifvghlsehinhhvihhsihgslhgvthhhihhnghhslhgrsg drtghomheqnecuffhomhgrihhnpegtrhgvrghtihhonhdrthhoohhlshenucfkphepkeef rdeljedrvdefrddvleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehprgifvghlsehinhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomh X-ME-Proxy: Received: from localhost.localdomain (unknown [83.97.23.29]) by mail.messagingengine.com (Postfix) with ESMTPA id 9D3BE3280062; Thu, 20 Feb 2020 08:31:23 -0500 (EST) From: =?utf-8?q?Pawe=C5=82_Marczewski?= To: xen-devel@lists.xenproject.org Date: Thu, 20 Feb 2020 14:31:03 +0100 Message-Id: <6613fdc72f9e7c4a7eb29ae73c19db810501944f.1582203228.git.pawel@invisiblethingslab.com> X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH v2] libxl: wait for console path before firing console_available X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , =?utf-8?q?Pawe=C5=82_Marczew?= =?utf-8?q?ski?= , Ian Jackson , =?utf-8?q?Marek_Marczykowski-G?= =?utf-8?q?=C3=B3recki?= , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" If we skip the bootloader, the TTY path will be set for xenconsoled. However, there is no guarantee that this will happen by the time we want to call the console_available callback, so we have to wait. Signed-off-by: Paweł Marczewski Reviewed-by: Marek Marczykowski-Górecki --- Changed since v1: * use xswait mechanism to add a timeout As mentioned before, this is to fix a race condition that appears when using libxl via libvirt and not using bootloader (console_available fires too early). I have tested the patch on Qubes OS 4.1 (with Xen 4.13), and it seems to solve the problem. I also checked the timeout: when xenconsoled is stopped, libxl waits for 10 seconds and then aborts domain creation. tools/libxl/libxl_create.c | 43 +++++++++++++++++++++++++++++++++--- tools/libxl/libxl_internal.h | 1 + 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 3a7364e2ac..4b150d92b9 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -1190,6 +1190,33 @@ static void domcreate_console_available(libxl__egc *egc, dcs->aop_console_how.for_event)); } +static void console_xswait_callback(libxl__egc *egc, libxl__xswait_state *xswa, + int rc, const char *p) +{ + EGC_GC; + libxl__domain_create_state *dcs = CONTAINER_OF(xswa, *dcs, console_xswait); + char *dompath = libxl__xs_get_dompath(gc, dcs->guest_domid); + char *tty_path = GCSPRINTF("%s/console/tty", dompath); + char *tty; + + if (rc) { + if (rc == ERROR_TIMEDOUT) + LOG(ERROR, "%s: timed out", xswa->what); + libxl__xswait_stop(gc, xswa); + domcreate_complete(egc, dcs, rc); + return; + } + + tty = libxl__xs_read(gc, XBT_NULL, tty_path); + + if (tty && tty[0] != '\0') { + libxl__xswait_stop(gc, xswa); + + domcreate_console_available(egc, dcs); + domcreate_complete(egc, dcs, 0); + } +} + static void domcreate_bootloader_done(libxl__egc *egc, libxl__bootloader_state *bl, int rc) @@ -1728,9 +1755,18 @@ static void domcreate_attach_devices(libxl__egc *egc, return; } - domcreate_console_available(egc, dcs); - - domcreate_complete(egc, dcs, 0); + dcs->console_xswait.ao = ao; + dcs->console_xswait.what = GCSPRINTF("domain %d console tty", domid); + dcs->console_xswait.path = GCSPRINTF("%s/console/tty", + libxl__xs_get_dompath(gc, domid)); + dcs->console_xswait.timeout_ms = 10 * 1000; + dcs->console_xswait.callback = console_xswait_callback; + ret = libxl__xswait_start(gc, &dcs->console_xswait); + if (ret) { + LOG(ERROR, "unable to set up watch for domain %d console path", + domid); + goto error_out; + } return; @@ -1861,6 +1897,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_domain_config *d_config, libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how); cdcs->domid_out = domid; + libxl__xswait_init(&cdcs->dcs.console_xswait); initiate_domain_create(egc, &cdcs->dcs); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 4936446069..d8129417dc 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -4180,6 +4180,7 @@ struct libxl__domain_create_state { /* necessary if the domain creation failed and we have to destroy it */ libxl__domain_destroy_state dds; libxl__multidev multidev; + libxl__xswait_state console_xswait; }; _hidden int libxl__device_nic_set_devids(libxl__gc *gc,