From nobody Sun Nov 24 03:36:23 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=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1726220810; cv=none; d=zohomail.com; s=zohoarc; b=SMGruDzGzcNBh/6ySpr5f0pr49/xB7M/SyWzziKpeW9tPakxvHiZPTlVoC6lOwyPiMCb4jCwwNQf/K6OW0Xi/e5jtqbgGP3ud4fYDOrypuXmF1vqfGNumZURVzmgXJW6WXwrqWIRvOGqj6CZ2ONiNMhpBon2g/YEu53GYM8Abgs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726220810; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FK6qn4h8Kpstus0Ea7EXTfjFnpuIfQI2yZTMfG9QD0s=; b=hRiWUe1rsNkG9YuscZz0KWwkizbtGXcn91I7LfcquD5za5mtkB/e2cnF1QeyR+6oNkuqwilDP5KMYpROhKuj8astOvfzNI0UjOpGXvC882CYD6uCxi4voMJ0QYvFc2rNEkWXfGX4mSYlvMkA+WiTa9eMT7Ni9hz66vEO6qHKScQ= 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 1726220809692472.0661945756559; Fri, 13 Sep 2024 02:46:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sp2sn-0006e4-WD; Fri, 13 Sep 2024 05:46:30 -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 1sp2sh-0006cn-5P for qemu-devel@nongnu.org; Fri, 13 Sep 2024 05:46:26 -0400 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sp2sd-0006VX-WA for qemu-devel@nongnu.org; Fri, 13 Sep 2024 05:46:22 -0400 Received: from mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net [IPv6:2a02:6b8:c12:42af:0:640:8187:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 6AFB160D6C; Fri, 13 Sep 2024 12:46:12 +0300 (MSK) Received: from d-tatianin-lin.yandex-team.ru (unknown [2a02:6b8:b081:b644::1:2c]) by mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 8khGTP1gweA0-QdbJmDTj; Fri, 13 Sep 2024 12:46:11 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1726220771; bh=FK6qn4h8Kpstus0Ea7EXTfjFnpuIfQI2yZTMfG9QD0s=; h=Message-Id:Date:Cc:Subject:To:From; b=G53LAuyJ+EM0Q3BEkZz6HVQPiQESQVu/dn8qGD4lLUvP06v5GKK4O8dGT5PbZmqcI 3i0c+0PRM0XLvs1kk1ANILwNHcUSm1PFJcrEG02bO0j6fXgxkJZKkOyvJRgREWdGgP dokcrxQA1ANqf+/1eAlNP/RPnV52jXI82gcgYfug= Authentication-Results: mail-nwsmtp-smtp-corp-main-26.myt.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Daniil Tatianin To: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Cc: Daniil Tatianin , Paolo Bonzini , Eric Blake , Markus Armbruster , qemu-devel@nongnu.org, devel@lists.libvirt.org, Peter Krempa , Michal Privoznik , Vladimir Sementsov-Ogievskiy Subject: [PATCH v2] chardev: introduce 'reconnect-ms' and deprecate 'reconnect' Date: Fri, 13 Sep 2024 12:46:04 +0300 Message-Id: <20240913094604.269135-1-d-tatianin@yandex-team.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c02:900:1:45:d181:df01; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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 @yandex-team.ru) X-ZM-MESSAGEID: 1726220812268116600 Content-Type: text/plain; charset="utf-8" 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 --- Changes since v0: - Mention the deprecation in docs (Paolo) Changes since v1: - Move option validation to qmp_chardev_validate_socket as qemu_chr_parse_s= ocket is only called for the command line and not QMP. (thanks to Markus Armbru= ster for spotting) --- chardev/char-socket.c | 33 ++++++++++++++++++++++++--------- chardev/char.c | 3 +++ docs/about/deprecated.rst | 6 ++++++ include/chardev/char-socket.h | 2 +- qapi/char.json | 17 +++++++++++++++-- 5 files changed, 49 insertions(+), 12 deletions(-) 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, diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst index 88f0f03786..e5db9bc6e9 100644 --- a/docs/about/deprecated.rst +++ b/docs/about/deprecated.rst @@ -430,6 +430,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/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/qapi/char.json b/qapi/char.json index ef58445cee..7f117438c6 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 ## --=20 2.34.1