Skip to contentSkip to conversation

btrfs-progs: prep work for syncing ctree.c

PATCH In review Josef Bacik 2 participants 12 messages Apr 19, 2023 – May 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover btrfs-progs: prep work for syncing ctree.c

Hello,

These patches update a lot of the different ctree.c related helpers that have diverged from the kernel in order to make ite easier syncing ctree.c directly. This also syncs locking.[ch], but this is to just stub out the locking. This will make it easier to sync ctree.c as well since there's locking in the kernel that didn't exist when we had this in btrfs-progs.

This series depends on

btrfs-progs: prep work for syncing files into kernel-shared
btrfs-progs: sync basic code from the kernel

Thanks,

Josef

Josef Bacik (10):
btrfs-progs: const-ify the extent buffer helpers
btrfs-progs: bring root->state into btrfs-progs
btrfs-progs: rename btrfs_alloc_free_block to btrfs_alloc_tree_block
btrfs-progs: sync locking.h and stub out all the helpers
btrfs-progs: add btrfs_locking_nest to btrfs_alloc_tree_block
btrfs-progs: add some missing extent buffer helpers
btrfs-progs: rename btrfs_set_block_flags ->
btrfs_set_disk_extent_flags
btrfs-progs: cleanup args for btrfs_set_disk_extent_flags
btrfs-progs: rename clear_extent_buffer_dirty =>
btrfs_clear_buffer_dirty
btrfs-progs: make __btrfs_cow_block static

 Makefile                    |   1 +
 check/main.c                |   7 +-
 cmds/rescue-chunk-recover.c |   4 +-
 cmds/rescue.c               |   2 +-
 include/kerncompat.h        |   4 +
 kernel-shared/ctree.c       |  72 +++++-----
 kernel-shared/ctree.h       |  82 ++++++++++--
 kernel-shared/disk-io.c     |  33 +++--
 kernel-shared/extent-tree.c |  28 ++--
 kernel-shared/extent_io.c   |  28 ++--
 kernel-shared/extent_io.h   |  15 ++-
 kernel-shared/locking.c     |  22 +++
 kernel-shared/locking.h     | 258 ++++++++++++++++++++++++++++++++++++
 kernel-shared/transaction.c |   4 +-
 14 files changed, 464 insertions(+), 96 deletions(-)
 create mode 100644 kernel-shared/locking.c
 create mode 100644 kernel-shared/locking.h
Signature · 1 line
2.40.0
#5 lore raw

PATCH 5/10 btrfs-progs: add btrfs_locking_nest to btrfs_alloc_tree_block

This is how btrfs_alloc_tree_block is defined in the kernel, so when we go to sync this code in it'll be easier if we're already setup to accept this argument. Since we're in progs we don't care about nesting so just use BTRFS_NORMAL_NESTING everywhere, as we sync in the kernel code it'll get updated to whatever is appropriate.

---
 check/main.c                |  2 +-
 cmds/rescue-chunk-recover.c |  2 +-
 kernel-shared/ctree.c       | 18 ++++++++++++------
 kernel-shared/ctree.h       |  4 +++-
 kernel-shared/disk-io.c     |  3 ++-
 kernel-shared/extent-tree.c |  3 ++-
 6 files changed, 21 insertions(+), 11 deletions(-)
check/main.c +1 -1
index c5131b7a..09805511 100644
@@ -9098,7 +9098,7 @@ static struct extent_buffer *btrfs_fsck_clear_root(
 
 	c = btrfs_alloc_tree_block(trans, gfs_info->tree_root,
 				   gfs_info->nodesize, key->objectid,
-				   &disk_key, 0, 0, 0);
+				   &disk_key, 0, 0, 0, BTRFS_NESTING_NORMAL);
 	if (IS_ERR(c)) {
 		btrfs_free_path(path);
 		return c;
cmds/rescue-chunk-recover.c +1 -1
index b18d422e..52119d98 100644
@@ -1148,7 +1148,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans,
 
 	cow = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 				     BTRFS_CHUNK_TREE_OBJECTID,
-				     &disk_key, 0, 0, 0);
+				     &disk_key, 0, 0, 0, BTRFS_NESTING_NORMAL);
 	btrfs_set_header_bytenr(cow, cow->start);
 	btrfs_set_header_generation(cow, trans->transid);
 	btrfs_set_header_nritems(cow, 0);
kernel-shared/ctree.c +12 -6
index 230dae1b..cad15093 100644
@@ -169,7 +169,8 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 		btrfs_node_key(buf, &disk_key, 0);
 	cow = btrfs_alloc_tree_block(trans, new_root, buf->len,
 				     new_root_objectid, &disk_key,
-				     level, buf->start, 0);
+				     level, buf->start, 0,
+				     BTRFS_NESTING_NORMAL);
 	if (IS_ERR(cow)) {
 		kfree(new_root);
 		return PTR_ERR(cow);
@@ -231,7 +232,8 @@ int btrfs_create_root(struct btrfs_trans_handle *trans,
 	new_root->root_key.offset = 0;
 
 	node = btrfs_alloc_tree_block(trans, new_root, fs_info->nodesize,
-				      objectid, &disk_key, 0, 0, 0);
+				      objectid, &disk_key, 0, 0, 0,
+				      BTRFS_NESTING_NORMAL);
 	if (IS_ERR(node)) {
 		ret = PTR_ERR(node);
 		error("failed to create root node for tree %llu: %d (%m)",
@@ -463,7 +465,8 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 
 	cow = btrfs_alloc_tree_block(trans, root, buf->len,
 				     root->root_key.objectid, &disk_key,
-				     level, search_start, empty_size);
+				     level, search_start, empty_size,
+				     BTRFS_NESTING_NORMAL);
 	if (IS_ERR(cow))
 		return PTR_ERR(cow);
 
@@ -1734,7 +1737,8 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
 
 	c = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 				   root->root_key.objectid, &lower_key,
-				   level, root->node->start, 0);
+				   level, root->node->start, 0,
+				   BTRFS_NESTING_NORMAL);
 
 	if (IS_ERR(c))
 		return PTR_ERR(c);
@@ -1860,7 +1864,8 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
 
 	split = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 					root->root_key.objectid,
-					&disk_key, level, c->start, 0);
+					&disk_key, level, c->start, 0,
+					BTRFS_NESTING_NORMAL);
 	if (IS_ERR(split))
 		return PTR_ERR(split);
 
@@ -2427,7 +2432,8 @@ again:
 
 	right = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 					root->root_key.objectid,
-					&disk_key, 0, l->start, 0);
+					&disk_key, 0, l->start, 0,
+					BTRFS_NESTING_NORMAL);
 	if (IS_ERR(right)) {
 		BUG_ON(1);
 		return PTR_ERR(right);
kernel-shared/ctree.h +3 -1
index af60ba66..f416fc36 100644
@@ -29,6 +29,7 @@
 #include "kernel-shared/uapi/btrfs_tree.h"
 #include "accessors.h"
 #include "extent-io-tree.h"
+#include "locking.h"
 
 struct btrfs_root;
 struct btrfs_trans_handle;
@@ -853,7 +854,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
 					struct btrfs_root *root,
 					u32 blocksize, u64 root_objectid,
 					struct btrfs_disk_key *key, int level,
-					u64 hint, u64 empty_size);
+					u64 hint, u64 empty_size,
+					enum btrfs_lock_nesting nest);
 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
 			     struct btrfs_fs_info *fs_info, u64 bytenr,
 			     u64 offset, int metadata, u64 *refs, u64 *flags);
kernel-shared/disk-io.c +2 -1
index 6f9dc327..7ee45ad1 100644
@@ -2334,7 +2334,8 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
 	memcpy(&root->root_key, key, sizeof(struct btrfs_key));
 
 	leaf = btrfs_alloc_tree_block(trans, root, fs_info->nodesize,
-				      root->root_key.objectid, NULL, 0, 0, 0);
+				      root->root_key.objectid, NULL, 0, 0, 0,
+				      BTRFS_NESTING_NORMAL);
 	if (IS_ERR(leaf)) {
 		ret = PTR_ERR(leaf);
 		leaf = NULL;
kernel-shared/extent-tree.c +2 -1
index d0b3aee3..916eb840 100644
@@ -2559,7 +2559,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
 					struct btrfs_root *root,
 					u32 blocksize, u64 root_objectid,
 					struct btrfs_disk_key *key, int level,
-					u64 hint, u64 empty_size)
+					u64 hint, u64 empty_size,
+					enum btrfs_lock_nesting nest)
 {
 	struct btrfs_key ins;
 	int ret;
Signature · 1 line
2.40.0
#6 lore raw

PATCH 6/10 btrfs-progs: add some missing extent buffer helpers

In reply to Josef Bacik

The following are some extent buffer helpers we have in the kernel but not in btrfs-progs. Sync these in to make syncing ctree.c easier.

---
 kernel-shared/extent_io.c | 11 +++++++++++
 kernel-shared/extent_io.h |  3 +++
 2 files changed, 14 insertions(+)
kernel-shared/extent_io.c +11 -0
index 01dc5b1e..f740b3a6 100644
@@ -617,6 +617,12 @@ void copy_extent_buffer(const struct extent_buffer *dst,
 	memcpy((void *)dst->data + dst_offset, src->data + src_offset, len);
 }
 
+void copy_extent_buffer_full(const struct extent_buffer *dst,
+			     const struct extent_buffer *src)
+{
+	copy_extent_buffer(dst, src, 0, 0, src->len);
+}
+
 void memmove_extent_buffer(const struct extent_buffer *dst, unsigned long dst_offset,
 			   unsigned long src_offset, unsigned long len)
 {
@@ -634,3 +640,8 @@ int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start,
 {
 	return le_test_bit(nr, (u8 *)eb->data + start);
 }
+
+void write_extent_buffer_fsid(const struct extent_buffer *eb, const void *srcv)
+{
+	write_extent_buffer(eb, srcv, btrfs_header_fsid(), BTRFS_FSID_SIZE);
+}
kernel-shared/extent_io.h +3 -0
index 69133c3c..103f93cb 100644
@@ -114,6 +114,8 @@ void copy_extent_buffer(const struct extent_buffer *dst,
 			const struct extent_buffer *src,
 			unsigned long dst_offset, unsigned long src_offset,
 			unsigned long len);
+void copy_extent_buffer_full(const struct extent_buffer *dst,
+			     const struct extent_buffer *src);
 void memmove_extent_buffer(const struct extent_buffer *dst,
 			   const unsigned long dst_offset,
 			   unsigned long src_offset, unsigned long len);
@@ -133,5 +135,6 @@ void extent_buffer_bitmap_set(struct extent_buffer *eb, unsigned long start,
                               unsigned long pos, unsigned long len);
 void extent_buffer_init_cache(struct btrfs_fs_info *fs_info);
 void extent_buffer_free_cache(struct btrfs_fs_info *fs_info);
+void write_extent_buffer_fsid(const struct extent_buffer *eb, const void *srcv);
 
 #endif
Signature · 1 line
2.40.0
#8 lore raw

PATCH 8/10 btrfs-progs: cleanup args for btrfs_set_disk_extent_flags

In reply to Josef Bacik

In the kernel we just pass in the extent_buffer and get the fields we need from that to update the extent ref flags. Update this helper to match the kernel to make syncing ctree.c easier.

---
 kernel-shared/ctree.c       |  4 +---
 kernel-shared/ctree.h       |  4 ++--
 kernel-shared/extent-tree.c | 11 +++++++----
 3 files changed, 10 insertions(+), 9 deletions(-)
kernel-shared/ctree.c +1 -3
index e95dcc79..ea2a7af3 100644
@@ -419,9 +419,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
 			BUG_ON(ret);
 		}
 		if (new_flags != 0) {
-			ret = btrfs_set_disk_extent_flags(trans, buf->start,
-							  btrfs_header_level(buf),
-							  new_flags);
+			ret = btrfs_set_disk_extent_flags(trans, buf, new_flags);
 			BUG_ON(ret);
 		}
 	} else {
kernel-shared/ctree.h +2 -2
index aaace45e..069e000d 100644
@@ -859,8 +859,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
 			     struct btrfs_fs_info *fs_info, u64 bytenr,
 			     u64 offset, int metadata, u64 *refs, u64 *flags);
-int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr,
-				int level, u64 flags);
+int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
+				struct extent_buffer *eb, u64 flags);
 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		  struct extent_buffer *buf, int record_parent);
 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
kernel-shared/extent-tree.c +7 -4
index 8a6ab996..cfce4426 100644
@@ -1375,26 +1375,29 @@ out:
 	return ret;
 }
 
-int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr,
-				int level, u64 flags)
+int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
+				struct extent_buffer *eb, u64 flags)
 {
 	struct btrfs_fs_info *fs_info = trans->fs_info;
-	struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr);
+	struct btrfs_root *extent_root;
 	struct btrfs_path *path;
 	int ret;
 	struct btrfs_key key;
 	struct extent_buffer *l;
 	struct btrfs_extent_item *item;
 	u32 item_size;
+	u64 bytenr = eb->start;
 	int skinny_metadata = btrfs_fs_incompat(fs_info, SKINNY_METADATA);
 
 	path = btrfs_alloc_path();
 	if (!path)
 		return -ENOMEM;
 
+	extent_root = btrfs_extent_root(fs_info, bytenr);
+
 	key.objectid = bytenr;
 	if (skinny_metadata) {
-		key.offset = level;
+		key.offset = btrfs_header_level(eb);
 		key.type = BTRFS_METADATA_ITEM_KEY;
 	} else {
 		key.offset = fs_info->nodesize;
Signature · 1 line
2.40.0
#2 lore raw

PATCH 2/10 btrfs-progs: bring root->state into btrfs-progs

In reply to Josef Bacik

We changed from members in the root for all the different flags to a bit based flag system. In order to make syncing the kernel code into btrfs-progs easier go ahead and sync in the bits we use and update all the users of the old ->track_dirty and ->ref_cows to use the state bits.

---
 check/main.c                |  3 +-
 kernel-shared/ctree.c       | 22 ++++++++-----
 kernel-shared/ctree.h       | 66 +++++++++++++++++++++++++++++++++++--
 kernel-shared/disk-io.c     | 21 ++++++------
 kernel-shared/extent-tree.c | 10 +++---
 5 files changed, 94 insertions(+), 28 deletions(-)
check/main.c +2 -1
index 99ff3bc3..45e3442d 100644
@@ -63,6 +63,7 @@
 #include "check/qgroup-verify.h"
 #include "check/clear-cache.h"
 #include "kernel-shared/uapi/btrfs.h"
+#include "kernel-lib/bitops.h"
 
 /* Global context variables */
 struct btrfs_fs_info *gfs_info;
@@ -467,7 +468,7 @@ static void record_root_in_trans(struct btrfs_trans_handle *trans,
 				 struct btrfs_root *root)
 {
 	if (root->last_trans != trans->transid) {
-		root->track_dirty = 1;
+		set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
 		root->last_trans = trans->transid;
 		root->commit_root = root->node;
 		extent_buffer_get(root->node);
kernel-shared/ctree.c +13 -9
index 911ec51c..cfbcc689 100644
@@ -20,6 +20,7 @@
 #include "kernel-shared/disk-io.h"
 #include "kernel-shared/transaction.h"
 #include "kernel-shared/print-tree.h"
+#include "kernel-lib/bitops.h"
 #include "crypto/crc32c.h"
 #include "common/internal.h"
 #include "common/messages.h"
@@ -119,7 +120,8 @@ void btrfs_release_path(struct btrfs_path *p)
 
 void add_root_to_dirty_list(struct btrfs_root *root)
 {
-	if (root->track_dirty && list_empty(&root->dirty_list)) {
+	if (test_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state) &&
+	    list_empty(&root->dirty_list)) {
 		list_add(&root->dirty_list,
 			 &root->fs_info->dirty_cowonly_roots);
 	}
@@ -155,9 +157,10 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	memcpy(new_root, root, sizeof(*new_root));
 	new_root->root_key.objectid = new_root_objectid;
 
-	WARN_ON(root->ref_cows && trans->transid !=
-		root->fs_info->running_transaction->transid);
-	WARN_ON(root->ref_cows && trans->transid != root->last_trans);
+	WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
+		trans->transid != root->fs_info->running_transaction->transid);
+	WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
+		trans->transid != root->last_trans);
 
 	level = btrfs_header_level(buf);
 	if (level == 0)
@@ -219,7 +222,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans,
 
 	btrfs_setup_root(new_root, fs_info, objectid);
 	if (!is_fstree(objectid))
-		new_root->track_dirty = 1;
+		set_bit(BTRFS_ROOT_TRACK_DIRTY, &new_root->state);
 	add_root_to_dirty_list(new_root);
 
 	new_root->objectid = objectid;
@@ -332,7 +335,7 @@ static int btrfs_block_can_be_shared(struct btrfs_root *root,
 	 * snapshot and the block was not allocated by tree relocation,
 	 * we know the block is not shared.
 	 */
-	if (root->ref_cows &&
+	if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
 	    buf != root->node && buf != root->commit_root &&
 	    (btrfs_header_generation(buf) <=
 	     btrfs_root_last_snapshot(&root->root_item) ||
@@ -446,9 +449,10 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 	struct btrfs_disk_key disk_key;
 	int level;
 
-	WARN_ON(root->ref_cows && trans->transid !=
-		root->fs_info->running_transaction->transid);
-	WARN_ON(root->ref_cows && trans->transid != root->last_trans);
+	WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
+		trans->transid != root->fs_info->running_transaction->transid);
+	WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
+		trans->transid != root->last_trans);
 
 	level = btrfs_header_level(buf);
 
kernel-shared/ctree.h +63 -3

78 lines not on this page · raw message

kernel-shared/disk-io.c +11 -10
index 030bc780..44462d8f 100644
@@ -32,6 +32,7 @@
 #include "crypto/crc32c.h"
 #include "common/utils.h"
 #include "kernel-shared/print-tree.h"
+#include "kernel-lib/bitops.h"
 #include "common/rbtree-utils.h"
 #include "common/device-scan.h"
 #include "common/device-utils.h"
@@ -491,8 +492,7 @@ void btrfs_setup_root(struct btrfs_root *root, struct btrfs_fs_info *fs_info,
 {
 	root->node = NULL;
 	root->commit_root = NULL;
-	root->ref_cows = 0;
-	root->track_dirty = 0;
+	root->state = 0;
 
 	root->fs_info = fs_info;
 	root->objectid = objectid;
@@ -654,9 +654,9 @@ out:
 	}
 insert:
 	if (root->root_key.objectid != BTRFS_TREE_LOG_OBJECTID)
-		root->track_dirty = 1;
+		set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
 	if (is_fstree(root->root_key.objectid))
-		root->ref_cows = 1;
+		set_bit(BTRFS_ROOT_SHAREABLE, &root->state);
 	return root;
 }
 
@@ -1062,7 +1062,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info,
 			free(root);
 			break;
 		}
-		root->track_dirty = 1;
+		set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
 
 		ret = btrfs_global_root_insert(fs_info, root);
 		if (ret) {
@@ -1099,7 +1099,7 @@ static int load_global_roots_objectid(struct btrfs_fs_info *fs_info,
 			root->root_key.objectid = objectid;
 			root->root_key.type = BTRFS_ROOT_ITEM_KEY;
 			root->root_key.offset = i;
-			root->track_dirty = 1;
+			set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
 			root->node = btrfs_find_create_tree_block(fs_info, 0);
 			if (!root->node) {
 				free(root);
@@ -1232,7 +1232,8 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
 			error("couldn't load block group tree");
 			return -EIO;
 		}
-		fs_info->block_group_root->track_dirty = 1;
+		set_bit(BTRFS_ROOT_TRACK_DIRTY,
+			&fs_info->block_group_root->state);
 	}
 
 	ret = btrfs_find_and_setup_root(root, fs_info,
@@ -1242,7 +1243,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
 		printk("Couldn't setup device tree\n");
 		return -EIO;
 	}
-	fs_info->dev_root->track_dirty = 1;
+	set_bit(BTRFS_ROOT_TRACK_DIRTY, &fs_info->dev_root->state);
 
 	ret = btrfs_find_and_setup_root(root, fs_info,
 					BTRFS_UUID_TREE_OBJECTID,
@@ -1251,7 +1252,7 @@ int btrfs_setup_all_roots(struct btrfs_fs_info *fs_info, u64 root_tree_bytenr,
 		free(fs_info->uuid_root);
 		fs_info->uuid_root = NULL;
 	} else {
-		fs_info->uuid_root->track_dirty = 1;
+		set_bit(BTRFS_ROOT_TRACK_DIRTY, &fs_info->uuid_root->state);
 	}
 
 	ret = btrfs_find_and_setup_root(root, fs_info,
@@ -2355,7 +2356,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
 
 	extent_buffer_get(root->node);
 	root->commit_root = root->node;
-	root->track_dirty = 1;
+	set_bit(BTRFS_ROOT_TRACK_DIRTY, &root->state);
 
 	root->root_item.flags = 0;
 	root->root_item.byte_limit = 0;
kernel-shared/extent-tree.c +5 -5
index 2a71b97a..8f3477bf 100644
@@ -1471,7 +1471,7 @@ static int __btrfs_mod_ref(struct btrfs_trans_handle *trans,
 	nritems = btrfs_header_nritems(buf);
 	level = btrfs_header_level(buf);
 
-	if (!root->ref_cows && level == 0)
+	if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state) && level == 0)
 		return 0;
 
 	if (inc)
@@ -2359,11 +2359,11 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
 	}
 
 	/*
-	 * Also preallocate metadata for csum tree and fs trees (root->ref_cows
-	 * already set), as they can consume a lot of metadata space.
-	 * Pre-allocate to avoid unexpected ENOSPC.
+	 * Also preallocate metadata for csum tree and fs trees
+	 * (BTRFS_ROOT_SHAREABLE already set) as they can consume a lot of
+	 * metadata space.  Pre-allocate to avoid unexpected ENOSPC.
 	 */
-	if (root->ref_cows ||
+	if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state) ||
 	    root->root_key.objectid == BTRFS_CSUM_TREE_OBJECTID) {
 		if (!(profile & BTRFS_BLOCK_GROUP_METADATA)) {
 			ret = do_chunk_alloc(trans, info,
Signature · 1 line
2.40.0
#9 lore raw

PATCH 9/10 btrfs-progs: rename clear_extent_buffer_dirty => btrfs_clear_buffer_dirty

In reply to Josef Bacik

This is a mirror of the change I've done in the kernel, but in progs it's even more simply because clean_tree_block was just a wrapper around clear_extent_buffer_dirty. Change this to btrfs_clear_buffer_dirty, and then update all the callers to use this helper instead of clean_tree_block and clear_extent_buffer_dirty.

---
 cmds/rescue.c               |  2 +-
 kernel-shared/ctree.c       | 12 ++++++------
 kernel-shared/disk-io.c     |  7 +------
 kernel-shared/extent-tree.c |  2 +-
 kernel-shared/extent_io.c   |  2 +-
 kernel-shared/extent_io.h   |  2 +-
 kernel-shared/transaction.c |  4 ++--
 7 files changed, 13 insertions(+), 18 deletions(-)
cmds/rescue.c +1 -1
index cbeaa6f2..b84166ea 100644
@@ -340,7 +340,7 @@ static int clear_uuid_tree(struct btrfs_fs_info *fs_info)
 	if (ret < 0)
 		goto out;
 	list_del(&uuid_root->dirty_list);
-	ret = clean_tree_block(uuid_root->node);
+	ret = btrfs_clear_buffer_dirty(uuid_root->node);
 	if (ret < 0)
 		goto out;
 	ret = btrfs_free_tree_block(trans, uuid_root, uuid_root->node, 0, 1);
kernel-shared/ctree.c +6 -6
index ea2a7af3..4d33994d 100644
@@ -433,7 +433,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
 			ret = btrfs_dec_ref(trans, root, buf, 1);
 			BUG_ON(ret);
 		}
-		clean_tree_block(buf);
+		btrfs_clear_buffer_dirty(buf);
 	}
 	return 0;
 }
@@ -936,7 +936,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
 		root->node = child;
 		add_root_to_dirty_list(root);
 		path->nodes[level] = NULL;
-		clean_tree_block(mid);
+		btrfs_clear_buffer_dirty(mid);
 		/* once for the path */
 		free_extent_buffer(mid);
 
@@ -991,7 +991,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
 			u64 bytenr = right->start;
 			u32 blocksize = right->len;
 
-			clean_tree_block(right);
+			btrfs_clear_buffer_dirty(right);
 			free_extent_buffer(right);
 			right = NULL;
 			wret = btrfs_del_ptr(root, path, level + 1, pslot + 1);
@@ -1039,7 +1039,7 @@ static int balance_level(struct btrfs_trans_handle *trans,
 		/* we've managed to empty the middle node, drop it */
 		u64 bytenr = mid->start;
 		u32 blocksize = mid->len;
-		clean_tree_block(mid);
+		btrfs_clear_buffer_dirty(mid);
 		free_extent_buffer(mid);
 		mid = NULL;
 		wret = btrfs_del_ptr(root, path, level + 1, pslot);
@@ -3012,7 +3012,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		if (leaf == root->node) {
 			btrfs_set_header_level(leaf, 0);
 		} else {
-			clean_tree_block(leaf);
+			btrfs_clear_buffer_dirty(leaf);
 			wret = btrfs_del_leaf(trans, root, path, leaf);
 			BUG_ON(ret);
 			if (wret)
@@ -3048,7 +3048,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 			}
 
 			if (btrfs_header_nritems(leaf) == 0) {
-				clean_tree_block(leaf);
+				btrfs_clear_buffer_dirty(leaf);
 				path->slots[1] = slot;
 				ret = btrfs_del_leaf(trans, root, path, leaf);
 				BUG_ON(ret);
kernel-shared/disk-io.c +1 -6
index 7ee45ad1..7bbcc381 100644
@@ -2255,11 +2255,6 @@ skip_commit:
 	return err;
 }
 
-int clean_tree_block(struct extent_buffer *eb)
-{
-	return clear_extent_buffer_dirty(eb);
-}
-
 void btrfs_mark_buffer_dirty(struct extent_buffer *eb)
 {
 	set_extent_buffer_dirty(eb);
@@ -2303,7 +2298,7 @@ int btrfs_delete_and_free_root(struct btrfs_trans_handle *trans,
 		return ret;
 
 	list_del(&root->dirty_list);
-	ret = clean_tree_block(root->node);
+	ret = btrfs_clear_buffer_dirty(root->node);
 	if (ret)
 		return ret;
 	ret = btrfs_free_tree_block(trans, root, root->node, 0, 1);
kernel-shared/extent-tree.c +1 -1
index cfce4426..4dfb35d4 100644
@@ -1902,7 +1902,7 @@ static int pin_down_bytes(struct btrfs_trans_handle *trans, u64 bytenr,
 		if (header_owner != BTRFS_TREE_LOG_OBJECTID &&
 		    header_transid == trans->transid &&
 		    !btrfs_header_flag(buf, BTRFS_HEADER_FLAG_WRITTEN)) {
-			clean_tree_block(buf);
+			btrfs_clear_buffer_dirty(buf);
 			free_extent_buffer(buf);
 			return 1;
 		}
kernel-shared/extent_io.c +1 -1
index f740b3a6..4dff81bd 100644
@@ -579,7 +579,7 @@ int set_extent_buffer_dirty(struct extent_buffer *eb)
 	return 0;
 }
 
-int clear_extent_buffer_dirty(struct extent_buffer *eb)
+int btrfs_clear_buffer_dirty(struct extent_buffer *eb)
 {
 	struct extent_io_tree *tree = &eb->fs_info->dirty_buffers;
 	if (eb->flags & EXTENT_BUFFER_DIRTY) {
kernel-shared/extent_io.h +1 -1
index 103f93cb..09f3c82a 100644
@@ -124,7 +124,7 @@ void memset_extent_buffer(const struct extent_buffer *eb, char c,
 int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start,
 			   unsigned long nr);
 int set_extent_buffer_dirty(struct extent_buffer *eb);
-int clear_extent_buffer_dirty(struct extent_buffer *eb);
+int btrfs_clear_buffer_dirty(struct extent_buffer *eb);
 int read_data_from_disk(struct btrfs_fs_info *info, void *buf, u64 logical,
 			u64 *len, int mirror);
 int write_data_to_disk(struct btrfs_fs_info *info, void *buf, u64 offset,
kernel-shared/transaction.c +2 -2
index b16c07c3..f99bc684 100644
@@ -161,7 +161,7 @@ again:
 				goto cleanup;
 			}
 			start += eb->len;
-			clear_extent_buffer_dirty(eb);
+			btrfs_clear_buffer_dirty(eb);
 			free_extent_buffer(eb);
 		}
 	}
@@ -184,7 +184,7 @@ cleanup:
 			eb = find_first_extent_buffer(fs_info, start);
 			BUG_ON(!eb || eb->start != start);
 			start += eb->len;
-			clear_extent_buffer_dirty(eb);
+			btrfs_clear_buffer_dirty(eb);
 			free_extent_buffer(eb);
 		}
 	}
Signature · 1 line
2.40.0
#3 lore raw

PATCH 3/10 btrfs-progs: rename btrfs_alloc_free_block to btrfs_alloc_tree_block

In reply to Josef Bacik

This is in keeping with what the function actually does, and is named this way in the kernel.

---
 check/main.c                |  2 +-
 cmds/rescue-chunk-recover.c |  2 +-
 kernel-shared/ctree.c       | 14 +++++++-------
 kernel-shared/ctree.h       |  2 +-
 kernel-shared/disk-io.c     |  2 +-
 kernel-shared/extent-tree.c |  2 +-
 6 files changed, 12 insertions(+), 12 deletions(-)
check/main.c +1 -1
index 45e3442d..c5131b7a 100644
@@ -9096,7 +9096,7 @@ static struct extent_buffer *btrfs_fsck_clear_root(
 	if (!path)
 		return ERR_PTR(-ENOMEM);
 
-	c = btrfs_alloc_free_block(trans, gfs_info->tree_root,
+	c = btrfs_alloc_tree_block(trans, gfs_info->tree_root,
 				   gfs_info->nodesize, key->objectid,
 				   &disk_key, 0, 0, 0);
 	if (IS_ERR(c)) {
cmds/rescue-chunk-recover.c +1 -1
index ce53da2e..b18d422e 100644
@@ -1146,7 +1146,7 @@ static int __rebuild_chunk_root(struct btrfs_trans_handle *trans,
 	btrfs_set_disk_key_type(&disk_key, BTRFS_DEV_ITEM_KEY);
 	btrfs_set_disk_key_offset(&disk_key, min_devid);
 
-	cow = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
+	cow = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 				     BTRFS_CHUNK_TREE_OBJECTID,
 				     &disk_key, 0, 0, 0);
 	btrfs_set_header_bytenr(cow, cow->start);
kernel-shared/ctree.c +7 -7
index cfbcc689..230dae1b 100644
@@ -167,7 +167,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
 		btrfs_item_key(buf, &disk_key, 0);
 	else
 		btrfs_node_key(buf, &disk_key, 0);
-	cow = btrfs_alloc_free_block(trans, new_root, buf->len,
+	cow = btrfs_alloc_tree_block(trans, new_root, buf->len,
 				     new_root_objectid, &disk_key,
 				     level, buf->start, 0);
 	if (IS_ERR(cow)) {
@@ -230,7 +230,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans,
 	new_root->root_key.type = BTRFS_ROOT_ITEM_KEY;
 	new_root->root_key.offset = 0;
 
-	node = btrfs_alloc_free_block(trans, new_root, fs_info->nodesize,
+	node = btrfs_alloc_tree_block(trans, new_root, fs_info->nodesize,
 				      objectid, &disk_key, 0, 0, 0);
 	if (IS_ERR(node)) {
 		ret = PTR_ERR(node);
@@ -285,7 +285,7 @@ int btrfs_create_root(struct btrfs_trans_handle *trans,
 	/*
 	 * Essential trees can't be created by this function, yet.
 	 * As we expect such skeleton exists, or a lot of functions like
-	 * btrfs_alloc_free_block() doesn't work at all
+	 * btrfs_alloc_tree_block() doesn't work at all
 	 */
 	case BTRFS_ROOT_TREE_OBJECTID:
 	case BTRFS_EXTENT_TREE_OBJECTID:
@@ -461,7 +461,7 @@ int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 	else
 		btrfs_node_key(buf, &disk_key, 0);
 
-	cow = btrfs_alloc_free_block(trans, root, buf->len,
+	cow = btrfs_alloc_tree_block(trans, root, buf->len,
 				     root->root_key.objectid, &disk_key,
 				     level, search_start, empty_size);
 	if (IS_ERR(cow))
@@ -1732,7 +1732,7 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
 	else
 		btrfs_node_key(lower, &lower_key, 0);
 
-	c = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
+	c = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 				   root->root_key.objectid, &lower_key,
 				   level, root->node->start, 0);
 
@@ -1858,7 +1858,7 @@ static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
 	mid = (c_nritems + 1) / 2;
 	btrfs_node_key(c, &disk_key, mid);
 
-	split = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
+	split = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 					root->root_key.objectid,
 					&disk_key, level, c->start, 0);
 	if (IS_ERR(split))
@@ -2425,7 +2425,7 @@ again:
 	else
 		btrfs_item_key(l, &disk_key, mid);
 
-	right = btrfs_alloc_free_block(trans, root, root->fs_info->nodesize,
+	right = btrfs_alloc_tree_block(trans, root, root->fs_info->nodesize,
 					root->root_key.objectid,
 					&disk_key, 0, l->start, 0);
 	if (IS_ERR(right)) {
kernel-shared/ctree.h +1 -1
index 84acefef..af60ba66 100644
@@ -849,7 +849,7 @@ struct btrfs_block_group *btrfs_lookup_block_group(struct btrfs_fs_info *info,
 struct btrfs_block_group *btrfs_lookup_first_block_group(struct
 						       btrfs_fs_info *info,
 						       u64 bytenr);
-struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
+struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
 					struct btrfs_root *root,
 					u32 blocksize, u64 root_objectid,
 					struct btrfs_disk_key *key, int level,
kernel-shared/disk-io.c +1 -1
index 44462d8f..6f9dc327 100644
@@ -2333,7 +2333,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
 	btrfs_setup_root(root, fs_info, key->objectid);
 	memcpy(&root->root_key, key, sizeof(struct btrfs_key));
 
-	leaf = btrfs_alloc_free_block(trans, root, fs_info->nodesize,
+	leaf = btrfs_alloc_tree_block(trans, root, fs_info->nodesize,
 				      root->root_key.objectid, NULL, 0, 0, 0);
 	if (IS_ERR(leaf)) {
 		ret = PTR_ERR(leaf);
kernel-shared/extent-tree.c +1 -1
index 8f3477bf..d0b3aee3 100644
@@ -2555,7 +2555,7 @@ static int alloc_tree_block(struct btrfs_trans_handle *trans,
  * helper function to allocate a block for a given tree
  * returns the tree buffer or NULL.
  */
-struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
+struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
 					struct btrfs_root *root,
 					u32 blocksize, u64 root_objectid,
 					struct btrfs_disk_key *key, int level,
Signature · 1 line
2.40.0
#10 lore raw

PATCH 10/10 btrfs-progs: make __btrfs_cow_block static

In reply to Josef Bacik

This isn't used anywhere other than ctree.c, make it static.

---
 kernel-shared/ctree.c | 2 +-
 kernel-shared/ctree.h | 6 ------
 2 files changed, 1 insertion(+), 7 deletions(-)
kernel-shared/ctree.c +1 -1
index 4d33994d..da9282b9 100644
@@ -438,7 +438,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
 	return 0;
 }
 
-int __btrfs_cow_block(struct btrfs_trans_handle *trans,
+static int __btrfs_cow_block(struct btrfs_trans_handle *trans,
 			     struct btrfs_root *root,
 			     struct extent_buffer *buf,
 			     struct extent_buffer *parent, int parent_slot,
kernel-shared/ctree.h +0 -6
index 069e000d..655b714f 100644
@@ -936,12 +936,6 @@ int btrfs_cow_block(struct btrfs_trans_handle *trans,
 		    struct btrfs_root *root, struct extent_buffer *buf,
 		    struct extent_buffer *parent, int parent_slot,
 		    struct extent_buffer **cow_ret);
-int __btrfs_cow_block(struct btrfs_trans_handle *trans,
-			     struct btrfs_root *root,
-			     struct extent_buffer *buf,
-			     struct extent_buffer *parent, int parent_slot,
-			     struct extent_buffer **cow_ret,
-			     u64 search_start, u64 empty_size);
 int btrfs_copy_root(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *root,
 		      struct extent_buffer *buf,
Signature · 1 line
2.40.0
#7 lore raw

PATCH 7/10 btrfs-progs: rename btrfs_set_block_flags -> btrfs_set_disk_extent_flags

In reply to Josef Bacik

This helper in the kernel is named btrfs_set_disk_extent_flags, which is a more accurate description than btrfs_set_block_flags. Rename to the in kernel name to make sync'ing ctree.c easier.

---
 kernel-shared/ctree.c       | 6 +++---
 kernel-shared/ctree.h       | 4 ++--
 kernel-shared/extent-tree.c | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)
kernel-shared/ctree.c +3 -3
index cad15093..e95dcc79 100644
@@ -419,9 +419,9 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans,
 			BUG_ON(ret);
 		}
 		if (new_flags != 0) {
-			ret = btrfs_set_block_flags(trans, buf->start,
-						    btrfs_header_level(buf),
-						    new_flags);
+			ret = btrfs_set_disk_extent_flags(trans, buf->start,
+							  btrfs_header_level(buf),
+							  new_flags);
 			BUG_ON(ret);
 		}
 	} else {
kernel-shared/ctree.h +2 -2
index f416fc36..aaace45e 100644
@@ -859,8 +859,8 @@ struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
 int btrfs_lookup_extent_info(struct btrfs_trans_handle *trans,
 			     struct btrfs_fs_info *fs_info, u64 bytenr,
 			     u64 offset, int metadata, u64 *refs, u64 *flags);
-int btrfs_set_block_flags(struct btrfs_trans_handle *trans, u64 bytenr,
-			  int level, u64 flags);
+int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr,
+				int level, u64 flags);
 int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		  struct extent_buffer *buf, int record_parent);
 int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
kernel-shared/extent-tree.c +2 -2
index 916eb840..8a6ab996 100644
@@ -1375,8 +1375,8 @@ out:
 	return ret;
 }
 
-int btrfs_set_block_flags(struct btrfs_trans_handle *trans, u64 bytenr,
-			  int level, u64 flags)
+int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, u64 bytenr,
+				int level, u64 flags)
 {
 	struct btrfs_fs_info *fs_info = trans->fs_info;
 	struct btrfs_root *extent_root = btrfs_extent_root(fs_info, bytenr);
Signature · 1 line
2.40.0
#4 lore raw

PATCH 4/10 btrfs-progs: sync locking.h and stub out all the helpers

In reply to Josef Bacik

We want locking.h to have all the definitions that get used throughout the codebase, however we don't want to actually use any of the actual locking. This sync's the bulk of locking.h, and then stubs out all of the definitions. We need a locking.c for the root lock helpers that return the extent buffer, but everything else can simply be inlined out.

---
 Makefile                |   1 +
 include/kerncompat.h    |   4 +
 kernel-shared/locking.c |  22 ++++
 kernel-shared/locking.h | 258 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 285 insertions(+)
 create mode 100644 kernel-shared/locking.c
 create mode 100644 kernel-shared/locking.h
Makefile +1 -0
index 43dfd296..8001f46a 100644
@@ -182,6 +182,7 @@ objects = \
 	kernel-shared/free-space-tree.o	\
 	kernel-shared/inode-item.o	\
 	kernel-shared/inode.o	\
+	kernel-shared/locking.o	\
 	kernel-shared/messages.o	\
 	kernel-shared/print-tree.o	\
 	kernel-shared/root-tree.o	\
include/kerncompat.h +4 -0
index 68007915..28e9f443 100644
@@ -615,6 +615,10 @@ do {									\
 #define smp_mb__before_atomic() do {} while (0)
 #define smp_mb() do {} while (0)
 
+struct percpu_counter {
+	int count;
+};
+
 typedef struct refcount_struct {
 	int refs;
 } refcount_t;
kernel-shared/locking.c new file +22 -0
new file mode 100644
index 00000000..c4138e68
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2008 Oracle.  All rights reserved.
+ */
+
+#include "ctree.h"
+#include "locking.h"
+
+struct extent_buffer *btrfs_read_lock_root_node(struct btrfs_root *root)
+{
+	return root->node;
+}
+
+struct extent_buffer *btrfs_try_read_lock_root_node(struct btrfs_root *root)
+{
+	return root->node;
+}
+
+struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root)
+{
+	return root->node;
+}
kernel-shared/locking.h new file +258 -0

258 lines not on this page · raw message

Signature · 1 line
2.40.0
#1 lore raw

PATCH 1/10 btrfs-progs: const-ify the extent buffer helpers

In reply to Josef Bacik

These helpers are all take const struct extent_buffer in the kernel, do the same in btrfs-progs in order to enable us to more easily sync ctree.c.

---
 kernel-shared/extent_io.c | 15 ++++++++-------
 kernel-shared/extent_io.h | 10 ++++++----
 2 files changed, 14 insertions(+), 11 deletions(-)
kernel-shared/extent_io.c +8 -7
index 46c0fb3f..01dc5b1e 100644
@@ -609,26 +609,27 @@ void write_extent_buffer(const struct extent_buffer *eb, const void *src,
 	memcpy((void *)eb->data + start, src, len);
 }
 
-void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
+void copy_extent_buffer(const struct extent_buffer *dst,
+			const struct extent_buffer *src,
 			unsigned long dst_offset, unsigned long src_offset,
 			unsigned long len)
 {
-	memcpy(dst->data + dst_offset, src->data + src_offset, len);
+	memcpy((void *)dst->data + dst_offset, src->data + src_offset, len);
 }
 
-void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
+void memmove_extent_buffer(const struct extent_buffer *dst, unsigned long dst_offset,
 			   unsigned long src_offset, unsigned long len)
 {
-	memmove(dst->data + dst_offset, dst->data + src_offset, len);
+	memmove((void *)dst->data + dst_offset, dst->data + src_offset, len);
 }
 
-void memset_extent_buffer(struct extent_buffer *eb, char c,
+void memset_extent_buffer(const struct extent_buffer *eb, char c,
 			  unsigned long start, unsigned long len)
 {
-	memset(eb->data + start, c, len);
+	memset((void *)eb->data + start, c, len);
 }
 
-int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start,
+int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start,
 			   unsigned long nr)
 {
 	return le_test_bit(nr, (u8 *)eb->data + start);
kernel-shared/extent_io.h +6 -4
index 8ba56eed..69133c3c 100644
@@ -110,14 +110,16 @@ void read_extent_buffer(const struct extent_buffer *eb, void *dst,
 			unsigned long start, unsigned long len);
 void write_extent_buffer(const struct extent_buffer *eb, const void *src,
 			 unsigned long start, unsigned long len);
-void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
+void copy_extent_buffer(const struct extent_buffer *dst,
+			const struct extent_buffer *src,
 			unsigned long dst_offset, unsigned long src_offset,
 			unsigned long len);
-void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
+void memmove_extent_buffer(const struct extent_buffer *dst,
+			   const unsigned long dst_offset,
 			   unsigned long src_offset, unsigned long len);
-void memset_extent_buffer(struct extent_buffer *eb, char c,
+void memset_extent_buffer(const struct extent_buffer *eb, char c,
 			  unsigned long start, unsigned long len);
-int extent_buffer_test_bit(struct extent_buffer *eb, unsigned long start,
+int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start,
 			   unsigned long nr);
 int set_extent_buffer_dirty(struct extent_buffer *eb);
 int clear_extent_buffer_dirty(struct extent_buffer *eb);
Signature · 1 line
2.40.0
#11 lore raw
In reply to Josef Bacik
Quoted 17 lines · Josef Bacik

Hello,

These patches update a lot of the different ctree.c related helpers that have diverged from the kernel in order to make ite easier syncing ctree.c directly. This also syncs locking.[ch], but this is to just stub out the locking. This will make it easier to sync ctree.c as well since there's locking in the kernel that didn't exist when we had this in btrfs-progs.

This series depends on

btrfs-progs: prep work for syncing files into kernel-shared
btrfs-progs: sync basic code from the kernel

Thanks,

Josef

Quoted 13 lines

Josef Bacik (10):
btrfs-progs: const-ify the extent buffer helpers
btrfs-progs: bring root->state into btrfs-progs
btrfs-progs: rename btrfs_alloc_free_block to btrfs_alloc_tree_block
btrfs-progs: sync locking.h and stub out all the helpers
btrfs-progs: add btrfs_locking_nest to btrfs_alloc_tree_block
btrfs-progs: add some missing extent buffer helpers
btrfs-progs: rename btrfs_set_block_flags ->
btrfs_set_disk_extent_flags
btrfs-progs: cleanup args for btrfs_set_disk_extent_flags
btrfs-progs: rename clear_extent_buffer_dirty =>
btrfs_clear_buffer_dirty
btrfs-progs: make __btrfs_cow_block static

Added to devel. However, this fails build on Centos7 image with warnings like

[CC] kernel-shared/backref.o
In file included from ./kernel-shared/ctree.h:30:0,

                 from kernel-shared/volumes.h:23,
                 from btrfs.c:24:
./kernel-shared/accessors.h: In function 'btrfs_device_total_bytes':
./kernel-shared/accessors.h:118:58: error: expected ',' before ')' token
         sizeof(((struct btrfs_dev_item *)0))->total_bytes);
                                                          ^
./kernel-shared/accessors.h: In function 'btrfs_set_device_total_bytes':
./kernel-shared/accessors.h:132:58: error: expected ',' before ')' token
         sizeof(((struct btrfs_dev_item *)0))->total_bytes);
                                                          ^

The code is same as in kernel e.g.

114 static inline u64 btrfs_device_total_bytes(const struct extent_buffer *eb,
115 struct btrfs_dev_item *s)
116 {
117 static_assert(sizeof(u64) ==
118 sizeof(((struct btrfs_dev_item *)0))->total_bytes);
119 return btrfs_get_64(eb, s, offsetof(struct btrfs_dev_item,
120 total_bytes));
121 }