btrfs: headers cleanup to remove unnecessary local includes

[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>
This commit is contained in:
Qu Wenruo 2025-10-28 10:06:36 +10:30 committed by David Sterba
parent afc04c8b1b
commit c5667f9c8e
21 changed files with 21 additions and 22 deletions

View File

@ -12,6 +12,7 @@
#include <linux/string.h> #include <linux/string.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <uapi/linux/btrfs_tree.h> #include <uapi/linux/btrfs_tree.h>
#include "fs.h"
#include "extent_io.h" #include "extent_io.h"
struct extent_buffer; struct extent_buffer;

View File

@ -18,20 +18,20 @@
#include <linux/lockdep.h> #include <linux/lockdep.h>
#include <uapi/linux/btrfs_tree.h> #include <uapi/linux/btrfs_tree.h>
#include <trace/events/btrfs.h> #include <trace/events/btrfs.h>
#include "ctree.h"
#include "block-rsv.h" #include "block-rsv.h"
#include "extent_map.h" #include "extent_map.h"
#include "extent_io.h"
#include "extent-io-tree.h" #include "extent-io-tree.h"
#include "ordered-data.h"
#include "delayed-inode.h"
struct extent_state;
struct posix_acl; struct posix_acl;
struct iov_iter; struct iov_iter;
struct writeback_control; struct writeback_control;
struct btrfs_root; struct btrfs_root;
struct btrfs_fs_info; struct btrfs_fs_info;
struct btrfs_trans_handle; 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 * Since we search a directory based on f_pos (struct dir_context::pos) we have

View File

@ -14,14 +14,11 @@
#include <linux/pagemap.h> #include <linux/pagemap.h>
#include "bio.h" #include "bio.h"
#include "fs.h" #include "fs.h"
#include "messages.h"
struct address_space; struct address_space;
struct page;
struct inode; struct inode;
struct btrfs_inode; struct btrfs_inode;
struct btrfs_ordered_extent; struct btrfs_ordered_extent;
struct btrfs_bio;
/* /*
* We want to make sure that amount of RAM required to uncompress an extent is * We want to make sure that amount of RAM required to uncompress an extent is

View File

@ -17,9 +17,7 @@
#include <linux/refcount.h> #include <linux/refcount.h>
#include <uapi/linux/btrfs_tree.h> #include <uapi/linux/btrfs_tree.h>
#include "locking.h" #include "locking.h"
#include "fs.h"
#include "accessors.h" #include "accessors.h"
#include "extent-io-tree.h"
struct extent_buffer; struct extent_buffer;
struct btrfs_block_rsv; struct btrfs_block_rsv;

View File

@ -15,6 +15,7 @@
#include "defrag.h" #include "defrag.h"
#include "file-item.h" #include "file-item.h"
#include "super.h" #include "super.h"
#include "compression.h"
static struct kmem_cache *btrfs_inode_defrag_cachep; static struct kmem_cache *btrfs_inode_defrag_cachep;

View File

@ -9,6 +9,7 @@
#include "transaction.h" #include "transaction.h"
#include "accessors.h" #include "accessors.h"
#include "dir-item.h" #include "dir-item.h"
#include "delayed-inode.h"
/* /*
* insert a name into a directory, doing overflow properly if there is a hash * insert a name into a directory, doing overflow properly if there is a hash

View File

@ -10,6 +10,8 @@
#include "fs.h" #include "fs.h"
#include "transaction.h" #include "transaction.h"
#include "volumes.h" #include "volumes.h"
#include "bio.h"
#include "ordered-data.h"
struct btrfs_dio_data { struct btrfs_dio_data {
ssize_t submitted; ssize_t submitted;

View File

@ -50,6 +50,7 @@
#include "relocation.h" #include "relocation.h"
#include "scrub.h" #include "scrub.h"
#include "super.h" #include "super.h"
#include "delayed-inode.h"
#define BTRFS_SUPER_FLAG_SUPP (BTRFS_HEADER_FLAG_WRITTEN |\ #define BTRFS_SUPER_FLAG_SUPP (BTRFS_HEADER_FLAG_WRITTEN |\
BTRFS_HEADER_FLAG_RELOC |\ BTRFS_HEADER_FLAG_RELOC |\

View File

@ -9,7 +9,8 @@
#include <linux/sizes.h> #include <linux/sizes.h>
#include <linux/compiler_types.h> #include <linux/compiler_types.h>
#include "ctree.h" #include "ctree.h"
#include "fs.h" #include "bio.h"
#include "ordered-data.h"
struct block_device; struct block_device;
struct super_block; struct super_block;

View File

@ -40,6 +40,7 @@
#include "orphan.h" #include "orphan.h"
#include "tree-checker.h" #include "tree-checker.h"
#include "raid-stripe-tree.h" #include "raid-stripe-tree.h"
#include "delayed-inode.h"
#undef SCRAMBLE_DELAYED_REFS #undef SCRAMBLE_DELAYED_REFS

View File

@ -12,7 +12,6 @@
#include <linux/rwsem.h> #include <linux/rwsem.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/slab.h> #include <linux/slab.h>
#include "compression.h"
#include "messages.h" #include "messages.h"
#include "ulist.h" #include "ulist.h"
#include "misc.h" #include "misc.h"

View File

@ -8,8 +8,7 @@
#include <linux/rbtree.h> #include <linux/rbtree.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/refcount.h> #include <linux/refcount.h>
#include "misc.h" #include "fs.h"
#include "compression.h"
struct btrfs_inode; struct btrfs_inode;
struct btrfs_fs_info; struct btrfs_fs_info;

View File

@ -7,7 +7,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <uapi/linux/btrfs_tree.h> #include <uapi/linux/btrfs_tree.h>
#include "ctree.h" #include "ctree.h"
#include "accessors.h" #include "ordered-data.h"
struct extent_map; struct extent_map;
struct btrfs_file_extent_item; struct btrfs_file_extent_item;

View File

@ -71,6 +71,7 @@
#include "backref.h" #include "backref.h"
#include "raid-stripe-tree.h" #include "raid-stripe-tree.h"
#include "fiemap.h" #include "fiemap.h"
#include "delayed-inode.h"
#define COW_FILE_RANGE_KEEP_LOCKED (1UL << 0) #define COW_FILE_RANGE_KEEP_LOCKED (1UL << 0)
#define COW_FILE_RANGE_NO_INLINE (1UL << 1) #define COW_FILE_RANGE_NO_INLINE (1UL << 1)

View File

@ -15,6 +15,7 @@
#include "accessors.h" #include "accessors.h"
#include "extent-tree.h" #include "extent-tree.h"
#include "zoned.h" #include "zoned.h"
#include "delayed-inode.h"
/* /*
* HOW DOES SPACE RESERVATION WORK * HOW DOES SPACE RESERVATION WORK

View File

@ -7,7 +7,6 @@
#include <linux/atomic.h> #include <linux/atomic.h>
#include <linux/sizes.h> #include <linux/sizes.h>
#include "btrfs_inode.h" #include "btrfs_inode.h"
#include "fs.h"
struct address_space; struct address_space;
struct folio; struct folio;

View File

@ -32,6 +32,8 @@
#include "ioctl.h" #include "ioctl.h"
#include "relocation.h" #include "relocation.h"
#include "scrub.h" #include "scrub.h"
#include "ordered-data.h"
#include "delayed-inode.h"
static struct kmem_cache *btrfs_trans_handle_cachep; static struct kmem_cache *btrfs_trans_handle_cachep;

View File

@ -14,10 +14,6 @@
#include <linux/wait.h> #include <linux/wait.h>
#include "btrfs_inode.h" #include "btrfs_inode.h"
#include "delayed-ref.h" #include "delayed-ref.h"
#include "extent-io-tree.h"
#include "block-rsv.h"
#include "messages.h"
#include "misc.h"
struct dentry; struct dentry;
struct inode; struct inode;

View File

@ -29,6 +29,7 @@
#include "orphan.h" #include "orphan.h"
#include "print-tree.h" #include "print-tree.h"
#include "tree-checker.h" #include "tree-checker.h"
#include "delayed-inode.h"
#define MAX_CONFLICT_INODES 10 #define MAX_CONFLICT_INODES 10

View File

@ -8,8 +8,7 @@
#include <linux/list.h> #include <linux/list.h>
#include <linux/fs.h> #include <linux/fs.h>
#include "messages.h" #include <linux/fscrypt.h>
#include "ctree.h"
#include "transaction.h" #include "transaction.h"
struct inode; struct inode;

View File

@ -15,7 +15,6 @@
#include "disk-io.h" #include "disk-io.h"
#include "block-group.h" #include "block-group.h"
#include "btrfs_inode.h" #include "btrfs_inode.h"
#include "fs.h"
struct block_device; struct block_device;
struct extent_buffer; struct extent_buffer;