]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
conf: Add helper to check whether domain has offline vCPUs
authorPeter Krempa <pkrempa@redhat.com>
Mon, 19 Oct 2015 16:23:23 +0000 (18:23 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 9 Dec 2015 13:57:12 +0000 (14:57 +0100)
The new helper will simplify checking whether the domain config contains
inactive vCPUs.

src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/openvz/openvz_driver.c
src/qemu/qemu_command.c
src/vbox/vbox_common.c
src/vmx/vmx.c
src/vz/vz_sdk.c
src/xenconfig/xen_common.c
src/xenconfig/xen_sxpr.c

index 5370a089f11f67676d57118f96e566c4c3d970a3..cee5c1c13a78f12d13d00edae5c85dee23c2b56d 100644 (file)
@@ -1297,6 +1297,13 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
 }
 
 
+bool
+virDomainDefHasVcpusOffline(const virDomainDef *def)
+{
+    return def->vcpus < def->maxvcpus;
+}
+
+
 virDomainDiskDefPtr
 virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
 {
@@ -21521,7 +21528,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         virBufferAsprintf(buf, " cpuset='%s'", cpumask);
         VIR_FREE(cpumask);
     }
-    if (def->vcpus != def->maxvcpus)
+    if (virDomainDefHasVcpusOffline(def))
         virBufferAsprintf(buf, " current='%u'", def->vcpus);
     virBufferAsprintf(buf, ">%u</vcpu>\n", def->maxvcpus);
 
index eda66a5adedde048b91e6cd540ac625e515ea62e..89c22e3c2acc47f0e0f411576013454c6f660bd2 100644 (file)
@@ -2344,6 +2344,7 @@ struct _virDomainDef {
 };
 
 int virDomainDefSetVcpusMax(virDomainDefPtr def, unsigned int vcpus);
+bool virDomainDefHasVcpusOffline(const virDomainDef *def);
 
 unsigned long long virDomainDefGetMemoryInitial(const virDomainDef *def);
 void virDomainDefSetMemoryTotal(virDomainDefPtr def, unsigned long long size);
index b76299b7a3b3945dc4ca697c2f1674de1acb5be3..a8ad00a197b10a534092d1bcb25aa3872c9c5f24 100644 (file)
@@ -219,6 +219,7 @@ virDomainDefGetMemoryInitial;
 virDomainDefGetSecurityLabelDef;
 virDomainDefHasDeviceAddress;
 virDomainDefHasMemoryHotplug;
+virDomainDefHasVcpusOffline;
 virDomainDefMaybeAddController;
 virDomainDefMaybeAddInput;
 virDomainDefNeedsPlacementAdvice;
index 307b607a25cb6370e90867a455e7a764b7301cdc..56569d179108733204aa399ed02a7aa29366bb81 100644 (file)
@@ -1030,7 +1030,7 @@ openvzDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int fla
     if (openvzDomainSetNetworkConfig(conn, vm->def) < 0)
         goto cleanup;
 
-    if (vm->def->vcpus != vm->def->maxvcpus) {
+    if (virDomainDefHasVcpusOffline(vm->def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("current vcpu count must equal maximum"));
         goto cleanup;
index b2cbb52a0f1529185aed64871bfd751b14596160..aca5221bfd7bbfb089fdd5e677e7718cd363fb18 100644 (file)
@@ -7962,7 +7962,7 @@ qemuBuildSmpArgStr(const virDomainDef *def,
     virBufferAsprintf(&buf, "%u", def->vcpus);
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SMP_TOPOLOGY)) {
-        if (def->vcpus != def->maxvcpus)
+        if (virDomainDefHasVcpusOffline(def))
             virBufferAsprintf(&buf, ",maxcpus=%u", def->maxvcpus);
         /* sockets, cores, and threads are either all zero
          * or all non-zero, thus checking one of them is enough */
@@ -7975,7 +7975,7 @@ qemuBuildSmpArgStr(const virDomainDef *def,
             virBufferAsprintf(&buf, ",cores=%u", 1);
             virBufferAsprintf(&buf, ",threads=%u", 1);
         }
-    } else if (def->vcpus != def->maxvcpus) {
+    } else if (virDomainDefHasVcpusOffline(def)) {
         virBufferFreeAndReset(&buf);
         /* FIXME - consider hot-unplugging cpus after boot for older qemu */
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
index 9bfe60287b323bad81ec1ee3bab486e610e2a31e..b9aa085723fb30d67d5e03e53575965d2539c48a 100644 (file)
@@ -1895,7 +1895,7 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags
                        def->mem.cur_balloon, (unsigned)rc);
     }
 
-    if (def->vcpus != def->maxvcpus) {
+    if (virDomainDefHasVcpusOffline(def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("current vcpu count must equal maximum"));
     }
index dda072640b12c4f4e78e45570b741176f9f23e3e..54024e4d4bf9bb07066a5d46f75cece4c8227798 100644 (file)
@@ -3180,7 +3180,7 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe
     }
 
     /* def:maxvcpus -> vmx:numvcpus */
-    if (def->vcpus != def->maxvcpus) {
+    if (virDomainDefHasVcpusOffline(def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("No support for domain XML entry 'vcpu' attribute "
                          "'current'"));
index 30e3c0ccbb534eaf064f682b0063406a9b515568..6c61c12700525bd8ab075662350bfe47039a33e4 100644 (file)
@@ -1933,7 +1933,7 @@ prlsdkCheckUnsupportedParams(PRL_HANDLE sdkdom, virDomainDefPtr def)
         return -1;
     }
 
-    if (def->vcpus != def->maxvcpus) {
+    if (virDomainDefHasVcpusOffline(def)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("current vcpus must be equal to maxvcpus"));
         return -1;
index 33849e784d129d7c07d698f9f6edf37096b87604..c3640e1a419ac548e99ff7b1f53b9fdf1b9c945b 100644 (file)
@@ -1533,7 +1533,7 @@ xenFormatCPUAllocation(virConfPtr conf, virDomainDefPtr def)
 
     /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
        either 32, or 64 on a platform where long is big enough.  */
-    if (def->vcpus < def->maxvcpus &&
+    if (virDomainDefHasVcpusOffline(def) &&
         xenConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0)
         goto cleanup;
 
index 3ce283aa14b0d34d9f52c8d4afec40edd66f2570..0acc5209fef36d27bf00ebcd2c024f18117609b1 100644 (file)
@@ -2240,7 +2240,7 @@ xenFormatSxpr(virConnectPtr conn,
     virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
     /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
        either 32, or 64 on a platform where long is big enough.  */
-    if (def->vcpus < def->maxvcpus)
+    if (virDomainDefHasVcpusOffline(def))
         virBufferAsprintf(&buf, "(vcpu_avail %lu)", (1UL << def->vcpus) - 1);
 
     if (def->cpumask) {
@@ -2322,7 +2322,7 @@ xenFormatSxpr(virConnectPtr conn,
                 virBufferEscapeSexpr(&buf, "(kernel '%s')", def->os.loader->path);
 
             virBufferAsprintf(&buf, "(vcpus %u)", def->maxvcpus);
-            if (def->vcpus < def->maxvcpus)
+            if (virDomainDefHasVcpusOffline(def))
                 virBufferAsprintf(&buf, "(vcpu_avail %lu)",
                                   (1UL << def->vcpus) - 1);