Commit f3372065 authored by Johannes Thumshirn's avatar Johannes Thumshirn Committed by David Sterba

btrfs: rename delete_unused_bgs_mutex to reclaim_bgs_lock

As a preparation for extending the block group deletion use case, rename
the unused_bgs_mutex to reclaim_bgs_lock.
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 01e86008
...@@ -1289,7 +1289,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) ...@@ -1289,7 +1289,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
* Long running balances can keep us blocked here for eternity, so * Long running balances can keep us blocked here for eternity, so
* simply skip deletion if we're unable to get the mutex. * simply skip deletion if we're unable to get the mutex.
*/ */
if (!mutex_trylock(&fs_info->delete_unused_bgs_mutex)) if (!mutex_trylock(&fs_info->reclaim_bgs_lock))
return; return;
spin_lock(&fs_info->unused_bgs_lock); spin_lock(&fs_info->unused_bgs_lock);
...@@ -1462,12 +1462,12 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) ...@@ -1462,12 +1462,12 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
spin_lock(&fs_info->unused_bgs_lock); spin_lock(&fs_info->unused_bgs_lock);
} }
spin_unlock(&fs_info->unused_bgs_lock); spin_unlock(&fs_info->unused_bgs_lock);
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
return; return;
flip_async: flip_async:
btrfs_end_transaction(trans); btrfs_end_transaction(trans);
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
btrfs_put_block_group(block_group); btrfs_put_block_group(block_group);
btrfs_discard_punt_unused_bgs_list(fs_info); btrfs_discard_punt_unused_bgs_list(fs_info);
} }
......
...@@ -963,7 +963,8 @@ struct btrfs_fs_info { ...@@ -963,7 +963,8 @@ struct btrfs_fs_info {
spinlock_t unused_bgs_lock; spinlock_t unused_bgs_lock;
struct list_head unused_bgs; struct list_head unused_bgs;
struct mutex unused_bg_unpin_mutex; struct mutex unused_bg_unpin_mutex;
struct mutex delete_unused_bgs_mutex; /* Protect block groups that are going to be deleted */
struct mutex reclaim_bgs_lock;
/* Cached block sizes */ /* Cached block sizes */
u32 nodesize; u32 nodesize;
......
...@@ -1890,10 +1890,10 @@ static int cleaner_kthread(void *arg) ...@@ -1890,10 +1890,10 @@ static int cleaner_kthread(void *arg)
btrfs_run_defrag_inodes(fs_info); btrfs_run_defrag_inodes(fs_info);
/* /*
* Acquires fs_info->delete_unused_bgs_mutex to avoid racing * Acquires fs_info->reclaim_bgs_lock to avoid racing
* with relocation (btrfs_relocate_chunk) and relocation * with relocation (btrfs_relocate_chunk) and relocation
* acquires fs_info->cleaner_mutex (btrfs_relocate_block_group) * acquires fs_info->cleaner_mutex (btrfs_relocate_block_group)
* after acquiring fs_info->delete_unused_bgs_mutex. So we * after acquiring fs_info->reclaim_bgs_lock. So we
* can't hold, nor need to, fs_info->cleaner_mutex when deleting * can't hold, nor need to, fs_info->cleaner_mutex when deleting
* unused block groups. * unused block groups.
*/ */
...@@ -2876,7 +2876,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info) ...@@ -2876,7 +2876,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
spin_lock_init(&fs_info->treelog_bg_lock); spin_lock_init(&fs_info->treelog_bg_lock);
rwlock_init(&fs_info->tree_mod_log_lock); rwlock_init(&fs_info->tree_mod_log_lock);
mutex_init(&fs_info->unused_bg_unpin_mutex); mutex_init(&fs_info->unused_bg_unpin_mutex);
mutex_init(&fs_info->delete_unused_bgs_mutex); mutex_init(&fs_info->reclaim_bgs_lock);
mutex_init(&fs_info->reloc_mutex); mutex_init(&fs_info->reloc_mutex);
mutex_init(&fs_info->delalloc_root_mutex); mutex_init(&fs_info->delalloc_root_mutex);
mutex_init(&fs_info->zoned_meta_io_lock); mutex_init(&fs_info->zoned_meta_io_lock);
......
...@@ -3118,7 +3118,7 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset) ...@@ -3118,7 +3118,7 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
* we release the path used to search the chunk/dev tree and before * we release the path used to search the chunk/dev tree and before
* the current task acquires this mutex and calls us. * the current task acquires this mutex and calls us.
*/ */
lockdep_assert_held(&fs_info->delete_unused_bgs_mutex); lockdep_assert_held(&fs_info->reclaim_bgs_lock);
/* step one, relocate all the extents inside this chunk */ /* step one, relocate all the extents inside this chunk */
btrfs_scrub_pause(fs_info); btrfs_scrub_pause(fs_info);
...@@ -3188,10 +3188,10 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info) ...@@ -3188,10 +3188,10 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
key.type = BTRFS_CHUNK_ITEM_KEY; key.type = BTRFS_CHUNK_ITEM_KEY;
while (1) { while (1) {
mutex_lock(&fs_info->delete_unused_bgs_mutex); mutex_lock(&fs_info->reclaim_bgs_lock);
ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
goto error; goto error;
} }
BUG_ON(ret == 0); /* Corruption */ BUG_ON(ret == 0); /* Corruption */
...@@ -3199,7 +3199,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info) ...@@ -3199,7 +3199,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
ret = btrfs_previous_item(chunk_root, path, key.objectid, ret = btrfs_previous_item(chunk_root, path, key.objectid,
key.type); key.type);
if (ret) if (ret)
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
if (ret < 0) if (ret < 0)
goto error; goto error;
if (ret > 0) if (ret > 0)
...@@ -3220,7 +3220,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info) ...@@ -3220,7 +3220,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
else else
BUG_ON(ret); BUG_ON(ret);
} }
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
if (found_key.offset == 0) if (found_key.offset == 0)
break; break;
...@@ -3760,10 +3760,10 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3760,10 +3760,10 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
goto error; goto error;
} }
mutex_lock(&fs_info->delete_unused_bgs_mutex); mutex_lock(&fs_info->reclaim_bgs_lock);
ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
goto error; goto error;
} }
...@@ -3777,7 +3777,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3777,7 +3777,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
ret = btrfs_previous_item(chunk_root, path, 0, ret = btrfs_previous_item(chunk_root, path, 0,
BTRFS_CHUNK_ITEM_KEY); BTRFS_CHUNK_ITEM_KEY);
if (ret) { if (ret) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
ret = 0; ret = 0;
break; break;
} }
...@@ -3787,7 +3787,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3787,7 +3787,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
btrfs_item_key_to_cpu(leaf, &found_key, slot); btrfs_item_key_to_cpu(leaf, &found_key, slot);
if (found_key.objectid != key.objectid) { if (found_key.objectid != key.objectid) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
break; break;
} }
...@@ -3804,12 +3804,12 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3804,12 +3804,12 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
btrfs_release_path(path); btrfs_release_path(path);
if (!ret) { if (!ret) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
goto loop; goto loop;
} }
if (counting) { if (counting) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
spin_lock(&fs_info->balance_lock); spin_lock(&fs_info->balance_lock);
bctl->stat.expected++; bctl->stat.expected++;
spin_unlock(&fs_info->balance_lock); spin_unlock(&fs_info->balance_lock);
...@@ -3834,7 +3834,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3834,7 +3834,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
count_meta < bctl->meta.limit_min) count_meta < bctl->meta.limit_min)
|| ((chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) && || ((chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) &&
count_sys < bctl->sys.limit_min)) { count_sys < bctl->sys.limit_min)) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
goto loop; goto loop;
} }
...@@ -3848,7 +3848,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3848,7 +3848,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
ret = btrfs_may_alloc_data_chunk(fs_info, ret = btrfs_may_alloc_data_chunk(fs_info,
found_key.offset); found_key.offset);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
goto error; goto error;
} else if (ret == 1) { } else if (ret == 1) {
chunk_reserved = 1; chunk_reserved = 1;
...@@ -3856,7 +3856,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) ...@@ -3856,7 +3856,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
} }
ret = btrfs_relocate_chunk(fs_info, found_key.offset); ret = btrfs_relocate_chunk(fs_info, found_key.offset);
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
enospc_errors++; enospc_errors++;
} else if (ret == -ETXTBSY) { } else if (ret == -ETXTBSY) {
...@@ -4741,16 +4741,16 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4741,16 +4741,16 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
key.type = BTRFS_DEV_EXTENT_KEY; key.type = BTRFS_DEV_EXTENT_KEY;
do { do {
mutex_lock(&fs_info->delete_unused_bgs_mutex); mutex_lock(&fs_info->reclaim_bgs_lock);
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
goto done; goto done;
} }
ret = btrfs_previous_item(root, path, 0, key.type); ret = btrfs_previous_item(root, path, 0, key.type);
if (ret) { if (ret) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
if (ret < 0) if (ret < 0)
goto done; goto done;
ret = 0; ret = 0;
...@@ -4763,7 +4763,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4763,7 +4763,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
btrfs_item_key_to_cpu(l, &key, path->slots[0]); btrfs_item_key_to_cpu(l, &key, path->slots[0]);
if (key.objectid != device->devid) { if (key.objectid != device->devid) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
btrfs_release_path(path); btrfs_release_path(path);
break; break;
} }
...@@ -4772,7 +4772,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4772,7 +4772,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
length = btrfs_dev_extent_length(l, dev_extent); length = btrfs_dev_extent_length(l, dev_extent);
if (key.offset + length <= new_size) { if (key.offset + length <= new_size) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
btrfs_release_path(path); btrfs_release_path(path);
break; break;
} }
...@@ -4788,12 +4788,12 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4788,12 +4788,12 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
*/ */
ret = btrfs_may_alloc_data_chunk(fs_info, chunk_offset); ret = btrfs_may_alloc_data_chunk(fs_info, chunk_offset);
if (ret < 0) { if (ret < 0) {
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
goto done; goto done;
} }
ret = btrfs_relocate_chunk(fs_info, chunk_offset); ret = btrfs_relocate_chunk(fs_info, chunk_offset);
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
if (ret == -ENOSPC) { if (ret == -ENOSPC) {
failed++; failed++;
} else if (ret) { } else if (ret) {
...@@ -8068,7 +8068,7 @@ static int relocating_repair_kthread(void *data) ...@@ -8068,7 +8068,7 @@ static int relocating_repair_kthread(void *data)
return -EBUSY; return -EBUSY;
} }
mutex_lock(&fs_info->delete_unused_bgs_mutex); mutex_lock(&fs_info->reclaim_bgs_lock);
/* Ensure block group still exists */ /* Ensure block group still exists */
cache = btrfs_lookup_block_group(fs_info, target); cache = btrfs_lookup_block_group(fs_info, target);
...@@ -8090,7 +8090,7 @@ static int relocating_repair_kthread(void *data) ...@@ -8090,7 +8090,7 @@ static int relocating_repair_kthread(void *data)
out: out:
if (cache) if (cache)
btrfs_put_block_group(cache); btrfs_put_block_group(cache);
mutex_unlock(&fs_info->delete_unused_bgs_mutex); mutex_unlock(&fs_info->reclaim_bgs_lock);
btrfs_exclop_finish(fs_info); btrfs_exclop_finish(fs_info);
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment