]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: Store cpu count as unsigned int
authorPeter Krempa <pkrempa@redhat.com>
Mon, 25 May 2015 13:43:29 +0000 (15:43 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 4 Jun 2015 08:52:30 +0000 (10:52 +0200)
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
src/conf/domain_conf.h
src/libvirt-domain.c
src/qemu/qemu_driver.c

index d2c1d2e8a92d61c49e69184ab1fb6fc8926afb5a..2a12a0653a743f579c419bc3cbbbbd6b259230f2 100644 (file)
@@ -13893,7 +13893,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;
@@ -14176,44 +14175,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);
index b69ad9ec1b73a3251fd8ce13fd04435288554923..906ec4f9c5be6515fadeefcf19dc5e52bd9c4d98 100644 (file)
@@ -2159,8 +2159,8 @@ struct _virDomainDef {
     virDomainBlkiotune blkio;
     virDomainMemtune mem;
 
-    unsigned short vcpus;
-    unsigned short maxvcpus;
+    unsigned int vcpus;
+    unsigned int maxvcpus;
     int placement_mode;
     virBitmapPtr cpumask;
 
index c40826deff3725466c8e092944bb3d8334bc24ec..05990c7a68523988cb58c91fdc4af02903ae5e9b 100644 (file)
@@ -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);
index a4134f38e172b630076ab04e27c0f21cf8faa1dc..3e6633c867133142012e457c36da2f6112b61551 100644 (file)
@@ -4870,12 +4870,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;