From nobody Sun Nov 24 09:08:54 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=1723802921; cv=none; d=zohomail.com; s=zohoarc; b=COPxoOpuYWXWYRM7boCuuOxBrcGOx0BMl0jOQrXyKYt5CD3/LXrvJWqQXV53+vYyT7GMt340epZabyhaQ1DD8JvZ6jdRwo0d0FSFxuA8IJi/lxcA4IlDy8LRZjR7No/OuId558PLYFX2JPtTrH+QUyqfeexubk6fVLumCURdNYo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723802921; 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=MOrL4YLgzsNM6+Jo2KZEeZLSI3TzEzfFCKW7qPYGL+k=; b=JhfS9QkpnVz9D7Odb0u7CBwRTkMtSS/rxW48x0KBY6m+CH5u34X3y2Yndz/G1BJWSvwohskmghluhfz/M36+fC579lFxv8ed6Pf2TKcAhUhF2QVk2Wq5sDsqA8xjAXPKYRydNHvrhA3K/HkNN2FqRuOB5NXSl8ASTzOg11UTE8s= 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 1723802920773634.4288353918314; Fri, 16 Aug 2024 03:08:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1setrx-0004Vx-AP; Fri, 16 Aug 2024 06:07:41 -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 1setru-0004VK-Lo for qemu-devel@nongnu.org; Fri, 16 Aug 2024 06:07:38 -0400 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1setrr-0001iD-HK for qemu-devel@nongnu.org; Fri, 16 Aug 2024 06:07:38 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1c0f:0:640:cad:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id 68BEC60BB0; Fri, 16 Aug 2024 13:07:29 +0300 (MSK) Received: from d-tatianin-lin.yandex-team.ru (unknown [2a02:6b8:b081:b593::1:1f]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id O7GhxJ0gACg0-2j9T7cmM; Fri, 16 Aug 2024 13:07:28 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1723802848; bh=MOrL4YLgzsNM6+Jo2KZEeZLSI3TzEzfFCKW7qPYGL+k=; h=Message-Id:Date:Cc:Subject:To:From; b=I9lVKGFe7lf2UpygTcUOuCES4USRh5+PSGwdMTrAkEs/BIv8dlNOQeEIwswVPNAON a5MP+JGBZrUHA2UDyc9yhkwJOyjyJXLUtnRMMMti3bCLBn2mmVvpQqR1WoFqTjcWL9 Jc2SYKXCjmA2Mt84IPifDLC30VZpwcSOinvumgBw= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.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 Subject: [PATCH] chardev: allow specifying finer-grained reconnect timeouts Date: Fri, 16 Aug 2024 13:07:23 +0300 Message-Id: <20240816100723.2815-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:c41:1300:1:45:d181:df01; envelope-from=d-tatianin@yandex-team.ru; helo=forwardcorp1d.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, T_SCC_BODY_TEXT_LINE=-0.01 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: 1723802924625116600 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. Make it possible to specify a smaller timeout by treating the value in "reconnect" as milliseconds via the new "reconnect-is-ms" option. Signed-off-by: Daniil Tatianin --- chardev/char-socket.c | 7 +++++-- chardev/char.c | 3 +++ qapi/char.json | 12 +++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1ca9441b1b..d87859e641 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, socket_reconnect_timeout, chr); g_source_set_name(s->reconnect_timer, name); @@ -1082,7 +1082,7 @@ static int tcp_chr_wait_connected(Chardev *chr, Error= **errp) if (tcp_chr_connect_client_sync(chr, &err) < 0) { if (s->reconnect_time) { error_free(err); - g_usleep(s->reconnect_time * 1000ULL * 1000ULL); + g_usleep(s->reconnect_time * 1000ULL); } else { error_propagate(errp, err); return -1; @@ -1509,6 +1509,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); + if (!qemu_opt_get_bool(opts, "reconnect-is-ms", false)) { + sock->reconnect *=3D 1000ULL; + } 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 3c43fb1278..f6e5f1d5c9 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -859,6 +859,9 @@ QemuOptsList qemu_chardev_opts =3D { },{ .name =3D "reconnect", .type =3D QEMU_OPT_NUMBER, + },{ + .name =3D "reconnect-is-ms", + .type =3D QEMU_OPT_BOOL, },{ .name =3D "telnet", .type =3D QEMU_OPT_BOOL, diff --git a/qapi/char.json b/qapi/char.json index ef58445cee..61aeccf09d 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -272,8 +272,13 @@ # (default: false) (Since: 3.1) # # @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) +# attempt a reconnect after the given number of seconds (unless +# @reconnect-is-ms is set to true, in that case the number is +# treated as milliseconds). Setting this to zero disables +# this function. (default: 0) (Since: 2.2) +# +# @reconnect-is-ms: The value specified in @reconnect should be treated +# as milliseconds. (default: false) (Since: 9.2) # # Since: 1.4 ## @@ -287,7 +292,8 @@ '*telnet': 'bool', '*tn3270': 'bool', '*websocket': 'bool', - '*reconnect': 'int' }, + '*reconnect': 'int', + '*reconnect-is-ms': 'bool' }, 'base': 'ChardevCommon' } =20 ## --=20 2.34.1