提交 9cc8ecc8 编写于 作者: D Daniel P. Berrangé

remote: change generated methods to not directly access connection

The driver dispatch methods access the priv->conn variables directly.
In future we want to dynamically open the connections for the secondary
driver. Thus we want the methods to call a method to get the connection
handle instead of assuming the private variable is non-NULL.
Reviewed-by: NAndrea Bolognani <abologna@redhat.com>
Signed-off-by: NDaniel P. Berrangé <berrange@redhat.com>
上级 690f0275
...@@ -206,6 +206,15 @@ adminConnectGetLibVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED, ...@@ -206,6 +206,15 @@ adminConnectGetLibVersion(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
return 0; return 0;
} }
static virNetDaemonPtr
adminGetConn(virNetServerClientPtr client)
{
struct daemonAdmClientPrivate *priv =
virNetServerClientGetPrivateData(client);
return priv->dmn;
}
static int static int
adminDispatchServerGetThreadpoolParameters(virNetServerPtr server ATTRIBUTE_UNUSED, adminDispatchServerGetThreadpoolParameters(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client, virNetServerClientPtr client,
......
...@@ -112,6 +112,22 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors, ...@@ -112,6 +112,22 @@ remoteSerializeDomainDiskErrors(virDomainDiskErrorPtr errors,
remote_domain_disk_error **ret_errors_val, remote_domain_disk_error **ret_errors_val,
u_int *ret_errors_len); u_int *ret_errors_len);
static virConnectPtr
remoteGetHypervisorConn(virNetServerClientPtr client);
static virConnectPtr
remoteGetInterfaceConn(virNetServerClientPtr client);
static virConnectPtr
remoteGetNetworkConn(virNetServerClientPtr client);
static virConnectPtr
remoteGetNodeDevConn(virNetServerClientPtr client);
static virConnectPtr
remoteGetNWFilterConn(virNetServerClientPtr client);
static virConnectPtr
remoteGetSecretConn(virNetServerClientPtr client);
static virConnectPtr
remoteGetStorageConn(virNetServerClientPtr client);
#include "remote_daemon_dispatch_stubs.h" #include "remote_daemon_dispatch_stubs.h"
#include "remote_daemon_dispatch_qemu_stubs.h" #include "remote_daemon_dispatch_qemu_stubs.h"
#include "remote_daemon_dispatch_lxc_stubs.h" #include "remote_daemon_dispatch_lxc_stubs.h"
...@@ -1925,6 +1941,111 @@ static void remoteClientCloseFunc(virNetServerClientPtr client) ...@@ -1925,6 +1941,111 @@ static void remoteClientCloseFunc(virNetServerClientPtr client)
} }
static virConnectPtr
remoteGetHypervisorConn(virNetServerClientPtr client)
{
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->conn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hypervisor connection not open"));
return NULL;
}
return priv->conn;
}
static virConnectPtr
remoteGetInterfaceConn(virNetServerClientPtr client)
{
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->interfaceConn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hypervisor connection not open"));
return NULL;
}
return priv->interfaceConn;
}
static virConnectPtr
remoteGetNetworkConn(virNetServerClientPtr client)
{
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->networkConn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hypervisor connection not open"));
return NULL;
}
return priv->networkConn;
}
static virConnectPtr
remoteGetNodeDevConn(virNetServerClientPtr client)
{
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->nodedevConn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hypervisor connection not open"));
return NULL;
}
return priv->nodedevConn;
}
static virConnectPtr
remoteGetNWFilterConn(virNetServerClientPtr client)
{
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->nwfilterConn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hypervisor connection not open"));
return NULL;
}
return priv->nwfilterConn;
}
static virConnectPtr
remoteGetSecretConn(virNetServerClientPtr client)
{
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->secretConn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hypervisor connection not open"));
return NULL;
}
return priv->secretConn;
}
static virConnectPtr
remoteGetStorageConn(virNetServerClientPtr client)
{
struct daemonClientPrivate *priv =
virNetServerClientGetPrivateData(client);
if (!priv->storageConn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("hypervisor connection not open"));
return NULL;
}
return priv->storageConn;
}
void *remoteClientNew(virNetServerClientPtr client, void *remoteClientNew(virNetServerClientPtr client,
void *opaque ATTRIBUTE_UNUSED) void *opaque ATTRIBUTE_UNUSED)
{ {
......
...@@ -111,13 +111,29 @@ sub name_to_TypeName { ...@@ -111,13 +111,29 @@ sub name_to_TypeName {
return $typename; return $typename;
} }
sub get_conn_arg { sub get_conn_type {
if ($structprefix eq "admin") {
return "virNetDaemonPtr";
} else {
return "virConnectPtr";
}
}
sub get_conn_var {
if ($structprefix eq "admin") {
return "dmn";
} else {
return "conn";
}
}
sub get_conn_method {
my $proc = shift; my $proc = shift;
my $args = shift; my $args = shift;
my $rets = shift; my $rets = shift;
if ($structprefix eq "admin") { if ($structprefix eq "admin") {
return "priv->dmn"; return "adminGetConn";
} }
my @types; my @types;
...@@ -127,22 +143,22 @@ sub get_conn_arg { ...@@ -127,22 +143,22 @@ sub get_conn_arg {
# This correctly detects most APIs # This correctly detects most APIs
foreach my $type (@types) { foreach my $type (@types) {
if ($type =~ /remote_nonnull_interface/) { if ($type =~ /remote_nonnull_interface/) {
return "priv->interfaceConn"; return "remoteGetInterfaceConn";
} }
if ($type =~ /remote_nonnull_network/) { if ($type =~ /remote_nonnull_network/) {
return "priv->networkConn"; return "remoteGetNetworkConn";
} }
if ($type =~ /remote_nonnull_node_device/) { if ($type =~ /remote_nonnull_node_device/) {
return "priv->nodedevConn"; return "remoteGetNodeDevConn";
} }
if ($type =~ /remote_nonnull_nwfilter/) { if ($type =~ /remote_nonnull_nwfilter/) {
return "priv->nwfilterConn"; return "remoteGetNWFilterConn";
} }
if ($type =~ /remote_nonnull_secret/) { if ($type =~ /remote_nonnull_secret/) {
return "priv->secretConn"; return "remoteGetSecretConn";
} }
if ($type =~ /remote_nonnull_storage/) { if ($type =~ /remote_nonnull_storage/) {
return "priv->storageConn"; return "remoteGetStorageConn";
} }
} }
...@@ -150,25 +166,25 @@ sub get_conn_arg { ...@@ -150,25 +166,25 @@ sub get_conn_arg {
# return things which aren't objects. eg list # return things which aren't objects. eg list
# of pool names, or number of pools. # of pool names, or number of pools.
if ($proc =~ /Connect.*Interface/ || $proc =~ /InterfaceChange/) { if ($proc =~ /Connect.*Interface/ || $proc =~ /InterfaceChange/) {
return "priv->interfaceConn"; return "remoteGetInterfaceConn";
} }
if ($proc =~ /Connect.*Network/) { if ($proc =~ /Connect.*Network/) {
return "priv->networkConn"; return "remoteGetNetworkConn";
} }
if ($proc =~ /Node.*Device/) { if ($proc =~ /Node.*Device/) {
return "priv->nodedevConn"; return "remoteGetNodeDevConn";
} }
if ($proc =~ /Connect.*NWFilter/) { if ($proc =~ /Connect.*NWFilter/) {
return "priv->nwfilterConn"; return "remoteGetNWFilterConn";
} }
if ($proc =~ /Connect.*Secret/) { if ($proc =~ /Connect.*Secret/) {
return "priv->secretConn"; return "remoteGetSecretConn";
} }
if ($proc =~ /Connect.*Storage/) { if ($proc =~ /Connect.*Storage/) {
return "priv->storageConn"; return "remoteGetStorageConn";
} }
return "priv->conn"; return "remoteGetHypervisorConn";
} }
# Read the input file (usually remote_protocol.x) and form an # Read the input file (usually remote_protocol.x) and form an
...@@ -535,7 +551,9 @@ elsif ($mode eq "server") { ...@@ -535,7 +551,9 @@ elsif ($mode eq "server") {
my @free_list = (); my @free_list = ();
my @free_list_on_error = ("virNetMessageSaveError(rerr);"); my @free_list_on_error = ("virNetMessageSaveError(rerr);");
my $conn = get_conn_arg($call->{ProcName}, $call->{args_members}, $call->{ret_members}); my $conn_method = get_conn_method($call->{ProcName}, $call->{args_members}, $call->{ret_members});
my $conn_var = get_conn_var();
my $conn_type = get_conn_type();
# handle arguments to the function # handle arguments to the function
if ($argtype ne "void") { if ($argtype ne "void") {
...@@ -547,7 +565,7 @@ elsif ($mode eq "server") { ...@@ -547,7 +565,7 @@ elsif ($mode eq "server") {
$has_node_device = 1; $has_node_device = 1;
push(@vars_list, "virNodeDevicePtr dev = NULL"); push(@vars_list, "virNodeDevicePtr dev = NULL");
push(@getters_list, push(@getters_list,
" if (!(dev = virNodeDeviceLookupByName($conn, args->name)))\n" . " if (!(dev = virNodeDeviceLookupByName($conn_var, args->name)))\n" .
" goto cleanup;\n"); " goto cleanup;\n");
push(@args_list, "dev"); push(@args_list, "dev");
push(@free_list, push(@free_list,
...@@ -563,7 +581,7 @@ elsif ($mode eq "server") { ...@@ -563,7 +581,7 @@ elsif ($mode eq "server") {
push(@vars_list, "vir${type_name}Ptr $2 = NULL"); push(@vars_list, "vir${type_name}Ptr $2 = NULL");
push(@getters_list, push(@getters_list,
" if (!($2 = get_nonnull_$1($conn, args->$2)))\n" . " if (!($2 = get_nonnull_$1($conn_var, args->$2)))\n" .
" goto cleanup;\n"); " goto cleanup;\n");
push(@args_list, "$2"); push(@args_list, "$2");
push(@free_list, push(@free_list,
...@@ -574,7 +592,7 @@ elsif ($mode eq "server") { ...@@ -574,7 +592,7 @@ elsif ($mode eq "server") {
push(@vars_list, "virDomainPtr dom = NULL"); push(@vars_list, "virDomainPtr dom = NULL");
push(@vars_list, "virDomain${type_name}Ptr ${1} = NULL"); push(@vars_list, "virDomain${type_name}Ptr ${1} = NULL");
push(@getters_list, push(@getters_list,
" if (!(dom = get_nonnull_domain($conn, args->${2}.dom)))\n" . " if (!(dom = get_nonnull_domain($conn_var, args->${2}.dom)))\n" .
" goto cleanup;\n" . " goto cleanup;\n" .
"\n" . "\n" .
" if (!($1 = get_nonnull_domain_${1}(dom, args->$2)))\n" . " if (!($1 = get_nonnull_domain_${1}(dom, args->$2)))\n" .
...@@ -584,11 +602,11 @@ elsif ($mode eq "server") { ...@@ -584,11 +602,11 @@ elsif ($mode eq "server") {
" virObjectUnref($1);\n" . " virObjectUnref($1);\n" .
" virObjectUnref(dom);"); " virObjectUnref(dom);");
} elsif ($args_member =~ m/^(?:(?:admin|remote)_string|remote_uuid) (\S+)<\S+>;/) { } elsif ($args_member =~ m/^(?:(?:admin|remote)_string|remote_uuid) (\S+)<\S+>;/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
push(@args_list, "args->$1.$1_val"); push(@args_list, "args->$1.$1_val");
push(@args_list, "args->$1.$1_len"); push(@args_list, "args->$1.$1_len");
} elsif ($args_member =~ m/^(?:opaque|(?:admin|remote)_nonnull_string) (\S+)<\S+>;(.*)$/) { } elsif ($args_member =~ m/^(?:opaque|(?:admin|remote)_nonnull_string) (\S+)<\S+>;(.*)$/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
my $cast = ""; my $cast = "";
my $arg_name = $1; my $arg_name = $1;
...@@ -605,7 +623,7 @@ elsif ($mode eq "server") { ...@@ -605,7 +623,7 @@ elsif ($mode eq "server") {
push(@args_list, "${cast}args->$arg_name.${arg_name}_val"); push(@args_list, "${cast}args->$arg_name.${arg_name}_val");
push(@args_list, "args->$arg_name.${arg_name}_len"); push(@args_list, "args->$arg_name.${arg_name}_len");
} elsif ($args_member =~ m/^(?:unsigned )?int (\S+)<\S+>;/) { } elsif ($args_member =~ m/^(?:unsigned )?int (\S+)<\S+>;/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
push(@args_list, "args->$1.$1_val"); push(@args_list, "args->$1.$1_val");
push(@args_list, "args->$1.$1_len"); push(@args_list, "args->$1.$1_len");
...@@ -613,7 +631,7 @@ elsif ($mode eq "server") { ...@@ -613,7 +631,7 @@ elsif ($mode eq "server") {
push(@vars_list, "virTypedParameterPtr $1 = NULL"); push(@vars_list, "virTypedParameterPtr $1 = NULL");
push(@vars_list, "int n$1 = 0"); push(@vars_list, "int n$1 = 0");
if ($call->{ProcName} eq "NodeSetMemoryParameters") { if ($call->{ProcName} eq "NodeSetMemoryParameters") {
push(@args_list, "$conn"); push(@args_list, $conn_var);
} }
push(@args_list, "$1"); push(@args_list, "$1");
push(@args_list, "n$1"); push(@args_list, "n$1");
...@@ -628,25 +646,25 @@ elsif ($mode eq "server") { ...@@ -628,25 +646,25 @@ elsif ($mode eq "server") {
# just make all other array types fail # just make all other array types fail
die "unhandled type for argument value: $args_member"; die "unhandled type for argument value: $args_member";
} elsif ($args_member =~ m/^remote_uuid (\S+);/) { } elsif ($args_member =~ m/^remote_uuid (\S+);/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
push(@args_list, "(unsigned char *) args->$1"); push(@args_list, "(unsigned char *) args->$1");
} elsif ($args_member =~ m/^(?:admin|remote)_string (\S+);/) { } elsif ($args_member =~ m/^(?:admin|remote)_string (\S+);/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
push(@vars_list, "char *$1"); push(@vars_list, "char *$1");
push(@optionals_list, "$1"); push(@optionals_list, "$1");
push(@args_list, "$1"); push(@args_list, "$1");
} elsif ($args_member =~ m/^(?:admin|remote)_nonnull_string (\S+);/) { } elsif ($args_member =~ m/^(?:admin|remote)_nonnull_string (\S+);/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
push(@args_list, "args->$1"); push(@args_list, "args->$1");
} elsif ($args_member =~ m/^(unsigned )?int (\S+);/) { } elsif ($args_member =~ m/^(unsigned )?int (\S+);/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
push(@args_list, "args->$2"); push(@args_list, "args->$2");
} elsif ($args_member =~ m/^(unsigned )?hyper (\S+);/) { } elsif ($args_member =~ m/^(unsigned )?hyper (\S+);/) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
my $arg_name = $2; my $arg_name = $2;
...@@ -665,7 +683,7 @@ elsif ($mode eq "server") { ...@@ -665,7 +683,7 @@ elsif ($mode eq "server") {
push(@vars_list, "virNet${type_name}Ptr $2 = NULL"); push(@vars_list, "virNet${type_name}Ptr $2 = NULL");
push(@getters_list, push(@getters_list,
" if (!($2 = get_nonnull_$1($conn, args->$2)))\n" . " if (!($2 = get_nonnull_$1($conn_var, args->$2)))\n" .
" goto cleanup;\n"); " goto cleanup;\n");
push(@args_list, "$2"); push(@args_list, "$2");
push(@free_list, push(@free_list,
...@@ -676,7 +694,7 @@ elsif ($mode eq "server") { ...@@ -676,7 +694,7 @@ elsif ($mode eq "server") {
push(@vars_list, "virNetServerPtr srv = NULL"); push(@vars_list, "virNetServerPtr srv = NULL");
push(@vars_list, "virNetServer${type_name}Ptr $2 = NULL"); push(@vars_list, "virNetServer${type_name}Ptr $2 = NULL");
push(@getters_list, push(@getters_list,
" if (!(srv = get_nonnull_server($conn, args->$2.srv)))\n" . " if (!(srv = get_nonnull_server($conn_var, args->$2.srv)))\n" .
" goto cleanup;\n"); " goto cleanup;\n");
push(@getters_list, push(@getters_list,
" if (!($2 = get_nonnull_$1(srv, args->$2)))\n" . " if (!($2 = get_nonnull_$1(srv, args->$2)))\n" .
...@@ -952,7 +970,7 @@ elsif ($mode eq "server") { ...@@ -952,7 +970,7 @@ elsif ($mode eq "server") {
# select struct type for multi-return-value functions # select struct type for multi-return-value functions
if ($multi_ret) { if ($multi_ret) {
if (defined $call->{ret_offset}) { if (defined $call->{ret_offset}) {
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
if ($modern_ret_as_list) { if ($modern_ret_as_list) {
my $struct_name = name_to_TypeName($modern_ret_struct_name); my $struct_name = name_to_TypeName($modern_ret_struct_name);
...@@ -1032,13 +1050,6 @@ elsif ($mode eq "server") { ...@@ -1032,13 +1050,6 @@ elsif ($mode eq "server") {
print " $var;\n"; print " $var;\n";
} }
if ($structprefix eq "admin") {
print " struct daemonAdmClientPrivate *priv =\n";
} else {
print " struct daemonClientPrivate *priv =\n";
}
print " virNetServerClientGetPrivateData(client);\n";
if ($call->{streamflag} ne "none") { if ($call->{streamflag} ne "none") {
print " virStreamPtr st = NULL;\n"; print " virStreamPtr st = NULL;\n";
print " daemonClientStreamPtr stream = NULL;\n"; print " daemonClientStreamPtr stream = NULL;\n";
...@@ -1051,10 +1062,9 @@ elsif ($mode eq "server") { ...@@ -1051,10 +1062,9 @@ elsif ($mode eq "server") {
print "\n"; print "\n";
print " if (!$conn) {\n"; print " $conn_type $conn_var = $conn_method(client);\n";
print " virReportError(VIR_ERR_INTERNAL_ERROR, \"%s\", _(\"connection not open\"));\n"; print " if (!$conn_var) \n";
print " goto cleanup;\n"; print " goto cleanup;\n";
print " }\n";
print "\n"; print "\n";
if ($single_ret_as_list) { if ($single_ret_as_list) {
...@@ -1081,7 +1091,7 @@ elsif ($mode eq "server") { ...@@ -1081,7 +1091,7 @@ elsif ($mode eq "server") {
} }
if ($call->{streamflag} ne "none") { if ($call->{streamflag} ne "none") {
print " if (!(st = virStreamNew($conn, VIR_STREAM_NONBLOCK)))\n"; print " if (!(st = virStreamNew($conn_var, VIR_STREAM_NONBLOCK)))\n";
print " goto cleanup;\n"; print " goto cleanup;\n";
print "\n"; print "\n";
print " if (!(stream = daemonCreateClientStream(client, st, remoteProgram, &msg->header, sparse)))\n"; print " if (!(stream = daemonCreateClientStream(client, st, remoteProgram, &msg->header, sparse)))\n";
...@@ -1098,7 +1108,7 @@ elsif ($mode eq "server") { ...@@ -1098,7 +1108,7 @@ elsif ($mode eq "server") {
} elsif (!$multi_ret) { } elsif (!$multi_ret) {
my $proc_name = $call->{ProcName}; my $proc_name = $call->{ProcName};
push(@args_list, $conn) if !@args_list; push(@args_list, $conn_var) if !@args_list;
if ($structprefix eq "qemu" && if ($structprefix eq "qemu" &&
$call->{ProcName} =~ /^(Connect)?Domain/) { $call->{ProcName} =~ /^(Connect)?Domain/) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册