Add a period in seconds to allow/enable statistics gathering from the
Balloon driver for 'virsh dommemstat <domain>'.
---
docs/formatdomain.html.in | 10 ++++++++++
docs/schemas/domaincommon.rng | 7 +++++++
src/conf/domain_conf.c | 38 +++++++++++++++++++++++++++++++-------
src/conf/domain_conf.h | 1 +
4 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 52a6353..93d2416 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -4637,6 +4637,7 @@ qemu-kvm -net nic,model=? /dev/null
<devices>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x0'/>
+ <stats period='10'/>
</memballoon>
</devices>
</domain></pre>
@@ -4654,6 +4655,15 @@ qemu-kvm -net nic,model=? /dev/null
<li>'xen' — default with Xen</li>
</ul>
</dd>
+ <dt><code>period</code></dt>
+ <dd>
+ <p>
+ The optional <code>period</code> allows the QEMU virtio memory
+ balloon driver to provide statistics through the <code>virsh
+ dommemstat [domain]</code> command.
+ <span class='since'>Since 1.1.1, requires QEMU 1.5</span>
+ </p>
+ </dd>
</dl>
<h4><a name="elementsRng">Random number generator
device</a></h4>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index c135530..7a6852b 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2946,6 +2946,13 @@
<optional>
<ref name="address"/>
</optional>
+ <optional>
+ <element name="stats">
+ <attribute name="period">
+ <ref name="positiveInteger"/>
+ </attribute>
+ </element>
+ </optional>
</element>
</define>
<define name="parallel">
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 33ae4a7..816b96c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8530,32 +8530,43 @@ error:
static virDomainMemballoonDefPtr
virDomainMemballoonDefParseXML(const xmlNodePtr node,
+ xmlXPathContextPtr ctxt,
unsigned int flags)
{
char *model;
virDomainMemballoonDefPtr def;
+ xmlNodePtr save = ctxt->node;
if (VIR_ALLOC(def) < 0)
return NULL;
model = virXMLPropString(node, "model");
if (model == NULL) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ virReportError(VIR_ERR_XML_ERROR, "%s",
_("balloon memory must contain model name"));
goto error;
}
+
if ((def->model = virDomainMemballoonModelTypeFromString(model)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
+ virReportError(VIR_ERR_XML_ERROR,
_("unknown memory balloon model '%s'"), model);
goto error;
}
+ ctxt->node = node;
+ if (virXPathUInt("string(./stats/@period)", ctxt, &def->period) <
-1) {
+ virReportError(VIR_ERR_XML_ERROR, "%s",
+ _("invalid statistics collection period"));
+ goto error;
+ }
+
if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
goto error;
cleanup:
VIR_FREE(model);
+ ctxt->node = save;
return def;
error:
@@ -9428,7 +9439,9 @@ virDomainDeviceDefParse(const char *xmlStr,
goto error;
break;
case VIR_DOMAIN_DEVICE_MEMBALLOON:
- if (!(dev->data.memballoon = virDomainMemballoonDefParseXML(node, flags)))
+ if (!(dev->data.memballoon = virDomainMemballoonDefParseXML(node,
+ ctxt,
+ flags)))
goto error;
break;
case VIR_DOMAIN_DEVICE_NVRAM:
@@ -11931,7 +11944,7 @@ virDomainDefParseXML(xmlDocPtr xml,
}
if (n > 0) {
virDomainMemballoonDefPtr memballoon =
- virDomainMemballoonDefParseXML(nodes[0], flags);
+ virDomainMemballoonDefParseXML(nodes[0], ctxt, flags);
if (!memballoon)
goto error;
@@ -15127,6 +15140,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
unsigned int flags)
{
const char *model = virDomainMemballoonModelTypeToString(def->model);
+ bool noopts = true;
if (!model) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -15140,11 +15154,21 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
virBufferAddLit(buf, ">\n");
if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
return -1;
- virBufferAddLit(buf, " </memballoon>\n");
- } else {
- virBufferAddLit(buf, "/>\n");
+ noopts = false;
}
+ if (def->period) {
+ if (noopts)
+ virBufferAddLit(buf, ">\n");
+ virBufferAsprintf(buf, " <stats period='%u'/>\n",
def->period);
+ noopts = false;
+ }
+
+ if (noopts)
+ virBufferAddLit(buf, "/>\n");
+ else
+ virBufferAddLit(buf, " </memballoon>\n");
+
return 0;
}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 4a7dcd2..ed314d9 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1533,6 +1533,7 @@ enum {
struct _virDomainMemballoonDef {
int model;
virDomainDeviceInfo info;
+ unsigned int period; /* seconds between collections */
};
struct _virDomainNVRAMDef {
--
1.8.1.4