[PATCH 25/45] list: Implemente RPC calls for virConnectListAllInterfaces

[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 remoteDispatchConnectListAllInterfaces.

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

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

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

diff --git a/daemon/remote.c b/daemon/remote.c
index f0313e7..81c53e9 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4111,6 +4111,60 @@ cleanup:
     return rv;
 }
 
+static int
+remoteDispatchConnectListAllInterfaces(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                       virNetServerClientPtr client,
+                                       virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                       virNetMessageErrorPtr rerr,
+                                       remote_connect_list_all_interfaces_args *args,
+                                       remote_connect_list_all_interfaces_ret *ret)
+{
+    virInterfacePtr *ifaces = NULL;
+    int nifaces = 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 ((nifaces = virConnectListAllInterfaces(priv->conn,
+                                               args->need_results ? &ifaces : NULL,
+                                               args->flags)) < 0)
+        goto cleanup;
+
+    if (ifaces && nifaces) {
+        if (VIR_ALLOC_N(ret->ifaces.ifaces_val, nifaces) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        ret->ifaces.ifaces_len = nifaces;
+
+        for (i = 0; i < nifaces; i++)
+            make_nonnull_interface(ret->ifaces.ifaces_val + i, ifaces[i]);
+    } else {
+        ret->ifaces.ifaces_len = 0;
+        ret->ifaces.ifaces_val = NULL;
+    }
+
+    ret->ret = nifaces;
+
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (ifaces) {
+        for (i = 0; i < nifaces; i++)
+            virInterfaceFree(ifaces[i]);
+        VIR_FREE(ifaces);
+    }
+    return rv;
+}
+
 
 /*----- Helpers. -----*/
 
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 0729a73..6d002f6 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2863,6 +2863,69 @@ done:
     return rv;
 }
 
+static int
+remoteConnectListAllInterfaces(virConnectPtr conn,
+                               virInterfacePtr **ifaces,
+                               unsigned int flags)
+{
+    int rv = -1;
+    int i;
+    virInterfacePtr *tmp_ifaces = NULL;
+    remote_connect_list_all_interfaces_args args;
+    remote_connect_list_all_interfaces_ret ret;
+
+    struct private_data *priv = conn->privateData;
+
+    remoteDriverLock(priv);
+
+    args.need_results = !!ifaces;
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+    if (call(conn,
+             priv,
+             0,
+             REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES,
+             (xdrproc_t) xdr_remote_connect_list_all_interfaces_args,
+             (char *) &args,
+             (xdrproc_t) xdr_remote_connect_list_all_interfaces_ret,
+             (char *) &ret) == -1)
+        goto done;
+
+    if (ifaces) {
+        if (VIR_ALLOC_N(tmp_ifaces, ret.ifaces.ifaces_len + 1) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        for (i = 0; i < ret.ifaces.ifaces_len; i++) {
+            tmp_ifaces[i] = get_nonnull_interface (conn, ret.ifaces.ifaces_val[i]);
+            if (!tmp_ifaces[i]) {
+                virReportOOMError();
+                goto cleanup;
+            }
+        }
+        *ifaces = tmp_ifaces;
+        tmp_ifaces = NULL;
+    }
+
+    rv = ret.ret;
+
+cleanup:
+    if (tmp_ifaces) {
+        for (i = 0; i < ret.ifaces.ifaces_len; i++)
+            if (tmp_ifaces[i])
+                virInterfaceFree(tmp_ifaces[i]);
+        VIR_FREE(tmp_ifaces);
+    }
+
+    xdr_free((xdrproc_t) xdr_remote_connect_list_all_interfaces_ret, (char *) &ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
+
 
 /*----------------------------------------------------------------------*/
 
@@ -5595,6 +5658,7 @@ static virInterfaceDriver interface_driver = {
     .listInterfaces = remoteListInterfaces, /* 0.7.2 */
     .numOfDefinedInterfaces = remoteNumOfDefinedInterfaces, /* 0.7.2 */
     .listDefinedInterfaces = remoteListDefinedInterfaces, /* 0.7.2 */
+    .listAllInterfaces = remoteConnectListAllInterfaces, /* 0.10.0 */
     .interfaceLookupByName = remoteInterfaceLookupByName, /* 0.7.2 */
     .interfaceLookupByMACString = remoteInterfaceLookupByMACString, /* 0.7.2 */
     .interfaceGetXMLDesc = remoteInterfaceGetXMLDesc, /* 0.7.2 */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index d095a2c..36db5b1 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2558,6 +2558,16 @@ struct remote_connect_list_all_networks_ret {
     unsigned int ret;
 };
 
+struct remote_connect_list_all_interfaces_args {
+    int need_results;
+    unsigned int flags;
+};
+
+struct remote_connect_list_all_interfaces_ret {
+    remote_nonnull_interface ifaces<>;
+    unsigned int ret;
+};
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -2887,7 +2897,9 @@ enum remote_procedure {
     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_CONNECT_LIST_ALL_NETWORKS = 280 /* 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 */
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index fe3c627..8281991 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2015,6 +2015,17 @@ struct remote_list_all_networks_ret {
         } nets;
         u_int                      ret;
 };
+struct remote_connect_list_all_interfaces_args {
+        int                        need_results;
+        u_int                      flags;
+};
+struct remote_connect_list_all_interfaces_ret {
+        struct {
+                u_int              ifaces_len;
+                remote_nonnull_interface * ifaces_val;
+        } pools;
+        u_int                      ret;
+};
 enum remote_procedure {
         REMOTE_PROC_OPEN = 1,
         REMOTE_PROC_CLOSE = 2,
@@ -2296,4 +2307,5 @@ enum remote_procedure {
         REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 278,
         REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 279,
         REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 280,
+        REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 281,
 };
-- 
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]