From: elohimes@gmail.com
To: mst@redhat.com, marcandre.lureau@redhat.com, jasowang@redhat.com,
yury-kotov@yandex-team.ru, maxime.coquelin@redhat.com
Cc: qemu-devel@nongnu.org, zhangyu31@baidu.com, chaiwen@baidu.com,
nixun@baidu.com, lilin24@baidu.com,
Xie Yongji <xieyongji@baidu.com>
Subject: [Qemu-devel] [PATCH v2 for-4.0 1/7] chardev: Add disconnected option for chardev socket
Date: Tue, 18 Dec 2018 17:59:56 +0800 [thread overview]
Message-ID: <20181218100002.11219-2-xieyongji@baidu.com> (raw)
In-Reply-To: <20181218100002.11219-1-xieyongji@baidu.com>
From: Xie Yongji <xieyongji@baidu.com>
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 <yury-kotov@yandex-team.ru>
Signed-off-by: Xie Yongji <xieyongji@baidu.com>
Signed-off-by: Zhang Yu <zhangyu31@baidu.com>
---
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.
--
2.17.1
next prev parent reply other threads:[~2018-12-18 10:00 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-18 9:59 [Qemu-devel] [PATCH v2 for-4.0 0/7] vhost-user-blk: Add support for backend reconnecting elohimes
2018-12-18 9:59 ` elohimes [this message]
2018-12-18 12:24 ` [Qemu-devel] [PATCH v2 for-4.0 1/7] chardev: Add disconnected option for chardev socket Marc-André Lureau
2018-12-18 13:33 ` Yongji Xie
2018-12-18 15:25 ` Daniel P. Berrangé
2018-12-18 16:02 ` Michael S. Tsirkin
2018-12-18 16:09 ` Daniel P. Berrangé
2018-12-19 9:01 ` Yongji Xie
2018-12-19 15:55 ` Michael S. Tsirkin
2018-12-19 16:01 ` Daniel P. Berrangé
2018-12-19 16:50 ` Michael S. Tsirkin
2018-12-19 17:09 ` Daniel P. Berrangé
2018-12-19 18:18 ` Michael S. Tsirkin
2018-12-20 4:25 ` Yongji Xie
2018-12-18 9:59 ` [Qemu-devel] [PATCH v2 for-4.0 2/7] vhost-user: Support providing shared memory to backend elohimes
2018-12-18 14:25 ` Michael S. Tsirkin
2018-12-18 14:47 ` Yongji Xie
2018-12-18 14:57 ` Michael S. Tsirkin
2018-12-18 15:10 ` Yongji Xie
2018-12-18 9:59 ` [Qemu-devel] [PATCH v2 for-4.0 3/7] libvhost-user: Introduce vu_queue_map_desc() elohimes
2018-12-18 9:59 ` [Qemu-devel] [PATCH v2 for-4.0 4/7] libvhost-user: Support recording inflight I/O in shared memory elohimes
2018-12-18 10:00 ` [Qemu-devel] [PATCH v2 for-4.0 5/7] vhost-user-blk: Add support to provide shared memory to backend elohimes
2018-12-18 10:00 ` [Qemu-devel] [PATCH v2 for-4.0 6/7] vhost-user-blk: Add support to reconnect backend elohimes
2018-12-18 12:30 ` Yury Kotov
2018-12-18 14:16 ` Yongji Xie
2018-12-18 14:35 ` Yury Kotov
2018-12-18 14:59 ` Yongji Xie
2018-12-18 15:33 ` Yury Kotov
2018-12-19 8:42 ` Yongji Xie
2018-12-18 10:00 ` [Qemu-devel] [PATCH v2 for-4.0 7/7] contrib/vhost-user-blk: enable inflight I/O recording elohimes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181218100002.11219-2-xieyongji@baidu.com \
--to=elohimes@gmail.com \
--cc=chaiwen@baidu.com \
--cc=jasowang@redhat.com \
--cc=lilin24@baidu.com \
--cc=marcandre.lureau@redhat.com \
--cc=maxime.coquelin@redhat.com \
--cc=mst@redhat.com \
--cc=nixun@baidu.com \
--cc=qemu-devel@nongnu.org \
--cc=xieyongji@baidu.com \
--cc=yury-kotov@yandex-team.ru \
--cc=zhangyu31@baidu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).