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