remote: add support for new network port APIs

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

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2018-12-10 17:43:42 +00:00
parent e69444e179
commit 0e2ef3a954
5 changed files with 346 additions and 7 deletions

View File

@ -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;
@ -7175,6 +7177,54 @@ remoteDispatchStorageVolGetInfoFlags(virNetServerPtr server ATTRIBUTE_UNUSED,
}
static int
remoteDispatchNetworkPortGetParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client ATTRIBUTE_UNUSED,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr,
remote_network_port_get_parameters_args *args,
remote_network_port_get_parameters_ret *ret)
{
int rv = -1;
virNetworkPortPtr port = NULL;
virTypedParameterPtr params = NULL;
int nparams = 0;
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->networkConn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
goto cleanup;
}
if (!(port = get_nonnull_network_port(priv->networkConn, args->port)))
goto cleanup;
if (virNetworkPortGetParameters(port, &params, &nparams, args->flags) < 0)
goto cleanup;
if (nparams > REMOTE_NETWORK_PORT_PARAMETERS_MAX) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nparams too large"));
goto cleanup;
}
if (virTypedParamsSerialize(params, nparams,
(virTypedParameterRemotePtr *) &ret->params.params_val,
&ret->params.params_len,
args->flags) < 0)
goto cleanup;
rv = 0;
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
virObjectUnref(port);
virTypedParamsFree(params, nparams);
return rv;
}
/*----- Helpers. -----*/
/* get_nonnull_domain and get_nonnull_network turn an on-wire
@ -7198,6 +7248,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)
{
@ -7270,6 +7333,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)

View File

@ -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);
@ -8132,6 +8134,45 @@ remoteStorageVolGetInfoFlags(virStorageVolPtr vol,
}
static int
remoteNetworkPortGetParameters(virNetworkPortPtr port,
virTypedParameterPtr *params,
int *nparams,
unsigned int flags)
{
int rv = -1;
struct private_data *priv = port->net->conn->privateData;
remote_network_port_get_parameters_args args;
remote_network_port_get_parameters_ret ret;
remoteDriverLock(priv);
make_nonnull_network_port(&args.port, port);
args.flags = flags;
memset(&ret, 0, sizeof(ret));
if (call(port->net->conn, priv, 0, REMOTE_PROC_NETWORK_PORT_GET_PARAMETERS,
(xdrproc_t) xdr_remote_network_port_get_parameters_args, (char *) &args,
(xdrproc_t) xdr_remote_network_port_get_parameters_ret, (char *) &ret) == -1)
goto done;
if (virTypedParamsDeserialize((virTypedParameterRemotePtr) ret.params.params_val,
ret.params.params_len,
REMOTE_NETWORK_PORT_PARAMETERS_MAX,
params,
nparams) < 0)
goto cleanup;
rv = 0;
cleanup:
xdr_free((xdrproc_t) xdr_remote_network_port_get_parameters_ret, (char *) &ret);
done:
remoteDriverUnlock(priv);
return rv;
}
/* get_nonnull_domain and get_nonnull_network turn an on-wire
* (name, uuid) pair into virDomainPtr or virNetworkPtr object.
* These can return NULL if underlying memory allocations fail,
@ -8149,6 +8190,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)
{
@ -8216,6 +8270,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)
@ -8542,6 +8604,13 @@ static virNetworkDriver network_driver = {
.networkIsActive = remoteNetworkIsActive, /* 0.7.3 */
.networkIsPersistent = remoteNetworkIsPersistent, /* 0.7.3 */
.networkGetDHCPLeases = remoteNetworkGetDHCPLeases, /* 1.2.6 */
.networkListAllPorts = remoteNetworkListAllPorts, /* 5.5.0 */
.networkPortLookupByUUID = remoteNetworkPortLookupByUUID, /* 5.5.0 */
.networkPortCreateXML = remoteNetworkPortCreateXML, /* 5.5.0 */
.networkPortGetXMLDesc = remoteNetworkPortGetXMLDesc, /* 5.5.0 */
.networkPortSetParameters = remoteNetworkPortSetParameters, /* 5.5.0 */
.networkPortGetParameters = remoteNetworkPortGetParameters, /* 5.5.0 */
.networkPortDelete = remoteNetworkPortDelete, /* 5.5.0 */
};
static virInterfaceDriver interface_driver = {

View File

@ -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;
@ -263,6 +266,12 @@ const REMOTE_NODE_SEV_INFO_MAX = 64;
/* Upper limit on number of launch security information entries */
const REMOTE_DOMAIN_LAUNCH_SECURITY_INFO_PARAMS_MAX = 64;
/*
* Upper limit on list of network port parameters
*/
const REMOTE_NETWORK_PORT_PARAMETERS_MAX = 16;
/* UUID. VIR_UUID_BUFLEN definition comes from libvirt.h */
typedef opaque remote_uuid[VIR_UUID_BUFLEN];
@ -279,6 +288,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 +345,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;
@ -3573,6 +3588,68 @@ struct remote_connect_get_storage_pool_capabilities_ret {
remote_nonnull_string capabilities;
};
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_set_parameters_args {
remote_nonnull_network_port port;
remote_typed_param params<REMOTE_NETWORK_PORT_PARAMETERS_MAX>;
unsigned int flags;
};
struct remote_network_port_get_parameters_args {
remote_nonnull_network_port port;
int nparams;
unsigned int flags;
};
struct remote_network_port_get_parameters_ret {
remote_typed_param params<REMOTE_NETWORK_PORT_PARAMETERS_MAX>;
int nparams;
};
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. */
@ -6342,5 +6419,50 @@ enum remote_procedure {
* @generate: both
* @acl: connect:read
*/
REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES = 403
REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES = 403,
/**
* @generate: both
* @priority: high
* @acl: network:search_ports
* @aclfilter: network_port:getattr
*/
REMOTE_PROC_NETWORK_LIST_ALL_PORTS = 404,
/**
* @generate: both
* @priority: high
* @acl: network_port:getattr
*/
REMOTE_PROC_NETWORK_PORT_LOOKUP_BY_UUID = 405,
/**
* @generate: both
* @acl: network_port:create
*/
REMOTE_PROC_NETWORK_PORT_CREATE_XML = 406,
/**
* @generate: none
* @acl: network_port:read
*/
REMOTE_PROC_NETWORK_PORT_GET_PARAMETERS = 407,
/**
* @generate: both
* @acl: network_port:write
*/
REMOTE_PROC_NETWORK_PORT_SET_PARAMETERS = 408,
/**
* @generate: both
* @acl: network_port:read
*/
REMOTE_PROC_NETWORK_PORT_GET_XML_DESC = 409,
/**
* @generate: both
* @acl: network_port:delete
*/
REMOTE_PROC_NETWORK_PORT_DELETE = 410
};

View File

@ -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;
@ -2981,6 +2985,64 @@ struct remote_connect_get_storage_pool_capabilities_args {
struct remote_connect_get_storage_pool_capabilities_ret {
remote_nonnull_string capabilities;
};
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_set_parameters_args {
remote_nonnull_network_port port;
struct {
u_int params_len;
remote_typed_param * params_val;
} params;
u_int flags;
};
struct remote_network_port_get_parameters_args {
remote_nonnull_network_port port;
int nparams;
u_int flags;
};
struct remote_network_port_get_parameters_ret {
struct {
u_int params_len;
remote_typed_param * params_val;
} params;
int nparams;
};
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,
@ -3385,4 +3447,11 @@ enum remote_procedure {
REMOTE_PROC_CONNECT_LIST_ALL_NWFILTER_BINDINGS = 401,
REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS = 402,
REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES = 403,
REMOTE_PROC_NETWORK_LIST_ALL_PORTS = 404,
REMOTE_PROC_NETWORK_PORT_LOOKUP_BY_UUID = 405,
REMOTE_PROC_NETWORK_PORT_CREATE_XML = 406,
REMOTE_PROC_NETWORK_PORT_GET_PARAMETERS = 407,
REMOTE_PROC_NETWORK_PORT_SET_PARAMETERS = 408,
REMOTE_PROC_NETWORK_PORT_GET_XML_DESC = 409,
REMOTE_PROC_NETWORK_PORT_DELETE = 410,
};

View File

@ -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);
@ -2135,6 +2137,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";
}
@ -2164,6 +2168,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;
}