]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/printk.h
Update bcachefs sources to 3610542890 bcachefs: Convert to skcipher interface for...
[bcachefs-tools-debian] / include / linux / printk.h
1 #ifndef __TOOLS_LINUX_PRINTK_H
2 #define __TOOLS_LINUX_PRINTK_H
3
4 #ifndef pr_fmt
5 #define pr_fmt(fmt) fmt
6 #endif
7
8 #include <stdarg.h>
9 #include <stdio.h>
10
11 #define KERN_EMERG      ""
12 #define KERN_ALERT      ""
13 #define KERN_CRIT       ""
14 #define KERN_ERR        ""
15 #define KERN_WARNING    ""
16 #define KERN_NOTICE     ""
17 #define KERN_INFO       ""
18 #define KERN_DEBUG      ""
19 #define KERN_DEFAULT    ""
20 #define KERN_CONT       ""
21
22 static inline int vscnprintf(char *buf, size_t size, const char *fmt, va_list args)
23 {
24        int i = vsnprintf(buf, size, fmt, args);
25        ssize_t ssize = size;
26
27        return (i >= ssize) ? (ssize - 1) : i;
28 }
29
30 static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
31 {
32        ssize_t ssize = size;
33        va_list args;
34        int i;
35
36        va_start(args, fmt);
37        i = vsnprintf(buf, size, fmt, args);
38        va_end(args);
39
40        return (i >= ssize) ? (ssize - 1) : i;
41 }
42
43 #define printk(...)     printf(__VA_ARGS__)
44
45 #define no_printk(fmt, ...)                             \
46 ({                                                      \
47         do {                                            \
48                 if (0)                                  \
49                         printk(fmt, ##__VA_ARGS__);     \
50         } while (0);                                    \
51         0;                                              \
52 })
53
54 #define pr_emerg(fmt, ...) \
55         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
56 #define pr_alert(fmt, ...) \
57         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
58 #define pr_crit(fmt, ...) \
59         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
60 #define pr_err(fmt, ...) \
61         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
62 #define pr_warning(fmt, ...) \
63         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
64 #define pr_warn pr_warning
65 #define pr_notice(fmt, ...) \
66         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
67 #define pr_info(fmt, ...) \
68         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
69 /*
70  * Like KERN_CONT, pr_cont() should only be used when continuing
71  * a line with no newline ('\n') enclosed. Otherwise it defaults
72  * back to KERN_DEFAULT.
73  */
74 #define pr_cont(fmt, ...) \
75         printk(KERN_CONT fmt, ##__VA_ARGS__)
76
77 /* pr_devel() should produce zero code unless DEBUG is defined */
78 #ifdef DEBUG
79 #define pr_devel(fmt, ...) \
80         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
81 #else
82 #define pr_devel(fmt, ...) \
83         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
84 #endif
85
86
87 /* If you are writing a driver, please use dev_dbg instead */
88 #if defined(CONFIG_DYNAMIC_DEBUG)
89 #include <linux/dynamic_debug.h>
90
91 /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
92 #define pr_debug(fmt, ...) \
93         dynamic_pr_debug(fmt, ##__VA_ARGS__)
94 #elif defined(DEBUG)
95 #define pr_debug(fmt, ...) \
96         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
97 #else
98 #define pr_debug(fmt, ...) \
99         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
100 #endif
101
102 /*
103  * Print a one-time message (analogous to WARN_ONCE() et al):
104  */
105
106 #define printk_once(fmt, ...)                                   \
107 ({                                                              \
108         static bool __print_once __read_mostly;                 \
109         bool __ret_print_once = !__print_once;                  \
110                                                                 \
111         if (!__print_once) {                                    \
112                 __print_once = true;                            \
113                 printk(fmt, ##__VA_ARGS__);                     \
114         }                                                       \
115         unlikely(__ret_print_once);                             \
116 })
117 #define printk_deferred_once(fmt, ...)                          \
118 ({                                                              \
119         static bool __print_once __read_mostly;                 \
120         bool __ret_print_once = !__print_once;                  \
121                                                                 \
122         if (!__print_once) {                                    \
123                 __print_once = true;                            \
124                 printk_deferred(fmt, ##__VA_ARGS__);            \
125         }                                                       \
126         unlikely(__ret_print_once);                             \
127 })
128
129 #define pr_emerg_once(fmt, ...)                                 \
130         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
131 #define pr_alert_once(fmt, ...)                                 \
132         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
133 #define pr_crit_once(fmt, ...)                                  \
134         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
135 #define pr_err_once(fmt, ...)                                   \
136         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
137 #define pr_warn_once(fmt, ...)                                  \
138         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
139 #define pr_notice_once(fmt, ...)                                \
140         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
141 #define pr_info_once(fmt, ...)                                  \
142         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
143 #define pr_cont_once(fmt, ...)                                  \
144         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
145
146 #if defined(DEBUG)
147 #define pr_devel_once(fmt, ...)                                 \
148         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
149 #else
150 #define pr_devel_once(fmt, ...)                                 \
151         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
152 #endif
153
154 /* If you are writing a driver, please use dev_dbg instead */
155 #if defined(DEBUG)
156 #define pr_debug_once(fmt, ...)                                 \
157         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
158 #else
159 #define pr_debug_once(fmt, ...)                                 \
160         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
161 #endif
162
163 /*
164  * ratelimited messages with local ratelimit_state,
165  * no local ratelimit_state used in the !PRINTK case
166  */
167 #ifdef CONFIG_PRINTK
168 #define printk_ratelimited(fmt, ...)                                    \
169 ({                                                                      \
170         static DEFINE_RATELIMIT_STATE(_rs,                              \
171                                       DEFAULT_RATELIMIT_INTERVAL,       \
172                                       DEFAULT_RATELIMIT_BURST);         \
173                                                                         \
174         if (__ratelimit(&_rs))                                          \
175                 printk(fmt, ##__VA_ARGS__);                             \
176 })
177 #else
178 #define printk_ratelimited(fmt, ...)                                    \
179         no_printk(fmt, ##__VA_ARGS__)
180 #endif
181
182 #define pr_emerg_ratelimited(fmt, ...)                                  \
183         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
184 #define pr_alert_ratelimited(fmt, ...)                                  \
185         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
186 #define pr_crit_ratelimited(fmt, ...)                                   \
187         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
188 #define pr_err_ratelimited(fmt, ...)                                    \
189         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
190 #define pr_warn_ratelimited(fmt, ...)                                   \
191         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
192 #define pr_notice_ratelimited(fmt, ...)                                 \
193         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
194 #define pr_info_ratelimited(fmt, ...)                                   \
195         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
196 /* no pr_cont_ratelimited, don't do that... */
197
198 #if defined(DEBUG)
199 #define pr_devel_ratelimited(fmt, ...)                                  \
200         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
201 #else
202 #define pr_devel_ratelimited(fmt, ...)                                  \
203         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
204 #endif
205 #endif /* __TOOLS_LINUX_PRINTK_H */