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

[libvirt] [PATCH 3/4] Simplify remote driver error reporting



Remove redundant error reporting functions which obscured the
filename/line number reporting. Removed code which created a
virDomain/virNetwork object, since those are silently dropped
in error reporting functions now

* src/remote_internal.c: Remove error() and errorf() in favour of
 macros, and remove server_error in favour of direct call

Signed-off-by: Daniel P. Berrange <berrange redhat com>
---
 src/remote_internal.c |   84 ++++++++++--------------------------------------
 1 files changed, 18 insertions(+), 66 deletions(-)

diff --git a/src/remote_internal.c b/src/remote_internal.c
index eefead0..76032ae 100644
--- a/src/remote_internal.c
+++ b/src/remote_internal.c
@@ -206,10 +206,13 @@ static int remoteAuthSASL (virConnectPtr conn, struct private_data *priv, int in
 static int remoteAuthPolkit (virConnectPtr conn, struct private_data *priv, int in_open,
                              virConnectAuthPtr auth);
 #endif /* HAVE_POLKIT */
-static void error (virConnectPtr conn, virErrorNumber code, const char *info);
-static void errorf (virConnectPtr conn, virErrorNumber code,
-                     const char *fmt, ...) ATTRIBUTE_FORMAT(printf, 3, 4);
-static void server_error (virConnectPtr conn, remote_error *err);
+#define error(conn, code, info)                                 \
+    virReportErrorHelper(conn, VIR_FROM_QEMU, code, __FILE__,   \
+                         __FUNCTION__, __LINE__, "%s", info)
+#define errorf(conn, code, fmt...)                              \
+    virReportErrorHelper(conn, VIR_FROM_QEMU, code, __FILE__,   \
+                         __FUNCTION__, __LINE__, fmt)
+
 static virDomainPtr get_nonnull_domain (virConnectPtr conn, remote_nonnull_domain domain);
 static virNetworkPtr get_nonnull_network (virConnectPtr conn, remote_nonnull_network network);
 static virInterfacePtr get_nonnull_interface (virConnectPtr conn, remote_nonnull_interface iface);
@@ -7090,8 +7093,17 @@ cleanup:
             STRPREFIX(*thiscall->err.message, "unknown procedure")) {
             rv = -2;
         } else {
-            server_error (flags & REMOTE_CALL_IN_OPEN ? NULL : conn,
-                          &thiscall->err);
+            virRaiseErrorFull(flags & REMOTE_CALL_IN_OPEN ? NULL : conn,
+                              __FILE__, __FUNCTION__, __LINE__,
+                              thiscall->err.domain,
+                              thiscall->err.code,
+                              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 ? *thiscall->err.message : NULL);
             rv = -1;
         }
         xdr_free((xdrproc_t)xdr_remote_error,  (char *)&thiscall->err);
@@ -7236,66 +7248,6 @@ remoteDomainEventQueueFlush(int timer ATTRIBUTE_UNUSED, void *opaque)
 }
 
 
-/* For errors internal to this library. */
-static void
-error (virConnectPtr conn, virErrorNumber code, const char *info)
-{
-    const char *errmsg;
-
-    errmsg = virErrorMsg (code, info);
-    virRaiseError (conn, NULL, NULL, VIR_FROM_REMOTE,
-                     code, VIR_ERR_ERROR, errmsg, info, NULL, 0, 0,
-                     errmsg, info);
-}
-
-/* For errors internal to this library.
-   Identical to the above, but with a format string and optional params.  */
-static void
-errorf (virConnectPtr conn, virErrorNumber code, const char *fmt, ...)
-{
-    const char *errmsg;
-    va_list args;
-    char errorMessage[256];
-
-    if (fmt) {
-        va_start(args, fmt);
-        vsnprintf(errorMessage, sizeof errorMessage - 1, fmt, args);
-        va_end(args);
-    } else {
-        errorMessage[0] = '\0';
-    }
-
-    errmsg = virErrorMsg (code, errorMessage);
-    virRaiseError (conn, NULL, NULL, VIR_FROM_REMOTE,
-                     code, VIR_ERR_ERROR,
-                     errmsg, errorMessage, NULL, -1, -1,
-                     errmsg, errorMessage);
-}
-
-/* For errors generated on the server side and sent back to us. */
-static void
-server_error (virConnectPtr conn, remote_error *err)
-{
-    virDomainPtr dom;
-    virNetworkPtr net;
-
-    /* Get the domain and network, if set. */
-    dom = err->dom ? get_nonnull_domain (conn, *err->dom) : NULL;
-    net = err->net ? get_nonnull_network (conn, *err->net) : NULL;
-
-    virRaiseError (conn, dom, net,
-                     err->domain, err->code, err->level,
-                     err->str1 ? *err->str1 : NULL,
-                     err->str2 ? *err->str2 : NULL,
-                     err->str3 ? *err->str3 : NULL,
-                     err->int1, err->int2,
-                     "%s", err->message ? *err->message : NULL);
-    if (dom)
-        virDomainFree(dom);
-    if (net)
-        virNetworkFree(net);
-}
-
 /* 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,
-- 
1.6.2.5


-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|


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