debug.h 3.79 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2005-2019 Junjiro R. Okajima
 */

/*
 * debug print functions
 */

#ifndef __AUFS_DEBUG_H__
#define __AUFS_DEBUG_H__

#ifdef __KERNEL__

J. R. Okajima's avatar
J. R. Okajima committed
15
16
#include <linux/atomic.h>
#include <linux/module.h>
17
#include <linux/kallsyms.h>
J. R. Okajima's avatar
J. R. Okajima committed
18

J. R. Okajima's avatar
J. R. Okajima committed
19
20
#ifdef CONFIG_AUFS_DEBUG
#define AuDebugOn(a)		BUG_ON(a)
J. R. Okajima's avatar
J. R. Okajima committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/* 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
37
38
#else
#define AuDebugOn(a)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
39
40
41
AuStubVoid(au_debug_on, void)
AuStubVoid(au_debug_off, void)
AuStubInt0(au_debug_test, void)
J. R. Okajima's avatar
J. R. Okajima committed
42
43
#endif /* CONFIG_AUFS_DEBUG */

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

J. R. Okajima's avatar
J. R. Okajima committed
46
47
48
49
50
51
52
53
54
/* ---------------------------------------------------------------------- */

/* 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
55
#define AuIOErr(fmt, ...)	pr_err("I/O Error, " fmt, ##__VA_ARGS__)
56
57
58
59
60
#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
61

J. R. Okajima's avatar
J. R. Okajima committed
62
63
64
65
66
67
#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
68
69
70
71
72
73
#define AuIOErr1(fmt, ...) do { \
	static unsigned char _c; \
	if (!_c++) \
		AuIOErr(fmt, ##__VA_ARGS__); \
} while (0)

74
75
76
77
78
79
80
#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
81
82
83
84
85
86
87
88
89
90
#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)

91
92
93
/* 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
94
95
96
97
98
99
100
101
/* ---------------------------------------------------------------------- */

struct dentry;
#ifdef CONFIG_AUFS_DEBUG
extern struct mutex au_dbg_mtx;
extern char *au_plevel;
struct inode;
void au_dpri_inode(struct inode *inode);
J. R. Okajima's avatar
J. R. Okajima committed
102
103
void au_dpri_dalias(struct inode *inode);
void au_dpri_dentry(struct dentry *dentry);
104
105
struct super_block;
void au_dpri_sb(struct super_block *sb);
J. R. Okajima's avatar
J. R. Okajima committed
106
107
108

#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
109
void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen);
J. R. Okajima's avatar
J. R. Okajima committed
110
void au_dbg_verify_kthread(void);
J. R. Okajima's avatar
J. R. Okajima committed
111
112
113
114
115
116
117

#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
118
119
120
121
122
123
124
125
126
127
128
129
130
131

#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)
132
133
134
135
136
137
138

#define AuDbgSb(sb) do { \
	mutex_lock(&au_dbg_mtx); \
	AuDbg(#sb "\n"); \
	au_dpri_sb(sb); \
	mutex_unlock(&au_dbg_mtx); \
} while (0)
139
140
141
142
143
144

#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
145
#else
J. R. Okajima's avatar
J. R. Okajima committed
146
AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry)
J. R. Okajima's avatar
J. R. Okajima committed
147
AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen)
J. R. Okajima's avatar
J. R. Okajima committed
148
AuStubVoid(au_dbg_verify_kthread, void)
J. R. Okajima's avatar
J. R. Okajima committed
149

J. R. Okajima's avatar
J. R. Okajima committed
150
#define AuDbgInode(i)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
151
152
#define AuDbgDAlias(i)		do {} while (0)
#define AuDbgDentry(d)		do {} while (0)
153
#define AuDbgSb(sb)		do {} while (0)
154
#define AuDbgSym(addr)		do {} while (0)
J. R. Okajima's avatar
J. R. Okajima committed
155
156
#endif /* CONFIG_AUFS_DEBUG */

J. R. Okajima's avatar
J. R. Okajima committed
157
158
#endif /* __KERNEL__ */
#endif /* __AUFS_DEBUG_H__ */