btrfs: move leaf_data_end into ctree.c
authorJosef Bacik <josef@toxicpanda.com>
Tue, 15 Nov 2022 16:16:11 +0000 (11:16 -0500)
committerDavid Sterba <dsterba@suse.com>
Mon, 5 Dec 2022 17:00:58 +0000 (18:00 +0100)
This is only used in ctree.c, with the exception of zero'ing out extent
buffers we're getting ready to write out.  In theory we shouldn't have
an extent buffer with 0 items that we're writing out, however I'd rather
be safe than sorry so open code it in extent_io.c, and then copy the
helper into ctree.c.  This will make it easier to sync accessors.[ch]
into btrfs-progs, as this requires a helper that isn't defined in
accessors.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/accessors.h
fs/btrfs/ctree.c
fs/btrfs/extent_io.c

index 57ba6894a5f4c5d86bc5a15fbabe798a95b18970..b9d9a69685df7ef01364933f8521124e7a14aeca 100644 (file)
@@ -897,19 +897,6 @@ const char *btrfs_super_csum_name(u16 csum_type);
 const char *btrfs_super_csum_driver(u16 csum_type);
 size_t __attribute_const__ btrfs_get_num_csums(void);
 
-/*
- * The leaf data grows from end-to-front in the node.  this returns the address
- * of the start of the last item, which is the stop of the leaf data stack.
- */
-static inline unsigned int leaf_data_end(const struct extent_buffer *leaf)
-{
-       u32 nr = btrfs_header_nritems(leaf);
-
-       if (nr == 0)
-               return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
-       return btrfs_item_offset(leaf, nr - 1);
-}
-
 /* struct btrfs_file_extent_item */
 BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item,
                         type, 8);
index f75e398d7b712e17df74980667aaea7f0c7bfa37..dc38c24a0ffaeaffbbd603db9d508bb0303dc13b 100644 (file)
@@ -51,6 +51,19 @@ static const struct btrfs_csums {
                                     .driver = "blake2b-256" },
 };
 
+/*
+ * The leaf data grows from end-to-front in the node.  this returns the address
+ * of the start of the last item, which is the stop of the leaf data stack.
+ */
+static unsigned int leaf_data_end(const struct extent_buffer *leaf)
+{
+       u32 nr = btrfs_header_nritems(leaf);
+
+       if (nr == 0)
+               return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
+       return btrfs_item_offset(leaf, nr - 1);
+}
+
 int btrfs_super_csum_size(const struct btrfs_super_block *s)
 {
        u16 t = btrfs_super_csum_type(s);
index 8528e7d3f38fed76ddd11e4bbffaa75f89d2a6c3..9fc9f806806926becf7025b4d1527b83c3b49753 100644 (file)
@@ -2537,7 +2537,11 @@ 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;
+               if (nritems == 0)
+                       end += BTRFS_LEAF_DATA_SIZE(eb->fs_info);
+               else
+                       end += btrfs_item_offset(eb, nritems - 1);
                memzero_extent_buffer(eb, start, end - start);
        }
 }