qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: Ian Molton <ian.molton@collabora.co.uk>
Cc: "Krumme, Chris" <Chris.Krumme@windriver.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] Socket reconnection.
Date: Thu, 03 Dec 2009 08:22:07 -0600	[thread overview]
Message-ID: <4B17C98F.1060208@codemonkey.ws> (raw)
In-Reply-To: <4B178D2E.9090608@collabora.co.uk>

Ian Molton wrote:
> Fresh patch attached. Anthony, if this is ok, I can rebase this and its
> prerequisite.
>
> From 05581c5badd693b7537fe57f85a2ff5ddcb7972d Mon Sep 17 00:00:00 2001
> From: Ian Molton <ian.molton@collabora.co.uk>
> Date: Tue, 1 Dec 2009 11:18:41 +0000
> Subject: [PATCH 2/4] socket: Add a reconnect option.
>
> 	Add a reconnect option that allows sockets to reconnect (after a
> specified delay) to the specified server. This makes the virtio-rng driver
> useful in production environments where the EGD server may need to be restarted.
>
> Signed-off-by: Ian Molton <ian.molton@collabora.co.uk>
> ---
>  qemu-char.c   |  169 ++++++++++++++++++++++++++++++++++++++++++++-------------
>  qemu-char.h   |    2 +
>  qemu-config.c |    3 +
>  vl.c          |    4 ++
>  4 files changed, 139 insertions(+), 39 deletions(-)
>
> diff --git a/qemu-char.c b/qemu-char.c
> index e202585..f20d697 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -1870,8 +1870,12 @@ typedef struct {
>      int max_size;
>      int do_telnetopt;
>      int do_nodelay;
> +    int reconnect;
>      int is_unix;
>      int msgfd;
> +    QemuOpts *opts;
> +    CharDriverState *chr;
> +    int (*setup)(QemuOpts *opts);
>  } TCPCharDriver;
>  
>  static void tcp_chr_accept(void *opaque);
> @@ -2011,6 +2015,61 @@ static ssize_t tcp_chr_recv(CharDriverState *chr, char *buf, size_t len)
>  }
>  #endif
>  
> +struct reconnect_list {
>   

CODING_STYLE is off (as I mentioned before).

> +    TCPCharDriver *s;
> +    uint64_t when;
> +    struct reconnect_list *next;
> +};
> +
> +static struct reconnect_list *rc_list;
> +
> +static void qemu_chr_sched_reconnect(TCPCharDriver *s)
> +{
> +    struct reconnect_list *new = qemu_malloc(sizeof(*new));
> +    struct timeval tv;
> +
> +    gettimeofday(&tv, NULL);
>   

This will break Win32 (use qemu_gettimeofday).

> +    new->s = s;
> +    new->when = (s->reconnect + tv.tv_sec) * 1000000 + tv.tv_usec;
> +    new->next = rc_list;
> +    rc_list = new;
>   

Don't open code a list, use one of the sys-queue types.

> +}
> +
> +static int qemu_chr_connect_socket(TCPCharDriver *s);
>   

Forward declarations usually imply some form of code motion is required.

> +void qemu_chr_reconnect(void)
> +{
> +    struct reconnect_list *this = rc_list, *prev = NULL;
> +    struct timeval tv;
> +    uint64_t now;
> +
> +    if (!this)
> +        return;
> +
> +    gettimeofday(&tv, NULL);
> +    now = tv.tv_sec * 1000000 + tv.tv_usec;
> +
> +    while (this) {
> +        if (this->when <= now) {
> +            if (qemu_chr_connect_socket(this->s)) {
> +                if (prev)
> +                    prev->next = this->next;
> +                else
> +                    rc_list = NULL;
> +                qemu_chr_event(this->s->chr, CHR_EVENT_RECONNECTED);
> +                free(this);
> +                this = prev;
> +            }
> +            else {
> +                this->when += this->s->reconnect * 1000000;
> +            }
> +        }
> +        prev = this;
> +	if (this)
> +            this = this->next;
> +    }
> +}
> +
>   

Mixing tabs and spaces.

Regards,

Anthony Liguori

  parent reply	other threads:[~2009-12-03 14:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-26  0:31 [Qemu-devel] Socket reconnection Ian Molton
2009-11-26  9:21 ` Gerd Hoffmann
2009-11-27  9:01 ` Jamie Lokier
2009-12-01 11:55   ` Ian Molton
2009-12-06 14:32     ` Jamie Lokier
2009-12-06 16:33       ` Ian Molton
2009-12-07  2:29         ` Jamie Lokier
2009-12-07  9:29           ` Ian Molton
2009-11-30 17:18 ` Anthony Liguori
2009-12-01 11:54   ` Ian Molton
2009-12-01 14:38     ` Krumme, Chris
2009-12-01 18:29       ` Ian Molton
2009-12-01 18:54       ` Anthony Liguori
2009-12-02 10:40         ` Ian Molton
2009-12-02 12:04           ` [Qemu-devel] " Jan Kiszka
2009-12-02 19:56           ` [Qemu-devel] " Anthony Liguori
2009-12-02 22:35           ` Krumme, Chris
2009-12-03 10:04             ` Ian Molton
2009-12-03 10:23               ` Kevin Wolf
2009-12-03 14:22               ` Anthony Liguori [this message]
2009-12-03 18:37                 ` [Qemu-devel] [PATCH]Socket reconnection Ian Molton
2009-12-05 22:03                   ` Ian Molton

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=4B17C98F.1060208@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=Chris.Krumme@windriver.com \
    --cc=ian.molton@collabora.co.uk \
    --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).