testutilsqemu.c 4.4 KB
Newer Older
1
#include <config.h>
A
Atsushi SAKAI 已提交
2
#ifdef WITH_QEMU
3 4 5 6
#include <sys/utsname.h>
#include <stdlib.h>

#include "testutilsqemu.h"
7 8
#include "testutils.h"
#include "memory.h"
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
static virCapsGuestMachinePtr *testQemuAllocMachines(int *nmachines)
{
    virCapsGuestMachinePtr *machines;
    static const char *const x86_machines[] = {
        "pc", "isapc"
    };

    machines = virCapabilitiesAllocMachines(x86_machines,
                                            ARRAY_CARDINALITY(x86_machines));
    if (machines == NULL)
        return NULL;

    *nmachines = ARRAY_CARDINALITY(x86_machines);

    return machines;
}

M
Mark McLoughlin 已提交
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/* Newer versions of qemu have versioned machine types to allow
 * compatibility with older releases.
 * The 'pc' machine type is an alias of the newest machine type.
 */
static virCapsGuestMachinePtr *testQemuAllocNewerMachines(int *nmachines)
{
    virCapsGuestMachinePtr *machines;
    char *canonical;
    static const char *const x86_machines[] = {
        "pc-0.11", "pc", "pc-0.10", "isapc"
    };

    if ((canonical = strdup(x86_machines[0])) == NULL)
        return NULL;

    machines = virCapabilitiesAllocMachines(x86_machines,
                                            ARRAY_CARDINALITY(x86_machines));
    if (machines == NULL) {
        VIR_FREE(canonical);
        return NULL;
    }

    machines[1]->canonical = canonical;

    *nmachines = ARRAY_CARDINALITY(x86_machines);

    return machines;
}

56 57 58 59
virCapsPtr testQemuCapsInit(void) {
    struct utsname utsname;
    virCapsPtr caps;
    virCapsGuestPtr guest;
60 61
    virCapsGuestMachinePtr *machines;
    int nmachines;
62 63 64 65 66 67 68 69 70
    static const char *const xen_machines[] = {
        "xenner"
    };

    uname (&utsname);
    if ((caps = virCapabilitiesNew(utsname.machine,
                                   0, 0)) == NULL)
        return NULL;

71
    if ((machines = testQemuAllocMachines(&nmachines)) == NULL)
72 73
        goto cleanup;

74 75
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
                                         "/usr/bin/qemu", NULL,
76
                                         nmachines, machines)) == NULL)
77
        goto cleanup;
78 79
    machines = NULL;

80 81 82 83 84 85 86 87
    if (virCapabilitiesAddGuestDomain(guest,
                                      "qemu",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

M
Mark McLoughlin 已提交
88
    if ((machines = testQemuAllocNewerMachines(&nmachines)) == NULL)
89 90
        goto cleanup;

91 92
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 64,
                                         "/usr/bin/qemu-system-x86_64", NULL,
93
                                         nmachines, machines)) == NULL)
94
        goto cleanup;
95 96
    machines = NULL;

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    if (virCapabilitiesAddGuestDomain(guest,
                                      "qemu",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

112
    nmachines = ARRAY_CARDINALITY(xen_machines);
113 114 115
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

116 117
    if ((guest = virCapabilitiesAddGuest(caps, "xen", "x86_64", 64,
                                         "/usr/bin/xenner", NULL,
118
                                         nmachines, machines)) == NULL)
119
        goto cleanup;
120 121
    machines = NULL;

122 123 124 125 126 127 128 129
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

130 131 132 133 134 135 136 137 138 139 140 141
    if (testDebug) {
        char *caps_str;

        caps_str = virCapabilitiesFormatXML(caps);
        if (!caps_str)
            goto cleanup;

        fprintf(stderr, "QEMU driver capabilities:\n%s", caps_str);

        VIR_FREE(caps_str);
    }

142 143 144
    return caps;

cleanup:
145
    virCapabilitiesFreeMachines(machines, nmachines);
146 147 148
    virCapabilitiesFree(caps);
    return NULL;
}
A
Atsushi SAKAI 已提交
149
#endif