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(a)us.ibm.com>
To: libvirt list <libvir-list(a)redhat.com>
Cc: Daniel Veillard <veillard(a)redhat.com>
Cc: Daniel P. Berrange <berrange(a)redhat.com>
---
daemon/remote.c | 56 ++++++++++++++++++++++++++++++++++++++++++
src/remote/remote_driver.c | 44 ++++++++++++++++++++++++++++++++-
src/remote/remote_protocol.c | 35 ++++++++++++++++++++++++++
src/remote/remote_protocol.h | 25 ++++++++++++++++++
src/remote/remote_protocol.x | 18 ++++++++++++-
5 files changed, 176 insertions(+), 2 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 7a43046..2066c49 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, 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[i].tag = stats[i].tag;
+ ret->stats[i].val = stats[i].val;
+ }
+ ret->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..384779d 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -3366,6 +3366,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.len; i++) {
+ stats[i].tag = ret.stats[i].tag;
+ stats[i].val = ret.stats[i].val;
+ }
+ rv = ret.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 +8856,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 a10558a..45510ae 100644
--- a/src/remote/remote_protocol.c
+++ b/src/remote/remote_protocol.c
@@ -597,6 +597,41 @@ 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_memory_stat (XDR *xdrs, remote_domain_memory_stat *objp)
+{
+ if (!xdr_int (xdrs, &objp->tag))
+ return FALSE;
+ if (!xdr_u_hyper (xdrs, &objp->val))
+ 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;
+
+ if (!xdr_u_int (xdrs, &objp->len))
+ return FALSE;
+ if (!xdr_array (xdrs, objp_cpp0, (u_int *) &objp->len,
+ REMOTE_DOMAIN_MEMORY_STATS_MAX,
+ sizeof (struct remote_domain_memory_stat),
+ (xdrproc_t) xdr_remote_memory_stat))
+ 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 2ba9be4..e7832ff 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -40,6 +40,7 @@ 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_BLOCK_PEEK_BUFFER_MAX 65536
#define REMOTE_DOMAIN_MEMORY_PEEK_BUFFER_MAX 65536
#define REMOTE_SECURITY_MODEL_MAX VIR_SECURITY_MODEL_BUFLEN
@@ -307,6 +308,24 @@ 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_stat {
+ int tag;
+ uint64_t val;
+};
+typedef struct remote_domain_memory_stat remote_domain_memory_stat;
+
+struct remote_domain_memory_stats_ret {
+ u_int len;
+ struct remote_domain_memory_stat *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;
@@ -1777,6 +1796,7 @@ enum remote_procedure {
REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155,
REMOTE_PROC_INTERFACE_IS_ACTIVE = 156,
REMOTE_PROC_GET_LIB_VERSION = 157,
+ REMOTE_PROC_DOMAIN_MEMORY_STATS = 158,
};
typedef enum remote_procedure remote_procedure;
@@ -1853,6 +1873,9 @@ 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_memory_stat (XDR *xdrs, remote_domain_memory_stat *objp);
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*);
@@ -2124,6 +2147,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 92f7010..36e7f73 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -405,6 +405,21 @@ 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_stat {
+ int tag;
+ unsigned hyper val;
+};
+
+struct remote_domain_memory_stats_ret {
+ u_int len;
+ remote_domain_memory_stat<REMOTE_DOMAIN_MEMORY_STATS_MAX>;
+};
+
struct remote_domain_block_peek_args {
remote_nonnull_domain dom;
remote_nonnull_string path;
@@ -1611,7 +1626,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