maint: improve debug of libvirt-{qemu,lxc} apis

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>
This commit is contained in:
Eric Blake 2013-12-19 15:43:46 -07:00
parent 80aed9f87f
commit 13f8372007
5 changed files with 87 additions and 81 deletions

View 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;

View 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();

View 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__);

View 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;

View 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
@ -26,6 +26,24 @@
# 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);