[libvirt] [PATCH v2 07/10] Add new public API virDomainSetMemoryStatsPeriodFlags

John Ferlan jferlan at redhat.com
Mon Jul 8 19:20:33 UTC 2013


Add new API in order to set the balloon memory driver statistics collection
period in order to allow dynamic period adjustment for the virsh dommemstats to
display balloon stats data
---
 include/libvirt/libvirt.h.in |  3 ++
 src/driver.h                 |  6 ++++
 src/libvirt.c                | 65 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |  5 ++++
 4 files changed, 79 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index b87255a..069cac8 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1909,6 +1909,9 @@ int                     virDomainSetMemory      (virDomainPtr domain,
 int                     virDomainSetMemoryFlags (virDomainPtr domain,
                                                  unsigned long memory,
                                                  unsigned int flags);
+int                     virDomainSetMemoryStatsPeriodFlags (virDomainPtr domain,
+                                                            int period,
+                                                            unsigned int flags);
 int                     virDomainGetMaxVcpus    (virDomainPtr domain);
 int                     virDomainGetSecurityLabel (virDomainPtr domain,
                                                    virSecurityLabelPtr seclabel);
diff --git a/src/driver.h b/src/driver.h
index 31851cb..a8964e9 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -207,6 +207,11 @@ typedef int
                               unsigned int flags);
 
 typedef int
+(*virDrvDomainSetMemoryStatsPeriodFlags)(virDomainPtr domain,
+                                         int period,
+                                         unsigned int flags);
+
+typedef int
 (*virDrvDomainSetMemoryParameters)(virDomainPtr domain,
                                    virTypedParameterPtr params,
                                    int nparams,
@@ -1158,6 +1163,7 @@ struct _virDriver {
     virDrvDomainSetMaxMemory domainSetMaxMemory;
     virDrvDomainSetMemory domainSetMemory;
     virDrvDomainSetMemoryFlags domainSetMemoryFlags;
+    virDrvDomainSetMemoryStatsPeriodFlags domainSetMemoryStatsPeriodFlags;
     virDrvDomainSetMemoryParameters domainSetMemoryParameters;
     virDrvDomainGetMemoryParameters domainGetMemoryParameters;
     virDrvDomainSetNumaParameters domainSetNumaParameters;
diff --git a/src/libvirt.c b/src/libvirt.c
index 8e19c64..e02ef09 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3782,6 +3782,71 @@ error:
     return -1;
 }
 
+/**
+ * virDomainSetMemoryStatsPeriodFlags:
+ * @domain: a domain object or NULL
+ * @period: the period in seconds for stats collection
+ * @flags: bitwise-OR of virDomainMemoryModFlags
+ *
+ * Dynamically change the domain memory balloon driver statistics collection
+ * period. Use 0 to disable and a positive value to enable.
+ *
+ * @flags may include VIR_DOMAIN_AFFECT_LIVE or VIR_DOMAIN_AFFECT_CONFIG.
+ * Both flags may be set. If VIR_DOMAIN_AFFECT_LIVE is set, the change affects
+ * a running domain and will fail if domain is not active.
+ * If VIR_DOMAIN_AFFECT_CONFIG is set, the change affects persistent state,
+ * and will fail for transient domains. If neither flag is specified
+ * (that is, @flags is VIR_DOMAIN_AFFECT_CURRENT), then an inactive domain
+ * modifies persistent setup, while an active domain is hypervisor-dependent
+ * on whether just live or both live and persistent state is changed.
+ *
+ * Not all hypervisors can support all flag combinations.
+ *
+ * Returns 0 in case of success, -1 in case of failure.
+ */
+
+int
+virDomainSetMemoryStatsPeriodFlags(virDomainPtr domain, int period,
+                                   unsigned int flags)
+{
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "peroid=%d, flags=%x", period, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+
+    if (domain->conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+
+    /* This must be positive to set the balloon collection period */
+    virCheckNonNegativeArgGoto(period, error);
+
+    conn = domain->conn;
+
+    if (conn->driver->domainSetMemoryStatsPeriodFlags) {
+        int ret;
+        ret = conn->driver->domainSetMemoryStatsPeriodFlags(domain, period,
+                                                            flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
 /* Helper function called to validate incoming client array on any
  * interface that sets typed parameters in the hypervisor.  */
 static int
diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms
index 7c6edf6..d4e4834 100644
--- a/src/libvirt_public.syms
+++ b/src/libvirt_public.syms
@@ -627,4 +627,9 @@ LIBVIRT_1.1.0 {
         virDomainMigrateToURI3;
 } LIBVIRT_1.0.6;
 
+LIBVIRT_1.1.1 {
+    global:
+        virDomainSetMemoryStatsPeriodFlags;
+} LIBVIRT_1.1.0;
+
 # .... define new API here using predicted next version number ....
-- 
1.8.1.4




More information about the libvir-list mailing list