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