Add 'period' for Memballoon statistics gathering capability

Add a period in seconds to allow/enable statistics gathering from the
Balloon driver for 'virsh dommemstat <domain>'.
This commit is contained in:
John Ferlan 2013-06-26 07:00:00 -04:00
parent 96518d4316
commit 9ed3a5ca34
7 changed files with 81 additions and 7 deletions

View File

@ -4641,6 +4641,7 @@ qemu-kvm -net nic,model=? /dev/null
&lt;devices&gt;
&lt;memballoon model='virtio'&gt;
&lt;address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/&gt;
&lt;stats period='10'/&gt;
&lt;/memballoon&gt;
&lt;/devices&gt;
&lt;/domain&gt;</pre>
@ -4658,6 +4659,15 @@ qemu-kvm -net nic,model=? /dev/null
<li>'xen' &mdash; 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>

View File

@ -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">

View File

@ -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, " </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;
}

View File

@ -1533,6 +1533,7 @@ enum {
struct _virDomainMemballoonDef {
int model;
virDomainDeviceInfo info;
unsigned int period; /* seconds between collections */
};
struct _virDomainNVRAMDef {

View File

@ -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

View File

@ -0,0 +1,26 @@
<domain type='qemu'>
<name>QEMUGuest1</name>
<uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>219136</memory>
<currentMemory unit='KiB'>219136</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='i686' machine='pc'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu</emulator>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='hda' bus='ide'/>
</disk>
<memballoon model='virtio'>
<address type='pci' domain='0' bus='0' slot='18' function='0'/>
<stats period='10'/>
</memballoon>
</devices>
</domain>

View File

@ -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,