From nobody Fri Nov 7 05:45:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1546511046867504.7257056569018; Thu, 3 Jan 2019 02:24:06 -0800 (PST) Received: from localhost ([127.0.0.1]:50443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf0AX-0000yO-Hk for importer@patchew.org; Thu, 03 Jan 2019 05:24:05 -0500 Received: from eggs.gnu.org ([208.118.235.92]:44044) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf05k-00042M-ET for qemu-devel@nongnu.org; Thu, 03 Jan 2019 05:19:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gf05i-0002ir-De for qemu-devel@nongnu.org; Thu, 03 Jan 2019 05:19:08 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:42173) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gf05g-0002gu-CH for qemu-devel@nongnu.org; Thu, 03 Jan 2019 05:19:06 -0500 Received: by mail-pf1-x444.google.com with SMTP id 64so16489607pfr.9 for ; Thu, 03 Jan 2019 02:19:03 -0800 (PST) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id w185sm83109728pfb.135.2019.01.03.02.19.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jan 2019 02:19:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=aAATJahSzpb7CqJ/MNyIYQ/06vLxFUTaW2AexnRpbuc=; b=YcUtBNOD1giqNxRd2+D2yF+WqfQqorq5xPHS57TD6Wp06z5XMplmcENR2387lESiCH FG/JlCeqdZitGrOBQUaZMHT1Ckwplo0U+ZTh5566B7/BxBsIG2jo8SnBU+T5eTkw42+X n1Aroze/cjI290ZshHYn6tvpJh+Lr1SNQ6S+Wg7uPGPUG4tcql+jOIUtQ5cnMJDn2OV7 3BX5KDOp2yUePOajNEuHzNjg7GSCOpXo12O3H3l8LYFBH2GFo/gPBnCi2mb0EePCaJbw D6bsrr8F9HHCpXYFNC559fParzYq2VapnEDCg984TjtQ6ck9Nqmik5jS81IaEjjKHtaI nnUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=aAATJahSzpb7CqJ/MNyIYQ/06vLxFUTaW2AexnRpbuc=; b=cgKuXS5mx86ehYOrpbZ2zOgte69iihddFqIqOGW12U4ODfYSdqvSkK1UttxPjL4JP2 glPjqomFxK3bx3L+haagDdNifQzfyAKnVmPz6/iLHzOjZq/2dptvVcxiLr+y6WfR3hjY DNGMec409p1wQ4voSEtzXSeFUTI3XAD4zag3lsckHivGzkmiOfq4sRYmRimyABuivo+t Y9Y0oH++H8bq3o+AODFDBUS9Hx1pTJ/n7uKUMajhsfYBq6UEOi0jPPs8AhfXuX4J/5Hq tZqT27Y5pahQFceHJVIwmZIwbexUuF+wGRLmCfjyBzyeQzXBBs1L+jsLxM7e69VjesRY zUQg== X-Gm-Message-State: AA+aEWbtAqx6tEnqpUvXS6TayE+WTOznBoDaPzZo+V6ifRC4cDqr7Wc0 08JKXlcZYW8IeOSZdR8VJF4= X-Google-Smtp-Source: AFSGD/Xvr4VvoDqse4ItzgxKvTBeMqp/C2SUPAtC0RGmKexCSX09mcm8snD3wm3nxAeGEC/wJtYn0g== X-Received: by 2002:aa7:810c:: with SMTP id b12mr47376726pfi.44.1546510743125; Thu, 03 Jan 2019 02:19:03 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com, berrange@redhat.com, jasowang@redhat.com, maxime.coquelin@redhat.com, yury-kotov@yandex-team.ru, wrfsh@yandex-team.ru Date: Thu, 3 Jan 2019 18:18:13 +0800 Message-Id: <20190103101819.7418-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190103101819.7418-1-xieyongji@baidu.com> References: <20190103101819.7418-1-xieyongji@baidu.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 Subject: [Qemu-devel] [PATCH v3 for-4.0 1/7] char-socket: Enable "nowait" option on client sockets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nixun@baidu.com, qemu-devel@nongnu.org, lilin24@baidu.com, zhangyu31@baidu.com, chaiwen@baidu.com, Xie Yongji Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Xie Yongji Enable "nowait" option to make QEMU not do a connect on client sockets during initialization of the chardev. Then we can use qemu_chr_fe_wait_connected() to connect when necessary. Now it would be used for unix domain socket of vhost-user-blk device to support reconnect. Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- chardev/char-socket.c | 56 +++++++++++++++++++++---------------------- qapi/char.json | 3 +-- qemu-options.hx | 9 ++++--- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index eaa8e8b68f..f803f4f7d3 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -1072,37 +1072,37 @@ static void qmp_chardev_open_socket(Chardev *chr, s->reconnect_time =3D reconnect; } =20 - if (s->reconnect_time) { - tcp_chr_connect_async(chr); - } else { - if (s->is_listen) { - char *name; - s->listener =3D qio_net_listener_new(); + if (s->is_listen) { + char *name; + s->listener =3D qio_net_listener_new(); =20 - name =3D g_strdup_printf("chardev-tcp-listener-%s", chr->label= ); - qio_net_listener_set_name(s->listener, name); - g_free(name); + name =3D g_strdup_printf("chardev-tcp-listener-%s", chr->label); + qio_net_listener_set_name(s->listener, name); + g_free(name); =20 - if (qio_net_listener_open_sync(s->listener, s->addr, errp) < 0= ) { - object_unref(OBJECT(s->listener)); - s->listener =3D NULL; - goto error; - } + if (qio_net_listener_open_sync(s->listener, s->addr, errp) < 0) { + object_unref(OBJECT(s->listener)); + s->listener =3D NULL; + goto error; + } =20 - qapi_free_SocketAddress(s->addr); - s->addr =3D socket_local_address(s->listener->sioc[0]->fd, err= p); - update_disconnected_filename(s); + qapi_free_SocketAddress(s->addr); + s->addr =3D socket_local_address(s->listener->sioc[0]->fd, errp); + update_disconnected_filename(s); =20 - if (is_waitconnect && - qemu_chr_wait_connected(chr, errp) < 0) { - return; - } - if (!s->ioc) { - qio_net_listener_set_client_func_full(s->listener, - tcp_chr_accept, - chr, NULL, - chr->gcontext); - } + if (is_waitconnect && + qemu_chr_wait_connected(chr, errp) < 0) { + return; + } + if (!s->ioc) { + qio_net_listener_set_client_func_full(s->listener, + tcp_chr_accept, + chr, NULL, + chr->gcontext); + } + } else if (is_waitconnect) { + if (s->reconnect_time) { + tcp_chr_connect_async(chr); } else if (qemu_chr_wait_connected(chr, errp) < 0) { goto error; } @@ -1120,7 +1120,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Cha= rdevBackend *backend, Error **errp) { bool is_listen =3D qemu_opt_get_bool(opts, "server", false); - bool is_waitconnect =3D is_listen && qemu_opt_get_bool(opts, "wait", t= rue); + bool is_waitconnect =3D qemu_opt_get_bool(opts, "wait", true); bool is_telnet =3D qemu_opt_get_bool(opts, "telnet", false); bool is_tn3270 =3D qemu_opt_get_bool(opts, "tn3270", false); bool is_websock =3D qemu_opt_get_bool(opts, "websocket", false); diff --git a/qapi/char.json b/qapi/char.json index 77ed847972..6a3b5bcd71 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -249,8 +249,7 @@ # or connect to (server=3Dfalse) # @tls-creds: the ID of the TLS credentials object (since 2.6) # @server: create server socket (default: true) -# @wait: wait for incoming connection on server -# sockets (default: false). +# @wait: wait for being connected or connecting to (default: false) # @nodelay: set TCP_NODELAY socket option (default: false) # @telnet: enable telnet protocol on server # sockets (default: false) diff --git a/qemu-options.hx b/qemu-options.hx index df42116ecc..66d99c6e83 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2556,8 +2556,9 @@ undefined if TCP options are specified for a unix soc= ket. =20 @option{server} specifies that the socket shall be a listening socket. =20 -@option{nowait} specifies that QEMU should not block waiting for a client = to -connect to a listening socket. +@option{nowait} specifies that QEMU should not wait for being connected on +server sockets or try to do a sync/async connect on client sockets during +initialization of the chardev. =20 @option{telnet} specifies that traffic on the socket should interpret teln= et escape sequences. @@ -3093,7 +3094,9 @@ I/O to a location or wait for a connection from a loc= ation. By default the TCP Net Console is sent to @var{host} at the @var{port}. If you use the @var{server} option QEMU will wait for a client socket application to connect to the port before continuing, unless the @code{nowait} -option was specified. The @code{nodelay} option disables the Nagle buffer= ing +option was specified. And the @code{nowait} option could also be +used when @var{noserver} is set to disallow QEMU to connect during +initialization. The @code{nodelay} option disables the Nagle buffering algorithm. The @code{reconnect} option only applies if @var{noserver} is set, if the connection goes down it will attempt to reconnect at the given interval. If @var{host} is omitted, 0.0.0.0 is assumed. Only --=20 2.17.1