diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index d2dbcb8ca9..a1cc1e10e7 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -4641,6 +4641,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> @@ -4658,6 +4659,15 @@ qemu-kvm -net nic,model=? /dev/null
  • 'xen' — default with Xen
  • +
    period
    +
    +

    + The optional period allows the QEMU virtio memory + balloon driver to provide statistics through the virsh + dommemstat [domain] command. + Since 1.1.1, requires QEMU 1.5 +

    +

    Random number generator device

    diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index c1355300a5..7a6852b377 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -2946,6 +2946,13 @@ + + + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5f7ef1952d..44be81e204 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8574,32 +8574,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: @@ -9472,7 +9483,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: @@ -12105,7 +12118,7 @@ virDomainDefParseXML(xmlDocPtr xml, } if (n > 0) { virDomainMemballoonDefPtr memballoon = - virDomainMemballoonDefParseXML(nodes[0], flags); + virDomainMemballoonDefParseXML(nodes[0], ctxt, flags); if (!memballoon) goto error; @@ -15301,6 +15314,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainMemballoonModelTypeToString(def->model); + bool noopts = true; if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -15314,11 +15328,21 @@ virDomainMemballoonDefFormat(virBufferPtr buf, virBufferAddLit(buf, ">\n"); if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; - virBufferAddLit(buf, " \n"); - } else { - virBufferAddLit(buf, "/>\n"); + noopts = false; } + if (def->period) { + if (noopts) + virBufferAddLit(buf, ">\n"); + virBufferAsprintf(buf, " \n", def->period); + noopts = false; + } + + if (noopts) + virBufferAddLit(buf, "/>\n"); + else + virBufferAddLit(buf, " \n"); + return 0; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c26f4e2a44..b14afd9a3c 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 { diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.args b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.args new file mode 100644 index 0000000000..48af1c42f1 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.args @@ -0,0 +1,5 @@ +LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ +pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -monitor \ +unix:/tmp/test-monitor,server,nowait -no-acpi -boot c -usb -hda \ +/dev/HostVG/QEMUGuest1 -device virtio-balloon-pci,id=balloon0,bus=pci.0,\ +addr=0x12 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.xml b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.xml new file mode 100644 index 0000000000..c47c9bfaec --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.xml @@ -0,0 +1,26 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu + + + + + +
    + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 7d7332f8e3..0f96eef91e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -837,6 +837,7 @@ mymain(void) DO_TEST("balloon-device", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("balloon-device-auto", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); + DO_TEST("balloon-device-period", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG); DO_TEST("sound", NONE); DO_TEST("sound-device", QEMU_CAPS_DEVICE, QEMU_CAPS_NODEFCONFIG,