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

#include <sys/utsname.h>

#include "testutilsxen.h"
P
Pavel Hrdina 已提交
6
#include "testutilshostcpus.h"
7 8
#include "domain_conf.h"

9 10 11 12 13 14 15 16 17 18 19
virCapsPtr
testXLInitCaps(void)
{
    virCapsPtr caps;
    virCapsGuestPtr guest;
    virCapsGuestMachinePtr *machines;
    int nmachines;
    static const char *const x86_machines[] = {
        "xenfv"
    };
    static const char *const xen_machines[] = {
20 21 22 23
        "xenpv",
    };
    static const char *const pvh_machines[] = {
        "xenpvh",
24 25 26 27 28
    };

    if ((caps = virCapabilitiesNew(virArchFromHost(),
                                   false, false)) == NULL)
        return NULL;
29 30 31

    caps->host.cpu = virCPUDefCopy(&cpuDefaultData);

32
    nmachines = G_N_ELEMENTS(x86_machines);
33 34
    if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
        goto cleanup;
35 36
    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_HVM,
                                         VIR_ARCH_X86_64,
37 38
                                         "/usr/lib/xen/bin/qemu-system-i386",
                                         "/usr/lib/xen/boot/hvmloader",
39 40 41
                                         nmachines, machines)) == NULL)
        goto cleanup;
    machines = NULL;
42
    if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
43 44
                                      NULL, 0, NULL) == NULL)
        goto cleanup;
45
    nmachines = G_N_ELEMENTS(xen_machines);
46 47 48
    if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
        goto cleanup;

49 50
    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_XEN,
                                         VIR_ARCH_X86_64,
51 52 53
                                         "/usr/lib/xen/bin/qemu-system-i386",
                                         NULL,
                                         nmachines, machines)) == NULL)
54 55 56
        goto cleanup;
    machines = NULL;

57 58 59
    if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
                                      NULL, 0, NULL) == NULL)
        goto cleanup;
60
    nmachines = G_N_ELEMENTS(pvh_machines);
61 62 63 64 65 66 67 68 69 70 71
    if ((machines = virCapabilitiesAllocMachines(pvh_machines, nmachines)) == NULL)
        goto cleanup;

    if ((guest = virCapabilitiesAddGuest(caps, VIR_DOMAIN_OSTYPE_XENPVH,
                                         VIR_ARCH_X86_64,
                                         "/usr/lib/xen/bin/qemu-system-i386",
                                         NULL,
                                         nmachines, machines)) == NULL)
        goto cleanup;
    machines = NULL;

72
    if (virCapabilitiesAddGuestDomain(guest, VIR_DOMAIN_VIRT_XEN, NULL,
73 74 75 76 77 78 79 80 81
                                      NULL, 0, NULL) == NULL)
        goto cleanup;
    return caps;

 cleanup:
    virCapabilitiesFreeMachines(machines, nmachines);
    virObjectUnref(caps);
    return NULL;
}