From patchwork Thu Jan 3 10:18:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10747179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D78646C5 for ; Thu, 3 Jan 2019 10:23:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C54DB28563 for ; Thu, 3 Jan 2019 10:23:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B83FF28623; Thu, 3 Jan 2019 10:23:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B51428563 for ; Thu, 3 Jan 2019 10:23:42 +0000 (UTC) Received: from localhost ([127.0.0.1]:50443 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gf0A9-0000yO-AH for patchwork-qemu-devel@patchwork.kernel.org; Thu, 03 Jan 2019 05:23:41 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = reconnect; } - if (s->reconnect_time) { - tcp_chr_connect_async(chr); - } else { - if (s->is_listen) { - char *name; - s->listener = qio_net_listener_new(); + if (s->is_listen) { + char *name; + s->listener = qio_net_listener_new(); - name = g_strdup_printf("chardev-tcp-listener-%s", chr->label); - qio_net_listener_set_name(s->listener, name); - g_free(name); + name = g_strdup_printf("chardev-tcp-listener-%s", chr->label); + qio_net_listener_set_name(s->listener, name); + g_free(name); - if (qio_net_listener_open_sync(s->listener, s->addr, errp) < 0) { - object_unref(OBJECT(s->listener)); - s->listener = NULL; - goto error; - } + if (qio_net_listener_open_sync(s->listener, s->addr, errp) < 0) { + object_unref(OBJECT(s->listener)); + s->listener = NULL; + goto error; + } - qapi_free_SocketAddress(s->addr); - s->addr = socket_local_address(s->listener->sioc[0]->fd, errp); - update_disconnected_filename(s); + qapi_free_SocketAddress(s->addr); + s->addr = socket_local_address(s->listener->sioc[0]->fd, errp); + update_disconnected_filename(s); - 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, ChardevBackend *backend, Error **errp) { bool is_listen = qemu_opt_get_bool(opts, "server", false); - bool is_waitconnect = is_listen && qemu_opt_get_bool(opts, "wait", true); + bool is_waitconnect = qemu_opt_get_bool(opts, "wait", true); bool is_telnet = qemu_opt_get_bool(opts, "telnet", false); bool is_tn3270 = qemu_opt_get_bool(opts, "tn3270", false); bool is_websock = 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=false) # @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 socket. @option{server} specifies that the socket shall be a listening socket. -@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. @option{telnet} specifies that traffic on the socket should interpret telnet escape sequences. @@ -3093,7 +3094,9 @@ I/O to a location or wait for a connection from a location. 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 buffering +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