From: Martin Kletzander Date: Fri, 13 Mar 2015 16:08:15 +0000 (+0100) Subject: conf: Use correct type for balloon stats period X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=ad69e8be4a7592c68174a7c0d8b07a2c392ea336;p=people%2Fliuw%2Flibxenctrl-split%2Flibvirt.git conf: Use correct type for balloon stats period We're parsing memballoon status period as unsigned int, but when we're trying to set it, both we and qemu use signed int. That means large values will get wrapped around to negative one resulting in error. Basically the same problem as commit e3a7b874 was dealing with when updating live domain. QEMU changed the accepted value to int64 in commit 1f9296b5, but even values as INT_MAX don't make sense since the value passed means seconds. Hence adding capability flag for this change isn't worth it. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1140958 Signed-off-by: Luyao Huang Signed-off-by: Martin Kletzander --- diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 40e2b2979..8d9891554 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -5618,18 +5618,17 @@ qemu-kvm -net nic,model=? /dev/null
period

- The optional period allows the QEMU virtio memory - balloon driver to provide statistics through the virsh - dommemstat [domain] command. By default, collection is - not enabled. In order to enable, use the virsh dommemstat - [domain] --period [number] command or virsh edit - command to add the option to the XML definition. - The virsh dommemstat will accept the options - --live, --current, or --config. - If an option is not provided, the change for a running domain will - only be made to the active guest. - If the QEMU driver is not at the right - revision, the attempt to set the period will fail. + The optional period allows the QEMU virtio memory balloon + driver to provide statistics through the virsh dommemstat + [domain] command. By default, collection is not enabled. In + order to enable, use the virsh dommemstat [domain] --period + [number] command or virsh edit command to add the + option to the XML definition. The virsh dommemstat will + accept the options --live, --current, + or --config. If an option is not provided, the change + for a running domain will only be made to the active guest. If the + QEMU driver is not at the right revision, the attempt to set the + period will fail. Large values (e.g. many years) might be ignored. Since 1.1.1, requires QEMU 1.5

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3865854a5..c75b54359 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10492,6 +10492,7 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, char *model; virDomainMemballoonDefPtr def; xmlNodePtr save = ctxt->node; + unsigned int period = 0; if (VIR_ALLOC(def) < 0) return NULL; @@ -10510,12 +10511,16 @@ virDomainMemballoonDefParseXML(xmlNodePtr node, } ctxt->node = node; - if (virXPathUInt("string(./stats/@period)", ctxt, &def->period) < -1) { + if (virXPathUInt("string(./stats/@period)", ctxt, &period) < -1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("invalid statistics collection period")); goto error; } + def->period = period; + if (def->period < 0) + def->period = 0; + if (def->model == VIR_DOMAIN_MEMBALLOON_MODEL_NONE) VIR_DEBUG("Ignoring device address for none model Memballoon"); else if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0) @@ -18839,7 +18844,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, virBufferAdjustIndent(&childrenBuf, indent + 2); if (def->period) - virBufferAsprintf(&childrenBuf, "\n", def->period); + virBufferAsprintf(&childrenBuf, "\n", def->period); if (virDomainDeviceInfoNeedsFormat(&def->info, flags) && virDomainDeviceInfoFormat(&childrenBuf, &def->info, flags) < 0) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4b437b440..4eb774288 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1560,7 +1560,7 @@ enum { struct _virDomainMemballoonDef { int model; virDomainDeviceInfo info; - unsigned int period; /* seconds between collections */ + int period; /* seconds between collections */ }; struct _virDomainNVRAMDef { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 5bb7e5b39..ae315df09 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4309,7 +4309,7 @@ int qemuProcessStart(virConnectPtr conn, virCommandPtr cmd = NULL; struct qemuProcessHookData hookData; unsigned long cur_balloon; - unsigned int period = 0; + int period = 0; size_t i; bool rawio_set = false; char *nodeset = NULL;