]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: headers cleanup to remove unnecessary local includes
authorQu Wenruo <wqu@suse.com>
Mon, 27 Oct 2025 23:36:36 +0000 (10:06 +1030)
committerDavid Sterba <dsterba@suse.com>
Mon, 24 Nov 2025 21:34:52 +0000 (22:34 +0100)
[BUG]
When I tried to remove btrfs_bio::fs_info and use btrfs_bio::inode to
grab the fs_info, the header "btrfs_inode.h" is needed to access the
full btrfs_inode structure.

Then btrfs will fail to compile.

[CAUSE]
There is a recursive including chain:

  "bio.h" -> "btrfs_inode.h" -> "extent_map.h" -> "compression.h" ->
  "bio.h"

That recursive including is causing problems for btrfs.

[ENHANCEMENT]
To reduce the risk of recursive including:

- Remove unnecessary local includes from btrfs headers
  Either the included header is pulled in by other headers, or is
  completely unnecessary.

- Remove btrfs local includes if the header only requires a pointer
  In that case let the implementing C file to pull the required header.

  This is especially important for headers like "btrfs_inode.h" which
  pulls in a lot of other btrfs headers, thus it's a mine field of
  recursive including.

- Remove unnecessary temporary structure definition
  Either if we have included the header defining the structure, or
  completely unused.

Now including "btrfs_inode.h" inside "bio.h" is completely fine,
although "btrfs_inode.h" still includes "extent_map.h", but that header
only includes "fs.h", no more chain back to "bio.h".

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
21 files changed:
fs/btrfs/accessors.h
fs/btrfs/btrfs_inode.h
fs/btrfs/compression.h
fs/btrfs/ctree.h
fs/btrfs/defrag.c
fs/btrfs/dir-item.c
fs/btrfs/direct-io.c
fs/btrfs/disk-io.c
fs/btrfs/disk-io.h
fs/btrfs/extent-tree.c
fs/btrfs/extent_io.h
fs/btrfs/extent_map.h
fs/btrfs/file-item.h
fs/btrfs/inode.c
fs/btrfs/space-info.c
fs/btrfs/subpage.h
fs/btrfs/transaction.c
fs/btrfs/transaction.h
fs/btrfs/tree-log.c
fs/btrfs/tree-log.h
fs/btrfs/zoned.h

index 99b3ced12805bb0003c08a5560ebc32c5cd0d6af..78721412951c5a81005eddcaf811e3fe2a141de9 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/string.h>
 #include <linux/mm.h>
 #include <uapi/linux/btrfs_tree.h>
+#include "fs.h"
 #include "extent_io.h"
 
 struct extent_buffer;
index af373d50a901f2dfc4ab686e9fb4f5d1c854f2cd..a66ca5531b5c57726e71555bd3607121c8ffd64f 100644 (file)
 #include <linux/lockdep.h>
 #include <uapi/linux/btrfs_tree.h>
 #include <trace/events/btrfs.h>
+#include "ctree.h"
 #include "block-rsv.h"
 #include "extent_map.h"
-#include "extent_io.h"
 #include "extent-io-tree.h"
-#include "ordered-data.h"
-#include "delayed-inode.h"
 
-struct extent_state;
 struct posix_acl;
 struct iov_iter;
 struct writeback_control;
 struct btrfs_root;
 struct btrfs_fs_info;
 struct btrfs_trans_handle;
+struct btrfs_bio;
+struct btrfs_file_extent;
+struct btrfs_delayed_node;
 
 /*
  * Since we search a directory based on f_pos (struct dir_context::pos) we have
index eba188a9e3bb58987acbd9d693eb59bc76c3f91a..c6812d5fcab7910eead5c964ffb84419fc2529d0 100644 (file)
 #include <linux/pagemap.h>
 #include "bio.h"
 #include "fs.h"
-#include "messages.h"
 
 struct address_space;
-struct page;
 struct inode;
 struct btrfs_inode;
 struct btrfs_ordered_extent;
-struct btrfs_bio;
 
 /*
  * We want to make sure that amount of RAM required to uncompress an extent is
index fe70b593c7cd9dcb5f0ce751f11d9599bdf1d542..16dd11c48531309053becb72a9286fdc7b30fd6e 100644 (file)
@@ -17,9 +17,7 @@
 #include <linux/refcount.h>
 #include <uapi/linux/btrfs_tree.h>
 #include "locking.h"
-#include "fs.h"
 #include "accessors.h"
-#include "extent-io-tree.h"
 
 struct extent_buffer;
 struct btrfs_block_rsv;
index 7b277934f66f9229bf8bd55b23a525791128670f..a4cc1bc63562272b9d400488d609f1350077204c 100644 (file)
@@ -15,6 +15,7 @@
 #include "defrag.h"
 #include "file-item.h"
 #include "super.h"
+#include "compression.h"
 
 static struct kmem_cache *btrfs_inode_defrag_cachep;
 
index 69863e398e223f05f7a7cef07498c88debfc038b..77e1bcb2a74bf11a3cd1fd0cbfb5042aa697a669 100644 (file)
@@ -9,6 +9,7 @@
 #include "transaction.h"
 #include "accessors.h"
 #include "dir-item.h"
+#include "delayed-inode.h"
 
 /*
  * insert a name into a directory, doing overflow properly if there is a hash
index db0191567b8db0b57acb8dd482593024833d141a..f225cc3fd3a1097caff821ef162c2a658590992a 100644 (file)
@@ -10,6 +10,8 @@
 #include "fs.h"
 #include "transaction.h"
 #include "volumes.h"
+#include "bio.h"
+#include "ordered-data.h"
 
 struct btrfs_dio_data {
        ssize_t submitted;
index 0aa7e5d1b05f6c9fa4b0a76db6a4b1928bc02715..46b715f3447b41747b04f5fc2639bbbadaf3db47 100644 (file)
@@ -50,6 +50,7 @@
 #include "relocation.h"
 #include "scrub.h"
 #include "super.h"
+#include "delayed-inode.h"
 
 #define BTRFS_SUPER_FLAG_SUPP  (BTRFS_HEADER_FLAG_WRITTEN |\
                                 BTRFS_HEADER_FLAG_RELOC |\
index 57920f2c6fe4ef32569f1f0a870a225675a1cde5..5320da83d0cf8ec15607756aed49fd1b50f62494 100644 (file)
@@ -9,7 +9,8 @@
 #include <linux/sizes.h>
 #include <linux/compiler_types.h>
 #include "ctree.h"
-#include "fs.h"
+#include "bio.h"
+#include "ordered-data.h"
 
 struct block_device;
 struct super_block;
index d7e5be81ea81812a4058d7ab47eedc6b5a557d48..86004b8daa96e934501703a7c8c417d0c5cd293c 100644 (file)
@@ -40,6 +40,7 @@
 #include "orphan.h"
 #include "tree-checker.h"
 #include "raid-stripe-tree.h"
+#include "delayed-inode.h"
 
 #undef SCRAMBLE_DELAYED_REFS
 
index 5fcbfe44218c443bef62d4a9377f46d2154e5d18..02ebb2f238afc1fcc6472906bf97f67b15454e9b 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/rwsem.h>
 #include <linux/list.h>
 #include <linux/slab.h>
-#include "compression.h"
 #include "messages.h"
 #include "ulist.h"
 #include "misc.h"
index d4b81ee4d97bdb459a89fe1627a2c045f307fdd5..6f685f3c93272169530da650ca2fd75a9f2142ca 100644 (file)
@@ -8,8 +8,7 @@
 #include <linux/rbtree.h>
 #include <linux/list.h>
 #include <linux/refcount.h>
-#include "misc.h"
-#include "compression.h"
+#include "fs.h"
 
 struct btrfs_inode;
 struct btrfs_fs_info;
index 63216c43676defd6a1d7d246d0039086b99c22d8..0d59e830018a633664a111bfc5d9cd56cf8dc473 100644 (file)
@@ -7,7 +7,7 @@
 #include <linux/list.h>
 #include <uapi/linux/btrfs_tree.h>
 #include "ctree.h"
-#include "accessors.h"
+#include "ordered-data.h"
 
 struct extent_map;
 struct btrfs_file_extent_item;
index 7958e6c4f6b3a79b360091363490646463d02063..3c8bcdcf525e5d6f9a73e34a870bc545a7437c1f 100644 (file)
@@ -71,6 +71,7 @@
 #include "backref.h"
 #include "raid-stripe-tree.h"
 #include "fiemap.h"
+#include "delayed-inode.h"
 
 #define COW_FILE_RANGE_KEEP_LOCKED     (1UL << 0)
 #define COW_FILE_RANGE_NO_INLINE       (1UL << 1)
index c3e1831a48a3631142e34440d7a91d5b85c1a98b..4ae6928fdca42fadb20ee5b4c793a3ca338d2546 100644 (file)
@@ -15,6 +15,7 @@
 #include "accessors.h"
 #include "extent-tree.h"
 #include "zoned.h"
+#include "delayed-inode.h"
 
 /*
  * HOW DOES SPACE RESERVATION WORK
index ad0552db7c7dcbfb7f091465a2c5ed020fbea683..d81a0ade559fd18ea5b5f727f236e2018698929e 100644 (file)
@@ -7,7 +7,6 @@
 #include <linux/atomic.h>
 #include <linux/sizes.h>
 #include "btrfs_inode.h"
-#include "fs.h"
 
 struct address_space;
 struct folio;
index 907f2d047b448a7ea7460dd34d281f940259b02f..03c62fd1a091d879b70bce7d063a6c985f63e00b 100644 (file)
@@ -32,6 +32,8 @@
 #include "ioctl.h"
 #include "relocation.h"
 #include "scrub.h"
+#include "ordered-data.h"
+#include "delayed-inode.h"
 
 static struct kmem_cache *btrfs_trans_handle_cachep;
 
index 9f7c777af6356c3cfaa6c706577ff436283b98eb..18ef069197e5bab9cc43e81f6b62ad8103ce7b72 100644 (file)
 #include <linux/wait.h>
 #include "btrfs_inode.h"
 #include "delayed-ref.h"
-#include "extent-io-tree.h"
-#include "block-rsv.h"
-#include "messages.h"
-#include "misc.h"
 
 struct dentry;
 struct inode;
index bec93a0a6756d0fadc693eaef1b5ef2fb75d9139..c9eb35fa5b2076ee4008e3d94fc392780ba3ef2f 100644 (file)
@@ -29,6 +29,7 @@
 #include "orphan.h"
 #include "print-tree.h"
 #include "tree-checker.h"
+#include "delayed-inode.h"
 
 #define MAX_CONFLICT_INODES 10
 
index dc313e6bb2faa11e7cbdc6ce25cd0e44b3fdca96..4f149d7d4fdee13deb929fd2f30c0ca57f80d49c 100644 (file)
@@ -8,8 +8,7 @@
 
 #include <linux/list.h>
 #include <linux/fs.h>
-#include "messages.h"
-#include "ctree.h"
+#include <linux/fscrypt.h>
 #include "transaction.h"
 
 struct inode;
index d64f7c9255faf916d2876c352a5ff782cb17f790..5cefdeb08b7b71f511478dd2c06c8a2fd8646dfe 100644 (file)
@@ -15,7 +15,6 @@
 #include "disk-io.h"
 #include "block-group.h"
 #include "btrfs_inode.h"
-#include "fs.h"
 
 struct block_device;
 struct extent_buffer;