提交 aca20efb 编写于 作者: E Eric Blake

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.
上级 e6b68d74
/*
* 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
*
* This library is free software; you can redistribute it and/or
......@@ -190,8 +190,8 @@ int
virCapabilitiesAddHostFeature(virCapsPtr caps,
const char *name)
{
if (VIR_REALLOC_N(caps->host.features,
caps->host.nfeatures + 1) < 0)
if (VIR_RESIZE_N(caps->host.features, caps->host.nfeatures_max,
caps->host.nfeatures, 1) < 0)
return -1;
if ((caps->host.features[caps->host.nfeatures] = strdup(name)) == NULL)
......@@ -213,8 +213,8 @@ int
virCapabilitiesAddHostMigrateTransport(virCapsPtr caps,
const char *name)
{
if (VIR_REALLOC_N(caps->host.migrateTrans,
caps->host.nmigrateTrans + 1) < 0)
if (VIR_RESIZE_N(caps->host.migrateTrans, caps->host.nmigrateTrans_max,
caps->host.nmigrateTrans, 1) < 0)
return -1;
if ((caps->host.migrateTrans[caps->host.nmigrateTrans] = strdup(name)) == NULL)
......@@ -243,8 +243,8 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps,
{
virCapsHostNUMACellPtr cell;
if (VIR_REALLOC_N(caps->host.numaCell,
caps->host.nnumaCell + 1) < 0)
if (VIR_RESIZE_N(caps->host.numaCell, caps->host.nnumaCell_max,
caps->host.nnumaCell, 1) < 0)
return -1;
if (VIR_ALLOC(cell) < 0)
......@@ -261,8 +261,7 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps,
cell->ncpus = ncpus;
cell->num = num;
caps->host.numaCell[caps->host.nnumaCell] = cell;
caps->host.nnumaCell++;
caps->host.numaCell[caps->host.nnumaCell++] = cell;
return 0;
}
......@@ -380,11 +379,10 @@ virCapabilitiesAddGuest(virCapsPtr caps,
(guest->arch.defaultInfo.loader = strdup(loader)) == NULL)
goto no_memory;
if (VIR_REALLOC_N(caps->guests,
caps->nguests + 1) < 0)
if (VIR_RESIZE_N(caps->guests, caps->nguests_max,
caps->nguests, 1) < 0)
goto no_memory;
caps->guests[caps->nguests] = guest;
caps->nguests++;
caps->guests[caps->nguests++] = guest;
if (nmachines) {
guest->arch.defaultInfo.nmachines = nmachines;
......@@ -434,8 +432,8 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
(dom->info.loader = strdup(loader)) == NULL)
goto no_memory;
if (VIR_REALLOC_N(guest->arch.domains,
guest->arch.ndomains + 1) < 0)
if (VIR_RESIZE_N(guest->arch.domains, guest->arch.ndomains_max,
guest->arch.ndomains, 1) < 0)
goto no_memory;
guest->arch.domains[guest->arch.ndomains] = dom;
guest->arch.ndomains++;
......@@ -478,11 +476,10 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
feature->defaultOn = defaultOn;
feature->toggle = toggle;
if (VIR_REALLOC_N(guest->features,
guest->nfeatures + 1) < 0)
if (VIR_RESIZE_N(guest->features, guest->nfeatures_max,
guest->nfeatures, 1) < 0)
goto no_memory;
guest->features[guest->nfeatures] = feature;
guest->nfeatures++;
guest->features[guest->nfeatures++] = feature;
return feature;
......@@ -706,7 +703,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
if (caps->host.nnumaCell) {
virBufferAddLit(&xml, " <topology>\n");
virBufferVSprintf(&xml, " <cells num='%d'>\n",
virBufferVSprintf(&xml, " <cells num='%zu'>\n",
caps->host.nnumaCell);
for (i = 0 ; i < caps->host.nnumaCell ; i++) {
virBufferVSprintf(&xml, " <cell id='%d'>\n",
......
/*
* 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
*
* This library is free software; you can redistribute it and/or
......@@ -71,7 +71,8 @@ struct _virCapsGuestArch {
char *name;
int wordsize;
virCapsGuestDomainInfo defaultInfo;
int ndomains;
size_t ndomains;
size_t ndomains_max;
virCapsGuestDomainPtr *domains;
};
......@@ -80,7 +81,8 @@ typedef virCapsGuest *virCapsGuestPtr;
struct _virCapsGuest {
char *ostype;
virCapsGuestArch arch;
int nfeatures;
size_t nfeatures;
size_t nfeatures_max;
virCapsGuestFeaturePtr *features;
};
......@@ -102,13 +104,16 @@ typedef struct _virCapsHost virCapsHost;
typedef virCapsHost *virCapsHostPtr;
struct _virCapsHost {
char *arch;
int nfeatures;
size_t nfeatures;
size_t nfeatures_max;
char **features;
int offlineMigrate;
int liveMigrate;
int nmigrateTrans;
size_t nmigrateTrans;
size_t nmigrateTrans_max;
char **migrateTrans;
int nnumaCell;
size_t nnumaCell;
size_t nnumaCell_max;
virCapsHostNUMACellPtr *numaCell;
virCapsHostSecModel secModel;
virCPUDefPtr cpu;
......@@ -134,7 +139,8 @@ typedef struct _virCaps virCaps;
typedef virCaps* virCapsPtr;
struct _virCaps {
virCapsHost host;
int nguests;
size_t nguests;
size_t nguests_max;
virCapsGuestPtr *guests;
unsigned char macPrefix[VIR_MAC_PREFIX_BUFLEN];
unsigned int emulatorRequired : 1;
......
......@@ -83,6 +83,7 @@ virCPUDefCopy(const virCPUDefPtr cpu)
|| (cpu->vendor && !(copy->vendor = strdup(cpu->vendor)))
|| VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
goto no_memory;
copy->nfeatures_max = cpu->nfeatures;
copy->type = cpu->type;
copy->match = cpu->match;
......@@ -234,7 +235,8 @@ virCPUDefParseXML(const xmlNodePtr node,
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;
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;
if (def->type == VIR_CPU_TYPE_HOST)
......
/*
* 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
* modify it under the terms of the GNU Lesser General Public
......@@ -74,7 +74,8 @@ struct _virCPUDef {
unsigned int sockets;
unsigned int cores;
unsigned int threads;
unsigned int nfeatures;
size_t nfeatures;
size_t nfeatures_max;
virCPUFeatureDefPtr features;
};
......
......@@ -89,6 +89,7 @@ virCapsPtr testQemuCapsInit(void) {
2, /* cores */
1, /* threads */
ARRAY_CARDINALITY(host_cpu_features), /* nfeatures */
ARRAY_CARDINALITY(host_cpu_features), /* nfeatures_max */
host_cpu_features /* features */
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册