Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfs: add initial support for CONFIG_DEBUG_VFS

Small collection of macros taken from mmdebug.h

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://lore.kernel.org/r/20250209185523.745956-2-mjguzik@gmail.com
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Mateusz Guzik and committed by
Christian Brauner
8b17e540 2014c95a

+70
+15
fs/inode.c
··· 2953 2953 return mode & ~S_ISGID; 2954 2954 } 2955 2955 EXPORT_SYMBOL(mode_strip_sgid); 2956 + 2957 + #ifdef CONFIG_DEBUG_VFS 2958 + /* 2959 + * Dump an inode. 2960 + * 2961 + * TODO: add a proper inode dumping routine, this is a stub to get debug off the 2962 + * ground. 2963 + */ 2964 + void dump_inode(struct inode *inode, const char *reason) 2965 + { 2966 + pr_warn("%s encountered for inode %px", reason, inode); 2967 + } 2968 + 2969 + EXPORT_SYMBOL(dump_inode); 2970 + #endif
+1
include/linux/fs.h
··· 2 2 #ifndef _LINUX_FS_H 3 3 #define _LINUX_FS_H 4 4 5 + #include <linux/vfsdebug.h> 5 6 #include <linux/linkage.h> 6 7 #include <linux/wait_bit.h> 7 8 #include <linux/kdev_t.h>
+45
include/linux/vfsdebug.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef LINUX_VFS_DEBUG_H 3 + #define LINUX_VFS_DEBUG_H 1 4 + 5 + #include <linux/bug.h> 6 + 7 + struct inode; 8 + 9 + #ifdef CONFIG_DEBUG_VFS 10 + void dump_inode(struct inode *inode, const char *reason); 11 + 12 + #define VFS_BUG_ON(cond) BUG_ON(cond) 13 + #define VFS_WARN_ON(cond) (void)WARN_ON(cond) 14 + #define VFS_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond) 15 + #define VFS_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format) 16 + #define VFS_WARN(cond, format...) (void)WARN(cond, format) 17 + 18 + #define VFS_BUG_ON_INODE(cond, inode) ({ \ 19 + if (unlikely(!!(cond))) { \ 20 + dump_inode(inode, "VFS_BUG_ON_INODE(" #cond")");\ 21 + BUG_ON(1); \ 22 + } \ 23 + }) 24 + 25 + #define VFS_WARN_ON_INODE(cond, inode) ({ \ 26 + int __ret_warn = !!(cond); \ 27 + \ 28 + if (unlikely(__ret_warn)) { \ 29 + dump_inode(inode, "VFS_WARN_ON_INODE(" #cond")");\ 30 + WARN_ON(1); \ 31 + } \ 32 + unlikely(__ret_warn); \ 33 + }) 34 + #else 35 + #define VFS_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond) 36 + #define VFS_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond) 37 + #define VFS_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond) 38 + #define VFS_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond) 39 + #define VFS_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond) 40 + 41 + #define VFS_BUG_ON_INODE(cond, inode) VFS_BUG_ON(cond) 42 + #define VFS_WARN_ON_INODE(cond, inode) BUILD_BUG_ON_INVALID(cond) 43 + #endif /* CONFIG_DEBUG_VFS */ 44 + 45 + #endif
+9
lib/Kconfig.debug
··· 808 808 An architecture should select this when it can successfully 809 809 build and run DEBUG_VM_PGTABLE. 810 810 811 + config DEBUG_VFS 812 + bool "Debug VFS" 813 + depends on DEBUG_KERNEL 814 + help 815 + Enable this to turn on extended checks in the VFS layer that may impact 816 + performance. 817 + 818 + If unsure, say N. 819 + 811 820 config DEBUG_VM_IRQSOFF 812 821 def_bool DEBUG_VM && !PREEMPT_RT 813 822