[PATCH 2/7] list: Implemente RPC calls for virConnectListAllNodeDevices

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 fe2f9dd..d7cce78 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4319,6 +4319,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 5c97061..b1671ae 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2844,6 +2844,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;
+}
+
 
 /*----------------------------------------------------------------------*/
 
@@ -5928,6 +5991,7 @@ static virDeviceMonitor dev_monitor = {
     .close = remoteDevMonClose, /* 0.5.0 */
     .numOfDevices = remoteNodeNumOfDevices, /* 0.5.0 */
     .listDevices = remoteNodeListDevices, /* 0.5.0 */
+    .listAllNodeDevices  = remoteConnectListAllNodeDevices, /* 0.10.2 */
     .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 54054af..d467772 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2599,6 +2599,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. */
@@ -2933,7 +2943,8 @@ enum remote_procedure {
     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_CONNECT_LIST_ALL_NETWORKS = 283, /* skipgen skipgen priority:high */
-    REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 284 /* skipgen skipgen priority:high */
+    REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 284, /* skipgen skipgen priority:high */
+    REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 285 /* 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 4e41c67..cd7bc50 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2056,6 +2056,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,
@@ -2341,4 +2352,5 @@ enum remote_procedure {
         REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 282,
         REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 283,
         REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 284,
+        REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 285,
 };
-- 
1.7.7.3

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]