xref: /linux/fs/smb/client/cifs_debug.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1*38c8a9a5SSteve French /* SPDX-License-Identifier: GPL-2.0-or-later */
2*38c8a9a5SSteve French /*
3*38c8a9a5SSteve French  *
4*38c8a9a5SSteve French  *   Copyright (c) International Business Machines  Corp., 2000,2002
5*38c8a9a5SSteve French  *   Modified by Steve French (sfrench@us.ibm.com)
6*38c8a9a5SSteve French  */
7*38c8a9a5SSteve French 
8*38c8a9a5SSteve French #ifndef _H_CIFS_DEBUG
9*38c8a9a5SSteve French #define _H_CIFS_DEBUG
10*38c8a9a5SSteve French 
11*38c8a9a5SSteve French #ifdef pr_fmt
12*38c8a9a5SSteve French #undef pr_fmt
13*38c8a9a5SSteve French #endif
14*38c8a9a5SSteve French 
15*38c8a9a5SSteve French #define pr_fmt(fmt) "CIFS: " fmt
16*38c8a9a5SSteve French 
17*38c8a9a5SSteve French void cifs_dump_mem(char *label, void *data, int length);
18*38c8a9a5SSteve French void cifs_dump_detail(void *buf, struct TCP_Server_Info *ptcp_info);
19*38c8a9a5SSteve French void cifs_dump_mids(struct TCP_Server_Info *);
20*38c8a9a5SSteve French extern bool traceSMB;		/* flag which enables the function below */
21*38c8a9a5SSteve French void dump_smb(void *, int);
22*38c8a9a5SSteve French #define CIFS_INFO	0x01
23*38c8a9a5SSteve French #define CIFS_RC		0x02
24*38c8a9a5SSteve French #define CIFS_TIMER	0x04
25*38c8a9a5SSteve French 
26*38c8a9a5SSteve French #define VFS 1
27*38c8a9a5SSteve French #define FYI 2
28*38c8a9a5SSteve French extern int cifsFYI;
29*38c8a9a5SSteve French #ifdef CONFIG_CIFS_DEBUG2
30*38c8a9a5SSteve French #define NOISY 4
31*38c8a9a5SSteve French #else
32*38c8a9a5SSteve French #define NOISY 0
33*38c8a9a5SSteve French #endif
34*38c8a9a5SSteve French #define ONCE 8
35*38c8a9a5SSteve French 
36*38c8a9a5SSteve French /*
37*38c8a9a5SSteve French  *	debug ON
38*38c8a9a5SSteve French  *	--------
39*38c8a9a5SSteve French  */
40*38c8a9a5SSteve French #ifdef CONFIG_CIFS_DEBUG
41*38c8a9a5SSteve French 
42*38c8a9a5SSteve French 
43*38c8a9a5SSteve French /*
44*38c8a9a5SSteve French  * When adding tracepoints and debug messages we have various choices.
45*38c8a9a5SSteve French  * Some considerations:
46*38c8a9a5SSteve French  *
47*38c8a9a5SSteve French  * Use cifs_dbg(VFS, ...) for things we always want logged, and the user to see
48*38c8a9a5SSteve French  *     cifs_info(...) slightly less important, admin can filter via loglevel > 6
49*38c8a9a5SSteve French  *     cifs_dbg(FYI, ...) minor debugging messages, off by default
50*38c8a9a5SSteve French  *     trace_smb3_*  ftrace functions are preferred for complex debug messages
51*38c8a9a5SSteve French  *                 intended for developers or experienced admins, off by default
52*38c8a9a5SSteve French  */
53*38c8a9a5SSteve French 
54*38c8a9a5SSteve French /* Information level messages, minor events */
55*38c8a9a5SSteve French #define cifs_info_func(ratefunc, fmt, ...)				\
56*38c8a9a5SSteve French 	pr_info_ ## ratefunc(fmt, ##__VA_ARGS__)
57*38c8a9a5SSteve French 
58*38c8a9a5SSteve French #define cifs_info(fmt, ...)						\
59*38c8a9a5SSteve French 	cifs_info_func(ratelimited, fmt, ##__VA_ARGS__)
60*38c8a9a5SSteve French 
61*38c8a9a5SSteve French /* information message: e.g., configuration, major event */
62*38c8a9a5SSteve French #define cifs_dbg_func(ratefunc, type, fmt, ...)				\
63*38c8a9a5SSteve French do {									\
64*38c8a9a5SSteve French 	if ((type) & FYI && cifsFYI & CIFS_INFO) {			\
65*38c8a9a5SSteve French 		pr_debug_ ## ratefunc("%s: " fmt,			\
66*38c8a9a5SSteve French 				      __FILE__, ##__VA_ARGS__);		\
67*38c8a9a5SSteve French 	} else if ((type) & VFS) {					\
68*38c8a9a5SSteve French 		pr_err_ ## ratefunc("VFS: " fmt, ##__VA_ARGS__);	\
69*38c8a9a5SSteve French 	} else if ((type) & NOISY && (NOISY != 0)) {			\
70*38c8a9a5SSteve French 		pr_debug_ ## ratefunc(fmt, ##__VA_ARGS__);		\
71*38c8a9a5SSteve French 	}								\
72*38c8a9a5SSteve French } while (0)
73*38c8a9a5SSteve French 
74*38c8a9a5SSteve French #define cifs_dbg(type, fmt, ...)					\
75*38c8a9a5SSteve French do {									\
76*38c8a9a5SSteve French 	if ((type) & ONCE)						\
77*38c8a9a5SSteve French 		cifs_dbg_func(once, type, fmt, ##__VA_ARGS__);		\
78*38c8a9a5SSteve French 	else								\
79*38c8a9a5SSteve French 		cifs_dbg_func(ratelimited, type, fmt, ##__VA_ARGS__);	\
80*38c8a9a5SSteve French } while (0)
81*38c8a9a5SSteve French 
82*38c8a9a5SSteve French #define cifs_server_dbg_func(ratefunc, type, fmt, ...)			\
83*38c8a9a5SSteve French do {									\
84*38c8a9a5SSteve French 	spin_lock(&server->srv_lock);					\
85*38c8a9a5SSteve French 	if ((type) & FYI && cifsFYI & CIFS_INFO) {			\
86*38c8a9a5SSteve French 		pr_debug_ ## ratefunc("%s: \\\\%s " fmt,		\
87*38c8a9a5SSteve French 				      __FILE__, server->hostname,	\
88*38c8a9a5SSteve French 				      ##__VA_ARGS__);			\
89*38c8a9a5SSteve French 	} else if ((type) & VFS) {					\
90*38c8a9a5SSteve French 		pr_err_ ## ratefunc("VFS: \\\\%s " fmt,			\
91*38c8a9a5SSteve French 				    server->hostname, ##__VA_ARGS__);	\
92*38c8a9a5SSteve French 	} else if ((type) & NOISY && (NOISY != 0)) {			\
93*38c8a9a5SSteve French 		pr_debug_ ## ratefunc("\\\\%s " fmt,			\
94*38c8a9a5SSteve French 				      server->hostname, ##__VA_ARGS__);	\
95*38c8a9a5SSteve French 	}								\
96*38c8a9a5SSteve French 	spin_unlock(&server->srv_lock);					\
97*38c8a9a5SSteve French } while (0)
98*38c8a9a5SSteve French 
99*38c8a9a5SSteve French #define cifs_server_dbg(type, fmt, ...)					\
100*38c8a9a5SSteve French do {									\
101*38c8a9a5SSteve French 	if ((type) & ONCE)						\
102*38c8a9a5SSteve French 		cifs_server_dbg_func(once, type, fmt, ##__VA_ARGS__);	\
103*38c8a9a5SSteve French 	else								\
104*38c8a9a5SSteve French 		cifs_server_dbg_func(ratelimited, type, fmt,		\
105*38c8a9a5SSteve French 				     ##__VA_ARGS__);			\
106*38c8a9a5SSteve French } while (0)
107*38c8a9a5SSteve French 
108*38c8a9a5SSteve French #define cifs_tcon_dbg_func(ratefunc, type, fmt, ...)			\
109*38c8a9a5SSteve French do {									\
110*38c8a9a5SSteve French 	const char *tn = "";						\
111*38c8a9a5SSteve French 	if (tcon && tcon->tree_name)					\
112*38c8a9a5SSteve French 		tn = tcon->tree_name;					\
113*38c8a9a5SSteve French 	if ((type) & FYI && cifsFYI & CIFS_INFO) {			\
114*38c8a9a5SSteve French 		pr_debug_ ## ratefunc("%s: %s "	fmt,			\
115*38c8a9a5SSteve French 				      __FILE__, tn, ##__VA_ARGS__);	\
116*38c8a9a5SSteve French 	} else if ((type) & VFS) {					\
117*38c8a9a5SSteve French 		pr_err_ ## ratefunc("VFS: %s " fmt, tn, ##__VA_ARGS__);	\
118*38c8a9a5SSteve French 	} else if ((type) & NOISY && (NOISY != 0)) {			\
119*38c8a9a5SSteve French 		pr_debug_ ## ratefunc("%s " fmt, tn, ##__VA_ARGS__);	\
120*38c8a9a5SSteve French 	}								\
121*38c8a9a5SSteve French } while (0)
122*38c8a9a5SSteve French 
123*38c8a9a5SSteve French #define cifs_tcon_dbg(type, fmt, ...)					\
124*38c8a9a5SSteve French do {									\
125*38c8a9a5SSteve French 	if ((type) & ONCE)						\
126*38c8a9a5SSteve French 		cifs_tcon_dbg_func(once, type, fmt, ##__VA_ARGS__);	\
127*38c8a9a5SSteve French 	else								\
128*38c8a9a5SSteve French 		cifs_tcon_dbg_func(ratelimited, type, fmt,		\
129*38c8a9a5SSteve French 				   ##__VA_ARGS__);			\
130*38c8a9a5SSteve French } while (0)
131*38c8a9a5SSteve French 
132*38c8a9a5SSteve French /*
133*38c8a9a5SSteve French  *	debug OFF
134*38c8a9a5SSteve French  *	---------
135*38c8a9a5SSteve French  */
136*38c8a9a5SSteve French #else		/* _CIFS_DEBUG */
137*38c8a9a5SSteve French #define cifs_dbg(type, fmt, ...)					\
138*38c8a9a5SSteve French do {									\
139*38c8a9a5SSteve French 	if (0)								\
140*38c8a9a5SSteve French 		pr_debug(fmt, ##__VA_ARGS__);				\
141*38c8a9a5SSteve French } while (0)
142*38c8a9a5SSteve French 
143*38c8a9a5SSteve French #define cifs_server_dbg(type, fmt, ...)					\
144*38c8a9a5SSteve French do {									\
145*38c8a9a5SSteve French 	if (0)								\
146*38c8a9a5SSteve French 		pr_debug("\\\\%s " fmt,					\
147*38c8a9a5SSteve French 			 server->hostname, ##__VA_ARGS__);		\
148*38c8a9a5SSteve French } while (0)
149*38c8a9a5SSteve French 
150*38c8a9a5SSteve French #define cifs_tcon_dbg(type, fmt, ...)					\
151*38c8a9a5SSteve French do {									\
152*38c8a9a5SSteve French 	if (0)								\
153*38c8a9a5SSteve French 		pr_debug("%s " fmt, tcon->tree_name, ##__VA_ARGS__);	\
154*38c8a9a5SSteve French } while (0)
155*38c8a9a5SSteve French 
156*38c8a9a5SSteve French #define cifs_info(fmt, ...)						\
157*38c8a9a5SSteve French 	pr_info(fmt, ##__VA_ARGS__)
158*38c8a9a5SSteve French #endif
159*38c8a9a5SSteve French 
160*38c8a9a5SSteve French #endif				/* _H_CIFS_DEBUG */
161