[PATCH 2/5] list: Implement RPC calls for virConnectListAllNWFilters

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

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

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

  * src/remote_protocol-structs: Likewise.
---
 daemon/remote.c              |   54 ++++++++++++++++++++++++++++++++++++
 src/remote/remote_driver.c   |   63 ++++++++++++++++++++++++++++++++++++++++++
 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 d7cce78..00ce9c8 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -4373,6 +4373,60 @@ cleanup:
     return rv;
 }
 
+static int
+remoteDispatchConnectListAllNWFilters(virNetServerPtr server ATTRIBUTE_UNUSED,
+                                      virNetServerClientPtr client,
+                                      virNetMessagePtr msg ATTRIBUTE_UNUSED,
+                                      virNetMessageErrorPtr rerr,
+                                      remote_connect_list_all_nwfilters_args *args,
+                                      remote_connect_list_all_nwfilters_ret *ret)
+{
+    virNWFilterPtr *filters = NULL;
+    int nfilters = 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 ((nfilters = virConnectListAllNWFilters(priv->conn,
+                                               args->need_results ? &filters : NULL,
+                                               args->flags)) < 0)
+        goto cleanup;
+
+    if (filters && nfilters) {
+        if (VIR_ALLOC_N(ret->filters.filters_val, nfilters) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        ret->filters.filters_len = nfilters;
+
+        for (i = 0; i < nfilters; i++)
+            make_nonnull_nwfilter(ret->filters.filters_val + i, filters[i]);
+    } else {
+        ret->filters.filters_len = 0;
+        ret->filters.filters_val = NULL;
+    }
+
+    ret->ret = nfilters;
+
+    rv = 0;
+
+cleanup:
+    if (rv < 0)
+        virNetMessageSaveError(rerr);
+    if (filters) {
+        for (i = 0; i < nfilters; i++)
+            virNWFilterFree(filters[i]);
+        VIR_FREE(filters);
+    }
+    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 b1671ae..2afe5b0 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -2907,6 +2907,68 @@ done:
     return rv;
 }
 
+static int
+remoteConnectListAllNWFilters(virConnectPtr conn,
+                              virNWFilterPtr **filters,
+                              unsigned int flags)
+{
+    int rv = -1;
+    int i;
+    virNWFilterPtr *tmp_filters = NULL;
+    remote_connect_list_all_nwfilters_args args;
+    remote_connect_list_all_nwfilters_ret ret;
+
+    struct private_data *priv = conn->privateData;
+
+    remoteDriverLock(priv);
+
+    args.need_results = !!filters;
+    args.flags = flags;
+
+    memset(&ret, 0, sizeof(ret));
+    if (call(conn,
+             priv,
+             0,
+             REMOTE_PROC_CONNECT_LIST_ALL_NWFILTERS,
+             (xdrproc_t) xdr_remote_connect_list_all_nwfilters_args,
+             (char *) &args,
+             (xdrproc_t) xdr_remote_connect_list_all_nwfilters_ret,
+             (char *) &ret) == -1)
+        goto done;
+
+    if (filters) {
+        if (VIR_ALLOC_N(tmp_filters, ret.filters.filters_len + 1) < 0) {
+            virReportOOMError();
+            goto cleanup;
+        }
+
+        for (i = 0; i < ret.filters.filters_len; i++) {
+            tmp_filters[i] = get_nonnull_nwfilter (conn, ret.filters.filters_val[i]);
+            if (!tmp_filters[i]) {
+                virReportOOMError();
+                goto cleanup;
+            }
+        }
+        *filters = tmp_filters;
+        tmp_filters = NULL;
+    }
+
+    rv = ret.ret;
+
+cleanup:
+    if (tmp_filters) {
+        for (i = 0; i < ret.filters.filters_len; i++)
+            if (tmp_filters[i])
+                virNWFilterFree(tmp_filters[i]);
+        VIR_FREE(tmp_filters);
+    }
+
+    xdr_free((xdrproc_t) xdr_remote_connect_list_all_nwfilters_ret, (char *) &ret);
+
+done:
+    remoteDriverUnlock(priv);
+    return rv;
+}
 
 /*----------------------------------------------------------------------*/
 
@@ -6012,6 +6074,7 @@ static virNWFilterDriver nwfilter_driver = {
     .undefine             = remoteNWFilterUndefine, /* 0.8.0 */
     .numOfNWFilters       = remoteNumOfNWFilters, /* 0.8.0 */
     .listNWFilters        = remoteListNWFilters, /* 0.8.0 */
+    .listAllNWFilters     = remoteConnectListAllNWFilters, /* 0.10.2 */
 };
 
 
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index d467772..46269c8 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2609,6 +2609,16 @@ struct remote_connect_list_all_node_devices_ret {
     unsigned int ret;
 };
 
+struct remote_connect_list_all_nwfilters_args {
+    int need_results;
+    unsigned int flags;
+};
+
+struct remote_connect_list_all_nwfilters_ret {
+    remote_nonnull_nwfilter filters<>;
+    unsigned int ret;
+};
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -2944,7 +2954,8 @@ enum remote_procedure {
     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_NODE_DEVICES = 285 /* skipgen skipgen priority:high */
+    REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 285, /* skipgen skipgen priority:high */
+    REMOTE_PROC_CONNECT_LIST_ALL_NWFILTERS = 286 /* 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 cd7bc50..0dde9fc 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -2067,6 +2067,17 @@ struct remote_connect_list_all_node_devices_ret {
         } devices;
         u_int                      ret;
 };
+struct remote_connect_list_all_nwfilters_args {
+        int                        need_results;
+        u_int                      flags;
+};
+struct remote_connect_list_all_nwfilters_ret {
+        struct {
+                u_int              filters_len;
+                remote_nonnull_nwfilter * filters_val;
+        } filters;
+        u_int                      ret;
+};
 enum remote_procedure {
         REMOTE_PROC_OPEN = 1,
         REMOTE_PROC_CLOSE = 2,
@@ -2353,4 +2364,5 @@ enum remote_procedure {
         REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 283,
         REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 284,
         REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 285,
+        REMOTE_PROC_CONNECT_LIST_ALL_NWFILTERS = 286,
 };
-- 
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]