[libvirt] [PATCH] convert missing server entry points into unsupported errors

Daniel Veillard veillard at redhat.com
Tue Dec 22 10:14:35 UTC 2009


  If using a remote access, sometimes an RPC entry point is not
available, and currently we just end up with a raw:
   error: unknown procedure: xxx
error, while this should be more cleanly reported as an unsupported
entry point like for local access, e.g when calling an older RHEL-5.3

without patch

paphio:~/libvirt -> tools/virsh --connect xen+ssh://root@test3 dominfo
test5
Id:             1
Name:           test5
UUID:           62cd4e2e-5117-e4ba-2dbf-68a37031c3e4
OS Type:        linux
State:          idle
CPU(s):         1
CPU time:       254.5s
Max memory:     524288 kB
Used memory:    524108 kB
error: unknown procedure: 122

with patch

paphio:~/libvirt -> tools/virsh --connect xen+ssh://root@test3 dominfo
test5
Id:             1
Name:           test5
UUID:           62cd4e2e-5117-e4ba-2dbf-68a37031c3e4
OS Type:        linux
State:          idle
CPU(s):         1
CPU time:       254.6s
Max memory:     524288 kB
Used memory:    524080 kB

paphio:~/libvirt ->

the application knows that some feature may not be avilable but expects
the VIR_ERR_NO_SUPPORT to be reported, not an internal RPC problem,

I also noticed that we do

  "%s", thiscall->err.message ? *thiscall->err.message : NULL);

for passing the error message, which is a sure way to crash if there is
no error message and changing this to

  "%s", thiscall->err.message ? *thiscall->err.message : "unknown");

I expect the server to always return an error message in practice, but
this need fixing.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/
-------------- next part --------------
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 23fd0e3..b6ace7f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -8530,6 +8530,27 @@ cleanup:
             thiscall->err.message &&
             STRPREFIX(*thiscall->err.message, "unknown procedure")) {
             rv = -2;
+        } else if (thiscall->err.domain == VIR_FROM_REMOTE &&
+                   thiscall->err.code == VIR_ERR_RPC &&
+                   thiscall->err.level == VIR_ERR_ERROR &&
+                   thiscall->err.message &&
+                   STRPREFIX(*thiscall->err.message, "unknown procedure")) {
+            /*
+             * convert missing remote entry points into the unsupported
+             * feature error
+             */
+            virRaiseErrorFull(flags & REMOTE_CALL_IN_OPEN ? NULL : conn,
+                              __FILE__, __FUNCTION__, __LINE__,
+                              thiscall->err.domain,
+                              VIR_ERR_NO_SUPPORT,
+                              thiscall->err.level,
+                              thiscall->err.str1 ? *thiscall->err.str1 : NULL,
+                              thiscall->err.str2 ? *thiscall->err.str2 : NULL,
+                              thiscall->err.str3 ? *thiscall->err.str3 : NULL,
+                              thiscall->err.int1,
+                              thiscall->err.int2,
+                              "%s", *thiscall->err.message);
+            rv = -1;
         } else {
             virRaiseErrorFull(flags & REMOTE_CALL_IN_OPEN ? NULL : conn,
                               __FILE__, __FUNCTION__, __LINE__,
@@ -8541,7 +8562,7 @@ cleanup:
                               thiscall->err.str3 ? *thiscall->err.str3 : NULL,
                               thiscall->err.int1,
                               thiscall->err.int2,
-                              "%s", thiscall->err.message ? *thiscall->err.message : NULL);
+                              "%s", thiscall->err.message ? *thiscall->err.message : "unknown");
             rv = -1;
         }
         xdr_free((xdrproc_t)xdr_remote_error,  (char *)&thiscall->err);


More information about the libvir-list mailing list