testutilsxen.c 2.1 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

10 11
virCapsPtr testXenCapsInit(void)
{
12 13 14
    struct utsname utsname;
    virCapsPtr caps;
    virCapsGuestPtr guest;
15 16
    virCapsGuestMachinePtr *machines;
    int nmachines;
17 18 19 20 21 22 23
    static const char *const x86_machines[] = {
        "xenfv"
    };
    static const char *const xen_machines[] = {
        "xenpv"
    };

24
    uname(&utsname);
25
    if ((caps = virCapabilitiesNew(VIR_ARCH_I686,
26 27 28
                                   0, 0)) == NULL)
        return NULL;

29 30 31 32
    nmachines = ARRAY_CARDINALITY(x86_machines);
    if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
        goto cleanup;

33
    if ((guest = virCapabilitiesAddGuest(caps, "hvm", VIR_ARCH_I686,
34
                                         "/usr/lib/xen/bin/qemu-dm", NULL,
35
                                         nmachines, machines)) == NULL)
36
        goto cleanup;
37 38
    machines = NULL;

39 40 41 42 43 44 45 46
    if (virCapabilitiesAddGuestDomain(guest,
                                      "xen",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

47 48 49 50
    nmachines = ARRAY_CARDINALITY(xen_machines);
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

51
    if ((guest = virCapabilitiesAddGuest(caps, "xen", VIR_ARCH_I686,
52
                                         "/usr/lib/xen/bin/qemu-dm", NULL,
53
                                         nmachines, machines)) == NULL)
54
        goto cleanup;
55 56
    machines = NULL;

57 58 59 60 61 62 63 64 65 66 67
    if (virCapabilitiesAddGuestDomain(guest,
                                      "xen",
                                      NULL,
                                      NULL,
                                      0,
                                      NULL) == NULL)
        goto cleanup;

    return caps;

cleanup:
68
    virCapabilitiesFreeMachines(machines, nmachines);
69
    virObjectUnref(caps);
70 71
    return NULL;
}