2008-05-22 20:18:40 +04:00
# include <config.h>
2008-06-26 13:37:51 +04:00
# ifdef WITH_QEMU
2008-05-16 20:51:30 +04:00
# include <sys/utsname.h>
# include <stdlib.h>
# include "testutilsqemu.h"
2009-09-10 14:07:20 +04:00
# include "testutils.h"
# include "memory.h"
2008-05-16 20:51:30 +04:00
2009-09-10 13:16:27 +04:00
static virCapsGuestMachinePtr * testQemuAllocMachines ( int * nmachines )
{
virCapsGuestMachinePtr * machines ;
static const char * const x86_machines [ ] = {
" pc " , " isapc "
} ;
machines = virCapabilitiesAllocMachines ( x86_machines ,
ARRAY_CARDINALITY ( x86_machines ) ) ;
if ( machines = = NULL )
return NULL ;
* nmachines = ARRAY_CARDINALITY ( x86_machines ) ;
return machines ;
}
2009-09-10 14:19:12 +04:00
/* Newer versions of qemu have versioned machine types to allow
* compatibility with older releases .
* The ' pc ' machine type is an alias of the newest machine type .
*/
static virCapsGuestMachinePtr * testQemuAllocNewerMachines ( int * nmachines )
{
virCapsGuestMachinePtr * machines ;
char * canonical ;
static const char * const x86_machines [ ] = {
" pc-0.11 " , " pc " , " pc-0.10 " , " isapc "
} ;
if ( ( canonical = strdup ( x86_machines [ 0 ] ) ) = = NULL )
return NULL ;
machines = virCapabilitiesAllocMachines ( x86_machines ,
ARRAY_CARDINALITY ( x86_machines ) ) ;
if ( machines = = NULL ) {
VIR_FREE ( canonical ) ;
return NULL ;
}
machines [ 1 ] - > canonical = canonical ;
* nmachines = ARRAY_CARDINALITY ( x86_machines ) ;
return machines ;
}
2008-05-16 20:51:30 +04:00
virCapsPtr testQemuCapsInit ( void ) {
struct utsname utsname ;
virCapsPtr caps ;
virCapsGuestPtr guest ;
2009-07-23 21:31:34 +04:00
virCapsGuestMachinePtr * machines ;
int nmachines ;
2008-05-16 20:51:30 +04:00
static const char * const xen_machines [ ] = {
" xenner "
} ;
uname ( & utsname ) ;
if ( ( caps = virCapabilitiesNew ( utsname . machine ,
0 , 0 ) ) = = NULL )
return NULL ;
2009-09-10 13:16:27 +04:00
if ( ( machines = testQemuAllocMachines ( & nmachines ) ) = = NULL )
2009-07-23 21:31:34 +04:00
goto cleanup ;
2008-05-16 20:51:30 +04:00
if ( ( guest = virCapabilitiesAddGuest ( caps , " hvm " , " i686 " , 32 ,
" /usr/bin/qemu " , NULL ,
2009-07-23 21:31:34 +04:00
nmachines , machines ) ) = = NULL )
2008-05-16 20:51:30 +04:00
goto cleanup ;
2009-07-23 21:31:34 +04:00
machines = NULL ;
2008-05-16 20:51:30 +04:00
if ( virCapabilitiesAddGuestDomain ( guest ,
" qemu " ,
NULL ,
NULL ,
0 ,
NULL ) = = NULL )
goto cleanup ;
2009-09-10 14:19:12 +04:00
if ( ( machines = testQemuAllocNewerMachines ( & nmachines ) ) = = NULL )
2009-07-23 21:31:34 +04:00
goto cleanup ;
2008-05-16 20:51:30 +04:00
if ( ( guest = virCapabilitiesAddGuest ( caps , " hvm " , " x86_64 " , 64 ,
" /usr/bin/qemu-system-x86_64 " , NULL ,
2009-07-23 21:31:34 +04:00
nmachines , machines ) ) = = NULL )
2008-05-16 20:51:30 +04:00
goto cleanup ;
2009-07-23 21:31:34 +04:00
machines = NULL ;
2008-05-16 20:51:30 +04:00
if ( virCapabilitiesAddGuestDomain ( guest ,
" qemu " ,
NULL ,
NULL ,
0 ,
NULL ) = = NULL )
goto cleanup ;
if ( virCapabilitiesAddGuestDomain ( guest ,
" kvm " ,
" /usr/bin/kvm " ,
NULL ,
0 ,
NULL ) = = NULL )
goto cleanup ;
2009-09-10 13:16:27 +04:00
nmachines = ARRAY_CARDINALITY ( xen_machines ) ;
2009-07-23 21:31:34 +04:00
if ( ( machines = virCapabilitiesAllocMachines ( xen_machines , nmachines ) ) = = NULL )
goto cleanup ;
2008-05-16 20:51:30 +04:00
if ( ( guest = virCapabilitiesAddGuest ( caps , " xen " , " x86_64 " , 64 ,
" /usr/bin/xenner " , NULL ,
2009-09-10 13:16:27 +04:00
nmachines , machines ) ) = = NULL )
2008-05-16 20:51:30 +04:00
goto cleanup ;
2009-07-23 21:31:34 +04:00
machines = NULL ;
2008-05-16 20:51:30 +04:00
if ( virCapabilitiesAddGuestDomain ( guest ,
" kvm " ,
" /usr/bin/kvm " ,
NULL ,
0 ,
NULL ) = = NULL )
goto cleanup ;
2009-09-10 14:07:20 +04:00
if ( testDebug ) {
char * caps_str ;
caps_str = virCapabilitiesFormatXML ( caps ) ;
if ( ! caps_str )
goto cleanup ;
fprintf ( stderr , " QEMU driver capabilities: \n %s " , caps_str ) ;
VIR_FREE ( caps_str ) ;
}
2008-05-16 20:51:30 +04:00
return caps ;
cleanup :
2009-07-23 21:31:34 +04:00
virCapabilitiesFreeMachines ( machines , nmachines ) ;
2008-05-16 20:51:30 +04:00
virCapabilitiesFree ( caps ) ;
return NULL ;
}
2008-06-26 13:37:51 +04:00
# endif