From nobody Wed May 14 11:36:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1522250323926864.5132178731747; Wed, 28 Mar 2018 08:18:43 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0CB0664D83; Wed, 28 Mar 2018 15:18:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBF4D63143; Wed, 28 Mar 2018 15:18:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 77E9E181BA07; Wed, 28 Mar 2018 15:18:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2SFIcav014168 for ; Wed, 28 Mar 2018 11:18:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id CB2241C722; Wed, 28 Mar 2018 15:18:38 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4108894581; Wed, 28 Mar 2018 15:18:38 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 28 Mar 2018 16:18:26 +0100 Message-Id: <20180328151832.7683-2-berrange@redhat.com> In-Reply-To: <20180328151832.7683-1-berrange@redhat.com> References: <20180328151832.7683-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/7] rpc: refactor way connection object is generated for remote dispatch X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 28 Mar 2018 15:18:42 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Calling a push_privconn method to directly push the connection object name into the arg list is inconvenient. Refactor so that we acquire the connection variable name upfront, and push it to the arg list separately. This allows various hardcoded usage of "priv->conn" to be parameterized. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: John Ferlan --- src/rpc/gendispatch.pl | 48 ++++++++++++++++++++++------------------------= -- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index fb15cc4849..e11921f3d9 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -110,19 +110,13 @@ sub name_to_TypeName { return $typename; } =20 -sub push_privconn { - my $args =3D shift; - - if (!@$args) { - if ($structprefix eq "admin") { - push(@$args, "priv->dmn"); - } else { - push(@$args, "priv->conn"); - } +sub get_conn_arg { + if ($structprefix eq "admin") { + return "priv->dmn"; } + return "priv->conn"; } =20 - # Read the input file (usually remote_protocol.x) and form an # opinion about the name, args and return type of each RPC. my ($name, $ProcName, $id, $flags, %calls, @calls, %opts); @@ -487,6 +481,8 @@ elsif ($mode eq "server") { my @free_list =3D (); my @free_list_on_error =3D ("virNetMessageSaveError(rerr);"); =20 + my $conn =3D get_conn_arg(); + # handle arguments to the function if ($argtype ne "void") { # node device is special, as it's identified by name @@ -497,7 +493,7 @@ elsif ($mode eq "server") { $has_node_device =3D 1; push(@vars_list, "virNodeDevicePtr dev =3D NULL"); push(@getters_list, - " if (!(dev =3D virNodeDeviceLookupByName(priv->co= nn, args->name)))\n" . + " if (!(dev =3D virNodeDeviceLookupByName($conn, a= rgs->name)))\n" . " goto cleanup;\n"); push(@args_list, "dev"); push(@free_list, @@ -513,7 +509,7 @@ elsif ($mode eq "server") { =20 push(@vars_list, "vir${type_name}Ptr $2 =3D NULL"); push(@getters_list, - " if (!($2 =3D get_nonnull_$1(priv->conn, args= ->$2)))\n" . + " if (!($2 =3D get_nonnull_$1($conn, args->$2)= ))\n" . " goto cleanup;\n"); push(@args_list, "$2"); push(@free_list, @@ -522,7 +518,7 @@ elsif ($mode eq "server") { push(@vars_list, "virDomainPtr dom =3D NULL"); push(@vars_list, "virDomainSnapshotPtr snapshot =3D NU= LL"); push(@getters_list, - " if (!(dom =3D get_nonnull_domain(priv->conn,= args->${1}.dom)))\n" . + " if (!(dom =3D get_nonnull_domain($conn, args= ->${1}.dom)))\n" . " goto cleanup;\n" . "\n" . " if (!(snapshot =3D get_nonnull_domain_snapsh= ot(dom, args->${1})))\n" . @@ -532,11 +528,11 @@ elsif ($mode eq "server") { " virObjectUnref(snapshot);\n" . " virObjectUnref(dom);"); } elsif ($args_member =3D~ m/^(?:(?:admin|remote)_string|r= emote_uuid) (\S+)<\S+>;/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; push(@args_list, "args->$1.$1_val"); push(@args_list, "args->$1.$1_len"); } elsif ($args_member =3D~ m/^(?:opaque|(?:admin|remote)_n= onnull_string) (\S+)<\S+>;(.*)$/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 my $cast =3D ""; my $arg_name =3D $1; @@ -553,7 +549,7 @@ elsif ($mode eq "server") { push(@args_list, "${cast}args->$arg_name.${arg_name}_v= al"); push(@args_list, "args->$arg_name.${arg_name}_len"); } elsif ($args_member =3D~ m/^(?:unsigned )?int (\S+)<\S+>= ;/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 push(@args_list, "args->$1.$1_val"); push(@args_list, "args->$1.$1_len"); @@ -561,7 +557,7 @@ elsif ($mode eq "server") { push(@vars_list, "virTypedParameterPtr $1 =3D NULL"); push(@vars_list, "int n$1 =3D 0"); if ($call->{ProcName} eq "NodeSetMemoryParameters") { - push(@args_list, "priv->conn"); + push(@args_list, "$conn"); } push(@args_list, "$1"); push(@args_list, "n$1"); @@ -576,25 +572,25 @@ elsif ($mode eq "server") { # just make all other array types fail die "unhandled type for argument value: $args_member"; } elsif ($args_member =3D~ m/^remote_uuid (\S+);/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 push(@args_list, "(unsigned char *) args->$1"); } elsif ($args_member =3D~ m/^(?:admin|remote)_string (\S+= );/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 push(@vars_list, "char *$1"); push(@optionals_list, "$1"); push(@args_list, "$1"); } elsif ($args_member =3D~ m/^(?:admin|remote)_nonnull_str= ing (\S+);/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 push(@args_list, "args->$1"); } elsif ($args_member =3D~ m/^(unsigned )?int (\S+);/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 push(@args_list, "args->$2"); } elsif ($args_member =3D~ m/^(unsigned )?hyper (\S+);/) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 my $arg_name =3D $2; =20 @@ -900,7 +896,7 @@ elsif ($mode eq "server") { # select struct type for multi-return-value functions if ($multi_ret) { if (defined $call->{ret_offset}) { - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 if ($modern_ret_as_list) { my $struct_name =3D name_to_TypeName($modern_ret_struc= t_name); @@ -1002,7 +998,7 @@ elsif ($mode eq "server") { if ($structprefix eq "admin") { print " if (!priv->dmn) {\n"; } else { - print " if (!priv->conn) {\n"; + print " if (!$conn) {\n"; } =20 print " virReportError(VIR_ERR_INTERNAL_ERROR, \"%s\", _(\"= connection not open\"));\n"; @@ -1034,7 +1030,7 @@ elsif ($mode eq "server") { } =20 if ($call->{streamflag} ne "none") { - print " if (!(st =3D virStreamNew(priv->conn, VIR_STREAM_NO= NBLOCK)))\n"; + print " if (!(st =3D virStreamNew($conn, VIR_STREAM_NONBLOC= K)))\n"; print " goto cleanup;\n"; print "\n"; print " if (!(stream =3D daemonCreateClientStream(client, s= t, remoteProgram, &msg->header, sparse)))\n"; @@ -1051,7 +1047,7 @@ elsif ($mode eq "server") { } elsif (!$multi_ret) { my $proc_name =3D $call->{ProcName}; =20 - push_privconn(\@args_list); + push(@args_list, $conn) if !@args_list; =20 if ($structprefix eq "qemu" && $call->{ProcName} =3D~ /^(Connect)?Domain/) { --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list