Skip to contentSkip to conversation

btrfs: split out larger chunks of ctree.h

PATCH Superseded Josef Bacik 4 participants 45 messages Sep 14, 2022 – Oct 11, 2022 Btrfs file system

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover btrfs: split out larger chunks of ctree.h

Hello,

This series is based on the series

btrfs: initial ctree.h cleanups, simple stuff

which needs to be in place before applying these patches.

This is likely going to have the largest patch of the series, which bulk moves all of the struct funcs defines out of ctree.h into their own file. This isn't really possible to do piecemeal like other changes because we're using macros instead of functions. However the code is well organized so it allows for a bulk copy and paste, so is straightforward.

I've done my best with naming, but I'm open to suggestions. My general plan is to have all fs wide definitions in fs.h, and then separate out individual things to their own headers.

The biggest things I've done in this series are

1. Move the printk helpers into their own files.
2. Move the main state flags and core fs helpers into their own files.
3. Moved the struct func definitions to their own files.

This is by no means complete, this is just the first big pass, but as you can see is already 17 patches long. Subsequent patches will move more code and do more cleanups. Thanks,

Josef

Josef Bacik (16):
btrfs: move fs wide helpers out of ctree.h
btrfs: move larger compat flag helpers to their own c file
btrfs: move the printk helpers out of ctree.h
btrfs: push extra checks into __btrfs_abort_transaction
btrfs: move assert and error helpers out of btrfs-printk.h
btrfs: push printk index code into their respective helpers
btrfs: move BTRFS_FS_STATE* defs and helpers to fs.h
btrfs: move incompat and compat flag helpers to fs.c
btrfs: move mount option definitions to fs.h
btrfs: move fs_info->flags enum to fs.h
btrfs: add a BTRFS_FS_NEED_TRANS_COMMIT flag
btrfs: remove fs_info::pending_changes and related code
btrfs: move the compat/incompat flag masks to fs.h
btrfs: rename struct-funcs.c -> item-accessors.c
btrfs: move btrfs_map_token to item-accessors
btrfs: move accessor helpers into item-accessors.h

 fs/btrfs/Makefile                             |    4 +-
 fs/btrfs/backref.c                            |    2 +
 fs/btrfs/backref.h                            |    1 +
 fs/btrfs/block-group.c                        |    2 +
 fs/btrfs/block-rsv.c                          |    2 +
 fs/btrfs/btrfs-printk.h                       |  206 ++
 fs/btrfs/check-integrity.c                    |    2 +
 fs/btrfs/compression.c                        |    1 +
 fs/btrfs/ctree.c                              |    3 +
 fs/btrfs/ctree.h                              | 1784 +----------------
 fs/btrfs/delalloc-space.c                     |    2 +
 fs/btrfs/delayed-inode.c                      |    3 +
 fs/btrfs/delayed-ref.c                        |    2 +
 fs/btrfs/dev-replace.c                        |    2 +
 fs/btrfs/dir-item.c                           |    2 +
 fs/btrfs/discard.c                            |    1 +
 fs/btrfs/disk-io.c                            |    8 +-
 fs/btrfs/export.c                             |    1 +
 fs/btrfs/extent-io-tree.c                     |    1 +
 fs/btrfs/extent-tree.c                        |    2 +
 fs/btrfs/extent_io.c                          |    2 +
 fs/btrfs/extent_map.c                         |    1 +
 fs/btrfs/file-item.c                          |    3 +
 fs/btrfs/file.c                               |    2 +
 fs/btrfs/free-space-cache.c                   |    3 +
 fs/btrfs/free-space-tree.c                    |    3 +
 fs/btrfs/fs.c                                 |  108 +
 fs/btrfs/fs.h                                 |  320 +++
 fs/btrfs/inode-item.c                         |    2 +
 fs/btrfs/inode.c                              |    2 +
 fs/btrfs/ioctl.c                              |    2 +
 fs/btrfs/{struct-funcs.c => item-accessors.c} |   10 +
 fs/btrfs/item-accessors.h                     | 1104 ++++++++++
 fs/btrfs/lzo.c                                |    1 +
 fs/btrfs/ordered-data.c                       |    1 +
 fs/btrfs/print-tree.c                         |    2 +
 fs/btrfs/props.c                              |    3 +
 fs/btrfs/qgroup.c                             |    2 +
 fs/btrfs/raid56.c                             |    1 +
 fs/btrfs/ref-verify.c                         |    3 +
 fs/btrfs/reflink.c                            |    2 +
 fs/btrfs/relocation.c                         |    2 +
 fs/btrfs/root-tree.c                          |    3 +
 fs/btrfs/scrub.c                              |    2 +
 fs/btrfs/send.c                               |    1 +
 fs/btrfs/space-info.c                         |    2 +
 fs/btrfs/subpage.c                            |    1 +
 fs/btrfs/super.c                              |   51 +-
 fs/btrfs/sysfs.c                              |    7 +-
 fs/btrfs/tests/btrfs-tests.c                  |    1 +
 fs/btrfs/tests/extent-buffer-tests.c          |    1 +
 fs/btrfs/tests/free-space-tree-tests.c        |    1 +
 fs/btrfs/tests/inode-tests.c                  |    1 +
 fs/btrfs/tests/qgroup-tests.c                 |    2 +
 fs/btrfs/transaction.c                        |   29 +-
 fs/btrfs/transaction.h                        |    1 -
 fs/btrfs/tree-checker.c                       |    3 +
 fs/btrfs/tree-defrag.c                        |    1 +
 fs/btrfs/tree-log.c                           |    2 +
 fs/btrfs/tree-log.h                           |    1 +
 fs/btrfs/tree-mod-log.c                       |    3 +
 fs/btrfs/ulist.c                              |    1 +
 fs/btrfs/uuid-tree.c                          |    4 +-
 fs/btrfs/verity.c                             |    3 +
 fs/btrfs/volumes.c                            |    2 +
 fs/btrfs/xattr.c                              |    2 +
 fs/btrfs/zoned.c                              |    2 +
 fs/btrfs/zoned.h                              |    1 +
 68 files changed, 1915 insertions(+), 1823 deletions(-)
 create mode 100644 fs/btrfs/btrfs-printk.h
 create mode 100644 fs/btrfs/fs.c
 create mode 100644 fs/btrfs/fs.h
 rename fs/btrfs/{struct-funcs.c => item-accessors.c} (96%)
 create mode 100644 fs/btrfs/item-accessors.h
Signature · 1 line
2.26.3
#1 lore raw

PATCH 1/16 btrfs: move fs wide helpers out of ctree.h

We have several fs wide related helpers in ctree.h. The bulk of these are the incompat flag test helpers, but there are things such as btrfs_fs_closing() and the read only helpers that also aren't directly related to the ctree code. Move these into a fs.h header, which will serve as the location for file system wide related helpers.

---
 fs/btrfs/backref.c         |   1 +
 fs/btrfs/block-group.c     |   1 +
 fs/btrfs/ctree.h           | 164 -----------------------------------
 fs/btrfs/disk-io.c         |   1 +
 fs/btrfs/extent-tree.c     |   1 +
 fs/btrfs/file-item.c       |   1 +
 fs/btrfs/file.c            |   1 +
 fs/btrfs/free-space-tree.c |   1 +
 fs/btrfs/fs.h              | 170 +++++++++++++++++++++++++++++++++++++
 fs/btrfs/inode.c           |   1 +
 fs/btrfs/ioctl.c           |   1 +
 fs/btrfs/props.c           |   1 +
 fs/btrfs/qgroup.c          |   1 +
 fs/btrfs/relocation.c      |   1 +
 fs/btrfs/scrub.c           |   1 +
 fs/btrfs/space-info.c      |   1 +
 fs/btrfs/super.c           |   1 +
 fs/btrfs/transaction.c     |   1 +
 fs/btrfs/tree-checker.c    |   1 +
 fs/btrfs/tree-log.c        |   1 +
 fs/btrfs/uuid-tree.c       |   1 +
 fs/btrfs/verity.c          |   1 +
 fs/btrfs/volumes.c         |   1 +
 fs/btrfs/zoned.c           |   1 +
 24 files changed, 192 insertions(+), 164 deletions(-)
 create mode 100644 fs/btrfs/fs.h
fs/btrfs/backref.c +1 -0
index 9d06f8c18b15..d2a33c4d2f35 100644
@@ -15,6 +15,7 @@
 #include "locking.h"
 #include "misc.h"
 #include "tree-mod-log.h"
+#include "fs.h"
 
 /* Just an arbitrary number so we can be sure this happened */
 #define BACKREF_FOUND_SHARED 6
fs/btrfs/block-group.c +1 -0
index c91f47a45b06..510d58290edc 100644
@@ -17,6 +17,7 @@
 #include "discard.h"
 #include "raid56.h"
 #include "zoned.h"
+#include "fs.h"
 
 #ifdef CONFIG_BTRFS_DEBUG
 int btrfs_should_fragment_free_space(struct btrfs_block_group *block_group)
fs/btrfs/ctree.h +0 -164

176 lines not on this page · raw message

fs/btrfs/disk-io.c +1 -0
index d32aa67f962b..f103bf712f75 100644
@@ -43,6 +43,7 @@
 #include "space-info.h"
 #include "zoned.h"
 #include "subpage.h"
+#include "fs.h"
 
 #define BTRFS_SUPER_FLAG_SUPP	(BTRFS_HEADER_FLAG_WRITTEN |\
 				 BTRFS_HEADER_FLAG_RELOC |\
fs/btrfs/extent-tree.c +1 -0
index 9818285dface..37f9f074da33 100644
@@ -36,6 +36,7 @@
 #include "rcu-string.h"
 #include "zoned.h"
 #include "dev-replace.h"
+#include "fs.h"
 
 #undef SCRAMBLE_DELAYED_REFS
 
fs/btrfs/file-item.c +1 -0
index 45949261c699..b5b54140847d 100644
@@ -16,6 +16,7 @@
 #include "volumes.h"
 #include "print-tree.h"
 #include "compression.h"
+#include "fs.h"
 
 #define __MAX_CSUM_ITEMS(r, size) ((unsigned long)(((BTRFS_LEAF_DATA_SIZE(r) - \
 				   sizeof(struct btrfs_item) * 2) / \
fs/btrfs/file.c +1 -0
index fea508a35900..7fc77b454d8e 100644
@@ -30,6 +30,7 @@
 #include "delalloc-space.h"
 #include "reflink.h"
 #include "subpage.h"
+#include "fs.h"
 
 static struct kmem_cache *btrfs_inode_defrag_cachep;
 /*
fs/btrfs/free-space-tree.c +1 -0
index 367bcfcf68f5..bfc21eb8ec63 100644
@@ -11,6 +11,7 @@
 #include "free-space-tree.h"
 #include "transaction.h"
 #include "block-group.h"
+#include "fs.h"
 
 static int __add_block_group_free_space(struct btrfs_trans_handle *trans,
 					struct btrfs_block_group *block_group,
fs/btrfs/fs.h new file +170 -0

170 lines not on this page · raw message

fs/btrfs/inode.c +1 -0
index da5be8f23f68..a6615106002a 100644
@@ -55,6 +55,7 @@
 #include "zoned.h"
 #include "subpage.h"
 #include "inode-item.h"
+#include "fs.h"
 
 struct btrfs_iget_args {
 	u64 ino;
fs/btrfs/ioctl.c +1 -0
index d5dd8bed1488..e8b5dc147637 100644
@@ -50,6 +50,7 @@
 #include "delalloc-space.h"
 #include "block-group.h"
 #include "subpage.h"
+#include "fs.h"
 
 #ifdef CONFIG_64BIT
 /* If we have a 32-bit userspace and 64-bit kernel, then the UAPI
fs/btrfs/props.c +1 -0
index 07f62e3ba6a5..ef17014221e2 100644
@@ -11,6 +11,7 @@
 #include "xattr.h"
 #include "compression.h"
 #include "space-info.h"
+#include "fs.h"
 
 #define BTRFS_PROP_HANDLERS_HT_BITS 8
 static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS);
fs/btrfs/qgroup.c +1 -0
index 9334c3157c22..041e4b368ea8 100644
@@ -24,6 +24,7 @@
 #include "block-group.h"
 #include "sysfs.h"
 #include "tree-mod-log.h"
+#include "fs.h"
 
 /*
  * Helpers to access qgroup reservation
fs/btrfs/relocation.c +1 -0
index 41adbfa3a5f6..5198dde6ad97 100644
@@ -28,6 +28,7 @@
 #include "zoned.h"
 #include "inode-item.h"
 #include "space-info.h"
+#include "fs.h"
 
 /*
  * Relocation overview
fs/btrfs/scrub.c +1 -0
index 35fca65f0f2a..c758d8ff2e69 100644
@@ -21,6 +21,7 @@
 #include "raid56.h"
 #include "block-group.h"
 #include "zoned.h"
+#include "fs.h"
 
 /*
  * This is only the first step towards a full-features scrub. It reads all
fs/btrfs/space-info.c +1 -0
index 226727b71dde..46be83bd4d70 100644
@@ -10,6 +10,7 @@
 #include "transaction.h"
 #include "block-group.h"
 #include "zoned.h"
+#include "fs.h"
 
 /*
  * HOW DOES SPACE RESERVATION WORK
fs/btrfs/super.c +1 -0
index c2e634de01e4..fc474d472566 100644
@@ -50,6 +50,7 @@
 #include "qgroup.h"
 #include "raid56.h"
 #include "space-info.h"
+#include "fs.h"
 #define CREATE_TRACE_POINTS
 #include <trace/events/btrfs.h>
 
fs/btrfs/transaction.c +1 -0
index ae7d4aca771d..bae77fb05e2b 100644
@@ -23,6 +23,7 @@
 #include "block-group.h"
 #include "space-info.h"
 #include "zoned.h"
+#include "fs.h"
 
 static struct kmem_cache *btrfs_trans_handle_cachep;
 
fs/btrfs/tree-checker.c +1 -0
index 43f905ab0a18..862d67798de5 100644
@@ -25,6 +25,7 @@
 #include "volumes.h"
 #include "misc.h"
 #include "btrfs_inode.h"
+#include "fs.h"
 
 /*
  * Error message should follow the following format:
fs/btrfs/tree-log.c +1 -0
index b5018e42cf06..90cc8a97c13b 100644
@@ -21,6 +21,7 @@
 #include "space-info.h"
 #include "zoned.h"
 #include "inode-item.h"
+#include "fs.h"
 
 #define MAX_CONFLICT_INODES 10
 
fs/btrfs/uuid-tree.c +1 -0
index b458452a1aaf..2d7eb290fb9c 100644
@@ -9,6 +9,7 @@
 #include "transaction.h"
 #include "disk-io.h"
 #include "print-tree.h"
+#include "fs.h"
 
 
 static void btrfs_uuid_to_key(u8 *uuid, u8 type, struct btrfs_key *key)
fs/btrfs/verity.c +1 -0
index ee00e33c309e..ab0b39badbbe 100644
@@ -15,6 +15,7 @@
 #include "transaction.h"
 #include "disk-io.h"
 #include "locking.h"
+#include "fs.h"
 
 /*
  * Implementation of the interface defined in struct fsverity_operations.
fs/btrfs/volumes.c +1 -0
index b4de4d5ed69f..1938fbf49507 100644
@@ -33,6 +33,7 @@
 #include "block-group.h"
 #include "discard.h"
 #include "zoned.h"
+#include "fs.h"
 
 static struct bio_set btrfs_bioset;
 
fs/btrfs/zoned.c +1 -0
index e2d073b08a7d..19b533a5766d 100644
@@ -15,6 +15,7 @@
 #include "transaction.h"
 #include "dev-replace.h"
 #include "space-info.h"
+#include "fs.h"
 
 /* Maximum number of zones to report per blkdev_report_zones() call */
 #define BTRFS_REPORT_NR_ZONES   4096
Signature · 1 line
2.26.3
Reviewed-by on v1 1/16
#2 lore raw

Re: [PATCH 01/16] btrfs: move fs wide helpers out of ctree.h

Quoted 7 lines · Josef Bacik

We have several fs wide related helpers in ctree.h. The bulk of these are the incompat flag test helpers, but there are things such as btrfs_fs_closing() and the read only helpers that also aren't directly related to the ctree code. Move these into a fs.h header, which will serve as the location for file system wide related helpers.

#3 lore raw

PATCH 2/16 btrfs: move larger compat flag helpers to their own c file

In reply to Josef Bacik

These helpers use a lot of different functions that would be defined elsewhere. Push them into a C file so we don't end up with weird header file dependencies.

---
 fs/btrfs/Makefile |   2 +-
 fs/btrfs/fs.c     |  92 +++++++++++++++++++++++++++++++++++++++
 fs/btrfs/fs.h     | 108 +++++++---------------------------------------
 3 files changed, 108 insertions(+), 94 deletions(-)
 create mode 100644 fs/btrfs/fs.c
fs/btrfs/Makefile +1 -1
index fa9ddcc9eb0b..eebb45c06485 100644
@@ -31,7 +31,7 @@ btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
 	   backref.o ulist.o qgroup.o send.o dev-replace.o raid56.o \
 	   uuid-tree.o props.o free-space-tree.o tree-checker.o space-info.o \
 	   block-rsv.o delalloc-space.o block-group.o discard.o reflink.o \
-	   subpage.o tree-mod-log.o extent-io-tree.o
+	   subpage.o tree-mod-log.o extent-io-tree.o fs.o
 
 btrfs-$(CONFIG_BTRFS_FS_POSIX_ACL) += acl.o
 btrfs-$(CONFIG_BTRFS_FS_CHECK_INTEGRITY) += check-integrity.o
fs/btrfs/fs.c new file +92 -0

92 lines not on this page · raw message

fs/btrfs/fs.h +15 -93

139 lines not on this page · raw message

Signature · 1 line
2.26.3
#4 lore raw

Re: [PATCH 02/16] btrfs: move larger compat flag helpers to their own c file

fs/btrfs/fs.h line 14

Quoted 5 lines
fs/btrfs/fs.h +4 -0
+void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
+			      const char *name);
+void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
+			      const char *name);

There is an extra definition here.
I think David can take care of it while merging.

While here, I would prefer to have functions arranged. Like, first, set-function and then its related clear-function; it improves readability.

Quoted 4 lines
  
  #define btrfs_set_fs_incompat(__fs_info, opt) \
  	__btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
  				#opt)

Further, the #defines are in the middle of the function definitions. I suggest they be at the bottom of the file.

Thanks,
Anand

Reviewed-by
#5 lore raw

Re: [PATCH 02/16] btrfs: move larger compat flag helpers to their own c file

Quoted 8 lines · Anand Jain

fs/btrfs/fs.h line 14

Quoted 5 lines
fs/btrfs/fs.h +4 -0
+void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
+                  const char *name);
+void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
+                  const char *name);

 There is an extra definition here.
 I think David can take care of it while merging.

With the above fixed. You may add

Quoted 13 lines

 While here, I would prefer to have functions arranged. Like, first, set-function and then its related clear-function; it improves readability.

Quoted 3 lines

  #define btrfs_set_fs_incompat(__fs_info, opt) \
      __btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
                  #opt)

 Further, the #defines are in the middle of the function definitions. I suggest they be at the bottom of the file.

Thanks,
Anand

#6 lore raw

Re: [PATCH 02/16] btrfs: move larger compat flag helpers to their own c file

In reply to Anand Jain
Quoted 14 lines · Anand Jain

fs/btrfs/fs.h line 14

Quoted 5 lines
fs/btrfs/fs.h +4 -0
+void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
+			      const char *name);
+void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
+			      const char *name);

There is an extra definition here.
I think David can take care of it while merging.

While here, I would prefer to have functions arranged. Like, first, set-function and then its related clear-function; it improves readability.

Quoted 1 line
Quoted 6 lines
Quoted 3 lines
  #define btrfs_set_fs_incompat(__fs_info, opt) \
  	__btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
  				#opt)

Further, the #defines are in the middle of the function definitions. I suggest they be at the bottom of the file.

I've moved the defines before the function prototypes.

#7 lore raw

PATCH 3/16 btrfs: move the printk helpers out of ctree.h

In reply to Josef Bacik

We have a bunch of printk helpers that are in ctree.h. These have nothing to do with ctree.c, so move them into their own header. Subsequent patches will cleanup the printk helpers.

---
 fs/btrfs/backref.h          |   1 +
 fs/btrfs/btrfs-printk.h     | 269 ++++++++++++++++++++++++++++++++++++
 fs/btrfs/check-integrity.c  |   1 +
 fs/btrfs/ctree.c            |   1 +
 fs/btrfs/ctree.h            | 258 ----------------------------------
 fs/btrfs/delalloc-space.c   |   1 +
 fs/btrfs/delayed-inode.c    |   1 +
 fs/btrfs/delayed-ref.c      |   1 +
 fs/btrfs/dir-item.c         |   1 +
 fs/btrfs/extent-io-tree.c   |   1 +
 fs/btrfs/extent_map.c       |   1 +
 fs/btrfs/file-item.c        |   1 +
 fs/btrfs/free-space-cache.c |   1 +
 fs/btrfs/free-space-tree.c  |   1 +
 fs/btrfs/fs.c               |   1 +
 fs/btrfs/inode-item.c       |   1 +
 fs/btrfs/lzo.c              |   1 +
 fs/btrfs/ordered-data.c     |   1 +
 fs/btrfs/print-tree.c       |   1 +
 fs/btrfs/props.c            |   1 +
 fs/btrfs/raid56.c           |   1 +
 fs/btrfs/ref-verify.c       |   1 +
 fs/btrfs/reflink.c          |   1 +
 fs/btrfs/root-tree.c        |   1 +
 fs/btrfs/struct-funcs.c     |   1 +
 fs/btrfs/subpage.c          |   1 +
 fs/btrfs/super.c            |   1 +
 fs/btrfs/sysfs.c            |   1 +
 fs/btrfs/tree-checker.c     |   1 +
 fs/btrfs/tree-log.h         |   1 +
 fs/btrfs/tree-mod-log.c     |   1 +
 fs/btrfs/ulist.c            |   1 +
 fs/btrfs/uuid-tree.c        |   1 +
 fs/btrfs/verity.c           |   1 +
 fs/btrfs/xattr.c            |   1 +
 fs/btrfs/zoned.h            |   1 +
 36 files changed, 303 insertions(+), 258 deletions(-)
 create mode 100644 fs/btrfs/btrfs-printk.h
fs/btrfs/backref.h +1 -0
index 52ae6957b414..d60052247a81 100644
@@ -7,6 +7,7 @@
 #define BTRFS_BACKREF_H
 
 #include <linux/btrfs.h>
+#include "btrfs-printk.h"
 #include "ulist.h"
 #include "disk-io.h"
 #include "extent_io.h"
fs/btrfs/btrfs-printk.h new file +269 -0

269 lines not on this page · raw message

fs/btrfs/check-integrity.c +1 -0
index 98c6e5feab19..60ff8ce1820e 100644
@@ -82,6 +82,7 @@
 #include <linux/mm.h>
 #include <linux/string.h>
 #include <crypto/hash.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
fs/btrfs/ctree.c +1 -0
index 0f7f93bc2582..c4a0228322fe 100644
@@ -8,6 +8,7 @@
 #include <linux/rbtree.h>
 #include <linux/mm.h>
 #include <linux/error-injection.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
fs/btrfs/ctree.h +0 -258

276 lines not on this page · raw message

fs/btrfs/delalloc-space.c +1 -0
index 1e8f17ff829e..006b12ee12af 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "delalloc-space.h"
 #include "block-rsv.h"
fs/btrfs/delayed-inode.c +1 -0
index a411f04a7b97..f3ff22ce3a7b 100644
@@ -6,6 +6,7 @@
 
 #include <linux/slab.h>
 #include <linux/iversion.h>
+#include "btrfs-printk.h"
 #include "misc.h"
 #include "delayed-inode.h"
 #include "disk-io.h"
fs/btrfs/delayed-ref.c +1 -0
index 36a3debe9493..6d30f74a4574 100644
@@ -6,6 +6,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/sort.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "delayed-ref.h"
 #include "transaction.h"
fs/btrfs/dir-item.c +1 -0
index 72fb2c518a2b..e53640dfacca 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2007 Oracle.  All rights reserved.
  */
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
fs/btrfs/extent-io-tree.c +1 -0
index 52a9dbca79bc..f76f3ec6fc9e 100644
@@ -2,6 +2,7 @@
 
 #include <linux/slab.h>
 #include <trace/events/btrfs.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "extent-io-tree.h"
 #include "btrfs_inode.h"
fs/btrfs/extent_map.c +1 -0
index d5640e695e6b..1ee4d0c4c20a 100644
@@ -3,6 +3,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "volumes.h"
 #include "extent_map.h"
fs/btrfs/file-item.c +1 -0
index b5b54140847d..07cfffabbe84 100644
@@ -9,6 +9,7 @@
 #include <linux/highmem.h>
 #include <linux/sched/mm.h>
 #include <crypto/hash.h>
+#include "btrfs-printk.h"
 #include "misc.h"
 #include "ctree.h"
 #include "disk-io.h"
fs/btrfs/free-space-cache.c +1 -0
index ee03c5e6db4c..3027c709a7cf 100644
@@ -11,6 +11,7 @@
 #include <linux/ratelimit.h>
 #include <linux/error-injection.h>
 #include <linux/sched/mm.h>
+#include "btrfs-printk.h"
 #include "misc.h"
 #include "ctree.h"
 #include "free-space-cache.h"
fs/btrfs/free-space-tree.c +1 -0
index bfc21eb8ec63..5e0829456eb9 100644
@@ -5,6 +5,7 @@
 
 #include <linux/kernel.h>
 #include <linux/sched/mm.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "locking.h"
fs/btrfs/fs.c +1 -0
index d4ba948eba56..31cac6c6f062 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "fs.h"
 
fs/btrfs/inode-item.c +1 -0
index 366f3a788c6a..02cd4210edf3 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2007 Oracle.  All rights reserved.
  */
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "inode-item.h"
 #include "disk-io.h"
fs/btrfs/lzo.c +1 -0
index 89bc5f825e0a..69e7c6cc6a6f 100644
@@ -13,6 +13,7 @@
 #include <linux/bio.h>
 #include <linux/lzo.h>
 #include <linux/refcount.h>
+#include "btrfs-printk.h"
 #include "compression.h"
 #include "ctree.h"
 
fs/btrfs/ordered-data.c +1 -0
index 40a364c11178..60de19da09e1 100644
@@ -7,6 +7,7 @@
 #include <linux/blkdev.h>
 #include <linux/writeback.h>
 #include <linux/sched/mm.h>
+#include "btrfs-printk.h"
 #include "misc.h"
 #include "ctree.h"
 #include "transaction.h"
fs/btrfs/print-tree.c +1 -0
index dd8777872143..40576965d3da 100644
@@ -3,6 +3,7 @@
  * Copyright (C) 2007 Oracle.  All rights reserved.
  */
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "print-tree.h"
fs/btrfs/props.c +1 -0
index ef17014221e2..f95bc8e8d90a 100644
@@ -4,6 +4,7 @@
  */
 
 #include <linux/hashtable.h>
+#include "btrfs-printk.h"
 #include "props.h"
 #include "btrfs_inode.h"
 #include "transaction.h"
fs/btrfs/raid56.c +1 -0
index f6395e8288d6..cb8e3a362f50 100644
@@ -13,6 +13,7 @@
 #include <linux/list_sort.h>
 #include <linux/raid/xor.h>
 #include <linux/mm.h>
+#include "btrfs-printk.h"
 #include "misc.h"
 #include "ctree.h"
 #include "disk-io.h"
fs/btrfs/ref-verify.c +1 -0
index a248f46cfe72..0d74ebd07159 100644
@@ -5,6 +5,7 @@
 
 #include <linux/sched.h>
 #include <linux/stacktrace.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "disk-io.h"
 #include "locking.h"
fs/btrfs/reflink.c +1 -0
index f50586ff85c8..6bc2231a7874 100644
@@ -2,6 +2,7 @@
 
 #include <linux/blkdev.h>
 #include <linux/iversion.h>
+#include "btrfs-printk.h"
 #include "compression.h"
 #include "ctree.h"
 #include "delalloc-space.h"
fs/btrfs/root-tree.c +1 -0
index e1f599d7a916..ab9e891ddb79 100644
@@ -5,6 +5,7 @@
 
 #include <linux/err.h>
 #include <linux/uuid.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "transaction.h"
 #include "disk-io.h"
fs/btrfs/struct-funcs.c +1 -0
index 12455b2b41de..ec6b0436d09a 100644
@@ -5,6 +5,7 @@
 
 #include <asm/unaligned.h>
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 
 static bool check_setget_bounds(const struct extent_buffer *eb,
fs/btrfs/subpage.c +1 -0
index 6fc2b77ae5c3..271776f217c5 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
 #include <linux/slab.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "subpage.h"
 #include "btrfs_inode.h"
fs/btrfs/super.c +1 -0
index fc474d472566..1b713c75ca08 100644
@@ -26,6 +26,7 @@
 #include <linux/ratelimit.h>
 #include <linux/crc32c.h>
 #include <linux/btrfs.h>
+#include "btrfs-printk.h"
 #include "delayed-inode.h"
 #include "ctree.h"
 #include "disk-io.h"
fs/btrfs/sysfs.c +1 -0
index 699b54b3acaa..24079df977ff 100644
@@ -11,6 +11,7 @@
 #include <linux/bug.h>
 #include <crypto/hash.h>
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "discard.h"
 #include "disk-io.h"
fs/btrfs/tree-checker.c +1 -0
index 862d67798de5..ec7de2a42b99 100644
@@ -18,6 +18,7 @@
 #include <linux/types.h>
 #include <linux/stddef.h>
 #include <linux/error-injection.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "tree-checker.h"
 #include "disk-io.h"
fs/btrfs/tree-log.h +1 -0
index aed1e05e9879..d8501f4988dd 100644
@@ -6,6 +6,7 @@
 #ifndef BTRFS_TREE_LOG_H
 #define BTRFS_TREE_LOG_H
 
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "transaction.h"
 
fs/btrfs/tree-mod-log.c +1 -0
index 8a3a14686d3e..51ace0ac5c2d 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include "btrfs-printk.h"
 #include "tree-mod-log.h"
 #include "disk-io.h"
 
fs/btrfs/ulist.c +1 -0
index 3374c9e9be67..2535f9482112 100644
@@ -5,6 +5,7 @@
  */
 
 #include <linux/slab.h>
+#include "btrfs-printk.h"
 #include "ulist.h"
 #include "ctree.h"
 
fs/btrfs/uuid-tree.c +1 -0
index 2d7eb290fb9c..a24c5b13cf85 100644
@@ -5,6 +5,7 @@
 
 #include <linux/uuid.h>
 #include <asm/unaligned.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "transaction.h"
 #include "disk-io.h"
fs/btrfs/verity.c +1 -0
index ab0b39badbbe..5b38625f915e 100644
@@ -10,6 +10,7 @@
 #include <linux/iversion.h>
 #include <linux/fsverity.h>
 #include <linux/sched/mm.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "btrfs_inode.h"
 #include "transaction.h"
fs/btrfs/xattr.c +1 -0
index 5bb8d8c86311..69ead7e90478 100644
@@ -12,6 +12,7 @@
 #include <linux/posix_acl_xattr.h>
 #include <linux/iversion.h>
 #include <linux/sched/mm.h>
+#include "btrfs-printk.h"
 #include "ctree.h"
 #include "btrfs_inode.h"
 #include "transaction.h"
fs/btrfs/zoned.h +1 -0
index e17462db3a84..1fd53e1a6fca 100644
@@ -5,6 +5,7 @@
 
 #include <linux/types.h>
 #include <linux/blkdev.h>
+#include "btrfs-printk.h"
 #include "volumes.h"
 #include "disk-io.h"
 #include "block-group.h"
Signature · 1 line
2.26.3
Reviewed-by on v1 3/16
#8 lore raw

Re: [PATCH 03/16] btrfs: move the printk helpers out of ctree.h

Quoted 5 lines · Josef Bacik

We have a bunch of printk helpers that are in ctree.h. These have nothing to do with ctree.c, so move them into their own header. Subsequent patches will cleanup the printk helpers.

#9 lore raw

PATCH 4/16 btrfs: push extra checks into __btrfs_abort_transaction

In reply to Josef Bacik

The btrfs_abort_transaction() macro uses quite a bit of flags and such that aren't local to btrfs-printk.h. Push this code down into __btrfs_abort_transaction to allow for a cleaner header file.

---
 fs/btrfs/btrfs-printk.h | 24 +++---------------------
 fs/btrfs/super.c        | 17 +++++++++++++++--
 2 files changed, 18 insertions(+), 23 deletions(-)
fs/btrfs/btrfs-printk.h +3 -21
index dd7a9fd4791c..7fd7c547c935 100644
@@ -206,32 +206,14 @@ const char * __attribute_const__ btrfs_decode_error(int errno);
 __cold
 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
 			       const char *function,
-			       unsigned int line, int errno, bool first_hit);
+			       unsigned int line, int errno);
 
 /*
  * Call btrfs_abort_transaction as early as possible when an error condition is
  * detected, that way the exact line number is reported.
  */
-#define btrfs_abort_transaction(trans, errno)		\
-do {								\
-	bool first = false;					\
-	/* Report first abort since mount */			\
-	if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,	\
-			&((trans)->fs_info->fs_state))) {	\
-		first = true;					\
-		if ((errno) != -EIO && (errno) != -EROFS) {		\
-			WARN(1, KERN_DEBUG				\
-			"BTRFS: Transaction aborted (error %d)\n",	\
-			(errno));					\
-		} else {						\
-			btrfs_debug((trans)->fs_info,			\
-				    "Transaction aborted (error %d)", \
-				  (errno));			\
-		}						\
-	}							\
-	__btrfs_abort_transaction((trans), __func__,		\
-				  __LINE__, (errno), first);	\
-} while (0)
+#define btrfs_abort_transaction(trans, errno)				\
+	__btrfs_abort_transaction((trans), __func__, __LINE__, (errno))
 
 #ifdef CONFIG_PRINTK_INDEX
 
fs/btrfs/super.c +15 -2
index 1b713c75ca08..6d5e161d94e1 100644
@@ -349,13 +349,26 @@ void __cold btrfs_err_32bit_limit(struct btrfs_fs_info *fs_info)
 __cold
 void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
 			       const char *function,
-			       unsigned int line, int errno, bool first_hit)
+			       unsigned int line, int errno)
 {
 	struct btrfs_fs_info *fs_info = trans->fs_info;
+	bool first = false;
+
+	/* Report first abort since mount */
+	if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,
+			      &fs_info->fs_state)) {
+		first = true;
+		if (errno != -EIO && errno != -EROFS)
+			WARN(1, KERN_DEBUG
+			     "BTRFS: Transaction aborted (error %d)\n", errno);
+		else
+			btrfs_debug(fs_info, "Transaction aborted (error %d)",
+				    errno);
+	}
 
 	WRITE_ONCE(trans->aborted, errno);
 	WRITE_ONCE(trans->transaction->aborted, errno);
-	if (first_hit && errno == -ENOSPC)
+	if (first && errno == -ENOSPC)
 		btrfs_dump_space_info_for_trans_abort(fs_info);
 	/* Wake up anybody who may be waiting on this transaction */
 	wake_up(&fs_info->transaction_wait);
Signature · 1 line
2.26.3
Reviewed-by on v1 4/16
#10 lore raw

Re: [PATCH 04/16] btrfs: push extra checks into __btrfs_abort_transaction

Quoted 5 lines · Josef Bacik

The btrfs_abort_transaction() macro uses quite a bit of flags and such that aren't local to btrfs-printk.h. Push this code down into __btrfs_abort_transaction to allow for a cleaner header file.

#11 lore raw

Re: [PATCH 04/16] btrfs: push extra checks into __btrfs_abort_transaction

In reply to Josef Bacik
Quoted 7 lines · Josef Bacik

The btrfs_abort_transaction() macro uses quite a bit of flags and such that aren't local to btrfs-printk.h. Push this code down into __btrfs_abort_transaction to allow for a cleaner header file.

---

fs/btrfs/btrfs-printk.h +0 -1
-#define btrfs_abort_transaction(trans, errno)		\

fs/btrfs/btrfs-printk.h const char * __attribute_const__ btrfs_decode_error(int errno); · line 225

Quoted 10 lines
fs/btrfs/btrfs-printk.h +0 -10
-do {								\
-	bool first = false;					\
-	/* Report first abort since mount */			\
-	if (!test_and_set_bit(BTRFS_FS_STATE_TRANS_ABORTED,	\
-			&((trans)->fs_info->fs_state))) {	\
-		first = true;					\
-		if ((errno) != -EIO && (errno) != -EROFS) {		\
-			WARN(1, KERN_DEBUG				\
-			"BTRFS: Transaction aborted (error %d)\n",	\
-			(errno));					\

The point of this was to print the stack trace from the function where it happens and not with btrfs_abort_transaction at the top. IIRC this was confusing when people were reporting transaction abort and all the reports were hard to distinguish because all were "warning in __btrfs_transaction_abort:line".

1a9a8a71ed1d457d "btrfs: report exact callsite where transaction abort occurs"

Quoted 9 lines
fs/btrfs/btrfs-printk.h +0 -9
-		} else {						\
-			btrfs_debug((trans)->fs_info,			\
-				    "Transaction aborted (error %d)", \
-				  (errno));			\
-		}						\
-	}							\
-	__btrfs_abort_transaction((trans), __func__,		\
-				  __LINE__, (errno), first);	\
-} while (0)
#12 lore raw

PATCH 5/16 btrfs: move assert and error helpers out of btrfs-printk.h

In reply to Josef Bacik

These helpers call functions that aren't defined inside of btrfs-printk.h, move them into super.c where the rest of the helpers exist.

---
 fs/btrfs/btrfs-printk.h | 26 +++++---------------------
 fs/btrfs/super.c        | 16 +++++++++++++++-
 2 files changed, 20 insertions(+), 22 deletions(-)
fs/btrfs/btrfs-printk.h +5 -21
index 7fd7c547c935..87e46d24b4ad 100644
@@ -4,7 +4,6 @@
 #define BTRFS_PRINTK_H
 
 #include <linux/printk.h>
-#include <asm/bug.h>
 
 struct btrfs_fs_info;
 struct btrfs_trans_handle;
@@ -174,27 +173,15 @@ do {								\
 } while (0)
 
 #ifdef CONFIG_BTRFS_ASSERT
-__cold __noreturn
-static inline void assertfail(const char *expr, const char *file, int line)
-{
-	pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
-	BUG();
-}
-
+__cold
+void btrfs_assertfail(const char *expr, const char *file, int line);
 #define ASSERT(expr)						\
-	(likely(expr) ? (void)0 : assertfail(#expr, __FILE__, __LINE__))
-
+	(likely(expr) ? (void)0 : btrfs_assertfail(#expr, __FILE__, __LINE__))
 #else
-static inline void assertfail(const char *expr, const char* file, int line) { }
 #define ASSERT(expr)	(void)(expr)
 #endif
 
-__cold
-static inline void btrfs_print_v0_err(struct btrfs_fs_info *fs_info)
-{
-	btrfs_err(fs_info,
-"Unsupported V0 extent filesystem detected. Aborting. Please re-create your filesystem with a newer kernel");
-}
+__cold void btrfs_print_v0_err(struct btrfs_fs_info *fs_info);
 
 __printf(5, 6)
 __cold
@@ -243,9 +230,6 @@ void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
  * will panic().  Otherwise we BUG() here.
  */
 #define btrfs_panic(fs_info, errno, fmt, args...)			\
-do {									\
-	__btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args);	\
-	BUG();								\
-} while (0)
+	__btrfs_panic(fs_info, __func__, __LINE__, errno, fmt, ##args)
 
 #endif /* BTRFS_PRINTK_H */
fs/btrfs/super.c +15 -1
index 6d5e161d94e1..781e5faf83d5 100644
@@ -307,6 +307,20 @@ void __cold _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt,
 }
 #endif
 
+#ifdef CONFIG_BTRFS_ASSERT
+void __cold btrfs_assertfail(const char *expr, const char *file, int line)
+{
+	pr_err("assertion failed: %s, in %s:%d\n", expr, file, line);
+	BUG();
+}
+#endif
+
+void __cold btrfs_print_v0_err(struct btrfs_fs_info *fs_info)
+{
+	btrfs_err(fs_info,
+"Unsupported V0 extent filesystem detected. Aborting. Please re-create your filesystem with a newer kernel");
+}
+
 #if BITS_PER_LONG == 32
 void __cold btrfs_warn_32bit_limit(struct btrfs_fs_info *fs_info)
 {
@@ -402,7 +416,7 @@ void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
 	btrfs_crit(fs_info, "panic in %s:%d: %pV (errno=%d %s)",
 		   function, line, &vaf, errno, errstr);
 	va_end(args);
-	/* Caller calls BUG() */
+	BUG();
 }
 
 static void btrfs_put_super(struct super_block *sb)
Signature · 1 line
2.26.3
#14 lore raw

PATCH 6/16 btrfs: push printk index code into their respective helpers

In reply to Josef Bacik

The printk index work can be pushed into the printk helpers themselves, this allows us to further sanitize btrfs-printk.h, removing the last include in the header itself.

---
 fs/btrfs/btrfs-printk.h | 31 +------------------------------
 fs/btrfs/super.c        | 12 +++++++++++-
 2 files changed, 12 insertions(+), 31 deletions(-)
fs/btrfs/btrfs-printk.h +1 -30
index 87e46d24b4ad..e2fd6bbc7aa1 100644
@@ -3,8 +3,6 @@
 #ifndef BTRFS_PRINTK_H
 #define BTRFS_PRINTK_H
 
-#include <linux/printk.h>
-
 struct btrfs_fs_info;
 struct btrfs_trans_handle;
 
@@ -13,19 +11,7 @@ void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...)
 {
 }
 
-#ifdef CONFIG_PRINTK_INDEX
-
-#define btrfs_printk(fs_info, fmt, args...)					\
-do {										\
-	printk_index_subsys_emit("%sBTRFS %s (device %s): ", NULL, fmt);	\
-	_btrfs_printk(fs_info, fmt, ##args);					\
-} while (0)
-
-__printf(2, 3)
-__cold
-void _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...);
-
-#elif defined(CONFIG_PRINTK)
+#ifdef CONFIG_PRINTK
 
 #define btrfs_printk(fs_info, fmt, args...)				\
 	_btrfs_printk(fs_info, fmt, ##args)
@@ -202,25 +188,10 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
 #define btrfs_abort_transaction(trans, errno)				\
 	__btrfs_abort_transaction((trans), __func__, __LINE__, (errno))
 
-#ifdef CONFIG_PRINTK_INDEX
-
-#define btrfs_handle_fs_error(fs_info, errno, fmt, args...)		\
-do {									\
-	printk_index_subsys_emit(					\
-		"BTRFS: error (device %s%s) in %s:%d: errno=%d %s",	\
-		KERN_CRIT, fmt);					\
-	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,		\
-				(errno), fmt, ##args);			\
-} while (0)
-
-#else
-
 #define btrfs_handle_fs_error(fs_info, errno, fmt, args...)		\
 	__btrfs_handle_fs_error((fs_info), __func__, __LINE__,		\
 				(errno), fmt, ##args)
 
-#endif
-
 __printf(5, 6)
 __cold
 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
fs/btrfs/super.c +11 -1
index 781e5faf83d5..2865676b8327 100644
@@ -182,6 +182,12 @@ void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function
 	const char *errstr;
 #endif
 
+#ifdef CONFIG_PRINTK_INDEX
+	printk_index_subsys_emit(
+		"BTRFS: error (device %s%s) in %s:%d: errno=%d %s",
+		KERN_CRIT, fmt);
+#endif
+
 	/*
 	 * Special case: if the error is EROFS, and we're already
 	 * under SB_RDONLY, then it is safe here.
@@ -207,7 +213,7 @@ void __btrfs_handle_fs_error(struct btrfs_fs_info *fs_info, const char *function
 		pr_crit("BTRFS: error (device %s%s) in %s:%d: errno=%d %s\n",
 			sb->s_id, statestr, function, line, errno, errstr);
 	}
-#endif
+#endif /* CONFIG_PRINTK */
 
 	/*
 	 * Today we only save the error info to memory.  Long term we'll
@@ -274,6 +280,10 @@ void __cold _btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt,
 	const char *type = logtypes[4];
 	struct ratelimit_state *ratelimit = &printk_limits[4];
 
+#ifdef CONFIG_PRINTK_INDEX
+	printk_index_subsys_emit("%sBTRFS %s (device %s): ", NULL, fmt);
+#endif
+
 	va_start(args, fmt);
 
 	while ((kern_level = printk_get_level(fmt)) != 0) {
Signature · 1 line
2.26.3
Reviewed-by on v1 6/16
#15 lore raw

Re: [PATCH 06/16] btrfs: push printk index code into their respective helpers

Quoted 5 lines · Josef Bacik

The printk index work can be pushed into the printk helpers themselves, this allows us to further sanitize btrfs-printk.h, removing the last include in the header itself.

#16 lore raw

PATCH 7/16 btrfs: move BTRFS_FS_STATE* defs and helpers to fs.h

In reply to Josef Bacik

We're going to use fs.h to hold fs wide related helpers and definitions, move the FS_STATE enum and related helpers to fs.h, and then update all files that need these definitions to include fs.h.

---
 fs/btrfs/compression.c       |  1 +
 fs/btrfs/ctree.c             |  1 +
 fs/btrfs/ctree.h             | 46 ---------------------------------
 fs/btrfs/delalloc-space.c    |  1 +
 fs/btrfs/dev-replace.c       |  1 +
 fs/btrfs/extent_io.c         |  1 +
 fs/btrfs/fs.h                | 50 ++++++++++++++++++++++++++++++++++++
 fs/btrfs/sysfs.c             |  1 +
 fs/btrfs/tests/btrfs-tests.c |  1 +
 9 files changed, 57 insertions(+), 46 deletions(-)
fs/btrfs/compression.c +1 -0
index 54caa00a2245..d456c85f94dd 100644
@@ -31,6 +31,7 @@
 #include "extent_map.h"
 #include "subpage.h"
 #include "zoned.h"
+#include "fs.h"
 
 static const char* const btrfs_compress_types[] = { "", "zlib", "lzo", "zstd" };
 
fs/btrfs/ctree.c +1 -0
index c4a0228322fe..a5fd4e2369f1 100644
@@ -18,6 +18,7 @@
 #include "qgroup.h"
 #include "tree-mod-log.h"
 #include "tree-checker.h"
+#include "fs.h"
 
 static struct kmem_cache *btrfs_path_cachep;
 
fs/btrfs/ctree.h +0 -46

64 lines not on this page · raw message

fs/btrfs/delalloc-space.c +1 -0
index 006b12ee12af..7d561911f9ba 100644
@@ -9,6 +9,7 @@
 #include "transaction.h"
 #include "qgroup.h"
 #include "block-group.h"
+#include "fs.h"
 
 /*
  * HOW DOES THIS WORK
fs/btrfs/dev-replace.c +1 -0
index 61e58066b5fd..348aef453e69 100644
@@ -23,6 +23,7 @@
 #include "sysfs.h"
 #include "zoned.h"
 #include "block-group.h"
+#include "fs.h"
 
 /*
  * Device replace overview
fs/btrfs/extent_io.c +1 -0
index a426f0e6c145..c11c05ea099d 100644
@@ -30,6 +30,7 @@
 #include "zoned.h"
 #include "block-group.h"
 #include "compression.h"
+#include "fs.h"
 
 static struct kmem_cache *extent_buffer_cache;
 
fs/btrfs/fs.h +50 -0

60 lines not on this page · raw message

fs/btrfs/sysfs.c +1 -0
index 24079df977ff..4acff123fe66 100644
@@ -23,6 +23,7 @@
 #include "block-group.h"
 #include "qgroup.h"
 #include "misc.h"
+#include "fs.h"
 
 /*
  * Structure name                       Path
fs/btrfs/tests/btrfs-tests.c +1 -0
index 9c478fa256f6..1538c65f2b17 100644
@@ -16,6 +16,7 @@
 #include "../disk-io.h"
 #include "../qgroup.h"
 #include "../block-group.h"
+#include "../fs.h"
 
 static struct vfsmount *test_mnt = NULL;
 
Signature · 1 line
2.26.3
Reviewed-by on v1 7/16
#17 lore raw

Re: [PATCH 07/16] btrfs: move BTRFS_FS_STATE* defs and helpers to fs.h

Quoted 5 lines · Josef Bacik

We're going to use fs.h to hold fs wide related helpers and definitions, move the FS_STATE enum and related helpers to fs.h, and then update all files that need these definitions to include fs.h.

#18 lore raw

PATCH 8/16 btrfs: move incompat and compat flag helpers to fs.c

In reply to Josef Bacik

These helpers use functions not defined in fs.h, move them to fs.c to keep the header clean.

---
 fs/btrfs/fs.c | 14 ++++++++++++++
 fs/btrfs/fs.h | 16 ++--------------
 2 files changed, 16 insertions(+), 14 deletions(-)
fs/btrfs/fs.c +14 -0
index 31cac6c6f062..32fbc7f55730 100644
@@ -91,3 +91,17 @@ void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
 		spin_unlock(&fs_info->super_lock);
 	}
 }
+
+bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
+{
+	struct btrfs_super_block *disk_super;
+	disk_super = fs_info->super_copy;
+	return !!(btrfs_super_incompat_flags(disk_super) & flag);
+}
+
+int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)
+{
+	struct btrfs_super_block *disk_super;
+	disk_super = fs_info->super_copy;
+	return !!(btrfs_super_compat_ro_flags(disk_super) & flag);
+}
fs/btrfs/fs.h +2 -14
index 43fd78a9f46c..5e21ca9d172a 100644
@@ -45,6 +45,8 @@ void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
 			      const char *name);
 void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
 				const char *name);
+bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag);
+int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag);
 
 #define btrfs_set_fs_incompat(__fs_info, opt) \
 	__btrfs_set_fs_incompat((__fs_info), BTRFS_FEATURE_INCOMPAT_##opt, \
@@ -68,20 +70,6 @@ void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
 #define btrfs_fs_compat_ro(fs_info, opt) \
 	__btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
 
-static inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
-{
-	struct btrfs_super_block *disk_super;
-	disk_super = fs_info->super_copy;
-	return !!(btrfs_super_incompat_flags(disk_super) & flag);
-}
-
-static inline int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)
-{
-	struct btrfs_super_block *disk_super;
-	disk_super = fs_info->super_copy;
-	return !!(btrfs_super_compat_ro_flags(disk_super) & flag);
-}
-
 static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
 {
 	/*
Signature · 1 line
2.26.3
#20 lore raw

Re: [PATCH 08/16] btrfs: move incompat and compat flag helpers to fs.c

In reply to Josef Bacik
Quoted 2 lines · Josef Bacik

These helpers use functions not defined in fs.h, move them to fs.c to keep the header clean.

This is one of the examples where functions are switched from inline to out-of-line, so I'll reply for all of them.

fs/btrfs/fs.c void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag, · line 100

Quoted 6 lines
fs/btrfs/fs.c +6 -0
+bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
+{
+	struct btrfs_super_block *disk_super;
+	disk_super = fs_info->super_copy;
+	return !!(btrfs_super_incompat_flags(disk_super) & flag);
+}

This needs a separate function and unlike for the inline it needs a call which has some impact on the instruction flow. This should be evaluated if the un-inlined function is on a hot path or not.

In this case I think the incompat bits should be inline as it's in many places part of switching access to some structures or lookup.

At minimum some numbers and assembly examination should be done before ding that. The header cleanup part is nice but if the changes have performance implications it's suddenly not so easy.

I'll do some analysis to get an idea how bad/good it is.

#21 lore raw

Re: [PATCH 08/16] btrfs: move incompat and compat flag helpers to fs.c

Quoted 18 lines · David Sterba
Quoted 2 lines · Josef Bacik

These helpers use functions not defined in fs.h, move them to fs.c to keep the header clean.

This is one of the examples where functions are switched from inline to out-of-line, so I'll reply for all of them.

fs/btrfs/fs.c void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag, · line 100

Quoted 6 lines
fs/btrfs/fs.c +6 -0
+bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
+{
+	struct btrfs_super_block *disk_super;
+	disk_super = fs_info->super_copy;
+	return !!(btrfs_super_incompat_flags(disk_super) & flag);
+}

This needs a separate function and unlike for the inline it needs a call which has some impact on the instruction flow. This should be evaluated if the un-inlined function is on a hot path or not.

Quoted 8 lines

In this case I think the incompat bits should be inline as it's in many places part of switching access to some structures or lookup.

At minimum some numbers and assembly examination should be done before ding that. The header cleanup part is nice but if the changes have performance implications it's suddenly not so easy.

I'll do some analysis to get an idea how bad/good it is.

Not that good. When inlined it's basically

mov memory, rax
mov memory(rax), rax
test 0x1, rax

while uninlined it's

mov memory, rdi
mov memory, rsi
call
test rax, rax

the function itself is 4 instructions but with some additional ones compared to the inlined version (2).

#22 lore raw

PATCH 9/16 btrfs: move mount option definitions to fs.h

In reply to Josef Bacik

These are fs wide definitions and helpers, move them out of ctree.h and into fs.h.

---
 fs/btrfs/block-rsv.c        |  1 +
 fs/btrfs/ctree.h            | 62 -------------------------------------
 fs/btrfs/delayed-ref.c      |  1 +
 fs/btrfs/discard.c          |  1 +
 fs/btrfs/free-space-cache.c |  1 +
 fs/btrfs/fs.h               | 62 +++++++++++++++++++++++++++++++++++++
 fs/btrfs/ref-verify.c       |  1 +
 7 files changed, 67 insertions(+), 62 deletions(-)
fs/btrfs/block-rsv.c +1 -0
index ec96285357e0..6dad02dd1d63 100644
@@ -7,6 +7,7 @@
 #include "transaction.h"
 #include "block-group.h"
 #include "disk-io.h"
+#include "fs.h"
 
 /*
  * HOW DO BLOCK RESERVES WORK
fs/btrfs/ctree.h +0 -62

68 lines not on this page · raw message

fs/btrfs/delayed-ref.c +1 -0
index 6d30f74a4574..a2fbd48b46f1 100644
@@ -13,6 +13,7 @@
 #include "qgroup.h"
 #include "space-info.h"
 #include "tree-mod-log.h"
+#include "fs.h"
 
 struct kmem_cache *btrfs_delayed_ref_head_cachep;
 struct kmem_cache *btrfs_delayed_tree_ref_cachep;
fs/btrfs/discard.c +1 -0
index e1b7bd927d69..51f0ef386046 100644
@@ -11,6 +11,7 @@
 #include "block-group.h"
 #include "discard.h"
 #include "free-space-cache.h"
+#include "fs.h"
 
 /*
  * This contains the logic to handle async discard.
fs/btrfs/free-space-cache.c +1 -0
index 3027c709a7cf..b472da0e9d1b 100644
@@ -25,6 +25,7 @@
 #include "discard.h"
 #include "subpage.h"
 #include "inode-item.h"
+#include "fs.h"
 
 #define BITS_PER_BITMAP		(PAGE_SIZE * 8UL)
 #define MAX_CACHE_BYTES_PER_GIG	SZ_64K
fs/btrfs/fs.h +62 -0

74 lines not on this page · raw message

fs/btrfs/ref-verify.c +1 -0
index 0d74ebd07159..eddeb8885701 100644
@@ -11,6 +11,7 @@
 #include "locking.h"
 #include "delayed-ref.h"
 #include "ref-verify.h"
+#include "fs.h"
 
 /*
  * Used to keep track the roots and number of refs each root has for a given
Signature · 1 line
2.26.3
#24 lore raw

PATCH 10/16 btrfs: move fs_info->flags enum to fs.h

In reply to Josef Bacik

These definitions are fs wide, take them out of ctree.h and put them in fs.h.

---
 fs/btrfs/ctree.h              | 68 -----------------------------------
 fs/btrfs/delayed-inode.c      |  1 +
 fs/btrfs/fs.h                 | 68 +++++++++++++++++++++++++++++++++++
 fs/btrfs/root-tree.c          |  1 +
 fs/btrfs/tests/qgroup-tests.c |  1 +
 fs/btrfs/tree-mod-log.c       |  1 +
 6 files changed, 72 insertions(+), 68 deletions(-)
fs/btrfs/ctree.h +0 -68
index e08e956bd603..8decad27a6c5 100644
@@ -317,69 +317,6 @@ struct btrfs_swapfile_pin {
 
 bool btrfs_pinned_by_swapfile(struct btrfs_fs_info *fs_info, void *ptr);
 
-enum {
-	BTRFS_FS_CLOSING_START,
-	BTRFS_FS_CLOSING_DONE,
-	BTRFS_FS_LOG_RECOVERING,
-	BTRFS_FS_OPEN,
-	BTRFS_FS_QUOTA_ENABLED,
-	BTRFS_FS_UPDATE_UUID_TREE_GEN,
-	BTRFS_FS_CREATING_FREE_SPACE_TREE,
-	BTRFS_FS_BTREE_ERR,
-	BTRFS_FS_LOG1_ERR,
-	BTRFS_FS_LOG2_ERR,
-	BTRFS_FS_QUOTA_OVERRIDE,
-	/* Used to record internally whether fs has been frozen */
-	BTRFS_FS_FROZEN,
-	/*
-	 * Indicate that balance has been set up from the ioctl and is in the
-	 * main phase. The fs_info::balance_ctl is initialized.
-	 */
-	BTRFS_FS_BALANCE_RUNNING,
-
-	/*
-	 * Indicate that relocation of a chunk has started, it's set per chunk
-	 * and is toggled between chunks.
-	 */
-	BTRFS_FS_RELOC_RUNNING,
-
-	/* Indicate that the cleaner thread is awake and doing something. */
-	BTRFS_FS_CLEANER_RUNNING,
-
-	/*
-	 * The checksumming has an optimized version and is considered fast,
-	 * so we don't need to offload checksums to workqueues.
-	 */
-	BTRFS_FS_CSUM_IMPL_FAST,
-
-	/* Indicate that the discard workqueue can service discards. */
-	BTRFS_FS_DISCARD_RUNNING,
-
-	/* Indicate that we need to cleanup space cache v1 */
-	BTRFS_FS_CLEANUP_SPACE_CACHE_V1,
-
-	/* Indicate that we can't trust the free space tree for caching yet */
-	BTRFS_FS_FREE_SPACE_TREE_UNTRUSTED,
-
-	/* Indicate whether there are any tree modification log users */
-	BTRFS_FS_TREE_MOD_LOG_USERS,
-
-	/* Indicate that we want the transaction kthread to commit right now. */
-	BTRFS_FS_COMMIT_TRANS,
-
-	/* Indicate we have half completed snapshot deletions pending. */
-	BTRFS_FS_UNFINISHED_DROPS,
-
-	/* Indicate we have to finish a zone to do next allocation. */
-	BTRFS_FS_NEED_ZONE_FINISH,
-
-#if BITS_PER_LONG == 32
-	/* Indicate if we have error/warn message printed on 32bit systems */
-	BTRFS_FS_32BIT_ERROR,
-	BTRFS_FS_32BIT_WARN,
-#endif
-};
-
 /*
  * Exclusive operations (device replace, resize, device add/remove, balance)
  */
@@ -1012,11 +949,6 @@ enum btrfs_lockdep_trans_states {
 				 &lock##_key, 0);				\
 	} while (0)
 
-static inline void btrfs_wake_unfinished_drop(struct btrfs_fs_info *fs_info)
-{
-	clear_and_wake_up_bit(BTRFS_FS_UNFINISHED_DROPS, &fs_info->flags);
-}
-
 /*
  * Record swapped tree blocks of a subvolume tree for delayed subtree trace
  * code. For detail check comment in fs/btrfs/qgroup.c.
fs/btrfs/delayed-inode.c +1 -0
index f3ff22ce3a7b..8acb3785ad6e 100644
@@ -16,6 +16,7 @@
 #include "locking.h"
 #include "inode-item.h"
 #include "space-info.h"
+#include "fs.h"
 
 #define BTRFS_DELAYED_WRITEBACK		512
 #define BTRFS_DELAYED_BACKGROUND	128
fs/btrfs/fs.h +68 -0

80 lines not on this page · raw message

fs/btrfs/root-tree.c +1 -0
index ab9e891ddb79..04b94727373f 100644
@@ -12,6 +12,7 @@
 #include "print-tree.h"
 #include "qgroup.h"
 #include "space-info.h"
+#include "fs.h"
 
 /*
  * Read a root item from the tree. In case we detect a root item smaller then
fs/btrfs/tests/qgroup-tests.c +1 -0
index eee1e4459541..09b45c3d8386 100644
@@ -10,6 +10,7 @@
 #include "../disk-io.h"
 #include "../qgroup.h"
 #include "../backref.h"
+#include "../fs.h"
 
 static int insert_normal_tree_ref(struct btrfs_root *root, u64 bytenr,
 				  u64 num_bytes, u64 parent, u64 root_objectid)
fs/btrfs/tree-mod-log.c +1 -0
index 51ace0ac5c2d..523a184d10cc 100644
@@ -3,6 +3,7 @@
 #include "btrfs-printk.h"
 #include "tree-mod-log.h"
 #include "disk-io.h"
+#include "fs.h"
 
 struct tree_mod_root {
 	u64 logical;
Signature · 1 line
2.26.3
#26 lore raw

PATCH 11/16 btrfs: add a BTRFS_FS_NEED_TRANS_COMMIT flag

In reply to Josef Bacik

Currently we are only using fs_info->pending_changes to indicate that we need a transaction commit. The original users for this were removed years ago, so this is the only remaining reason to have this field. Add a flag so we can remove this code.

---
 fs/btrfs/fs.h          | 3 +++
 fs/btrfs/super.c       | 3 ++-
 fs/btrfs/sysfs.c       | 4 ++--
 fs/btrfs/transaction.c | 2 ++
 4 files changed, 9 insertions(+), 3 deletions(-)
fs/btrfs/fs.h +3 -0
index c7eb21768b66..6181657bdc90 100644
@@ -90,6 +90,9 @@ enum {
 	/* Indicate we have to finish a zone to do next allocation. */
 	BTRFS_FS_NEED_ZONE_FINISH,
 
+	/* Indicate that we want to commit the transaction. */
+	BTRFS_FS_NEED_TRANS_COMMIT,
+
 #if BITS_PER_LONG == 32
 	/* Indicate if we have error/warn message printed on 32bit systems */
 	BTRFS_FS_32BIT_ERROR,
fs/btrfs/super.c +2 -1
index 2865676b8327..63a639056882 100644
@@ -1547,7 +1547,8 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
 			 * Exit unless we have some pending changes
 			 * that need to go through commit
 			 */
-			if (fs_info->pending_changes == 0)
+			if (!test_bit(BTRFS_FS_NEED_TRANS_COMMIT,
+				      &fs_info->flags))
 				return 0;
 			/*
 			 * A non-blocking test if the fs is frozen. We must not
fs/btrfs/sysfs.c +2 -2
index 4acff123fe66..6a7ab762a543 100644
@@ -250,7 +250,7 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,
 	/*
 	 * We don't want to do full transaction commit from inside sysfs
 	 */
-	btrfs_set_pending(fs_info, COMMIT);
+	set_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
 	wake_up_process(fs_info->transaction_kthread);
 
 	return count;
@@ -961,7 +961,7 @@ static ssize_t btrfs_label_store(struct kobject *kobj,
 	/*
 	 * We don't want to do full transaction commit from inside sysfs
 	 */
-	btrfs_set_pending(fs_info, COMMIT);
+	set_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
 	wake_up_process(fs_info->transaction_kthread);
 
 	return len;
fs/btrfs/transaction.c +2 -0
index bae77fb05e2b..7b6b68ab089a 100644
@@ -2104,6 +2104,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	ASSERT(refcount_read(&trans->use_count) == 1);
 	btrfs_trans_state_lockdep_acquire(fs_info, BTRFS_LOCKDEP_TRANS_COMMIT_START);
 
+	clear_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
+
 	/* Stop the commit early if ->aborted is set */
 	if (TRANS_ABORTED(cur_trans)) {
 		ret = cur_trans->aborted;
Signature · 1 line
2.26.3
#27 lore raw

Re: [PATCH 11/16] btrfs: add a BTRFS_FS_NEED_TRANS_COMMIT flag

Quoted 5 lines · Josef Bacik

Currently we are only using fs_info->pending_changes to indicate that we need a transaction commit. The original users for this were removed years ago, so this is the only remaining reason to have this field. Add a flag so we can remove this code.

The following #defines are unused. Why not remove them?

#define btrfs_test_pending(info, opt)  \
       test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
#define btrfs_set_pending(info, opt)   \
       set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
#define btrfs_clear_pending(info, opt) \
       clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)

Thanks, Anand

Quoted 71 lines
---
  fs/btrfs/fs.h          | 3 +++
  fs/btrfs/super.c       | 3 ++-
  fs/btrfs/sysfs.c       | 4 ++--
  fs/btrfs/transaction.c | 2 ++
  4 files changed, 9 insertions(+), 3 deletions(-)
fs/btrfs/fs.h +3 -0
index c7eb21768b66..6181657bdc90 100644
@@ -90,6 +90,9 @@ enum {
  	/* Indicate we have to finish a zone to do next allocation. */
  	BTRFS_FS_NEED_ZONE_FINISH,
 
+	/* Indicate that we want to commit the transaction. */
+	BTRFS_FS_NEED_TRANS_COMMIT,
+
  #if BITS_PER_LONG == 32
  	/* Indicate if we have error/warn message printed on 32bit systems */
  	BTRFS_FS_32BIT_ERROR,
fs/btrfs/super.c +2 -1
index 2865676b8327..63a639056882 100644
@@ -1547,7 +1547,8 @@ int btrfs_sync_fs(struct super_block *sb, int wait)
  			 * Exit unless we have some pending changes
  			 * that need to go through commit
  			 */
-			if (fs_info->pending_changes == 0)
+			if (!test_bit(BTRFS_FS_NEED_TRANS_COMMIT,
+				      &fs_info->flags))
  				return 0;
  			/*
  			 * A non-blocking test if the fs is frozen. We must not
fs/btrfs/sysfs.c +2 -2
index 4acff123fe66..6a7ab762a543 100644
@@ -250,7 +250,7 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,
  	/*
  	 * We don't want to do full transaction commit from inside sysfs
  	 */
-	btrfs_set_pending(fs_info, COMMIT);
+	set_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
  	wake_up_process(fs_info->transaction_kthread);
 
  	return count;
@@ -961,7 +961,7 @@ static ssize_t btrfs_label_store(struct kobject *kobj,
  	/*
  	 * We don't want to do full transaction commit from inside sysfs
  	 */
-	btrfs_set_pending(fs_info, COMMIT);
+	set_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
  	wake_up_process(fs_info->transaction_kthread);
 
  	return len;
fs/btrfs/transaction.c +2 -0
index bae77fb05e2b..7b6b68ab089a 100644
@@ -2104,6 +2104,8 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
  	ASSERT(refcount_read(&trans->use_count) == 1);
  	btrfs_trans_state_lockdep_acquire(fs_info, BTRFS_LOCKDEP_TRANS_COMMIT_START);
 
+	clear_bit(BTRFS_FS_NEED_TRANS_COMMIT, &fs_info->flags);
+
  	/* Stop the commit early if ->aborted is set */
  	if (TRANS_ABORTED(cur_trans)) {
  		ret = cur_trans->aborted;
Reviewed-by
#28 lore raw

Re: [PATCH 11/16] btrfs: add a BTRFS_FS_NEED_TRANS_COMMIT flag

Quoted 7 lines · Anand Jain
Quoted 5 lines · Josef Bacik

Currently we are only using fs_info->pending_changes to indicate that we need a transaction commit.  The original users for this were removed years ago, so this is the only remaining reason to have this field.  Add a flag so we can remove this code.

Quoted 8 lines

The following #defines are unused. Why not remove them?

#define btrfs_test_pending(info, opt)  \
       test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
#define btrfs_set_pending(info, opt)   \
       set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
#define btrfs_clear_pending(info, opt) \
       clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)

Patch 12/16 did it.

Quoted 3 lines
Quoted 3 lines
#29 lore raw

PATCH 12/16 btrfs: remove fs_info::pending_changes and related code

In reply to Josef Bacik

Now that we're not using this code anywhere we can remove it as well as the member from fs_info.

---
 fs/btrfs/ctree.h       | 23 +----------------------
 fs/btrfs/disk-io.c     |  6 ------
 fs/btrfs/transaction.c | 25 -------------------------
 fs/btrfs/transaction.h |  1 -
 4 files changed, 1 insertion(+), 54 deletions(-)
fs/btrfs/ctree.h +1 -22
index 8decad27a6c5..f44c744fe7a2 100644
@@ -410,11 +410,7 @@ struct btrfs_fs_info {
 	 */
 	u64 last_trans_log_full_commit;
 	unsigned long mount_opt;
-	/*
-	 * Track requests for actions that need to be done during transaction
-	 * commit (like for some mount options).
-	 */
-	unsigned long pending_changes;
+
 	unsigned long compress_type:4;
 	unsigned int compress_level;
 	u32 commit_interval;
@@ -1235,23 +1231,6 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 	return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
 }
 
-/*
- * Requests for changes that need to be done during transaction commit.
- *
- * Internal mount options that are used for special handling of the real
- * mount options (eg. cannot be set during remount and have to be set during
- * transaction commit)
- */
-
-#define BTRFS_PENDING_COMMIT			(0)
-
-#define btrfs_test_pending(info, opt)	\
-	test_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
-#define btrfs_set_pending(info, opt)	\
-	set_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
-#define btrfs_clear_pending(info, opt)	\
-	clear_bit(BTRFS_PENDING_##opt, &(info)->pending_changes)
-
 struct btrfs_map_token {
 	struct extent_buffer *eb;
 	char *kaddr;
fs/btrfs/disk-io.c +0 -6
index f103bf712f75..719c00757579 100644
@@ -3702,12 +3702,6 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 		btrfs_set_and_info(fs_info, SSD, "enabling ssd optimizations");
 	}
 
-	/*
-	 * Mount does not set all options immediately, we can do it now and do
-	 * not have to wait for transaction commit
-	 */
-	btrfs_apply_pending_changes(fs_info);
-
 #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY
 	if (btrfs_test_opt(fs_info, CHECK_INTEGRITY)) {
 		ret = btrfsic_mount(fs_info, fs_devices,
fs/btrfs/transaction.c +0 -25
index 7b6b68ab089a..37d0baaa41d8 100644
@@ -2359,12 +2359,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
 	if (ret)
 		goto unlock_reloc;
 
-	/*
-	 * Since the transaction is done, we can apply the pending changes
-	 * before the next transaction.
-	 */
-	btrfs_apply_pending_changes(fs_info);
-
 	/* commit_fs_roots gets rid of all the tree log roots, it is now
 	 * safe to free the root of tree log roots
 	 */
@@ -2587,25 +2581,6 @@ int btrfs_clean_one_deleted_snapshot(struct btrfs_fs_info *fs_info)
 	return (ret < 0) ? 0 : 1;
 }
 
-void btrfs_apply_pending_changes(struct btrfs_fs_info *fs_info)
-{
-	unsigned long prev;
-	unsigned long bit;
-
-	prev = xchg(&fs_info->pending_changes, 0);
-	if (!prev)
-		return;
-
-	bit = 1 << BTRFS_PENDING_COMMIT;
-	if (prev & bit)
-		btrfs_debug(fs_info, "pending commit done");
-	prev &= ~bit;
-
-	if (prev)
-		btrfs_warn(fs_info,
-			"unknown pending changes left 0x%lx, ignoring", prev);
-}
-
 int __init btrfs_transaction_init(void)
 {
 	btrfs_trans_handle_cachep = kmem_cache_create("btrfs_trans_handle",
fs/btrfs/transaction.h +0 -1
index b5651c372946..cf3356cb797b 100644
@@ -231,7 +231,6 @@ int btrfs_wait_tree_log_extents(struct btrfs_root *root, int mark);
 int btrfs_transaction_blocked(struct btrfs_fs_info *info);
 int btrfs_transaction_in_commit(struct btrfs_fs_info *info);
 void btrfs_put_transaction(struct btrfs_transaction *transaction);
-void btrfs_apply_pending_changes(struct btrfs_fs_info *fs_info);
 void btrfs_add_dropped_root(struct btrfs_trans_handle *trans,
 			    struct btrfs_root *root);
 void btrfs_trans_release_chunk_metadata(struct btrfs_trans_handle *trans);
Signature · 1 line
2.26.3
#31 lore raw

Re: [PATCH 12/16] btrfs: remove fs_info::pending_changes and related code

In reply to Josef Bacik
Quoted 2 lines · Josef Bacik

Now that we're not using this code anywhere we can remove it as well as the member from fs_info.

So it looks like we don't have any mount options or on/off features that would utilize the pending infrastructure, the last one was inode_cache. There was a patchset [1] to enable some features from sysfs that would break things if it would be set immediately. In case we'll need that kind of logic again the patch can be reverted, but for the current use it can be replaced by the single state bit to do the commit.

[1] https://lore.kernel.org/linux-btrfs/[email protected]/

#32 lore raw

PATCH 13/16 btrfs: move the compat/incompat flag masks to fs.h

In reply to Josef Bacik

This is fs wide information, move it out of ctree.h into fs.h.

---
 fs/btrfs/ctree.h | 57 ------------------------------------------------
 fs/btrfs/fs.h    | 57 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 57 deletions(-)
fs/btrfs/ctree.h +0 -57
index f44c744fe7a2..b6e86c1bc4b2 100644
@@ -65,63 +65,6 @@ static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
  */
 #define BTRFS_DEVICE_RANGE_RESERVED			(SZ_1M)
 
-/*
- * Compat flags that we support.  If any incompat flags are set other than the
- * ones specified below then we will fail to mount
- */
-#define BTRFS_FEATURE_COMPAT_SUPP		0ULL
-#define BTRFS_FEATURE_COMPAT_SAFE_SET		0ULL
-#define BTRFS_FEATURE_COMPAT_SAFE_CLEAR		0ULL
-
-#define BTRFS_FEATURE_COMPAT_RO_SUPP			\
-	(BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE |	\
-	 BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID | \
-	 BTRFS_FEATURE_COMPAT_RO_VERITY |		\
-	 BTRFS_FEATURE_COMPAT_RO_BLOCK_GROUP_TREE)
-
-#define BTRFS_FEATURE_COMPAT_RO_SAFE_SET	0ULL
-#define BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR	0ULL
-
-#ifdef CONFIG_BTRFS_DEBUG
-/*
- * Extent tree v2 supported only with CONFIG_BTRFS_DEBUG
- */
-#define BTRFS_FEATURE_INCOMPAT_SUPP			\
-	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
-	 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |	\
-	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
-	 BTRFS_FEATURE_INCOMPAT_BIG_METADATA |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD |		\
-	 BTRFS_FEATURE_INCOMPAT_RAID56 |		\
-	 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF |		\
-	 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA |	\
-	 BTRFS_FEATURE_INCOMPAT_NO_HOLES	|	\
-	 BTRFS_FEATURE_INCOMPAT_METADATA_UUID	|	\
-	 BTRFS_FEATURE_INCOMPAT_RAID1C34	|	\
-	 BTRFS_FEATURE_INCOMPAT_ZONED		|	\
-	 BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2)
-#else
-#define BTRFS_FEATURE_INCOMPAT_SUPP			\
-	(BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF |		\
-	 BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL |	\
-	 BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS |		\
-	 BTRFS_FEATURE_INCOMPAT_BIG_METADATA |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO |		\
-	 BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD |		\
-	 BTRFS_FEATURE_INCOMPAT_RAID56 |		\
-	 BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF |		\
-	 BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA |	\
-	 BTRFS_FEATURE_INCOMPAT_NO_HOLES	|	\
-	 BTRFS_FEATURE_INCOMPAT_METADATA_UUID	|	\
-	 BTRFS_FEATURE_INCOMPAT_RAID1C34	|	\
-	 BTRFS_FEATURE_INCOMPAT_ZONED)
-#endif
-
-#define BTRFS_FEATURE_INCOMPAT_SAFE_SET			\
-	(BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF)
-#define BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR		0ULL
-
 /* Read ahead values for struct btrfs_path.reada */
 enum {
 	READA_NONE,
fs/btrfs/fs.h +57 -0

63 lines not on this page · raw message

Signature · 1 line
2.26.3
#34 lore raw

PATCH 14/16 btrfs: rename struct-funcs.c -> item-accessors.c

In reply to Josef Bacik

Rename struct-funcs.c to item-accessors.c so we can move the item accessors out of ctree.h. item-accessors.c is a better description of the code that is contained in these files.

---
 fs/btrfs/Makefile                             | 2 +-
 fs/btrfs/{struct-funcs.c => item-accessors.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename fs/btrfs/{struct-funcs.c => item-accessors.c} (100%)
fs/btrfs/Makefile +1 -1
index eebb45c06485..5a5906e7231d 100644
@@ -24,7 +24,7 @@ obj-$(CONFIG_BTRFS_FS) := btrfs.o
 btrfs-y += super.o ctree.o extent-tree.o print-tree.o root-tree.o dir-item.o \
 	   file-item.o inode-item.o disk-io.o \
 	   transaction.o inode.o file.o tree-defrag.o \
-	   extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \
+	   extent_map.o sysfs.o item-accessors.o xattr.o ordered-data.o \
 	   extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \
 	   export.o tree-log.o free-space-cache.o zlib.o lzo.o zstd.o \
 	   compression.o delayed-ref.o relocation.o delayed-inode.o scrub.o \
fs/btrfs/item-accessors.c renamed from fs/btrfs/struct-funcs.c +0 -0
similarity index 100%
rename from fs/btrfs/struct-funcs.c
rename to fs/btrfs/item-accessors.c
Signature · 1 line
2.26.3
Reviewed-by on v1 14/16
#35 lore raw

Re: [PATCH 14/16] btrfs: rename struct-funcs.c -> item-accessors.c

Quoted 5 lines · Josef Bacik

Rename struct-funcs.c to item-accessors.c so we can move the item accessors out of ctree.h. item-accessors.c is a better description of the code that is contained in these files.

#36 lore raw

PATCH 15/16 btrfs: move btrfs_map_token to item-accessors

In reply to Josef Bacik

This is specific to the item-accessor code, move it out of ctree.h into item-accessor.h/.c and then update the users to include the new header file.

---
 fs/btrfs/ctree.c          |  1 +
 fs/btrfs/ctree.h          | 16 ++--------------
 fs/btrfs/inode.c          |  1 +
 fs/btrfs/item-accessors.c |  9 +++++++++
 fs/btrfs/item-accessors.h | 14 ++++++++++++++
 fs/btrfs/tree-log.c       |  1 +
 6 files changed, 28 insertions(+), 14 deletions(-)
 create mode 100644 fs/btrfs/item-accessors.h
fs/btrfs/ctree.c +1 -0
index a5fd4e2369f1..de01c892a885 100644
@@ -19,6 +19,7 @@
 #include "tree-mod-log.h"
 #include "tree-checker.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 static struct kmem_cache *btrfs_path_cachep;
 
fs/btrfs/ctree.h +2 -14
index b6e86c1bc4b2..324400c5597f 100644
@@ -46,6 +46,8 @@ struct btrfs_ref;
 struct btrfs_bio;
 struct btrfs_ioctl_encoded_io_args;
 
+struct btrfs_map_token;
+
 #define BTRFS_OLDEST_GENERATION	0ULL
 
 #define BTRFS_EMPTY_DIR_SIZE 0
@@ -1174,23 +1176,9 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 	return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
 }
 
-struct btrfs_map_token {
-	struct extent_buffer *eb;
-	char *kaddr;
-	unsigned long offset;
-};
-
 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \
 				((bytes) >> (fs_info)->sectorsize_bits)
 
-static inline void btrfs_init_map_token(struct btrfs_map_token *token,
-					struct extent_buffer *eb)
-{
-	token->eb = eb;
-	token->kaddr = page_address(eb->pages[0]);
-	token->offset = 0;
-}
-
 /* some macros to generate set/get functions for the struct fields.  This
  * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  * one for u8:
fs/btrfs/inode.c +1 -0
index a6615106002a..ca6fa9b01785 100644
@@ -56,6 +56,7 @@
 #include "subpage.h"
 #include "inode-item.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 struct btrfs_iget_args {
 	u64 ino;
fs/btrfs/item-accessors.c +9 -0
index ec6b0436d09a..7edb59ba99fc 100644
@@ -7,6 +7,7 @@
 
 #include "btrfs-printk.h"
 #include "ctree.h"
+#include "item-accessors.h"
 
 static bool check_setget_bounds(const struct extent_buffer *eb,
 				const void *ptr, unsigned off, int size)
@@ -24,6 +25,14 @@ static bool check_setget_bounds(const struct extent_buffer *eb,
 	return true;
 }
 
+void btrfs_init_map_token(struct btrfs_map_token *token,
+			  struct extent_buffer *eb)
+{
+	token->eb = eb;
+	token->kaddr = page_address(eb->pages[0]);
+	token->offset = 0;
+}
+
 /*
  * Macro templates that define helpers to read/write extent buffer data of a
  * given size, that are also used via ctree.h for access to item members by
fs/btrfs/item-accessors.h new file +14 -0
new file mode 100644
index 000000000000..1f40aa503047
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#ifndef BTRFS_ITEM_ACCESSORS_H
+#define BTRFS_ITEM_ACCESSORS_H
+
+struct btrfs_map_token {
+	struct extent_buffer *eb;
+	char *kaddr;
+	unsigned long offset;
+};
+
+void btrfs_init_map_token(struct btrfs_map_token *token,
+			  struct extent_buffer *eb);
+#endif /* BTRFS_ITEM_ACCESSORS_H */
fs/btrfs/tree-log.c +1 -0
index 90cc8a97c13b..8818a2b19192 100644
@@ -22,6 +22,7 @@
 #include "zoned.h"
 #include "inode-item.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #define MAX_CONFLICT_INODES 10
 
Signature · 1 line
2.26.3
#38 lore raw

Re: [PATCH 15/16] btrfs: move btrfs_map_token to item-accessors

In reply to Josef Bacik
Quoted 89 lines · Josef Bacik

This is specific to the item-accessor code, move it out of ctree.h into item-accessor.h/.c and then update the users to include the new header file.

---
 fs/btrfs/ctree.c          |  1 +
 fs/btrfs/ctree.h          | 16 ++--------------
 fs/btrfs/inode.c          |  1 +
 fs/btrfs/item-accessors.c |  9 +++++++++
 fs/btrfs/item-accessors.h | 14 ++++++++++++++
 fs/btrfs/tree-log.c       |  1 +
 6 files changed, 28 insertions(+), 14 deletions(-)
 create mode 100644 fs/btrfs/item-accessors.h
fs/btrfs/ctree.c +1 -0
index a5fd4e2369f1..de01c892a885 100644
@@ -19,6 +19,7 @@
 #include "tree-mod-log.h"
 #include "tree-checker.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 static struct kmem_cache *btrfs_path_cachep;
 
fs/btrfs/ctree.h +2 -14
index b6e86c1bc4b2..324400c5597f 100644
@@ -46,6 +46,8 @@ struct btrfs_ref;
 struct btrfs_bio;
 struct btrfs_ioctl_encoded_io_args;
 
+struct btrfs_map_token;
+
 #define BTRFS_OLDEST_GENERATION	0ULL
 
 #define BTRFS_EMPTY_DIR_SIZE 0
@@ -1174,23 +1176,9 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 	return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
 }
 
-struct btrfs_map_token {
-	struct extent_buffer *eb;
-	char *kaddr;
-	unsigned long offset;
-};
-
 #define BTRFS_BYTES_TO_BLKS(fs_info, bytes) \
 				((bytes) >> (fs_info)->sectorsize_bits)
 
-static inline void btrfs_init_map_token(struct btrfs_map_token *token,
-					struct extent_buffer *eb)
-{
-	token->eb = eb;
-	token->kaddr = page_address(eb->pages[0]);
-	token->offset = 0;
-}
-
 /* some macros to generate set/get functions for the struct fields.  This
  * assumes there is a lefoo_to_cpu for every type, so lets make a simple
  * one for u8:
fs/btrfs/inode.c +1 -0
index a6615106002a..ca6fa9b01785 100644
@@ -56,6 +56,7 @@
 #include "subpage.h"
 #include "inode-item.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 struct btrfs_iget_args {
 	u64 ino;
fs/btrfs/item-accessors.c +1 -0
index ec6b0436d09a..7edb59ba99fc 100644
@@ -7,6 +7,7 @@
 
 #include "btrfs-printk.h"
 #include "ctree.h"
+#include "item-accessors.h"
 
 static bool check_setget_bounds(const struct extent_buffer *eb,
 				const void *ptr, unsigned off, int size)

fs/btrfs/item-accessors.c static bool check_setget_bounds(const struct extent_buffer *eb, · line 33

Quoted 9 lines
fs/btrfs/item-accessors.c +6 -0
@@ -24,6 +25,14 @@ static bool check_setget_bounds(const struct extent_buffer *eb,
 	return true;
 }
 
+void btrfs_init_map_token(struct btrfs_map_token *token,
+			  struct extent_buffer *eb)
+{
+	token->eb = eb;
+	token->kaddr = page_address(eb->pages[0]);
+	token->offset = 0;

This is prooobably ok to be uninlined, it's called once when used and all call sites typically do lot of work using the token but still a function call for three simple assignments does not look optimal.

#39 lore raw

Re: [PATCH 15/16] btrfs: move btrfs_map_token to item-accessors

Quoted 11 lines · David Sterba

fs/btrfs/item-accessors.c static bool check_setget_bounds(const struct extent_buffer *eb, · line 33

Quoted 6 lines · Josef Bacik
fs/btrfs/item-accessors.c +6 -0
+void btrfs_init_map_token(struct btrfs_map_token *token,
+			  struct extent_buffer *eb)
+{
+	token->eb = eb;
+	token->kaddr = page_address(eb->pages[0]);
+	token->offset = 0;

This is prooobably ok to be uninlined, it's called once when used and all call sites typically do lot of work using the token but still a function call for three simple assignments does not look optimal.

It looks simple in C but in asm it's about 27 instructions due to page_address that does some masking and and check. Overall, uninlining seems ok.

#40 lore raw

PATCH 16/16 btrfs: move accessor helpers into item-accessors.h

In reply to Josef Bacik

This is a large patch, but because they're all macros it's impossible to split up. Simply copy all of the item accessors in ctree.h and paste them in item-accessors.h, and then update any files to include the header so everything compiles.

---
 fs/btrfs/backref.c                     |    1 +
 fs/btrfs/block-group.c                 |    1 +
 fs/btrfs/block-rsv.c                   |    1 +
 fs/btrfs/check-integrity.c             |    1 +
 fs/btrfs/ctree.h                       | 1090 ------------------------
 fs/btrfs/delayed-inode.c               |    1 +
 fs/btrfs/dev-replace.c                 |    1 +
 fs/btrfs/dir-item.c                    |    1 +
 fs/btrfs/disk-io.c                     |    1 +
 fs/btrfs/export.c                      |    1 +
 fs/btrfs/extent-tree.c                 |    1 +
 fs/btrfs/extent_io.c                   |    1 +
 fs/btrfs/file-item.c                   |    1 +
 fs/btrfs/file.c                        |    1 +
 fs/btrfs/free-space-cache.c            |    1 +
 fs/btrfs/free-space-tree.c             |    1 +
 fs/btrfs/fs.c                          |    1 +
 fs/btrfs/inode-item.c                  |    1 +
 fs/btrfs/ioctl.c                       |    1 +
 fs/btrfs/item-accessors.h              | 1090 ++++++++++++++++++++++++
 fs/btrfs/print-tree.c                  |    1 +
 fs/btrfs/props.c                       |    1 +
 fs/btrfs/qgroup.c                      |    1 +
 fs/btrfs/ref-verify.c                  |    1 +
 fs/btrfs/reflink.c                     |    1 +
 fs/btrfs/relocation.c                  |    1 +
 fs/btrfs/root-tree.c                   |    1 +
 fs/btrfs/scrub.c                       |    1 +
 fs/btrfs/send.c                        |    1 +
 fs/btrfs/space-info.c                  |    1 +
 fs/btrfs/super.c                       |    1 +
 fs/btrfs/sysfs.c                       |    1 +
 fs/btrfs/tests/extent-buffer-tests.c   |    1 +
 fs/btrfs/tests/free-space-tree-tests.c |    1 +
 fs/btrfs/tests/inode-tests.c           |    1 +
 fs/btrfs/tests/qgroup-tests.c          |    1 +
 fs/btrfs/transaction.c                 |    1 +
 fs/btrfs/tree-checker.c                |    1 +
 fs/btrfs/tree-defrag.c                 |    1 +
 fs/btrfs/tree-mod-log.c                |    1 +
 fs/btrfs/uuid-tree.c                   |    2 +-
 fs/btrfs/verity.c                      |    1 +
 fs/btrfs/volumes.c                     |    1 +
 fs/btrfs/xattr.c                       |    1 +
 fs/btrfs/zoned.c                       |    1 +
 45 files changed, 1133 insertions(+), 1091 deletions(-)
fs/btrfs/backref.c +1 -0
index d2a33c4d2f35..959f234a670f 100644
@@ -16,6 +16,7 @@
 #include "misc.h"
 #include "tree-mod-log.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /* Just an arbitrary number so we can be sure this happened */
 #define BACKREF_FOUND_SHARED 6
fs/btrfs/block-group.c +1 -0
index 510d58290edc..20da92ae5c6b 100644
@@ -18,6 +18,7 @@
 #include "raid56.h"
 #include "zoned.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #ifdef CONFIG_BTRFS_DEBUG
 int btrfs_should_fragment_free_space(struct btrfs_block_group *block_group)
fs/btrfs/block-rsv.c +1 -0
index 6dad02dd1d63..8144b9225207 100644
@@ -8,6 +8,7 @@
 #include "block-group.h"
 #include "disk-io.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * HOW DO BLOCK RESERVES WORK
fs/btrfs/check-integrity.c +1 -0
index 60ff8ce1820e..f42b2697d888 100644
@@ -93,6 +93,7 @@
 #include "check-integrity.h"
 #include "rcu-string.h"
 #include "compression.h"
+#include "item-accessors.h"
 
 #define BTRFSIC_BLOCK_HASHTABLE_SIZE 0x10000
 #define BTRFSIC_BLOCK_LINK_HASHTABLE_SIZE 0x10000
fs/btrfs/ctree.h +0 -1090

1,102 lines not on this page · raw message

fs/btrfs/delayed-inode.c +1 -0
index 8acb3785ad6e..aa79445ad722 100644
@@ -17,6 +17,7 @@
 #include "inode-item.h"
 #include "space-info.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #define BTRFS_DELAYED_WRITEBACK		512
 #define BTRFS_DELAYED_BACKGROUND	128
fs/btrfs/dev-replace.c +1 -0
index 348aef453e69..c6222057f655 100644
@@ -24,6 +24,7 @@
 #include "zoned.h"
 #include "block-group.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Device replace overview
fs/btrfs/dir-item.c +1 -0
index e53640dfacca..fb88f3d4c8cd 100644
@@ -7,6 +7,7 @@
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
+#include "item-accessors.h"
 
 /*
  * insert a name into a directory, doing overflow properly if there is a hash
fs/btrfs/disk-io.c +1 -0
index 719c00757579..124c210c4e02 100644
@@ -44,6 +44,7 @@
 #include "zoned.h"
 #include "subpage.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #define BTRFS_SUPER_FLAG_SUPP	(BTRFS_HEADER_FLAG_WRITTEN |\
 				 BTRFS_HEADER_FLAG_RELOC |\
fs/btrfs/export.c +1 -0
index 1d4c2397d0d6..1ee7a552f7d0 100644
@@ -7,6 +7,7 @@
 #include "btrfs_inode.h"
 #include "print-tree.h"
 #include "export.h"
+#include "item-accessors.h"
 
 #define BTRFS_FID_SIZE_NON_CONNECTABLE (offsetof(struct btrfs_fid, \
 						 parent_objectid) / 4)
fs/btrfs/extent-tree.c +1 -0
index 37f9f074da33..7cf7844c9dba 100644
@@ -37,6 +37,7 @@
 #include "zoned.h"
 #include "dev-replace.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #undef SCRAMBLE_DELAYED_REFS
 
fs/btrfs/extent_io.c +1 -0
index c11c05ea099d..b1d57727be02 100644
@@ -31,6 +31,7 @@
 #include "block-group.h"
 #include "compression.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 static struct kmem_cache *extent_buffer_cache;
 
fs/btrfs/file-item.c +1 -0
index 07cfffabbe84..7bd6e1b91495 100644
@@ -18,6 +18,7 @@
 #include "print-tree.h"
 #include "compression.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #define __MAX_CSUM_ITEMS(r, size) ((unsigned long)(((BTRFS_LEAF_DATA_SIZE(r) - \
 				   sizeof(struct btrfs_item) * 2) / \
fs/btrfs/file.c +1 -0
index 7fc77b454d8e..c395bf8e7522 100644
@@ -31,6 +31,7 @@
 #include "reflink.h"
 #include "subpage.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 static struct kmem_cache *btrfs_inode_defrag_cachep;
 /*
fs/btrfs/free-space-cache.c +1 -0
index b472da0e9d1b..c0853b5e0dd1 100644
@@ -26,6 +26,7 @@
 #include "subpage.h"
 #include "inode-item.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #define BITS_PER_BITMAP		(PAGE_SIZE * 8UL)
 #define MAX_CACHE_BYTES_PER_GIG	SZ_64K
fs/btrfs/free-space-tree.c +1 -0
index 5e0829456eb9..758662aef880 100644
@@ -13,6 +13,7 @@
 #include "transaction.h"
 #include "block-group.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 static int __add_block_group_free_space(struct btrfs_trans_handle *trans,
 					struct btrfs_block_group *block_group,
fs/btrfs/fs.c +1 -0
index 32fbc7f55730..a95d86679d14 100644
@@ -3,6 +3,7 @@
 #include "btrfs-printk.h"
 #include "ctree.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag,
 			     const char *name)
fs/btrfs/inode-item.c +1 -0
index 02cd4210edf3..d5df6a1c4301 100644
@@ -10,6 +10,7 @@
 #include "transaction.h"
 #include "print-tree.h"
 #include "space-info.h"
+#include "item-accessors.h"
 
 struct btrfs_inode_ref *btrfs_find_name_in_backref(struct extent_buffer *leaf,
 						   int slot, const char *name,
fs/btrfs/ioctl.c +1 -0
index e8b5dc147637..09d0ea32f6c4 100644
@@ -51,6 +51,7 @@
 #include "block-group.h"
 #include "subpage.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #ifdef CONFIG_64BIT
 /* If we have a 32-bit userspace and 64-bit kernel, then the UAPI
fs/btrfs/item-accessors.h +1090 -0

1,096 lines not on this page · raw message

fs/btrfs/print-tree.c +1 -0
index 40576965d3da..ae3c2738422e 100644
@@ -7,6 +7,7 @@
 #include "ctree.h"
 #include "disk-io.h"
 #include "print-tree.h"
+#include "item-accessors.h"
 
 struct root_name_map {
 	u64 id;
fs/btrfs/props.c +1 -0
index f95bc8e8d90a..53bab37f328f 100644
@@ -13,6 +13,7 @@
 #include "compression.h"
 #include "space-info.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 #define BTRFS_PROP_HANDLERS_HT_BITS 8
 static DEFINE_HASHTABLE(prop_handlers_ht, BTRFS_PROP_HANDLERS_HT_BITS);
fs/btrfs/qgroup.c +1 -0
index 041e4b368ea8..e98e57266e12 100644
@@ -25,6 +25,7 @@
 #include "sysfs.h"
 #include "tree-mod-log.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Helpers to access qgroup reservation
fs/btrfs/ref-verify.c +1 -0
index eddeb8885701..6b163ac13704 100644
@@ -12,6 +12,7 @@
 #include "delayed-ref.h"
 #include "ref-verify.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Used to keep track the roots and number of refs each root has for a given
fs/btrfs/reflink.c +1 -0
index 6bc2231a7874..ff0edd68ec30 100644
@@ -10,6 +10,7 @@
 #include "reflink.h"
 #include "transaction.h"
 #include "subpage.h"
+#include "item-accessors.h"
 
 #define BTRFS_MAX_DEDUPE_LEN	SZ_16M
 
fs/btrfs/relocation.c +1 -0
index 5198dde6ad97..f33d6bb1cfe6 100644
@@ -29,6 +29,7 @@
 #include "inode-item.h"
 #include "space-info.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Relocation overview
fs/btrfs/root-tree.c +1 -0
index 04b94727373f..5b8e01f46b2d 100644
@@ -13,6 +13,7 @@
 #include "qgroup.h"
 #include "space-info.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Read a root item from the tree. In case we detect a root item smaller then
fs/btrfs/scrub.c +1 -0
index c758d8ff2e69..d5c23faceb8e 100644
@@ -22,6 +22,7 @@
 #include "block-group.h"
 #include "zoned.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * This is only the first step towards a full-features scrub. It reads all
fs/btrfs/send.c +1 -0
index 4ef4167072b8..a82e84094016 100644
@@ -27,6 +27,7 @@
 #include "compression.h"
 #include "xattr.h"
 #include "print-tree.h"
+#include "item-accessors.h"
 
 /*
  * Maximum number of references an extent can have in order for us to attempt to
fs/btrfs/space-info.c +1 -0
index 46be83bd4d70..62e8e7a379b1 100644
@@ -11,6 +11,7 @@
 #include "block-group.h"
 #include "zoned.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * HOW DOES SPACE RESERVATION WORK
fs/btrfs/super.c +1 -0
index 63a639056882..a7ce6f4889db 100644
@@ -52,6 +52,7 @@
 #include "raid56.h"
 #include "space-info.h"
 #include "fs.h"
+#include "item-accessors.h"
 #define CREATE_TRACE_POINTS
 #include <trace/events/btrfs.h>
 
fs/btrfs/sysfs.c +1 -0
index 6a7ab762a543..7c5a8d77f2a7 100644
@@ -24,6 +24,7 @@
 #include "qgroup.h"
 #include "misc.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Structure name                       Path
fs/btrfs/tests/extent-buffer-tests.c +1 -0
index b7d181a08eab..5df542b889c8 100644
@@ -8,6 +8,7 @@
 #include "../ctree.h"
 #include "../extent_io.h"
 #include "../disk-io.h"
+#include "../item-accessors.h"
 
 static int test_btrfs_split_item(u32 sectorsize, u32 nodesize)
 {
fs/btrfs/tests/free-space-tree-tests.c +1 -0
index 13734ed43bfc..fcf9257435ca 100644
@@ -10,6 +10,7 @@
 #include "../free-space-tree.h"
 #include "../transaction.h"
 #include "../block-group.h"
+#include "../item-accessors.h"
 
 struct free_space_extent {
 	u64 start;
fs/btrfs/tests/inode-tests.c +1 -0
index b1c88dd187cb..d3178abb8996 100644
@@ -11,6 +11,7 @@
 #include "../extent_io.h"
 #include "../volumes.h"
 #include "../compression.h"
+#include "../item-accessors.h"
 
 static void insert_extent(struct btrfs_root *root, u64 start, u64 len,
 			  u64 ram_bytes, u64 offset, u64 disk_bytenr,
fs/btrfs/tests/qgroup-tests.c +1 -0
index 09b45c3d8386..4095224d9e2c 100644
@@ -11,6 +11,7 @@
 #include "../qgroup.h"
 #include "../backref.h"
 #include "../fs.h"
+#include "../item-accessors.h"
 
 static int insert_normal_tree_ref(struct btrfs_root *root, u64 bytenr,
 				  u64 num_bytes, u64 parent, u64 root_objectid)
fs/btrfs/transaction.c +1 -0
index 37d0baaa41d8..f14bd5b39a09 100644
@@ -24,6 +24,7 @@
 #include "space-info.h"
 #include "zoned.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 static struct kmem_cache *btrfs_trans_handle_cachep;
 
fs/btrfs/tree-checker.c +1 -0
index ec7de2a42b99..99c761ae0352 100644
@@ -27,6 +27,7 @@
 #include "misc.h"
 #include "btrfs_inode.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Error message should follow the following format:
fs/btrfs/tree-defrag.c +1 -0
index b6cf39f4e7e4..b07479d2f900 100644
@@ -9,6 +9,7 @@
 #include "print-tree.h"
 #include "transaction.h"
 #include "locking.h"
+#include "item-accessors.h"
 
 /*
  * Defrag all the leaves in a given btree.
fs/btrfs/tree-mod-log.c +1 -0
index 523a184d10cc..862b5df3ed62 100644
@@ -4,6 +4,7 @@
 #include "tree-mod-log.h"
 #include "disk-io.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 struct tree_mod_root {
 	u64 logical;
fs/btrfs/uuid-tree.c +1 -1
index a24c5b13cf85..e62c88b920ba 100644
@@ -11,7 +11,7 @@
 #include "disk-io.h"
 #include "print-tree.h"
 #include "fs.h"
-
+#include "item-accessors.h"
 
 static void btrfs_uuid_to_key(u8 *uuid, u8 type, struct btrfs_key *key)
 {
fs/btrfs/verity.c +1 -0
index 5b38625f915e..30488102c2da 100644
@@ -17,6 +17,7 @@
 #include "disk-io.h"
 #include "locking.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /*
  * Implementation of the interface defined in struct fsverity_operations.
fs/btrfs/volumes.c +1 -0
index 1938fbf49507..09c1434c3cae 100644
@@ -34,6 +34,7 @@
 #include "discard.h"
 #include "zoned.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 static struct bio_set btrfs_bioset;
 
fs/btrfs/xattr.c +1 -0
index 69ead7e90478..4d7e295414b5 100644
@@ -20,6 +20,7 @@
 #include "disk-io.h"
 #include "props.h"
 #include "locking.h"
+#include "item-accessors.h"
 
 int btrfs_getxattr(struct inode *inode, const char *name,
 				void *buffer, size_t size)
fs/btrfs/zoned.c +1 -0
index 19b533a5766d..4d6647925545 100644
@@ -16,6 +16,7 @@
 #include "dev-replace.h"
 #include "space-info.h"
 #include "fs.h"
+#include "item-accessors.h"
 
 /* Maximum number of zones to report per blkdev_report_zones() call */
 #define BTRFS_REPORT_NR_ZONES   4096
Signature · 1 line
2.26.3
#41 lore raw

Re: [PATCH 16/16] btrfs: move accessor helpers into item-accessors.h

Quoted 6 lines · Josef Bacik

This is a large patch, but because they're all macros it's impossible to split up. Simply copy all of the item accessors in ctree.h and paste them in item-accessors.h, and then update any files to include the header so everything compiles.

Josef,

I hope the patch series dependency is correct, which I understand as below:

------------
[PATCH 00/17] btrfs: initial ctree.h cleanups, simple stuff [PATCH 00/16] btrfs: split out larger chunks of ctree.h [PATCH 00/15] btrfs: strip out btrfs_fs_info dependencies [PATCH 00/10] btrfs: clean up zoned device helpers
------------

However, this patch compilation errors out:

-------------
/Volumes/ws/btrfs-devel/fs/btrfs/locking.c:98:52: error: implicit declaration of function ‘btrfs_header_level’; did you mean ‘btrfs_qgroup_level’? [-Werror=implicit-function-declaration]
98 | eb,

btrfs_header_level(eb));
      | 
^~~~~~~~~~~~~~~~~~
      |

-------------

It can be fixed by the below diff:

--------------

fs/btrfs/locking.c +1 -0
index 9063072b399b..aa7aec25672a 100644
@@ -12,6 +12,7 @@
 #include "ctree.h"
 #include "extent_io.h"
 #include "locking.h"
+#include "item-accessors.h"
 
 /*
  * Lockdep class keys for extent_buffer->lock's in this root.  For a given

-------------

Thanks, Anand

#42 lore raw
In reply to Josef Bacik
Quoted 39 lines · Josef Bacik

Hello,

This series is based on the series

btrfs: initial ctree.h cleanups, simple stuff

which needs to be in place before applying these patches.

This is likely going to have the largest patch of the series, which bulk moves all of the struct funcs defines out of ctree.h into their own file. This isn't really possible to do piecemeal like other changes because we're using macros instead of functions. However the code is well organized so it allows for a bulk copy and paste, so is straightforward.

I've done my best with naming, but I'm open to suggestions. My general plan is to have all fs wide definitions in fs.h, and then separate out individual things to their own headers.

The biggest things I've done in this series are

1. Move the printk helpers into their own files.
2. Move the main state flags and core fs helpers into their own files.
3. Moved the struct func definitions to their own files.

This is by no means complete, this is just the first big pass, but as you can see is already 17 patches long. Subsequent patches will move more code and do more cleanups. Thanks,

Josef

Josef Bacik (16):
btrfs: move fs wide helpers out of ctree.h
btrfs: move larger compat flag helpers to their own c file
btrfs: move the printk helpers out of ctree.h
btrfs: push extra checks into __btrfs_abort_transaction
btrfs: move assert and error helpers out of btrfs-printk.h
btrfs: push printk index code into their respective helpers
btrfs: move BTRFS_FS_STATE* defs and helpers to fs.h
btrfs: move incompat and compat flag helpers to fs.c

Quoted 8 lines

btrfs: move mount option definitions to fs.h
btrfs: move fs_info->flags enum to fs.h
btrfs: add a BTRFS_FS_NEED_TRANS_COMMIT flag
btrfs: remove fs_info::pending_changes and related code
btrfs: move the compat/incompat flag masks to fs.h
btrfs: rename struct-funcs.c -> item-accessors.c
btrfs: move btrfs_map_token to item-accessors
btrfs: move accessor helpers into item-accessors.h

Oh my god, I have "accessors.h" in my btrfs-fuse project from day 1, finally can see it in upstream btrfs.

But one thing to mention is, "item" looks more leaf oriented, while I believe node accessors would also be in the same header?

Thus what about just plain "accessors.h"?

Thanks,
Qu

Quoted 76 lines
  fs/btrfs/Makefile                             |    4 +-
  fs/btrfs/backref.c                            |    2 +
  fs/btrfs/backref.h                            |    1 +
  fs/btrfs/block-group.c                        |    2 +
  fs/btrfs/block-rsv.c                          |    2 +
  fs/btrfs/btrfs-printk.h                       |  206 ++
  fs/btrfs/check-integrity.c                    |    2 +
  fs/btrfs/compression.c                        |    1 +
  fs/btrfs/ctree.c                              |    3 +
  fs/btrfs/ctree.h                              | 1784 +----------------
  fs/btrfs/delalloc-space.c                     |    2 +
  fs/btrfs/delayed-inode.c                      |    3 +
  fs/btrfs/delayed-ref.c                        |    2 +
  fs/btrfs/dev-replace.c                        |    2 +
  fs/btrfs/dir-item.c                           |    2 +
  fs/btrfs/discard.c                            |    1 +
  fs/btrfs/disk-io.c                            |    8 +-
  fs/btrfs/export.c                             |    1 +
  fs/btrfs/extent-io-tree.c                     |    1 +
  fs/btrfs/extent-tree.c                        |    2 +
  fs/btrfs/extent_io.c                          |    2 +
  fs/btrfs/extent_map.c                         |    1 +
  fs/btrfs/file-item.c                          |    3 +
  fs/btrfs/file.c                               |    2 +
  fs/btrfs/free-space-cache.c                   |    3 +
  fs/btrfs/free-space-tree.c                    |    3 +
  fs/btrfs/fs.c                                 |  108 +
  fs/btrfs/fs.h                                 |  320 +++
  fs/btrfs/inode-item.c                         |    2 +
  fs/btrfs/inode.c                              |    2 +
  fs/btrfs/ioctl.c                              |    2 +
  fs/btrfs/{struct-funcs.c => item-accessors.c} |   10 +
  fs/btrfs/item-accessors.h                     | 1104 ++++++++++
  fs/btrfs/lzo.c                                |    1 +
  fs/btrfs/ordered-data.c                       |    1 +
  fs/btrfs/print-tree.c                         |    2 +
  fs/btrfs/props.c                              |    3 +
  fs/btrfs/qgroup.c                             |    2 +
  fs/btrfs/raid56.c                             |    1 +
  fs/btrfs/ref-verify.c                         |    3 +
  fs/btrfs/reflink.c                            |    2 +
  fs/btrfs/relocation.c                         |    2 +
  fs/btrfs/root-tree.c                          |    3 +
  fs/btrfs/scrub.c                              |    2 +
  fs/btrfs/send.c                               |    1 +
  fs/btrfs/space-info.c                         |    2 +
  fs/btrfs/subpage.c                            |    1 +
  fs/btrfs/super.c                              |   51 +-
  fs/btrfs/sysfs.c                              |    7 +-
  fs/btrfs/tests/btrfs-tests.c                  |    1 +
  fs/btrfs/tests/extent-buffer-tests.c          |    1 +
  fs/btrfs/tests/free-space-tree-tests.c        |    1 +
  fs/btrfs/tests/inode-tests.c                  |    1 +
  fs/btrfs/tests/qgroup-tests.c                 |    2 +
  fs/btrfs/transaction.c                        |   29 +-
  fs/btrfs/transaction.h                        |    1 -
  fs/btrfs/tree-checker.c                       |    3 +
  fs/btrfs/tree-defrag.c                        |    1 +
  fs/btrfs/tree-log.c                           |    2 +
  fs/btrfs/tree-log.h                           |    1 +
  fs/btrfs/tree-mod-log.c                       |    3 +
  fs/btrfs/ulist.c                              |    1 +
  fs/btrfs/uuid-tree.c                          |    4 +-
  fs/btrfs/verity.c                             |    3 +
  fs/btrfs/volumes.c                            |    2 +
  fs/btrfs/xattr.c                              |    2 +
  fs/btrfs/zoned.c                              |    2 +
  fs/btrfs/zoned.h                              |    1 +
  68 files changed, 1915 insertions(+), 1823 deletions(-)

create mode 100644 fs/btrfs/btrfs-printk.h create mode 100644 fs/btrfs/fs.c
create mode 100644 fs/btrfs/fs.h
rename fs/btrfs/{struct-funcs.c => item-accessors.c} (96%) create mode 100644 fs/btrfs/item-accessors.h

#43 lore raw
Quoted 5 lines · Qu Wenruo
Quoted 1 line · Josef Bacik

btrfs: move accessor helpers into item-accessors.h

Oh my god, I have "accessors.h" in my btrfs-fuse project from day 1, finally can see it in upstream btrfs.

Good for you, you don't have to repeat the same mistakes and copy the file naming scheme in a fresh project, that's the advantage. In an actively developed yet old code base it's not for free. We basically have to stop for one dev cycle and do only cleanups and renaming and this will haunt us for years when doing backports. I'm not looking forward to that but we need it.

Quoted 4 lines

But one thing to mention is, "item" looks more leaf oriented, while I believe node accessors would also be in the same header?

Thus what about just plain "accessors.h"?

Yeah probably accessors.h will be the final name.

#44 lore raw
In reply to Josef Bacik
Quoted 14 lines · Josef Bacik

Hello,

This series is based on the series

btrfs: initial ctree.h cleanups, simple stuff

which needs to be in place before applying these patches.

This is likely going to have the largest patch of the series, which bulk moves all of the struct funcs defines out of ctree.h into their own file. This isn't really possible to do piecemeal like other changes because we're using macros instead of functions. However the code is well organized so it allows for a bulk copy and paste, so is straightforward.

Quoted 3 lines

I've done my best with naming, but I'm open to suggestions. My general plan is to have all fs wide definitions in fs.h, and then separate out individual things to their own headers.

The fs.h feels like another ctree.h but we have to start somewhere and further moving stuff from fs.h sounds like a plan.

Quoted 10 lines

The biggest things I've done in this series are

1. Move the printk helpers into their own files.
2. Move the main state flags and core fs helpers into their own files.
3. Moved the struct func definitions to their own files.

This is by no means complete, this is just the first big pass, but as you can see is already 17 patches long. Subsequent patches will move more code and do more cleanups. Thanks,

I'll try to merge such straightforward patchsets without much delay as long as the changes are straightforward and reasonable assuming that we'll reach perfection eventually. This series can be used as reference for what is OK, with some minor fixups or renames. The name of btrfs-printk.h stands out as it's using two subsystems while I'd expect something more decriptive of what's inside like messages.h. For that a resend is not necessary, just that we agree that a rename is fine.