[PATCH 05/15] Teach gendispatch how to handle admin dispatching files

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

 



Since this is just a new option for gendispatch, it looks more like a
cleanup.  The only differences handled by it are connect pointers,
private pointers and API naming customs.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 src/rpc/gendispatch.pl | 128 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 78 insertions(+), 50 deletions(-)

diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl
index 199b38f..683bb92 100755
--- a/src/rpc/gendispatch.pl
+++ b/src/rpc/gendispatch.pl
@@ -49,6 +49,8 @@ my $procprefix = shift or die "missing procedure prefix argument";
 my $protocol = shift or die "missing protocol argument";
 my @autogen;

+my $connect_ptr = $structprefix eq "admin" ? "virAdmConnectPtr" : "virConnectPtr";
+my $prefix = ($structprefix eq "admin") ? "adm" : "vir";

 sub fixup_name {
     my $name = shift;
@@ -78,9 +80,12 @@ sub fixup_name {
 # Convert name_of_call to NameOfCall.
 sub name_to_ProcName {
     my $name = shift;
+    my $forcefix = $structprefix eq "admin";

     my @elems;
-    if ($name =~ /_/ || (lc $name) eq "open" || (lc $name) eq "close") {
+
+    if ($forcefix || $name =~ /_/ ||
+        (lc $name) eq "open" || (lc $name) eq "close") {
         @elems = split /_/, $name;
         @elems = map lc, @elems;
         @elems = map ucfirst, @elems;
@@ -104,6 +109,19 @@ sub name_to_TypeName {
     return $typename;
 }

+sub push_privconn {
+    my $args = shift;
+
+    if (!@$args) {
+        if ($structprefix eq "admin") {
+            push(@$args, "priv->srv");
+        } else {
+            push(@$args, "priv->conn");
+        }
+    }
+}
+
+
 # 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);
@@ -506,16 +524,11 @@ elsif ($mode eq "server") {
                          "    virObjectUnref(snapshot);\n" .
                          "    virObjectUnref(dom);");
                 } elsif ($args_member =~ m/^(?:remote_string|remote_uuid) (\S+)<\S+>;/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
-
+                    push_privconn(\@args_list);
                     push(@args_list, "args->$1.$1_val");
                     push(@args_list, "args->$1.$1_len");
                 } elsif ($args_member =~ m/^(?:opaque|remote_nonnull_string) (\S+)<\S+>;(.*)$/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
+                    push_privconn(\@args_list);

                     my $cast = "";
                     my $arg_name = $1;
@@ -532,9 +545,7 @@ elsif ($mode eq "server") {
                     push(@args_list, "${cast}args->$arg_name.${arg_name}_val");
                     push(@args_list, "args->$arg_name.${arg_name}_len");
                 } elsif ($args_member =~ m/^(?:unsigned )?int (\S+)<\S+>;/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
+                    push_privconn(\@args_list);

                     push(@args_list, "args->$1.$1_val");
                     push(@args_list, "args->$1.$1_len");
@@ -556,35 +567,25 @@ elsif ($mode eq "server") {
                     # just make all other array types fail
                     die "unhandled type for argument value: $args_member";
                 } elsif ($args_member =~ m/^remote_uuid (\S+);/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
+                    push_privconn(\@args_list);

                     push(@args_list, "(unsigned char *) args->$1");
                 } elsif ($args_member =~ m/^remote_string (\S+);/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
+                    push_privconn(\@args_list);

                     push(@vars_list, "char *$1");
                     push(@optionals_list, "$1");
                     push(@args_list, "$1");
                 } elsif ($args_member =~ m/^remote_nonnull_string (\S+);/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
+                    push_privconn(\@args_list);

                     push(@args_list, "args->$1");
                 } elsif ($args_member =~ m/^(unsigned )?int (\S+);/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
+                    push_privconn(\@args_list);

                     push(@args_list, "args->$2");
                 } elsif ($args_member =~ m/^(unsigned )?hyper (\S+);/) {
-                    if (! @args_list) {
-                        push(@args_list, "priv->conn");
-                    }
+                    push_privconn(\@args_list);

                     my $arg_name = $2;

@@ -819,9 +820,7 @@ elsif ($mode eq "server") {
                 die "multi-return-value without insert@<offset> annotation: $call->{ret}";
             }

-            if (! @args_list) {
-                push(@args_list, "priv->conn");
-            }
+            push_privconn(\@args_list);

             my $struct_name = $call->{ProcName};
             $struct_name =~ s/Get//;
@@ -871,7 +870,12 @@ elsif ($mode eq "server") {
         foreach my $var (@vars_list) {
             print "    $var;\n";
         }
-        print "    struct daemonClientPrivate *priv =\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") {
@@ -880,7 +884,13 @@ elsif ($mode eq "server") {
         }

         print "\n";
-        print "    if (!priv->conn) {\n";
+
+        if ($structprefix eq "admin") {
+            print "    if (!priv->srv) {\n";
+        } else {
+            print "    if (!priv->conn) {\n";
+        }
+
         print "        virReportError(VIR_ERR_INTERNAL_ERROR, \"%s\", _(\"connection not open\"));\n";
         print "        goto cleanup;\n";
         print "    }\n";
@@ -919,18 +929,15 @@ elsif ($mode eq "server") {
         }

         if ($rettype eq "void") {
-            print "    if (vir$call->{ProcName}(";
+            print "    if ($prefix$call->{ProcName}(";
             print join(', ', @args_list);
             print ") < 0)\n";
             print "        goto cleanup;\n";
             print "\n";
         } elsif (!$multi_ret) {
-            my $prefix = "";
             my $proc_name = $call->{ProcName};

-            if (! @args_list) {
-                push(@args_list, "priv->conn");
-            }
+            push_privconn(\@args_list);

             if ($structprefix eq "qemu" &&
                 $call->{ProcName} =~ /^(Connect)?Domain/) {
@@ -949,7 +956,7 @@ elsif ($mode eq "server") {
             }

             if ($single_ret_by_ref) {
-                print "    if (vir$prefix$proc_name(";
+                print "    if ($prefix$proc_name(";
                 print join(', ', @args_list);

                 if (defined $single_ret_var) {
@@ -958,7 +965,7 @@ elsif ($mode eq "server") {

                 print ") < 0)\n";
             } else {
-                print "    if (($single_ret_var = vir$prefix$proc_name(";
+                print "    if (($single_ret_var = $prefix$proc_name(";
                 print join(', ', @args_list);
                 print "))$single_ret_check)\n";
             }
@@ -1241,14 +1248,14 @@ elsif ($mode eq "client") {
                 }

                 if ($is_first_arg and $priv_src eq "conn") {
-                    unshift(@args_list, "virConnectPtr conn");
+                    unshift(@args_list, "$connect_ptr conn");
                 }

                 $is_first_arg = 0;
             }
         }

-        if (! @args_list) {
+        if (($structprefix ne "admin") && !@args_list) {
             push(@args_list, "virConnectPtr conn");
         }

@@ -1442,7 +1449,11 @@ elsif ($mode eq "client") {
             my $proc = $call->{ProcName};
             my $extra = $structprefix;
             $extra =~ s/^(\w)/uc $1/e;
-            $proc =~ s/^(Domain)(.*)/$1 . $extra . $2/e;
+            if ($structprefix eq "admin") {
+                $proc = $extra . $proc;
+            } else {
+                $proc =~ s/^(Domain)(.*)/$1 . $extra . $2/e;
+            }
             print "remote$proc(";
         }

@@ -1451,7 +1462,11 @@ elsif ($mode eq "client") {
         print ")\n";
         print "{\n";
         print "    $single_ret_var;\n";
-        print "    struct private_data *priv = $priv_src->privateData;\n";
+        if ($structprefix eq "admin") {
+            print "    remoteAdminPrivPtr priv = $priv_src->privateData;\n";
+        } else {
+            print "    struct private_data *priv = $priv_src->privateData;\n";
+        }

         foreach my $var (@vars_list) {
             print "    $var;\n";
@@ -1466,7 +1481,11 @@ elsif ($mode eq "client") {
         }

         print "\n";
-        print "    remoteDriverLock(priv);\n";
+        if ($structprefix eq "admin") {
+            print "    remoteAdminLock(priv);\n";
+        } else {
+            print "    remoteDriverLock(priv);\n";
+        }

         if ($call->{streamflag} ne "none") {
             print "\n";
@@ -1546,8 +1565,12 @@ elsif ($mode eq "client") {
             $callflags = "REMOTE_CALL_LXC";
         }

+        if ($structprefix ne "admin") {
+            $priv_src = "$priv_src, priv";
+        }
+
         print "\n";
-        print "    if (call($priv_src, priv, $callflags, $call->{constname},\n";
+        print "    if (call($priv_src, $callflags, $call->{constname},\n";
         print "             (xdrproc_t)xdr_$argtype, (char *)$call_args,\n";
         print "             (xdrproc_t)xdr_$rettype, (char *)$call_ret) == -1) {\n";

@@ -1622,7 +1645,12 @@ elsif ($mode eq "client") {

         print join("\n", @free_list);

-        print "    remoteDriverUnlock(priv);\n";
+        if ($structprefix eq "admin") {
+            print "    remoteAdminUnlock(priv);\n";
+        } else {
+            print "    remoteDriverUnlock(priv);\n";
+        }
+
         print "    return rv;\n";
         print "}\n";
     }
@@ -1682,7 +1710,7 @@ elsif ($mode eq "client") {
         next if $call->{acl}->[0] eq "none";

         if ($mode eq "aclsym") {
-            my $apiname = "vir" . $call->{ProcName};
+            my $apiname = $prefix . $call->{ProcName};
             if ($structprefix eq "qemu") {
                 $apiname =~ s/(vir(Connect)?Domain)/${1}Qemu/;
             } elsif ($structprefix eq "lxc") {
@@ -1722,7 +1750,7 @@ elsif ($mode eq "client") {
                 }
             }

-            my $apiname = "vir" . $call->{ProcName};
+            my $apiname = $prefix . $call->{ProcName};
             if ($structprefix eq "qemu") {
                 $apiname =~ s/(vir(Connect)?Domain)/${1}Qemu/;
             } elsif ($structprefix eq "lxc") {
@@ -1735,7 +1763,7 @@ elsif ($mode eq "client") {
             $object =~ s/^(\w)/uc $1/e;
             $object =~ s/_(\w)/uc $1/e;
             $object =~ s/Nwfilter/NWFilter/;
-            my $objecttype = "vir" . $object . "DefPtr";
+            my $objecttype = $prefix . $object . "DefPtr";
             $apiname .= $action . "ACL";

             if ($arg eq "interface") {
@@ -1743,7 +1771,7 @@ elsif ($mode eq "client") {
             }

             my @argdecls;
-            push @argdecls, "virConnectPtr conn";
+            push @argdecls, "$connect_ptr conn";
             if ($object ne "Connect") {
                 if ($object eq "StorageVol") {
                     push @argdecls, "virStoragePoolDefPtr pool";
@@ -1834,7 +1862,7 @@ elsif ($mode eq "client") {
         sub generate_aclapi {
             my $call = shift;

-            my $apiname = "vir" . $call->{ProcName};
+            my $apiname = $prefix . $call->{ProcName};
             if ($structprefix eq "qemu") {
                 $apiname =~ s/(vir(Connect)?Domain)/${1}Qemu/;
             } elsif ($structprefix eq "lxc") {
-- 
2.3.5

--
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]