Commit 3d95fb97 authored by Eric Blake's avatar Eric Blake Committed by Thomas Huth
Browse files

libqos: Use explicit QTestState for remaining libqos operations



Drop one more client of global_qtest by teaching all remaining
libqos stragglers to pass in an explicit QTestState.  Change the
setting of global_qtest from being implicit in libqos' call to
qtest_start() to instead be explicit in all clients that are
still relying on global_qtest.

Note that qmp_execute() can be greatly simplified in the process,
and that we also get rid of interpolation of a JSON string into a
temporary variable when qtest_qmp() can do it more reliably.

Signed-off-by: default avatarEric Blake <eblake@redhat.com>
Acked-by: default avatarGreg Kurz <groug@kaod.org>
Reviewed-by: default avatarJohn Snow <jsnow@redhat.com>
Signed-off-by: default avatarThomas Huth <thuth@redhat.com>
parent 10747e55
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -158,6 +158,7 @@ static AHCIQState *ahci_vboot(const char *cli, va_list ap)

    s = g_new0(AHCIQState, 1);
    s->parent = qtest_pc_vboot(cli, ap);
    global_qtest = s->parent->qts;
    alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);

    /* Verify that we have an AHCI device present. */
+1 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ static void setup_vm_cmd(IVState *s, const char *cmd, bool msix)
        g_printerr("ivshmem-test tests are only available on x86 or ppc64\n");
        exit(EXIT_FAILURE);
    }
    global_qtest = s->qs->qts;
    s->dev = get_device(s->qs->pcibus);

    s->reg_bar = qpci_iomap(s->dev, 0, &barsize);
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ QOSState *qtest_pc_boot(const char *cmdline_fmt, ...)
    qs = qtest_vboot(&qos_ops, cmdline_fmt, ap);
    va_end(ap);

    qtest_irq_intercept_in(global_qtest, "ioapic");
    qtest_irq_intercept_in(qs->qts, "ioapic");

    return qs;
}
+10 −20
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ QOSState *qtest_vboot(QOSOps *ops, const char *cmdline_fmt, va_list ap)
    QOSState *qs = g_new0(QOSState, 1);

    cmdline = g_strdup_vprintf(cmdline_fmt, ap);
    qs->qts = qtest_start(cmdline);
    qs->qts = qtest_init(cmdline);
    qs->ops = ops;
    if (ops) {
        qs->alloc = ops->init_allocator(qs->qts, ALLOC_NO_FLAGS);
@@ -81,29 +81,21 @@ void set_context(QOSState *s)
    global_qtest = s->qts;
}

static QDict *qmp_execute(const char *command)
static QDict *qmp_execute(QTestState *qts, const char *command)
{
    char *fmt;
    QDict *rsp;

    fmt = g_strdup_printf("{ 'execute': '%s' }", command);
    rsp = qmp(fmt);
    g_free(fmt);

    return rsp;
    return qtest_qmp(qts, "{ 'execute': %s }", command);
}

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");
    rsp = qmp_execute(from->qts, "query-status");
    g_assert(qdict_haskey(rsp, "return"));
    sub = qdict_get_qdict(rsp, "return");
    g_assert(qdict_haskey(sub, "running"));
@@ -111,30 +103,28 @@ void migrate(QOSState *from, QOSState *to, const char *uri)
    QDECREF(rsp);

    /* Issue the migrate command. */
    s = g_strdup_printf("{ 'execute': 'migrate',"
                        "'arguments': { 'uri': '%s' } }",
    rsp = qtest_qmp(from->qts,
                    "{ '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");
        qtest_qmp_eventwait(from->qts, "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");
        qtest_qmp_eventwait(to->qts, "RESUME");
        return;
    }

    /* Otherwise, we need to wait: poll until migration is completed. */
    while (1) {
        rsp = qmp_execute("query-migrate");
        rsp = qmp_execute(from->qts, "query-migrate");
        g_assert(qdict_haskey(rsp, "return"));
        sub = qdict_get_qdict(rsp, "return");
        g_assert(qdict_haskey(sub, "status"));
+4 −1
Original line number Diff line number Diff line
@@ -15,13 +15,16 @@

static QOSState *qmegasas_start(const char *extra_opts)
{
    QOSState *qs;
    const char *arch = qtest_get_arch();
    const char *cmd = "-drive id=hd0,if=none,file=null-co://,format=raw "
                      "-device megasas,id=scsi0,addr=04.0 "
                      "-device scsi-hd,bus=scsi0.0,drive=hd0 %s";

    if (strcmp(arch, "i386") == 0 || strcmp(arch, "x86_64") == 0) {
        return qtest_pc_boot(cmd, extra_opts ? : "");
        qs = qtest_pc_boot(cmd, extra_opts ? : "");
        global_qtest = qs->qts;
        return qs;
    }

    g_printerr("virtio-scsi tests are only available on x86 or ppc64\n");
Loading