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

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



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                | 64 ++++++++++++++++++++++++++++++++++++++++++++
 src/libvirt_public.syms      |  5 ++++
 4 files changed, 78 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index b87255a..32c36f1 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                     virDomainSetMemoryStatsPeriod (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..da03021 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -207,6 +207,11 @@ typedef int
                               unsigned int flags);
 
 typedef int
+(*virDrvDomainSetMemoryStatsPeriod)(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;
+    virDrvDomainSetMemoryStatsPeriod domainSetMemoryStatsPeriod;
     virDrvDomainSetMemoryParameters domainSetMemoryParameters;
     virDrvDomainGetMemoryParameters domainGetMemoryParameters;
     virDrvDomainSetNumaParameters domainSetNumaParameters;
diff --git a/src/libvirt.c b/src/libvirt.c
index 4dc91d7..0cdac0d 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -3781,6 +3781,70 @@ error:
     return -1;
 }
 
+/**
+ * virDomainSetMemoryStatsPeriod:
+ * @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
+virDomainSetMemoryStatsPeriod(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->domainSetMemoryStatsPeriod) {
+        int ret;
+        ret = conn->driver->domainSetMemoryStatsPeriod(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..4be5104 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:
+        virDomainSetMemoryStatsPeriod;
+} LIBVIRT_1.1.0;
+
 # .... define new API here using predicted next version number ....
-- 
1.8.1.4


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