From 909fa8d0e46a086da4ab44d40b652b8fe2917df4 Mon Sep 17 00:00:00 2001
Message-Id: <909fa8d0e46a086da4ab44d40b652b8fe2917df4@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 24 Aug 2016 16:10:47 -0400
Subject: [PATCH] conf: convert def->vcpus to a array of pointers
https://bugzilla.redhat.com/show_bug.cgi?id=1097930
https://bugzilla.redhat.com/show_bug.cgi?id=1224341
(cherry picked from commit 990b06de03b3f4e294e3e9eca831fea7b1edb067)
---
src/conf/domain_conf.c | 44 +++++++++++++++++++++++++++++++-------------
src/conf/domain_conf.h | 2 +-
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7a12462..6d0f967 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1312,14 +1312,26 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def)
}
+static virDomainVcpuDefPtr
+virDomainVcpuDefNew(void)
+{
+ virDomainVcpuDefPtr ret;
+
+ ignore_value(VIR_ALLOC(ret));
+
+ return ret;
+}
+
+
static void
-virDomainVcpuDefClear(virDomainVcpuDefPtr info)
+virDomainVcpuDefFree(virDomainVcpuDefPtr info)
{
if (!info)
return;
virBitmapFree(info->cpumask);
info->cpumask = NULL;
+ VIR_FREE(info);
}
@@ -1327,6 +1339,7 @@ int
virDomainDefSetVcpusMax(virDomainDefPtr def,
unsigned int maxvcpus)
{
+ size_t oldmax = def->maxvcpus;
size_t i;
if (def->maxvcpus == maxvcpus)
@@ -1335,9 +1348,14 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
if (def->maxvcpus < maxvcpus) {
if (VIR_EXPAND_N(def->vcpus, def->maxvcpus, maxvcpus - def->maxvcpus) < 0)
return -1;
+
+ for (i = oldmax; i < def->maxvcpus; i++) {
+ if (!(def->vcpus[i] = virDomainVcpuDefNew()))
+ return -1;
+ }
} else {
for (i = maxvcpus; i < def->maxvcpus; i++)
- virDomainVcpuDefClear(&def->vcpus[i]);
+ virDomainVcpuDefFree(def->vcpus[i]);
VIR_SHRINK_N(def->vcpus, def->maxvcpus, def->maxvcpus - maxvcpus);
}
@@ -1352,7 +1370,7 @@ virDomainDefHasVcpusOffline(const virDomainDef *def)
size_t i;
for (i = 0; i < def->maxvcpus; i++) {
- if (!def->vcpus[i].online)
+ if (!def->vcpus[i]->online)
return true;
}
@@ -1381,10 +1399,10 @@ virDomainDefSetVcpus(virDomainDefPtr def,
}
for (i = 0; i < vcpus; i++)
- def->vcpus[i].online = true;
+ def->vcpus[i]->online = true;
for (i = vcpus; i < def->maxvcpus; i++)
- def->vcpus[i].online = false;
+ def->vcpus[i]->online = false;
return 0;
}
@@ -1397,7 +1415,7 @@ virDomainDefGetVcpus(const virDomainDef *def)
unsigned int ret = 0;
for (i = 0; i < def->maxvcpus; i++) {
- if (def->vcpus[i].online)
+ if (def->vcpus[i]->online)
ret++;
}
@@ -1421,7 +1439,7 @@ virDomainDefGetOnlineVcpumap(const virDomainDef *def)
return NULL;
for (i = 0; i < def->maxvcpus; i++) {
- if (def->vcpus[i].online)
+ if (def->vcpus[i]->online)
ignore_value(virBitmapSetBit(ret, i));
}
@@ -1436,7 +1454,7 @@ virDomainDefGetVcpu(virDomainDefPtr def,
if (vcpu >= def->maxvcpus)
return NULL;
- return &def->vcpus[vcpu];
+ return def->vcpus[vcpu];
}
@@ -1465,7 +1483,7 @@ virDomainDefHasVcpuPin(const virDomainDef *def)
size_t i;
for (i = 0; i < def->maxvcpus; i++) {
- if (def->vcpus[i].cpumask)
+ if (def->vcpus[i]->cpumask)
return true;
}
@@ -2526,7 +2544,7 @@ void virDomainDefFree(virDomainDefPtr def)
virDomainResourceDefFree(def->resource);
for (i = 0; i < def->maxvcpus; i++)
- virDomainVcpuDefClear(&def->vcpus[i]);
+ virDomainVcpuDefFree(def->vcpus[i]);
VIR_FREE(def->vcpus);
/* hostdevs must be freed before nets (or any future "intelligent
@@ -18634,8 +18652,8 @@ virDomainDefVcpuCheckAbiStability(virDomainDefPtr src,
}
for (i = 0; i < src->maxvcpus; i++) {
- virDomainVcpuDefPtr svcpu = &src->vcpus[i];
- virDomainVcpuDefPtr dvcpu = &dst->vcpus[i];
+ virDomainVcpuDefPtr svcpu = src->vcpus[i];
+ virDomainVcpuDefPtr dvcpu = dst->vcpus[i];
if (svcpu->online != dvcpu->online) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -22819,7 +22837,7 @@ virDomainCputuneDefFormat(virBufferPtr buf,
for (i = 0; i < def->maxvcpus; i++) {
char *cpumask;
- virDomainVcpuDefPtr vcpu = def->vcpus + i;
+ virDomainVcpuDefPtr vcpu = def->vcpus[i];
if (!vcpu->cpumask)
continue;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index c20ea79..ac37382 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2132,7 +2132,7 @@ struct _virDomainDef {
virDomainBlkiotune blkio;
virDomainMemtune mem;
- virDomainVcpuDefPtr vcpus;
+ virDomainVcpuDefPtr *vcpus;
size_t maxvcpus;
int placement_mode;
virBitmapPtr cpumask;
--
2.10.0