]> git.dujemihanovic.xyz Git - linux.git/commitdiff
btrfs: migrate the block group ref counting stuff
authorJosef Bacik <josef@toxicpanda.com>
Thu, 20 Jun 2019 19:37:46 +0000 (15:37 -0400)
committerDavid Sterba <dsterba@suse.com>
Mon, 9 Sep 2019 12:59:04 +0000 (14:59 +0200)
Another easy set to move over to block-group.c.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/ctree.h
fs/btrfs/extent-tree.c

index ebe7b1c5c1e3921b3a21c2a5eef2bce68429a33e..4328196a4d448ef7966b61cdc139356b4a5b2e2b 100644 (file)
@@ -3,6 +3,31 @@
 #include "ctree.h"
 #include "block-group.h"
 
+void btrfs_get_block_group(struct btrfs_block_group_cache *cache)
+{
+       atomic_inc(&cache->count);
+}
+
+void btrfs_put_block_group(struct btrfs_block_group_cache *cache)
+{
+       if (atomic_dec_and_test(&cache->count)) {
+               WARN_ON(cache->pinned > 0);
+               WARN_ON(cache->reserved > 0);
+
+               /*
+                * If not empty, someone is still holding mutex of
+                * full_stripe_lock, which can only be released by caller.
+                * And it will definitely cause use-after-free when caller
+                * tries to release full stripe lock.
+                *
+                * No better way to resolve, but only to warn.
+                */
+               WARN_ON(!RB_EMPTY_ROOT(&cache->full_stripe_locks_root.root));
+               kfree(cache->free_space_ctl);
+               kfree(cache);
+       }
+}
+
 /*
  * This will return the block group at or after bytenr if contains is 0, else
  * it will return the block group that contains the bytenr
index 87bac0d5ad693311886fe1b785ebd385f69a026b..f7c7d1ac6d9bdea0cc66923fba917a19b7dfa0de 100644 (file)
@@ -157,5 +157,7 @@ struct btrfs_block_group_cache *btrfs_lookup_block_group(
                struct btrfs_fs_info *info, u64 bytenr);
 struct btrfs_block_group_cache *btrfs_next_block_group(
                struct btrfs_block_group_cache *cache);
+void btrfs_get_block_group(struct btrfs_block_group_cache *cache);
+void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
 
 #endif /* BTRFS_BLOCK_GROUP_H */
index 49ac72c3d0cd70c8b8c0cf065f60aa5306538d67..ae8f39c3dcd23ddc3c683b78ef3d36b3e07a3cb7 100644 (file)
@@ -2479,7 +2479,6 @@ void btrfs_wait_block_group_reservations(struct btrfs_block_group_cache *bg);
 bool btrfs_inc_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr);
 void btrfs_dec_nocow_writers(struct btrfs_fs_info *fs_info, u64 bytenr);
 void btrfs_wait_nocow_writers(struct btrfs_block_group_cache *bg);
-void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
 int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
                           unsigned long count);
 void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
@@ -2496,8 +2495,6 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info,
 int btrfs_exclude_logged_extents(struct extent_buffer *eb);
 int btrfs_cross_ref_exist(struct btrfs_root *root,
                          u64 objectid, u64 offset, u64 bytenr);
-void btrfs_get_block_group(struct btrfs_block_group_cache *cache);
-void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
 struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
                                             struct btrfs_root *root,
                                             u64 parent, u64 root_objectid,
index a454945227cacd58499f64341023bb7b8dd2c8ee..dc1fb9286fee1c365c35aba26af55e4a1f6c0f19 100644 (file)
@@ -68,31 +68,6 @@ static int block_group_bits(struct btrfs_block_group_cache *cache, u64 bits)
        return (cache->flags & bits) == bits;
 }
 
-void btrfs_get_block_group(struct btrfs_block_group_cache *cache)
-{
-       atomic_inc(&cache->count);
-}
-
-void btrfs_put_block_group(struct btrfs_block_group_cache *cache)
-{
-       if (atomic_dec_and_test(&cache->count)) {
-               WARN_ON(cache->pinned > 0);
-               WARN_ON(cache->reserved > 0);
-
-               /*
-                * If not empty, someone is still holding mutex of
-                * full_stripe_lock, which can only be released by caller.
-                * And it will definitely cause use-after-free when caller
-                * tries to release full stripe lock.
-                *
-                * No better way to resolve, but only to warn.
-                */
-               WARN_ON(!RB_EMPTY_ROOT(&cache->full_stripe_locks_root.root));
-               kfree(cache->free_space_ctl);
-               kfree(cache);
-       }
-}
-
 /*
  * this adds the block group to the fs_info rb tree for the block group
  * cache