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

[libvirt] [PATCH 2/4 V2] remote: mplement new API virDomainGetPcpusUsage for remote driver



Signed-off-by: Lai Jiangshan <laijs cn fujitsu com>
---
 daemon/remote.c              |   68 ++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   51 +++++++++++++++++++++++++++++++
 src/remote/remote_protocol.x |   17 ++++++++++-
 src/remote_protocol-structs  |   13 ++++++++
 4 files changed, 148 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index a28a754..9b0206f 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2084,6 +2084,74 @@ cleanup:
     return rv;
 }
 
+static int
+remoteDispatchDomainGetPcpusUsage(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                  virNetServerClientPtr client ATTRIBUTE_UNUSED,
+                                  virNetMessagePtr hdr ATTRIBUTE_UNUSED,
+                                  virNetMessageErrorPtr rerr,
+                                  remote_domain_get_pcpus_usage_args *args,
+                                  remote_domain_get_pcpus_usage_ret *ret)
+{
+    int i;
+    virDomainPtr dom = NULL;
+    int rv = -1;
+    unsigned long long *usages;
+    int nr_usages = args->nr_usages;
+    struct daemonClientPrivate *priv =
+        virNetServerClientGetPrivateData(client);
+
+    if (!priv->conn) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if (nr_usages > REMOTE_DOMAIN_PCPUS_USAGE_PARAMETERS_MAX) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("nr_usages too large"));
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC_N(usages, nr_usages) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    if (!(dom = get_nonnull_domain(priv->conn, args->dom)))
+        goto cleanup;
+
+    if (virDomainGetPcpusUsage(dom, usages, &nr_usages, args->flags) < 0)
+        goto cleanup;
+
+    ret->nr_usages = nr_usages;
+
+    /*
+     * In this case, we need to send back the number of parameters
+     * supported
+     */
+    if (args->nr_usages == 0) {
+        goto success;
+    }
+
+    ret->usages.usages_len = MIN(args->nr_usages, nr_usages);
+    if (VIR_ALLOC_N(ret->usages.usages_val, ret->usages.usages_len) < 0) {
+        virReportOOMError();
+        goto cleanup;
+    }
+
+    for (i = 0; i < ret->usages.usages_len; i++) {
+        ret->usages.usages_val[i] = usages[i];
+    }
+
+success:
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    VIR_FREE(usages);
+    if (dom)
+        virDomainFree(dom);
+    return rv;
+}
 
 #ifdef HAVE_SASL
 /*
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 7580477..7dd3876 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2305,6 +2305,56 @@ done:
     return rv;
 }
 
+static int remoteDomainGetPcpusUsage(virDomainPtr domain,
+                                     unsigned long long *usages,
+                                     int *nr_usages,
+                                     unsigned int flags)
+{
+    int i;
+    int rv = -1;
+    remote_domain_get_pcpus_usage_args args;
+    remote_domain_get_pcpus_usage_ret ret;
+    struct private_data *priv = domain->conn->privateData;
+
+    remoteDriverLock(priv);
+
+    make_nonnull_domain(&args.dom, domain);
+    args.nr_usages = *nr_usages;
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+
+    if (call(domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_PCPUS_USAGE,
+             (xdrproc_t) xdr_remote_domain_get_pcpus_usage_args,
+               (char *) &args,
+             (xdrproc_t) xdr_remote_domain_get_pcpus_usage_ret,
+               (char *) &ret) == -1) {
+        goto done;
+    }
+
+    /* Handle the case when the caller does not know the number of parameters
+     * and is asking for the number of parameters supported
+     */
+    if (*nr_usages == 0) {
+        *nr_usages = ret.nr_usages;
+        goto cleanup;
+    }
+
+    for (i = 0; i < MIN(*nr_usages, ret.usages.usages_len); i++) {
+        usages[i] = ret.usages.usages_val[i];
+    }
+    *nr_usages = ret.nr_usages;
+
+    rv = 0;
+
+cleanup:
+    xdr_free ((xdrproc_t) xdr_remote_domain_get_pcpus_usage_ret,
+              (char *) &ret);
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 /*----------------------------------------------------------------------*/
 
 static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
@@ -4739,6 +4789,7 @@ static virDriver remote_driver = {
     .domainGetBlockIoTune = remoteDomainGetBlockIoTune, /* 0.9.8 */
     .domainSetNumaParameters = remoteDomainSetNumaParameters, /* 0.9.9 */
     .domainGetNumaParameters = remoteDomainGetNumaParameters, /* 0.9.9 */
+    .domainGetPcpusUsage = remoteDomainGetPcpusUsage, /* 0.9.10 */
 };
 
 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index ca739ff..d38206d 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -131,6 +131,9 @@ const REMOTE_DOMAIN_BLOCK_IO_TUNE_PARAMETERS_MAX = 16;
 /* Upper limit on list of numa parameters. */
 const REMOTE_DOMAIN_NUMA_PARAMETERS_MAX = 16;
 
+/* Upper limit on list of physic cpu parameters. */
+const REMOTE_DOMAIN_PCPUS_USAGE_PARAMETERS_MAX = 16;
+
 /* Upper limit on list of node cpu stats. */
 const REMOTE_NODE_CPU_STATS_MAX = 16;
 
@@ -1148,6 +1151,17 @@ struct remote_domain_get_block_io_tune_ret {
     int nparams;
 };
 
+struct remote_domain_get_pcpus_usage_args {
+    remote_nonnull_domain dom;
+    int nr_usages;
+    unsigned int flags;
+};
+
+struct remote_domain_get_pcpus_usage_ret {
+    uint64_t usages<REMOTE_DOMAIN_PCPUS_USAGE_PARAMETERS_MAX>;
+    int nr_usages;
+};
+
 /* Network calls: */
 
 struct remote_num_of_networks_ret {
@@ -2653,7 +2667,8 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_SET_NUMA_PARAMETERS = 254, /* autogen autogen */
     REMOTE_PROC_DOMAIN_GET_NUMA_PARAMETERS = 255, /* skipgen skipgen */
     REMOTE_PROC_DOMAIN_SET_INTERFACE_PARAMETERS = 256, /* autogen autogen */
-    REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257 /* skipgen skipgen */
+    REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257, /* skipgen skipgen */
+    REMOTE_PROC_DOMAIN_GET_PCPUS_USAGE = 258 /* skipgen skipgen */
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 2758315..4fd7b6d 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1832,6 +1832,18 @@ struct remote_node_suspend_for_duration_args {
         uint64_t                   duration;
         u_int                      flags;
 };
+struct remote_domain_get_pcpus_usage_args {
+        remote_nonnull_domain      dom;
+        int                        nr_usages;
+        u_int                      flags;
+};
+struct remote_domain_get_pcpus_usage_ret {
+        struct {
+                u_int              usages_len;
+                unsigned long long *usages_val;
+        } usages;
+        int                        nr_usages;
+};
 enum remote_procedure {
         REMOTE_PROC_OPEN = 1,
         REMOTE_PROC_CLOSE = 2,
@@ -2090,4 +2102,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_GET_NUMA_PARAMETERS = 255,
         REMOTE_PROC_DOMAIN_SET_INTERFACE_PARAMETERS = 256,
         REMOTE_PROC_DOMAIN_GET_INTERFACE_PARAMETERS = 257,
+        REMOTE_PROC_DOMAIN_GET_PCPU_USAGE = 258,
 };
-- 
1.7.4.4


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