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

[libvirt] [PATCH 23/27] remote: add support for new network port APIs



Define the wire protocol for the virNetworkPort APIs and enable the
client/server RPC dispatch.

Signed-off-by: Daniel P. Berrangé <berrange redhat com>
---
 src/remote/remote_daemon_dispatch.c | 25 ++++++++
 src/remote/remote_driver.c          | 28 +++++++++
 src/remote/remote_protocol.x        | 89 ++++++++++++++++++++++++++++-
 src/remote_protocol-structs         | 47 +++++++++++++++
 src/rpc/gendispatch.pl              | 18 ++++--
 5 files changed, 200 insertions(+), 7 deletions(-)

diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon_dispatch.c
index fcd602304f..2620699600 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -83,6 +83,7 @@ struct daemonClientEventCallback {
 
 static virDomainPtr get_nonnull_domain(virConnectPtr conn, remote_nonnull_domain domain);
 static virNetworkPtr get_nonnull_network(virConnectPtr conn, remote_nonnull_network network);
+static virNetworkPortPtr get_nonnull_network_port(virConnectPtr conn, remote_nonnull_network_port port);
 static virInterfacePtr get_nonnull_interface(virConnectPtr conn, remote_nonnull_interface iface);
 static virStoragePoolPtr get_nonnull_storage_pool(virConnectPtr conn, remote_nonnull_storage_pool pool);
 static virStorageVolPtr get_nonnull_storage_vol(virConnectPtr conn, remote_nonnull_storage_vol vol);
@@ -93,6 +94,7 @@ static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr dom, remote
 static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote_nonnull_node_device dev);
 static int make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src) ATTRIBUTE_RETURN_CHECK;
 static int make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src) ATTRIBUTE_RETURN_CHECK;
+static int make_nonnull_network_port(remote_nonnull_network_port *port_dst, virNetworkPortPtr port_src) ATTRIBUTE_RETURN_CHECK;
 static int make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src) ATTRIBUTE_RETURN_CHECK;
 static int make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr pool_src) ATTRIBUTE_RETURN_CHECK;
 static int make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src) ATTRIBUTE_RETURN_CHECK;
@@ -7202,6 +7204,19 @@ get_nonnull_network(virConnectPtr conn, remote_nonnull_network network)
     return virGetNetwork(conn, network.name, BAD_CAST network.uuid);
 }
 
+static virNetworkPortPtr
+get_nonnull_network_port(virConnectPtr conn, remote_nonnull_network_port port)
+{
+    virNetworkPortPtr ret;
+    virNetworkPtr net;
+    net = virGetNetwork(conn, port.net.name, BAD_CAST port.net.uuid);
+    if (!net)
+        return NULL;
+    ret = virGetNetworkPort(net, BAD_CAST port.uuid);
+    virObjectUnref(net);
+    return ret;
+}
+
 static virInterfacePtr
 get_nonnull_interface(virConnectPtr conn, remote_nonnull_interface iface)
 {
@@ -7274,6 +7289,16 @@ make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src)
     return 0;
 }
 
+static int
+make_nonnull_network_port(remote_nonnull_network_port *port_dst, virNetworkPortPtr port_src)
+{
+    if (VIR_STRDUP(port_dst->net.name, port_src->net->name) < 0)
+        return -1;
+    memcpy(port_dst->net.uuid, port_src->net->uuid, VIR_UUID_BUFLEN);
+    memcpy(port_dst->uuid, port_src->uuid, VIR_UUID_BUFLEN);
+    return 0;
+}
+
 static int
 make_nonnull_interface(remote_nonnull_interface *interface_dst,
                        virInterfacePtr interface_src)
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 058e4c926b..d2e8ce2473 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -138,6 +138,7 @@ static int remoteAuthPolkit(virConnectPtr conn, struct private_data *priv,
 
 static virDomainPtr get_nonnull_domain(virConnectPtr conn, remote_nonnull_domain domain);
 static virNetworkPtr get_nonnull_network(virConnectPtr conn, remote_nonnull_network network);
+static virNetworkPortPtr get_nonnull_network_port(virConnectPtr conn, remote_nonnull_network_port port);
 static virNWFilterPtr get_nonnull_nwfilter(virConnectPtr conn, remote_nonnull_nwfilter nwfilter);
 static virNWFilterBindingPtr get_nonnull_nwfilter_binding(virConnectPtr conn, remote_nonnull_nwfilter_binding binding);
 static virInterfacePtr get_nonnull_interface(virConnectPtr conn, remote_nonnull_interface iface);
@@ -148,6 +149,7 @@ static virSecretPtr get_nonnull_secret(virConnectPtr conn, remote_nonnull_secret
 static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr domain, remote_nonnull_domain_snapshot snapshot);
 static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPtr dom_src);
 static void make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src);
+static void make_nonnull_network_port(remote_nonnull_network_port *port_dst, virNetworkPortPtr port_src);
 static void make_nonnull_interface(remote_nonnull_interface *interface_dst, virInterfacePtr interface_src);
 static void make_nonnull_storage_pool(remote_nonnull_storage_pool *pool_dst, virStoragePoolPtr vol_src);
 static void make_nonnull_storage_vol(remote_nonnull_storage_vol *vol_dst, virStorageVolPtr vol_src);
@@ -8168,6 +8170,19 @@ get_nonnull_network(virConnectPtr conn, remote_nonnull_network network)
     return virGetNetwork(conn, network.name, BAD_CAST network.uuid);
 }
 
+static virNetworkPortPtr
+get_nonnull_network_port(virConnectPtr conn, remote_nonnull_network_port port)
+{
+    virNetworkPortPtr ret;
+    virNetworkPtr net;
+    net = virGetNetwork(conn, port.net.name, BAD_CAST port.net.uuid);
+    if (!net)
+        return NULL;
+    ret = virGetNetworkPort(net, BAD_CAST port.uuid);
+    virObjectUnref(net);
+    return ret;
+}
+
 static virInterfacePtr
 get_nonnull_interface(virConnectPtr conn, remote_nonnull_interface iface)
 {
@@ -8235,6 +8250,14 @@ make_nonnull_network(remote_nonnull_network *net_dst, virNetworkPtr net_src)
     memcpy(net_dst->uuid, net_src->uuid, VIR_UUID_BUFLEN);
 }
 
+static void
+make_nonnull_network_port(remote_nonnull_network_port *port_dst, virNetworkPortPtr port_src)
+{
+    port_dst->net.name = port_src->net->name;
+    memcpy(port_dst->net.uuid, port_src->net->uuid, VIR_UUID_BUFLEN);
+    memcpy(port_dst->uuid, port_src->uuid, VIR_UUID_BUFLEN);
+}
+
 static void
 make_nonnull_interface(remote_nonnull_interface *interface_dst,
                         virInterfacePtr interface_src)
@@ -8561,6 +8584,11 @@ static virNetworkDriver network_driver = {
     .networkIsActive = remoteNetworkIsActive, /* 0.7.3 */
     .networkIsPersistent = remoteNetworkIsPersistent, /* 0.7.3 */
     .networkGetDHCPLeases = remoteNetworkGetDHCPLeases, /* 1.2.6 */
+    .networkListAllPorts = remoteNetworkListAllPorts, /* 5.0.0 */
+    .networkPortLookupByUUID = remoteNetworkPortLookupByUUID, /* 5.0.0 */
+    .networkPortCreateXML = remoteNetworkPortCreateXML, /* 5.0.0 */
+    .networkPortGetXMLDesc = remoteNetworkPortGetXMLDesc, /* 5.0.0 */
+    .networkPortDelete = remoteNetworkPortDelete, /* 5.0.0 */
 };
 
 static virInterfaceDriver interface_driver = {
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index b9d26b1849..d9c3bfe5f1 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -74,6 +74,9 @@ const REMOTE_MIGRATE_COOKIE_MAX = 4194304;
 /* Upper limit on lists of networks. */
 const REMOTE_NETWORK_LIST_MAX = 16384;
 
+/* Upper limit on lists of network ports. */
+const REMOTE_NETWORK_PORT_LIST_MAX = 16384;
+
 /* Upper limit on lists of interfaces. */
 const REMOTE_INTERFACE_LIST_MAX = 16384;
 
@@ -279,6 +282,11 @@ struct remote_nonnull_network {
     remote_uuid uuid;
 };
 
+struct remote_nonnull_network_port {
+    remote_nonnull_network net;
+    remote_uuid uuid;
+};
+
 /* A network filter which may not be NULL. */
 struct remote_nonnull_nwfilter {
     remote_nonnull_string name;
@@ -331,6 +339,7 @@ struct remote_nonnull_domain_snapshot {
 /* A domain or network which may be NULL. */
 typedef remote_nonnull_domain *remote_domain;
 typedef remote_nonnull_network *remote_network;
+typedef remote_nonnull_network_port *remote_network_port;
 typedef remote_nonnull_nwfilter *remote_nwfilter;
 typedef remote_nonnull_nwfilter_binding *remote_nwfilter_binding;
 typedef remote_nonnull_storage_pool *remote_storage_pool;
@@ -3565,6 +3574,51 @@ struct remote_connect_list_all_nwfilter_bindings_ret { /* insert 1 */
     unsigned int ret;
 };
 
+struct remote_network_list_all_ports_args {
+    remote_nonnull_network network;
+    int need_results;
+    unsigned int flags;
+};
+
+struct remote_network_list_all_ports_ret { /* insert 1 */
+    remote_nonnull_network_port ports<REMOTE_NETWORK_PORT_LIST_MAX>;
+    unsigned int ret;
+};
+
+struct remote_network_port_lookup_by_uuid_args {
+    remote_nonnull_network network;
+    remote_uuid uuid;
+};
+
+struct remote_network_port_lookup_by_uuid_ret {
+    remote_nonnull_network_port port;
+};
+
+struct remote_network_port_create_xml_args {
+    remote_nonnull_network network;
+    remote_nonnull_string xml;
+    unsigned int flags;
+};
+
+struct remote_network_port_create_xml_ret {
+    remote_nonnull_network_port port;
+};
+
+struct remote_network_port_get_xml_desc_args {
+    remote_nonnull_network_port port;
+    unsigned int flags;
+};
+
+struct remote_network_port_get_xml_desc_ret {
+    remote_nonnull_string xml;
+};
+
+struct remote_network_port_delete_args {
+    remote_nonnull_network_port port;
+    unsigned int flags;
+};
+
+
 /*----- Protocol. -----*/
 
 /* Define the program number, protocol version and procedure numbers here. */
@@ -6328,6 +6382,39 @@ enum remote_procedure {
      * @acl: domain:save:!VIR_DOMAIN_AFFECT_CONFIG|VIR_DOMAIN_AFFECT_LIVE
      * @acl: domain:save:VIR_DOMAIN_AFFECT_CONFIG
      */
-    REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS = 402
+    REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS = 402,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: network:search_ports
+     * @aclfilter: network_port:getattr
+     */
+    REMOTE_PROC_NETWORK_LIST_ALL_PORTS = 403,
+
+    /**
+     * @generate: both
+     * @priority: high
+     * @acl: network_port:getattr
+     */
+    REMOTE_PROC_NETWORK_PORT_LOOKUP_BY_UUID = 404,
+
+    /**
+     * @generate: both
+     * @acl: network_port:create
+     */
+    REMOTE_PROC_NETWORK_PORT_CREATE_XML = 405,
+
+    /**
+     * @generate: both
+     * @acl: network_port:read
+     */
+    REMOTE_PROC_NETWORK_PORT_GET_XML_DESC = 406,
+
+    /**
+     * @generate: both
+     * @acl: network_port:delete
+     */
+    REMOTE_PROC_NETWORK_PORT_DELETE = 407
 
 };
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 7c27c63542..8f419e60f8 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -17,6 +17,10 @@ struct remote_nonnull_network {
         remote_nonnull_string      name;
         remote_uuid                uuid;
 };
+struct remote_nonnull_network_port {
+        remote_nonnull_network     net;
+        remote_uuid                uuid;
+};
 struct remote_nonnull_nwfilter {
         remote_nonnull_string      name;
         remote_uuid                uuid;
@@ -2975,6 +2979,44 @@ struct remote_connect_list_all_nwfilter_bindings_ret {
         } bindings;
         u_int                      ret;
 };
+struct remote_network_list_all_ports_args {
+        remote_nonnull_network     network;
+        int                        need_results;
+        u_int                      flags;
+};
+struct remote_network_list_all_ports_ret {
+        struct {
+                u_int              ports_len;
+                remote_nonnull_network_port * ports_val;
+        } ports;
+        u_int                      ret;
+};
+struct remote_network_port_lookup_by_uuid_args {
+        remote_nonnull_network     network;
+        remote_uuid                uuid;
+};
+struct remote_network_port_lookup_by_uuid_ret {
+        remote_nonnull_network_port port;
+};
+struct remote_network_port_create_xml_args {
+        remote_nonnull_network     network;
+        remote_nonnull_string      xml;
+        u_int                      flags;
+};
+struct remote_network_port_create_xml_ret {
+        remote_nonnull_network_port port;
+};
+struct remote_network_port_get_xml_desc_args {
+        remote_nonnull_network_port port;
+        u_int                      flags;
+};
+struct remote_network_port_get_xml_desc_ret {
+        remote_nonnull_string      xml;
+};
+struct remote_network_port_delete_args {
+        remote_nonnull_network_port port;
+        u_int                      flags;
+};
 enum remote_procedure {
         REMOTE_PROC_CONNECT_OPEN = 1,
         REMOTE_PROC_CONNECT_CLOSE = 2,
@@ -3378,4 +3420,9 @@ enum remote_procedure {
         REMOTE_PROC_NWFILTER_BINDING_DELETE = 400,
         REMOTE_PROC_CONNECT_LIST_ALL_NWFILTER_BINDINGS = 401,
         REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS = 402,
+        REMOTE_PROC_NETWORK_LIST_ALL_PORTS = 403,
+        REMOTE_PROC_NETWORK_PORT_LOOKUP_BY_UUID = 404,
+        REMOTE_PROC_NETWORK_PORT_CREATE_XML = 405,
+        REMOTE_PROC_NETWORK_PORT_GET_XML_DESC = 406,
+        REMOTE_PROC_NETWORK_PORT_DELETE = 407,
 };
diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index ce4db5d7b7..6b950ee839 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -557,7 +557,7 @@ elsif ($mode eq "server") {
                 if ($args_member =~ m/^remote_nonnull_string name;/ and $has_node_device) {
                     # ignore the name arg for node devices
                     next
-                } elsif ($args_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding) (\S+);/) {
+                } elsif ($args_member =~ m/^remote_nonnull_(domain|network|network_port|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding) (\S+);/) {
                     my $type_name = name_to_TypeName($1);
 
                     push(@vars_list, "vir${type_name}Ptr $2 = NULL");
@@ -722,7 +722,7 @@ elsif ($mode eq "server") {
                         if (!$modern_ret_as_list) {
                             push(@ret_list, "ret->$3 = tmp.$3;");
                         }
-                    } elsif ($ret_member =~ m/(?:admin|remote)_nonnull_(secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) {
+                    } elsif ($ret_member =~ m/(?:admin|remote)_nonnull_(secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port|storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) {
                         $modern_ret_struct_name = $1;
                         $single_ret_list_error_msg_type = $1;
                         $single_ret_list_name = $2;
@@ -780,7 +780,7 @@ elsif ($mode eq "server") {
                     $single_ret_var = $1;
                     $single_ret_by_ref = 0;
                     $single_ret_check = " == NULL";
-                } elsif ($ret_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|node_device|secret|nwfilter|nwfilter_binding|domain_snapshot) (\S+);/) {
+                } elsif ($ret_member =~ m/^remote_nonnull_(domain|network|network_port|storage_pool|storage_vol|interface|node_device|secret|nwfilter|nwfilter_binding|domain_snapshot) (\S+);/) {
                     my $type_name = name_to_TypeName($1);
 
                     if ($call->{ProcName} eq "DomainCreateWithFlags") {
@@ -1328,7 +1328,7 @@ elsif ($mode eq "client") {
                     $priv_src = "dev->conn";
                     push(@args_list, "virNodeDevicePtr dev");
                     push(@setters_list, "args.name = dev->name;");
-                } elsif ($args_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding|domain_snapshot) (\S+);/) {
+                } elsif ($args_member =~ m/^remote_nonnull_(domain|network|network_port|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding|domain_snapshot) (\S+);/) {
                     my $name = $1;
                     my $arg_name = $2;
                     my $type_name = name_to_TypeName($name);
@@ -1336,6 +1336,8 @@ elsif ($mode eq "client") {
                     if ($is_first_arg) {
                         if ($name eq "domain_snapshot") {
                             $priv_src = "$arg_name->domain->conn";
+                        } elsif ($name eq "network_port") {
+                            $priv_src = "$arg_name->net->conn";
                         } else {
                             $priv_src = "$arg_name->conn";
                         }
@@ -1521,7 +1523,7 @@ elsif ($mode eq "client") {
                         }
 
                         push(@ret_list, "memcpy(result->$3, ret.$3, sizeof(result->$3));");
-                    } elsif ($ret_member =~ m/(?:admin|remote)_nonnull_(secret|nwfilter|nwfilter_binding|node_device|interface|network|storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) {
+                    } elsif ($ret_member =~ m/(?:admin|remote)_nonnull_(secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port|storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)>;/) {
                         my $proc_name = name_to_TypeName($1);
 
                         if ($structprefix eq "admin") {
@@ -1574,7 +1576,7 @@ elsif ($mode eq "client") {
                     push(@ret_list, "VIR_FREE(ret.$1);");
                     $single_ret_var = "char *rv = NULL";
                     $single_ret_type = "char *";
-                } elsif ($ret_member =~ m/^remote_nonnull_(domain|network|storage_pool|storage_vol|node_device|interface|secret|nwfilter|nwfilter_binding|domain_snapshot) (\S+);/) {
+                } elsif ($ret_member =~ m/^remote_nonnull_(domain|network|network_port|storage_pool|storage_vol|node_device|interface|secret|nwfilter|nwfilter_binding|domain_snapshot) (\S+);/) {
                     my $name = $1;
                     my $arg_name = $2;
                     my $type_name = name_to_TypeName($name);
@@ -2134,6 +2136,8 @@ elsif ($mode eq "client") {
             if ($object ne "Connect") {
                 if ($object eq "StorageVol") {
                     push @argdecls, "virStoragePoolDefPtr pool";
+                } elsif ($object eq "NetworkPort") {
+                    push @argdecls, "virNetworkDefPtr net";
                 }
                 push @argdecls, "$objecttype $arg";
             }
@@ -2163,6 +2167,8 @@ elsif ($mode eq "client") {
                 if ($object ne "Connect") {
                     if ($object eq "StorageVol") {
                         push @argvars, "pool";
+                    } elsif ($object eq "NetworkPort") {
+                        push @argvars, "net";
                     }
                     push @argvars, $arg;
                 }
-- 
2.19.2


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