]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Add 'period' for Memballoon statistics gathering capability
authorJohn Ferlan <jferlan@redhat.com>
Wed, 26 Jun 2013 11:00:00 +0000 (07:00 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 16 Jul 2013 12:44:52 +0000 (08:44 -0400)
Add a period in seconds to allow/enable statistics gathering from the
Balloon driver for 'virsh dommemstat <domain>'.

docs/formatdomain.html.in
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h
tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.args [new file with mode: 0644]
tests/qemuxml2argvdata/qemuxml2argv-balloon-device-period.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c

index d2dbcb8ca9d39a63f3ff8612aa15d08b56ec7823..a1cc1e10e7485531c5263acd43e2493626aa3c8c 100644 (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>
 
index c1355300a501cded520b5cc4b274c42be91065c9..7a6852b3779401f04c01cc5f591748b1bc629e24 100644 (file)
       <optional>
         <ref name="address"/>
       </optional>
+      <optional>
+        <element name="stats">
+          <attribute name="period">
+            <ref name="positiveInteger"/>
+          </attribute>
+        </element>
+      </optional>
     </element>
   </define>
   <define name="parallel">
index 5f7ef1952dc7db7045d423567213d3347afd32cc..44be81e2040e00b16e04d3b9048511c8f547f4c8 100644 (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;
 }
 
index c26f4e2a44a5688f98d6ef5a1e12cd8c882b3673..b14afd9a3c07412cf11d357149af215f877ec175 100644 (file)
@@ -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 (file)
index 0000000..48af1c4
--- /dev/null
@@ -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 (file)
index 0000000..c47c9bf
--- /dev/null
@@ -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>
index 7d7332f8e3c7963aa52796e632fa6173de515c11..0f96eef91e069b317a77228490e34f96e89d50e7 100644 (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,