testutilsxen.c 2.4 KB
Newer Older
1 2 3 4 5 6
#include <config.h>

#include <sys/utsname.h>
#include <stdlib.h>

#include "testutilsxen.h"
7 8
#include "domain_conf.h"

9
static int testXenDefaultConsoleType(const char *ostype,
10
                                     virArch arch ATTRIBUTE_UNUSED)
11 12 13 14 15 16
{
    if (STREQ(ostype, "hvm"))
        return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
    else
        return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
}
17 18 19 20 21

virCapsPtr testXenCapsInit(void) {
    struct utsname utsname;
    virCapsPtr caps;
    virCapsGuestPtr guest;
22 23
    virCapsGuestMachinePtr *machines;
    int nmachines;
24 25 26 27 28 29 30
    static const char *const x86_machines[] = {
        "xenfv"
    };
    static const char *const xen_machines[] = {
        "xenpv"
    };

31
    uname(&utsname);
32
    if ((caps = virCapabilitiesNew(VIR_ARCH_I686,
33 34 35
                                   0, 0)) == NULL)
        return NULL;

36 37
    caps->defaultConsoleTargetType = testXenDefaultConsoleType;

38 39 40 41
    nmachines = ARRAY_CARDINALITY(x86_machines);
    if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
        goto cleanup;

42
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686,
43
                                         "/usr/lib/xen/bin/qemu-dm", NULL,
44
                                         nmachines, machines)) == NULL)
45
        goto cleanup;
46 47
    machines = NULL;

48 49 50 51 52 53 54 55
    if (virCapabilitiesAddGuestDomain(guest,
                                      "xen",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

56 57 58 59
    nmachines = ARRAY_CARDINALITY(xen_machines);
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

60
    if ((guest = virCapabilitiesAddGuest(caps, "xen", VIR_ARCH_I686,
61
                                         "/usr/lib/xen/bin/qemu-dm", NULL,
62
                                         nmachines, machines)) == NULL)
63
        goto cleanup;
64 65
    machines = NULL;

66 67 68 69 70 71 72 73 74 75 76
    if (virCapabilitiesAddGuestDomain(guest,
                                      "xen",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

    return caps;

cleanup:
77
    virCapabilitiesFreeMachines(machines, nmachines);
78 79 80
    virCapabilitiesFree(caps);
    return NULL;
}