[libvirt] [PATCHv2 02/27] maint: print flags in hex during debug

Eric Blake eblake at redhat.com
Fri Jul 8 19:25:44 UTC 2011


Continuation of commit 313ac7fd, and enforce things with a syntax
check.

Technically, virNetServerClientCalculateHandleMode is not printing
a mode_t, but rather a collection of VIR_EVENT_HANDLE_* bits;
however, these bits are < 8, so there is no different in the
output, and that was the easiest way to silence the new syntax check.

* cfg.mk (sc_flags_debug): New syntax check.
(exclude_file_name_regexp--sc_flags_debug): Add exemptions.
* src/fdstream.c (virFDStreamOpenFileInternal): Print flags in
hex, mode_t in octal.
* src/libvirt-qemu.c (virDomainQemuMonitorCommand): Likewise.
* src/locking/lock_driver_nop.c (virLockManagerNopInit): Likewise.
* src/locking/lock_driver_sanlock.c (virLockManagerSanlockInit):
Likewise.
* src/locking/lock_manager.c: Likewise.
* src/qemu/qemu_migration.c: Likewise.
* src/qemu/qemu_monitor.c: Likewise.
* src/rpc/virnetserverclient.c
(virNetServerClientCalculateHandleMode): Print mode with %o.
---

v2: new patch, first new syntax check

 cfg.mk                            |   11 +++++++++++
 src/fdstream.c                    |    2 +-
 src/libvirt-qemu.c                |    5 +++--
 src/locking/lock_driver_nop.c     |    3 ++-
 src/locking/lock_driver_sanlock.c |    3 ++-
 src/locking/lock_manager.c        |   11 ++++++-----
 src/qemu/qemu_migration.c         |   16 ++++++++--------
 src/qemu/qemu_monitor.c           |   10 +++++-----
 src/rpc/virnetserverclient.c      |    2 +-
 9 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/cfg.mk b/cfg.mk
index f266bb0..24539b1 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -269,6 +269,15 @@ sc_avoid_write:
 	halt='consider using safewrite instead of write'		\
 	  $(_sc_search_regexp)

+# In debug statements, print flags as bitmask and mode_t as octal.
+sc_flags_debug:
+	@prohibit='\<mode=%[0-9.]*[diux]'				\
+	halt='debug mode_t values with %o'				\
+	  $(_sc_search_regexp)
+	@prohibit='\<flags=%[0-9.]*l*[diou]'				\
+	halt='debug flag values with %x'				\
+	  $(_sc_search_regexp)
+
 # Avoid functions that can lead to double-close bugs.
 sc_prohibit_close:
 	@prohibit='([^>.]|^)\<[fp]?close *\('				\
@@ -623,6 +632,8 @@ exclude_file_name_regexp--sc_avoid_write = \

 exclude_file_name_regexp--sc_bindtextdomain = ^(tests|examples)/

+exclude_file_name_regexp--sc_flags_debug = ^docs/
+
 exclude_file_name_regexp--sc_libvirt_unmarked_diagnostics = \
   ^src/rpc/gendispatch\.pl$$

diff --git a/src/fdstream.c b/src/fdstream.c
index 54f8198..c9fe2f3 100644
--- a/src/fdstream.c
+++ b/src/fdstream.c
@@ -516,7 +516,7 @@ virFDStreamOpenFileInternal(virStreamPtr st,
     int errfd = -1;
     pid_t pid = 0;

-    VIR_DEBUG("st=%p path=%s flags=%d offset=%llu length=%llu mode=%d delete=%d",
+    VIR_DEBUG("st=%p path=%s flags=%x offset=%llu length=%llu mode=%o delete=%d",
               st, path, flags, offset, length, mode, delete);

     if (flags & O_CREAT)
diff --git a/src/libvirt-qemu.c b/src/libvirt-qemu.c
index 46727c8..f03f804 100644
--- a/src/libvirt-qemu.c
+++ b/src/libvirt-qemu.c
@@ -2,7 +2,7 @@
  * libvirt-qemu.c: Interfaces for the libvirt library to handle qemu-specific
  *                 APIs.
  *
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 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
@@ -42,7 +42,8 @@ virDomainQemuMonitorCommand(virDomainPtr domain, const char *cmd,
 {
     virConnectPtr conn;

-    VIR_DEBUG("domain=%p, cmd=%s, result=%p, flags=%u", domain, cmd, result, flags);
+    VIR_DEBUG("domain=%p, cmd=%s, result=%p, flags=%x",
+              domain, cmd, result, flags);

     virResetLastError();

diff --git a/src/locking/lock_driver_nop.c b/src/locking/lock_driver_nop.c
index 0fab54c..0dcd794 100644
--- a/src/locking/lock_driver_nop.c
+++ b/src/locking/lock_driver_nop.c
@@ -31,7 +31,8 @@ static int virLockManagerNopInit(unsigned int version,
                                  const char *configFile,
                                  unsigned int flags)
 {
-    VIR_DEBUG("version=%u configFile=%s flags=%u", version, NULLSTR(configFile), flags);
+    VIR_DEBUG("version=%u configFile=%s flags=%x",
+              version, NULLSTR(configFile), flags);

     return 0;
 }
diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c
index cd2bbb5..e6b2f1b 100644
--- a/src/locking/lock_driver_sanlock.c
+++ b/src/locking/lock_driver_sanlock.c
@@ -265,7 +265,8 @@ static int virLockManagerSanlockInit(unsigned int version,
                                      const char *configFile,
                                      unsigned int flags)
 {
-    VIR_DEBUG("version=%u configFile=%s flags=%u", version, NULLSTR(configFile), flags);
+    VIR_DEBUG("version=%u configFile=%s flags=%x",
+              version, NULLSTR(configFile), flags);
     virCheckFlags(0, -1);

     if (driver)
diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c
index 4ee7f44..d27cf8f 100644
--- a/src/locking/lock_manager.c
+++ b/src/locking/lock_manager.c
@@ -286,7 +286,7 @@ virLockManagerPtr virLockManagerNew(virLockManagerPluginPtr plugin,
                                     unsigned int flags)
 {
     virLockManagerPtr lock;
-    VIR_DEBUG("plugin=%p type=%u nparams=%zu params=%p flags=%u",
+    VIR_DEBUG("plugin=%p type=%u nparams=%zu params=%p flags=%x",
               plugin, type, nparams, params, flags);
     virLockManagerLogParams(nparams, params);

@@ -315,7 +315,7 @@ int virLockManagerAddResource(virLockManagerPtr lock,
                               virLockManagerParamPtr params,
                               unsigned int flags)
 {
-    VIR_DEBUG("lock=%p type=%u name=%s nparams=%zu params=%p flags=%u",
+    VIR_DEBUG("lock=%p type=%u name=%s nparams=%zu params=%p flags=%x",
               lock, type, name, nparams, params, flags);
     virLockManagerLogParams(nparams, params);

@@ -332,7 +332,8 @@ int virLockManagerAcquire(virLockManagerPtr lock,
                           unsigned int flags,
                           int *fd)
 {
-    VIR_DEBUG("lock=%p state='%s' flags=%u fd=%p", lock, NULLSTR(state), flags, fd);
+    VIR_DEBUG("lock=%p state='%s' flags=%x fd=%p",
+              lock, NULLSTR(state), flags, fd);

     CHECK_MANAGER(drvAcquire, -1);

@@ -347,7 +348,7 @@ int virLockManagerRelease(virLockManagerPtr lock,
                           char **state,
                           unsigned int flags)
 {
-    VIR_DEBUG("lock=%p state=%p flags=%u", lock, state, flags);
+    VIR_DEBUG("lock=%p state=%p flags=%x", lock, state, flags);

     CHECK_MANAGER(drvRelease, -1);

@@ -359,7 +360,7 @@ int virLockManagerInquire(virLockManagerPtr lock,
                           char **state,
                           unsigned int flags)
 {
-    VIR_DEBUG("lock=%p state=%p flags=%u", lock, state, flags);
+    VIR_DEBUG("lock=%p state=%p flags=%x", lock, state, flags);

     CHECK_MANAGER(drvInquire, -1);

diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d7b27a0..48fc0c0 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1443,7 +1443,7 @@ static int doNativeMigrate(struct qemud_driver *driver,
     unsigned int background_flags = QEMU_MONITOR_MIGRATE_BACKGROUND;
     qemuMigrationCookiePtr mig = NULL;
     VIR_DEBUG("driver=%p, vm=%p, uri=%s, cookiein=%s, cookieinlen=%d, "
-              "cookieout=%p, cookieoutlen=%p, flags=%u, dname=%s, resource=%lu",
+              "cookieout=%p, cookieoutlen=%p, flags=%x, dname=%s, resource=%lu",
               driver, vm, uri, NULLSTR(cookiein), cookieinlen,
               cookieout, cookieoutlen, flags, NULLSTR(dname), resource);

@@ -1661,7 +1661,7 @@ static int doTunnelMigrate(struct qemud_driver *driver,
     qemuMigrationCookiePtr mig = NULL;
     qemuMigrationIOThreadPtr iothread = NULL;
     VIR_DEBUG("driver=%p, vm=%p, st=%p, cookiein=%s, cookieinlen=%d, "
-              "cookieout=%p, cookieoutlen=%p, flags=%lu, resource=%lu",
+              "cookieout=%p, cookieoutlen=%p, flags=%lx, resource=%lu",
               driver, vm, st, NULLSTR(cookiein), cookieinlen,
               cookieout, cookieoutlen, flags, resource);

@@ -1886,7 +1886,7 @@ static int doPeer2PeerMigrate2(struct qemud_driver *driver,
     int cancelled;
     virStreamPtr st = NULL;
     VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, vm=%p, dconnuri=%s, "
-              "flags=%lu, dname=%s, resource=%lu",
+              "flags=%lx, dname=%s, resource=%lu",
               driver, sconn, dconn, vm, NULLSTR(dconnuri),
               flags, NULLSTR(dname), resource);

@@ -2029,7 +2029,7 @@ static int doPeer2PeerMigrate3(struct qemud_driver *driver,
     int cancelled;
     virStreamPtr st = NULL;
     VIR_DEBUG("driver=%p, sconn=%p, dconn=%p, vm=%p, xmlin=%s, "
-              "dconnuri=%s, uri=%s, flags=%lu, dname=%s, resource=%lu",
+              "dconnuri=%s, uri=%s, flags=%lx, dname=%s, resource=%lu",
               driver, sconn, dconn, vm, NULLSTR(xmlin),
               NULLSTR(dconnuri), NULLSTR(uri), flags,
               NULLSTR(dname), resource);
@@ -2199,7 +2199,7 @@ static int doPeer2PeerMigrate(struct qemud_driver *driver,
     virConnectPtr dconn = NULL;
     bool p2p;
     VIR_DEBUG("driver=%p, sconn=%p, vm=%p, xmlin=%s, dconnuri=%s, "
-              "uri=%s, flags=%lu, dname=%s, resource=%lu",
+              "uri=%s, flags=%lx, dname=%s, resource=%lu",
               driver, sconn, vm, NULLSTR(xmlin), NULLSTR(dconnuri),
               NULLSTR(uri), flags, NULLSTR(dname), resource);

@@ -2278,7 +2278,7 @@ int qemuMigrationPerform(struct qemud_driver *driver,
     qemuDomainObjPrivatePtr priv = vm->privateData;
     VIR_DEBUG("driver=%p, conn=%p, vm=%p, xmlin=%s, dconnuri=%s, "
               "uri=%s, cookiein=%s, cookieinlen=%d, cookieout=%p, "
-              "cookieoutlen=%p, flags=%lu, dname=%s, resource=%lu, v3proto=%d",
+              "cookieoutlen=%p, flags=%lx, dname=%s, resource=%lu, v3proto=%d",
               driver, conn, vm, NULLSTR(xmlin), NULLSTR(dconnuri),
               NULLSTR(uri), NULLSTR(cookiein), cookieinlen,
               cookieout, cookieoutlen, flags, NULLSTR(dname),
@@ -2444,7 +2444,7 @@ qemuMigrationFinish(struct qemud_driver *driver,
     qemuDomainObjPrivatePtr priv = NULL;
     qemuMigrationCookiePtr mig = NULL;
     VIR_DEBUG("driver=%p, dconn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
-              "cookieout=%p, cookieoutlen=%p, flags=%lu, retcode=%d",
+              "cookieout=%p, cookieoutlen=%p, flags=%lx, retcode=%d",
               driver, dconn, vm, NULLSTR(cookiein), cookieinlen,
               cookieout, cookieoutlen, flags, retcode);
     virErrorPtr orig_err = NULL;
@@ -2612,7 +2612,7 @@ int qemuMigrationConfirm(struct qemud_driver *driver,
     virDomainEventPtr event = NULL;
     int rv = -1;
     VIR_DEBUG("driver=%p, conn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
-              "flags=%u, retcode=%d",
+              "flags=%x, retcode=%d",
               driver, conn, vm, NULLSTR(cookiein), cookieinlen,
               flags, retcode);

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 8573262..0ce822b 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1513,7 +1513,7 @@ int qemuMonitorMigrateToFd(qemuMonitorPtr mon,
                            int fd)
 {
     int ret;
-    VIR_DEBUG("mon=%p fd=%d flags=%u",
+    VIR_DEBUG("mon=%p fd=%d flags=%x",
           mon, fd, flags);

     if (!mon) {
@@ -1546,7 +1546,7 @@ int qemuMonitorMigrateToHost(qemuMonitorPtr mon,
 {
     int ret;
     char *uri = NULL;
-    VIR_DEBUG("mon=%p hostname=%s port=%d flags=%u",
+    VIR_DEBUG("mon=%p hostname=%s port=%d flags=%x",
           mon, hostname, port, flags);

     if (!mon) {
@@ -1578,7 +1578,7 @@ int qemuMonitorMigrateToCommand(qemuMonitorPtr mon,
     char *argstr;
     char *dest = NULL;
     int ret = -1;
-    VIR_DEBUG("mon=%p argv=%p flags=%u",
+    VIR_DEBUG("mon=%p argv=%p flags=%x",
           mon, argv, flags);

     if (!mon) {
@@ -1619,7 +1619,7 @@ int qemuMonitorMigrateToFile(qemuMonitorPtr mon,
     char *dest = NULL;
     int ret = -1;
     char *safe_target = NULL;
-    VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%u",
+    VIR_DEBUG("mon=%p argv=%p target=%s offset=%llu flags=%x",
           mon, argv, target, offset, flags);

     if (!mon) {
@@ -1682,7 +1682,7 @@ int qemuMonitorMigrateToUnix(qemuMonitorPtr mon,
 {
     char *dest = NULL;
     int ret = -1;
-    VIR_DEBUG("mon=%p, unixfile=%s flags=%u",
+    VIR_DEBUG("mon=%p, unixfile=%s flags=%x",
           mon, unixfile, flags);

     if (!mon) {
diff --git a/src/rpc/virnetserverclient.c b/src/rpc/virnetserverclient.c
index 742c3a4..341981f 100644
--- a/src/rpc/virnetserverclient.c
+++ b/src/rpc/virnetserverclient.c
@@ -156,7 +156,7 @@ virNetServerClientCalculateHandleMode(virNetServerClientPtr client) {
         if (client->tx)
             mode |= VIR_EVENT_HANDLE_WRITABLE;
     }
-    VIR_DEBUG("mode=%d", mode);
+    VIR_DEBUG("mode=%o", mode);
     return mode;
 }

-- 
1.7.4.4




More information about the libvir-list mailing list