1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00
libvirt/tests/testutilsqemu.c
Mark McLoughlin 38fd207e53 Add virCapsGuestMachine structure
A subsequent commit will add a "canonical" field to this structure,
this patch basically just prepares the way for that.

The new type is added, along with virCapabilitiesAlloc/FreeMachines()
helpers and a whole bunch of code to make the transition.

One quirk is that virCapabilitiesAddGuestDomain() and
virCapabilitiesAddGuest() take ownership of the machine list rather
than duping it. This makes sense to avoid needless copying.

* src/capabilities.h: add the virCapsGuestMachine struct and use it
  in virCapsGuestDomainInfo, add prototypes for new functions and
  update the AddGuest() prototypes

* src/capabilities.c: add code for allocating and freeing the new
  type, change the machines parameter to AddGuest() etc.

* src/libvirt_private.syms: export the new helpers

* src/qemu_conf.c: update all the machine type code to use the new
  struct

* src/xen_internal.c: ditto

* tests/testutilsqemu.c: ditto
2009-07-27 15:17:55 +01:00

95 lines
3.0 KiB
C

#include <config.h>
#ifdef WITH_QEMU
#include <sys/utsname.h>
#include <stdlib.h>
#include "testutilsqemu.h"
virCapsPtr testQemuCapsInit(void) {
struct utsname utsname;
virCapsPtr caps;
virCapsGuestPtr guest;
virCapsGuestMachinePtr *machines;
int nmachines;
static const char *const x86_machines[] = {
"pc", "isapc"
};
static const char *const xen_machines[] = {
"xenner"
};
uname (&utsname);
if ((caps = virCapabilitiesNew(utsname.machine,
0, 0)) == NULL)
return NULL;
nmachines = 2;
if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "i686", 32,
"/usr/bin/qemu", NULL,
nmachines, machines)) == NULL)
goto cleanup;
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"qemu",
NULL,
NULL,
0,
NULL) == NULL)
goto cleanup;
nmachines = 2;
if ((machines = virCapabilitiesAllocMachines(x86_machines, nmachines)) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "hvm", "x86_64", 64,
"/usr/bin/qemu-system-x86_64", NULL,
nmachines, machines)) == NULL)
goto cleanup;
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"qemu",
NULL,
NULL,
0,
NULL) == NULL)
goto cleanup;
if (virCapabilitiesAddGuestDomain(guest,
"kvm",
"/usr/bin/kvm",
NULL,
0,
NULL) == NULL)
goto cleanup;
nmachines = 1;
if ((machines = virCapabilitiesAllocMachines(xen_machines, nmachines)) == NULL)
goto cleanup;
if ((guest = virCapabilitiesAddGuest(caps, "xen", "x86_64", 64,
"/usr/bin/xenner", NULL,
1, machines)) == NULL)
goto cleanup;
machines = NULL;
if (virCapabilitiesAddGuestDomain(guest,
"kvm",
"/usr/bin/kvm",
NULL,
0,
NULL) == NULL)
goto cleanup;
return caps;
cleanup:
virCapabilitiesFreeMachines(machines, nmachines);
virCapabilitiesFree(caps);
return NULL;
}
#endif