Skip to contentSkip to conversation

btrfs: basic header cleanups

PATCH In review Qu Wenruo 3 participants 7 messages May 28, 2024 Btrfs file system

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

cover btrfs: basic header cleanups

While reading headers, clangd would do a lot of extra checks, from the very basic like including the header itself, to missing type definition inside the header's include chain.

There are 2 very basic fixes can be done immediately:

- Do not do recursive include

- Do not include rwlock_types.h
As it already mentioned to include spinlock_types.h instead.

Qu Wenruo (2):
btrfs: cleanup recursive include of the same header
btrfs: do not directly rwlock_types.h

 fs/btrfs/btrfs_inode.h | 1 -
 fs/btrfs/extent_map.h  | 3 +--
 fs/btrfs/fs.h          | 1 -
 fs/btrfs/locking.h     | 1 -
 fs/btrfs/lru_cache.h   | 1 -
 5 files changed, 1 insertion(+), 6 deletions(-)
Signature · 1 line
2.45.1
author
#1 lore raw

PATCH 1/2 btrfs: cleanup recursive include of the same header

We have several headers that are including themselves, triggering clangd warnings.

Just remove such unnecessary include.

---
 fs/btrfs/btrfs_inode.h | 1 -
 fs/btrfs/extent_map.h  | 1 -
 fs/btrfs/fs.h          | 1 -
 fs/btrfs/locking.h     | 1 -
 fs/btrfs/lru_cache.h   | 1 -
 5 files changed, 5 deletions(-)
fs/btrfs/btrfs_inode.h +0 -1
index 97ce56a60672..08828e1ea1f7 100644
@@ -19,7 +19,6 @@
 #include <uapi/linux/btrfs_tree.h>
 #include <trace/events/btrfs.h>
 #include "block-rsv.h"
-#include "btrfs_inode.h"
 #include "extent_map.h"
 #include "extent_io.h"
 #include "extent-io-tree.h"
fs/btrfs/extent_map.h +0 -1
index 2bcf7149b44c..d3d1e5b7528d 100644
@@ -9,7 +9,6 @@
 #include <linux/list.h>
 #include <linux/refcount.h>
 #include "misc.h"
-#include "extent_map.h"
 #include "compression.h"
 
 struct btrfs_inode;
fs/btrfs/fs.h +0 -1
index 89f0650631cd..e6b1903f6c32 100644
@@ -29,7 +29,6 @@
 #include "extent-io-tree.h"
 #include "async-thread.h"
 #include "block-rsv.h"
-#include "fs.h"
 
 struct inode;
 struct super_block;
fs/btrfs/locking.h +0 -1
index 1bc8e6738879..3c15c75e0582 100644
@@ -11,7 +11,6 @@
 #include <linux/lockdep.h>
 #include <linux/percpu_counter.h>
 #include "extent_io.h"
-#include "locking.h"
 
 struct extent_buffer;
 struct btrfs_path;
fs/btrfs/lru_cache.h +0 -1
index e32906ab6faa..07f1bb1c6aa3 100644
@@ -6,7 +6,6 @@
 #include <linux/types.h>
 #include <linux/maple_tree.h>
 #include <linux/list.h>
-#include "lru_cache.h"
 
 /*
  * A cache entry. This is meant to be embedded in a structure of a user of
Signature · 1 line
2.45.1
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] btrfs: cleanup recursive include of the same header

Quoted 7 lines · Qu Wenruo

We have several headers that are including themselves, triggering clangd warnings.

Just remove such unnecessary include.

Maybe add a

Fixes 602035d7fecf ("btrfs: add forward declarations and headers, part 2")

Not sure how many people are using clangd or if it causes warnings with other tools.

Anyway:

Thanks.

Quoted 72 lines
---
 fs/btrfs/btrfs_inode.h | 1 -
 fs/btrfs/extent_map.h  | 1 -
 fs/btrfs/fs.h          | 1 -
 fs/btrfs/locking.h     | 1 -
 fs/btrfs/lru_cache.h   | 1 -
 5 files changed, 5 deletions(-)
fs/btrfs/btrfs_inode.h +0 -1
index 97ce56a60672..08828e1ea1f7 100644
@@ -19,7 +19,6 @@
 #include <uapi/linux/btrfs_tree.h>
 #include <trace/events/btrfs.h>
 #include "block-rsv.h"
-#include "btrfs_inode.h"
 #include "extent_map.h"
 #include "extent_io.h"
 #include "extent-io-tree.h"
fs/btrfs/extent_map.h +0 -1
index 2bcf7149b44c..d3d1e5b7528d 100644
@@ -9,7 +9,6 @@
 #include <linux/list.h>
 #include <linux/refcount.h>
 #include "misc.h"
-#include "extent_map.h"
 #include "compression.h"
 
 struct btrfs_inode;
fs/btrfs/fs.h +0 -1
index 89f0650631cd..e6b1903f6c32 100644
@@ -29,7 +29,6 @@
 #include "extent-io-tree.h"
 #include "async-thread.h"
 #include "block-rsv.h"
-#include "fs.h"
 
 struct inode;
 struct super_block;
fs/btrfs/locking.h +0 -1
index 1bc8e6738879..3c15c75e0582 100644
@@ -11,7 +11,6 @@
 #include <linux/lockdep.h>
 #include <linux/percpu_counter.h>
 #include "extent_io.h"
-#include "locking.h"
 
 struct extent_buffer;
 struct btrfs_path;
fs/btrfs/lru_cache.h +0 -2
index e32906ab6faa..07f1bb1c6aa3 100644
@@ -6,7 +6,6 @@
 #include <linux/types.h>
 #include <linux/maple_tree.h>
 #include <linux/list.h>
-#include "lru_cache.h"
 
 /*
  * A cache entry. This is meant to be embedded in a structure of a user of
--

2.45.1

#3 lore raw

Re: [PATCH 1/2] btrfs: cleanup recursive include of the same header

Quoted 5 lines · Filipe Manana
Quoted 4 lines · Qu Wenruo

We have several headers that are including themselves, triggering clangd warnings.

Quoted 7 lines
Quoted 3 lines

Just remove such unnecessary include.

Maybe add a

Fixes 602035d7fecf ("btrfs: add forward declarations and headers, part 2")

Adding Fixes: to tags could trigger the stable workflow and the patches could be picked for backport although it's not necessary. Mentioning the patch that introduced the problme in changelog text should be sufficient in such cases.

author
#4 lore raw

PATCH 2/2 btrfs: do not directly rwlock_types.h

In reply to Qu Wenruo

There is already an error inside that header:

#if !defined(__LINUX_SPINLOCK_TYPES_H)

 # error "Do not include directly, include spinlock_types.h"
 #endif

Thankfully it never get triggered as some other headers have already included spinlock_types.h.

However clangd would still do a proper warning on that if only extent_map.h is opened.
Fix it by using spinlock_types.h instead.

---
 fs/btrfs/extent_map.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/extent_map.h +1 -1
index d3d1e5b7528d..5154a8f1d26c 100644
@@ -4,7 +4,7 @@
 #define BTRFS_EXTENT_MAP_H
 
 #include <linux/compiler_types.h>
-#include <linux/rwlock_types.h>
+#include <linux/spinlock_types.h>
 #include <linux/rbtree.h>
 #include <linux/list.h>
 #include <linux/refcount.h>
Signature · 1 line
2.45.1
Reviewed-by on v1 2/2
#5 lore raw

Re: [PATCH 2/2] btrfs: do not directly rwlock_types.h

Quoted 7 lines · Qu Wenruo

There is already an error inside that header:

#if !defined(__LINUX_SPINLOCK_TYPES_H)

 # error "Do not include directly, include spinlock_types.h"
 #endif
Quoted 8 lines

Thankfully it never get triggered as some other headers have already included spinlock_types.h.

However clangd would still do a proper warning on that if only extent_map.h is opened.
Fix it by using spinlock_types.h instead.

Looks good, but the subject is missing a word, it should be:

btrfs: do not directly include rwlock_types.h

Anyway, that can be updated when adding the patch to for-next, so:

Thanks.

Quoted 21 lines
---
 fs/btrfs/extent_map.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/extent_map.h +1 -2
index d3d1e5b7528d..5154a8f1d26c 100644
@@ -4,7 +4,7 @@
 #define BTRFS_EXTENT_MAP_H
 
 #include <linux/compiler_types.h>
-#include <linux/rwlock_types.h>
+#include <linux/spinlock_types.h>
 #include <linux/rbtree.h>
 #include <linux/list.h>
 #include <linux/refcount.h>
--

2.45.1

Reviewed-by on the v1 series
#6 lore raw
In reply to Qu Wenruo
Quoted 6 lines · Qu Wenruo

While reading headers, clangd would do a lot of extra checks, from the very basic like including the header itself, to missing type definition inside the header's include chain.

There are 2 very basic fixes can be done immediately:

Quoted 8 lines

- Do not do recursive include

- Do not include rwlock_types.h
As it already mentioned to include spinlock_types.h instead.

Qu Wenruo (2):
btrfs: cleanup recursive include of the same header
btrfs: do not directly rwlock_types.h