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 9 10 11 12 13 14 15
#include "domain_conf.h"

static int testXenDefaultConsoleType(const char *ostype ATTRIBUTE_UNUSED)
{
    if (STREQ(ostype, "hvm"))
        return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
    else
        return VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
}
16 17 18 19 20

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

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

35 36
    caps->defaultConsoleTargetType = testXenDefaultConsoleType;

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

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

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

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

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

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

    return caps;

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