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

6 7 8
# include "testutilsqemu.h"
# 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
    if (virCapabilitiesAddGuestDomain(guest,
                                      "qemu",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;
104 105 106 107

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

108 109 110 111
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
112 113
                                      nmachines,
                                      machines) == NULL)
114
        goto cleanup;
115
    machines = NULL;
116

117
    nmachines = ARRAY_CARDINALITY(xen_machines);
118 119 120
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

121 122
    if ((guest = virCapabilitiesAddGuest(caps, "xen", "x86_64", 64,
                                         "/usr/bin/xenner", NULL,
123
                                         nmachines, machines)) == NULL)
124
        goto cleanup;
125 126
    machines = NULL;

127 128 129 130 131 132 133 134
    if (virCapabilitiesAddGuestDomain(guest,
                                      "kvm",
                                      "/usr/bin/kvm",
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

135
    if (virTestGetDebug()) {
136 137 138 139 140 141 142 143 144 145 146
        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);
    }

147 148 149
    return caps;

cleanup:
150
    virCapabilitiesFreeMachines(machines, nmachines);
151 152 153
    virCapabilitiesFree(caps);
    return NULL;
}
A
Atsushi SAKAI 已提交
154
#endif