btrfs: drop @update_ref for btrfs_drop_snapshot()
PATCH 1/1 btrfs: drop @update_ref for btrfs_drop_snapshot()
Instead of making every caller decide @update_ref, let btrfs_drop_snapshot() figure it out itself using @for_reloc and backref_rev of the root node.
Callers that passed 'false' for for_reloc now get the right behaviour automatically; callers that passed 'true' continue to skip the update because for_reloc implies !update_ref.
Fix the comment accordingly. Also fix the comment which is rewritten wrongly in commit 67e78f983e6a1("btrfs: convert several int parameters to bool")
Signed-off-by Sun YangKai <[email protected]>
--- fs/btrfs/extent-tree.c | 10 ++++++---- fs/btrfs/extent-tree.h | 2 +- fs/btrfs/relocation.c | 4 ++-- fs/btrfs/transaction.c | 6 +----- 4 files changed, 10 insertions(+), 12 deletions(-)
fs/btrfs/extent-tree.c +6 -4
@@ -6047,15 +6047,14 @@ static noinline int walk_up_tree(struct btrfs_trans_handle *trans,* referenced by the tree. * * when a shared tree block is found. this function decreases its -* reference count by one. if update_ref is true, this function +* reference count by one. If for_reloc is false, this function * also make sure backrefs for the shared block and all lower level * blocks are properly updated. * -* If called with for_reloc set, may exit early with -EAGAIN +* If called with for_reloc == false, may exit early with -EAGAIN */ -int btrfs_drop_snapshot (struct btrfs_root *root,bool update_ref,bool for_reloc) +int btrfs_drop_snapshot (struct btrfs_root *root,bool for_reloc) { -const bool is_reloc_root = (btrfs_root_id (root) ==BTRFS_TREE_RELOC_OBJECTID );struct btrfs_fs_info *fs_info = root->fs_info;struct btrfs_path *path;struct btrfs_trans_handle *trans;
@@ -6066,6 +6065,9 @@ int btrfs_drop_snapshot(struct btrfs_root *root, bool update_ref, bool for_relocconst u64 rootid =btrfs_root_id (root);int ret =0 ;int level; +const bool is_reloc_root = (rootid ==BTRFS_TREE_RELOC_OBJECTID ); +const bool update_ref = (!for_reloc && +btrfs_header_backref_rev (root->node) >=BTRFS_MIXED_BACKREF_REV );bool root_dropped = false;bool unfinished_drop = false;
fs/btrfs/extent-tree.h +1 -1
@@ -155,7 +155,7 @@ int btrfs_pin_reserved_extent(struct btrfs_trans_handle *trans, const struct extent_buffer *eb);int btrfs_finish_extent_commit (struct btrfs_trans_handle *trans);int btrfs_inc_extent_ref (struct btrfs_trans_handle *trans,struct btrfs_ref *generic_ref); -int btrfs_drop_snapshot (struct btrfs_root *root,bool update_ref,bool for_reloc); +int btrfs_drop_snapshot (struct btrfs_root *root,bool for_reloc); int btrfs_drop_subtree(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *node,
fs/btrfs/relocation.c +2 -2
@@ -1483,7 +1483,7 @@ static int clean_dirty_subvols(struct reloc_control *rc)* ->reloc_root. If it fails however we must * drop the ref ourselves. */ - ret2 =btrfs_drop_snapshot (reloc_root, false, true); + ret2 =btrfs_drop_snapshot (reloc_root, true);if (ret2 <0 ) {btrfs_put_root (reloc_root);if (!ret)
@@ -1493,7 +1493,7 @@ static int clean_dirty_subvols(struct reloc_control *rc)btrfs_put_root (root); }else {/* Orphan reloc tree, just clean it up */ - ret2 =btrfs_drop_snapshot (root, false, true); + ret2 =btrfs_drop_snapshot (root, true);if (ret2 <0 ) {btrfs_put_root (root);if (!ret)
fs/btrfs/transaction.c +1 -5
@@ -2652,11 +2652,7 @@ int btrfs_clean_one_deleted_snapshot(struct btrfs_fs_info *fs_info)btrfs_kill_all_delayed_nodes (root); -if (btrfs_header_backref_rev (root->node) < -BTRFS_MIXED_BACKREF_REV ) - ret =btrfs_drop_snapshot (root, false, false); -else - ret =btrfs_drop_snapshot (root, true, false); + ret =btrfs_drop_snapshot (root, false);btrfs_put_root (root);return (ret <0 ) ?0 :1 ;
Signature · 1 line
2.51.2