chardev: Add reconnecting to client sockets
PATCH 1/1 chardev: Add reconnecting to client sockets
From: Corey Minyard <[email protected]>
Adds a "recon" option to socket backends that gives a reconnect timeout. This only applies to client sockets. If the other end of a socket closes the connection, qemu will attempt to reconnect after the given number of seconds.
This rearranges things a bit, all socket configuration is moved to qmp_chardev_open_socket() and that only gets called once at startup. qemu_chr_open_socket_fd() is called to open or re-open the connection.
--- qapi-schema.json | 6 +- qemu-char.c | 209 +++++++++++++++++++++++++++++++++++++++++-------------- qemu-options.hx | 20 ++++-- 3 files changed, 174 insertions(+), 61 deletions(-)
qapi-schema.json +5 -1
@@ -2648,6 +2648,9 @@ # @nodelay: #optional set TCP_NODELAY socket option (default: false) # @telnet: #optional enable telnet protocol on server # sockets (default: false) +# @recon: #optional If not a server socket, if the socket disconnect +# then reconnect after the given number of seconds. Setting +# to zero disables this function. (default: 0) # # Since: 1.4 ##
@@ -2655,7 +2658,8 @@ '*server' : 'bool', '*wait' : 'bool', '*nodelay' : 'bool', - '*telnet' : 'bool' } } + '*telnet' : 'bool', + '*recon' : 'int' } } ## # @ChardevUdp:
qemu-char.c +156 -53
302 lines not on this page · raw message
qemu-options.hx +13 -7
@@ -1930,9 +1930,9 @@ ETEXI DEF("chardev", HAS_ARG, QEMU_OPTION_chardev, "-chardev null,id=id[,mux=on|off]\n" - "-chardev socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay]\n" - " [,server][,nowait][,telnet][,mux=on|off] (tcp)\n" - "-chardev socket,id=id,path=path[,server][,nowait][,telnet],[mux=on|off] (unix)\n" + "-chardev socket,id=id[,host=host],port=port[,to=to][,ipv4][,ipv6][,nodelay][,recon=recon_time]\n" + " [,server][,nowait][,telnet][,recon=recon_time][,mux=on|off] (tcp)\n" + "-chardev socket,id=id,path=path[,server][,nowait][,telnet][,recon=recon_time][,mux=on|off] (unix)\n" "-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr]\n" " [,localport=localport][,ipv4][,ipv6][,mux=on|off]\n" "-chardev msmouse,id=id[,mux=on|off]\n"
@@ -2004,7 +2004,7 @@ Options to each backend are described below. 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] +@item -chardev socket ,id=@var{id} [@var{TCP options} or @var{unix options}] [,server] [,nowait] [,telnet] [,recon=recon_time] 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
@@ -2018,6 +2018,10 @@ connect to a listening socket. @option{telnet} specifies that traffic on the socket should interpret telnet escape sequences. +@option{recon} 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. + TCP and unix socket options are given below: @table @option
@@ -2687,14 +2691,16 @@ telnet on port 5555 to access the QEMU port. localhost 5555 @end table -@item tcp:[@var{host}]:@var{port}[,@var{server}][,nowait][,nodelay] +@item tcp:[@var{host}]:@var{port}[,@var{server}][,nowait][,nodelay][,recon=recon_time] 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. If @var{host} is omitted, 0.0.0.0 is assumed. Only +algorithm. The @code{recon} 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. @table @code
@@ -2715,7 +2721,7 @@ MAGIC_SYSRQ sequence if you use a telnet that supports sending the break sequence. Typically in unix telnet you do it with Control-] and then type "send break" followed by pressing the enter key. -@item unix:@var{path}[,server][,nowait] +@item unix:@var{path}[,server][,nowait][,recon=recon_time] 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.
Signature · 1 line
1.8.3.1
Quoted 6 lines · On Fri, Sep 19, 2014 at 04:58:57PM -0500, [email protected] wrote:
From: Corey Minyard <[email protected]>
Adds a "recon" option to socket backends that gives a reconnect timeout. This only applies to client sockets. If the other end of a socket closes the connection, qemu will attempt to reconnect after the given number of seconds.
We're enthusiastic about this - we're using a virtio rng via egd, and restarting our entropy distributor currently kills hwrng in the guest because the socket has gone away.
Signature · 1 line
Matthew Garrett | [email protected]
Il 19/09/2014 23:58, [email protected] ha scritto:
Quoted 10 lines
From: Corey Minyard <[email protected]>
Adds a "recon" option to socket backends that gives a reconnect timeout. This only applies to client sockets. If the other end of a socket closes the connection, qemu will attempt to reconnect after the given number of seconds.
This rearranges things a bit, all socket configuration is moved to
qmp_chardev_open_socket()and that only gets called once at startup.qemu_chr_open_socket_fd()is called to open or re-open the connection.
Please do this in a separate patch.
Also:
- qemu-char.c for various reasons is not using QEMU timers. Please use glib timers instead.
qapi-schema.json line 2653
Quoted 3 lines
qapi-schema.json +3
-0+# @recon: #optional If not a server socket, if the socket disconnect +# then reconnect after the given number of seconds. Setting +# to zero disables this function. (default: 0)
Please specify "Since: 2.2" inside the comment, and give a more descriptive name such as reconnect-interval to the option.
qemu-char.c static CharDriverState *qmp_chardev_open_parallel(ChardevHostdev *parallel, · line 4059
Quoted 2 lines
qemu-char.c +2
-0+ s->addr = addr;/* Steal the address from the socket */ + sock->addr =NULL ;
Please do a deep copy instead. (The sock struct should really be const). A function like this will do it for you:
*p_dest = NULL;
qov = qmp_output_visitor_new();
ov = qmp_output_get_visitor(qov);
visit_type_SocketAddress(ov, &src, NULL, errp);
obj = qmp_output_get_qobject(data->qov);
qmp_output_visitor_cleanup(qov);
if (!obj) {
return;
}
qiv = qmp_input_visitor_new(obj);
iv = qmp_input_get_visitor(qiv);
visit_type_SocketAddress(iv, p_dest, NULL, &error_abort);
qmp_input_visitor_cleanup(qiv);
qobject_decref(obj);
...
qapi_copy_SocketAddress(&s->addr, sock->addr, &error_abort);(Something like this should really be automatically generated for all types...).
I only skimmed the code, but nothing else jumped up.
Paolo
Quoted 23 lines · On 09/19/2014 03:58 PM, [email protected] wrote:
From: Corey Minyard <[email protected]>
Adds a "recon" option to socket backends that gives a reconnect timeout. This only applies to client sockets. If the other end of a socket closes the connection, qemu will attempt to reconnect after the given number of seconds.
This rearranges things a bit, all socket configuration is moved to
qmp_chardev_open_socket()and that only gets called once at startup.qemu_chr_open_socket_fd()is called to open or re-open the connection.Signed-off-by Corey Minyard <[email protected]>--- qapi-schema.json | 6 +- qemu-char.c | 209 +++++++++++++++++++++++++++++++++++++++++-------------- qemu-options.hx | 20 ++++-- 3 files changed, 174 insertions(+), 61 deletions(-)qapi-schema.json +0
-0
qapi-schema.json line 2653
Quoted 6 lines
qapi-schema.json +3
-0@@ -2648,6 +2648,9 @@ # @nodelay: #optional set TCP_NODELAY socket option (default: false) # @telnet: #optional enable telnet protocol on server # sockets (default: false) +# @recon: #optional If not a server socket, if the socket disconnect +# then reconnect after the given number of seconds. Setting +# to zero disables this function. (default: 0)
"recon" makes me think of spy novels, not reconnect. Any reason you can't name it something more descriptive, like "reconnect-time"?
Missing a "since 2.2" designation.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org