public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/12] btrfs: item helper prep work for snapshot_id
@ 2022-03-07 22:33 Josef Bacik
  2022-03-07 22:33 ` [PATCH 01/12] btrfs: move btrfs_node_key into ctree.h Josef Bacik
                   ` (12 more replies)
  0 siblings, 13 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Hello,

I sent a bunch of patches previously to rework a lot of our helpers in
preparation of adding the snapshot_id to the btrfs_header.  I missed a few
important areas with those patches, so here's the remaining work to make it
easier to expand the size of the btrfs_header.  These are general fixups and
cleanups that don't rely on the extent tree v2 work.  Thanks,

Josef

Josef Bacik (12):
  btrfs: move btrfs_node_key into ctree.h
  btrfs: add a btrfs_node_key_ptr helper, convert the users
  btrfs: introduce *_leaf_data helpers
  btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg
  btrfs: pass eb to the node_key_ptr helpers
  btrfs: pass eb to the item_nr_offset helper
  btrfs: add snapshot_id to the btrfs_header and related defs
  btrfs: move the header SETGET funcs
  btrfs: move the super SETGET funcs
  btrfs: move BTRFS_LEAF related definitions below super SETGET funcs
  btrfs: const-ify fs_info for the compat flag handlers
  btrfs: use _offset helpers instead of offsetof in generic_bin_search

 fs/btrfs/ctree.c                | 151 ++++++------
 fs/btrfs/ctree.h                | 411 +++++++++++++++++---------------
 fs/btrfs/extent_io.c            |   6 +-
 fs/btrfs/struct-funcs.c         |   8 -
 fs/btrfs/tree-checker.c         |   4 +-
 fs/btrfs/tree-mod-log.c         |   4 +-
 include/uapi/linux/btrfs_tree.h |   1 +
 7 files changed, 303 insertions(+), 282 deletions(-)

-- 
2.26.3


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 01/12] btrfs: move btrfs_node_key into ctree.h
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users Josef Bacik
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This is randomly in struct-funcs.c, well away from all of the other
related functions, move this to where it's family lives.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h        | 9 +++++++--
 fs/btrfs/struct-funcs.c | 8 --------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 29e0e009267b..819bd8631c4c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1998,8 +1998,13 @@ static inline unsigned long btrfs_node_key_ptr_offset(int nr)
 		sizeof(struct btrfs_key_ptr) * nr;
 }
 
-void btrfs_node_key(const struct extent_buffer *eb,
-		    struct btrfs_disk_key *disk_key, int nr);
+static inline void btrfs_node_key(const struct extent_buffer *eb,
+				  struct btrfs_disk_key *disk_key, int nr)
+{
+	unsigned long ptr = btrfs_node_key_ptr_offset(nr);
+	read_eb_member(eb, (struct btrfs_key_ptr *)ptr, struct btrfs_key_ptr,
+		       key, disk_key);
+}
 
 static inline void btrfs_set_node_key(const struct extent_buffer *eb,
 				      struct btrfs_disk_key *disk_key, int nr)
diff --git a/fs/btrfs/struct-funcs.c b/fs/btrfs/struct-funcs.c
index f429256f56db..7526005525cb 100644
--- a/fs/btrfs/struct-funcs.c
+++ b/fs/btrfs/struct-funcs.c
@@ -161,11 +161,3 @@ DEFINE_BTRFS_SETGET_BITS(8)
 DEFINE_BTRFS_SETGET_BITS(16)
 DEFINE_BTRFS_SETGET_BITS(32)
 DEFINE_BTRFS_SETGET_BITS(64)
-
-void btrfs_node_key(const struct extent_buffer *eb,
-		    struct btrfs_disk_key *disk_key, int nr)
-{
-	unsigned long ptr = btrfs_node_key_ptr_offset(nr);
-	read_eb_member(eb, (struct btrfs_key_ptr *)ptr,
-		       struct btrfs_key_ptr, key, disk_key);
-}
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
  2022-03-07 22:33 ` [PATCH 01/12] btrfs: move btrfs_node_key into ctree.h Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-09 13:48   ` Nikolay Borisov
  2022-03-07 22:33 ` [PATCH 03/12] btrfs: introduce *_leaf_data helpers Josef Bacik
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

All of the node helpers are getting the pointer offset and then casting
to btrfs_key_ptr.  Instead do this with a helper similar to how we do it
with items and change all the helpers to use the new helper.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h | 48 +++++++++++++++++++-----------------------------
 1 file changed, 19 insertions(+), 29 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 819bd8631c4c..d5d52b907143 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1958,61 +1958,51 @@ BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr,
 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
 			 generation, 64);
 
-static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
+static inline unsigned long btrfs_node_key_ptr_offset(int nr)
 {
-	unsigned long ptr;
-	ptr = offsetof(struct btrfs_node, ptrs) +
+	return offsetof(struct btrfs_node, ptrs) +
 		sizeof(struct btrfs_key_ptr) * nr;
-	return btrfs_key_blockptr(eb, (struct btrfs_key_ptr *)ptr);
+}
+
+static inline struct btrfs_key_ptr *btrfs_node_key_ptr(int nr)
+{
+	return (struct btrfs_key_ptr *)btrfs_node_key_ptr_offset(nr);
+}
+
+static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
+{
+	return btrfs_key_blockptr(eb, btrfs_node_key_ptr(nr));
 }
 
 static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
 					   int nr, u64 val)
 {
-	unsigned long ptr;
-	ptr = offsetof(struct btrfs_node, ptrs) +
-		sizeof(struct btrfs_key_ptr) * nr;
-	btrfs_set_key_blockptr(eb, (struct btrfs_key_ptr *)ptr, val);
+	btrfs_set_key_blockptr(eb, btrfs_node_key_ptr(nr), val);
 }
 
 static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
 {
-	unsigned long ptr;
-	ptr = offsetof(struct btrfs_node, ptrs) +
-		sizeof(struct btrfs_key_ptr) * nr;
-	return btrfs_key_generation(eb, (struct btrfs_key_ptr *)ptr);
+	return btrfs_key_generation(eb, btrfs_node_key_ptr(nr));
 }
 
 static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
 						 int nr, u64 val)
 {
-	unsigned long ptr;
-	ptr = offsetof(struct btrfs_node, ptrs) +
-		sizeof(struct btrfs_key_ptr) * nr;
-	btrfs_set_key_generation(eb, (struct btrfs_key_ptr *)ptr, val);
-}
-
-static inline unsigned long btrfs_node_key_ptr_offset(int nr)
-{
-	return offsetof(struct btrfs_node, ptrs) +
-		sizeof(struct btrfs_key_ptr) * nr;
+	btrfs_set_key_generation(eb, btrfs_node_key_ptr(nr), val);
 }
 
 static inline void btrfs_node_key(const struct extent_buffer *eb,
 				  struct btrfs_disk_key *disk_key, int nr)
 {
-	unsigned long ptr = btrfs_node_key_ptr_offset(nr);
-	read_eb_member(eb, (struct btrfs_key_ptr *)ptr, struct btrfs_key_ptr,
-		       key, disk_key);
+	read_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key,
+		       disk_key);
 }
 
 static inline void btrfs_set_node_key(const struct extent_buffer *eb,
 				      struct btrfs_disk_key *disk_key, int nr)
 {
-	unsigned long ptr;
-	ptr = btrfs_node_key_ptr_offset(nr);
-	write_eb_member(eb, (struct btrfs_key_ptr *)ptr,
-		       struct btrfs_key_ptr, key, disk_key);
+	write_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key,
+			disk_key);
 }
 
 /* struct btrfs_item */
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 03/12] btrfs: introduce *_leaf_data helpers
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
  2022-03-07 22:33 ` [PATCH 01/12] btrfs: move btrfs_node_key into ctree.h Josef Bacik
  2022-03-07 22:33 ` [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 04/12] btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg Josef Bacik
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

The item offsets are set not taking into account the
BTRFS_LEAF_DATA_OFFSET, which is to say they ignore the size of the
header.

ie btrfs_item_offset(nr) is actually sizeof(struct btrfs_header) +
btrfs_item_offset(nr) into the leaf.

Because of this anywhere we do memmove/copy of the item data we have to
add BTRFS_LEAF_DATA_OFFSET to the offsets we're using.  Which means we
have the following pattern

copy_extent_buffer(src, dst,
		   BTRFS_LEAF_DATA_OFFSET + btrfs_item_offset(nr),
		   BTRFS_LEAF_DATA_OFFSET + other_offset, size);

in a lot of spaces.  Clean this up by adding two helpers that do the
appropriate offset adjustment, and change all the users to simply pass
in the item_offset offsets.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.c | 84 ++++++++++++++++++++++++++----------------------
 1 file changed, 46 insertions(+), 38 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index eee0b7e3c68a..8a35db9d7319 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -43,6 +43,31 @@ static const struct btrfs_csums {
 				     .driver = "blake2b-256" },
 };
 
+/*
+ * These helpers take the btrfs_item_offset() values and adjust them based on
+ * the header size.  Do not use these with the value adjusted for the header,
+ * simply use the raw btrfs_item_offset() values.
+ */
+static inline void memmove_leaf_data(const struct extent_buffer *dst,
+				     unsigned long dst_offset,
+				     unsigned long src_offset,
+				     unsigned long len)
+{
+	dst_offset += BTRFS_LEAF_DATA_OFFSET;
+	src_offset += BTRFS_LEAF_DATA_OFFSET;
+	memmove_extent_buffer(dst, dst_offset, src_offset, len);
+}
+
+static inline void copy_leaf_data(const struct extent_buffer *dst,
+				  const struct extent_buffer *src,
+				  unsigned long dst_offset,
+				  unsigned long src_offset, unsigned long len)
+{
+	dst_offset += BTRFS_LEAF_DATA_OFFSET;
+	src_offset += BTRFS_LEAF_DATA_OFFSET;
+	copy_extent_buffer(dst, src, dst_offset, src_offset, len);
+}
+
 int btrfs_super_csum_size(const struct btrfs_super_block *s)
 {
 	u16 t = btrfs_super_csum_type(s);
@@ -2880,16 +2905,12 @@ static noinline int __push_leaf_right(struct btrfs_path *path,
 
 	/* make room in the right data area */
 	data_end = leaf_data_end(right);
-	memmove_extent_buffer(right,
-			      BTRFS_LEAF_DATA_OFFSET + data_end - push_space,
-			      BTRFS_LEAF_DATA_OFFSET + data_end,
-			      BTRFS_LEAF_DATA_SIZE(fs_info) - data_end);
+	memmove_leaf_data(right, data_end - push_space, data_end,
+			  BTRFS_LEAF_DATA_SIZE(fs_info) - data_end);
 
 	/* copy from the left data area */
-	copy_extent_buffer(right, left, BTRFS_LEAF_DATA_OFFSET +
-		     BTRFS_LEAF_DATA_SIZE(fs_info) - push_space,
-		     BTRFS_LEAF_DATA_OFFSET + leaf_data_end(left),
-		     push_space);
+	copy_leaf_data(right, left, BTRFS_LEAF_DATA_SIZE(fs_info) - push_space,
+		       leaf_data_end(left), push_space);
 
 	memmove_extent_buffer(right, btrfs_item_nr_offset(push_items),
 			      btrfs_item_nr_offset(0),
@@ -3098,11 +3119,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,
 	push_space = BTRFS_LEAF_DATA_SIZE(fs_info) -
 		     btrfs_item_offset(right, push_items - 1);
 
-	copy_extent_buffer(left, right, BTRFS_LEAF_DATA_OFFSET +
-		     leaf_data_end(left) - push_space,
-		     BTRFS_LEAF_DATA_OFFSET +
-		     btrfs_item_offset(right, push_items - 1),
-		     push_space);
+	copy_leaf_data(left, right, leaf_data_end(left) - push_space,
+		       btrfs_item_offset(right, push_items - 1), push_space);
 	old_left_nritems = btrfs_header_nritems(left);
 	BUG_ON(old_left_nritems <= 0);
 
@@ -3125,10 +3143,9 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,
 	if (push_items < right_nritems) {
 		push_space = btrfs_item_offset(right, push_items - 1) -
 						  leaf_data_end(right);
-		memmove_extent_buffer(right, BTRFS_LEAF_DATA_OFFSET +
-				      BTRFS_LEAF_DATA_SIZE(fs_info) - push_space,
-				      BTRFS_LEAF_DATA_OFFSET +
-				      leaf_data_end(right), push_space);
+		memmove_leaf_data(right,
+				  BTRFS_LEAF_DATA_SIZE(fs_info) - push_space,
+				  leaf_data_end(right), push_space);
 
 		memmove_extent_buffer(right, btrfs_item_nr_offset(0),
 			      btrfs_item_nr_offset(push_items),
@@ -3269,10 +3286,8 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans,
 			   btrfs_item_nr_offset(mid),
 			   nritems * sizeof(struct btrfs_item));
 
-	copy_extent_buffer(right, l,
-		     BTRFS_LEAF_DATA_OFFSET + BTRFS_LEAF_DATA_SIZE(fs_info) -
-		     data_copy_size, BTRFS_LEAF_DATA_OFFSET +
-		     leaf_data_end(l), data_copy_size);
+	copy_leaf_data(right, l, BTRFS_LEAF_DATA_SIZE(fs_info) - data_copy_size,
+		       leaf_data_end(l), data_copy_size);
 
 	rt_data_off = BTRFS_LEAF_DATA_SIZE(fs_info) - btrfs_item_data_end(l, mid);
 
@@ -3755,9 +3770,8 @@ void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end)
 
 	/* shift the data */
 	if (from_end) {
-		memmove_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET +
-			      data_end + size_diff, BTRFS_LEAF_DATA_OFFSET +
-			      data_end, old_data_start + new_size - data_end);
+		memmove_leaf_data(leaf, data_end + size_diff, data_end,
+				  old_data_start + new_size - data_end);
 	} else {
 		struct btrfs_disk_key disk_key;
 		u64 offset;
@@ -3782,9 +3796,8 @@ void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end)
 			}
 		}
 
-		memmove_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET +
-			      data_end + size_diff, BTRFS_LEAF_DATA_OFFSET +
-			      data_end, old_data_start - data_end);
+		memmove_leaf_data(leaf, data_end + size_diff, data_end,
+				  old_data_start - data_end);
 
 		offset = btrfs_disk_key_offset(&disk_key);
 		btrfs_set_disk_key_offset(&disk_key, offset + size_diff);
@@ -3849,9 +3862,8 @@ void btrfs_extend_item(struct btrfs_path *path, u32 data_size)
 	}
 
 	/* shift the data */
-	memmove_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET +
-		      data_end - data_size, BTRFS_LEAF_DATA_OFFSET +
-		      data_end, old_data - data_end);
+	memmove_leaf_data(leaf, data_end - data_size, data_end,
+			  old_data - data_end);
 
 	data_end = old_data;
 	old_size = btrfs_item_size(leaf, slot);
@@ -3939,10 +3951,8 @@ static void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *p
 			      (nritems - slot) * sizeof(struct btrfs_item));
 
 		/* shift the data */
-		memmove_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET +
-				      data_end - batch->total_data_size,
-				      BTRFS_LEAF_DATA_OFFSET + data_end,
-				      old_data - data_end);
+		memmove_leaf_data(leaf, data_end - batch->total_data_size,
+				  data_end, old_data - data_end);
 		data_end = old_data;
 	}
 
@@ -4177,10 +4187,8 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		for (i = 0; i < nr; i++)
 			dsize += btrfs_item_size(leaf, slot + i);
 
-		memmove_extent_buffer(leaf, BTRFS_LEAF_DATA_OFFSET +
-			      data_end + dsize,
-			      BTRFS_LEAF_DATA_OFFSET + data_end,
-			      last_off - data_end);
+		memmove_leaf_data(leaf, data_end + dsize, data_end,
+				  last_off - data_end);
 
 		btrfs_init_map_token(&token, leaf);
 		for (i = slot + nr; i < nritems; i++) {
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 04/12] btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (2 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 03/12] btrfs: introduce *_leaf_data helpers Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 05/12] btrfs: pass eb to the node_key_ptr helpers Josef Bacik
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

When I expand the size of the btrfs_header we're going to need to
conditionally return a different offset.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.c     | 8 ++++----
 fs/btrfs/ctree.h     | 9 ++++++---
 fs/btrfs/extent_io.c | 2 +-
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 8a35db9d7319..2e270f8d995e 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -53,8 +53,8 @@ static inline void memmove_leaf_data(const struct extent_buffer *dst,
 				     unsigned long src_offset,
 				     unsigned long len)
 {
-	dst_offset += BTRFS_LEAF_DATA_OFFSET;
-	src_offset += BTRFS_LEAF_DATA_OFFSET;
+	dst_offset += BTRFS_LEAF_DATA_OFFSET(dst);
+	src_offset += BTRFS_LEAF_DATA_OFFSET(dst);
 	memmove_extent_buffer(dst, dst_offset, src_offset, len);
 }
 
@@ -63,8 +63,8 @@ static inline void copy_leaf_data(const struct extent_buffer *dst,
 				  unsigned long dst_offset,
 				  unsigned long src_offset, unsigned long len)
 {
-	dst_offset += BTRFS_LEAF_DATA_OFFSET;
-	src_offset += BTRFS_LEAF_DATA_OFFSET;
+	dst_offset += BTRFS_LEAF_DATA_OFFSET(dst);
+	src_offset += BTRFS_LEAF_DATA_OFFSET(dst);
 	copy_extent_buffer(dst, src, dst_offset, src_offset, len);
 }
 
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index d5d52b907143..f4f3d41775e6 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1422,7 +1422,10 @@ static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
 	return info->nodesize - sizeof(struct btrfs_header);
 }
 
-#define BTRFS_LEAF_DATA_OFFSET		offsetof(struct btrfs_leaf, items)
+static inline unsigned long BTRFS_LEAF_DATA_OFFSET(const struct extent_buffer *leaf)
+{
+	return offsetof(struct btrfs_leaf, items);
+}
 
 static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info)
 {
@@ -2692,11 +2695,11 @@ BTRFS_SETGET_STACK_FUNCS(stack_dev_replace_cursor_right,
 
 /* helper function to cast into the data area of the leaf. */
 #define btrfs_item_ptr(leaf, slot, type) \
-	((type *)(BTRFS_LEAF_DATA_OFFSET + \
+	((type *)(BTRFS_LEAF_DATA_OFFSET(leaf) + \
 	btrfs_item_offset(leaf, slot)))
 
 #define btrfs_item_ptr_offset(leaf, slot) \
-	((unsigned long)(BTRFS_LEAF_DATA_OFFSET + \
+	((unsigned long)(BTRFS_LEAF_DATA_OFFSET(leaf) + \
 	btrfs_item_offset(leaf, slot)))
 
 static inline u32 btrfs_crc32c(u32 crc, const void *address, unsigned length)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 78486bbd1ac9..c5334af2fae5 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4508,7 +4508,7 @@ static void prepare_eb_write(struct extent_buffer *eb)
 		 * header 0 1 2 .. N ... data_N .. data_2 data_1 data_0
 		 */
 		start = btrfs_item_nr_offset(nritems);
-		end = BTRFS_LEAF_DATA_OFFSET + leaf_data_end(eb);
+		end = BTRFS_LEAF_DATA_OFFSET(eb) + leaf_data_end(eb);
 		memzero_extent_buffer(eb, start, end - start);
 	}
 }
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 05/12] btrfs: pass eb to the node_key_ptr helpers
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (3 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 04/12] btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 06/12] btrfs: pass eb to the item_nr_offset helper Josef Bacik
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

These helpers are going to require the eb in order to determine the size
of the header we need to use, so add the eb to the arguments and change
all of the callers to pass in the eb.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.c        | 28 ++++++++++++++--------------
 fs/btrfs/ctree.h        | 20 +++++++++++---------
 fs/btrfs/extent_io.c    |  2 +-
 fs/btrfs/tree-mod-log.c |  4 ++--
 4 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 2e270f8d995e..508bbc50fe8b 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2495,8 +2495,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,
 		return ret;
 	}
 	copy_extent_buffer(dst, src,
-			   btrfs_node_key_ptr_offset(dst_nritems),
-			   btrfs_node_key_ptr_offset(0),
+			   btrfs_node_key_ptr_offset(dst, dst_nritems),
+			   btrfs_node_key_ptr_offset(src, 0),
 			   push_items * sizeof(struct btrfs_key_ptr));
 
 	if (push_items < src_nritems) {
@@ -2504,8 +2504,8 @@ static int push_node_left(struct btrfs_trans_handle *trans,
 		 * Don't call btrfs_tree_mod_log_insert_move() here, key removal
 		 * was already fully logged by btrfs_tree_mod_log_eb_copy() above.
 		 */
-		memmove_extent_buffer(src, btrfs_node_key_ptr_offset(0),
-				      btrfs_node_key_ptr_offset(push_items),
+		memmove_extent_buffer(src, btrfs_node_key_ptr_offset(src, 0),
+				      btrfs_node_key_ptr_offset(src, push_items),
 				      (src_nritems - push_items) *
 				      sizeof(struct btrfs_key_ptr));
 	}
@@ -2565,8 +2565,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
 	}
 	ret = btrfs_tree_mod_log_insert_move(dst, push_items, 0, dst_nritems);
 	BUG_ON(ret < 0);
-	memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(push_items),
-				      btrfs_node_key_ptr_offset(0),
+	memmove_extent_buffer(dst, btrfs_node_key_ptr_offset(dst, push_items),
+				      btrfs_node_key_ptr_offset(dst, 0),
 				      (dst_nritems) *
 				      sizeof(struct btrfs_key_ptr));
 
@@ -2577,8 +2577,8 @@ static int balance_node_right(struct btrfs_trans_handle *trans,
 		return ret;
 	}
 	copy_extent_buffer(dst, src,
-			   btrfs_node_key_ptr_offset(0),
-			   btrfs_node_key_ptr_offset(src_nritems - push_items),
+			   btrfs_node_key_ptr_offset(dst, 0),
+			   btrfs_node_key_ptr_offset(src, src_nritems - push_items),
 			   push_items * sizeof(struct btrfs_key_ptr));
 
 	btrfs_set_header_nritems(src, src_nritems - push_items);
@@ -2681,8 +2681,8 @@ static void insert_ptr(struct btrfs_trans_handle *trans,
 			BUG_ON(ret < 0);
 		}
 		memmove_extent_buffer(lower,
-			      btrfs_node_key_ptr_offset(slot + 1),
-			      btrfs_node_key_ptr_offset(slot),
+			      btrfs_node_key_ptr_offset(lower, slot + 1),
+			      btrfs_node_key_ptr_offset(lower, slot),
 			      (nritems - slot) * sizeof(struct btrfs_key_ptr));
 	}
 	if (level) {
@@ -2764,8 +2764,8 @@ static noinline int split_node(struct btrfs_trans_handle *trans,
 		return ret;
 	}
 	copy_extent_buffer(split, c,
-			   btrfs_node_key_ptr_offset(0),
-			   btrfs_node_key_ptr_offset(mid),
+			   btrfs_node_key_ptr_offset(split, 0),
+			   btrfs_node_key_ptr_offset(c, mid),
 			   (c_nritems - mid) * sizeof(struct btrfs_key_ptr));
 	btrfs_set_header_nritems(split, c_nritems - mid);
 	btrfs_set_header_nritems(c, mid);
@@ -4106,8 +4106,8 @@ static void del_ptr(struct btrfs_root *root, struct btrfs_path *path,
 			BUG_ON(ret < 0);
 		}
 		memmove_extent_buffer(parent,
-			      btrfs_node_key_ptr_offset(slot),
-			      btrfs_node_key_ptr_offset(slot + 1),
+			      btrfs_node_key_ptr_offset(parent, slot),
+			      btrfs_node_key_ptr_offset(parent, slot + 1),
 			      sizeof(struct btrfs_key_ptr) *
 			      (nritems - slot - 1));
 	} else if (level) {
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index f4f3d41775e6..53a8e200c953 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1961,50 +1961,52 @@ BTRFS_SETGET_STACK_FUNCS(stack_key_blockptr, struct btrfs_key_ptr,
 BTRFS_SETGET_STACK_FUNCS(stack_key_generation, struct btrfs_key_ptr,
 			 generation, 64);
 
-static inline unsigned long btrfs_node_key_ptr_offset(int nr)
+static inline unsigned long btrfs_node_key_ptr_offset(const struct extent_buffer *eb,
+						      int nr)
 {
 	return offsetof(struct btrfs_node, ptrs) +
 		sizeof(struct btrfs_key_ptr) * nr;
 }
 
-static inline struct btrfs_key_ptr *btrfs_node_key_ptr(int nr)
+static inline struct btrfs_key_ptr *btrfs_node_key_ptr(const struct extent_buffer *eb,
+						       int nr)
 {
-	return (struct btrfs_key_ptr *)btrfs_node_key_ptr_offset(nr);
+	return (struct btrfs_key_ptr *)btrfs_node_key_ptr_offset(eb, nr);
 }
 
 static inline u64 btrfs_node_blockptr(const struct extent_buffer *eb, int nr)
 {
-	return btrfs_key_blockptr(eb, btrfs_node_key_ptr(nr));
+	return btrfs_key_blockptr(eb, btrfs_node_key_ptr(eb, nr));
 }
 
 static inline void btrfs_set_node_blockptr(const struct extent_buffer *eb,
 					   int nr, u64 val)
 {
-	btrfs_set_key_blockptr(eb, btrfs_node_key_ptr(nr), val);
+	btrfs_set_key_blockptr(eb, btrfs_node_key_ptr(eb, nr), val);
 }
 
 static inline u64 btrfs_node_ptr_generation(const struct extent_buffer *eb, int nr)
 {
-	return btrfs_key_generation(eb, btrfs_node_key_ptr(nr));
+	return btrfs_key_generation(eb, btrfs_node_key_ptr(eb, nr));
 }
 
 static inline void btrfs_set_node_ptr_generation(const struct extent_buffer *eb,
 						 int nr, u64 val)
 {
-	btrfs_set_key_generation(eb, btrfs_node_key_ptr(nr), val);
+	btrfs_set_key_generation(eb, btrfs_node_key_ptr(eb, nr), val);
 }
 
 static inline void btrfs_node_key(const struct extent_buffer *eb,
 				  struct btrfs_disk_key *disk_key, int nr)
 {
-	read_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key,
+	read_eb_member(eb, btrfs_node_key_ptr(eb, nr), struct btrfs_key_ptr, key,
 		       disk_key);
 }
 
 static inline void btrfs_set_node_key(const struct extent_buffer *eb,
 				      struct btrfs_disk_key *disk_key, int nr)
 {
-	write_eb_member(eb, btrfs_node_key_ptr(nr), struct btrfs_key_ptr, key,
+	write_eb_member(eb, btrfs_node_key_ptr(eb, nr), struct btrfs_key_ptr, key,
 			disk_key);
 }
 
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index c5334af2fae5..86a0dd3b55b0 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4500,7 +4500,7 @@ static void prepare_eb_write(struct extent_buffer *eb)
 	/* Set btree blocks beyond nritems with 0 to avoid stale content */
 	nritems = btrfs_header_nritems(eb);
 	if (btrfs_header_level(eb) > 0) {
-		end = btrfs_node_key_ptr_offset(nritems);
+		end = btrfs_node_key_ptr_offset(eb, nritems);
 		memzero_extent_buffer(eb, end, eb->len - end);
 	} else {
 		/*
diff --git a/fs/btrfs/tree-mod-log.c b/fs/btrfs/tree-mod-log.c
index 8a3a14686d3e..e73fc11c8887 100644
--- a/fs/btrfs/tree-mod-log.c
+++ b/fs/btrfs/tree-mod-log.c
@@ -694,8 +694,8 @@ static void tree_mod_log_rewind(struct btrfs_fs_info *fs_info,
 			n--;
 			break;
 		case BTRFS_MOD_LOG_MOVE_KEYS:
-			o_dst = btrfs_node_key_ptr_offset(tm->slot);
-			o_src = btrfs_node_key_ptr_offset(tm->move.dst_slot);
+			o_dst = btrfs_node_key_ptr_offset(eb, tm->slot);
+			o_src = btrfs_node_key_ptr_offset(eb, tm->move.dst_slot);
 			memmove_extent_buffer(eb, o_dst, o_src,
 					      tm->move.nr_items * p_size);
 			break;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 06/12] btrfs: pass eb to the item_nr_offset helper
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (4 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 05/12] btrfs: pass eb to the node_key_ptr helpers Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-09 13:55   ` Nikolay Borisov
  2022-03-07 22:33 ` [PATCH 07/12] btrfs: add snapshot_id to the btrfs_header and related defs Josef Bacik
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This helper needs to know what version of the fs we're looking at to
return the proper offset into the leaf where the item starts, so pass in
the eb so we can get the proper offset.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.c        | 35 ++++++++++++++++++-----------------
 fs/btrfs/ctree.h        | 20 +++++++++++---------
 fs/btrfs/extent_io.c    |  2 +-
 fs/btrfs/tree-checker.c |  4 ++--
 4 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 508bbc50fe8b..1a6f24baf33b 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -2912,13 +2912,13 @@ static noinline int __push_leaf_right(struct btrfs_path *path,
 	copy_leaf_data(right, left, BTRFS_LEAF_DATA_SIZE(fs_info) - push_space,
 		       leaf_data_end(left), push_space);
 
-	memmove_extent_buffer(right, btrfs_item_nr_offset(push_items),
-			      btrfs_item_nr_offset(0),
+	memmove_extent_buffer(right, btrfs_item_nr_offset(right, push_items),
+			      btrfs_item_nr_offset(right, 0),
 			      right_nritems * sizeof(struct btrfs_item));
 
 	/* copy the items from left to right */
-	copy_extent_buffer(right, left, btrfs_item_nr_offset(0),
-		   btrfs_item_nr_offset(left_nritems - push_items),
+	copy_extent_buffer(right, left, btrfs_item_nr_offset(right, 0),
+		   btrfs_item_nr_offset(left, left_nritems - push_items),
 		   push_items * sizeof(struct btrfs_item));
 
 	/* update the item pointers */
@@ -3112,8 +3112,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,
 
 	/* push data from right to left */
 	copy_extent_buffer(left, right,
-			   btrfs_item_nr_offset(btrfs_header_nritems(left)),
-			   btrfs_item_nr_offset(0),
+			   btrfs_item_nr_offset(left, btrfs_header_nritems(left)),
+			   btrfs_item_nr_offset(right, 0),
 			   push_items * sizeof(struct btrfs_item));
 
 	push_space = BTRFS_LEAF_DATA_SIZE(fs_info) -
@@ -3147,8 +3147,8 @@ static noinline int __push_leaf_left(struct btrfs_path *path, int data_size,
 				  BTRFS_LEAF_DATA_SIZE(fs_info) - push_space,
 				  leaf_data_end(right), push_space);
 
-		memmove_extent_buffer(right, btrfs_item_nr_offset(0),
-			      btrfs_item_nr_offset(push_items),
+		memmove_extent_buffer(right, btrfs_item_nr_offset(right, 0),
+			      btrfs_item_nr_offset(right, push_items),
 			     (btrfs_header_nritems(right) - push_items) *
 			     sizeof(struct btrfs_item));
 	}
@@ -3282,8 +3282,8 @@ static noinline void copy_for_split(struct btrfs_trans_handle *trans,
 	btrfs_set_header_nritems(right, nritems);
 	data_copy_size = btrfs_item_data_end(l, mid) - leaf_data_end(l);
 
-	copy_extent_buffer(right, l, btrfs_item_nr_offset(0),
-			   btrfs_item_nr_offset(mid),
+	copy_extent_buffer(right, l, btrfs_item_nr_offset(right, 0),
+			   btrfs_item_nr_offset(l, mid),
 			   nritems * sizeof(struct btrfs_item));
 
 	copy_leaf_data(right, l, BTRFS_LEAF_DATA_SIZE(fs_info) - data_copy_size,
@@ -3657,8 +3657,8 @@ static noinline int split_item(struct btrfs_path *path,
 	nritems = btrfs_header_nritems(leaf);
 	if (slot != nritems) {
 		/* shift the items */
-		memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + 1),
-				btrfs_item_nr_offset(slot),
+		memmove_extent_buffer(leaf, btrfs_item_nr_offset(leaf, slot + 1),
+				btrfs_item_nr_offset(leaf, slot),
 				(nritems - slot) * sizeof(struct btrfs_item));
 	}
 
@@ -3946,9 +3946,10 @@ static void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *p
 						       ioff - batch->total_data_size);
 		}
 		/* shift the items */
-		memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot + batch->nr),
-			      btrfs_item_nr_offset(slot),
-			      (nritems - slot) * sizeof(struct btrfs_item));
+		memmove_extent_buffer(leaf,
+				      btrfs_item_nr_offset(leaf, slot + batch->nr),
+				      btrfs_item_nr_offset(leaf, slot),
+				      (nritems - slot) * sizeof(struct btrfs_item));
 
 		/* shift the data */
 		memmove_leaf_data(leaf, data_end - batch->total_data_size,
@@ -4198,8 +4199,8 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 			btrfs_set_token_item_offset(&token, i, ioff + dsize);
 		}
 
-		memmove_extent_buffer(leaf, btrfs_item_nr_offset(slot),
-			      btrfs_item_nr_offset(slot + nr),
+		memmove_extent_buffer(leaf, btrfs_item_nr_offset(leaf, slot),
+			      btrfs_item_nr_offset(leaf, slot + nr),
 			      sizeof(struct btrfs_item) *
 			      (nritems - slot - nr));
 	}
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 53a8e200c953..0551bd500ce0 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -2016,38 +2016,40 @@ BTRFS_SETGET_FUNCS(raw_item_size, struct btrfs_item, size, 32);
 BTRFS_SETGET_STACK_FUNCS(stack_item_offset, struct btrfs_item, offset, 32);
 BTRFS_SETGET_STACK_FUNCS(stack_item_size, struct btrfs_item, size, 32);
 
-static inline unsigned long btrfs_item_nr_offset(int nr)
+static inline unsigned long btrfs_item_nr_offset(const struct extent_buffer *eb,
+						 int nr)
 {
 	return offsetof(struct btrfs_leaf, items) +
 		sizeof(struct btrfs_item) * nr;
 }
 
-static inline struct btrfs_item *btrfs_item_nr(int nr)
+static inline struct btrfs_item *btrfs_item_nr(const struct extent_buffer *eb,
+					       int nr)
 {
-	return (struct btrfs_item *)btrfs_item_nr_offset(nr);
+	return (struct btrfs_item *)btrfs_item_nr_offset(eb, nr);
 }
 
 #define BTRFS_ITEM_SETGET_FUNCS(member)						\
 static inline u32 btrfs_item_##member(const struct extent_buffer *eb,		\
 				      int slot)					\
 {										\
-	return btrfs_raw_item_##member(eb, btrfs_item_nr(slot));		\
+	return btrfs_raw_item_##member(eb, btrfs_item_nr(eb, slot));		\
 }										\
 static inline void btrfs_set_item_##member(const struct extent_buffer *eb,	\
 					   int slot, u32 val)			\
 {										\
-	btrfs_set_raw_item_##member(eb, btrfs_item_nr(slot), val);		\
+	btrfs_set_raw_item_##member(eb, btrfs_item_nr(eb, slot), val);		\
 }										\
 static inline u32 btrfs_token_item_##member(struct btrfs_map_token *token,	\
 					    int slot)				\
 {										\
-	struct btrfs_item *item = btrfs_item_nr(slot);				\
+	struct btrfs_item *item = btrfs_item_nr(token->eb, slot);		\
 	return btrfs_token_raw_item_##member(token, item);			\
 }										\
 static inline void btrfs_set_token_item_##member(struct btrfs_map_token *token,	\
 						 int slot, u32 val)		\
 {										\
-	struct btrfs_item *item = btrfs_item_nr(slot);				\
+	struct btrfs_item *item = btrfs_item_nr(token->eb, slot);		\
 	btrfs_set_token_raw_item_##member(token, item, val);			\
 }
 
@@ -2062,14 +2064,14 @@ static inline u32 btrfs_item_data_end(const struct extent_buffer *eb, int nr)
 static inline void btrfs_item_key(const struct extent_buffer *eb,
 			   struct btrfs_disk_key *disk_key, int nr)
 {
-	struct btrfs_item *item = btrfs_item_nr(nr);
+	struct btrfs_item *item = btrfs_item_nr(eb, nr);
 	read_eb_member(eb, item, struct btrfs_item, key, disk_key);
 }
 
 static inline void btrfs_set_item_key(struct extent_buffer *eb,
 			       struct btrfs_disk_key *disk_key, int nr)
 {
-	struct btrfs_item *item = btrfs_item_nr(nr);
+	struct btrfs_item *item = btrfs_item_nr(eb, nr);
 	write_eb_member(eb, item, struct btrfs_item, key, disk_key);
 }
 
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 86a0dd3b55b0..951b2e0e0df1 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -4507,7 +4507,7 @@ static void prepare_eb_write(struct extent_buffer *eb)
 		 * Leaf:
 		 * header 0 1 2 .. N ... data_N .. data_2 data_1 data_0
 		 */
-		start = btrfs_item_nr_offset(nritems);
+		start = btrfs_item_nr_offset(eb, nritems);
 		end = BTRFS_LEAF_DATA_OFFSET(eb) + leaf_data_end(eb);
 		memzero_extent_buffer(eb, start, end - start);
 	}
diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index e56c0107eea3..f0aabda9fd94 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -1759,10 +1759,10 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data)
 
 		/* Also check if the item pointer overlaps with btrfs item. */
 		if (unlikely(btrfs_item_ptr_offset(leaf, slot) <
-			     btrfs_item_nr_offset(slot) + sizeof(struct btrfs_item))) {
+			     btrfs_item_nr_offset(leaf, slot) + sizeof(struct btrfs_item))) {
 			generic_err(leaf, slot,
 		"slot overlaps with its data, item end %lu data start %lu",
-				btrfs_item_nr_offset(slot) +
+				btrfs_item_nr_offset(leaf, slot) +
 				sizeof(struct btrfs_item),
 				btrfs_item_ptr_offset(leaf, slot));
 			return -EUCLEAN;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 07/12] btrfs: add snapshot_id to the btrfs_header and related defs
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (5 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 06/12] btrfs: pass eb to the item_nr_offset helper Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 08/12] btrfs: move the header SETGET funcs Josef Bacik
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This adds the snapshot_id field to the btrfs_header, the HEADER_FLAG
that we're going to use to indicate that we have the larger header, as
well as the set/get helpers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h                | 19 +++++++++++++++++++
 include/uapi/linux/btrfs_tree.h |  1 +
 2 files changed, 20 insertions(+)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 0551bd500ce0..7261c5c8f672 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -179,6 +179,11 @@ struct btrfs_header {
 	u8 level;
 } __attribute__ ((__packed__));
 
+struct btrfs_header_v2 {
+	struct btrfs_header header_v1;
+	__le64 snapshot_id;
+} __attribute__ ((__packed__));
+
 /*
  * this is a very generous portion of the super block, giving us
  * room to translate 14 chunks with 3 stripes each.
@@ -373,6 +378,11 @@ struct btrfs_leaf {
 	struct btrfs_item items[];
 } __attribute__ ((__packed__));
 
+struct btrfs_leaf_v2 {
+	struct btrfs_header_v2 header;
+	struct btrfs_item items[];
+} __attribute__ ((__packed__));
+
 /*
  * all non-leaf blocks are nodes, they hold only keys and pointers to
  * other blocks
@@ -388,6 +398,11 @@ struct btrfs_node {
 	struct btrfs_key_ptr ptrs[];
 } __attribute__ ((__packed__));
 
+struct btrfs_node_v2 {
+	struct btrfs_header_v2 header;
+	struct btrfs_key_ptr ptrs[];
+} __attribute__ ((__packed__));
+
 /* Read ahead values for struct btrfs_path.reada */
 enum {
 	READA_NONE,
@@ -2235,12 +2250,16 @@ BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
 BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
 BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
+BTRFS_SETGET_HEADER_FUNCS(header_snapshot_id, struct btrfs_header_v2,
+			  snapshot_id, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
 			 generation, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
 BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header,
 			 nritems, 32);
 BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_snapshot_id, struct btrfs_header_v2,
+			 snapshot_id, 64);
 
 static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
 {
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h
index 4a363289c90e..92760ea4b448 100644
--- a/include/uapi/linux/btrfs_tree.h
+++ b/include/uapi/linux/btrfs_tree.h
@@ -496,6 +496,7 @@ struct btrfs_free_space_header {
 
 #define BTRFS_HEADER_FLAG_WRITTEN	(1ULL << 0)
 #define BTRFS_HEADER_FLAG_RELOC		(1ULL << 1)
+#define BTRFS_HEADER_FLAG_V2		(1ULL << 2)
 
 /* Super block flags */
 /* Errors detected */
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 08/12] btrfs: move the header SETGET funcs
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (6 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 07/12] btrfs: add snapshot_id to the btrfs_header and related defs Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 09/12] btrfs: move the super " Josef Bacik
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

These need to be above the item/key_ptr functions so we can read the
header flags to determine which version of the header we have.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h | 103 +++++++++++++++++++++++------------------------
 1 file changed, 51 insertions(+), 52 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 7261c5c8f672..57b68115fa1e 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1718,6 +1718,57 @@ static inline void btrfs_set_##name(type *s, u##bits val)		\
 	put_unaligned_le##bits(val, &s->member);			\
 }
 
+/* struct btrfs_header */
+BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
+BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
+			  generation, 64);
+BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
+BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
+BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
+BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
+BTRFS_SETGET_HEADER_FUNCS(header_snapshot_id, struct btrfs_header_v2,
+			  snapshot_id, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
+			 generation, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header,
+			 nritems, 32);
+BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
+BTRFS_SETGET_STACK_FUNCS(stack_header_snapshot_id, struct btrfs_header_v2,
+			 snapshot_id, 64);
+
+static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
+{
+	return (btrfs_header_flags(eb) & flag) == flag;
+}
+
+static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
+{
+	u64 flags = btrfs_header_flags(eb);
+	btrfs_set_header_flags(eb, flags | flag);
+}
+
+static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
+{
+	u64 flags = btrfs_header_flags(eb);
+	btrfs_set_header_flags(eb, flags & ~flag);
+}
+
+static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
+{
+	u64 flags = btrfs_header_flags(eb);
+	return flags >> BTRFS_BACKREF_REV_SHIFT;
+}
+
+static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
+						int rev)
+{
+	u64 flags = btrfs_header_flags(eb);
+	flags &= ~BTRFS_BACKREF_REV_MASK;
+	flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
+	btrfs_set_header_flags(eb, flags);
+}
+
 static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
 					   struct btrfs_dev_item *s)
 {
@@ -1736,7 +1787,6 @@ static inline void btrfs_set_device_total_bytes(const struct extent_buffer *eb,
 	btrfs_set_64(eb, s, offsetof(struct btrfs_dev_item, total_bytes), val);
 }
 
-
 BTRFS_SETGET_FUNCS(device_type, struct btrfs_dev_item, type, 64);
 BTRFS_SETGET_FUNCS(device_bytes_used, struct btrfs_dev_item, bytes_used, 64);
 BTRFS_SETGET_FUNCS(device_io_align, struct btrfs_dev_item, io_align, 32);
@@ -2242,57 +2292,6 @@ static inline void btrfs_dir_item_key_to_cpu(const struct extent_buffer *eb,
 
 #endif
 
-/* struct btrfs_header */
-BTRFS_SETGET_HEADER_FUNCS(header_bytenr, struct btrfs_header, bytenr, 64);
-BTRFS_SETGET_HEADER_FUNCS(header_generation, struct btrfs_header,
-			  generation, 64);
-BTRFS_SETGET_HEADER_FUNCS(header_owner, struct btrfs_header, owner, 64);
-BTRFS_SETGET_HEADER_FUNCS(header_nritems, struct btrfs_header, nritems, 32);
-BTRFS_SETGET_HEADER_FUNCS(header_flags, struct btrfs_header, flags, 64);
-BTRFS_SETGET_HEADER_FUNCS(header_level, struct btrfs_header, level, 8);
-BTRFS_SETGET_HEADER_FUNCS(header_snapshot_id, struct btrfs_header_v2,
-			  snapshot_id, 64);
-BTRFS_SETGET_STACK_FUNCS(stack_header_generation, struct btrfs_header,
-			 generation, 64);
-BTRFS_SETGET_STACK_FUNCS(stack_header_owner, struct btrfs_header, owner, 64);
-BTRFS_SETGET_STACK_FUNCS(stack_header_nritems, struct btrfs_header,
-			 nritems, 32);
-BTRFS_SETGET_STACK_FUNCS(stack_header_bytenr, struct btrfs_header, bytenr, 64);
-BTRFS_SETGET_STACK_FUNCS(stack_header_snapshot_id, struct btrfs_header_v2,
-			 snapshot_id, 64);
-
-static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
-{
-	return (btrfs_header_flags(eb) & flag) == flag;
-}
-
-static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
-{
-	u64 flags = btrfs_header_flags(eb);
-	btrfs_set_header_flags(eb, flags | flag);
-}
-
-static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
-{
-	u64 flags = btrfs_header_flags(eb);
-	btrfs_set_header_flags(eb, flags & ~flag);
-}
-
-static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
-{
-	u64 flags = btrfs_header_flags(eb);
-	return flags >> BTRFS_BACKREF_REV_SHIFT;
-}
-
-static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
-						int rev)
-{
-	u64 flags = btrfs_header_flags(eb);
-	flags &= ~BTRFS_BACKREF_REV_MASK;
-	flags |= (u64)rev << BTRFS_BACKREF_REV_SHIFT;
-	btrfs_set_header_flags(eb, flags);
-}
-
 static inline int btrfs_is_leaf(const struct extent_buffer *eb)
 {
 	return btrfs_header_level(eb) == 0;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 09/12] btrfs: move the super SETGET funcs
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (7 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 08/12] btrfs: move the header SETGET funcs Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 10/12] btrfs: move BTRFS_LEAF related definitions below " Josef Bacik
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Some of the helpers are going to need to check fs_incompat flags, so we
need these helpers to be higher up in ctree.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h | 158 +++++++++++++++++++++++------------------------
 1 file changed, 79 insertions(+), 79 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 57b68115fa1e..f20ce33e5c68 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1769,6 +1769,85 @@ static inline void btrfs_set_header_backref_rev(struct extent_buffer *eb,
 	btrfs_set_header_flags(eb, flags);
 }
 
+/* struct btrfs_super_block */
+BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
+BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
+BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
+			 generation, 64);
+BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
+BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
+			 struct btrfs_super_block, sys_chunk_array_size, 32);
+BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
+			 struct btrfs_super_block, chunk_root_generation, 64);
+BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
+			 root_level, 8);
+BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
+			 chunk_root, 64);
+BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
+			 chunk_root_level, 8);
+BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
+			 log_root, 64);
+BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
+			 log_root_transid, 64);
+BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
+			 log_root_level, 8);
+BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
+			 total_bytes, 64);
+BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
+			 bytes_used, 64);
+BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
+			 sectorsize, 32);
+BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
+			 nodesize, 32);
+BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
+			 stripesize, 32);
+BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
+			 root_dir_objectid, 64);
+BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
+			 num_devices, 64);
+BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
+			 compat_flags, 64);
+BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
+			 compat_ro_flags, 64);
+BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
+			 incompat_flags, 64);
+BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
+			 csum_type, 16);
+BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
+			 cache_generation, 64);
+BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
+BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
+			 uuid_tree_generation, 64);
+BTRFS_SETGET_STACK_FUNCS(super_block_group_root, struct btrfs_super_block,
+			 block_group_root, 64);
+BTRFS_SETGET_STACK_FUNCS(super_block_group_root_generation,
+			 struct btrfs_super_block,
+			 block_group_root_generation, 64);
+BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level, struct btrfs_super_block,
+			 block_group_root_level, 8);
+BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block,
+			 nr_global_roots, 64);
+
+#define btrfs_fs_incompat(fs_info, opt) \
+	__btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##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);
+}
+
+#define btrfs_fs_compat_ro(fs_info, opt) \
+	__btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
+
+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 u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
 					   struct btrfs_dev_item *s)
 {
@@ -2489,65 +2568,6 @@ btrfs_cpu_balance_args_to_disk(struct btrfs_disk_balance_args *disk,
 	disk->stripes_max = cpu_to_le32(cpu->stripes_max);
 }
 
-/* struct btrfs_super_block */
-BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
-BTRFS_SETGET_STACK_FUNCS(super_flags, struct btrfs_super_block, flags, 64);
-BTRFS_SETGET_STACK_FUNCS(super_generation, struct btrfs_super_block,
-			 generation, 64);
-BTRFS_SETGET_STACK_FUNCS(super_root, struct btrfs_super_block, root, 64);
-BTRFS_SETGET_STACK_FUNCS(super_sys_array_size,
-			 struct btrfs_super_block, sys_chunk_array_size, 32);
-BTRFS_SETGET_STACK_FUNCS(super_chunk_root_generation,
-			 struct btrfs_super_block, chunk_root_generation, 64);
-BTRFS_SETGET_STACK_FUNCS(super_root_level, struct btrfs_super_block,
-			 root_level, 8);
-BTRFS_SETGET_STACK_FUNCS(super_chunk_root, struct btrfs_super_block,
-			 chunk_root, 64);
-BTRFS_SETGET_STACK_FUNCS(super_chunk_root_level, struct btrfs_super_block,
-			 chunk_root_level, 8);
-BTRFS_SETGET_STACK_FUNCS(super_log_root, struct btrfs_super_block,
-			 log_root, 64);
-BTRFS_SETGET_STACK_FUNCS(super_log_root_transid, struct btrfs_super_block,
-			 log_root_transid, 64);
-BTRFS_SETGET_STACK_FUNCS(super_log_root_level, struct btrfs_super_block,
-			 log_root_level, 8);
-BTRFS_SETGET_STACK_FUNCS(super_total_bytes, struct btrfs_super_block,
-			 total_bytes, 64);
-BTRFS_SETGET_STACK_FUNCS(super_bytes_used, struct btrfs_super_block,
-			 bytes_used, 64);
-BTRFS_SETGET_STACK_FUNCS(super_sectorsize, struct btrfs_super_block,
-			 sectorsize, 32);
-BTRFS_SETGET_STACK_FUNCS(super_nodesize, struct btrfs_super_block,
-			 nodesize, 32);
-BTRFS_SETGET_STACK_FUNCS(super_stripesize, struct btrfs_super_block,
-			 stripesize, 32);
-BTRFS_SETGET_STACK_FUNCS(super_root_dir, struct btrfs_super_block,
-			 root_dir_objectid, 64);
-BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block,
-			 num_devices, 64);
-BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block,
-			 compat_flags, 64);
-BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block,
-			 compat_ro_flags, 64);
-BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block,
-			 incompat_flags, 64);
-BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block,
-			 csum_type, 16);
-BTRFS_SETGET_STACK_FUNCS(super_cache_generation, struct btrfs_super_block,
-			 cache_generation, 64);
-BTRFS_SETGET_STACK_FUNCS(super_magic, struct btrfs_super_block, magic, 64);
-BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block,
-			 uuid_tree_generation, 64);
-BTRFS_SETGET_STACK_FUNCS(super_block_group_root, struct btrfs_super_block,
-			 block_group_root, 64);
-BTRFS_SETGET_STACK_FUNCS(super_block_group_root_generation,
-			 struct btrfs_super_block,
-			 block_group_root_generation, 64);
-BTRFS_SETGET_STACK_FUNCS(super_block_group_root_level, struct btrfs_super_block,
-			 block_group_root_level, 8);
-BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block,
-			 nr_global_roots, 64);
-
 int btrfs_super_csum_size(const struct btrfs_super_block *s);
 const char *btrfs_super_csum_name(u16 csum_type);
 const char *btrfs_super_csum_driver(u16 csum_type);
@@ -3773,16 +3793,6 @@ static inline void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info,
 	}
 }
 
-#define btrfs_fs_incompat(fs_info, opt) \
-	__btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##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);
-}
-
 #define btrfs_set_fs_compat_ro(__fs_info, opt) \
 	__btrfs_set_fs_compat_ro((__fs_info), BTRFS_FEATURE_COMPAT_RO_##opt, \
 				 #opt)
@@ -3835,16 +3845,6 @@ static inline void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info,
 	}
 }
 
-#define btrfs_fs_compat_ro(fs_info, opt) \
-	__btrfs_fs_compat_ro((fs_info), BTRFS_FEATURE_COMPAT_RO_##opt)
-
-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);
-}
-
 /* acl.c */
 #ifdef CONFIG_BTRFS_FS_POSIX_ACL
 struct posix_acl *btrfs_get_acl(struct inode *inode, int type, bool rcu);
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 10/12] btrfs: move BTRFS_LEAF related definitions below super SETGET funcs
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (8 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 09/12] btrfs: move the super " Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 11/12] btrfs: const-ify fs_info for the compat flag handlers Josef Bacik
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We're going to need to do btrfs_fs_incompat(fs_info, EXTENT_TREE_V2),
which requires reading the super flags, so move these helpers below the
super SETGET funcs.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h | 69 ++++++++++++++++++++++++------------------------
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index f20ce33e5c68..8187e8ec457a 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1430,41 +1430,6 @@ struct btrfs_file_private {
 	void *filldir_buf;
 };
 
-
-static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
-{
-
-	return info->nodesize - sizeof(struct btrfs_header);
-}
-
-static inline unsigned long BTRFS_LEAF_DATA_OFFSET(const struct extent_buffer *leaf)
-{
-	return offsetof(struct btrfs_leaf, items);
-}
-
-static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info)
-{
-	return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item);
-}
-
-static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info)
-{
-	return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr);
-}
-
-#define BTRFS_FILE_EXTENT_INLINE_DATA_START		\
-		(offsetof(struct btrfs_file_extent_item, disk_bytenr))
-static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
-{
-	return BTRFS_MAX_ITEM_SIZE(info) -
-	       BTRFS_FILE_EXTENT_INLINE_DATA_START;
-}
-
-static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
-{
-	return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
-}
-
 /*
  * Flags for mount options.
  *
@@ -2219,6 +2184,40 @@ static inline void btrfs_set_item_key(struct extent_buffer *eb,
 	write_eb_member(eb, item, struct btrfs_item, key, disk_key);
 }
 
+static inline u32 BTRFS_LEAF_DATA_SIZE(const struct btrfs_fs_info *info)
+{
+
+	return info->nodesize - sizeof(struct btrfs_header);
+}
+
+static inline unsigned long BTRFS_LEAF_DATA_OFFSET(const struct extent_buffer *leaf)
+{
+	return offsetof(struct btrfs_leaf, items);
+}
+
+static inline u32 BTRFS_MAX_ITEM_SIZE(const struct btrfs_fs_info *info)
+{
+	return BTRFS_LEAF_DATA_SIZE(info) - sizeof(struct btrfs_item);
+}
+
+static inline u32 BTRFS_NODEPTRS_PER_BLOCK(const struct btrfs_fs_info *info)
+{
+	return BTRFS_LEAF_DATA_SIZE(info) / sizeof(struct btrfs_key_ptr);
+}
+
+#define BTRFS_FILE_EXTENT_INLINE_DATA_START		\
+		(offsetof(struct btrfs_file_extent_item, disk_bytenr))
+static inline u32 BTRFS_MAX_INLINE_DATA_SIZE(const struct btrfs_fs_info *info)
+{
+	return BTRFS_MAX_ITEM_SIZE(info) -
+	       BTRFS_FILE_EXTENT_INLINE_DATA_START;
+}
+
+static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
+{
+	return BTRFS_MAX_ITEM_SIZE(info) - sizeof(struct btrfs_dir_item);
+}
+
 BTRFS_SETGET_FUNCS(dir_log_end, struct btrfs_dir_log_item, end, 64);
 
 /*
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 11/12] btrfs: const-ify fs_info for the compat flag handlers
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (9 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 10/12] btrfs: move BTRFS_LEAF related definitions below " Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-07 22:33 ` [PATCH 12/12] btrfs: use _offset helpers instead of offsetof in generic_bin_search Josef Bacik
  2022-03-09 13:57 ` [PATCH 00/12] btrfs: item helper prep work for snapshot_id Nikolay Borisov
  12 siblings, 0 replies; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We don't modify fs_info here, use const.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 8187e8ec457a..ec77871ad839 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1796,7 +1796,7 @@ BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block,
 #define btrfs_fs_incompat(fs_info, opt) \
 	__btrfs_fs_incompat((fs_info), BTRFS_FEATURE_INCOMPAT_##opt)
 
-static inline bool __btrfs_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag)
+static inline bool __btrfs_fs_incompat(const struct btrfs_fs_info *fs_info, u64 flag)
 {
 	struct btrfs_super_block *disk_super;
 	disk_super = fs_info->super_copy;
@@ -1806,7 +1806,7 @@ static inline bool __btrfs_fs_incompat(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 int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)
+static inline int __btrfs_fs_compat_ro(const struct btrfs_fs_info *fs_info, u64 flag)
 {
 	struct btrfs_super_block *disk_super;
 	disk_super = fs_info->super_copy;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 12/12] btrfs: use _offset helpers instead of offsetof in generic_bin_search
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (10 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 11/12] btrfs: const-ify fs_info for the compat flag handlers Josef Bacik
@ 2022-03-07 22:33 ` Josef Bacik
  2022-03-09 13:51   ` Nikolay Borisov
  2022-03-09 13:57 ` [PATCH 00/12] btrfs: item helper prep work for snapshot_id Nikolay Borisov
  12 siblings, 1 reply; 19+ messages in thread
From: Josef Bacik @ 2022-03-07 22:33 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

The starting offset for the items/keys are going to be dependent on
extent tree v2, use the helpers instead of offsetof directly.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 1a6f24baf33b..6e8c02eec548 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -781,10 +781,10 @@ static noinline int generic_bin_search(struct extent_buffer *eb, int low,
 	}
 
 	if (btrfs_header_level(eb) == 0) {
-		p = offsetof(struct btrfs_leaf, items);
+		p = btrfs_item_nr_offset(eb, 0);
 		item_size = sizeof(struct btrfs_item);
 	} else {
-		p = offsetof(struct btrfs_node, ptrs);
+		p = btrfs_node_key_ptr_offset(eb, 0);
 		item_size = sizeof(struct btrfs_key_ptr);
 	}
 
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users
  2022-03-07 22:33 ` [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users Josef Bacik
@ 2022-03-09 13:48   ` Nikolay Borisov
  2022-03-09 13:48     ` Nikolay Borisov
  0 siblings, 1 reply; 19+ messages in thread
From: Nikolay Borisov @ 2022-03-09 13:48 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team



On 8.03.22 г. 0:33 ч., Josef Bacik wrote:
> All of the node helpers are getting the pointer offset and then casting
> to btrfs_key_ptr.  Instead do this with a helper similar to how we do it
> with items and change all the helpers to use the new helper.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

This patch is already included in the btrfs-progs: cleanup btrfs_item* 
accessors series as patch 12.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users
  2022-03-09 13:48   ` Nikolay Borisov
@ 2022-03-09 13:48     ` Nikolay Borisov
  0 siblings, 0 replies; 19+ messages in thread
From: Nikolay Borisov @ 2022-03-09 13:48 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team



On 9.03.22 г. 15:48 ч., Nikolay Borisov wrote:
> 
> 
> On 8.03.22 г. 0:33 ч., Josef Bacik wrote:
>> All of the node helpers are getting the pointer offset and then casting
>> to btrfs_key_ptr.  Instead do this with a helper similar to how we do it
>> with items and change all the helpers to use the new helper.
>>
>> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> 
> This patch is already included in the btrfs-progs: cleanup btrfs_item* 
> accessors series as patch 12.
> 

Ah, this is the kernel portion... disregard.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 12/12] btrfs: use _offset helpers instead of offsetof in generic_bin_search
  2022-03-07 22:33 ` [PATCH 12/12] btrfs: use _offset helpers instead of offsetof in generic_bin_search Josef Bacik
@ 2022-03-09 13:51   ` Nikolay Borisov
  0 siblings, 0 replies; 19+ messages in thread
From: Nikolay Borisov @ 2022-03-09 13:51 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team



On 8.03.22 г. 0:33 ч., Josef Bacik wrote:
> The starting offset for the items/keys are going to be dependent on
> extent tree v2, use the helpers instead of offsetof directly.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>   fs/btrfs/ctree.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
> index 1a6f24baf33b..6e8c02eec548 100644
> --- a/fs/btrfs/ctree.c
> +++ b/fs/btrfs/ctree.c
> @@ -781,10 +781,10 @@ static noinline int generic_bin_search(struct extent_buffer *eb, int low,
>   	}
>   
>   	if (btrfs_header_level(eb) == 0) {
> -		p = offsetof(struct btrfs_leaf, items);
> +		p = btrfs_item_nr_offset(eb, 0);

nit: This could be switched to BTRFS_LEAF_DATA_OFFSET.

>   		item_size = sizeof(struct btrfs_item);
>   	} else {
> -		p = offsetof(struct btrfs_node, ptrs);
> +		p = btrfs_node_key_ptr_offset(eb, 0);
>   		item_size = sizeof(struct btrfs_key_ptr);
>   	}
>   

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 06/12] btrfs: pass eb to the item_nr_offset helper
  2022-03-07 22:33 ` [PATCH 06/12] btrfs: pass eb to the item_nr_offset helper Josef Bacik
@ 2022-03-09 13:55   ` Nikolay Borisov
  0 siblings, 0 replies; 19+ messages in thread
From: Nikolay Borisov @ 2022-03-09 13:55 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team



On 8.03.22 г. 0:33 ч., Josef Bacik wrote:
> This helper needs to know what version of the fs we're looking at to
> return the proper offset into the leaf where the item starts, so pass in
> the eb so we can get the proper offset.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Perhaps a patch can be included before this one which converts asll 
btrfs_item_nr_offset(, 0) into calls to BTRFS_LEAF_DATA_OFFSET as there 
seem to be a couple of those.

<snip>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] btrfs: item helper prep work for snapshot_id
  2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
                   ` (11 preceding siblings ...)
  2022-03-07 22:33 ` [PATCH 12/12] btrfs: use _offset helpers instead of offsetof in generic_bin_search Josef Bacik
@ 2022-03-09 13:57 ` Nikolay Borisov
  2022-03-14 17:12   ` Sweet Tea Dorminy
  12 siblings, 1 reply; 19+ messages in thread
From: Nikolay Borisov @ 2022-03-09 13:57 UTC (permalink / raw)
  To: Josef Bacik, linux-btrfs, kernel-team



On 8.03.22 г. 0:33 ч., Josef Bacik wrote:
> Hello,
> 
> I sent a bunch of patches previously to rework a lot of our helpers in
> preparation of adding the snapshot_id to the btrfs_header.  I missed a few
> important areas with those patches, so here's the remaining work to make it
> easier to expand the size of the btrfs_header.  These are general fixups and
> cleanups that don't rely on the extent tree v2 work.  Thanks,
> 
> Josef
> 
> Josef Bacik (12):
>    btrfs: move btrfs_node_key into ctree.h
>    btrfs: add a btrfs_node_key_ptr helper, convert the users
>    btrfs: introduce *_leaf_data helpers
>    btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg
>    btrfs: pass eb to the node_key_ptr helpers
>    btrfs: pass eb to the item_nr_offset helper
>    btrfs: add snapshot_id to the btrfs_header and related defs
>    btrfs: move the header SETGET funcs
>    btrfs: move the super SETGET funcs
>    btrfs: move BTRFS_LEAF related definitions below super SETGET funcs
>    btrfs: const-ify fs_info for the compat flag handlers
>    btrfs: use _offset helpers instead of offsetof in generic_bin_search
> 
>   fs/btrfs/ctree.c                | 151 ++++++------
>   fs/btrfs/ctree.h                | 411 +++++++++++++++++---------------
>   fs/btrfs/extent_io.c            |   6 +-
>   fs/btrfs/struct-funcs.c         |   8 -
>   fs/btrfs/tree-checker.c         |   4 +-
>   fs/btrfs/tree-mod-log.c         |   4 +-
>   include/uapi/linux/btrfs_tree.h |   1 +
>   7 files changed, 303 insertions(+), 282 deletions(-)
> 

Overall LGTM:

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 00/12] btrfs: item helper prep work for snapshot_id
  2022-03-09 13:57 ` [PATCH 00/12] btrfs: item helper prep work for snapshot_id Nikolay Borisov
@ 2022-03-14 17:12   ` Sweet Tea Dorminy
  0 siblings, 0 replies; 19+ messages in thread
From: Sweet Tea Dorminy @ 2022-03-14 17:12 UTC (permalink / raw)
  To: Nikolay Borisov, Josef Bacik, linux-btrfs, kernel-team


On 3/9/22 08:57, Nikolay Borisov wrote:
>
>
> On 8.03.22 г. 0:33 ч., Josef Bacik wrote:
>> Hello,
>>
>> I sent a bunch of patches previously to rework a lot of our helpers in
>> preparation of adding the snapshot_id to the btrfs_header.  I missed 
>> a few
>> important areas with those patches, so here's the remaining work to 
>> make it
>> easier to expand the size of the btrfs_header.  These are general 
>> fixups and
>> cleanups that don't rely on the extent tree v2 work.  Thanks,
>>
>> Josef
>>
>> Josef Bacik (12):
>>    btrfs: move btrfs_node_key into ctree.h
>>    btrfs: add a btrfs_node_key_ptr helper, convert the users
>>    btrfs: introduce *_leaf_data helpers
>>    btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg
>>    btrfs: pass eb to the node_key_ptr helpers
>>    btrfs: pass eb to the item_nr_offset helper
>>    btrfs: add snapshot_id to the btrfs_header and related defs
>>    btrfs: move the header SETGET funcs
>>    btrfs: move the super SETGET funcs
>>    btrfs: move BTRFS_LEAF related definitions below super SETGET funcs
>>    btrfs: const-ify fs_info for the compat flag handlers
>>    btrfs: use _offset helpers instead of offsetof in generic_bin_search
>>
>>   fs/btrfs/ctree.c                | 151 ++++++------
>>   fs/btrfs/ctree.h                | 411 +++++++++++++++++---------------
>>   fs/btrfs/extent_io.c            |   6 +-
>>   fs/btrfs/struct-funcs.c         |   8 -
>>   fs/btrfs/tree-checker.c         |   4 +-
>>   fs/btrfs/tree-mod-log.c         |   4 +-
>>   include/uapi/linux/btrfs_tree.h |   1 +
>>   7 files changed, 303 insertions(+), 282 deletions(-)
>>
>
> Overall LGTM:
>
> Reviewed-by: Nikolay Borisov <nborisov@suse.com>
Also Reviewed-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me>, for 
what it's worth.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2022-03-14 17:13 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-07 22:33 [PATCH 00/12] btrfs: item helper prep work for snapshot_id Josef Bacik
2022-03-07 22:33 ` [PATCH 01/12] btrfs: move btrfs_node_key into ctree.h Josef Bacik
2022-03-07 22:33 ` [PATCH 02/12] btrfs: add a btrfs_node_key_ptr helper, convert the users Josef Bacik
2022-03-09 13:48   ` Nikolay Borisov
2022-03-09 13:48     ` Nikolay Borisov
2022-03-07 22:33 ` [PATCH 03/12] btrfs: introduce *_leaf_data helpers Josef Bacik
2022-03-07 22:33 ` [PATCH 04/12] btrfs: make BTRFS_LEAF_DATA_OFFSET take an eb arg Josef Bacik
2022-03-07 22:33 ` [PATCH 05/12] btrfs: pass eb to the node_key_ptr helpers Josef Bacik
2022-03-07 22:33 ` [PATCH 06/12] btrfs: pass eb to the item_nr_offset helper Josef Bacik
2022-03-09 13:55   ` Nikolay Borisov
2022-03-07 22:33 ` [PATCH 07/12] btrfs: add snapshot_id to the btrfs_header and related defs Josef Bacik
2022-03-07 22:33 ` [PATCH 08/12] btrfs: move the header SETGET funcs Josef Bacik
2022-03-07 22:33 ` [PATCH 09/12] btrfs: move the super " Josef Bacik
2022-03-07 22:33 ` [PATCH 10/12] btrfs: move BTRFS_LEAF related definitions below " Josef Bacik
2022-03-07 22:33 ` [PATCH 11/12] btrfs: const-ify fs_info for the compat flag handlers Josef Bacik
2022-03-07 22:33 ` [PATCH 12/12] btrfs: use _offset helpers instead of offsetof in generic_bin_search Josef Bacik
2022-03-09 13:51   ` Nikolay Borisov
2022-03-09 13:57 ` [PATCH 00/12] btrfs: item helper prep work for snapshot_id Nikolay Borisov
2022-03-14 17:12   ` Sweet Tea Dorminy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox