[PATCH v2 04/27] conf: Add helper to check whether domain has offline vCPUs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The new helper will simplify checking whether the domain config contains
inactive vCPUs.
---
 src/conf/domain_conf.c     | 9 ++++++++-
 src/conf/domain_conf.h     | 1 +
 src/libvirt_private.syms   | 1 +
 src/openvz/openvz_driver.c | 2 +-
 src/qemu/qemu_command.c    | 4 ++--
 src/vbox/vbox_common.c     | 2 +-
 src/vmx/vmx.c              | 2 +-
 src/vz/vz_sdk.c            | 2 +-
 src/xenconfig/xen_common.c | 2 +-
 src/xenconfig/xen_sxpr.c   | 4 ++--
 10 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 99a789b..8289acf 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1443,6 +1443,13 @@ virDomainDefSetVcpusMax(virDomainDefPtr def,
 }


+bool
+virDomainDefHasVcpusOffline(const virDomainDef *def)
+{
+    return def->vcpus < def->maxvcpus;
+}
+
+
 virDomainDiskDefPtr
 virDomainDiskDefNew(virDomainXMLOptionPtr xmlopt)
 {
@@ -21821,7 +21828,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);

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f65026b..7f43d26 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2338,6 +2338,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);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b1bced7..4ccf04c 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -219,6 +219,7 @@ virDomainDefGetMemoryInitial;
 virDomainDefGetSecurityLabelDef;
 virDomainDefHasDeviceAddress;
 virDomainDefHasMemoryHotplug;
+virDomainDefHasVcpusOffline;
 virDomainDefMaybeAddController;
 virDomainDefMaybeAddInput;
 virDomainDefNeedsPlacementAdvice;
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 307b607..56569d1 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -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;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 30d7bdb..f3327c0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -7866,7 +7866,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 */
@@ -7879,7 +7879,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",
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 1a0cc63..0a17aeb 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1891,7 +1891,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"));
     }
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index fe9d407..0813553 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -3175,7 +3175,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'"));
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index eb0d2e8..c90220c 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -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;
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index eba5be2..878d1ae 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -1531,7 +1531,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;

diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index 76c4051..7799f9e 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -2226,7 +2226,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) {
@@ -2308,7 +2308,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);

-- 
2.6.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]