From: minyard@acm.org
To: qemu-devel@nongnu.org
Cc: Corey Minyard <cminyard@mvista.com>
Subject: [Qemu-devel] [PATCH 05/18] qemu-char: Allow a chardev to reconnect if disconnected
Date: Thu, 19 Jul 2012 13:53:20 -0500 [thread overview]
Message-ID: <1342724013-1633-6-git-send-email-minyard@acm.org> (raw)
In-Reply-To: <1342724013-1633-1-git-send-email-minyard@acm.org>
From: Corey Minyard <cminyard@mvista.com>
Allow a socket that connects to reconnect on a periodic basis if it
fails to connect at startup or if the connection drops while in use.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
qemu-char.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++----
qemu-char.h | 4 +++
qemu-config.c | 3 ++
qemu-options.hx | 11 +++++++--
4 files changed, 72 insertions(+), 8 deletions(-)
diff --git a/qemu-char.c b/qemu-char.c
index ce3c05d..43277d0 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -111,9 +111,17 @@ void qemu_chr_be_event(CharDriverState *s, int event)
/* Keep track if the char device is open */
switch (event) {
case CHR_EVENT_OPENED:
+ if (s->recon_timer) {
+ qemu_del_timer(s->recon_timer);
+ }
s->opened = 1;
break;
case CHR_EVENT_CLOSED:
+ if (s->recon_timer) {
+ qemu_mod_timer(s->recon_timer,
+ (qemu_get_clock_ns(vm_clock) +
+ (s->recon_time * 1000000000ULL)));
+ }
s->opened = 0;
break;
}
@@ -2726,6 +2734,20 @@ static const struct {
#endif
};
+static void recon_timeout(void *opaque)
+{
+ CharDriverState *chr = opaque;
+
+ if (chr->opened) {
+ return;
+ }
+
+ qemu_mod_timer(chr->recon_timer,
+ (qemu_get_clock_ns(vm_clock) +
+ (chr->recon_time * 1000000000ULL)));
+ backend_table[chr->backend].open(chr, chr->opts);
+}
+
CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
void (*init)(struct CharDriverState *s))
{
@@ -2753,11 +2775,37 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts *opts,
}
chr = g_malloc0(sizeof(CharDriverState));
+
+ chr->backend = i;
+ chr->recon_time = qemu_opt_get_number(opts, "reconnect", 0);
+ if (chr->recon_time) {
+ if (strcmp(qemu_opt_get(opts, "backend"), "socket") != 0) {
+ g_free(chr);
+ fprintf(stderr, "chardev: reconnect only supported on sockets\n");
+ return NULL;
+ }
+ if (qemu_opt_get_bool(opts, "server", 0)) {
+ g_free(chr);
+ fprintf(stderr, "chardev: server device cannot reconnect\n");
+ return NULL;
+ }
+ chr->opts = opts;
+ chr->recon_timer = qemu_new_timer_ns(vm_clock, recon_timeout, chr);
+
+ /* Make sure it connects in time. */
+ qemu_mod_timer(chr->recon_timer,
+ (qemu_get_clock_ns(vm_clock) +
+ (chr->recon_time * 1000000000ULL)));
+ }
+
if (!backend_table[i].open(chr, opts)) {
- g_free(chr);
- fprintf(stderr, "chardev: opening backend \"%s\" failed\n",
- qemu_opt_get(opts, "backend"));
- return NULL;
+ if (!chr->recon_time) {
+ /* Reconnect is not enabled, give up */
+ g_free(chr);
+ fprintf(stderr, "chardev: opening backend \"%s\" failed\n",
+ qemu_opt_get(opts, "backend"));
+ return NULL;
+ }
}
if (!chr->filename)
@@ -2827,8 +2875,12 @@ void qemu_chr_fe_close(struct CharDriverState *chr)
void qemu_chr_delete(CharDriverState *chr)
{
QTAILQ_REMOVE(&chardevs, chr, next);
- if (chr->chr_close)
+ if (chr->chr_close) {
chr->chr_close(chr);
+ }
+ if (chr->recon_timer) {
+ qemu_free_timer(chr->recon_timer);
+ }
g_free(chr->filename);
g_free(chr->label);
g_free(chr);
diff --git a/qemu-char.h b/qemu-char.h
index 486644b..d21ae39 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -75,6 +75,10 @@ struct CharDriverState {
int opened;
int avail_connections;
QTAILQ_ENTRY(CharDriverState) next;
+ int backend;
+ QemuOpts *opts;
+ QEMUTimer *recon_timer;
+ uint64_t recon_time;
};
/**
diff --git a/qemu-config.c b/qemu-config.c
index 54694cc..9ebe432 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -209,6 +209,9 @@ static QemuOptsList qemu_chardev_opts = {
.name = "mux",
.type = QEMU_OPT_BOOL,
},{
+ .name = "reconnect",
+ .type = QEMU_OPT_NUMBER,
+ },{
.name = "signal",
.type = QEMU_OPT_BOOL,
},{
diff --git a/qemu-options.hx b/qemu-options.hx
index 72aace6..c5f592c 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1620,8 +1620,9 @@ DEFHEADING(Character device options:)
DEF("chardev", HAS_ARG, QEMU_OPTION_chardev,
"-chardev null,id=id[,mux=on|off]\n"
"-chardev socket,id=id[,host=host],port=host[,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"
+ " [,server][,nowait][,telnet][,mux=on|off][,reconnect=seconds] (tcp)\n"
+ "-chardev socket,id=id,path=path[,server][,nowait][,telnet][,mux=on|off]\n"
+ " [,reconnect=seconds] (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"
@@ -1690,7 +1691,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] [,reconnect=@var{seconds}]
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
@@ -1704,6 +1705,10 @@ connect to a listening socket.
@option{telnet} specifies that traffic on the socket should interpret telnet
escape sequences.
+@option{reconnect} specifies that if the socket does not come up at startup,
+or if the socket is closed for some reason (like the other end exited),
+wait the given number of seconds and attempt to reconnect.
+
TCP and unix socket options are given below:
@table @option
--
1.7.4.1
next prev parent reply other threads:[~2012-07-19 18:54 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-19 18:53 [Qemu-devel] Third shot at adding IPMI to qemu minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 01/18] smbios: Add a function to directly add an entry minyard
2012-07-30 15:37 ` Anthony Liguori
2012-07-30 16:44 ` Corey Minyard
2012-07-30 17:25 ` Anthony Liguori
2012-07-30 17:40 ` Corey Minyard
2012-08-02 1:15 ` Kevin O'Connor
2012-08-02 2:11 ` Corey Minyard
2012-08-02 2:40 ` Anthony Liguori
2012-08-02 12:17 ` Corey Minyard
2012-08-02 18:32 ` Anthony Liguori
2012-08-02 19:20 ` Corey Minyard
2012-08-02 21:05 ` Anthony Liguori
2012-08-06 15:38 ` Corey Minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 02/18] pc: move SMBIOS setup to after device init minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 03/18] vl: Move init_timer_alarm() earlier minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 04/18] qemu-char: Allocate CharDriverState in qemu_chr_new_from_opts minyard
2012-07-19 18:53 ` minyard [this message]
2012-07-19 18:53 ` [Qemu-devel] [PATCH 06/18] qemu-char: Fix a race reporting opens and closes minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 07/18] qemu-char: remove free of chr from win_stdio_close minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 08/18] qemu-char: Close fd at end of file minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 09/18] qdev: Add a pre-firmware init capability minyard
2012-07-30 14:36 ` Andreas Färber
2012-07-30 15:27 ` Corey Minyard
2012-07-30 15:40 ` Anthony Liguori
2012-07-19 18:53 ` [Qemu-devel] [PATCH 10/18] qom: release previous object when setting minyard
2012-07-30 13:51 ` Andreas Färber
2012-09-10 14:34 ` Andreas Färber
2012-07-19 18:53 ` [Qemu-devel] [PATCH 11/18] Add a base IPMI interface minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 12/18] IPMI: Add a PC ISA type structure minyard
2012-07-30 13:45 ` Andreas Färber
2012-07-30 17:09 ` Corey Minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 13/18] IPMI: Add a KCS low-level interface minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 14/18] IPMI: Add a BT " minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 15/18] IPMI: Add a local BMC simulation minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 16/18] IPMI: Add an external connection simulation interface minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 17/18] IPMI: Add tests minyard
2012-07-19 18:53 ` [Qemu-devel] [PATCH 18/18] IPMI: Add documentation minyard
2012-07-20 6:48 ` [Qemu-devel] Third shot at adding IPMI to qemu Paolo Bonzini
2012-07-30 13:34 ` Corey Minyard
2012-07-30 14:05 ` Andreas Färber
2012-07-30 15:17 ` Corey Minyard
2012-09-10 14:48 ` Andreas Färber
2012-09-10 16:52 ` Corey Minyard
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=1342724013-1633-6-git-send-email-minyard@acm.org \
--to=minyard@acm.org \
--cc=cminyard@mvista.com \
--cc=qemu-devel@nongnu.org \
/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).