mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
capabilities, cpu: use new array API
* src/conf/capabilities.h (_virCaps, _virCapsHost, _virCapsGuest) (_virCapsGuestArch): Add additional fields. * src/conf/cpu_conf.h (_virCPUDef): Likewise. * src/conf/capabilities.c (virCapabilitiesFormatXML): Reflect updated type. (virCapabilitiesAddGuest, virCapabilitiesAddHostFeature) (virCapabilitiesAddHostMigrateTransport) (virCapabilitiesAddHostNUMACell, virCapabilitiesAddGuestFeature) (virCapabilitiesAddGuestDomain): Use new array APIs. * src/conf/cpu_conf.c (virCPUDefAddFeature, virCPUDefCopy) (virCPUDefParseXML): Likewise. * tests/testutilsqemu.c (testQemuCapsInit): Adjust test.
This commit is contained in:
parent
e6b68d7479
commit
aca20efbf8
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* capabilities.c: hypervisor capabilities
|
* capabilities.c: hypervisor capabilities
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2008 Red Hat, Inc.
|
* Copyright (C) 2006-2008, 2010 Red Hat, Inc.
|
||||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -190,8 +190,8 @@ int
|
|||||||
virCapabilitiesAddHostFeature(virCapsPtr caps,
|
virCapabilitiesAddHostFeature(virCapsPtr caps,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
if (VIR_REALLOC_N(caps->host.features,
|
if (VIR_RESIZE_N(caps->host.features, caps->host.nfeatures_max,
|
||||||
caps->host.nfeatures + 1) < 0)
|
caps->host.nfeatures, 1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((caps->host.features[caps->host.nfeatures] = strdup(name)) == NULL)
|
if ((caps->host.features[caps->host.nfeatures] = strdup(name)) == NULL)
|
||||||
@ -213,8 +213,8 @@ int
|
|||||||
virCapabilitiesAddHostMigrateTransport(virCapsPtr caps,
|
virCapabilitiesAddHostMigrateTransport(virCapsPtr caps,
|
||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
if (VIR_REALLOC_N(caps->host.migrateTrans,
|
if (VIR_RESIZE_N(caps->host.migrateTrans, caps->host.nmigrateTrans_max,
|
||||||
caps->host.nmigrateTrans + 1) < 0)
|
caps->host.nmigrateTrans, 1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if ((caps->host.migrateTrans[caps->host.nmigrateTrans] = strdup(name)) == NULL)
|
if ((caps->host.migrateTrans[caps->host.nmigrateTrans] = strdup(name)) == NULL)
|
||||||
@ -243,8 +243,8 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps,
|
|||||||
{
|
{
|
||||||
virCapsHostNUMACellPtr cell;
|
virCapsHostNUMACellPtr cell;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(caps->host.numaCell,
|
if (VIR_RESIZE_N(caps->host.numaCell, caps->host.nnumaCell_max,
|
||||||
caps->host.nnumaCell + 1) < 0)
|
caps->host.nnumaCell, 1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (VIR_ALLOC(cell) < 0)
|
if (VIR_ALLOC(cell) < 0)
|
||||||
@ -261,8 +261,7 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps,
|
|||||||
cell->ncpus = ncpus;
|
cell->ncpus = ncpus;
|
||||||
cell->num = num;
|
cell->num = num;
|
||||||
|
|
||||||
caps->host.numaCell[caps->host.nnumaCell] = cell;
|
caps->host.numaCell[caps->host.nnumaCell++] = cell;
|
||||||
caps->host.nnumaCell++;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -380,11 +379,10 @@ virCapabilitiesAddGuest(virCapsPtr caps,
|
|||||||
(guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
|
(guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(caps->guests,
|
if (VIR_RESIZE_N(caps->guests, caps->nguests_max,
|
||||||
caps->nguests + 1) < 0)
|
caps->nguests, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
caps->guests[caps->nguests] = guest;
|
caps->guests[caps->nguests++] = guest;
|
||||||
caps->nguests++;
|
|
||||||
|
|
||||||
if (nmachines) {
|
if (nmachines) {
|
||||||
guest->arch.defaultInfo.nmachines = nmachines;
|
guest->arch.defaultInfo.nmachines = nmachines;
|
||||||
@ -434,8 +432,8 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
|
|||||||
(dom->info.loader = strdup(loader)) == NULL)
|
(dom->info.loader = strdup(loader)) == NULL)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(guest->arch.domains,
|
if (VIR_RESIZE_N(guest->arch.domains, guest->arch.ndomains_max,
|
||||||
guest->arch.ndomains + 1) < 0)
|
guest->arch.ndomains, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
guest->arch.domains[guest->arch.ndomains] = dom;
|
guest->arch.domains[guest->arch.ndomains] = dom;
|
||||||
guest->arch.ndomains++;
|
guest->arch.ndomains++;
|
||||||
@ -478,11 +476,10 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
|
|||||||
feature->defaultOn = defaultOn;
|
feature->defaultOn = defaultOn;
|
||||||
feature->toggle = toggle;
|
feature->toggle = toggle;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(guest->features,
|
if (VIR_RESIZE_N(guest->features, guest->nfeatures_max,
|
||||||
guest->nfeatures + 1) < 0)
|
guest->nfeatures, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
guest->features[guest->nfeatures] = feature;
|
guest->features[guest->nfeatures++] = feature;
|
||||||
guest->nfeatures++;
|
|
||||||
|
|
||||||
return feature;
|
return feature;
|
||||||
|
|
||||||
@ -706,7 +703,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
|
|||||||
|
|
||||||
if (caps->host.nnumaCell) {
|
if (caps->host.nnumaCell) {
|
||||||
virBufferAddLit(&xml, " <topology>\n");
|
virBufferAddLit(&xml, " <topology>\n");
|
||||||
virBufferVSprintf(&xml, " <cells num='%d'>\n",
|
virBufferVSprintf(&xml, " <cells num='%zu'>\n",
|
||||||
caps->host.nnumaCell);
|
caps->host.nnumaCell);
|
||||||
for (i = 0 ; i < caps->host.nnumaCell ; i++) {
|
for (i = 0 ; i < caps->host.nnumaCell ; i++) {
|
||||||
virBufferVSprintf(&xml, " <cell id='%d'>\n",
|
virBufferVSprintf(&xml, " <cell id='%d'>\n",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* capabilities.h: hypervisor capabilities
|
* capabilities.h: hypervisor capabilities
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2008 Red Hat, Inc.
|
* Copyright (C) 2006-2008, 2010 Red Hat, Inc.
|
||||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
@ -71,7 +71,8 @@ struct _virCapsGuestArch {
|
|||||||
char *name;
|
char *name;
|
||||||
int wordsize;
|
int wordsize;
|
||||||
virCapsGuestDomainInfo defaultInfo;
|
virCapsGuestDomainInfo defaultInfo;
|
||||||
int ndomains;
|
size_t ndomains;
|
||||||
|
size_t ndomains_max;
|
||||||
virCapsGuestDomainPtr *domains;
|
virCapsGuestDomainPtr *domains;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -80,7 +81,8 @@ typedef virCapsGuest *virCapsGuestPtr;
|
|||||||
struct _virCapsGuest {
|
struct _virCapsGuest {
|
||||||
char *ostype;
|
char *ostype;
|
||||||
virCapsGuestArch arch;
|
virCapsGuestArch arch;
|
||||||
int nfeatures;
|
size_t nfeatures;
|
||||||
|
size_t nfeatures_max;
|
||||||
virCapsGuestFeaturePtr *features;
|
virCapsGuestFeaturePtr *features;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -102,13 +104,16 @@ typedef struct _virCapsHost virCapsHost;
|
|||||||
typedef virCapsHost *virCapsHostPtr;
|
typedef virCapsHost *virCapsHostPtr;
|
||||||
struct _virCapsHost {
|
struct _virCapsHost {
|
||||||
char *arch;
|
char *arch;
|
||||||
int nfeatures;
|
size_t nfeatures;
|
||||||
|
size_t nfeatures_max;
|
||||||
char **features;
|
char **features;
|
||||||
int offlineMigrate;
|
int offlineMigrate;
|
||||||
int liveMigrate;
|
int liveMigrate;
|
||||||
int nmigrateTrans;
|
size_t nmigrateTrans;
|
||||||
|
size_t nmigrateTrans_max;
|
||||||
char **migrateTrans;
|
char **migrateTrans;
|
||||||
int nnumaCell;
|
size_t nnumaCell;
|
||||||
|
size_t nnumaCell_max;
|
||||||
virCapsHostNUMACellPtr *numaCell;
|
virCapsHostNUMACellPtr *numaCell;
|
||||||
virCapsHostSecModel secModel;
|
virCapsHostSecModel secModel;
|
||||||
virCPUDefPtr cpu;
|
virCPUDefPtr cpu;
|
||||||
@ -134,7 +139,8 @@ typedef struct _virCaps virCaps;
|
|||||||
typedef virCaps* virCapsPtr;
|
typedef virCaps* virCapsPtr;
|
||||||
struct _virCaps {
|
struct _virCaps {
|
||||||
virCapsHost host;
|
virCapsHost host;
|
||||||
int nguests;
|
size_t nguests;
|
||||||
|
size_t nguests_max;
|
||||||
virCapsGuestPtr *guests;
|
virCapsGuestPtr *guests;
|
||||||
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
|
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
|
||||||
unsigned int emulatorRequired : 1;
|
unsigned int emulatorRequired : 1;
|
||||||
|
@ -83,6 +83,7 @@ virCPUDefCopy(const virCPUDefPtr cpu)
|
|||||||
|| (cpu->vendor && !(copy->vendor = strdup(cpu->vendor)))
|
|| (cpu->vendor && !(copy->vendor = strdup(cpu->vendor)))
|
||||||
|| VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
|
|| VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
copy->nfeatures_max = cpu->nfeatures;
|
||||||
|
|
||||||
copy->type = cpu->type;
|
copy->type = cpu->type;
|
||||||
copy->match = cpu->match;
|
copy->match = cpu->match;
|
||||||
@ -234,7 +235,8 @@ virCPUDefParseXML(const xmlNodePtr node,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_ALLOC_N(def->features, n) < 0)
|
if (VIR_RESIZE_N(def->features, def->nfeatures_max,
|
||||||
|
def->nfeatures, n) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
def->nfeatures = n;
|
def->nfeatures = n;
|
||||||
}
|
}
|
||||||
@ -425,7 +427,8 @@ virCPUDefAddFeature(virCPUDefPtr def,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIR_REALLOC_N(def->features, def->nfeatures + 1) < 0)
|
if (VIR_RESIZE_N(def->features, def->nfeatures_max,
|
||||||
|
def->nfeatures, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (def->type == VIR_CPU_TYPE_HOST)
|
if (def->type == VIR_CPU_TYPE_HOST)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* cpu_conf.h: CPU XML handling
|
* cpu_conf.h: CPU XML handling
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009 Red Hat, Inc.
|
* Copyright (C) 2009, 2010 Red Hat, Inc.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@ -74,7 +74,8 @@ struct _virCPUDef {
|
|||||||
unsigned int sockets;
|
unsigned int sockets;
|
||||||
unsigned int cores;
|
unsigned int cores;
|
||||||
unsigned int threads;
|
unsigned int threads;
|
||||||
unsigned int nfeatures;
|
size_t nfeatures;
|
||||||
|
size_t nfeatures_max;
|
||||||
virCPUFeatureDefPtr features;
|
virCPUFeatureDefPtr features;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ virCapsPtr testQemuCapsInit(void) {
|
|||||||
2, /* cores */
|
2, /* cores */
|
||||||
1, /* threads */
|
1, /* threads */
|
||||||
ARRAY_CARDINALITY(host_cpu_features), /* nfeatures */
|
ARRAY_CARDINALITY(host_cpu_features), /* nfeatures */
|
||||||
|
ARRAY_CARDINALITY(host_cpu_features), /* nfeatures_max */
|
||||||
host_cpu_features /* features */
|
host_cpu_features /* features */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user