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

[libvirt] [PATCH 4/6] remote-driver: Add domainMemoryStats support



Use a dynamically sized xdr_array to pass memory stats on the wire.  This
supports the addition of future memory stats and reduces the message size since
only supported statistics are returned.

Signed-off-by: Adam Litke <agl us ibm com>
To: Daniel Veillard <veillard redhat com>
Cc: Daniel P. Berrange <berrange redhat com>
Cc: libvirt list <libvir-list redhat com>
---
 daemon/remote.c              |   56 ++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   45 +++++++++++++++++++++++++++++++++-
 src/remote/remote_protocol.x |   21 +++++++++++++++-
 3 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 7a43046..8658d6e 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -708,6 +708,62 @@ remoteDispatchDomainInterfaceStats (struct qemud_server *server ATTRIBUTE_UNUSED
 }
 
 static int
+remoteDispatchDomainMemoryStats (struct qemud_server *server ATTRIBUTE_UNUSED,
+                                 struct qemud_client *client ATTRIBUTE_UNUSED,
+                                 virConnectPtr conn,
+                                 remote_message_header *hdr ATTRIBUTE_UNUSED,
+                                 remote_error *rerr,
+                                 remote_domain_memory_stats_args *args,
+                                 remote_domain_memory_stats_ret *ret)
+{
+    virDomainPtr dom;
+    struct _virDomainMemoryStat *stats;
+    unsigned int nr_stats, i;
+
+    if (args->maxStats > REMOTE_DOMAIN_MEMORY_STATS_MAX) {
+        remoteDispatchFormatError (rerr, "%s",
+                               _("maxStats > REMOTE_DOMAIN_MEMORY_STATS_MAX"));
+        return -1;
+    }
+
+    dom = get_nonnull_domain (conn, args->dom);
+    if (dom == NULL) {
+        remoteDispatchConnError(rerr, conn);
+        return -1;
+    }
+
+    /* Allocate stats array for making dispatch call */
+    if (VIR_ALLOC_N(stats, args->maxStats) < 0) {
+        remoteDispatchOOMError(rerr);
+        return -1;
+     }
+
+    nr_stats = virDomainMemoryStats (dom, stats, args->maxStats, 0);
+    virDomainFree (dom);
+    if (nr_stats == -1) {
+        VIR_FREE(stats);
+        remoteDispatchConnError(rerr, conn);
+        return -1;
+    }
+
+    /* Allocate return buffer */
+    if (VIR_ALLOC_N(ret->stats.stats_val, args->maxStats) < 0) {
+        VIR_FREE(stats);
+        remoteDispatchOOMError(rerr);
+        return -1;
+    }
+
+    /* Copy the stats into the xdr return structure */
+    for (i = 0; i < nr_stats; i++) {
+        ret->stats.stats_val[i].tag = stats[i].tag;
+        ret->stats.stats_val[i].val = stats[i].val;
+    }
+    ret->stats.stats_len = nr_stats;
+    VIR_FREE(stats);
+    return 0;
+}
+
+static int
 remoteDispatchDomainBlockPeek (struct qemud_server *server ATTRIBUTE_UNUSED,
                                struct qemud_client *client ATTRIBUTE_UNUSED,
                                virConnectPtr conn,
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 5d32d3b..bd78984 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3366,6 +3366,49 @@ done:
 }
 
 static int
+remoteDomainMemoryStats (virDomainPtr domain,
+                         struct _virDomainMemoryStat *stats,
+                         unsigned int nr_stats)
+{
+    int rv = -1;
+    remote_domain_memory_stats_args args;
+    remote_domain_memory_stats_ret ret;
+    struct private_data *priv = domain->conn->privateData;
+    unsigned int i;
+
+    remoteDriverLock(priv);
+
+    make_nonnull_domain (&args.dom, domain);
+    if (nr_stats > REMOTE_DOMAIN_MEMORY_STATS_MAX) {
+        errorf (domain->conn, VIR_ERR_RPC,
+                _("too many memory stats requested: %d > %d"), nr_stats,
+                REMOTE_DOMAIN_MEMORY_STATS_MAX);
+        goto done;
+    }
+    args.maxStats = nr_stats;
+    args.flags = 0;
+    memset (&ret, 0, sizeof ret);
+
+    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_MEMORY_STATS,
+              (xdrproc_t) xdr_remote_domain_memory_stats_args,
+                (char *) &args,
+              (xdrproc_t) xdr_remote_domain_memory_stats_ret,
+                (char *) &ret) == -1)
+        goto done;
+
+    for (i = 0; i < ret.stats.stats_len; i++) {
+        stats[i].tag = ret.stats.stats_val[i].tag;
+        stats[i].val = ret.stats.stats_val[i].val;
+    }
+    rv = ret.stats.stats_len;
+    xdr_free((xdrproc_t) xdr_remote_domain_memory_stats_ret, (char *) &ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
+static int
 remoteDomainBlockPeek (virDomainPtr domain,
                        const char *path,
                        unsigned long long offset,
@@ -8814,7 +8857,7 @@ static virDriver remote_driver = {
     remoteDomainMigrateFinish, /* domainMigrateFinish */
     remoteDomainBlockStats, /* domainBlockStats */
     remoteDomainInterfaceStats, /* domainInterfaceStats */
-    NULL, /* domainMemoryStats */
+    remoteDomainMemoryStats, /* domainMemoryStats */
     remoteDomainBlockPeek, /* domainBlockPeek */
     remoteDomainMemoryPeek, /* domainMemoryPeek */
     remoteNodeGetCellsFreeMemory, /* nodeGetCellsFreeMemory */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 92f7010..d9d0fbc 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -115,6 +115,9 @@ const REMOTE_AUTH_SASL_DATA_MAX = 65536;
 /* Maximum number of auth types */
 const REMOTE_AUTH_TYPE_LIST_MAX = 20;
 
+/* Upper limit on list of memory stats */
+const REMOTE_DOMAIN_MEMORY_STATS_MAX = 1024;
+
 /* Maximum length of a block peek buffer message.
  * Note applications need to be aware of this limit and issue multiple
  * requests for large amounts of data.
@@ -405,6 +408,21 @@ struct remote_domain_interface_stats_ret {
     hyper tx_drop;
 };
 
+struct remote_domain_memory_stats_args {
+        remote_nonnull_domain dom;
+        u_int maxStats;
+        u_int flags;
+};
+
+struct remote_domain_memory_stat {
+    int tag;
+    unsigned hyper val;
+};
+
+struct remote_domain_memory_stats_ret {
+    remote_domain_memory_stat stats<REMOTE_DOMAIN_MEMORY_STATS_MAX>;
+};
+
 struct remote_domain_block_peek_args {
     remote_nonnull_domain dom;
     remote_nonnull_string path;
@@ -1611,7 +1629,8 @@ enum remote_procedure {
     REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154,
     REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155,
     REMOTE_PROC_INTERFACE_IS_ACTIVE = 156,
-    REMOTE_PROC_GET_LIB_VERSION = 157
+    REMOTE_PROC_GET_LIB_VERSION = 157,
+    REMOTE_PROC_DOMAIN_MEMORY_STATS = 158
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
-- 
1.6.5


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