aufs: debug, from aufs2.2-3.0
[zen-stable.git] / fs / aufs / debug.h
blob9d9d8e4880450316959c5bc4828c39985b590c6b
1 /*
2 * Copyright (C) 2005-2011 Junjiro R. Okajima
4 * This program, aufs is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * debug print functions
23 #ifndef __AUFS_DEBUG_H__
24 #define __AUFS_DEBUG_H__
26 #ifdef __KERNEL__
28 #include <asm/system.h>
29 #include <linux/bug.h>
30 /* #include <linux/err.h> */
31 #include <linux/init.h>
32 #include <linux/module.h>
33 #include <linux/kallsyms.h>
34 /* #include <linux/kernel.h> */
35 #include <linux/delay.h>
36 /* #include <linux/kd.h> */
37 #include <linux/sysrq.h>
38 #include <linux/aufs_type.h>
40 #ifdef CONFIG_AUFS_DEBUG
41 #define AuDebugOn(a) BUG_ON(a)
43 /* module parameter */
44 extern int aufs_debug;
45 static inline void au_debug(int n)
47 aufs_debug = n;
48 smp_mb();
51 static inline int au_debug_test(void)
53 return aufs_debug;
55 #else
56 #define AuDebugOn(a) do {} while (0)
57 AuStubVoid(au_debug, int n)
58 AuStubInt0(au_debug_test, void)
59 #endif /* CONFIG_AUFS_DEBUG */
61 /* ---------------------------------------------------------------------- */
63 /* debug print */
65 #define AuDbg(fmt, ...) do { \
66 if (au_debug_test()) \
67 pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
68 } while (0)
69 #define AuLabel(l) AuDbg(#l "\n")
70 #define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__)
71 #define AuWarn1(fmt, ...) do { \
72 static unsigned char _c; \
73 if (!_c++) \
74 pr_warning(fmt, ##__VA_ARGS__); \
75 } while (0)
77 #define AuErr1(fmt, ...) do { \
78 static unsigned char _c; \
79 if (!_c++) \
80 pr_err(fmt, ##__VA_ARGS__); \
81 } while (0)
83 #define AuIOErr1(fmt, ...) do { \
84 static unsigned char _c; \
85 if (!_c++) \
86 AuIOErr(fmt, ##__VA_ARGS__); \
87 } while (0)
89 #define AuUnsupportMsg "This operation is not supported." \
90 " Please report this application to aufs-users ML."
91 #define AuUnsupport(fmt, ...) do { \
92 pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
93 dump_stack(); \
94 } while (0)
96 #define AuTraceErr(e) do { \
97 if (unlikely((e) < 0)) \
98 AuDbg("err %d\n", (int)(e)); \
99 } while (0)
101 #define AuTraceErrPtr(p) do { \
102 if (IS_ERR(p)) \
103 AuDbg("err %ld\n", PTR_ERR(p)); \
104 } while (0)
106 /* dirty macros for debug print, use with "%.*s" and caution */
107 #define AuLNPair(qstr) (qstr)->len, (qstr)->name
108 #define AuDLNPair(d) AuLNPair(&(d)->d_name)
110 /* ---------------------------------------------------------------------- */
112 struct au_sbinfo;
113 struct au_finfo;
114 struct dentry;
115 #ifdef CONFIG_AUFS_DEBUG
116 extern char *au_plevel;
117 struct au_nhash;
118 void au_dpri_whlist(struct au_nhash *whlist);
119 struct au_vdir;
120 void au_dpri_vdir(struct au_vdir *vdir);
121 struct inode;
122 void au_dpri_inode(struct inode *inode);
123 void au_dpri_dalias(struct inode *inode);
124 void au_dpri_dentry(struct dentry *dentry);
125 struct file;
126 void au_dpri_file(struct file *filp);
127 struct super_block;
128 void au_dpri_sb(struct super_block *sb);
130 void au_dbg_sleep_jiffy(int jiffy);
131 struct iattr;
132 void au_dbg_iattr(struct iattr *ia);
134 #define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
135 void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
136 void au_dbg_verify_dir_parent(struct dentry *dentry, unsigned int sigen);
137 void au_dbg_verify_nondir_parent(struct dentry *dentry, unsigned int sigen);
138 void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
139 void au_dbg_verify_kthread(void);
141 int __init au_debug_init(void);
142 void au_debug_sbinfo_init(struct au_sbinfo *sbinfo);
143 #define AuDbgWhlist(w) do { \
144 AuDbg(#w "\n"); \
145 au_dpri_whlist(w); \
146 } while (0)
148 #define AuDbgVdir(v) do { \
149 AuDbg(#v "\n"); \
150 au_dpri_vdir(v); \
151 } while (0)
153 #define AuDbgInode(i) do { \
154 AuDbg(#i "\n"); \
155 au_dpri_inode(i); \
156 } while (0)
158 #define AuDbgDAlias(i) do { \
159 AuDbg(#i "\n"); \
160 au_dpri_dalias(i); \
161 } while (0)
163 #define AuDbgDentry(d) do { \
164 AuDbg(#d "\n"); \
165 au_dpri_dentry(d); \
166 } while (0)
168 #define AuDbgFile(f) do { \
169 AuDbg(#f "\n"); \
170 au_dpri_file(f); \
171 } while (0)
173 #define AuDbgSb(sb) do { \
174 AuDbg(#sb "\n"); \
175 au_dpri_sb(sb); \
176 } while (0)
178 #define AuDbgSleep(sec) do { \
179 AuDbg("sleep %d sec\n", sec); \
180 ssleep(sec); \
181 } while (0)
183 #define AuDbgSleepJiffy(jiffy) do { \
184 AuDbg("sleep %d jiffies\n", jiffy); \
185 au_dbg_sleep_jiffy(jiffy); \
186 } while (0)
188 #define AuDbgIAttr(ia) do { \
189 AuDbg("ia_valid 0x%x\n", (ia)->ia_valid); \
190 au_dbg_iattr(ia); \
191 } while (0)
193 #define AuDbgSym(addr) do { \
194 char sym[KSYM_SYMBOL_LEN]; \
195 sprint_symbol(sym, (unsigned long)addr); \
196 AuDbg("%s\n", sym); \
197 } while (0)
199 #define AuInfoSym(addr) do { \
200 char sym[KSYM_SYMBOL_LEN]; \
201 sprint_symbol(sym, (unsigned long)addr); \
202 AuInfo("%s\n", sym); \
203 } while (0)
204 #else
205 AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
206 AuStubVoid(au_dbg_verify_dir_parent, struct dentry *dentry, unsigned int sigen)
207 AuStubVoid(au_dbg_verify_nondir_parent, struct dentry *dentry,
208 unsigned int sigen)
209 AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
210 AuStubVoid(au_dbg_verify_kthread, void)
211 AuStubInt0(__init au_debug_init, void)
212 AuStubVoid(au_debug_sbinfo_init, struct au_sbinfo *sbinfo)
214 #define AuDbgWhlist(w) do {} while (0)
215 #define AuDbgVdir(v) do {} while (0)
216 #define AuDbgInode(i) do {} while (0)
217 #define AuDbgDAlias(i) do {} while (0)
218 #define AuDbgDentry(d) do {} while (0)
219 #define AuDbgFile(f) do {} while (0)
220 #define AuDbgSb(sb) do {} while (0)
221 #define AuDbgSleep(sec) do {} while (0)
222 #define AuDbgSleepJiffy(jiffy) do {} while (0)
223 #define AuDbgIAttr(ia) do {} while (0)
224 #define AuDbgSym(addr) do {} while (0)
225 #define AuInfoSym(addr) do {} while (0)
226 #endif /* CONFIG_AUFS_DEBUG */
228 /* ---------------------------------------------------------------------- */
230 #ifdef CONFIG_AUFS_MAGIC_SYSRQ
231 int __init au_sysrq_init(void);
232 void au_sysrq_fin(void);
234 #ifdef CONFIG_HW_CONSOLE
235 #define au_dbg_blocked() do { \
236 WARN_ON(1); \
237 handle_sysrq('w'); \
238 } while (0)
239 #else
240 AuStubVoid(au_dbg_blocked, void)
241 #endif
243 #else
244 AuStubInt0(__init au_sysrq_init, void)
245 AuStubVoid(au_sysrq_fin, void)
246 AuStubVoid(au_dbg_blocked, void)
247 #endif /* CONFIG_AUFS_MAGIC_SYSRQ */
249 #endif /* __KERNEL__ */
250 #endif /* __AUFS_DEBUG_H__ */