From nobody Mon Dec 2 13:51:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728463232; cv=none; d=zohomail.com; s=zohoarc; b=LbTxr78IU7/fSEtKwPJP2TGYWAa6TfZk2XJvAHcp3PC7WhjRVK3tQzWsfO4lKsKXP5oC9FZgLU0ldGB8G2UP1BIlcEvgsdyH++1SsBRTgM5Fe1Fe2eLwsz9t5rWVWPegVumd870IkajB3zWhPffTykbnDyMDOLWLV4hBytYuDag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728463232; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aOuSbBaYBdDOGGWMn9gqpOjH0y5Y7jL5jQiHg5Kot78=; b=DtaLWj8f7qg02tSCEBxmZmX6om60maNhTORIYVmb2xneWwglxE3zrjscpvdRn+A0luGTKigyd50vRG4qEboFYwgKnKVAQw3d0VH4pT7niDI+e0sf+ChYhGKCKNSrjbWLX7xPr+RINKfQImO2Xvjhj488k/l+bcBefeV3dnNHIlo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728463232214926.2290850990385; Wed, 9 Oct 2024 01:40:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sySEk-0002uk-7W; Wed, 09 Oct 2024 04:40:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sySEh-0002u6-Gn for qemu-devel@nongnu.org; Wed, 09 Oct 2024 04:39:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sySEf-0001KC-Qb for qemu-devel@nongnu.org; Wed, 09 Oct 2024 04:39:59 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-665-j4_OSMsZM5eoA2SonIY9jg-1; Wed, 09 Oct 2024 04:39:53 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 28C2C1944DE4; Wed, 9 Oct 2024 08:39:51 +0000 (UTC) Received: from localhost (unknown [10.39.208.46]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A054130001A8; Wed, 9 Oct 2024 08:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728463197; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aOuSbBaYBdDOGGWMn9gqpOjH0y5Y7jL5jQiHg5Kot78=; b=f3NS0/86SMboiJ/Bvj9ItwOo1pL5Fg0DR+G7jryA+G7X1Dc9+lkfKjkoJ3j0hoYHz2hvVc 247h2OfCQNk8PSw8YP/dldwExdcJ+xnHok3YNzeLh30ngeMDQSCv7ixW8WtlGjLfSw1+MM ATRmxJFLENNI4pY6llo5lRrE3ehMfnE= X-MC-Unique: j4_OSMsZM5eoA2SonIY9jg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Eric Blake , Paolo Bonzini , devel@lists.libvirt.org, peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Daniil Tatianin Subject: [PULL 1/2] chardev: introduce 'reconnect-ms' and deprecate 'reconnect' Date: Wed, 9 Oct 2024 12:39:37 +0400 Message-ID: <20241009083938.1504695-2-marcandre.lureau@redhat.com> In-Reply-To: <20241009083938.1504695-1-marcandre.lureau@redhat.com> References: <20241009083938.1504695-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728463233727116600 Content-Type: text/plain; charset="utf-8" From: Daniil Tatianin The 'reconnect' option only allows to specify the time in seconds, which is way too long for certain workflows. We have a lightweight disk backend server, which takes about 20ms to live update, but due to this limitation in QEMU, previously the guest disk controller would hang for one second because it would take this long for QEMU to reinitialize the socket connection. Introduce a new option called 'reconnect-ms', which is the same as 'reconnect', except the value is treated as milliseconds. These are mutually exclusive and specifying both results in an error. 'reconnect' is also deprecated by this commit to make it possible to remove it in the future as to not keep two options that control the same thing. Reviewed-by: Vladimir Sementsov-Ogievskiy Acked-by: Peter Krempa Signed-off-by: Daniil Tatianin Acked-by: Markus Armbruster Tested-by: Markus Armbruster Message-ID: <20240913094604.269135-1-d-tatianin@yandex-team.ru> --- docs/about/deprecated.rst | 6 ++++++ qapi/char.json | 17 +++++++++++++++-- include/chardev/char-socket.h | 2 +- chardev/char-socket.c | 33 ++++++++++++++++++++++++--------- chardev/char.c | 3 +++ 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index c02bbb66f7..82bb4927e8 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -394,6 +394,12 @@ Backend ``memory`` (since 9.0) =20 ``memory`` is a deprecated synonym for ``ringbuf``. =20 +``reconnect`` (since 9.2) +^^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``reconnect`` option only allows specifiying second granularity timeou= ts, +which is not enough for all types of use cases, use ``reconnect-ms`` inste= ad. + CPU device properties ''''''''''''''''''''' =20 diff --git a/qapi/char.json b/qapi/char.json index 0d6de1ee35..42eda4f98b 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -273,7 +273,19 @@ # # @reconnect: For a client socket, if a socket is disconnected, then # attempt a reconnect after the given number of seconds. Setting -# this to zero disables this function. (default: 0) (Since: 2.2) +# this to zero disables this function. The use of this member is +# deprecated, use @reconnect-ms instead. (default: 0) (Since: 2.2) +# +# @reconnect-ms: For a client socket, if a socket is disconnected, +# then attempt a reconnect after the given number of milliseconds. +# Setting this to zero disables this function. This member is +# mutually exclusive with @reconnect. +# (default: 0) (Since: 9.2) +# +# Features: +# +# @deprecated: Member @reconnect is deprecated. Use @reconnect-ms +# instead. # # Since: 1.4 ## @@ -287,7 +299,8 @@ '*telnet': 'bool', '*tn3270': 'bool', '*websocket': 'bool', - '*reconnect': 'int' }, + '*reconnect': { 'type': 'int', 'features': [ 'deprecated' ] }, + '*reconnect-ms': 'int' }, 'base': 'ChardevCommon' } =20 ## diff --git a/include/chardev/char-socket.h b/include/chardev/char-socket.h index 0708ca6fa9..d6d13ad37f 100644 --- a/include/chardev/char-socket.h +++ b/include/chardev/char-socket.h @@ -74,7 +74,7 @@ struct SocketChardev { bool is_websock; =20 GSource *reconnect_timer; - int64_t reconnect_time; + int64_t reconnect_time_ms; bool connect_err_reported; =20 QIOTask *connect_task; diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1ca9441b1b..91496ceda9 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -74,7 +74,7 @@ static void qemu_chr_socket_restart_timer(Chardev *chr) assert(!s->reconnect_timer); name =3D g_strdup_printf("chardev-socket-reconnect-%s", chr->label); s->reconnect_timer =3D qemu_chr_timeout_add_ms(chr, - s->reconnect_time * 1000, + s->reconnect_time_ms, socket_reconnect_timeout, chr); g_source_set_name(s->reconnect_timer, name); @@ -481,7 +481,7 @@ static void tcp_chr_disconnect_locked(Chardev *chr) if (emit_close) { qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } - if (s->reconnect_time && !s->reconnect_timer) { + if (s->reconnect_time_ms && !s->reconnect_timer) { qemu_chr_socket_restart_timer(chr); } } @@ -1080,9 +1080,9 @@ static int tcp_chr_wait_connected(Chardev *chr, Error= **errp) } else { Error *err =3D NULL; if (tcp_chr_connect_client_sync(chr, &err) < 0) { - if (s->reconnect_time) { + if (s->reconnect_time_ms) { error_free(err); - g_usleep(s->reconnect_time * 1000ULL * 1000ULL); + g_usleep(s->reconnect_time_ms * 1000ULL); } else { error_propagate(errp, err); return -1; @@ -1267,13 +1267,13 @@ skip_listen: =20 =20 static int qmp_chardev_open_socket_client(Chardev *chr, - int64_t reconnect, + int64_t reconnect_ms, Error **errp) { SocketChardev *s =3D SOCKET_CHARDEV(chr); =20 - if (reconnect > 0) { - s->reconnect_time =3D reconnect; + if (reconnect_ms > 0) { + s->reconnect_time_ms =3D reconnect_ms; tcp_chr_connect_client_async(chr); return 0; } else { @@ -1354,6 +1354,12 @@ static bool qmp_chardev_validate_socket(ChardevSocke= t *sock, } } =20 + if (sock->has_reconnect_ms && sock->has_reconnect) { + error_setg(errp, + "'reconnect' and 'reconnect-ms' are mutually exclusive"); + return false; + } + return true; } =20 @@ -1371,7 +1377,7 @@ static void qmp_chardev_open_socket(Chardev *chr, bool is_tn3270 =3D sock->has_tn3270 ? sock->tn3270 : false; bool is_waitconnect =3D sock->has_wait ? sock->wait : false; bool is_websock =3D sock->has_websocket ? sock->websocket : false; - int64_t reconnect =3D sock->has_reconnect ? sock->reconnect : 0; + int64_t reconnect_ms =3D 0; SocketAddress *addr; =20 s->is_listen =3D is_listen; @@ -1443,7 +1449,13 @@ static void qmp_chardev_open_socket(Chardev *chr, return; } } else { - if (qmp_chardev_open_socket_client(chr, reconnect, errp) < 0) { + if (sock->has_reconnect) { + reconnect_ms =3D sock->reconnect * 1000ULL; + } else if (sock->has_reconnect_ms) { + reconnect_ms =3D sock->reconnect_ms; + } + + if (qmp_chardev_open_socket_client(chr, reconnect_ms, errp) < 0) { return; } } @@ -1509,6 +1521,9 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, sock->wait =3D qemu_opt_get_bool(opts, "wait", true); sock->has_reconnect =3D qemu_opt_find(opts, "reconnect"); sock->reconnect =3D qemu_opt_get_number(opts, "reconnect", 0); + sock->has_reconnect_ms =3D qemu_opt_find(opts, "reconnect-ms"); + sock->reconnect_ms =3D qemu_opt_get_number(opts, "reconnect-ms", 0); + sock->tls_creds =3D g_strdup(qemu_opt_get(opts, "tls-creds")); sock->tls_authz =3D g_strdup(qemu_opt_get(opts, "tls-authz")); =20 diff --git a/chardev/char.c b/chardev/char.c index ba847b6e9e..35623c78a3 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -888,6 +888,9 @@ QemuOptsList qemu_chardev_opts =3D { },{ .name =3D "reconnect", .type =3D QEMU_OPT_NUMBER, + },{ + .name =3D "reconnect-ms", + .type =3D QEMU_OPT_NUMBER, },{ .name =3D "telnet", .type =3D QEMU_OPT_BOOL, --=20 2.47.0 From nobody Mon Dec 2 13:51:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1728463249; cv=none; d=zohomail.com; s=zohoarc; b=Dh+yUaGVPTkEdBIafrtik7GTb9WPNNZIjwFi8n7/V2PVQ7E7W1jKagCL2/8aXNBwDxi54GWDTEZKscHmFCSwx5YUa+elTx9JID3iRNyCsFhjsrLLa0izDfn05Gkpp+trheqNN3KfMPqkzRrfHG3gJPy6QoH7IcpxJpImyQVswBc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1728463249; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gwaHK/7FZjHwmu40oHbMCV+EFf1UdvIeS3hnoy1lHNU=; b=W6/J45NC8Tks0U/hK5VaD+8+WsyA+VIJG//4wWrirnZH/iBE4LvMFOoK+Q3V1BKiVfLZcdNuhCEatkergZ9aKfZZzESZpuKt4h7EceSIXE2DOQmhDI7Pg8ZRngvvO+Kr5y1w+26xZlPnwngm56wOWIQMAbZ8Y0Jyg5Jug4Nxypo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1728463249640744.9442736530931; Wed, 9 Oct 2024 01:40:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sySEx-00032A-8H; Wed, 09 Oct 2024 04:40:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sySEn-0002v4-Ol for qemu-devel@nongnu.org; Wed, 09 Oct 2024 04:40:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sySEl-0001LW-QE for qemu-devel@nongnu.org; Wed, 09 Oct 2024 04:40:05 -0400 Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-689-9QgfFwaVMnSlDCgAP8NMHQ-1; Wed, 09 Oct 2024 04:39:58 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1B8601985119; Wed, 9 Oct 2024 08:39:56 +0000 (UTC) Received: from localhost (unknown [10.39.208.46]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EA324300018D; Wed, 9 Oct 2024 08:39:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728463202; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gwaHK/7FZjHwmu40oHbMCV+EFf1UdvIeS3hnoy1lHNU=; b=arMj7FX0hgzCTsi5WxwXg8sMjXk0NBPlIp6ju57Oo9APKg8dH/QP08qY0+Ne4pm4Au5deG chzJz2GmHqomyEKTgm0Ily7VhTszpvM+Jbi9Itjr7i3ojeAfNWv0mX+QUuYXpdRWQlgepI tlFRQili6n3kz3nzenOV9/uJH0ntyO4= X-MC-Unique: 9QgfFwaVMnSlDCgAP8NMHQ-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: Markus Armbruster , Eric Blake , Paolo Bonzini , devel@lists.libvirt.org, peter.maydell@linaro.org, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Octavian Purdila , Paulo Neves Subject: [PULL 2/2] chardev: add path option for pty backend Date: Wed, 9 Oct 2024 12:39:38 +0400 Message-ID: <20241009083938.1504695-3-marcandre.lureau@redhat.com> In-Reply-To: <20241009083938.1504695-1-marcandre.lureau@redhat.com> References: <20241009083938.1504695-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.151, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1728463252038116600 From: Octavian Purdila Add path option to the pty char backend which will create a symbolic link to the given path that points to the allocated PTY. This avoids having to make QMP or HMP monitor queries to find out what the new PTY device path is. Based on patch from Paulo Neves: https://patchew.org/QEMU/1548509635-15776-1-git-send-email-ptsneves@gmail.c= om/ Tested with the following invocations that the link is created and removed when qemu stops: qemu-system-x86_64 -nodefaults -mon chardev=3Dcompat_monitor \ -chardev pty,path=3Dtest,id=3Dcompat_monitor0 qemu-system-x86_64 -nodefaults -monitor pty:test # check QMP invocation with path set qemu-system-x86_64 -nodefaults -qmp tcp:localhost:4444,server=3Don,wait= =3Doff nc localhost 4444 > {"execute": "qmp_capabilities"} > {"execute": "chardev-add", "arguments": {"id": "bar", "backend": { "type": "pty", "data": {"path": "test" }}}} # check QMP invocation with path not set qemu-system-x86_64 -nodefaults -qmp tcp:localhost:4444,server=3Don,wait= =3Doff nc localhost 4444 > {"execute": "qmp_capabilities"} > {"execute": "chardev-add", "arguments": {"id": "bar", "backend": { "type": "pty", "data": {}}}} Also tested that when a link path is not passed invocations still work, e.g= .: qemu-system-x86_64 -monitor pty Co-authored-by: Paulo Neves Signed-off-by: Paulo Neves [OP: rebase and address original patch review comments] Signed-off-by: Octavian Purdila Reviewed-by: Marc-Andr=C3=A9 Lureau Message-ID: <20240806010735.2450555-1-tavip@google.com> --- qapi/char.json | 27 ++++++++++++++++++++++++++- chardev/char-pty.c | 33 +++++++++++++++++++++++++++++++++ chardev/char.c | 5 +++++ qemu-options.hx | 33 +++++++++++++++++++++++++++------ 4 files changed, 91 insertions(+), 7 deletions(-) diff --git a/qapi/char.json b/qapi/char.json index 42eda4f98b..e045354350 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -444,6 +444,20 @@ 'base': 'ChardevCommon', 'if': 'CONFIG_SPICE_PROTOCOL' } =20 +## +# @ChardevPty: +# +# Configuration info for pty implementation. +# +# @path: optional path to create a symbolic link that points to the +# allocated PTY +# +# Since: 9.2 +## +{ 'struct': 'ChardevPty', + 'data': { '*path': 'str' }, + 'base': 'ChardevCommon' } + ## # @ChardevBackendKind: # @@ -655,6 +669,17 @@ { 'struct': 'ChardevRingbufWrapper', 'data': { 'data': 'ChardevRingbuf' } } =20 + +## +# @ChardevPtyWrapper: +# +# @data: Configuration info for pty chardevs +# +# Since: 9.2 +## +{ 'struct': 'ChardevPtyWrapper', + 'data': { 'data': 'ChardevPty' } } + ## # @ChardevBackend: # @@ -675,7 +700,7 @@ 'pipe': 'ChardevHostdevWrapper', 'socket': 'ChardevSocketWrapper', 'udp': 'ChardevUdpWrapper', - 'pty': 'ChardevCommonWrapper', + 'pty': 'ChardevPtyWrapper', 'null': 'ChardevCommonWrapper', 'mux': 'ChardevMuxWrapper', 'msmouse': 'ChardevCommonWrapper', diff --git a/chardev/char-pty.c b/chardev/char-pty.c index cc2f7617fe..cbb21b76ae 100644 --- a/chardev/char-pty.c +++ b/chardev/char-pty.c @@ -29,6 +29,7 @@ #include "qemu/sockets.h" #include "qemu/error-report.h" #include "qemu/module.h" +#include "qemu/option.h" #include "qemu/qemu-print.h" =20 #include "chardev/char-io.h" @@ -41,6 +42,7 @@ struct PtyChardev { =20 int connected; GSource *timer_src; + char *path; }; typedef struct PtyChardev PtyChardev; =20 @@ -204,6 +206,12 @@ static void char_pty_finalize(Object *obj) Chardev *chr =3D CHARDEV(obj); PtyChardev *s =3D PTY_CHARDEV(obj); =20 + /* unlink symlink */ + if (s->path) { + unlink(s->path); + g_free(s->path); + } + pty_chr_state(chr, 0); object_unref(OBJECT(s->ioc)); pty_chr_timer_cancel(s); @@ -330,6 +338,7 @@ static void char_pty_open(Chardev *chr, int master_fd, slave_fd; char pty_name[PATH_MAX]; char *name; + char *path =3D backend->u.pty.data->path; =20 master_fd =3D qemu_openpty_raw(&slave_fd, pty_name); if (master_fd < 0) { @@ -354,12 +363,36 @@ static void char_pty_open(Chardev *chr, g_free(name); s->timer_src =3D NULL; *be_opened =3D false; + + /* create symbolic link */ + if (path) { + int res =3D symlink(pty_name, path); + + if (res !=3D 0) { + error_setg_errno(errp, errno, "Failed to create PTY symlink"); + } else { + s->path =3D g_strdup(path); + } + } +} + +static void char_pty_parse(QemuOpts *opts, ChardevBackend *backend, + Error **errp) +{ + const char *path =3D qemu_opt_get(opts, "path"); + ChardevPty *pty; + + backend->type =3D CHARDEV_BACKEND_KIND_PTY; + pty =3D backend->u.pty.data =3D g_new0(ChardevPty, 1); + qemu_chr_parse_common(opts, qapi_ChardevPty_base(pty)); + pty->path =3D g_strdup(path); } =20 static void char_pty_class_init(ObjectClass *oc, void *data) { ChardevClass *cc =3D CHARDEV_CLASS(oc); =20 + cc->parse =3D char_pty_parse; cc->open =3D char_pty_open; cc->chr_write =3D char_pty_chr_write; cc->chr_update_read_handler =3D pty_chr_update_read_handler; diff --git a/chardev/char.c b/chardev/char.c index 35623c78a3..c0cc52824b 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -428,6 +428,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, con= st char *filename, qemu_opt_set(opts, "path", p, &error_abort); return opts; } + if (strstart(filename, "pty:", &p)) { + qemu_opt_set(opts, "backend", "pty", &error_abort); + qemu_opt_set(opts, "path", p, &error_abort); + return opts; + } if (strstart(filename, "tcp:", &p) || strstart(filename, "telnet:", &p) || strstart(filename, "tn3270:", &p) || diff --git a/qemu-options.hx b/qemu-options.hx index 20a1ce0d43..d5afefe5b6 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3712,7 +3712,7 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, "-chardev console,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend= =3Don|off]\n" "-chardev serial,id=3Did,path=3Dpath[,mux=3Don|off][,logfile=3DPATH][,= logappend=3Don|off]\n" #else - "-chardev pty,id=3Did[,mux=3Don|off][,logfile=3DPATH][,logappend=3Don|= off]\n" + "-chardev pty,id=3Did[,path=3Dpath][,mux=3Don|off][,logfile=3DPATH][,l= ogappend=3Don|off]\n" "-chardev stdio,id=3Did[,mux=3Don|off][,signal=3Don|off][,logfile=3DPA= TH][,logappend=3Don|off]\n" #endif #ifdef CONFIG_BRLAPI @@ -3951,12 +3951,22 @@ The available backends are: =20 ``path`` specifies the name of the serial device to open. =20 -``-chardev pty,id=3Did`` - Create a new pseudo-terminal on the host and connect to it. ``pty`` - does not take any options. +``-chardev pty,id=3Did[,path=3Dpath]`` + Create a new pseudo-terminal on the host and connect to it. =20 ``pty`` is not available on Windows hosts. =20 + If ``path`` is specified, QEMU will create a symbolic link at + that location which points to the new PTY device. + + This avoids having to make QMP or HMP monitor queries to find out + what the new PTY device path is. + + Note that while QEMU will remove the symlink when it exits + gracefully, it will not do so in case of crashes or on certain + startup errors. It is recommended that the user checks and removes + the symlink after QEMU terminates to account for this. + ``-chardev stdio,id=3Did[,signal=3Don|off]`` Connect to standard input and standard output of the QEMU process. =20 @@ -4314,8 +4324,19 @@ SRST =20 vc:80Cx24C =20 - ``pty`` - [Linux only] Pseudo TTY (a new PTY is automatically allocated) + ``pty[:path]`` + [Linux only] Pseudo TTY (a new PTY is automatically allocated). + + If ``path`` is specified, QEMU will create a symbolic link at + that location which points to the new PTY device. + + This avoids having to make QMP or HMP monitor queries to find + out what the new PTY device path is. + + Note that while QEMU will remove the symlink when it exits + gracefully, it will not do so in case of crashes or on certain + startup errors. It is recommended that the user checks and + removes the symlink after QEMU terminates to account for this. =20 ``none`` No device is allocated. Note that for machine types which --=20 2.47.0