2008-02-27 04:35:08 +00:00
|
|
|
/*
|
|
|
|
* capabilities.c: hypervisor capabilities
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2008 Red Hat, Inc.
|
|
|
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2008-02-27 14:40:19 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2008-02-27 04:35:08 +00:00
|
|
|
#include "capabilities.h"
|
|
|
|
#include "buf.h"
|
2008-04-28 21:44:54 +00:00
|
|
|
#include "memory.h"
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesNew:
|
|
|
|
* @arch: host machine architecture
|
|
|
|
* @offlineMigrate: non-zero if offline migration is available
|
|
|
|
* @liveMigrate: non-zero if live migration is available
|
2008-02-27 14:40:19 +00:00
|
|
|
*
|
2008-02-27 04:35:08 +00:00
|
|
|
* Allocate a new capabilities object
|
|
|
|
*/
|
|
|
|
virCapsPtr
|
|
|
|
virCapabilitiesNew(const char *arch,
|
|
|
|
int offlineMigrate,
|
|
|
|
int liveMigrate)
|
|
|
|
{
|
|
|
|
virCapsPtr caps;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC(caps) < 0)
|
2008-05-29 15:28:28 +00:00
|
|
|
return NULL;
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
if ((caps->host.arch = strdup(arch)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
caps->host.offlineMigrate = offlineMigrate;
|
|
|
|
caps->host.liveMigrate = liveMigrate;
|
|
|
|
|
|
|
|
return caps;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
virCapabilitiesFree(caps);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virCapabilitiesFreeHostNUMACell(virCapsHostNUMACellPtr cell)
|
|
|
|
{
|
2008-05-29 15:28:28 +00:00
|
|
|
if (cell == NULL)
|
|
|
|
return;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(cell->cpus);
|
|
|
|
VIR_FREE(cell);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virCapabilitiesFreeGuestDomain(virCapsGuestDomainPtr dom)
|
|
|
|
{
|
|
|
|
int i;
|
2008-05-29 15:28:28 +00:00
|
|
|
if (dom == NULL)
|
|
|
|
return;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(dom->info.emulator);
|
|
|
|
VIR_FREE(dom->info.loader);
|
2008-02-27 04:35:08 +00:00
|
|
|
for (i = 0 ; i < dom->info.nmachines ; i++)
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(dom->info.machines[i]);
|
|
|
|
VIR_FREE(dom->info.machines);
|
|
|
|
VIR_FREE(dom->type);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(dom);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virCapabilitiesFreeGuestFeature(virCapsGuestFeaturePtr feature)
|
|
|
|
{
|
2008-05-29 15:28:28 +00:00
|
|
|
if (feature == NULL)
|
|
|
|
return;
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(feature->name);
|
|
|
|
VIR_FREE(feature);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
virCapabilitiesFreeGuest(virCapsGuestPtr guest)
|
|
|
|
{
|
|
|
|
int i;
|
2008-05-29 15:28:28 +00:00
|
|
|
if (guest == NULL)
|
|
|
|
return;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(guest->ostype);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(guest->arch.name);
|
|
|
|
VIR_FREE(guest->arch.defaultInfo.emulator);
|
|
|
|
VIR_FREE(guest->arch.defaultInfo.loader);
|
2008-02-27 04:35:08 +00:00
|
|
|
for (i = 0 ; i < guest->arch.defaultInfo.nmachines ; i++)
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(guest->arch.defaultInfo.machines[i]);
|
|
|
|
VIR_FREE(guest->arch.defaultInfo.machines);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
for (i = 0 ; i < guest->arch.ndomains ; i++)
|
|
|
|
virCapabilitiesFreeGuestDomain(guest->arch.domains[i]);
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(guest->arch.domains);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
for (i = 0 ; i < guest->nfeatures ; i++)
|
|
|
|
virCapabilitiesFreeGuestFeature(guest->features[i]);
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(guest->features);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(guest);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesFree:
|
|
|
|
* @caps: object to free
|
|
|
|
*
|
|
|
|
* Free all memory associated with capabilities
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
virCapabilitiesFree(virCapsPtr caps) {
|
|
|
|
int i;
|
2008-05-29 15:28:28 +00:00
|
|
|
if (caps == NULL)
|
|
|
|
return;
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
for (i = 0 ; i < caps->nguests ; i++)
|
|
|
|
virCapabilitiesFreeGuest(caps->guests[i]);
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(caps->guests);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
for (i = 0 ; i < caps->host.nfeatures ; i++)
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(caps->host.features[i]);
|
|
|
|
VIR_FREE(caps->host.features);
|
2008-02-27 04:35:08 +00:00
|
|
|
for (i = 0 ; i < caps->host.nnumaCell ; i++)
|
|
|
|
virCapabilitiesFreeHostNUMACell(caps->host.numaCell[i]);
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(caps->host.numaCell);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-03-03 13:15:14 +00:00
|
|
|
for (i = 0 ; i < caps->host.nmigrateTrans ; i++)
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(caps->host.migrateTrans[i]);
|
|
|
|
VIR_FREE(caps->host.migrateTrans);
|
2008-03-03 13:15:14 +00:00
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
VIR_FREE(caps->host.arch);
|
|
|
|
VIR_FREE(caps);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesAddHostFeature:
|
|
|
|
* @caps: capabilities to extend
|
|
|
|
* @name: name of new feature
|
|
|
|
*
|
|
|
|
* Registers a new host CPU feature, eg 'pae', or 'vmx'
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virCapabilitiesAddHostFeature(virCapsPtr caps,
|
|
|
|
const char *name)
|
|
|
|
{
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_REALLOC_N(caps->host.features,
|
|
|
|
caps->host.nfeatures + 1) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ((caps->host.features[caps->host.nfeatures] = strdup(name)) == NULL)
|
|
|
|
return -1;
|
|
|
|
caps->host.nfeatures++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesAddHostMigrateTransport:
|
|
|
|
* @caps: capabilities to extend
|
|
|
|
* @name: name of migration transport
|
|
|
|
*
|
|
|
|
* Registers a new domain migration transport URI
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virCapabilitiesAddHostMigrateTransport(virCapsPtr caps,
|
|
|
|
const char *name)
|
|
|
|
{
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_REALLOC_N(caps->host.migrateTrans,
|
|
|
|
caps->host.nmigrateTrans + 1) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
if ((caps->host.migrateTrans[caps->host.nmigrateTrans] = strdup(name)) == NULL)
|
|
|
|
return -1;
|
|
|
|
caps->host.nmigrateTrans++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesAddHostNUMACell:
|
|
|
|
* @caps: capabilities to extend
|
|
|
|
* @num: ID number of NUMA cell
|
|
|
|
* @ncpus: number of CPUs in cell
|
|
|
|
* @cpus: array of CPU ID numbers for cell
|
|
|
|
*
|
|
|
|
* Registers a new NUMA cell for a host, passing in a
|
|
|
|
* array of CPU IDs belonging to the cell
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
virCapabilitiesAddHostNUMACell(virCapsPtr caps,
|
|
|
|
int num,
|
|
|
|
int ncpus,
|
|
|
|
const int *cpus)
|
|
|
|
{
|
2008-04-28 21:44:54 +00:00
|
|
|
virCapsHostNUMACellPtr cell;
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_REALLOC_N(caps->host.numaCell,
|
|
|
|
caps->host.nnumaCell + 1) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
return -1;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC(cell) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
return -1;
|
|
|
|
caps->host.numaCell[caps->host.nnumaCell] = cell;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC_N(caps->host.numaCell[caps->host.nnumaCell]->cpus,
|
|
|
|
ncpus) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
return -1;
|
|
|
|
memcpy(caps->host.numaCell[caps->host.nnumaCell]->cpus,
|
|
|
|
cpus,
|
|
|
|
ncpus * sizeof(*cpus));
|
|
|
|
|
|
|
|
caps->host.numaCell[caps->host.nnumaCell]->ncpus = ncpus;
|
|
|
|
caps->host.numaCell[caps->host.nnumaCell]->num = num;
|
|
|
|
caps->host.nnumaCell++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesAddGuest:
|
|
|
|
* @caps: capabilities to extend
|
|
|
|
* @ostype: guest operating system type ('hvm' or 'xen')
|
|
|
|
* @arch: guest CPU architecture ('i686', or 'x86_64', etc)
|
|
|
|
* @wordsize: number of bits in CPU word
|
|
|
|
* @emulator: path to default device emulator for arch/ostype
|
|
|
|
* @loader: path to default BIOS loader for arch/ostype
|
|
|
|
* @nmachines: number of machine variants for emulator
|
|
|
|
* @machines: machine variants for emulator ('pc', or 'isapc', etc)
|
|
|
|
*
|
|
|
|
* Registers a new guest operating system. This should be
|
|
|
|
* followed by registration of at least one domain for
|
|
|
|
* running the guest
|
|
|
|
*/
|
|
|
|
virCapsGuestPtr
|
|
|
|
virCapabilitiesAddGuest(virCapsPtr caps,
|
|
|
|
const char *ostype,
|
|
|
|
const char *arch,
|
|
|
|
int wordsize,
|
|
|
|
const char *emulator,
|
|
|
|
const char *loader,
|
|
|
|
int nmachines,
|
|
|
|
const char *const *machines)
|
|
|
|
{
|
2008-04-28 21:44:54 +00:00
|
|
|
virCapsGuestPtr guest;
|
2008-02-27 04:35:08 +00:00
|
|
|
int i;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC(guest) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if ((guest->ostype = strdup(ostype)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if ((guest->arch.name = strdup(arch)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
guest->arch.wordsize = wordsize;
|
|
|
|
|
|
|
|
if (emulator &&
|
|
|
|
(guest->arch.defaultInfo.emulator = strdup(emulator)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
if (loader &&
|
|
|
|
(guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
if (nmachines) {
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC_N(guest->arch.defaultInfo.machines,
|
|
|
|
nmachines) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
for (i = 0 ; i < nmachines ; i++) {
|
|
|
|
if ((guest->arch.defaultInfo.machines[i] = strdup(machines[i])) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
guest->arch.defaultInfo.nmachines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_REALLOC_N(caps->guests,
|
|
|
|
caps->nguests + 1) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
caps->guests[caps->nguests] = guest;
|
|
|
|
caps->nguests++;
|
|
|
|
|
|
|
|
return guest;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
virCapabilitiesFreeGuest(guest);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesAddGuestDomain:
|
|
|
|
* @guest: guest to support
|
|
|
|
* @hvtype: hypervisor type ('xen', 'qemu', 'kvm')
|
|
|
|
* @emulator: specialized device emulator for domain
|
|
|
|
* @loader: specialized BIOS loader for domain
|
|
|
|
* @nmachines: number of machine variants for emulator
|
|
|
|
* @machines: specialized machine variants for emulator
|
|
|
|
*
|
|
|
|
* Registers a virtual domain capable of running a
|
|
|
|
* guest operating system
|
|
|
|
*/
|
|
|
|
virCapsGuestDomainPtr
|
|
|
|
virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
|
|
|
|
const char *hvtype,
|
|
|
|
const char *emulator,
|
|
|
|
const char *loader,
|
|
|
|
int nmachines,
|
|
|
|
const char *const *machines)
|
|
|
|
{
|
2008-04-28 21:44:54 +00:00
|
|
|
virCapsGuestDomainPtr dom;
|
2008-02-27 04:35:08 +00:00
|
|
|
int i;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC(dom) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if ((dom->type = strdup(hvtype)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if (emulator &&
|
|
|
|
(dom->info.emulator = strdup(emulator)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
if (loader &&
|
|
|
|
(dom->info.loader = strdup(loader)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
if (nmachines) {
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC_N(dom->info.machines, nmachines) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
for (i = 0 ; i < nmachines ; i++) {
|
|
|
|
if ((dom->info.machines[i] = strdup(machines[i])) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
dom->info.nmachines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_REALLOC_N(guest->arch.domains,
|
|
|
|
guest->arch.ndomains + 1) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
guest->arch.domains[guest->arch.ndomains] = dom;
|
|
|
|
guest->arch.ndomains++;
|
|
|
|
|
|
|
|
|
|
|
|
return dom;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
virCapabilitiesFreeGuestDomain(dom);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesAddGuestFeature:
|
|
|
|
* @guest: guest to associate feature with
|
|
|
|
* @name: name of feature ('pae', 'acpi', 'apic')
|
|
|
|
* @defaultOn: non-zero if it defaults to on
|
|
|
|
* @toggle: non-zero if its state can be toggled
|
|
|
|
*
|
|
|
|
* Registers a feature for a guest domain
|
|
|
|
*/
|
|
|
|
virCapsGuestFeaturePtr
|
|
|
|
virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
|
|
|
|
const char *name,
|
|
|
|
int defaultOn,
|
|
|
|
int toggle)
|
|
|
|
{
|
2008-04-28 21:44:54 +00:00
|
|
|
virCapsGuestFeaturePtr feature;
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_ALLOC(feature) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
|
|
|
|
if ((feature->name = strdup(name)) == NULL)
|
|
|
|
goto no_memory;
|
|
|
|
feature->defaultOn = defaultOn;
|
|
|
|
feature->toggle = toggle;
|
|
|
|
|
2008-04-28 21:44:54 +00:00
|
|
|
if (VIR_REALLOC_N(guest->features,
|
|
|
|
guest->nfeatures + 1) < 0)
|
2008-02-27 04:35:08 +00:00
|
|
|
goto no_memory;
|
|
|
|
guest->features[guest->nfeatures] = feature;
|
|
|
|
guest->nfeatures++;
|
|
|
|
|
|
|
|
return feature;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
virCapabilitiesFreeGuestFeature(feature);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesSupportsGuestOSType:
|
|
|
|
* @caps: capabilities to query
|
|
|
|
* @ostype: OS type to search for (eg 'hvm', 'xen')
|
|
|
|
*
|
|
|
|
* Returns non-zero if the capabilities support the
|
|
|
|
* requested operating system type
|
|
|
|
*/
|
|
|
|
extern int
|
|
|
|
virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
|
|
|
|
const char *ostype)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0 ; i < caps->nguests ; i++) {
|
|
|
|
if (STREQ(caps->guests[i]->ostype, ostype))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesDefaultGuestArch:
|
|
|
|
* @caps: capabilities to query
|
|
|
|
* @ostype: OS type to search for
|
|
|
|
*
|
|
|
|
* Returns the first architecture able to run the
|
|
|
|
* requested operating system type
|
|
|
|
*/
|
|
|
|
extern const char *
|
|
|
|
virCapabilitiesDefaultGuestArch(virCapsPtr caps,
|
|
|
|
const char *ostype)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0 ; i < caps->nguests ; i++) {
|
|
|
|
if (STREQ(caps->guests[i]->ostype, ostype))
|
|
|
|
return caps->guests[i]->arch.name;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesDefaultGuestMachine:
|
|
|
|
* @caps: capabilities to query
|
|
|
|
* @ostype: OS type to search for
|
|
|
|
* @arch: architecture to search for
|
|
|
|
*
|
|
|
|
* Returns the first machine variant associated with
|
|
|
|
* the requested operating system type and architecture
|
|
|
|
*/
|
|
|
|
extern const char *
|
|
|
|
virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
|
|
|
|
const char *ostype,
|
|
|
|
const char *arch)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0 ; i < caps->nguests ; i++) {
|
|
|
|
if (STREQ(caps->guests[i]->ostype, ostype) &&
|
|
|
|
STREQ(caps->guests[i]->arch.name, arch) &&
|
|
|
|
caps->guests[i]->arch.defaultInfo.nmachines)
|
|
|
|
return caps->guests[i]->arch.defaultInfo.machines[0];
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesDefaultGuestMachine:
|
|
|
|
* @caps: capabilities to query
|
|
|
|
* @ostype: OS type to search for ('xen', 'hvm')
|
|
|
|
* @arch: architecture to search for
|
|
|
|
* @domain: domain type ('xen', 'qemu', 'kvm')
|
|
|
|
*
|
|
|
|
* Returns the first emulator path associated with
|
|
|
|
* the requested operating system type, architecture
|
|
|
|
* and domain type
|
|
|
|
*/
|
|
|
|
extern const char *
|
|
|
|
virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
|
|
|
|
const char *ostype,
|
|
|
|
const char *arch,
|
|
|
|
const char *domain)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
for (i = 0 ; i < caps->nguests ; i++) {
|
|
|
|
char *emulator;
|
|
|
|
if (STREQ(caps->guests[i]->ostype, ostype) &&
|
|
|
|
STREQ(caps->guests[i]->arch.name, arch)) {
|
|
|
|
emulator = caps->guests[i]->arch.defaultInfo.emulator;
|
|
|
|
for (j = 0 ; j < caps->guests[i]->arch.ndomains ; j++) {
|
|
|
|
if (STREQ(caps->guests[i]->arch.domains[j]->type, domain)) {
|
|
|
|
if (caps->guests[i]->arch.domains[j]->info.emulator)
|
|
|
|
emulator = caps->guests[i]->arch.domains[j]->info.emulator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return emulator;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* virCapabilitiesFormatXML:
|
|
|
|
* @caps: capabilities to format
|
|
|
|
*
|
|
|
|
* Convert the capabilities object into an XML representation
|
|
|
|
*
|
|
|
|
* Returns the XML document as a string
|
|
|
|
*/
|
|
|
|
char *
|
|
|
|
virCapabilitiesFormatXML(virCapsPtr caps)
|
|
|
|
{
|
2008-04-28 15:14:59 +00:00
|
|
|
virBuffer xml = VIR_BUFFER_INITIALIZER;
|
2008-02-27 04:35:08 +00:00
|
|
|
int i, j, k;
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, "<capabilities>\n\n");
|
|
|
|
virBufferAddLit(&xml, " <host>\n");
|
|
|
|
virBufferAddLit(&xml, " <cpu>\n");
|
|
|
|
virBufferVSprintf(&xml, " <arch>%s</arch>\n",
|
|
|
|
caps->host.arch);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
if (caps->host.nfeatures) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " <features>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
for (i = 0 ; i < caps->host.nfeatures ; i++) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <%s/>\n",
|
|
|
|
caps->host.features[i]);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </features>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </cpu>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
if (caps->host.offlineMigrate) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " <migration_features>\n");
|
|
|
|
if (caps->host.liveMigrate)
|
|
|
|
virBufferAddLit(&xml, " <live/>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
if (caps->host.nmigrateTrans) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " <uri_transports>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
for (i = 0 ; i < caps->host.nmigrateTrans ; i++) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <uri_transport>%s</uri_transport>\n",
|
|
|
|
caps->host.migrateTrans[i]);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </uri_transports>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </migration_features>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (caps->host.nnumaCell) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " <topology>\n");
|
|
|
|
virBufferVSprintf(&xml, " <cells num='%d'>\n",
|
|
|
|
caps->host.nnumaCell);
|
2008-02-27 04:35:08 +00:00
|
|
|
for (i = 0 ; i < caps->host.nnumaCell ; i++) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <cell id='%d'>\n",
|
|
|
|
caps->host.numaCell[i]->num);
|
|
|
|
virBufferVSprintf(&xml, " <cpus num='%d'>\n",
|
|
|
|
caps->host.numaCell[i]->ncpus);
|
2008-02-27 04:35:08 +00:00
|
|
|
for (j = 0 ; j < caps->host.numaCell[i]->ncpus ; j++)
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <cpu id='%d'/>\n",
|
|
|
|
caps->host.numaCell[i]->cpus[j]);
|
|
|
|
virBufferAddLit(&xml, " </cpus>\n");
|
|
|
|
virBufferAddLit(&xml, " </cell>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </cells>\n");
|
|
|
|
virBufferAddLit(&xml, " </topology>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </host>\n\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
for (i = 0 ; i < caps->nguests ; i++) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " <guest>\n");
|
|
|
|
virBufferVSprintf(&xml, " <os_type>%s</os_type>\n",
|
|
|
|
caps->guests[i]->ostype);
|
|
|
|
virBufferVSprintf(&xml, " <arch name='%s'>\n",
|
|
|
|
caps->guests[i]->arch.name);
|
|
|
|
virBufferVSprintf(&xml, " <wordsize>%d</wordsize>\n",
|
|
|
|
caps->guests[i]->arch.wordsize);
|
|
|
|
if (caps->guests[i]->arch.defaultInfo.emulator)
|
2008-02-27 04:35:08 +00:00
|
|
|
virBufferVSprintf(&xml, " <emulator>%s</emulator>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
caps->guests[i]->arch.defaultInfo.emulator);
|
|
|
|
if (caps->guests[i]->arch.defaultInfo.loader)
|
|
|
|
virBufferVSprintf(&xml, " <loader>%s</loader>\n",
|
|
|
|
caps->guests[i]->arch.defaultInfo.loader);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
for (j = 0 ; j < caps->guests[i]->arch.defaultInfo.nmachines ; j++) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <machine>%s</machine>\n",
|
|
|
|
caps->guests[i]->arch.defaultInfo.machines[j]);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 0 ; j < caps->guests[i]->arch.ndomains ; j++) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <domain type='%s'>\n",
|
|
|
|
caps->guests[i]->arch.domains[j]->type);
|
|
|
|
if (caps->guests[i]->arch.domains[j]->info.emulator)
|
2008-02-27 04:35:08 +00:00
|
|
|
virBufferVSprintf(&xml, " <emulator>%s</emulator>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
caps->guests[i]->arch.domains[j]->info.emulator);
|
|
|
|
if (caps->guests[i]->arch.domains[j]->info.loader)
|
2008-02-27 04:35:08 +00:00
|
|
|
virBufferVSprintf(&xml, " <loader>%s</loader>\n",
|
2008-04-28 15:14:59 +00:00
|
|
|
caps->guests[i]->arch.domains[j]->info.loader);
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
for (k = 0 ; k < caps->guests[i]->arch.domains[j]->info.nmachines ; k++) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <machine>%s</machine>\n",
|
|
|
|
caps->guests[i]->arch.domains[j]->info.machines[k]);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </domain>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </arch>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
if (caps->guests[i]->nfeatures) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " <features>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
|
|
|
|
for (j = 0 ; j < caps->guests[i]->nfeatures ; j++) {
|
|
|
|
if (STREQ(caps->guests[i]->features[j]->name, "pae") ||
|
|
|
|
STREQ(caps->guests[i]->features[j]->name, "nonpae") ||
|
|
|
|
STREQ(caps->guests[i]->features[j]->name, "ia64_be")) {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <%s/>\n",
|
|
|
|
caps->guests[i]->features[j]->name);
|
2008-02-27 04:35:08 +00:00
|
|
|
} else {
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferVSprintf(&xml, " <%s default='%s' toggle='%s'/>\n",
|
|
|
|
caps->guests[i]->features[j]->name,
|
|
|
|
caps->guests[i]->features[j]->defaultOn ? "on" : "off",
|
|
|
|
caps->guests[i]->features[j]->toggle ? "yes" : "no");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </features>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, " </guest>\n\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
virBufferAddLit(&xml, "</capabilities>\n");
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
if (virBufferError(&xml))
|
|
|
|
return NULL;
|
2008-02-27 04:35:08 +00:00
|
|
|
|
2008-04-28 15:14:59 +00:00
|
|
|
return virBufferContentAndReset(&xml);
|
2008-02-27 04:35:08 +00:00
|
|
|
}
|