qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: John Snow <jsnow@redhat.com>
Cc: marc.mari.barcelo@gmail.com, pbonzini@redhat.com,
	stefanha@redhat.com, qemu-devel@nongnu.org,
	qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v3 3/9] libqos: Add migration helpers
Date: Mon, 4 May 2015 14:07:27 +0200	[thread overview]
Message-ID: <20150504120727.GF3676@noname.str.redhat.com> (raw)
In-Reply-To: <1430417242-11859-4-git-send-email-jsnow@redhat.com>

Am 30.04.2015 um 20:07 hat John Snow geschrieben:
> libqos.c:
>     -set_context for addressing which commands go where
>     -migrate performs the actual migration
> 
> malloc.c:
>     - Structure of the allocator is adjusted slightly with
>       a second-tier malloc to make swapping around the allocators
>       easy when we "migrate" the lists from the source to the destination.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  tests/libqos/libqos.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/libqos/libqos.h |  2 ++
>  tests/libqos/malloc.c | 74 ++++++++++++++++++++++++++++++++++-----------
>  tests/libqos/malloc.h |  1 +
>  4 files changed, 144 insertions(+), 17 deletions(-)
> 
> diff --git a/tests/libqos/libqos.c b/tests/libqos/libqos.c
> index 7e72078..ac1bae1 100644
> --- a/tests/libqos/libqos.c
> +++ b/tests/libqos/libqos.c
> @@ -1,5 +1,6 @@
>  #include <stdio.h>
>  #include <stdlib.h>
> +#include <string.h>
>  #include <glib.h>
>  #include <unistd.h>
>  #include <fcntl.h>
> @@ -62,6 +63,89 @@ void qtest_shutdown(QOSState *qs)
>      g_free(qs);
>  }
>  
> +void set_context(QOSState *s)
> +{
> +    global_qtest = s->qts;
> +}
> +
> +static QDict *qmp_execute(const char *command)
> +{
> +    char *fmt;
> +    QDict *rsp;
> +
> +    fmt = g_strdup_printf("{ 'execute': '%s' }", command);
> +    rsp = qmp(fmt);
> +    g_free(fmt);
> +
> +    return rsp;
> +}
> +
> +void migrate(QOSState *from, QOSState *to, const char *uri)
> +{
> +    const char *st;
> +    char *s;
> +    QDict *rsp, *sub;
> +    bool running;
> +
> +    set_context(from);
> +
> +    /* Is the machine currently running? */
> +    rsp = qmp_execute("query-status");
> +    g_assert(qdict_haskey(rsp, "return"));
> +    sub = qdict_get_qdict(rsp, "return");
> +    g_assert(qdict_haskey(sub, "running"));
> +    running = qdict_get_bool(sub, "running");
> +    QDECREF(rsp);
> +
> +    /* Issue the migrate command. */
> +    s = g_strdup_printf("{ 'execute': 'migrate',"
> +                        "'arguments': { 'uri': '%s' } }",
> +                        uri);
> +    rsp = qmp(s);
> +    g_free(s);
> +    g_assert(qdict_haskey(rsp, "return"));
> +    QDECREF(rsp);
> +
> +    /* Wait for STOP event, but only if we were running: */
> +    if (running) {
> +        qmp_eventwait("STOP");
> +    }
> +
> +    /* If we were running, we can wait for an event. */
> +    if (running) {
> +        migrate_allocator(from->alloc, to->alloc);
> +        set_context(to);
> +        qmp_eventwait("RESUME");
> +        return;
> +    }
> +
> +    /* Otherwise, we need to wait: poll until migration is completed. */
> +    while (1) {
> +        rsp = qmp_execute("query-migrate");
> +        g_assert(qdict_haskey(rsp, "return"));
> +        sub = qdict_get_qdict(rsp, "return");
> +        g_assert(qdict_haskey(sub, "status"));
> +        st = qdict_get_str(sub, "status");
> +
> +        /* "setup", "active", "completed", "failed", "cancelled" */
> +        if (strcmp(st, "completed") == 0) {
> +            QDECREF(rsp);
> +            break;
> +        }
> +
> +        if ((strcmp(st, "setup") == 0) || (strcmp(st, "active") == 0)) {
> +            QDECREF(rsp);
> +            continue;

Wouldn't it be nicer to sleep a bit before retrying?

> +        }
> +
> +        fprintf(stderr, "Migration did not complete, status: %s\n", st);
> +        g_assert_not_reached();
> +    }
> +
> +    migrate_allocator(from->alloc, to->alloc);
> +    set_context(to);
> +}

Kevin

  reply	other threads:[~2015-05-04 12:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-30 18:07 [Qemu-devel] [PATCH v3 0/9] ahci: enable migration John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 1/9] libqos/ahci: Add halted command helpers John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 2/9] libqos/ahci: Fix sector set method John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 3/9] libqos: Add migration helpers John Snow
2015-05-04 12:07   ` Kevin Wolf [this message]
2015-05-04 17:52     ` [Qemu-devel] [Qemu-block] " John Snow
2015-05-05 11:35       ` Kevin Wolf
2015-05-05 15:50         ` John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 4/9] ich9/ahci: Enable Migration John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 5/9] qtest/ahci: Add migration test John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 6/9] qtest/ahci: add migrate dma test John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 7/9] qtest/ahci: add flush migrate test John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 8/9] qtest/ahci: add halted dma test John Snow
2015-04-30 18:07 ` [Qemu-devel] [PATCH v3 9/9] qtest/ahci: add migrate " John Snow
2015-05-04 12:29 ` [Qemu-devel] [Qemu-block] [PATCH v3 0/9] ahci: enable migration Kevin Wolf
2015-05-04 15:40   ` John Snow
2015-05-05 22:45 ` [Qemu-devel] " John Snow

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=20150504120727.GF3676@noname.str.redhat.com \
    --to=kwolf@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=marc.mari.barcelo@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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).