The RPC generator doesn't support returning list of object, this patch
do the work manually.

* daemon/remote.c:
  Implemente the server side handler remoteDispatchConnectListAllNetworks.

* src/remote/remote_driver.c:
  Add remote driver handler remoteConnectListAllNetworks.

* src/remote/remote_protocol.x:
  New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS and
  structs to represent the args and ret for it.

* src/remote_protocol-structs: Likewise.
---
 daemon/remote.c              |   55 ++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   64 ++++++++++++++++++++++++++++++++++++++++++
 src/remote/remote_protocol.x |   13 ++++++++-
 src/remote_protocol-structs  |   12 ++++++++
 4 files changed, 143 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index f2223ec..5a96b25 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4060,6 +4060,61 @@ cleanup:
     return rv;
 }
 
+static int
+remoteDispatchConnectListAllNetworks(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                     virNetServerClientPtr client,
+                                     virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                     virNetMessageErrorPtr rerr,
+                                     remote_connect_list_all_networks_args 
*args,
+                                     remote_connect_list_all_networks_ret *ret)
+{
+    virNetworkPtr *nets = NULL;
+    int nnets = 0;
+    int i;
+    int rv = -1;
+    struct daemonClientPrivate *priv = 
virNetServerClientGetPrivateData(client);
+
+    if (!priv->conn) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
+        goto cleanup;
+    }
+
+    if ((nnets = virConnectListAllNetworks(priv->conn,
+                                           args->need_results ? &nets : NULL,
+                                           args->flags)) < 0)
+        goto cleanup;
+
+    if (nets && nnets) {
+        if (VIR_ALLOC_N(ret->nets.nets_val, nnets) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        ret->nets.nets_len = nnets;
+
+        for (i = 0; i < nnets; i++)
+            make_nonnull_network(ret->nets.nets_val + i, nets[i]);
+    } else {
+        ret->nets.nets_len = 0;
+        ret->nets.nets_val = NULL;
+    }
+
+    ret->ret = nnets;
+
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (nets) {
+        for (i = 0; i < nnets; i++)
+            virNetworkFree(nets[i]);
+        VIR_FREE(nets);
+    }
+    return rv;
+}
+
+
 /*----- Helpers. -----*/
 
 /* get_nonnull_domain and get_nonnull_network turn an on-wire
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 578d73f..6bb4cc7 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2798,6 +2798,69 @@ done:
     return rv;
 }
 
+static int
+remoteConnectListAllNetworks(virConnectPtr conn,
+                             virNetworkPtr **nets,
+                             unsigned int flags)
+{
+    int rv = -1;
+    int i;
+    virNetworkPtr *tmp_nets = NULL;
+    remote_connect_list_all_networks_args args;
+    remote_connect_list_all_networks_ret ret;
+
+    struct private_data *priv = conn->privateData;
+
+    remoteDriverLock(priv);
+
+    args.need_results = !!nets;
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+    if (call(conn,
+             priv,
+             0,
+             REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS,
+             (xdrproc_t) xdr_remote_connect_list_all_networks_args,
+             (char *) &args,
+             (xdrproc_t) xdr_remote_connect_list_all_networks_ret,
+             (char *) &ret) == -1)
+        goto done;
+
+    if (nets) {
+        if (VIR_ALLOC_N(tmp_nets, ret.nets.nets_len + 1) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        for (i = 0; i < ret.nets.nets_len; i++) {
+            tmp_nets[i] = get_nonnull_network (conn, ret.nets.nets_val[i]);
+            if (!tmp_nets[i]) {
+                virReportOOMError();
+                goto cleanup;
+            }
+        }
+        *nets = tmp_nets;
+        tmp_nets = NULL;
+    }
+
+    rv = ret.ret;
+
+cleanup:
+    if (tmp_nets) {
+        for (i = 0; i < ret.nets.nets_len; i++)
+            if (tmp_nets[i])
+                virNetworkFree(tmp_nets[i]);
+        VIR_FREE(tmp_nets);
+    }
+
+    xdr_free((xdrproc_t) xdr_remote_connect_list_all_networks_ret, (char *) 
&ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 
 /*----------------------------------------------------------------------*/
 
@@ -5505,6 +5568,7 @@ static virNetworkDriver network_driver = {
     .listNetworks = remoteListNetworks, /* 0.3.0 */
     .numOfDefinedNetworks = remoteNumOfDefinedNetworks, /* 0.3.0 */
     .listDefinedNetworks = remoteListDefinedNetworks, /* 0.3.0 */
+    .listAllNetworks = remoteConnectListAllNetworks, /* 0.10.0 */
     .networkLookupByUUID = remoteNetworkLookupByUUID, /* 0.3.0 */
     .networkLookupByName = remoteNetworkLookupByName, /* 0.3.0 */
     .networkCreateXML = remoteNetworkCreateXML, /* 0.3.0 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 45a49fb..d095a2c 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2548,6 +2548,16 @@ struct remote_storage_pool_list_all_volumes_ret {
     unsigned int ret;
 };
 
+struct remote_connect_list_all_networks_args {
+    int need_results;
+    unsigned int flags;
+};
+
+struct remote_connect_list_all_networks_ret {
+    remote_nonnull_network nets<>;
+    unsigned int ret;
+};
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -2876,7 +2886,8 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_EVENT_BALLOON_CHANGE = 276, /* autogen autogen */
     REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277, /* autogen autogen */
     REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 278, /* skipgen skipgen 
priority:high */
-    REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 279 /* skipgen skipgen 
priority:high */
+    REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 279, /* skipgen skipgen 
priority:high */
+    REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 280 /* 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 d425a8b..fe3c627 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2004,6 +2004,17 @@ struct remote_storage_pool_list_all_volumes_ret {
         } vols;
         u_int                      ret;
 };
+struct remote_list_all_networks_args {
+        int                        need_results;
+        u_int                      flags;
+};
+struct remote_list_all_networks_ret {
+        struct {
+                u_int              nets_len;
+                remote_nonnull_network * nets_val;
+        } nets;
+        u_int                      ret;
+};
 enum remote_procedure {
         REMOTE_PROC_OPEN = 1,
         REMOTE_PROC_CLOSE = 2,
@@ -2284,4 +2295,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277,
         REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 278,
         REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 279,
+        REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 280,
 };
-- 
1.7.7.3

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

Reply via email to