From nobody Sat May 18 23:55:16 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1582205527; cv=none; d=zohomail.com; s=zohoarc; b=aYbiN4i39suMY17xRlsUW1Uo8OAjY0ZYSdkbbpdIL+4bAlEWiW46YlYZbtPDmpksxgTgo+XywwdMXrry1q2UP8zSYocEL/5s/jWTUUX87e8sYn37pNSgtn/yhPAuuOU8E8N/YDT7oZCIb4XKbJMFIZeMp95rn0Y21qFx1FwqYno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582205527; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=/NhF1V9MbiZJCmyWA0dL+ZifQNckVipqXg55Xbsk8NA=; b=BT77WbLSyh7xy6aFpMdc5jU6iRIVYifcjOQfJ+IDPuE7o/xpOa9/G22gExiNYH5c7q2OiEtaKYwItptIKV8CfJ2tQdqfKm6YFmXsmow5+741Ljc/7ytLXq0jGyLUkRirwap1IvvLkdrhpscVdZmjmTI8lA7xBoaKZawevxXhXbA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582205527578992.6844668816253; Thu, 20 Feb 2020 05:32:07 -0800 (PST) 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 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 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) X-Inumbo-ID: 4b2ca388-53e5-11ea-bc8e-bc764e2007e4 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: From: =?UTF-8?q?Pawe=C5=82=20Marczewski?= 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=20Marczewski?= , Ian Jackson , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C5=82 Marczewski Reviewed-by: Marek Marczykowski-G=C3=B3recki --- 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)); } =20 +static void console_xswait_callback(libxl__egc *egc, libxl__xswait_state *= xswa, + int rc, const char *p) +{ + EGC_GC; + libxl__domain_create_state *dcs =3D CONTAINER_OF(xswa, *dcs, console_x= swait); + char *dompath =3D libxl__xs_get_dompath(gc, dcs->guest_domid); + char *tty_path =3D GCSPRINTF("%s/console/tty", dompath); + char *tty; + + if (rc) { + if (rc =3D=3D ERROR_TIMEDOUT) + LOG(ERROR, "%s: timed out", xswa->what); + libxl__xswait_stop(gc, xswa); + domcreate_complete(egc, dcs, rc); + return; + } + + tty =3D libxl__xs_read(gc, XBT_NULL, tty_path); + + if (tty && tty[0] !=3D '\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; } =20 - domcreate_console_available(egc, dcs); - - domcreate_complete(egc, dcs, 0); + dcs->console_xswait.ao =3D ao; + dcs->console_xswait.what =3D GCSPRINTF("domain %d console tty", domid); + dcs->console_xswait.path =3D GCSPRINTF("%s/console/tty", + libxl__xs_get_dompath(gc, domid)); + dcs->console_xswait.timeout_ms =3D 10 * 1000; + dcs->console_xswait.callback =3D console_xswait_callback; + ret =3D 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; + } =20 return; =20 @@ -1861,6 +1897,7 @@ static int do_domain_create(libxl_ctx *ctx, libxl_dom= ain_config *d_config, =20 libxl__ao_progress_gethow(&cdcs->dcs.aop_console_how, aop_console_how); cdcs->domid_out =3D domid; + libxl__xswait_init(&cdcs->dcs.console_xswait); =20 initiate_domain_create(egc, &cdcs->dcs); =20 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; }; =20 _hidden int libxl__device_nic_set_devids(libxl__gc *gc, --=20 2.21.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel