]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: Replace writes to def->vcpus with accessor
authorPeter Krempa <pkrempa@redhat.com>
Thu, 22 Oct 2015 08:52:05 +0000 (10:52 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Dec 2015 13:57:12 +0000 (14:57 +0100)
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 f16518b020dafb1595c0df42f0173726521df31d..181820f02a74542581456a5bbf98ba9d38c27a48 100644 (file)
@@ -1289,7 +1289,7 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
                         unsigned int maxvcpus)
 {
     if (maxvcpus < def->vcpus)
-        def->vcpus = maxvcpus;
+        virDomainDefSetVcpus(def, maxvcpus);
 
     def->maxvcpus = maxvcpus;
 
@@ -1311,6 +1311,16 @@ virDomainDefGetVcpusMax(const virDomainDef *def)
 }
 
 
+int
+virDomainDefSetVcpus(virDomainDefPtr def,
+                     unsigned int vcpus)
+{
+    def->vcpus = vcpus;
+
+    return 0;
+}
+
+
 virDomainDiskDefPtr
 virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
 {
@@ -14402,6 +14412,7 @@ virDomainVcpuParse(virDomainDefPtr def,
     int n;
     char *tmp = NULL;
     unsigned int maxvcpus;
+    unsigned int vcpus;
     int ret = -1;
 
     if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &maxvcpus)) < 0) {
@@ -14417,16 +14428,19 @@ virDomainVcpuParse(virDomainDefPtr def,
     if (virDomainDefSetVcpusMax(def, maxvcpus) < 0)
         goto cleanup;
 
-    if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &def->vcpus)) < 0) {
+    if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &vcpus)) < 0) {
         if (n == -2) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("current vcpus count must be an integer"));
             goto cleanup;
         }
 
-        def->vcpus = maxvcpus;
+        vcpus = maxvcpus;
     }
 
+    if (virDomainDefSetVcpus(def, vcpus) < 0)
+        goto cleanup;
+
     if (maxvcpus < def->vcpus) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("maxvcpus must not be less than current vcpus "
index cbdb417b9833a91f2c5922c2493dacebc71e7b04..e1d5054e993abed0ec94302e8f2adb91218de254 100644 (file)
@@ -2346,6 +2346,7 @@ struct _virDomainDef {
 int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
 bool virDomainDefHasVcpusOffline(const virDomainDef *def);
 unsigned int virDomainDefGetVcpusMax(const virDomainDef *def);
+int virDomainDefSetVcpus(virDomainDefPtr def, unsigned int vcpus);
 
 unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
 void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
index 699435ceb28a7803aa6a01c6a517c5f962dea5c4..6ce35221750a592efb8c710290155b1fcf802556 100644 (file)
@@ -877,7 +877,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
                                 processorSettingData->data->VirtualQuantity) < 0)
         goto cleanup;
 
-    def->vcpus = processorSettingData->data->VirtualQuantity;
+    if (virDomainDefSetVcpus(def,
+                             processorSettingData->data->VirtualQuantity) < 0)
+        goto cleanup;
+
     def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
     /* FIXME: devices section is totally missing */
index a164798bbfefcf4982f25d9b813a5df0fd84aea5..7726eb3d828cc3c85df1060b760f2216035668ca 100644 (file)
@@ -232,6 +232,7 @@ virDomainDefParseString;
 virDomainDefPostParse;
 virDomainDefSetMemoryInitial;
 virDomainDefSetMemoryTotal;
+virDomainDefSetVcpus;
 virDomainDefSetVcpusMax;
 virDomainDeleteConfig;
 virDomainDeviceAddressIsValid;
index 77d290afc1db0c2636b49e5f66fe171b763d10f8..b5e8a7a9c4348a9f48282469c4471600f9d8bdde 100644 (file)
@@ -555,7 +555,8 @@ libxlAddDom0(libxlDriverPrivatePtr driver)
     if (virDomainDefSetVcpusMax(vm->def, d_info.vcpu_max_id + 1))
         goto cleanup;
 
-    vm->def->vcpus = d_info.vcpu_online;
+    if (virDomainDefSetVcpus(vm->def, d_info.vcpu_online) < 0)
+        goto cleanup;
     vm->def->mem.cur_balloon = d_info.current_memkb;
     virDomainDefSetMemoryTotal(vm->def, d_info.max_memkb);
 
@@ -2191,7 +2192,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
         break;
 
     case VIR_DOMAIN_VCPU_CONFIG:
-        def->vcpus = nvcpus;
+        if (virDomainDefSetVcpus(def, nvcpus) < 0)
+            goto cleanup;
         break;
 
     case VIR_DOMAIN_VCPU_LIVE:
@@ -2201,7 +2203,8 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                              " with libxenlight"), vm->def->id);
             goto endjob;
         }
-        vm->def->vcpus = nvcpus;
+        if (virDomainDefSetVcpus(vm->def, nvcpus) < 0)
+            goto endjob;
         break;
 
     case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
@@ -2211,8 +2214,9 @@ libxlDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                              " with libxenlight"), vm->def->id);
             goto endjob;
         }
-        vm->def->vcpus = nvcpus;
-        def->vcpus = nvcpus;
+        if (virDomainDefSetVcpus(vm->def, nvcpus) < 0 ||
+            virDomainDefSetVcpus(def, nvcpus) < 0)
+            goto endjob;
         break;
     }
 
index e67a5ad02dd5d3181de98491f3d37801d3ed2f41..78f9c6789bc1ec15b72da87ea94da6308ce7cc95 100644 (file)
@@ -1024,7 +1024,8 @@ lxcParseConfigString(const char *config,
     if (virDomainDefSetVcpusMax(vmdef, 1) < 0)
         goto error;
 
-    vmdef->vcpus = 1;
+    if (virDomainDefSetVcpus(vmdef, 1) < 0)
+        goto error;
 
     vmdef->nfss = 0;
     vmdef->os.type = VIR_DOMAIN_OSTYPE_EXE;
index 6629105eb0495a11c901023681e3a8777486be79..e32dd6f3af2088fcd7d401fce05661ca889bc708 100644 (file)
@@ -585,7 +585,8 @@ int openvzLoadDomains(struct openvz_driver *driver)
         if (virDomainDefSetVcpusMax(def, vcpus) < 0)
             goto cleanup;
 
-        def->vcpus = vcpus;
+        if (virDomainDefSetVcpus(def, vcpus) < 0)
+            goto cleanup;
 
         /* XXX load rest of VM config data .... */
 
index 5e55033fde609959a90da774ab91e5b7ca373b25..2a9e6acb907251652ca2509a27190c0d07089a56 100644 (file)
@@ -1371,7 +1371,9 @@ static int openvzDomainSetVcpusInternal(virDomainObjPtr vm,
     if (virDomainDefSetVcpusMax(vm->def, nvcpus) < 0)
         return -1;
 
-    vm->def->vcpus = nvcpus;
+    if (virDomainDefSetVcpus(vm->def, nvcpus) < 0)
+        return -1;
+
     return 0;
 }
 
index b60e5ba39db2124f062fd5918e27004529d0e731..3d086e3f699bc7fc4c4691b3a375e15e57953985 100644 (file)
@@ -3298,7 +3298,8 @@ phypDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     if (virDomainDefSetVcpusMax(&def, vcpus) < 0)
         goto err;
 
-    def.vcpus = vcpus;
+    if (virDomainDefSetVcpus(&def, vcpus) < 0)
+        goto err;
 
     return virDomainDefFormat(&def,
                               virDomainDefFormatConvertXMLFlags(flags));
index 837f94578be203e2b793ad6447ec8ecadbedcf25..c188aa3514531fee9b0ec43376190fcbba11da8e 100644 (file)
@@ -12712,6 +12712,7 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
     unsigned int cores = 0;
     unsigned int threads = 0;
     unsigned int maxcpus = 0;
+    unsigned int vcpus = 0;
     size_t i;
     int nkws;
     char **kws;
@@ -12726,9 +12727,8 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
     for (i = 0; i < nkws; i++) {
         if (vals[i] == NULL) {
             if (i > 0 ||
-                virStrToLong_i(kws[i], &end, 10, &n) < 0 || *end != '\0')
+                virStrToLong_ui(kws[i], &end, 10, &vcpus) < 0 || *end != '\0')
                 goto syntax;
-            dom->vcpus = n;
         } else {
             if (virStrToLong_i(vals[i], &end, 10, &n) < 0 || *end != '\0')
                 goto syntax;
@@ -12746,11 +12746,14 @@ qemuParseCommandLineSmp(virDomainDefPtr dom,
     }
 
     if (maxcpus == 0)
-        maxcpus = dom->vcpus;
+        maxcpus = vcpus;
 
     if (virDomainDefSetVcpusMax(dom, maxcpus) < 0)
         goto error;
 
+    if (virDomainDefSetVcpus(dom, vcpus) < 0)
+        goto error;
+
     if (sockets && cores && threads) {
         virCPUDefPtr cpu;
 
@@ -12865,7 +12868,8 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
     virDomainDefSetMemoryTotal(def, def->mem.cur_balloon);
     if (virDomainDefSetVcpusMax(def, 1) < 0)
         goto error;
-    def->vcpus = 1;
+    if (virDomainDefSetVcpus(def, 1) < 0)
+        goto error;
     def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
 
     def->onReboot = VIR_DOMAIN_LIFECYCLE_RESTART;
index 601344307100f6707953cd3eac897340d9633fff..f07d7a70509848d298770e5eca4bb6c727f5be8d 100644 (file)
@@ -4835,8 +4835,9 @@ qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
  cleanup:
     VIR_FREE(cpupids);
     VIR_FREE(mem_mask);
-    if (virDomainObjIsActive(vm))
-        vm->def->vcpus = vcpus;
+    if (virDomainObjIsActive(vm) &&
+        virDomainDefSetVcpus(vm->def, vcpus) < 0)
+        ret = -1;
     virDomainAuditVcpu(vm, oldvcpus, nvcpus, "update", rc == 1);
     if (cgroup_vcpu)
         virCgroupFree(&cgroup_vcpu);
@@ -4982,7 +4983,8 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                 if (virDomainDefSetVcpusMax(persistentDef, nvcpus) < 0)
                     goto endjob;
             } else {
-                persistentDef->vcpus = nvcpus;
+                if (virDomainDefSetVcpus(persistentDef, nvcpus) < 0)
+                    goto endjob;
             }
 
             if (virDomainSaveConfig(cfg->configDir, persistentDef) < 0)
index cb6ad7634fd30a8ff32c96f77f3180dcf27a0efa..56d8ef22da8e58a77eeb2a8889577a19b78184d8 100644 (file)
@@ -2375,15 +2375,17 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
         goto cleanup;
     }
 
-    if (def)
-        def->vcpus = nrCpus;
+    if (def &&
+        virDomainDefSetVcpus(def, nrCpus) < 0)
+        goto cleanup;
 
     if (persistentDef) {
         if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
             if (virDomainDefSetVcpusMax(persistentDef, nrCpus) < 0)
                 goto cleanup;
         } else {
-            persistentDef->vcpus = nrCpus;
+            if (virDomainDefSetVcpus(persistentDef, nrCpus) < 0)
+                goto cleanup;
         }
     }
 
index 61f6476a330ec584ec79566597fc9f26616c30fc..cf4de2db7405f59ddec66690477a9ce3919f1e87 100644 (file)
@@ -3910,7 +3910,8 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     if (virDomainDefSetVcpusMax(def, CPUCount) < 0)
         goto cleanup;
 
-    def->vcpus = CPUCount;
+    if (virDomainDefSetVcpus(def, CPUCount) < 0)
+        goto cleanup;
 
     /* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */
 
@@ -6067,7 +6068,8 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
         if (virDomainDefSetVcpusMax(def->dom, CPUCount) < 0)
             goto cleanup;
 
-        def->dom->vcpus = CPUCount;
+        if (virDomainDefSetVcpus(def->dom, CPUCount) < 0)
+            goto cleanup;
 
         if (vboxSnapshotGetReadWriteDisks(def, snapshot) < 0)
             VIR_DEBUG("Could not get read write disks for snapshot");
index 74b04e2d0bf17432e1b585ec7804bc8edec7c8b2..f94835635147cee0b46008bd14a0a7a0225fa9c2 100644 (file)
@@ -1461,7 +1461,8 @@ virVMXParseConfig(virVMXContext *ctx,
     if (virDomainDefSetVcpusMax(def, numvcpus) < 0)
         goto cleanup;
 
-    def->vcpus = numvcpus;
+    if (virDomainDefSetVcpus(def, numvcpus) < 0)
+        goto cleanup;
 
     /* vmx:sched.cpu.affinity -> def:cpumask */
     /* NOTE: maps to VirtualMachine:config.cpuAffinity.affinitySet */
index 6c61c12700525bd8ab075662350bfe47039a33e4..c26c0bfd0d399023098fa38ac6a91bc8521780cc 100644 (file)
@@ -1153,7 +1153,8 @@ prlsdkConvertCpuInfo(PRL_HANDLE sdkdom,
     if (virDomainDefSetVcpusMax(def, cpuCount) < 0)
         goto cleanup;
 
-    def->vcpus = cpuCount;
+    if (virDomainDefSetVcpus(def, cpuCount) < 0)
+        goto cleanup;
 
     pret = PrlVmCfg_GetCpuMask(sdkdom, NULL, &buflen);
     prlsdkCheckRetGoto(pret, cleanup);
index f9191acb75e7c10202b11b525fe09465bd054bb5..83444238c27e9e077a3ba3052757d2034310b413 100644 (file)
@@ -708,7 +708,8 @@ xenXMDomainSetVcpusFlags(virConnectPtr conn,
         if (virDomainDefSetVcpusMax(entry->def, vcpus) < 0)
             goto cleanup;
     } else {
-        entry->def->vcpus = vcpus;
+        if (virDomainDefSetVcpus(entry->def, vcpus) < 0)
+            goto cleanup;
     }
 
     /* If this fails, should we try to undo our changes to the
index fa66bb19c6c52d1ae66456272a9ced3670e096d7..e4e99360f1f01c021387810e62295697d9a8bf6f 100644 (file)
@@ -1505,7 +1505,8 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
     if (virDomainDefSetVcpusMax(defPtr, vcpus) < 0)
         goto error;
 
-    defPtr->vcpus = vcpus;
+    if (virDomainDefSetVcpus(defPtr, vcpus) < 0)
+        goto error;
 
     enum xen_on_normal_exit action;
     if (xen_vm_get_actions_after_shutdown(session, &action, vm))
index 39c8a795e17169b199baf9e6ae2bf37bc413d764..66bd4472f70e8521b2e0f33c0644291c66de051f 100644 (file)
@@ -508,7 +508,10 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
     if (xenConfigGetULong(conf, "vcpu_avail", &count, -1) < 0)
         return -1;
 
-    def->vcpus = MIN(count_one_bits_l(count), virDomainDefGetVcpusMax(def));
+    if (virDomainDefSetVcpus(def, MIN(count_one_bits_l(count),
+                                      virDomainDefGetVcpusMax(def))) < 0)
+        return -1;
+
     if (xenConfigGetString(conf, "cpus", &str, NULL) < 0)
         return -1;
 
index b251525a1e25fadd012b417b3fe22e8db343ff5a..484a0949b00ae3db83f1fbc849b87f2718ae2b86 100644 (file)
@@ -1092,6 +1092,7 @@ xenParseSxpr(const struct sexpr *root,
     const char *tmp;
     virDomainDefPtr def;
     int hvm = 0, vmlocaltime;
+    unsigned int vcpus;
 
     if (!(def = virDomainDefNew()))
         goto error;
@@ -1175,9 +1176,13 @@ xenParseSxpr(const struct sexpr *root,
 
     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 || virDomainDefGetVcpusMax(def) < def->vcpus)
-        def->vcpus = virDomainDefGetVcpusMax(def);
+
+    vcpus = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail"));
+    if (!vcpus || virDomainDefGetVcpusMax(def) < vcpus)
+        vcpus = virDomainDefGetVcpusMax(def);
+
+    if (virDomainDefSetVcpus(def, vcpus) < 0)
+        goto error;
 
     tmp = sexpr_node(root, "domain/on_poweroff");
     if (tmp != NULL) {