[PATCHv3 4/6] virNodeGetCPUTime: Implement remote protocol

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

 



virNodeGetCPUTime: Implement remote protocol

Signed-off-by: Minoru Usui <usui@xxxxxxxxxxxxxxxxx>
---
 daemon/remote.c                     |   46 +++++++++++++++++++++++++++++++++++
 daemon/remote_dispatch_args.h       |    1 +
 daemon/remote_dispatch_prototypes.h |    8 ++++++
 daemon/remote_dispatch_ret.h        |    1 +
 daemon/remote_dispatch_table.h      |    5 ++++
 src/remote/remote_driver.c          |   36 +++++++++++++++++++++++++++
 src/remote/remote_protocol.c        |   22 ++++++++++++++++
 src/remote/remote_protocol.h        |   20 +++++++++++++++
 src/remote/remote_protocol.x        |   15 ++++++++++-
 src/remote_protocol-structs         |   10 +++++++
 10 files changed, 163 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 5de1055..5cd5e6c 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -764,6 +764,52 @@ remoteDispatchNodeGetCellsFreeMemory(struct qemud_server *server ATTRIBUTE_UNUSE
     return 0;
 }
 
+static int
+remoteDispatchNodeGetCpuTime (struct qemud_server *server ATTRIBUTE_UNUSED,
+                              struct qemud_client *client ATTRIBUTE_UNUSED,
+                              virConnectPtr conn,
+                              remote_message_header *hdr ATTRIBUTE_UNUSED,
+                              remote_error *rerr,
+                              remote_node_get_cpu_time_args *args,
+                              remote_node_get_cpu_time_ret *ret)
+{
+    unsigned long long *stats;
+    unsigned int nr_stats, i;
+
+    if (args->maxStats > REMOTE_NODE_CPU_TIME_MAX) {
+        remoteDispatchFormatError (rerr, "%s",
+                                   _("maxStats > REMOTE_NODE_CPU_TIME_MAX"));
+        return -1;
+    }
+
+    /* Allocate stats array for making dispatch call */
+    if (VIR_ALLOC_N(stats, args->maxStats) < 0) {
+        remoteDispatchOOMError(rerr);
+        return -1;
+    }
+
+    nr_stats = virNodeGetCpuTime (conn, stats, args->maxStats, args->flags);
+    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] = stats[i];
+
+    ret->stats.stats_len = nr_stats;
+    VIR_FREE(stats);
+    return 0;
+}
 
 static int
 remoteDispatchNodeGetFreeMemory(struct qemud_server *server ATTRIBUTE_UNUSED,
diff --git a/daemon/remote_dispatch_args.h b/daemon/remote_dispatch_args.h
index f9537d7..a757899 100644
--- a/daemon/remote_dispatch_args.h
+++ b/daemon/remote_dispatch_args.h
@@ -178,3 +178,4 @@
     remote_domain_migrate_set_max_speed_args val_remote_domain_migrate_set_max_speed_args;
     remote_storage_vol_upload_args val_remote_storage_vol_upload_args;
     remote_storage_vol_download_args val_remote_storage_vol_download_args;
+    remote_node_get_cpu_time_args val_remote_node_get_cpu_time_args;
diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h
index 18bf41d..936ba23 100644
--- a/daemon/remote_dispatch_prototypes.h
+++ b/daemon/remote_dispatch_prototypes.h
@@ -1138,6 +1138,14 @@ static int remoteDispatchNodeGetCellsFreeMemory(
     remote_error *err,
     remote_node_get_cells_free_memory_args *args,
     remote_node_get_cells_free_memory_ret *ret);
+static int remoteDispatchNodeGetCpuTime(
+    struct qemud_server *server,
+    struct qemud_client *client,
+    virConnectPtr conn,
+    remote_message_header *hdr,
+    remote_error *err,
+    remote_node_get_cpu_time_args *args,
+    remote_node_get_cpu_time_ret *ret);
 static int remoteDispatchNodeGetFreeMemory(
     struct qemud_server *server,
     struct qemud_client *client,
diff --git a/daemon/remote_dispatch_ret.h b/daemon/remote_dispatch_ret.h
index 114e832..dfed98b 100644
--- a/daemon/remote_dispatch_ret.h
+++ b/daemon/remote_dispatch_ret.h
@@ -140,3 +140,4 @@
     remote_domain_is_updated_ret val_remote_domain_is_updated_ret;
     remote_get_sysinfo_ret val_remote_get_sysinfo_ret;
     remote_domain_get_blkio_parameters_ret val_remote_domain_get_blkio_parameters_ret;
+    remote_node_get_cpu_time_ret val_remote_node_get_cpu_time_ret;
diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h
index b39f7c2..5922d56 100644
--- a/daemon/remote_dispatch_table.h
+++ b/daemon/remote_dispatch_table.h
@@ -1052,3 +1052,8 @@
     .args_filter = (xdrproc_t) xdr_remote_storage_vol_download_args,
     .ret_filter = (xdrproc_t) xdr_void,
 },
+{   /* NodeGetCpuTime => 210 */
+    .fn = (dispatch_fn) remoteDispatchNodeGetCpuTime,
+    .args_filter = (xdrproc_t) xdr_remote_node_get_cpu_time_args,
+    .ret_filter = (xdrproc_t) xdr_remote_node_get_cpu_time_ret,
+},
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index ff48fa2..7bfa747 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1938,6 +1938,42 @@ done:
 }
 
 static int
+remoteNodeGetCpuTime (virConnectPtr conn,
+                      unsigned long long *stats,
+                      unsigned int nr_stats,
+                      unsigned int flags)
+{
+    int rv = -1;
+    remote_node_get_cpu_time_args args;
+    remote_node_get_cpu_time_ret ret;
+    struct private_data *priv = conn->privateData;
+    unsigned int i;
+
+    remoteDriverLock(priv);
+
+    args.maxStats = nr_stats;
+    args.flags = flags;
+    memset (&ret, 0, sizeof ret);
+
+    if (call (conn, priv, 0, REMOTE_PROC_NODE_GET_CPU_TIME,
+              (xdrproc_t) xdr_remote_node_get_cpu_time_args,
+                (char *) &args,
+              (xdrproc_t) xdr_remote_node_get_cpu_time_ret,
+                (char *) &ret) == -1)
+        goto done;
+
+    for (i = 0; i < ret.stats.stats_len; i++)
+        stats[i] = ret.stats.stats_val[i];
+
+    rv = ret.stats.stats_len;
+    xdr_free((xdrproc_t) xdr_remote_node_get_cpu_time_ret, (char *) &ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
+static int
 remoteNodeGetCellsFreeMemory(virConnectPtr conn,
                             unsigned long long *freeMems,
                             int startCell,
diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c
index 5604371..a5c658a 100644
--- a/src/remote/remote_protocol.c
+++ b/src/remote/remote_protocol.c
@@ -607,6 +607,28 @@ xdr_remote_get_capabilities_ret (XDR *xdrs, remote_get_capabilities_ret *objp)
 }
 
 bool_t
+xdr_remote_node_get_cpu_time_args (XDR *xdrs, remote_node_get_cpu_time_args *objp)
+{
+
+         if (!xdr_u_int (xdrs, &objp->maxStats))
+                 return FALSE;
+         if (!xdr_u_int (xdrs, &objp->flags))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
+xdr_remote_node_get_cpu_time_ret (XDR *xdrs, remote_node_get_cpu_time_ret *objp)
+{
+        char **objp_cpp0 = (char **) (void *) &objp->stats.stats_val;
+
+         if (!xdr_array (xdrs, objp_cpp0, (u_int *) &objp->stats.stats_len, REMOTE_NODE_CPU_TIME_MAX,
+                sizeof (uint64_t), (xdrproc_t) xdr_uint64_t))
+                 return FALSE;
+        return TRUE;
+}
+
+bool_t
 xdr_remote_node_get_cells_free_memory_args (XDR *xdrs, remote_node_get_cells_free_memory_args *objp)
 {
 
diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h
index d9bf151..b254919 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -55,6 +55,7 @@ typedef remote_nonnull_string *remote_string;
 #define REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX 16
 #define REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX 16
 #define REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX 16
+#define REMOTE_NODE_CPU_TIME_MAX 8
 #define REMOTE_NODE_MAX_CELLS 1024
 #define REMOTE_AUTH_SASL_DATA_MAX 65536
 #define REMOTE_AUTH_TYPE_LIST_MAX 20
@@ -304,6 +305,20 @@ struct remote_get_capabilities_ret {
 };
 typedef struct remote_get_capabilities_ret remote_get_capabilities_ret;
 
+struct remote_node_get_cpu_time_args {
+        u_int maxStats;
+        u_int flags;
+};
+typedef struct remote_node_get_cpu_time_args remote_node_get_cpu_time_args;
+
+struct remote_node_get_cpu_time_ret {
+        struct {
+                u_int stats_len;
+                uint64_t *stats_val;
+        } stats;
+};
+typedef struct remote_node_get_cpu_time_ret remote_node_get_cpu_time_ret;
+
 struct remote_node_get_cells_free_memory_args {
         int startCell;
         int maxCells;
@@ -2413,6 +2428,7 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207,
         REMOTE_PROC_STORAGE_VOL_UPLOAD = 208,
         REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 209,
+        REMOTE_PROC_NODE_GET_CPU_TIME = 210,
 };
 typedef enum remote_procedure remote_procedure;
 
@@ -2486,6 +2502,8 @@ extern  bool_t xdr_remote_get_max_vcpus_args (XDR *, remote_get_max_vcpus_args*)
 extern  bool_t xdr_remote_get_max_vcpus_ret (XDR *, remote_get_max_vcpus_ret*);
 extern  bool_t xdr_remote_node_get_info_ret (XDR *, remote_node_get_info_ret*);
 extern  bool_t xdr_remote_get_capabilities_ret (XDR *, remote_get_capabilities_ret*);
+extern  bool_t xdr_remote_node_get_cpu_time_args (XDR *, remote_node_get_cpu_time_args*);
+extern  bool_t xdr_remote_node_get_cpu_time_ret (XDR *, remote_node_get_cpu_time_ret*);
 extern  bool_t xdr_remote_node_get_cells_free_memory_args (XDR *, remote_node_get_cells_free_memory_args*);
 extern  bool_t xdr_remote_node_get_cells_free_memory_ret (XDR *, remote_node_get_cells_free_memory_ret*);
 extern  bool_t xdr_remote_node_get_free_memory_ret (XDR *, remote_node_get_free_memory_ret*);
@@ -2843,6 +2861,8 @@ extern bool_t xdr_remote_get_max_vcpus_args ();
 extern bool_t xdr_remote_get_max_vcpus_ret ();
 extern bool_t xdr_remote_node_get_info_ret ();
 extern bool_t xdr_remote_get_capabilities_ret ();
+extern bool_t xdr_remote_node_get_cpu_time_args ();
+extern bool_t xdr_remote_node_get_cpu_time_ret ();
 extern bool_t xdr_remote_node_get_cells_free_memory_args ();
 extern bool_t xdr_remote_node_get_cells_free_memory_ret ();
 extern bool_t xdr_remote_node_get_free_memory_ret ();
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 675eccd..0e801c2 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -134,6 +134,9 @@ const REMOTE_DOMAIN_BLKIO_PARAMETERS_MAX = 16;
 /* Upper limit on list of memory parameters. */
 const REMOTE_DOMAIN_MEMORY_PARAMETERS_MAX = 16;
 
+/* Upper limit on list of cpu time stats. */
+const REMOTE_NODE_CPU_TIME_MAX = 8;
+
 /* Upper limit on number of NUMA cells */
 const REMOTE_NODE_MAX_CELLS = 1024;
 
@@ -440,6 +443,15 @@ struct remote_get_capabilities_ret {
     remote_nonnull_string capabilities;
 };
 
+struct remote_node_get_cpu_time_args {
+    u_int maxStats;
+    u_int flags;
+};
+
+struct remote_node_get_cpu_time_ret {
+    unsigned hyper stats<REMOTE_NODE_CPU_TIME_MAX>;
+};
+
 struct remote_node_get_cells_free_memory_args {
     int startCell;
     int maxCells;
@@ -2176,7 +2188,8 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_GET_BLKIO_PARAMETERS = 206,
     REMOTE_PROC_DOMAIN_MIGRATE_SET_MAX_SPEED = 207,
     REMOTE_PROC_STORAGE_VOL_UPLOAD = 208,
-    REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 209
+    REMOTE_PROC_STORAGE_VOL_DOWNLOAD = 209,
+    REMOTE_PROC_NODE_GET_CPU_TIME = 210
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 944553c..3c63695 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -151,6 +151,16 @@ struct remote_node_get_info_ret {
 struct remote_get_capabilities_ret {
         remote_nonnull_string      capabilities;
 };
+struct remote_node_get_cpu_time_args {
+        u_int maxStats;
+        u_int flags;
+};
+struct remote_node_get_cpu_time_ret {
+        struct {
+                u_int stats_len;
+                uint64_t *stats_val;
+        } stats;
+};
 struct remote_node_get_cells_free_memory_args {
         int                        startCell;
         int                        maxCells;
-- 
1.7.1


-- 
Minoru Usui <usui@xxxxxxxxxxxxxxxxx>

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]