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 |   13 ++++++++-
 src/remote_protocol-structs  |   12 ++++++++
 4 files changed, 141 insertions(+), 1 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 50fb28d..1e4dbd2 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4168,6 +4168,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) {
+        virReportError(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 ab6ddd6..0e15153 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2924,6 +2924,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;
+}
+
 
 /*----------------------------------------------------------------------*/
 
@@ -5737,6 +5800,7 @@ static virDeviceMonitor dev_monitor = {
     .close = remoteDevMonClose, /* 0.5.0 */
     .numOfDevices = remoteNodeNumOfDevices, /* 0.5.0 */
     .listDevices = remoteNodeListDevices, /* 0.5.0 */
+    .listAllNodeDevices  = remoteConnectListAllNodeDevices, /* 0.10.0 */
     .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 36db5b1..4a7116c 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2568,6 +2568,16 @@ struct remote_connect_list_all_interfaces_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. */
@@ -2899,7 +2909,8 @@ enum remote_procedure {
     REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 279, /* skipgen skipgen 
priority:high */
     REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 280, /* skipgen skipgen 
priority:high */
 
-    REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 281 /* skipgen skipgen 
priority:high */
+    REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 281, /* skipgen skipgen 
priority:high */
+    REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 282 /* 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 8281991..aae8652 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2026,6 +2026,17 @@ struct remote_connect_list_all_interfaces_ret {
         } pools;
         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,
@@ -2308,4 +2319,5 @@ enum remote_procedure {
         REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 279,
         REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 280,
         REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 281,
+        REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 282,
 };
-- 
1.7.7.3

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

Reply via email to