File Index
Files and directories
Sign in
FILE

messages.h

File preview with syntax highlighting.

linux-6.19.14/fs/btrfs/messages.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2
  3#ifndef BTRFS_MESSAGES_H
  4#define BTRFS_MESSAGES_H
  5
  6#include <linux/types.h>
  7#include <linux/printk.h>
  8#include <linux/bug.h>
  9
 10struct btrfs_fs_info;
 11
 12/*
 13 * We want to be able to override this in btrfs-progs.
 14 */
 15#ifdef __KERNEL__
 16
 17static inline __printf(2, 3) __cold
 18void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 19{
 20}
 21
 22#endif
 23
 24#ifdef CONFIG_PRINTK
 25
 26#define btrfs_printk(fs_info, fmt, args...)				\
 27	_btrfs_printk(fs_info, fmt, ##args)
 28
 29__printf(2, 3)
 30__cold
 31void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
 32
 33#else
 34
 35#define btrfs_printk(fs_info, fmt, args...) \
 36	btrfs_no_printk(fs_info, fmt, ##args)
 37#endif
 38
 39/*
 40 * Print a message with filesystem info, enclosed in RCU protection.
 41 */
 42#define btrfs_crit(fs_info, fmt, args...) \
 43	btrfs_printk_in_rcu(fs_info, KERN_CRIT fmt, ##args)
 44#define btrfs_err(fs_info, fmt, args...) \
 45	btrfs_printk_in_rcu(fs_info, KERN_ERR fmt, ##args)
 46#define btrfs_warn(fs_info, fmt, args...) \
 47	btrfs_printk_in_rcu(fs_info, KERN_WARNING fmt, ##args)
 48#define btrfs_info(fs_info, fmt, args...) \
 49	btrfs_printk_in_rcu(fs_info, KERN_INFO fmt, ##args)
 50
 51/*
 52 * Wrappers that use a ratelimited printk
 53 */
 54#define btrfs_crit_rl(fs_info, fmt, args...) \
 55	btrfs_printk_rl_in_rcu(fs_info, KERN_CRIT fmt, ##args)
 56#define btrfs_err_rl(fs_info, fmt, args...) \
 57	btrfs_printk_rl_in_rcu(fs_info, KERN_ERR fmt, ##args)
 58#define btrfs_warn_rl(fs_info, fmt, args...) \
 59	btrfs_printk_rl_in_rcu(fs_info, KERN_WARNING fmt, ##args)
 60#define btrfs_info_rl(fs_info, fmt, args...) \
 61	btrfs_printk_rl_in_rcu(fs_info, KERN_INFO fmt, ##args)
 62
 63#if defined(CONFIG_DYNAMIC_DEBUG)
 64#define btrfs_debug(fs_info, fmt, args...)				\
 65	_dynamic_func_call_no_desc(fmt, btrfs_printk_in_rcu,		\
 66				   fs_info, KERN_DEBUG fmt, ##args)
 67#define btrfs_debug_rl(fs_info, fmt, args...)				\
 68	_dynamic_func_call_no_desc(fmt, btrfs_printk_rl_in_rcu,		\
 69				   fs_info, KERN_DEBUG fmt, ##args)
 70#elif defined(DEBUG)
 71#define btrfs_debug(fs_info, fmt, args...) \
 72	btrfs_printk_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
 73#define btrfs_debug_rl(fs_info, fmt, args...) \
 74	btrfs_printk_rl_in_rcu(fs_info, KERN_DEBUG fmt, ##args)
 75#else
 76/* When printk() is no_printk(), expand to no-op. */
 77#define btrfs_debug(fs_info, fmt, args...)	do { (void)(fs_info); } while(0)
 78#define btrfs_debug_rl(fs_info, fmt, args...)	do { (void)(fs_info); } while(0)
 79#endif
 80
 81#define btrfs_printk_in_rcu(fs_info, fmt, args...)	\
 82do {							\
 83	rcu_read_lock();				\
 84	btrfs_printk(fs_info, fmt, ##args);		\
 85	rcu_read_unlock();				\
 86} while (0)
 87
 88#define btrfs_printk_rl_in_rcu(fs_info, fmt, args...)		\
 89do {								\
 90	static DEFINE_RATELIMIT_STATE(_rs,			\
 91		DEFAULT_RATELIMIT_INTERVAL,			\
 92		DEFAULT_RATELIMIT_BURST);			\
 93								\
 94	rcu_read_lock();					\
 95	if (__ratelimit(&_rs))					\
 96		btrfs_printk(fs_info, fmt, ##args);		\
 97	rcu_read_unlock();					\
 98} while (0)
 99
100#ifdef CONFIG_BTRFS_ASSERT
101
102__printf(1, 2)
103static inline void verify_assert_printk_format(const char *fmt, ...) {
104	/* Stub to verify the assertion format string. */
105}
106
107/* Take the first token if any. */
108#define __FIRST_ARG(_, ...) _
109/*
110 * Skip the first token and return the rest, if it's empty the comma is dropped.
111 * As ##__VA_ARGS__ cannot be at the beginning of the macro the __VA_OPT__ is needed
112 * and supported since GCC 8 and Clang 12.
113 */
114#define __REST_ARGS(_, ... ) __VA_OPT__(,) __VA_ARGS__
115
116#if defined(CONFIG_CC_IS_CLANG) || GCC_VERSION >= 80000
117/*
118 * Assertion with optional printk() format.
119 *
120 * Accepted syntax:
121 * ASSERT(condition);
122 * ASSERT(condition, "string");
123 * ASSERT(condition, "variable=%d", variable);
124 *
125 * How it works:
126 * - if there's no format string, ""[0] evaluates at compile time to 0 and the
127 *   true branch is executed
128 * - any non-empty format string with the "" prefix evaluates to != 0 at
129 *   compile time and the false branch is executed
130 * - stringified condition is printed as %s so we don't accidentally mix format
131 *   strings (the % operator)
132 * - there can be only one printk() call, so the format strings and arguments are
133 *   spliced together:
134 *   DEFAULT_FMT [USER_FMT], DEFAULT_ARGS [, USER_ARGS]
135 * - comma between DEFAULT_ARGS and USER_ARGS is handled by preprocessor
136 *   (requires __VA_OPT__ support)
137 * - otherwise we could use __VA_OPT(,) __VA_ARGS__ for the 2nd+ argument of args,
138 */
139#define ASSERT(cond, args...)							\
140do {										\
141	verify_assert_printk_format("check the format string" args);		\
142	if (!likely(cond)) {							\
143		if (("" __FIRST_ARG(args) [0]) == 0) {				\
144			pr_err("assertion failed: %s :: %ld, in %s:%d\n",	\
145				#cond, (long)(cond), __FILE__, __LINE__);	\
146		} else {							\
147			pr_err("assertion failed: %s :: %ld, in %s:%d (" __FIRST_ARG(args) ")\n", \
148				#cond, (long)(cond), __FILE__, __LINE__ __REST_ARGS(args)); \
149		}								\
150		BUG();								\
151	}									\
152} while(0)
153
154#else
155
156/* For GCC < 8.x only the simple output. */
157
158#define ASSERT(cond, args...)							\
159do {										\
160	verify_assert_printk_format("check the format string" args);		\
161	if (!likely(cond)) {							\
162		pr_err("assertion failed: %s :: %ld, in %s:%d\n",		\
163			#cond, (long)(cond), __FILE__, __LINE__);		\
164		BUG();								\
165	}									\
166} while(0)
167
168#endif
169
170#else
171/* Compile check the @cond expression but don't generate any code. */
172#define ASSERT(cond, args...)			BUILD_BUG_ON_INVALID(cond)
173#endif
174
175#ifdef CONFIG_BTRFS_DEBUG
176/* Verbose warning only under debug build. */
177#define DEBUG_WARN(args...)			WARN(1, KERN_ERR args)
178#else
179#define DEBUG_WARN(...)				do {} while(0)
180#endif
181
182__printf(5, 6)
183__cold
184void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function,
185		     unsigned int line, int error, const char *fmt, ...);
186
187const char * __attribute_const__ btrfs_decode_error(int error);
188
189#define btrfs_handle_fs_error(fs_info, error, fmt, args...)		\
190	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,		\
191				(error), fmt, ##args)
192
193__printf(5, 6)
194__cold
195void __btrfs_panic(const struct btrfs_fs_info *fs_info, const char *function,
196		   unsigned int line, int error, const char *fmt, ...);
197/*
198 * If BTRFS_MOUNT_PANIC_ON_FATAL_ERROR is in mount_opt, __btrfs_panic
199 * will panic().  Otherwise we BUG() here.
200 */
201#define btrfs_panic(fs_info, error, fmt, args...)			\
202do {									\
203	__btrfs_panic(fs_info, __func__, __LINE__, error, fmt, ##args);	\
204	BUG();								\
205} while (0)
206
207#if BITS_PER_LONG == 32
208#define BTRFS_32BIT_MAX_FILE_SIZE (((u64)ULONG_MAX + 1) << PAGE_SHIFT)
209/*
210 * The warning threshold is 5/8th of the MAX_LFS_FILESIZE that limits the logical
211 * addresses of extents.
212 *
213 * For 4K page size it's about 10T, for 64K it's 160T.
214 */
215#define BTRFS_32BIT_EARLY_WARN_THRESHOLD (BTRFS_32BIT_MAX_FILE_SIZE * 5 / 8)
216void btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info);
217void btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info);
218#endif
219
220#endif
~/ Read-only file preview.