]>
Commit | Line | Data |
---|---|---|
c088e31d SF |
1 | /* |
2 | * Copyright (C) 2005-2017 Junjiro R. Okajima | |
3 | * | |
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. | |
8 | * | |
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. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License | |
15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
17 | ||
18 | /* | |
19 | * debug print functions | |
20 | */ | |
21 | ||
22 | #ifndef __AUFS_DEBUG_H__ | |
23 | #define __AUFS_DEBUG_H__ | |
24 | ||
25 | #ifdef __KERNEL__ | |
26 | ||
27 | #include <linux/atomic.h> | |
28 | #include <linux/module.h> | |
29 | #include <linux/kallsyms.h> | |
30 | #include <linux/sysrq.h> | |
31 | ||
32 | #ifdef CONFIG_AUFS_DEBUG | |
33 | #define AuDebugOn(a) BUG_ON(a) | |
34 | ||
35 | /* module parameter */ | |
36 | extern atomic_t aufs_debug; | |
37 | static inline void au_debug_on(void) | |
38 | { | |
39 | atomic_inc(&aufs_debug); | |
40 | } | |
41 | static inline void au_debug_off(void) | |
42 | { | |
43 | atomic_dec_if_positive(&aufs_debug); | |
44 | } | |
45 | ||
46 | static inline int au_debug_test(void) | |
47 | { | |
48 | return atomic_read(&aufs_debug) > 0; | |
49 | } | |
50 | #else | |
51 | #define AuDebugOn(a) do {} while (0) | |
52 | AuStubVoid(au_debug_on, void) | |
53 | AuStubVoid(au_debug_off, void) | |
54 | AuStubInt0(au_debug_test, void) | |
55 | #endif /* CONFIG_AUFS_DEBUG */ | |
56 | ||
57 | #define param_check_atomic_t(name, p) __param_check(name, p, atomic_t) | |
58 | ||
59 | /* ---------------------------------------------------------------------- */ | |
60 | ||
61 | /* debug print */ | |
62 | ||
63 | #define AuDbg(fmt, ...) do { \ | |
64 | if (au_debug_test()) \ | |
65 | pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \ | |
66 | } while (0) | |
67 | #define AuLabel(l) AuDbg(#l "\n") | |
68 | #define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__) | |
69 | #define AuWarn1(fmt, ...) do { \ | |
70 | static unsigned char _c; \ | |
71 | if (!_c++) \ | |
72 | pr_warn(fmt, ##__VA_ARGS__); \ | |
73 | } while (0) | |
74 | ||
75 | #define AuErr1(fmt, ...) do { \ | |
76 | static unsigned char _c; \ | |
77 | if (!_c++) \ | |
78 | pr_err(fmt, ##__VA_ARGS__); \ | |
79 | } while (0) | |
80 | ||
81 | #define AuIOErr1(fmt, ...) do { \ | |
82 | static unsigned char _c; \ | |
83 | if (!_c++) \ | |
84 | AuIOErr(fmt, ##__VA_ARGS__); \ | |
85 | } while (0) | |
86 | ||
87 | #define AuUnsupportMsg "This operation is not supported." \ | |
88 | " Please report this application to aufs-users ML." | |
89 | #define AuUnsupport(fmt, ...) do { \ | |
90 | pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \ | |
91 | dump_stack(); \ | |
92 | } while (0) | |
93 | ||
94 | #define AuTraceErr(e) do { \ | |
95 | if (unlikely((e) < 0)) \ | |
96 | AuDbg("err %d\n", (int)(e)); \ | |
97 | } while (0) | |
98 | ||
99 | #define AuTraceErrPtr(p) do { \ | |
100 | if (IS_ERR(p)) \ | |
101 | AuDbg("err %ld\n", PTR_ERR(p)); \ | |
102 | } while (0) | |
103 | ||
104 | /* dirty macros for debug print, use with "%.*s" and caution */ | |
105 | #define AuLNPair(qstr) (qstr)->len, (qstr)->name | |
106 | ||
107 | /* ---------------------------------------------------------------------- */ | |
108 | ||
109 | struct dentry; | |
110 | #ifdef CONFIG_AUFS_DEBUG | |
111 | extern struct mutex au_dbg_mtx; | |
112 | extern char *au_plevel; | |
113 | struct au_nhash; | |
114 | void au_dpri_whlist(struct au_nhash *whlist); | |
115 | struct au_vdir; | |
116 | void au_dpri_vdir(struct au_vdir *vdir); | |
117 | struct inode; | |
118 | void au_dpri_inode(struct inode *inode); | |
119 | void au_dpri_dalias(struct inode *inode); | |
120 | void au_dpri_dentry(struct dentry *dentry); | |
121 | struct file; | |
122 | void au_dpri_file(struct file *filp); | |
123 | struct super_block; | |
124 | void au_dpri_sb(struct super_block *sb); | |
125 | ||
126 | #define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__) | |
127 | void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line); | |
128 | void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen); | |
129 | void au_dbg_verify_kthread(void); | |
130 | ||
131 | int __init au_debug_init(void); | |
132 | ||
133 | #define AuDbgWhlist(w) do { \ | |
134 | mutex_lock(&au_dbg_mtx); \ | |
135 | AuDbg(#w "\n"); \ | |
136 | au_dpri_whlist(w); \ | |
137 | mutex_unlock(&au_dbg_mtx); \ | |
138 | } while (0) | |
139 | ||
140 | #define AuDbgVdir(v) do { \ | |
141 | mutex_lock(&au_dbg_mtx); \ | |
142 | AuDbg(#v "\n"); \ | |
143 | au_dpri_vdir(v); \ | |
144 | mutex_unlock(&au_dbg_mtx); \ | |
145 | } while (0) | |
146 | ||
147 | #define AuDbgInode(i) do { \ | |
148 | mutex_lock(&au_dbg_mtx); \ | |
149 | AuDbg(#i "\n"); \ | |
150 | au_dpri_inode(i); \ | |
151 | mutex_unlock(&au_dbg_mtx); \ | |
152 | } while (0) | |
153 | ||
154 | #define AuDbgDAlias(i) do { \ | |
155 | mutex_lock(&au_dbg_mtx); \ | |
156 | AuDbg(#i "\n"); \ | |
157 | au_dpri_dalias(i); \ | |
158 | mutex_unlock(&au_dbg_mtx); \ | |
159 | } while (0) | |
160 | ||
161 | #define AuDbgDentry(d) do { \ | |
162 | mutex_lock(&au_dbg_mtx); \ | |
163 | AuDbg(#d "\n"); \ | |
164 | au_dpri_dentry(d); \ | |
165 | mutex_unlock(&au_dbg_mtx); \ | |
166 | } while (0) | |
167 | ||
168 | #define AuDbgFile(f) do { \ | |
169 | mutex_lock(&au_dbg_mtx); \ | |
170 | AuDbg(#f "\n"); \ | |
171 | au_dpri_file(f); \ | |
172 | mutex_unlock(&au_dbg_mtx); \ | |
173 | } while (0) | |
174 | ||
175 | #define AuDbgSb(sb) do { \ | |
176 | mutex_lock(&au_dbg_mtx); \ | |
177 | AuDbg(#sb "\n"); \ | |
178 | au_dpri_sb(sb); \ | |
179 | mutex_unlock(&au_dbg_mtx); \ | |
180 | } while (0) | |
181 | ||
182 | #define AuDbgSym(addr) do { \ | |
183 | char sym[KSYM_SYMBOL_LEN]; \ | |
184 | sprint_symbol(sym, (unsigned long)addr); \ | |
185 | AuDbg("%s\n", sym); \ | |
186 | } while (0) | |
187 | #else | |
188 | AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry) | |
189 | AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen) | |
190 | AuStubVoid(au_dbg_verify_kthread, void) | |
191 | AuStubInt0(__init au_debug_init, void) | |
192 | ||
193 | #define AuDbgWhlist(w) do {} while (0) | |
194 | #define AuDbgVdir(v) do {} while (0) | |
195 | #define AuDbgInode(i) do {} while (0) | |
196 | #define AuDbgDAlias(i) do {} while (0) | |
197 | #define AuDbgDentry(d) do {} while (0) | |
198 | #define AuDbgFile(f) do {} while (0) | |
199 | #define AuDbgSb(sb) do {} while (0) | |
200 | #define AuDbgSym(addr) do {} while (0) | |
201 | #endif /* CONFIG_AUFS_DEBUG */ | |
202 | ||
203 | /* ---------------------------------------------------------------------- */ | |
204 | ||
205 | #ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
206 | int __init au_sysrq_init(void); | |
207 | void au_sysrq_fin(void); | |
208 | ||
209 | #ifdef CONFIG_HW_CONSOLE | |
210 | #define au_dbg_blocked() do { \ | |
211 | WARN_ON(1); \ | |
212 | handle_sysrq('w'); \ | |
213 | } while (0) | |
214 | #else | |
215 | AuStubVoid(au_dbg_blocked, void) | |
216 | #endif | |
217 | ||
218 | #else | |
219 | AuStubInt0(__init au_sysrq_init, void) | |
220 | AuStubVoid(au_sysrq_fin, void) | |
221 | AuStubVoid(au_dbg_blocked, void) | |
222 | #endif /* CONFIG_AUFS_MAGIC_SYSRQ */ | |
223 | ||
224 | #endif /* __KERNEL__ */ | |
225 | #endif /* __AUFS_DEBUG_H__ */ |