1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * linux/include/linux/sunrpc/debug.h
4 *
5 * Debugging support for sunrpc module
6 *
7 * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de>
8 */
9#ifndef _LINUX_SUNRPC_DEBUG_H_
10#define _LINUX_SUNRPC_DEBUG_H_
11
12#include <uapi/linux/sunrpc/debug.h>
13
14/*
15 * Debugging macros etc
16 */
17#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
18extern unsigned int rpc_debug;
19extern unsigned int nfs_debug;
20extern unsigned int nfsd_debug;
21extern unsigned int nlm_debug;
22#endif
23
24#define dprintk(fmt, ...) \
25 dfprintk(FACILITY, fmt, ##__VA_ARGS__)
26#define dprintk_rcu(fmt, ...) \
27 dfprintk_rcu(FACILITY, fmt, ##__VA_ARGS__)
28
29#undef ifdebug
30#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
31# define ifdebug(fac) if (unlikely(rpc_debug & RPCDBG_##fac))
32
33# if IS_ENABLED(CONFIG_SUNRPC_DEBUG_TRACE)
34# define __sunrpc_printk(fmt, ...) trace_printk(fmt, ##__VA_ARGS__)
35# else
36# define __sunrpc_printk(fmt, ...) printk(KERN_DEFAULT fmt, ##__VA_ARGS__)
37# endif
38
39# define dfprintk(fac, fmt, ...) \
40do { \
41 ifdebug(fac) \
42 __sunrpc_printk(fmt, ##__VA_ARGS__); \
43} while (0)
44
45# define dfprintk_rcu(fac, fmt, ...) \
46do { \
47 ifdebug(fac) { \
48 rcu_read_lock(); \
49 __sunrpc_printk(fmt, ##__VA_ARGS__); \
50 rcu_read_unlock(); \
51 } \
52} while (0)
53
54# define RPC_IFDEBUG(x) x
55#else
56# define ifdebug(fac) if (0)
57# define dfprintk(fac, fmt, ...) do {} while (0)
58# define dfprintk_rcu(fac, fmt, ...) do {} while (0)
59# define RPC_IFDEBUG(x)
60#endif
61
62/*
63 * Sysctl interface for RPC debugging
64 */
65
66struct rpc_clnt;
67struct rpc_xprt;
68
69#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
70void rpc_register_sysctl(void);
71void rpc_unregister_sysctl(void);
72void sunrpc_debugfs_init(void);
73void sunrpc_debugfs_exit(void);
74void rpc_clnt_debugfs_register(struct rpc_clnt *);
75void rpc_clnt_debugfs_unregister(struct rpc_clnt *);
76void rpc_xprt_debugfs_register(struct rpc_xprt *);
77void rpc_xprt_debugfs_unregister(struct rpc_xprt *);
78#else
79static inline void
80sunrpc_debugfs_init(void)
81{
82 return;
83}
84
85static inline void
86sunrpc_debugfs_exit(void)
87{
88 return;
89}
90
91static inline void
92rpc_clnt_debugfs_register(struct rpc_clnt *clnt)
93{
94 return;
95}
96
97static inline void
98rpc_clnt_debugfs_unregister(struct rpc_clnt *clnt)
99{
100 return;
101}
102
103static inline void
104rpc_xprt_debugfs_register(struct rpc_xprt *xprt)
105{
106 return;
107}
108
109static inline void
110rpc_xprt_debugfs_unregister(struct rpc_xprt *xprt)
111{
112 return;
113}
114#endif
115
116#endif /* _LINUX_SUNRPC_DEBUG_H_ */
117