]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: Replace writes to def->maxvcpus with accessor
authorPeter Krempa <pkrempa@redhat.com>
Fri, 16 Oct 2015 14:10:27 +0000 (16:10 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Dec 2015 13:57:12 +0000 (14:57 +0100)
To support further refactors replace all write access to def->maxvcpus
with a accessor function.

19 files changed:
src/conf/domain_conf.c
src/conf/domain_conf.h
src/hyperv/hyperv_driver.c
src/libvirt_private.syms
src/libxl/libxl_driver.c
src/lxc/lxc_native.c
src/openvz/openvz_conf.c
src/openvz/openvz_driver.c
src/phyp/phyp_driver.c
src/qemu/qemu_command.c
src/qemu/qemu_driver.c
src/test/test_driver.c
src/vbox/vbox_common.c
src/vmx/vmx.c
src/vz/vz_sdk.c
src/xen/xm_internal.c
src/xenapi/xenapi_driver.c
src/xenconfig/xen_common.c
src/xenconfig/xen_sxpr.c

index 2f5c0ed4b7f4a45c097b6fa9b45c89af3d862bed..50ff301e79c4bd174bb92118863027e1a483b17e 100644 (file)
@@ -1284,6 +1284,16 @@ void virDomainLeaseDefFree(virDomainLeaseDefPtr def)
 }
 
 
+int
+virDomainDefSetVcpusMax(virDomainDefPtr def,
+                        unsigned int maxvcpus)
+{
+    def->maxvcpus = maxvcpus;
+
+    return 0;
+}
+
+
 virDomainDiskDefPtr
 virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
 {
@@ -14374,18 +14384,22 @@ virDomainVcpuParse(virDomainDefPtr def,
 {
     int n;
     char *tmp = NULL;
+    unsigned int maxvcpus;
     int ret = -1;
 
-    if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &def->maxvcpus)) < 0) {
+    if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &maxvcpus)) < 0) {
         if (n == -2) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("maximum vcpus count must be an integer"));
             goto cleanup;
         }
 
-        def->maxvcpus = 1;
+        maxvcpus = 1;
     }
 
+    if (virDomainDefSetVcpusMax(def, maxvcpus) < 0)
+        goto cleanup;
+
     if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &def->vcpus)) < 0) {
         if (n == -2) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
index 90d8e13638c2310497d8dbe8a38b5d8bec6e71f3..eda66a5adedde048b91e6cd540ac625e515ea62e 100644 (file)
@@ -2343,6 +2343,8 @@ struct _virDomainDef {
     xmlNodePtr metadata;
 };
 
+int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
+
 unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
 void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
 void virDomainDefSetMemoryInitial(virDomainDefPtr def, unsigned long long size);
index 719539c730454d77287ac46b7fe7d0fcc6bd84aa..699435ceb28a7803aa6a01c6a517c5f962dea5c4 100644 (file)
@@ -873,8 +873,11 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
     virDomainDefSetMemoryTotal(def, memorySettingData->data->Limit * 1024); /* megabyte to kilobyte */
     def->mem.cur_balloon = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */
 
+    if (virDomainDefSetVcpusMax(def,
+                                processorSettingData->data->VirtualQuantity) < 0)
+        goto cleanup;
+
     def->vcpus = processorSettingData->data->VirtualQuantity;
-    def->maxvcpus = processorSettingData->data->VirtualQuantity;
     def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
     /* FIXME: devices section is totally missing */
index dd085c3487bf523cd89b9f4ee8fd4c78f600ba9a..b76299b7a3b3945dc4ca697c2f1674de1acb5be3 100644 (file)
@@ -230,6 +230,7 @@ virDomainDefParseString;
 virDomainDefPostParse;
 virDomainDefSetMemoryInitial;
 virDomainDefSetMemoryTotal;
+virDomainDefSetVcpusMax;
 virDomainDeleteConfig;
 virDomainDeviceAddressIsValid;
 virDomainDeviceAddressTypeToString;
index e3d2eaf06734b6e1ba26328652b04b6a97fb3592..80f5907375ba31447e7236b13914abdaff2ae8c6 100644 (file)
@@ -552,8 +552,10 @@ libxlAddDom0(libxlDriverPrivatePtr driver)
     def = NULL;
 
     virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
+    if (virDomainDefSetVcpusMax(vm->def, d_info.vcpu_max_id + 1))
+        goto cleanup;
+
     vm->def->vcpus = d_info.vcpu_online;
-    vm->def->maxvcpus = d_info.vcpu_max_id + 1;
     vm->def->mem.cur_balloon = d_info.current_memkb;
     virDomainDefSetMemoryTotal(vm->def, d_info.max_memkb);
 
@@ -2184,7 +2186,9 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
 
     switch (flags) {
     case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
-        def->maxvcpus = nvcpus;
+        if (virDomainDefSetVcpusMax(def, nvcpus) < 0)
+            goto cleanup;
+
         if (nvcpus < def->vcpus)
             def->vcpus = nvcpus;
         break;
index 8ff2253b46cc2f15b5a555c916fce0b68e019fc9..e67a5ad02dd5d3181de98491f3d37801d3ed2f41 100644 (file)
@@ -1021,7 +1021,9 @@ lxcParseConfigString(const char *config,
 
     /* Value not handled by the LXC driver, setting to
      * minimum required to make XML parsing pass */
-    vmdef->maxvcpus = 1;
+    if (virDomainDefSetVcpusMax(vmdef, 1) < 0)
+        goto error;
+
     vmdef->vcpus = 1;
 
     vmdef->nfss = 0;
index c0f65c918e1f431477f112ea5f98207fe981c7cd..6629105eb0495a11c901023681e3a8777486be79 100644 (file)
@@ -582,7 +582,9 @@ int openvzLoadDomains(struct openvz_driver *driver)
         if (ret == 0 || vcpus == 0)
             vcpus = openvzGetNodeCPUs();
 
-        def->maxvcpus = vcpus;
+        if (virDomainDefSetVcpusMax(def, vcpus) < 0)
+            goto cleanup;
+
         def->vcpus = vcpus;
 
         /* XXX load rest of VM config data .... */
index b8c0f50106075aac89a04788656d109e9a970370..307b607a25cb6370e90867a455e7a764b7301cdc 100644 (file)
@@ -1368,7 +1368,10 @@ static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
     if (virRun(prog, NULL) < 0)
         return -1;
 
-    vm->def->maxvcpus = vm->def->vcpus = nvcpus;
+    if (virDomainDefSetVcpusMax(vm->def, nvcpus) < 0)
+        return -1;
+
+    vm->def->vcpus = nvcpus;
     return 0;
 }
 
index 14264c0ce24c75c9d3e5f020c685b325920a4d88..b60e5ba39db2124f062fd5918e27004529d0e731 100644 (file)
@@ -3295,7 +3295,9 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         goto err;
     }
 
-    def.maxvcpus = vcpus;
+    if (virDomainDefSetVcpusMax(&def, vcpus) < 0)
+        goto err;
+
     def.vcpus = vcpus;
 
     return virDomainDefFormat(&def,
index 4ff31dc071c95e11c056f353ff28925a556adf31..b2cbb52a0f1529185aed64871bfd751b14596160 100644 (file)
@@ -12745,7 +12745,11 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
         }
     }
 
-    dom->maxvcpus = maxcpus ? maxcpus : dom->vcpus;
+    if (maxcpus == 0)
+        maxcpus = dom->vcpus;
+
+    if (virDomainDefSetVcpusMax(dom, maxcpus) < 0)
+        goto error;
 
     if (sockets && cores && threads) {
         virCPUDefPtr cpu;
@@ -12859,7 +12863,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
     def->id = -1;
     def->mem.cur_balloon = 64 * 1024;
     virDomainDefSetMemoryTotal(def, def->mem.cur_balloon);
-    def->maxvcpus = 1;
+    if (virDomainDefSetVcpusMax(def, 1) < 0)
+        goto error;
     def->vcpus = 1;
     def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
 
index ae1d8e7ab39708e739acba0b7f1a532242df5404..5dc72436b57c46d8b60175b0f48d76408c644d94 100644 (file)
@@ -4979,7 +4979,9 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
             }
 
             if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
-                persistentDef->maxvcpus = nvcpus;
+                if (virDomainDefSetVcpusMax(persistentDef, nvcpus) < 0)
+                    goto endjob;
+
                 if (nvcpus < persistentDef->vcpus)
                     persistentDef->vcpus = nvcpus;
             } else {
index 3b273963db0e1b1e6cba731c72745df9ac2bc51f..de0043adf298b724818ddb7771325625952fd4e9 100644 (file)
@@ -2377,7 +2377,9 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
 
     if (persistentDef) {
         if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
-            persistentDef->maxvcpus = nrCpus;
+            if (virDomainDefSetVcpusMax(persistentDef, nrCpus) < 0)
+                goto cleanup;
+
             if (nrCpus < persistentDef->vcpus)
                 persistentDef->vcpus = nrCpus;
         } else {
index 93693671d6f6b381aeca4cd92e71109a6b9e7402..9bfe60287b323bad81ec1ee3bab486e610e2a31e 100644 (file)
@@ -3907,7 +3907,10 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     virDomainDefSetMemoryTotal(def, memorySize * 1024);
 
     gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
-    def->maxvcpus = def->vcpus = CPUCount;
+    if (virDomainDefSetVcpusMax(def, CPUCount) < 0)
+        goto cleanup;
+
+    def->vcpus = CPUCount;
 
     /* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */
 
@@ -6061,7 +6064,11 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
         def->dom->os.type = VIR_DOMAIN_OSTYPE_HVM;
         def->dom->os.arch = virArchFromHost();
         gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
-        def->dom->maxvcpus = def->dom->vcpus = CPUCount;
+        if (virDomainDefSetVcpusMax(def->dom, CPUCount) < 0)
+            goto cleanup;
+
+        def->dom->vcpus = CPUCount;
+
         if (vboxSnapshotGetReadWriteDisks(def, snapshot) < 0)
             VIR_DEBUG("Could not get read write disks for snapshot");
 
index 2ae83f3513119a204ac7cc6729e75e94d5a5f0e1..dda072640b12c4f4e78e45570b741176f9f23e3e 100644 (file)
@@ -1458,7 +1458,10 @@ virVMXParseConfig(virVMXContext *ctx,
         goto cleanup;
     }
 
-    def->maxvcpus = def->vcpus = numvcpus;
+    if (virDomainDefSetVcpusMax(def, numvcpus) < 0)
+        goto cleanup;
+
+    def->vcpus = numvcpus;
 
     /* vmx:sched.cpu.affinity -> def:cpumask */
     /* NOTE: maps to VirtualMachine:config.cpuAffinity.affinitySet */
index 1fced3f8e92c83ce71d62cedace7b2e4d3ba4c8b..30e3c0ccbb534eaf064f682b0063406a9b515568 100644 (file)
@@ -1150,8 +1150,10 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
     if (cpuCount > hostcpus)
         cpuCount = hostcpus;
 
+    if (virDomainDefSetVcpusMax(def, cpuCount) < 0)
+        goto cleanup;
+
     def->vcpus = cpuCount;
-    def->maxvcpus = cpuCount;
 
     pret = PrlVmCfg_GetCpuMask(sdkdom, NULL, &buflen);
     prlsdkCheckRetGoto(pret, cleanup);
index 00c63d328641cdfa538ad2a1fb6ba436ff73a343..7b0c30518b72171fc954b4440d1fb4d7daba53cd 100644 (file)
@@ -704,7 +704,9 @@ xenXMDomainSetVcpusFlags(virConnectPtr conn,
     }
 
     if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
-        entry->def->maxvcpus = vcpus;
+        if (virDomainDefSetVcpusMax(entry->def, vcpus) < 0)
+            goto cleanup;
+
         if (entry->def->vcpus > vcpus)
             entry->def->vcpus = vcpus;
     } else {
index e503974c24b50185eaa7308baa6731c2465ccab4..fa66bb19c6c52d1ae66456272a9ced3670e096d7 100644 (file)
@@ -1502,7 +1502,9 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
 
     vcpus = xenapiDomainGetMaxVcpus(dom);
 
-    defPtr->maxvcpus = vcpus;
+    if (virDomainDefSetVcpusMax(defPtr, vcpus) < 0)
+        goto error;
+
     defPtr->vcpus = vcpus;
 
     enum xen_on_normal_exit action;
index ed6978ffa4aa2d5cfaca955d1d209242cd9d7b2b..33849e784d129d7c07d698f9f6edf37096b87604 100644 (file)
@@ -502,7 +502,9 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
         MAX_VIRT_CPUS < count)
         return -1;
 
-    def->maxvcpus = count;
+    if (virDomainDefSetVcpusMax(def, count) < 0)
+        return -1;
+
     if (xenConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
         return -1;
 
index 09989acc30c3cd0f4b0108b98dcc27ff51dd0d88..3ce283aa14b0d34d9f52c8d4afec40edd66f2570 100644 (file)
@@ -1173,7 +1173,8 @@ xenParseSxpr(const struct sexpr *root,
         }
     }
 
-    def->maxvcpus = sexpr_int(root, "domain/vcpus");
+    if (virDomainDefSetVcpusMax(def, sexpr_int(root, "domain/vcpus")) < 0)
+        goto error;
     def->vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
     if (!def->vcpus || def->maxvcpus < def->vcpus)
         def->vcpus = def->maxvcpus;