]> xenbits.xensource.com Git - libvirt.git/commitdiff
maint: improve debug of libvirt-{qemu,lxc} apis
authorEric Blake <eblake@redhat.com>
Thu, 19 Dec 2013 22:43:46 +0000 (15:43 -0700)
committerEric Blake <eblake@redhat.com>
Fri, 3 Jan 2014 05:17:11 +0000 (22:17 -0700)
I noticed that the virDomainQemuMonitorCommand debug output wasn't
telling me the name of the domain it was working on.  While it was
easy enough to determine which pointer matches the domain based on
other log messages, it is nicer to be consistent.

* src/util/viruuid.h (VIR_UUID_DEBUG): Moved here from...
* src/libvirt.c (VIR_UUID_DEBUG): ...here.
(VIR_ARG15, VIR_HAS_COMMA, VIR_DOMAIN_DEBUG_EXPAND)
(VIR_DOMAIN_DEBUG_PASTE, VIR_DOMAIN_DEBUG_0, VIR_DOMAIN_DEBUG_1)
(VIR_DOMAIN_DEBUG_2, VIR_DOMAIN_DEBUG): Move...
* src/datatypes.h: ...here.
* src/libvirt-qemu.c (virDomainQemuMonitorCommand)
(virDomainQemuAgentCommand): Better debug messages.
* src/libvirt-lxc.c (virDomainLxcOpenNamespace): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
src/datatypes.h
src/libvirt-lxc.c
src/libvirt-qemu.c
src/libvirt.c
src/util/viruuid.h

index 6026bb0ebbdaa80da65a2e0ac011081e50714d73..23fe7b00be86e4bf3df74c15d393ff458cb01b56 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * datatypes.h: management of structs for public data types
  *
- * Copyright (C) 2006-2008, 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2006-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -94,6 +94,64 @@ extern virClassPtr virStoragePoolClass;
     (VIR_IS_SNAPSHOT(obj) && VIR_IS_DOMAIN((obj)->domain))
 
 
+/* Helper macros to implement VIR_DOMAIN_DEBUG using just C99.  This
+ * assumes you pass fewer than 15 arguments to VIR_DOMAIN_DEBUG, but
+ * can easily be expanded if needed.
+ *
+ * Note that gcc provides extensions of "define a(b...) b" or
+ * "define a(b,...) b,##__VA_ARGS__" as a means of eliding a comma
+ * when no var-args are present, but we don't want to require gcc.
+ */
+# define VIR_ARG15(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, \
+                   _11, _12, _13, _14, _15, ...) _15
+# define VIR_HAS_COMMA(...) VIR_ARG15(__VA_ARGS__, \
+                                      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
+
+/* Form the name VIR_DOMAIN_DEBUG_[01], then call that macro,
+ * according to how many arguments are present.  Two-phase due to
+ * macro expansion rules.  */
+# define VIR_DOMAIN_DEBUG_EXPAND(a, b, ...)      \
+    VIR_DOMAIN_DEBUG_PASTE(a, b, __VA_ARGS__)
+# define VIR_DOMAIN_DEBUG_PASTE(a, b, ...)       \
+    a##b(__VA_ARGS__)
+
+/* Internal use only, when VIR_DOMAIN_DEBUG has one argument.  */
+# define VIR_DOMAIN_DEBUG_0(dom)                 \
+    VIR_DOMAIN_DEBUG_2(dom, "%s", "")
+
+/* Internal use only, when VIR_DOMAIN_DEBUG has three or more arguments.  */
+# define VIR_DOMAIN_DEBUG_1(dom, fmt, ...)       \
+    VIR_DOMAIN_DEBUG_2(dom, ", " fmt, __VA_ARGS__)
+
+/* Internal use only, with final format.  */
+# define VIR_DOMAIN_DEBUG_2(dom, fmt, ...)                              \
+    do {                                                                \
+        char _uuidstr[VIR_UUID_STRING_BUFLEN];                          \
+        const char *_domname = NULL;                                    \
+                                                                        \
+        if (!VIR_IS_DOMAIN(dom)) {                                      \
+            memset(_uuidstr, 0, sizeof(_uuidstr));                      \
+        } else {                                                        \
+            virUUIDFormat((dom)->uuid, _uuidstr);                       \
+            _domname = (dom)->name;                                     \
+        }                                                               \
+                                                                        \
+        VIR_DEBUG("dom=%p, (VM: name=%s, uuid=%s)" fmt,                 \
+                  dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__);       \
+    } while (0)
+
+/**
+ * VIR_DOMAIN_DEBUG:
+ * @dom: domain
+ * @fmt: optional format for additional information
+ * @...: optional arguments corresponding to @fmt.
+ */
+# define VIR_DOMAIN_DEBUG(...)                          \
+    VIR_DOMAIN_DEBUG_EXPAND(VIR_DOMAIN_DEBUG_,          \
+                            VIR_HAS_COMMA(__VA_ARGS__), \
+                            __VA_ARGS__)
+
+
 typedef struct _virConnectCloseCallbackData virConnectCloseCallbackData;
 typedef virConnectCloseCallbackData *virConnectCloseCallbackDataPtr;
 
index c8cdcea70ea2528f01008b2d08ba9e4157c50ae4..b69f6ca082769d4a8e3c1318f3f6dc180c2e144c 100644 (file)
@@ -2,7 +2,7 @@
  * libvirt-lxc.c: Interfaces for the libvirt library to handle lxc-specific
  *                 APIs.
  *
- * Copyright (C) 2012-2013 Red Hat, Inc.
+ * Copyright (C) 2012-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -28,6 +28,7 @@
 #include "virfile.h"
 #include "virlog.h"
 #include "virprocess.h"
+#include "viruuid.h"
 #include "datatypes.h"
 #ifdef WITH_SELINUX
 # include <selinux/selinux.h>
@@ -69,8 +70,7 @@ virDomainLxcOpenNamespace(virDomainPtr domain,
 {
     virConnectPtr conn;
 
-    VIR_DEBUG("domain=%p, fdlist=%p flags=%x",
-              domain, fdlist, flags);
+    VIR_DOMAIN_DEBUG(domain, "fdlist=%p flags=%x", fdlist, flags);
 
     virResetLastError();
 
index 83fb3b3ab4ec69d910adaae26a4ce94be19d223e..661e9ff5de5837fe2f7a1babe599c1821d66eb8e 100644 (file)
@@ -2,7 +2,7 @@
  * libvirt-qemu.c: Interfaces for the libvirt library to handle qemu-specific
  *                 APIs.
  *
- * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2010-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@
 
 #include "virerror.h"
 #include "virlog.h"
+#include "viruuid.h"
 #include "datatypes.h"
 
 #define VIR_FROM_THIS VIR_FROM_NONE
@@ -75,8 +76,8 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
 {
     virConnectPtr conn;
 
-    VIR_DEBUG("domain=%p, cmd=%s, result=%p, flags=%x",
-              domain, cmd, result, flags);
+    VIR_DOMAIN_DEBUG(domain, "cmd=%s, result=%p, flags=%x",
+                     cmd, result, flags);
 
     virResetLastError();
 
@@ -213,8 +214,8 @@ virDomainQemuAgentCommand(virDomainPtr domain,
     virConnectPtr conn;
     char *ret;
 
-    VIR_DEBUG("domain=%p, cmd=%s, timeout=%d, flags=%x",
-              domain, cmd, timeout, flags);
+    VIR_DOMAIN_DEBUG(domain, "cmd=%s, timeout=%d, flags=%x",
+                     cmd, timeout, flags);
 
     if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
         virLibDomainError(NULL, VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
index 69ee4acf92798a7c5174b12024882c47f29f2a86..79735bbf191e488290ec012a552804c51eab8d82 100644 (file)
@@ -341,77 +341,6 @@ static struct gcry_thread_cbs virTLSThreadImpl = {
 };
 #endif /* WITH_GNUTLS_GCRYPT */
 
-/* Helper macros to implement VIR_DOMAIN_DEBUG using just C99.  This
- * assumes you pass fewer than 15 arguments to VIR_DOMAIN_DEBUG, but
- * can easily be expanded if needed.
- *
- * Note that gcc provides extensions of "define a(b...) b" or
- * "define a(b,...) b,##__VA_ARGS__" as a means of eliding a comma
- * when no var-args are present, but we don't want to require gcc.
- */
-#define VIR_ARG15(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, ...) _15
-#define VIR_HAS_COMMA(...) VIR_ARG15(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0)
-
-/* Form the name VIR_DOMAIN_DEBUG_[01], then call that macro,
- * according to how many arguments are present.  Two-phase due to
- * macro expansion rules.  */
-#define VIR_DOMAIN_DEBUG_EXPAND(a, b, ...)      \
-    VIR_DOMAIN_DEBUG_PASTE(a, b, __VA_ARGS__)
-#define VIR_DOMAIN_DEBUG_PASTE(a, b, ...)       \
-    a##b(__VA_ARGS__)
-
-/* Internal use only, when VIR_DOMAIN_DEBUG has one argument.  */
-#define VIR_DOMAIN_DEBUG_0(dom)                 \
-    VIR_DOMAIN_DEBUG_2(dom, "%s", "")
-
-/* Internal use only, when VIR_DOMAIN_DEBUG has three or more arguments.  */
-#define VIR_DOMAIN_DEBUG_1(dom, fmt, ...)       \
-    VIR_DOMAIN_DEBUG_2(dom, ", " fmt, __VA_ARGS__)
-
-/* Internal use only, with final format.  */
-#define VIR_DOMAIN_DEBUG_2(dom, fmt, ...)                               \
-    do {                                                                \
-        char _uuidstr[VIR_UUID_STRING_BUFLEN];                          \
-        const char *_domname = NULL;                                    \
-                                                                        \
-        if (!VIR_IS_DOMAIN(dom)) {                                      \
-            memset(_uuidstr, 0, sizeof(_uuidstr));                      \
-        } else {                                                        \
-            virUUIDFormat((dom)->uuid, _uuidstr);                       \
-            _domname = (dom)->name;                                     \
-        }                                                               \
-                                                                        \
-        VIR_DEBUG("dom=%p, (VM: name=%s, uuid=%s)" fmt,                 \
-                  dom, NULLSTR(_domname), _uuidstr, __VA_ARGS__);       \
-    } while (0)
-
-/**
- * VIR_DOMAIN_DEBUG:
- * @dom: domain
- * @fmt: optional format for additional information
- * @...: optional arguments corresponding to @fmt.
- */
-#define VIR_DOMAIN_DEBUG(...)                           \
-    VIR_DOMAIN_DEBUG_EXPAND(VIR_DOMAIN_DEBUG_,          \
-                            VIR_HAS_COMMA(__VA_ARGS__), \
-                            __VA_ARGS__)
-
-/**
- * VIR_UUID_DEBUG:
- * @conn: connection
- * @uuid: possibly null UUID array
- */
-#define VIR_UUID_DEBUG(conn, uuid)                              \
-    do {                                                        \
-        if (uuid) {                                             \
-            char _uuidstr[VIR_UUID_STRING_BUFLEN];              \
-            virUUIDFormat(uuid, _uuidstr);                      \
-            VIR_DEBUG("conn=%p, uuid=%s", conn, _uuidstr);      \
-        } else {                                                \
-            VIR_DEBUG("conn=%p, uuid=(null)", conn);            \
-        }                                                       \
-    } while (0)
-
 
 static bool virGlobalError = false;
 static virOnceControl virGlobalOnce = VIR_ONCE_CONTROL_INITIALIZER;
index bebd338161b4000d4bb6feeb13ddcd4658a66e8d..5790a173648e4f825aef2f41126bc1ef99acda3c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * viruuid.h: helper APIs for dealing with UUIDs
  *
- * Copyright (C) 2007, 2011, 2012 Red Hat, Inc.
+ * Copyright (C) 2007, 2011-2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 
 # include "internal.h"
 
+
+/**
+ * VIR_UUID_DEBUG:
+ * @conn: connection
+ * @uuid: possibly null UUID array
+ */
+# define VIR_UUID_DEBUG(conn, uuid)                             \
+    do {                                                        \
+        if (uuid) {                                             \
+            char _uuidstr[VIR_UUID_STRING_BUFLEN];              \
+            virUUIDFormat(uuid, _uuidstr);                      \
+            VIR_DEBUG("conn=%p, uuid=%s", conn, _uuidstr);      \
+        } else {                                                \
+            VIR_DEBUG("conn=%p, uuid=(null)", conn);            \
+        }                                                       \
+    } while (0)
+
+
 int virSetHostUUIDStr(const char *host_uuid);
 int virGetHostUUID(unsigned char *host_uuid) ATTRIBUTE_NONNULL(1);