From patchwork Tue Dec 18 09:59:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yongji Xie X-Patchwork-Id: 10735301 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 ADF946C2 for ; Tue, 18 Dec 2018 10:04:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CFB8292D6 for ; Tue, 18 Dec 2018 10:04:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 916622A3E6; Tue, 18 Dec 2018 10:04:18 +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 BF0C4292D6 for ; Tue, 18 Dec 2018 10:04:17 +0000 (UTC) Received: from localhost ([::1]:52878 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZCEa-0002Cx-Tc for patchwork-qemu-devel@patchwork.kernel.org; Tue, 18 Dec 2018 05:04:16 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gZCBB-0007TS-8y for qemu-devel@nongnu.org; Tue, 18 Dec 2018 05:00:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gZCB5-0001cW-VG for qemu-devel@nongnu.org; Tue, 18 Dec 2018 05:00:45 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:34494) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gZCB5-0001cC-Ku for qemu-devel@nongnu.org; Tue, 18 Dec 2018 05:00:39 -0500 Received: by mail-pg1-x543.google.com with SMTP id j10so6377137pga.1 for ; Tue, 18 Dec 2018 02:00:39 -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=u7aRkd7Hl2cCq7qtVDK9s93blV0z1LSlZPpdhaPGNFI=; b=JUuX3JiWYE5mH3Xw9Qxl8fcTQ8/K7Fb7TC5YsfzYNn9axh8dYR6f+0PNQbNuQTaxDv FTJ+Vz1m1G/WZka5bsRq64RFavIfZpa18RVJj5tTno+DYfDDxFGPKGmnHmAjjXkHZhhH CXvRSbKfhh+DLVqn857ZsWb6fS0jAgDWj4sRX9WxBcaGWroecCoIOpyB5YW/zCRPcVm8 sO8FsDpD2/6U0fyHgz4+9XQr/jFcMossci4E6iKkE6ChD38qvCey8IUIiPYPGbklORBe qEBNmtSAhDCTe5bOwf9e51iG/gO65YUBXOdati59/PYX5TJsZDTjIonOSQijJeRxYzl0 xEBw== 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=u7aRkd7Hl2cCq7qtVDK9s93blV0z1LSlZPpdhaPGNFI=; b=PpdA5AubhHJLKwIfORaUwHZa5G/6Y4JpdvmODBxNaS8dUBsyBVo5V2xZGUtra0sSUH WgT50tBz7VCyAA/zqUL8DKNyq9ZTWY8IfZvTH8tZMUDdrPuUo79hyPKnHLWNxG6dWkiH a+/GXezPA+Glxi5e3YDO4mwzpg53ZjFfkOtBrq/GiGICFZCaMBGZAp9SckCjKbw49U3p xJUuAtmiJxnyBAOHpYB2M7w31BYKdxTHezSY5yDhxCsgrLC30YDUPVrAHCTDrFdJ0QQH sqocEuehyCU6tGOvjrNYZ6BqnQhJpkGy5jJvBWM0+tWGUWEyNYA7mujDxAtAtRkZSk4t VsSg== X-Gm-Message-State: AA+aEWZTe/mzG7SlElqD8wtuNZ47OVvkkDI9jdQx9FRLU/m0o3lpBlDE WP9ilMkmeLePLTFGA7uJep8= X-Google-Smtp-Source: AFSGD/WtNdfqHIA0jSFbZ4TiLx58a9CrET4kS4NTFvjkSMnGEHj98Jpd1NxDAagIbpij2xpye4sVyA== X-Received: by 2002:a62:f907:: with SMTP id o7mr15732000pfh.244.1545127238621; Tue, 18 Dec 2018 02:00:38 -0800 (PST) Received: from localhost ([116.247.112.152]) by smtp.gmail.com with ESMTPSA id s21sm24866959pfk.133.2018.12.18.02.00.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Dec 2018 02:00:38 -0800 (PST) From: elohimes@gmail.com X-Google-Original-From: xieyongji@baidu.com To: mst@redhat.com, marcandre.lureau@redhat.com, jasowang@redhat.com, yury-kotov@yandex-team.ru, maxime.coquelin@redhat.com Date: Tue, 18 Dec 2018 17:59:56 +0800 Message-Id: <20181218100002.11219-2-xieyongji@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181218100002.11219-1-xieyongji@baidu.com> References: <20181218100002.11219-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::543 Subject: [Qemu-devel] [PATCH v2 for-4.0 1/7] chardev: Add disconnected option for chardev socket 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 New option "disconnected" is added to init the chardev socket in disconnected state. 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. Suggested-by: Yury Kotov Signed-off-by: Xie Yongji Signed-off-by: Zhang Yu --- chardev/char-socket.c | 10 ++++++++++ chardev/char.c | 3 +++ qapi/char.json | 3 +++ qemu-options.hx | 28 ++++++++++++++++------------ 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index eaa8e8b68f..2464d7abad 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -70,6 +70,7 @@ typedef struct { TCPChardevTelnetInit *telnet_init; bool is_websock; + bool is_disconnected; GSource *reconnect_timer; int64_t reconnect_time; @@ -1000,6 +1001,7 @@ static void qmp_chardev_open_socket(Chardev *chr, bool is_tn3270 = sock->has_tn3270 ? sock->tn3270 : false; bool is_waitconnect = sock->has_wait ? sock->wait : false; bool is_websock = sock->has_websocket ? sock->websocket : false; + bool is_disconnected = sock->has_disconnected ? sock->disconnected : false; int64_t reconnect = sock->has_reconnect ? sock->reconnect : 0; QIOChannelSocket *sioc = NULL; SocketAddress *addr; @@ -1072,6 +1074,10 @@ static void qmp_chardev_open_socket(Chardev *chr, s->reconnect_time = reconnect; } + if (!s->is_listen && is_disconnected) { + return; + } + if (s->reconnect_time) { tcp_chr_connect_async(chr); } else { @@ -1125,6 +1131,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, bool is_tn3270 = qemu_opt_get_bool(opts, "tn3270", false); bool is_websock = qemu_opt_get_bool(opts, "websocket", false); bool do_nodelay = !qemu_opt_get_bool(opts, "delay", true); + bool is_disconnected = !is_listen && + qemu_opt_get_bool(opts, "disconnected", false); int64_t reconnect = qemu_opt_get_number(opts, "reconnect", 0); const char *path = qemu_opt_get(opts, "path"); const char *host = qemu_opt_get(opts, "host"); @@ -1176,6 +1184,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, sock->websocket = is_websock; sock->has_wait = true; sock->wait = is_waitconnect; + sock->has_disconnected = true; + sock->disconnected = is_disconnected; sock->has_reconnect = qemu_opt_find(opts, "reconnect"); sock->reconnect = reconnect; sock->tls_creds = g_strdup(tls_creds); diff --git a/chardev/char.c b/chardev/char.c index ccba36bafb..fb916eb176 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -862,6 +862,9 @@ QemuOptsList qemu_chardev_opts = { },{ .name = "delay", .type = QEMU_OPT_BOOL, + },{ + .name = "disconnected", + .type = QEMU_OPT_BOOL, },{ .name = "reconnect", .type = QEMU_OPT_NUMBER, diff --git a/qapi/char.json b/qapi/char.json index 77ed847972..b634442229 100644 --- a/qapi/char.json +++ b/qapi/char.json @@ -258,6 +258,8 @@ # sockets (default: false) (Since: 2.10) # @websocket: enable websocket protocol on server # sockets (default: false) (Since: 3.1) +# @disconnected: init a client socket in disconnected +# state (default: false) (Since: 4.0) # @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) @@ -274,6 +276,7 @@ '*telnet': 'bool', '*tn3270': 'bool', '*websocket': 'bool', + '*disconnected': 'bool', '*reconnect': 'int' }, 'base': 'ChardevCommon' } diff --git a/qemu-options.hx b/qemu-options.hx index df42116ecc..f9d3495dc8 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -2418,10 +2418,10 @@ DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, "-chardev help\n" "-chardev null,id=id[,mux=on|off][,logfile=PATH][,logappend=on|off]\n" "-chardev socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay][,reconnect=seconds]\n" - " [,server][,nowait][,telnet][,websocket][,reconnect=seconds][,mux=on|off]\n" - " [,logfile=PATH][,logappend=on|off][,tls-creds=ID] (tcp)\n" - "-chardev socket,id=id,path=path[,server][,nowait][,telnet][,websocket][,reconnect=seconds]\n" - " [,mux=on|off][,logfile=PATH][,logappend=on|off] (unix)\n" + " [,server][,nowait][,telnet][,websocket][,disconnected][,reconnect=seconds]\n" + " [,mux=on|off][,logfile=PATH][,logappend=on|off][,tls-creds=ID] (tcp)\n" + "-chardev socket,id=id,path=path[,server][,nowait][,telnet][,websocket][,disconnected]\n" + " [,reconnect=seconds][,mux=on|off][,logfile=PATH][,logappend=on|off] (unix)\n" "-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]\n" " [,localport=localport][,ipv4][,ipv6][,mux=on|off]\n" " [,logfile=PATH][,logappend=on|off]\n" @@ -2548,7 +2548,7 @@ The available backends are: A void device. This device will not emit any data, and will drop any data it receives. The null backend does not take any options. -@item -chardev socket,id=@var{id}[,@var{TCP options} or @var{unix options}][,server][,nowait][,telnet][,websocket][,reconnect=@var{seconds}][,tls-creds=@var{id}] +@item -chardev socket,id=@var{id}[,@var{TCP options} or @var{unix options}][,server][,nowait][,telnet][,websocket][,disconnected][,reconnect=@var{seconds}][,tls-creds=@var{id}] Create a two-way stream socket, which can be either a TCP or a unix socket. A unix socket will be created if @option{path} is specified. Behaviour is @@ -2565,6 +2565,9 @@ escape sequences. @option{websocket} specifies that the socket uses WebSocket protocol for communication. +@option{disconnected} specifies that the non-server socket should not try +to connect the remote during initialization. + @option{reconnect} sets the timeout for reconnecting on non-server sockets when the remote end goes away. qemu will delay this many seconds and then attempt to reconnect. Zero disables reconnecting, and is the default. @@ -3087,18 +3090,19 @@ telnet on port 5555 to access the QEMU port. localhost 5555 @end table -@item tcp:[@var{host}]:@var{port}[,@var{server}][,nowait][,nodelay][,reconnect=@var{seconds}] +@item tcp:[@var{host}]:@var{port}[,@var{server}][,nowait][,nodelay][,disconnected] +[,reconnect=@var{seconds}] The TCP Net Console has two modes of operation. It can send the serial 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 -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 -one TCP connection at a time is accepted. You can use @code{telnet} to -connect to the corresponding character device. +algorithm. If @var{noserver} is specified, the @code{disconnected} will disallow +QEMU to connect during initialization, and the @code{reconnect} will ask QEMU +to reconnect at the given interval when the connection goes down. If @var{host} +is omitted, 0.0.0.0 is assumed. Only one TCP connection at a time is accepted. +You can use @code{telnet} to connect to the corresponding character device. @table @code @item Example to send tcp console to 192.168.0.2 port 4444 -serial tcp:192.168.0.2:4444 @@ -3121,7 +3125,7 @@ type "send break" followed by pressing the enter key. The WebSocket protocol is used instead of raw tcp socket. The port acts as a WebSocket server. Client mode is not supported. -@item unix:@var{path}[,server][,nowait][,reconnect=@var{seconds}] +@item unix:@var{path}[,server][,nowait][,disconnected][,reconnect=@var{seconds}] A unix domain socket is used instead of a tcp socket. The option works the same as if you had specified @code{-serial tcp} except the unix domain socket @var{path} is used for connections.