The RPC generator doesn't support returning list of object yet, this patch do the work manually.
* daemon/remote.c: Implemente the server side handler remoteDispatchConnectListAllNodeDevices. * src/remote/remote_driver.c: Add remote driver handler remoteConnectListAllNodeDevices. * src/remote/remote_protocol.x: New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES and --- daemon/remote.c | 53 ++++++++++++++++++++++++++++++++++ src/remote/remote_driver.c | 64 ++++++++++++++++++++++++++++++++++++++++++ src/remote/remote_protocol.x | 14 ++++++++- src/remote_protocol-structs | 12 ++++++++ 4 files changed, 142 insertions(+), 1 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index aec7b3c..5a16dbe 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -4172,6 +4172,59 @@ cleanup: return rv; } +static int +remoteDispatchConnectListAllNodeDevices(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr, + remote_connect_list_all_node_devices_args *args, + remote_connect_list_all_node_devices_ret *ret) +{ + virNodeDevicePtr *devices = NULL; + int ndevices = 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 ((ndevices = virConnectListAllNodeDevices(priv->conn, + args->need_results ? &devices : NULL, + args->flags)) < 0) + goto cleanup; + + if (devices && ndevices) { + if (VIR_ALLOC_N(ret->devices.devices_val, ndevices) < 0) { + virReportOOMError(); + goto cleanup; + } + + ret->devices.devices_len = ndevices; + + for (i = 0; i < ndevices; i++) + make_nonnull_node_device(ret->devices.devices_val + i, devices[i]); + } else { + ret->devices.devices_len = 0; + ret->devices.devices_val = NULL; + } + + ret->ret = ndevices; + + rv = 0; + +cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + if (devices) { + for (i = 0; i < ndevices; i++) + virNodeDeviceFree(devices[i]); + VIR_FREE(devices); + } + return rv; +} /*----- Helpers. -----*/ diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 2b7c05e..22aad2f 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2905,6 +2905,69 @@ done: return rv; } +static int +remoteConnectListAllNodeDevices(virConnectPtr conn, + virNodeDevicePtr **devices, + unsigned int flags) +{ + int rv = -1; + int i; + virNodeDevicePtr *tmp_devices = NULL; + remote_connect_list_all_node_devices_args args; + remote_connect_list_all_node_devices_ret ret; + + struct private_data *priv = conn->privateData; + + remoteDriverLock(priv); + + args.need_results = !!devices; + args.flags = flags; + + memset(&ret, 0, sizeof(ret)); + if (call(conn, + priv, + 0, + REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES, + (xdrproc_t) xdr_remote_connect_list_all_node_devices_args, + (char *) &args, + (xdrproc_t) xdr_remote_connect_list_all_node_devices_ret, + (char *) &ret) == -1) + goto done; + + if (devices) { + if (VIR_ALLOC_N(tmp_devices, ret.devices.devices_len + 1) < 0) { + virReportOOMError(); + goto cleanup; + } + + for (i = 0; i < ret.devices.devices_len; i++) { + tmp_devices[i] = get_nonnull_node_device(conn, ret.devices.devices_val[i]); + if (!tmp_devices[i]) { + virReportOOMError(); + goto cleanup; + } + } + *devices = tmp_devices; + tmp_devices = NULL; + } + + rv = ret.ret; + +cleanup: + if (tmp_devices) { + for (i = 0; i < ret.devices.devices_len; i++) + if (tmp_devices[i]) + virNodeDeviceFree(tmp_devices[i]); + VIR_FREE(tmp_devices); + } + + xdr_free((xdrproc_t) xdr_remote_connect_list_all_node_devices_ret, (char *) &ret); + +done: + remoteDriverUnlock(priv); + return rv; +} + /*----------------------------------------------------------------------*/ @@ -5717,6 +5780,7 @@ static virDeviceMonitor dev_monitor = { .close = remoteDevMonClose, /* 0.5.0 */ .numOfDevices = remoteNodeNumOfDevices, /* 0.5.0 */ .listDevices = remoteNodeListDevices, /* 0.5.0 */ + .listAllNodeDevices = remoteConnectListAllNodeDevices, /* 0.9.14 */ .deviceLookupByName = remoteNodeDeviceLookupByName, /* 0.5.0 */ .deviceGetXMLDesc = remoteNodeDeviceGetXMLDesc, /* 0.5.0 */ .deviceGetParent = remoteNodeDeviceGetParent, /* 0.5.0 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index e4f0d62..d25e22c 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2557,6 +2557,16 @@ struct remote_connect_list_all_storage_pools_ret { unsigned int ret; }; +struct remote_connect_list_all_node_devices_args { + int need_results; + unsigned int flags; +}; + +struct remote_connect_list_all_node_devices_ret { + remote_nonnull_node_device devices<>; + unsigned int ret; +}; + /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -2886,7 +2896,9 @@ enum remote_procedure { REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 277, /* skipgen skipgen priority:high */ REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 278, /* skipgen skipgen priority:high */ REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 279, /* skipgen skipgen priority:high */ - REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 280 /* skipgen skipgen priority:high */ + REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 280, /* skipgen skipgen priority:high */ + + REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 281 /* 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 2640fd1..545186d 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -2019,6 +2019,17 @@ struct remote_storage_pool_list_all_volumes_ret { } vols; u_int ret; }; +struct remote_connect_list_all_node_devices_args { + int need_results; + u_int flags; +}; +struct remote_connect_list_all_node_devices_ret { + struct { + u_int devices_len; + remote_nonnull_node_device * devices_val; + } devices; + u_int ret; +}; enum remote_procedure { REMOTE_PROC_OPEN = 1, REMOTE_PROC_CLOSE = 2, @@ -2300,4 +2311,5 @@ enum remote_procedure { REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 278, REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 279, REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 280, + REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 281, }; -- 1.7.7.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list