From: Vyacheslav Dubeyko <[email protected]>
Subject: [PATCH 24/24] nilfs2: introduce option of using dynamic debugging

This patch implements opportunity of dynamic debugging in NILFS2 driver.
It introduces CONFIG_NILFS2_USE_PR_DEBUG kernel configuration
option. Enabling of this option results in using of pr_debug()
instead of printk() and print_hex_dump_bytes() instead of
print_hex_dump(). If CONFIG_NILFS2_USE_PR_DEBUG is not set then
debugging messages are selected for printing in system log by means of
comparing of requested flags and DBG_MASK's flags set. Otherwise, the
behaviour of of pr_debug()/print_hex_dump_bytes()s are controlled via
writing to a control file in the 'debugfs' filesystem.

If CONFIG_NILFS2_USE_PR_DEBUG option is not set then it is used
printk()/print_hex_dump() for printing debugging messages in
system log.

Signed-off-by: Vyacheslav Dubeyko <[email protected]>
CC: Ryusuke Konishi <[email protected]>
---
 fs/nilfs2/Kconfig |   22 ++++++++++++++++++++++
 fs/nilfs2/debug.h |   33 +++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+)

diff --git a/fs/nilfs2/Kconfig b/fs/nilfs2/Kconfig
index 451a3a2..502419a 100644
--- a/fs/nilfs2/Kconfig
+++ b/fs/nilfs2/Kconfig
@@ -36,6 +36,24 @@ config NILFS2_DEBUG
 
 if NILFS2_DEBUG
 
+config NILFS2_USE_PR_DEBUG
+       bool "Use pr_debug() instead of printk()"
+       default n
+       select DYNAMIC_DEBUG
+       help
+         This option enables using of pr_debug() instead of printk()
+         and print_hex_dump_bytes() instead of print_hex_dump().
+
+         If CONFIG_NILFS2_USE_PR_DEBUG is not set then debugging messages are
+         selected for printing in system log by means of comparing of
+         requested flags and DBG_MASK's flags set. Otherwise, the behaviour
+         of of pr_debug()/print_hex_dump_bytes()s are controlled via writing
+         to a control file in the 'debugfs' filesystem.
+
+         If CONFIG_NILFS2_USE_PR_DEBUG option is not set then it is used
+         printk()/print_hex_dump() for printing debugging messages in
+         system log.
+
 config NILFS2_DEBUG_SHOW_ERRORS
        bool "Show internal errors"
        default n
@@ -60,6 +78,8 @@ config NILFS2_DEBUG_DUMP_STACK
          printed out for all called functions in the case of dynamic
          debug (CONFIG_NILFS2_USE_PR_DEBUG).
 
+if !NILFS2_USE_PR_DEBUG || (NILFS2_USE_PR_DEBUG && !DYNAMIC_DEBUG)
+
 config NILFS2_DEBUG_SUBSYSTEMS
        bool "Enable output from subsystems"
        depends on NILFS2_DEBUG
@@ -142,6 +162,8 @@ config NILFS2_DEBUG_HEXDUMP
 
 endif # NILFS2_DEBUG_SUBSYSTEMS
 
+endif # !NILFS2_USE_PR_DEBUG || (NILFS2_USE_PR_DEBUG && !DYNAMIC_DEBUG)
+
 endif # NILFS2_DEBUG
 
 endif # NILFS2_FS
diff --git a/fs/nilfs2/debug.h b/fs/nilfs2/debug.h
index 821fc75..585477e 100644
--- a/fs/nilfs2/debug.h
+++ b/fs/nilfs2/debug.h
@@ -173,6 +173,37 @@ static u32 DBG_MASK = (
 #define NILFS2_SUBSYS_MASK     0x0FFFFFFF
 #define NILFS2_DBG_OUT_MASK    0xF0000000
 
+#if (defined(CONFIG_NILFS2_USE_PR_DEBUG) && defined(CONFIG_DYNAMIC_DEBUG))
+
+#define nilfs2_printk(f, a...) \
+       do { \
+               pr_debug("NILFS DEBUG (%s, %d): %s:\n", \
+                       __FILE__, __LINE__, __func__); \
+               pr_debug(f, ## a); \
+       } while (0)
+
+#define nilfs2_debug(flg, f, a...) \
+       do { \
+               bool can_dump_stack = DBG_MASK & DBG_DUMP_STACK; \
+               bool should_dump_stack = flg & DBG_DUMP_STACK; \
+               nilfs2_printk(f, ## a); \
+               if (can_dump_stack && should_dump_stack) \
+                       dump_stack(); \
+       } while (0)
+
+#define nilfs2_print_hexdump(prefix, ptr, size) \
+       do { \
+               pr_debug("NILFS HEXDUMP (%s, %d): %s:\n", \
+                               __FILE__, __LINE__, __func__); \
+               print_hex_dump_bytes(prefix, \
+                               DUMP_PREFIX_ADDRESS, ptr, size); \
+       } while (0)
+
+#define nilfs2_hexdump(flg, prefix, ptr, size) \
+               nilfs2_print_hexdump(prefix, ptr, size)
+
+#else /* CONFIG_NILFS2_USE_PR_DEBUG && CONFIG_DYNAMIC_DEBUG */
+
 #define nilfs2_printk(f, a...) \
        do { \
                printk(KERN_DEBUG "NILFS DEBUG (%s, %d): %s:\n", \
@@ -221,6 +252,8 @@ static u32 DBG_MASK = (
                } \
        } while (0)
 
+#endif /* CONFIG_NILFS2_USE_PR_DEBUG && CONFIG_DYNAMIC_DEBUG */
+
 static inline int nilfs2_error_dbg(unsigned int flg,
                                    const unsigned char *file,
                                    int line,
-- 
1.7.9.5



--
To unsubscribe from this list: send the line "unsubscribe linux-nilfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to