From e4afa2386324f971b1d73091a08b3a0ba938daa9 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 6 Aug 2024 13:36:31 +0200 Subject: [PATCH] libbtrfs: remove error reporting from kerncomat.h The stack trace and BUG_ON related reporting was inherited from the tools, this should not be part of libbtrfs and was not intended to be exported. BUG() is still in used in ctree.h and send-utils.c so replace it with a bare error report and remove the rest. Keep __always_inline as it's needed for Musl. Signed-off-by: David Sterba --- libbtrfs/kerncompat.h | 65 ++++++------------------------------------- 1 file changed, 8 insertions(+), 57 deletions(-) diff --git a/libbtrfs/kerncompat.h b/libbtrfs/kerncompat.h index 70e20a1d..156c6add 100644 --- a/libbtrfs/kerncompat.h +++ b/libbtrfs/kerncompat.h @@ -39,22 +39,13 @@ #include /* - * Glibc supports backtrace, some other libc implementations don't but need to - * be more careful detecting proper glibc. + * Libc compatibility. */ #if !defined(__GLIBC__) || defined(__UCLIBC__) -#ifndef BTRFS_DISABLE_BACKTRACE -#define BTRFS_DISABLE_BACKTRACE -#endif - +/* Musl does not define __always_inline */ #ifndef __always_inline #define __always_inline __inline __attribute__ ((__always_inline__)) #endif - -#endif - -#ifndef BTRFS_DISABLE_BACKTRACE -#include #endif #define __token_glue(a,b,c) ___token_glue(a,b,c) @@ -65,46 +56,6 @@ #define BUILD_ASSERT(x) #endif -#ifndef BTRFS_DISABLE_BACKTRACE -#define MAX_BACKTRACE 16 -static inline void print_trace(void) -{ - void *array[MAX_BACKTRACE]; - int size; - - size = backtrace(array, MAX_BACKTRACE); - backtrace_symbols_fd(array, size, 2); -} -#endif - -static inline void warning_trace(const char *assertion, const char *filename, - const char *func, unsigned line, long val) -{ - if (!val) - return; - fprintf(stderr, - "%s:%u: %s: Warning: assertion `%s` failed, value %ld\n", - filename, line, func, assertion, val); -#ifndef BTRFS_DISABLE_BACKTRACE - print_trace(); -#endif -} - -static inline void bugon_trace(const char *assertion, const char *filename, - const char *func, unsigned line, long val) -{ - if (!val) - return; - fprintf(stderr, - "%s:%u: %s: BUG_ON `%s` triggered, value %ld\n", - filename, line, func, assertion, val); -#ifndef BTRFS_DISABLE_BACKTRACE - print_trace(); -#endif - abort(); - exit(1); -} - #ifdef __CHECKER__ #define __force __attribute__((force)) #define __bitwise__ __attribute__((bitwise)) @@ -171,13 +122,13 @@ static inline int IS_ERR_OR_NULL(const void *ptr) return !ptr || IS_ERR(ptr); } -#define BUG_ON(c) bugon_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) -#define BUG() \ -do { \ - BUG_ON(1); \ - __builtin_unreachable(); \ +#define BUG() \ +do { \ + fprintf(stderr, "%s:%u: BUG in %s()\n", __FILE__, __LINE__, __func__); \ + abort(); \ + exit(1); \ + __builtin_unreachable(); \ } while (0) -#define WARN_ON(c) warning_trace(#c, __FILE__, __func__, __LINE__, (long)(c)) #define container_of(ptr, type, member) ({ \ const typeof( ((type *)0)->member ) *__mptr = (ptr); \