From patchwork Tue Mar 3 13:28:20 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: 11418003 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 1A5C8930 for ; Tue, 3 Mar 2020 13:30:01 +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 EAD8320838 for ; Tue, 3 Mar 2020 13:30:00 +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="2Qk2Xdgk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EAD8320838 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 1j97bU-00019D-P5; Tue, 03 Mar 2020 13:28:56 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j97bT-000196-8d for xen-devel@lists.xenproject.org; Tue, 03 Mar 2020 13:28:55 +0000 X-Inumbo-ID: ed5e40dc-5d52-11ea-94a0-bc764e2007e4 Received: from wout1-smtp.messagingengine.com (unknown [64.147.123.24]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ed5e40dc-5d52-11ea-94a0-bc764e2007e4; Tue, 03 Mar 2020 13:28:54 +0000 (UTC) Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.west.internal (Postfix) with ESMTP id 0FB9D9E8; Tue, 3 Mar 2020 08:28:52 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 03 Mar 2020 08:28:53 -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=aS9F76 Oi7vp/c9LnNBN1DALsqeSMFwjmhcbBXNME9pU=; b=2Qk2Xdgk+iOxdnPJolbPRq 6mr8gsQ08pOuSu1nf+xAMtKp/gekfoUmxu8wiGlukcfKY2oMCZ9fzLFz14v3cDnO PKxU97EG4QMxF3k41hiGsrzH1V4CApk1v/ukngnh/uvCz2QeIrnjoHvCuoqqGOuY KRIxP300HHoeE+dkJWwsNIEGx3OmGbZRT1GgSG5ryQrNjHI6cDwkQL4qcYjIiAp3 HrbQjHJR6QbxqXxUzi2qT8c9lmfFwonfJqPEqjKQdw1DwEbuUd35rZU8IcrHfgHV 5tIaixl8bCOW+7SRUM0CvnIkgkkURVDhp7UsTjf3yHRimCGKO5bkbOb82ZXO/Ztg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedruddtiedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffogggtgfesthekredtredtjeenucfhrhhomheprfgrfigvlhcu ofgrrhgtiigvfihskhhiuceophgrfigvlhesihhnvhhishhisghlvghthhhinhhgshhlrg gsrdgtohhmqeenucfkphepjeekrdehgedrvdehgedrjedunecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphgrfigvlhesihhnvhhishhisghlvg hthhhinhhgshhlrggsrdgtohhm X-ME-Proxy: Received: from localhost.localdomain (x4e36fe47.dyn.telefonica.de [78.54.254.71]) by mail.messagingengine.com (Postfix) with ESMTPA id 952883280064; Tue, 3 Mar 2020 08:28:51 -0500 (EST) From: =?utf-8?q?Pawe=C5=82_Marczewski?= To: xen-devel@lists.xenproject.org Date: Tue, 3 Mar 2020 14:28:20 +0100 Message-Id: X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 Subject: [Xen-devel] [XEN PATCH v4] 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 the path doesn't become available after LIBXL_INIT_TIMEOUT seconds, fail the domain creation. If we skip the bootloader, the TTY path will be set by 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 Reviewed-by: Anthony PERARD --- Changed since v3 (after review by Anthony Perard): * use libxl__console_tty_path * move console_xswait_callback to proper place in file * refactor console_xswait_callback so that it has a single "out" section * move xswait_init to proper function (initiate_domain_create) * add xswait_stop to cleanup (domcreate_complete) * mention in commit message that we fail after a timeout Changed since v2 (after review by Marek Marczykowski-Górecki): * replace hardcoded value with LIBXL_INIT_TIMEOUT Changed since v1: * use xswait mechanism to add a timeout tools/libxl/libxl_console.c | 4 +-- tools/libxl/libxl_create.c | 50 ++++++++++++++++++++++++++++++++++-- tools/libxl/libxl_internal.h | 3 +++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/tools/libxl/libxl_console.c b/tools/libxl/libxl_console.c index 088a455b52..047d23d7ae 100644 --- a/tools/libxl/libxl_console.c +++ b/tools/libxl/libxl_console.c @@ -16,8 +16,8 @@ #include "libxl_internal.h" -static int libxl__console_tty_path(libxl__gc *gc, uint32_t domid, int cons_num, - libxl_console_type type, char **tty_path) +int libxl__console_tty_path(libxl__gc *gc, uint32_t domid, int cons_num, + libxl_console_type type, char **tty_path) { int rc; char *dom_path; diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 3a7364e2ac..ada942bc8d 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -846,6 +846,8 @@ static void domcreate_devmodel_started(libxl__egc *egc, static void domcreate_attach_devices(libxl__egc *egc, libxl__multidev *multidev, int ret); +static void console_xswait_callback(libxl__egc *egc, libxl__xswait_state *xswa, + int rc, const char *p); /* Our own function to clean up and call the user's callback. * The final call in the sequence. */ @@ -1151,6 +1153,8 @@ static void initiate_domain_create(libxl__egc *egc, if (ret) goto error_out; + libxl__xswait_init(&dcs->console_xswait); + if (restore_fd >= 0 || dcs->soft_reset) { LOGD(DEBUG, domid, "restoring, not running bootloader"); domcreate_bootloader_done(egc, &dcs->bl, 0); @@ -1705,6 +1709,7 @@ static void domcreate_attach_devices(libxl__egc *egc, int domid = dcs->guest_domid; libxl_domain_config *const d_config = dcs->guest_config; const libxl__device_type *dt; + char *tty_path; if (ret) { LOGD(ERROR, domid, "unable to add %s devices", @@ -1728,9 +1733,24 @@ static void domcreate_attach_devices(libxl__egc *egc, return; } - domcreate_console_available(egc, dcs); + ret = libxl__console_tty_path(gc, domid, 0, LIBXL_CONSOLE_TYPE_PV, &tty_path); + if (ret) { + LOG(ERROR, "failed to get domain %d console tty path", + domid); + goto error_out; + } - domcreate_complete(egc, dcs, 0); + dcs->console_xswait.ao = ao; + dcs->console_xswait.what = GCSPRINTF("domain %d console tty", domid); + dcs->console_xswait.path = tty_path; + dcs->console_xswait.timeout_ms = LIBXL_INIT_TIMEOUT * 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 tty path", + domid); + goto error_out; + } return; @@ -1739,6 +1759,30 @@ error_out: domcreate_complete(egc, dcs, ret); } +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); + + if (rc) { + if (rc == ERROR_TIMEDOUT) + LOG(ERROR, "%s: timed out", xswa->what); + goto out; + } + + if (p && p[0] != '\0') { + domcreate_console_available(egc, dcs); + goto out; + } + + return; + +out: + libxl__xswait_stop(gc, xswa); + domcreate_complete(egc, dcs, rc); +} + static void domcreate_complete(libxl__egc *egc, libxl__domain_create_state *dcs, int rc) @@ -1747,6 +1791,8 @@ static void domcreate_complete(libxl__egc *egc, libxl_domain_config *const d_config = dcs->guest_config; libxl_domain_config *d_config_saved = &dcs->guest_config_saved; + libxl__xswait_stop(gc, &dcs->console_xswait); + libxl__domain_build_state_dispose(&dcs->build_state); if (!rc && d_config->b_info.exec_ssidref) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 4936446069..19d11cc6d6 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1517,6 +1517,8 @@ _hidden char *libxl__domain_device_libxl_path(libxl__gc *gc, uint32_t domid, uin libxl__device_kind device_kind); _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path, libxl__device *dev); +_hidden int libxl__console_tty_path(libxl__gc *gc, uint32_t domid, int cons_num, + libxl_console_type type, char **tty_path); _hidden int libxl__device_destroy(libxl__gc *gc, libxl__device *dev); _hidden int libxl__wait_for_backend(libxl__gc *gc, const char *be_path, const char *state); @@ -4180,6 +4182,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,