On 09/04/2012 11:55 AM, Osier Yang wrote: > 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 8208c71..dba51a7 100644 > --- a/daemon/remote.c > +++ b/daemon/remote.c > @@ -4211,6 +4211,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 8d4420e..56e50a6 100644 > --- a/src/remote/remote_driver.c > +++ b/src/remote/remote_driver.c > @@ -2718,6 +2718,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; > +} > + > > /*----------------------------------------------------------------------*/ > > @@ -5696,6 +5759,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 */ 0.10.2 > .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 e540167..12ecfd7 100644 > --- a/src/remote/remote_protocol.x > +++ b/src/remote/remote_protocol.x > @@ -2579,6 +2579,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. */ > @@ -2911,7 +2921,8 @@ enum remote_procedure { > REMOTE_PROC_DOMAIN_GET_EMULATOR_PIN_INFO = 280, /* skipgen skipgen */ > > REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 281, /* skipgen skipgen priority:high */ > - REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 282 /* skipgen skipgen priority:high */ > + REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 282, /* skipgen skipgen priority:high */ > + REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 283 /* 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 f105a38..45262f8 100644 > --- a/src/remote_protocol-structs > +++ b/src/remote_protocol-structs > @@ -2034,6 +2034,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, > @@ -2317,4 +2328,5 @@ enum remote_procedure { > REMOTE_PROC_DOMAIN_GET_EMULATOR_PIN_INFO = 280, > REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 281, > REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 282, > + REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 283, > }; ACK aside from the one small version number change. -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list