[PATCH v2 04/10] Add 'period' for Memballoon statistics gathering capability

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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        | 44 +++++++++++++++++++++++++++++++++++++------
 src/conf/domain_conf.h        |  1 +
 4 files changed, 56 insertions(+), 6 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
   &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>
@@ -4654,6 +4655,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>
 
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 402e6e9..d63b735 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8595,10 +8595,14 @@ error:
 
 static virDomainMemballoonDefPtr
 virDomainMemballoonDefParseXML(const xmlNodePtr node,
+                               xmlXPathContextPtr ctxt,
                                unsigned int flags)
 {
     char *model;
     virDomainMemballoonDefPtr def;
+    xmlNodePtr save = ctxt->node;
+    int period = -1;
+    int ret;
 
     if (VIR_ALLOC(def) < 0) {
         virReportOOMError();
@@ -8607,22 +8611,39 @@ virDomainMemballoonDefParseXML(const xmlNodePtr node,
 
     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;
+    ret = virXPathInt("string(./stats/@period)", ctxt, &period);
+    if (ret == -2) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("period value not a valid integer"));
+        goto error;
+    } else if (ret == 0) {
+        if (period < 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("period value must be 0 or more"));
+            goto error;
+        }
+        def->period = period;
+    }
+
     if (virDomainDeviceInfoParseXML(node, NULL, &def->info, flags) < 0)
         goto error;
 
 cleanup:
     VIR_FREE(model);
 
+    ctxt->node = save;
     return def;
 
 error:
@@ -11991,7 +12012,7 @@ virDomainDefParseXML(xmlDocPtr xml,
     }
     if (n > 0) {
         virDomainMemballoonDefPtr memballoon =
-            virDomainMemballoonDefParseXML(nodes[0], flags);
+            virDomainMemballoonDefParseXML(nodes[0], ctxt, flags);
         if (!memballoon)
             goto error;
 
@@ -15192,6 +15213,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
                              unsigned int flags)
 {
     const char *model = virDomainMemballoonModelTypeToString(def->model);
+    bool noopts = true;
 
     if (!model) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -15205,11 +15227,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='%d'/>\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 da83eb6..a8eb1fe 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1533,6 +1533,7 @@ enum {
 struct _virDomainMemballoonDef {
     int model;
     virDomainDeviceInfo info;
+    int period; /* seconds between collections */
 };
 
 struct _virDomainNVRAMDef {
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]