debug.h 5.67 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
/* SPDX-License-Identifier: GPL-2.0 */
/*
3
 * Copyright (C) 2005-2020 Junjiro R. Okajima
4
5
6
7
8
9
10
11
12
13
14
15
16
 *
 * This program, aufs is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
J. R. Okajima's avatar
J. R. Okajima committed
17
18
19
20
21
22
23
24
25
26
27
 */

/*
 * debug print functions
 */

#ifndef __AUFS_DEBUG_H__
#define __AUFS_DEBUG_H__

#ifdef __KERNEL__

J. R. Okajima's avatar
J. R. Okajima committed
28
29
#include <linux/atomic.h>
#include <linux/module.h>
30
#include <linux/kallsyms.h>
31
#include <linux/sysrq.h>
J. R. Okajima's avatar
J. R. Okajima committed
32

J. R. Okajima's avatar
J. R. Okajima committed
33
34
#ifdef CONFIG_AUFS_DEBUG
#define AuDebugOn(a)		BUG_ON(a)
J. R. Okajima's avatar
J. R. Okajima committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

/* module parameter */
extern atomic_t aufs_debug;
static inline void au_debug_on(void)
{
	atomic_inc(&aufs_debug);
}
static inline void au_debug_off(void)
{
	atomic_dec_if_positive(&aufs_debug);
}

static inline int au_debug_test(void)
{
	return atomic_read(&aufs_debug) > 0;
}
J. R. Okajima's avatar
J. R. Okajima committed
51
52
#else
#define AuDebugOn(a)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
53
54
55
AuStubVoid(au_debug_on, void)
AuStubVoid(au_debug_off, void)
AuStubInt0(au_debug_test, void)
J. R. Okajima's avatar
J. R. Okajima committed
56
57
#endif /* CONFIG_AUFS_DEBUG */

J. R. Okajima's avatar
J. R. Okajima committed
58
59
#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t)

J. R. Okajima's avatar
J. R. Okajima committed
60
61
62
63
64
65
66
67
68
/* ---------------------------------------------------------------------- */

/* debug print */

#define AuDbg(fmt, ...) do { \
	if (au_debug_test()) \
		pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \
} while (0)
#define AuLabel(l)		AuDbg(#l "\n")
J. R. Okajima's avatar
J. R. Okajima committed
69
#define AuIOErr(fmt, ...)	pr_err("I/O Error, " fmt, ##__VA_ARGS__)
70
71
72
73
74
#define AuWarn1(fmt, ...) do { \
	static unsigned char _c; \
	if (!_c++) \
		pr_warn(fmt, ##__VA_ARGS__); \
} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
75

J. R. Okajima's avatar
J. R. Okajima committed
76
77
78
79
80
81
#define AuErr1(fmt, ...) do { \
	static unsigned char _c; \
	if (!_c++) \
		pr_err(fmt, ##__VA_ARGS__); \
} while (0)

J. R. Okajima's avatar
J. R. Okajima committed
82
83
84
85
86
87
#define AuIOErr1(fmt, ...) do { \
	static unsigned char _c; \
	if (!_c++) \
		AuIOErr(fmt, ##__VA_ARGS__); \
} while (0)

88
89
90
91
92
93
94
#define AuUnsupportMsg	"This operation is not supported." \
			" Please report this application to aufs-users ML."
#define AuUnsupport(fmt, ...) do { \
	pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \
	dump_stack(); \
} while (0)

J. R. Okajima's avatar
J. R. Okajima committed
95
96
97
98
99
100
101
102
103
104
#define AuTraceErr(e) do { \
	if (unlikely((e) < 0)) \
		AuDbg("err %d\n", (int)(e)); \
} while (0)

#define AuTraceErrPtr(p) do { \
	if (IS_ERR(p)) \
		AuDbg("err %ld\n", PTR_ERR(p)); \
} while (0)

105
106
107
/* dirty macros for debug print, use with "%.*s" and caution */
#define AuLNPair(qstr)		(qstr)->len, (qstr)->name

J. R. Okajima's avatar
J. R. Okajima committed
108
109
110
111
112
113
/* ---------------------------------------------------------------------- */

struct dentry;
#ifdef CONFIG_AUFS_DEBUG
extern struct mutex au_dbg_mtx;
extern char *au_plevel;
114
115
116
117
struct au_nhash;
void au_dpri_whlist(struct au_nhash *whlist);
struct au_vdir;
void au_dpri_vdir(struct au_vdir *vdir);
J. R. Okajima's avatar
J. R. Okajima committed
118
119
struct inode;
void au_dpri_inode(struct inode *inode);
J. R. Okajima's avatar
J. R. Okajima committed
120
121
void au_dpri_dalias(struct inode *inode);
void au_dpri_dentry(struct dentry *dentry);
J. R. Okajima's avatar
J. R. Okajima committed
122
123
struct file;
void au_dpri_file(struct file *filp);
124
125
struct super_block;
void au_dpri_sb(struct super_block *sb);
J. R. Okajima's avatar
J. R. Okajima committed
126
127
128

#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__)
void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line);
J. R. Okajima's avatar
J. R. Okajima committed
129
void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
J. R. Okajima's avatar
J. R. Okajima committed
130
void au_dbg_verify_kthread(void);
J. R. Okajima's avatar
J. R. Okajima committed
131

132
133
int __init au_debug_init(void);

134
135
136
137
138
139
140
141
142
143
144
145
146
147
#define AuDbgWhlist(w) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#w "\n"); \
	au_dpri_whlist(w); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)

#define AuDbgVdir(v) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#v "\n"); \
	au_dpri_vdir(v); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)

J. R. Okajima's avatar
J. R. Okajima committed
148
149
150
151
152
153
#define AuDbgInode(i) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#i "\n"); \
	au_dpri_inode(i); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
154
155
156
157
158
159
160
161
162
163
164
165
166
167

#define AuDbgDAlias(i) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#i "\n"); \
	au_dpri_dalias(i); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)

#define AuDbgDentry(d) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#d "\n"); \
	au_dpri_dentry(d); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)
168

J. R. Okajima's avatar
J. R. Okajima committed
169
170
171
172
173
174
175
#define AuDbgFile(f) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#f "\n"); \
	au_dpri_file(f); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)

176
177
178
179
180
181
#define AuDbgSb(sb) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#sb "\n"); \
	au_dpri_sb(sb); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)
182
183
184
185
186
187

#define AuDbgSym(addr) do {				\
	char sym[KSYM_SYMBOL_LEN];			\
	sprint_symbol(sym, (unsigned long)addr);	\
	AuDbg("%s\n", sym);				\
} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
188
#else
J. R. Okajima's avatar
J. R. Okajima committed
189
AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
J. R. Okajima's avatar
J. R. Okajima committed
190
AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
J. R. Okajima's avatar
J. R. Okajima committed
191
AuStubVoid(au_dbg_verify_kthread, void)
192
AuStubInt0(__init au_debug_init, void)
J. R. Okajima's avatar
J. R. Okajima committed
193

194
195
#define AuDbgWhlist(w)		do {} while (0)
#define AuDbgVdir(v)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
196
#define AuDbgInode(i)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
197
198
#define AuDbgDAlias(i)		do {} while (0)
#define AuDbgDentry(d)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
199
#define AuDbgFile(f)		do {} while (0)
200
#define AuDbgSb(sb)		do {} while (0)
201
#define AuDbgSym(addr)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
202
203
#endif /* CONFIG_AUFS_DEBUG */

204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* ---------------------------------------------------------------------- */

#ifdef CONFIG_AUFS_MAGIC_SYSRQ
int __init au_sysrq_init(void);
void au_sysrq_fin(void);

#ifdef CONFIG_HW_CONSOLE
#define au_dbg_blocked() do { \
	WARN_ON(1); \
	handle_sysrq('w'); \
} while (0)
#else
AuStubVoid(au_dbg_blocked, void)
#endif

#else
AuStubInt0(__init au_sysrq_init, void)
AuStubVoid(au_sysrq_fin, void)
AuStubVoid(au_dbg_blocked, void)
#endif /* CONFIG_AUFS_MAGIC_SYSRQ */

J. R. Okajima's avatar
J. R. Okajima committed
225
226
#endif /* __KERNEL__ */
#endif /* __AUFS_DEBUG_H__ */