2008-05-22 20:18:40 +04:00
# include <config.h>
2008-06-26 13:37:51 +04:00
# ifdef WITH_QEMU
2010-03-09 21:22:22 +03:00
# include <sys / utsname.h>
# include <stdlib.h>
2008-05-16 20:51:30 +04:00
2010-03-09 21:22:22 +03:00
# include "testutilsqemu.h"
# include "testutils.h"
# include "memory.h"
2010-04-16 10:01:59 +04:00
# include "cpu_conf.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 ;
2010-04-22 19:00:30 +04:00
virCapsGuestMachinePtr * machines = NULL ;
int nmachines = 0 ;
2008-05-16 20:51:30 +04:00
static const char * const xen_machines [ ] = {
" xenner "
} ;
2010-04-16 10:01:59 +04:00
static virCPUFeatureDef host_cpu_features [ ] = {
{ ( char * ) " lahf_lm " , - 1 } ,
{ ( char * ) " xtpr " , - 1 } ,
{ ( char * ) " cx16 " , - 1 } ,
{ ( char * ) " tm2 " , - 1 } ,
{ ( char * ) " est " , - 1 } ,
{ ( char * ) " vmx " , - 1 } ,
{ ( char * ) " ds_cpl " , - 1 } ,
{ ( char * ) " pbe " , - 1 } ,
{ ( char * ) " tm " , - 1 } ,
{ ( char * ) " ht " , - 1 } ,
{ ( char * ) " ss " , - 1 } ,
{ ( char * ) " acpi " , - 1 } ,
{ ( char * ) " ds " , - 1 }
} ;
static virCPUDef host_cpu = {
VIR_CPU_TYPE_HOST , /* type */
0 , /* match */
( char * ) " x86_64 " , /* arch */
( char * ) " core2duo " , /* model */
1 , /* sockets */
2 , /* cores */
1 , /* threads */
ARRAY_CARDINALITY ( host_cpu_features ) , /* nfeatures */
host_cpu_features /* features */
} ;
2008-05-16 20:51:30 +04:00
uname ( & utsname ) ;
if ( ( caps = virCapabilitiesNew ( utsname . machine ,
0 , 0 ) ) = = NULL )
return NULL ;
2010-04-16 10:01:59 +04:00
if ( ( caps - > host . cpu = virCPUDefCopy ( & host_cpu ) ) = = NULL | |
( 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 ;
2009-09-10 14:22:32 +04:00
if ( ( machines = testQemuAllocMachines ( & nmachines ) ) = = NULL )
goto cleanup ;
2008-05-16 20:51:30 +04:00
if ( virCapabilitiesAddGuestDomain ( guest ,
" kvm " ,
" /usr/bin/kvm " ,
NULL ,
2009-09-10 14:22:32 +04:00
nmachines ,
machines ) = = NULL )
2008-05-16 20:51:30 +04:00
goto cleanup ;
2009-09-10 14:22:32 +04:00
machines = NULL ;
2008-05-16 20:51:30 +04:00
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-11-30 22:01:31 +03:00
if ( virTestGetDebug ( ) ) {
2009-09-10 14:07:20 +04:00
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