[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: libvirt list <libvir-list redhat com>
---
 daemon/remote.c              |   56 ++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   44 ++++++++++++++++++++++++++++++++-
 src/remote/remote_protocol.c |   22 ++++++++++++++++
 src/remote/remote_protocol.h |   22 ++++++++++++++++
 src/remote/remote_protocol.x |   16 +++++++++++-
 5 files changed, 158 insertions(+), 2 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 4296fc3..0083c1a 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -688,6 +688,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);
+    virDomainFree (dom);
+    if (nr_stats == -1) {
+        VIR_FREE(stats);
+        remoteDispatchConnError(rerr, conn);
+        return -1;
+    }
+
+    /* Allocate return buffer.  We need 2 slots per stat: the tag and value. */
+    if (VIR_ALLOC_N(ret->stats.stats_val, nr_stats * 2) < 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[2 * i] = (uint64_t) stats[i].tag;
+        ret->stats.stats_val[2 * i + 1] = stats[i].val;
+    }
+    ret->stats.stats_len = nr_stats * 2;
+    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 9ad47ad..38311d8 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3208,6 +3208,48 @@ 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;
+    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 / 2; i++) {
+        stats[i].tag = (unsigned int) ret.stats.stats_val[i * 2];
+        stats[i].val = ret.stats.stats_val[i * 2 + 1];
+    }
+    rv = ret.stats.stats_len / 2;
+    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,
@@ -8437,7 +8479,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.c b/src/remote/remote_protocol.c
index 1449ed4..8f65c26 100644
--- a/src/remote/remote_protocol.c
+++ b/src/remote/remote_protocol.c
@@ -588,6 +588,28 @@ xdr_remote_domain_interface_stats_ret (XDR *xdrs, remote_domain_interface_stats_
 }
 
 bool_t
+xdr_remote_domain_memory_stats_args (XDR *xdrs, remote_domain_memory_stats_args *objp)
+{
+        if (!xdr_remote_nonnull_domain (xdrs, &objp->dom))
+                return FALSE;
+        if (!xdr_u_int (xdrs, &objp->maxStats))
+                return FALSE;
+        return TRUE;
+}
+
+bool_t
+xdr_remote_domain_memory_stats_ret (XDR *xdrs, remote_domain_memory_stats_ret *objp)
+{
+        char **objp_cpp0 = (char **) (void *) &objp->stats.stats_val;
+
+        if (!xdr_array (xdrs, objp_cpp0, (u_int *) &objp->stats.stats_len,
+                        REMOTE_DOMAIN_MEMORY_STATS_MAX_ARRAY_SIZE,
+                        sizeof (uint64_t), (xdrproc_t) xdr_uint64_t))
+                return FALSE;
+        return TRUE;
+}
+
+bool_t
 xdr_remote_domain_block_peek_args (XDR *xdrs, remote_domain_block_peek_args *objp)
 {
 
diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h
index d87e8bc..3a4a790 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -40,6 +40,9 @@ typedef remote_nonnull_string *remote_string;
 #define REMOTE_NODE_MAX_CELLS 1024
 #define REMOTE_AUTH_SASL_DATA_MAX 65536
 #define REMOTE_AUTH_TYPE_LIST_MAX 20
+#define REMOTE_DOMAIN_MEMORY_STATS_MAX 1024
+#define REMOTE_DOMAIN_MEMORY_STATS_MAX_ARRAY_SIZE \
+            (REMOTE_DOMAIN_MEMORY_STATS_MAX * 2)
 #define REMOTE_DOMAIN_BLOCK_PEEK_BUFFER_MAX 65536
 #define REMOTE_DOMAIN_MEMORY_PEEK_BUFFER_MAX 65536
 #define REMOTE_SECURITY_MODEL_MAX VIR_SECURITY_MODEL_BUFLEN
@@ -302,6 +305,20 @@ struct remote_domain_interface_stats_ret {
 };
 typedef struct remote_domain_interface_stats_ret remote_domain_interface_stats_ret;
 
+struct remote_domain_memory_stats_args {
+        remote_nonnull_domain dom;
+        u_int maxStats;
+};
+typedef struct remote_domain_memory_stats_args remote_domain_memory_stats_args;
+
+struct remote_domain_memory_stats_ret {
+        struct {
+                u_int stats_len;
+                uint64_t *stats_val;
+        } stats;
+};
+typedef struct remote_domain_memory_stats_ret remote_domain_memory_stats_ret;
+
 struct remote_domain_block_peek_args {
         remote_nonnull_domain dom;
         remote_nonnull_string path;
@@ -1689,6 +1706,7 @@ enum remote_procedure {
         REMOTE_PROC_SECRET_UNDEFINE = 146,
         REMOTE_PROC_SECRET_LOOKUP_BY_USAGE = 147,
         REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL = 148,
+        REMOTE_PROC_DOMAIN_MEMORY_STATS = 149,
 };
 typedef enum remote_procedure remote_procedure;
 
@@ -1764,6 +1782,8 @@ extern  bool_t xdr_remote_domain_block_stats_args (XDR *, remote_domain_block_st
 extern  bool_t xdr_remote_domain_block_stats_ret (XDR *, remote_domain_block_stats_ret*);
 extern  bool_t xdr_remote_domain_interface_stats_args (XDR *, remote_domain_interface_stats_args*);
 extern  bool_t xdr_remote_domain_interface_stats_ret (XDR *, remote_domain_interface_stats_ret*);
+extern bool_t xdr_remote_domain_memory_stats_args (XDR *, remote_domain_memory_stats_args*);
+extern bool_t xdr_remote_domain_memory_stats_ret (XDR *, remote_domain_memory_stats_ret*);
 extern  bool_t xdr_remote_domain_block_peek_args (XDR *, remote_domain_block_peek_args*);
 extern  bool_t xdr_remote_domain_block_peek_ret (XDR *, remote_domain_block_peek_ret*);
 extern  bool_t xdr_remote_domain_memory_peek_args (XDR *, remote_domain_memory_peek_args*);
@@ -2019,6 +2039,8 @@ extern bool_t xdr_remote_domain_block_stats_args ();
 extern bool_t xdr_remote_domain_block_stats_ret ();
 extern bool_t xdr_remote_domain_interface_stats_args ();
 extern bool_t xdr_remote_domain_interface_stats_ret ();
+extern bool_t xdr_remote_domain_memory_stats_args ();
+extern bool_t xdr_remote_domain_memory_stats_ret ();
 extern bool_t xdr_remote_domain_block_peek_args ();
 extern bool_t xdr_remote_domain_block_peek_ret ();
 extern bool_t xdr_remote_domain_memory_peek_args ();
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 2b3c03b..263edd8 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -401,6 +401,18 @@ struct remote_domain_interface_stats_ret {
     hyper tx_drop;
 };
 
+struct remote_domain_memory_stats_args {
+        remote_nonnull_domain dom;
+        u_int maxStats;
+};
+
+struct remote_domain_memory_stats_ret {
+        struct {
+                u_int stats_len;
+                uint64_t *stats_val;
+        } stats;
+};
+
 struct remote_domain_block_peek_args {
     remote_nonnull_domain dom;
     remote_nonnull_string path;
@@ -1532,7 +1544,9 @@ enum remote_procedure {
     REMOTE_PROC_SECRET_UNDEFINE = 146,
     REMOTE_PROC_SECRET_LOOKUP_BY_USAGE = 147,
 
-    REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL = 148
+    REMOTE_PROC_DOMAIN_MIGRATE_PREPARE_TUNNEL = 148,
+
+    REMOTE_PROC_DOMAIN_MEMORY_STATS = 149,
 };
 
 
-- 
1.6.5


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