提交 fbbea798 编写于 作者: P Peter Krempa

conf: Store cpu count as unsigned int

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.
上级 d3889db0
...@@ -13893,7 +13893,6 @@ virDomainDefParseXML(xmlDocPtr xml, ...@@ -13893,7 +13893,6 @@ virDomainDefParseXML(xmlDocPtr xml,
int n; int n;
long id = -1; long id = -1;
virDomainDefPtr def; virDomainDefPtr def;
unsigned long count;
bool uuid_generated = false; bool uuid_generated = false;
virHashTablePtr bootHash = NULL; virHashTablePtr bootHash = NULL;
bool usb_none = false; bool usb_none = false;
...@@ -14176,45 +14175,32 @@ virDomainDefParseXML(xmlDocPtr xml, ...@@ -14176,45 +14175,32 @@ virDomainDefParseXML(xmlDocPtr xml,
&def->mem.swap_hard_limit) < 0) &def->mem.swap_hard_limit) < 0)
goto error; goto error;
n = virXPathULong("string(./vcpu[1])", ctxt, &count); if ((n = virXPathUInt("string(./vcpu[1])", ctxt, &def->maxvcpus)) < 0) {
if (n == -2) { if (n == -2) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("maximum vcpus must be an integer")); _("maximum vcpus count 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);
goto error; goto error;
} }
def->maxvcpus = 1;
} }
n = virXPathULong("string(./vcpu[1]/@current)", ctxt, &count); if ((n = virXPathUInt("string(./vcpu[1]/@current)", ctxt, &def->vcpus)) < 0) {
if (n == -2) { if (n == -2) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("current vcpus must be an integer")); _("current vcpus count must be an integer"));
goto error; goto error;
} else if (n < 0) { }
def->vcpus = def->maxvcpus; 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);
goto error;
} }
if (def->maxvcpus < count) { if (def->maxvcpus < def->vcpus) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("maxvcpus must not be less than current vcpus " _("maxvcpus must not be less than current vcpus "
"(%d < %lu)"), "(%u < %u)"), def->maxvcpus, def->vcpus);
def->maxvcpus, count);
goto error; goto error;
} }
}
tmp = virXPathString("string(./vcpu[1]/@placement)", ctxt); tmp = virXPathString("string(./vcpu[1]/@placement)", ctxt);
if (tmp) { if (tmp) {
......
...@@ -2159,8 +2159,8 @@ struct _virDomainDef { ...@@ -2159,8 +2159,8 @@ struct _virDomainDef {
virDomainBlkiotune blkio; virDomainBlkiotune blkio;
virDomainMemtune mem; virDomainMemtune mem;
unsigned short vcpus; unsigned int vcpus;
unsigned short maxvcpus; unsigned int maxvcpus;
int placement_mode; int placement_mode;
virBitmapPtr cpumask; virBitmapPtr cpumask;
......
...@@ -7279,10 +7279,6 @@ virDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus, ...@@ -7279,10 +7279,6 @@ virDomainSetVcpusFlags(virDomainPtr domain, unsigned int nvcpus,
virCheckNonZeroArgGoto(nvcpus, error); virCheckNonZeroArgGoto(nvcpus, error);
if ((unsigned short) nvcpus != nvcpus) {
virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"), nvcpus);
goto error;
}
conn = domain->conn; conn = domain->conn;
if (conn->driver->domainSetVcpusFlags) { if (conn->driver->domainSetVcpusFlags) {
...@@ -7403,11 +7399,6 @@ virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu, ...@@ -7403,11 +7399,6 @@ virDomainPinVcpu(virDomainPtr domain, unsigned int vcpu,
virCheckNonNullArgGoto(cpumap, error); virCheckNonNullArgGoto(cpumap, error);
virCheckPositiveArgGoto(maplen, error); virCheckPositiveArgGoto(maplen, error);
if ((unsigned short) vcpu != vcpu) {
virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"), vcpu);
goto error;
}
if (conn->driver->domainPinVcpu) { if (conn->driver->domainPinVcpu) {
int ret; int ret;
ret = conn->driver->domainPinVcpu(domain, vcpu, cpumap, maplen); ret = conn->driver->domainPinVcpu(domain, vcpu, cpumap, maplen);
...@@ -7475,11 +7466,6 @@ virDomainPinVcpuFlags(virDomainPtr domain, unsigned int vcpu, ...@@ -7475,11 +7466,6 @@ virDomainPinVcpuFlags(virDomainPtr domain, unsigned int vcpu,
virCheckNonNullArgGoto(cpumap, error); virCheckNonNullArgGoto(cpumap, error);
virCheckPositiveArgGoto(maplen, error); virCheckPositiveArgGoto(maplen, error);
if ((unsigned short) vcpu != vcpu) {
virReportError(VIR_ERR_OVERFLOW, _("input too large: %u"), vcpu);
goto error;
}
if (conn->driver->domainPinVcpuFlags) { if (conn->driver->domainPinVcpuFlags) {
int ret; int ret;
ret = conn->driver->domainPinVcpuFlags(domain, vcpu, cpumap, maplen, flags); ret = conn->driver->domainPinVcpuFlags(domain, vcpu, cpumap, maplen, flags);
......
...@@ -4870,12 +4870,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus, ...@@ -4870,12 +4870,6 @@ qemuDomainSetVcpusFlags(virDomainPtr dom, unsigned int nvcpus,
VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_MAXIMUM |
VIR_DOMAIN_VCPU_GUEST, -1); 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))) if (!(vm = qemuDomObjFromDomain(dom)))
goto cleanup; goto cleanup;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册