]> www.infradead.org Git - users/hch/misc.git/commitdiff
vfs: add initial support for CONFIG_DEBUG_VFS
authorMateusz Guzik <mjguzik@gmail.com>
Sun, 9 Feb 2025 18:55:20 +0000 (19:55 +0100)
committerChristian Brauner <brauner@kernel.org>
Fri, 21 Feb 2025 09:23:53 +0000 (10:23 +0100)
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>
fs/inode.c
include/linux/fs.h
include/linux/vfsdebug.h [new file with mode: 0644]
lib/Kconfig.debug

index 5587aabdaa5eec1212f19c2cf99420781517e64f..875e66261f064b253894ae22d6370e89188c2bff 100644 (file)
@@ -2953,3 +2953,18 @@ umode_t mode_strip_sgid(struct mnt_idmap *idmap,
        return mode & ~S_ISGID;
 }
 EXPORT_SYMBOL(mode_strip_sgid);
+
+#ifdef CONFIG_DEBUG_VFS
+/*
+ * Dump an inode.
+ *
+ * TODO: add a proper inode dumping routine, this is a stub to get debug off the
+ * ground.
+ */
+void dump_inode(struct inode *inode, const char *reason)
+{
+       pr_warn("%s encountered for inode %px", reason, inode);
+}
+
+EXPORT_SYMBOL(dump_inode);
+#endif
index be3ad155ec9f74460d971f11b96445e8db579c6f..d5e3fb14ad8c4528765ae7c6e4546fc6f09ffefa 100644 (file)
@@ -2,6 +2,7 @@
 #ifndef _LINUX_FS_H
 #define _LINUX_FS_H
 
+#include <linux/vfsdebug.h>
 #include <linux/linkage.h>
 #include <linux/wait_bit.h>
 #include <linux/kdev_t.h>
diff --git a/include/linux/vfsdebug.h b/include/linux/vfsdebug.h
new file mode 100644 (file)
index 0000000..9cf22d3
--- /dev/null
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef LINUX_VFS_DEBUG_H
+#define LINUX_VFS_DEBUG_H 1
+
+#include <linux/bug.h>
+
+struct inode;
+
+#ifdef CONFIG_DEBUG_VFS
+void dump_inode(struct inode *inode, const char *reason);
+
+#define VFS_BUG_ON(cond) BUG_ON(cond)
+#define VFS_WARN_ON(cond) (void)WARN_ON(cond)
+#define VFS_WARN_ON_ONCE(cond) (void)WARN_ON_ONCE(cond)
+#define VFS_WARN_ONCE(cond, format...) (void)WARN_ONCE(cond, format)
+#define VFS_WARN(cond, format...) (void)WARN(cond, format)
+
+#define VFS_BUG_ON_INODE(cond, inode)          ({                      \
+       if (unlikely(!!(cond))) {                                       \
+               dump_inode(inode, "VFS_BUG_ON_INODE(" #cond")");\
+               BUG_ON(1);                                              \
+       }                                                               \
+})
+
+#define VFS_WARN_ON_INODE(cond, inode)         ({                      \
+       int __ret_warn = !!(cond);                                      \
+                                                                       \
+       if (unlikely(__ret_warn)) {                                     \
+               dump_inode(inode, "VFS_WARN_ON_INODE(" #cond")");\
+               WARN_ON(1);                                             \
+       }                                                               \
+       unlikely(__ret_warn);                                           \
+})
+#else
+#define VFS_BUG_ON(cond) BUILD_BUG_ON_INVALID(cond)
+#define VFS_WARN_ON(cond) BUILD_BUG_ON_INVALID(cond)
+#define VFS_WARN_ON_ONCE(cond) BUILD_BUG_ON_INVALID(cond)
+#define VFS_WARN_ONCE(cond, format...) BUILD_BUG_ON_INVALID(cond)
+#define VFS_WARN(cond, format...) BUILD_BUG_ON_INVALID(cond)
+
+#define VFS_BUG_ON_INODE(cond, inode) VFS_BUG_ON(cond)
+#define VFS_WARN_ON_INODE(cond, inode)  BUILD_BUG_ON_INVALID(cond)
+#endif /* CONFIG_DEBUG_VFS */
+
+#endif
index 1af972a92d06f6e3f7beec4bd086c00b412c83ac..c08ce985c482d0711bd846163eb0ddc3d429e773 100644 (file)
@@ -808,6 +808,15 @@ config ARCH_HAS_DEBUG_VM_PGTABLE
          An architecture should select this when it can successfully
          build and run DEBUG_VM_PGTABLE.
 
+config DEBUG_VFS
+       bool "Debug VFS"
+       depends on DEBUG_KERNEL
+       help
+         Enable this to turn on extended checks in the VFS layer that may impact
+         performance.
+
+         If unsure, say N.
+
 config DEBUG_VM_IRQSOFF
        def_bool DEBUG_VM && !PREEMPT_RT