[PATCH 18/35] conf: Store cpu count as unsigned int

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

 



While we probably won't see machines with more than 65536 cpus for a
while lets store the cpu count as an integer so that we can avoid quite
a lot of overflow checks in our code.
---
 src/conf/domain_conf.c | 50 ++++++++++++++++++--------------------------------
 src/conf/domain_conf.h |  4 ++--
 src/libvirt-domain.c   | 14 --------------
 src/qemu/qemu_driver.c |  6 ------
 4 files changed, 20 insertions(+), 54 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8a45682..4a8c1b5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13868,7 +13868,6 @@ virDomainDefParseXML(xmlDocPtr xml,
     int n;
     long id = -1;
     virDomainDefPtr def;
-    unsigned long count;
     bool uuid_generated = false;
     virHashTablePtr bootHash = NULL;
     bool usb_none = false;
@@ -14151,44 +14150,31 @@ virDomainDefParseXML(xmlDocPtr xml,
                                   &def->mem.swap_hard_limit) < 0)
         goto error;

-    n = virXPathULong("string(./vcpu[1])", ctxt, &count);
-    if (n == -2) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("maximum vcpus must be an integer"));
-        goto error;
-    } else if (n < 0) {
-        def->maxvcpus = 1;
-    } else {
-        def->maxvcpus = count;
-        if (count == 0 || (unsigned short) count != count) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("invalid maximum number of vCPUs '%lu'"), count);
+    if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &def->maxvcpus)) < 0) {
+        if (n == -2) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("maximum vcpus count must be an integer"));
             goto error;
         }
+
+        def->maxvcpus = 1;
     }

-    n = virXPathULong("string(./vcpu[1]/@current)", ctxt, &count);
-    if (n == -2) {
-        virReportError(VIR_ERR_XML_ERROR, "%s",
-                       _("current vcpus must be an integer"));
-        goto error;
-    } else if (n < 0) {
-        def->vcpus = def->maxvcpus;
-    } else {
-        def->vcpus = count;
-        if (count == 0 || (unsigned short) count != count) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("invalid current number of vCPUs '%lu'"), count);
+    if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &def->vcpus)) < 0) {
+        if (n == -2) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("current vcpus count must be an integer"));
             goto error;
         }

-        if (def->maxvcpus < count) {
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("maxvcpus must not be less than current vcpus "
-                             "(%d < %lu)"),
-                           def->maxvcpus, count);
-            goto error;
-        }
+        def->vcpus = def->maxvcpus;
+    }
+
+    if (def->maxvcpus < def->vcpus) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("maxvcpus must not be less than current vcpus "
+                         "(%u < %u)"), def->maxvcpus, def->vcpus);
+        goto error;
     }

     tmp = virXPathString("string(./vcpu[1]/@placement)", ctxt);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a0f68ea..34b669d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2158,8 +2158,8 @@ struct _virDomainDef {
     virDomainBlkiotune blkio;
     virDomainMemtune mem;

-    unsigned short vcpus;
-    unsigned short maxvcpus;
+    unsigned int vcpus;
+    unsigned int maxvcpus;
     int placement_mode;
     virBitmapPtr cpumask;

diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index c40826d..05990c7 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -7279,10 +7279,6 @@ virDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,

     virCheckNonZeroArgGoto(nvcpus, error);

-    if ((unsigned short) nvcpus != nvcpus) {
-        virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"), nvcpus);
-        goto error;
-    }
     conn = domain->conn;

     if (conn->driver->domainSetVcpusFlags) {
@@ -7403,11 +7399,6 @@ virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
     virCheckNonNullArgGoto(cpumap, error);
     virCheckPositiveArgGoto(maplen, error);

-    if ((unsigned short) vcpu != vcpu) {
-        virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"), vcpu);
-        goto error;
-    }
-
     if (conn->driver->domainPinVcpu) {
         int ret;
         ret = conn->driver->domainPinVcpu(domain, vcpu, cpumap, maplen);
@@ -7475,11 +7466,6 @@ virDomainPinVcpuFlags(virDomainPtr domain, unsigned int vcpu,
     virCheckNonNullArgGoto(cpumap, error);
     virCheckPositiveArgGoto(maplen, error);

-    if ((unsigned short) vcpu != vcpu) {
-        virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"), vcpu);
-        goto error;
-    }
-
     if (conn->driver->domainPinVcpuFlags) {
         int ret;
         ret = conn->driver->domainPinVcpuFlags(domain, vcpu, cpumap, maplen, flags);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 92da08d..2be26c6 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4866,12 +4866,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
                   VIR_DOMAIN_VCPU_MAXIMUM |
                   VIR_DOMAIN_VCPU_GUEST, -1);

-    if (!nvcpus || (unsigned short) nvcpus != nvcpus) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("argument out of range: %d"), nvcpus);
-        return -1;
-    }
-
     if (!(vm = qemuDomObjFromDomain(dom)))
         goto cleanup;

-- 
2.4.1

--
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]