summaryrefslogtreecommitdiff
path: root/fs/btrfs/block-group.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2019-06-20 15:37:46 -0400
committerDavid Sterba <dsterba@suse.com>2019-09-09 14:59:04 +0200
commit3cad128400c2445d9140c0f5720018e075ef66c6 (patch)
tree43632afb0ad6869ff72eac40183aaf03240bf7c9 /fs/btrfs/block-group.c
parent2e405ad842546a1a37aaa586d5140d071cb1f802 (diff)
downloadlwn-3cad128400c2445d9140c0f5720018e075ef66c6.tar.gz
lwn-3cad128400c2445d9140c0f5720018e075ef66c6.zip
btrfs: migrate the block group ref counting stuff
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>
Diffstat (limited to 'fs/btrfs/block-group.c')
-rw-r--r--fs/btrfs/block-group.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index ebe7b1c5c1e3..4328196a4d44 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -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