[libvirt] [PATCHv3 04/12] remote: implement remote protocol for virConnectListAllDomains()

Peter Krempa pkrempa at redhat.com
Mon Jun 11 10:33:59 UTC 2012


This patch wires up the RPC protocol handlers for
virConnectListAllDomains(). The RPC generator has no support for the way
how virConnectListAllDomains() returns the results so the handler code
had to be done manually.

The new api is handled by REMOTE_PROC_CONNECT_LIST_ALL_DOMAINS, with
number 271 and marked with high priority.
---
Diff to v2:
- fixed spelling and style nits
- changed the boolean flag that tells the remote side if the list is needed to ing
- fixed returning of the correct count if no list is requested (I didn't fill and use ret.ret)
---
 daemon/remote.c              |   54 +++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   64 ++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_protocol.x |   14 ++++++++-
 src/remote_protocol-structs  |   12 ++++++++
 4 files changed, 143 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index a02c09b..8dd5a4f 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -996,6 +996,60 @@ no_memory:
 }

 static int
+remoteDispatchConnectListAllDomains(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                    virNetServerClientPtr client,
+                                    virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                    virNetMessageErrorPtr rerr,
+                                    remote_connect_list_all_domains_args *args,
+                                    remote_connect_list_all_domains_ret *ret)
+{
+    virDomainPtr *doms = NULL;
+    int ndomains = 0;
+    int i;
+    int rv = -1;
+    struct daemonClientPrivate *priv = virNetServerClientGetPrivateData(client);
+
+    if (!priv->conn) {
+        virNetError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if ((ndomains = virConnectListAllDomains(priv->conn,
+                                             args->need_results ? &doms : NULL,
+                                             args->flags)) < 0)
+        goto cleanup;
+
+    if (doms) {
+        if (VIR_ALLOC_N(ret->domains.domains_val, ndomains) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        ret->domains.domains_len = ndomains;
+
+        for (i = 0; i < ndomains; i++)
+            make_nonnull_domain(ret->domains.domains_val + i, doms[i]);
+    } else {
+        ret->domains.domains_len = 0;
+        ret->domains.domains_val = NULL;
+    }
+
+    ret->ret = ndomains;
+
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (doms) {
+        for (i = 0; i < ndomains; i++)
+            virDomainFree(doms[i]);
+        VIR_FREE(doms);
+    }
+    return rv;
+}
+
+static int
 remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE_UNUSED,
                                                 virNetServerClientPtr client ATTRIBUTE_UNUSED,
                                                 virNetMessagePtr msg ATTRIBUTE_UNUSED,
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 299cd69..53ddef3 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -1265,6 +1265,69 @@ done:
     return rv;
 }

+static int
+remoteConnectListAllDomains(virConnectPtr conn,
+                            virDomainPtr **domains,
+                            unsigned int flags)
+{
+    int rv = -1;
+    int i;
+    virDomainPtr *doms = NULL;
+    remote_connect_list_all_domains_args args;
+    remote_connect_list_all_domains_ret ret;
+
+    struct private_data *priv = conn->privateData;
+
+    remoteDriverLock(priv);
+
+    args.need_results = !!domains;
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+    if (call(conn,
+             priv,
+             0,
+             REMOTE_PROC_CONNECT_LIST_ALL_DOMAINS,
+             (xdrproc_t) xdr_remote_connect_list_all_domains_args,
+             (char *) &args,
+             (xdrproc_t) xdr_remote_connect_list_all_domains_ret,
+             (char *) &ret) == -1)
+        goto done;
+
+    if (domains) {
+        if (VIR_ALLOC_N(doms, ret.domains.domains_len + 1) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        for (i = 0; i < ret.domains.domains_len; i++) {
+            doms[i] = get_nonnull_domain(conn, ret.domains.domains_val[i]);
+            if (!doms[i]) {
+                virReportOOMError();
+                goto cleanup;
+            }
+        }
+        *domains = doms;
+        doms = NULL;
+    }
+
+    rv = ret.ret;
+
+cleanup:
+    if (doms) {
+        for (i = 0; i < ret.domains.domains_len; i++)
+            if (doms[i])
+                virDomainFree(doms[i]);
+        VIR_FREE(doms);
+    }
+
+    xdr_free((xdrproc_t) xdr_remote_connect_list_all_domains_ret, (char *) &ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 /* Helper to free typed parameters. */
 static void
 remoteFreeTypedParameters(remote_typed_param *args_params_val,
@@ -5111,6 +5174,7 @@ static virDriver remote_driver = {
     .domainGetDiskErrors = remoteDomainGetDiskErrors, /* 0.9.10 */
     .domainSetMetadata = remoteDomainSetMetadata, /* 0.9.10 */
     .domainGetMetadata = remoteDomainGetMetadata, /* 0.9.10 */
+    .listAllDomains = remoteConnectListAllDomains, /* 0.9.13 */
 };

 static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index d8a6576..e117ec3 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2463,6 +2463,16 @@ struct remote_domain_get_disk_errors_ret {
     int nerrors;
 };

+struct remote_connect_list_all_domains_args {
+    int need_results;
+    unsigned int flags;
+};
+
+struct remote_connect_list_all_domains_ret {
+    remote_nonnull_domain domains<>;
+    unsigned int ret;
+};
+

 /*----- Protocol. -----*/

@@ -2782,7 +2792,9 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_PM_WAKEUP = 267, /* autogen autogen */
     REMOTE_PROC_DOMAIN_EVENT_TRAY_CHANGE = 268, /* autogen autogen */
     REMOTE_PROC_DOMAIN_EVENT_PMWAKEUP = 269, /* autogen autogen */
-    REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND = 270 /* autogen autogen */
+    REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND = 270, /* autogen autogen */
+
+    REMOTE_PROC_CONNECT_LIST_ALL_DOMAINS = 271 /* skipgen skipgen priority:high */

     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 9b2414f..9539509 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1921,6 +1921,17 @@ struct remote_domain_get_disk_errors_ret {
         } errors;
         int                        nerrors;
 };
+struct remote_connect_list_all_domains_args {
+        int                        need_results;
+        u_int                      flags;
+};
+struct remote_connect_list_all_domains_ret {
+        struct {
+                u_int              domains_len;
+                remote_nonnull_domain * domains_val;
+        } domains;
+        u_int                      ret;
+};
 enum remote_procedure {
         REMOTE_PROC_OPEN = 1,
         REMOTE_PROC_CLOSE = 2,
@@ -2192,4 +2203,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_EVENT_TRAY_CHANGE = 268,
         REMOTE_PROC_DOMAIN_EVENT_PMWAKEUP = 269,
         REMOTE_PROC_DOMAIN_EVENT_PMSUSPEND = 270,
+        REMOTE_PROC_CONNECT_LIST_ALL_DOMAINS = 271,
 };
-- 
1.7.3.4




More information about the libvir-list mailing list