Skip to content

Commit f337206

Browse files
morbidrsakdave
authored andcommitted
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: Filipe Manana <[email protected]> Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 01e8600 commit f337206

File tree

4 files changed

+31
-30
lines changed

4 files changed

+31
-30
lines changed

fs/btrfs/block-group.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
12891289
* Long running balances can keep us blocked here for eternity, so
12901290
* simply skip deletion if we're unable to get the mutex.
12911291
*/
1292-
if (!mutex_trylock(&fs_info->delete_unused_bgs_mutex))
1292+
if (!mutex_trylock(&fs_info->reclaim_bgs_lock))
12931293
return;
12941294

12951295
spin_lock(&fs_info->unused_bgs_lock);
@@ -1462,12 +1462,12 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info)
14621462
spin_lock(&fs_info->unused_bgs_lock);
14631463
}
14641464
spin_unlock(&fs_info->unused_bgs_lock);
1465-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
1465+
mutex_unlock(&fs_info->reclaim_bgs_lock);
14661466
return;
14671467

14681468
flip_async:
14691469
btrfs_end_transaction(trans);
1470-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
1470+
mutex_unlock(&fs_info->reclaim_bgs_lock);
14711471
btrfs_put_block_group(block_group);
14721472
btrfs_discard_punt_unused_bgs_list(fs_info);
14731473
}

fs/btrfs/ctree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,8 @@ struct btrfs_fs_info {
963963
spinlock_t unused_bgs_lock;
964964
struct list_head unused_bgs;
965965
struct mutex unused_bg_unpin_mutex;
966-
struct mutex delete_unused_bgs_mutex;
966+
/* Protect block groups that are going to be deleted */
967+
struct mutex reclaim_bgs_lock;
967968

968969
/* Cached block sizes */
969970
u32 nodesize;

fs/btrfs/disk-io.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,10 +1890,10 @@ static int cleaner_kthread(void *arg)
18901890
btrfs_run_defrag_inodes(fs_info);
18911891

18921892
/*
1893-
* Acquires fs_info->delete_unused_bgs_mutex to avoid racing
1893+
* Acquires fs_info->reclaim_bgs_lock to avoid racing
18941894
* with relocation (btrfs_relocate_chunk) and relocation
18951895
* acquires fs_info->cleaner_mutex (btrfs_relocate_block_group)
1896-
* after acquiring fs_info->delete_unused_bgs_mutex. So we
1896+
* after acquiring fs_info->reclaim_bgs_lock. So we
18971897
* can't hold, nor need to, fs_info->cleaner_mutex when deleting
18981898
* unused block groups.
18991899
*/
@@ -2876,7 +2876,7 @@ void btrfs_init_fs_info(struct btrfs_fs_info *fs_info)
28762876
spin_lock_init(&fs_info->treelog_bg_lock);
28772877
rwlock_init(&fs_info->tree_mod_log_lock);
28782878
mutex_init(&fs_info->unused_bg_unpin_mutex);
2879-
mutex_init(&fs_info->delete_unused_bgs_mutex);
2879+
mutex_init(&fs_info->reclaim_bgs_lock);
28802880
mutex_init(&fs_info->reloc_mutex);
28812881
mutex_init(&fs_info->delalloc_root_mutex);
28822882
mutex_init(&fs_info->zoned_meta_io_lock);

fs/btrfs/volumes.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3118,7 +3118,7 @@ static int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset)
31183118
* we release the path used to search the chunk/dev tree and before
31193119
* the current task acquires this mutex and calls us.
31203120
*/
3121-
lockdep_assert_held(&fs_info->delete_unused_bgs_mutex);
3121+
lockdep_assert_held(&fs_info->reclaim_bgs_lock);
31223122

31233123
/* step one, relocate all the extents inside this chunk */
31243124
btrfs_scrub_pause(fs_info);
@@ -3188,18 +3188,18 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
31883188
key.type = BTRFS_CHUNK_ITEM_KEY;
31893189

31903190
while (1) {
3191-
mutex_lock(&fs_info->delete_unused_bgs_mutex);
3191+
mutex_lock(&fs_info->reclaim_bgs_lock);
31923192
ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
31933193
if (ret < 0) {
3194-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3194+
mutex_unlock(&fs_info->reclaim_bgs_lock);
31953195
goto error;
31963196
}
31973197
BUG_ON(ret == 0); /* Corruption */
31983198

31993199
ret = btrfs_previous_item(chunk_root, path, key.objectid,
32003200
key.type);
32013201
if (ret)
3202-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3202+
mutex_unlock(&fs_info->reclaim_bgs_lock);
32033203
if (ret < 0)
32043204
goto error;
32053205
if (ret > 0)
@@ -3220,7 +3220,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
32203220
else
32213221
BUG_ON(ret);
32223222
}
3223-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3223+
mutex_unlock(&fs_info->reclaim_bgs_lock);
32243224

32253225
if (found_key.offset == 0)
32263226
break;
@@ -3760,10 +3760,10 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
37603760
goto error;
37613761
}
37623762

3763-
mutex_lock(&fs_info->delete_unused_bgs_mutex);
3763+
mutex_lock(&fs_info->reclaim_bgs_lock);
37643764
ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
37653765
if (ret < 0) {
3766-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3766+
mutex_unlock(&fs_info->reclaim_bgs_lock);
37673767
goto error;
37683768
}
37693769

@@ -3777,7 +3777,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
37773777
ret = btrfs_previous_item(chunk_root, path, 0,
37783778
BTRFS_CHUNK_ITEM_KEY);
37793779
if (ret) {
3780-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3780+
mutex_unlock(&fs_info->reclaim_bgs_lock);
37813781
ret = 0;
37823782
break;
37833783
}
@@ -3787,7 +3787,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
37873787
btrfs_item_key_to_cpu(leaf, &found_key, slot);
37883788

37893789
if (found_key.objectid != key.objectid) {
3790-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3790+
mutex_unlock(&fs_info->reclaim_bgs_lock);
37913791
break;
37923792
}
37933793

@@ -3804,12 +3804,12 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
38043804

38053805
btrfs_release_path(path);
38063806
if (!ret) {
3807-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3807+
mutex_unlock(&fs_info->reclaim_bgs_lock);
38083808
goto loop;
38093809
}
38103810

38113811
if (counting) {
3812-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3812+
mutex_unlock(&fs_info->reclaim_bgs_lock);
38133813
spin_lock(&fs_info->balance_lock);
38143814
bctl->stat.expected++;
38153815
spin_unlock(&fs_info->balance_lock);
@@ -3834,7 +3834,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
38343834
count_meta < bctl->meta.limit_min)
38353835
|| ((chunk_type & BTRFS_BLOCK_GROUP_SYSTEM) &&
38363836
count_sys < bctl->sys.limit_min)) {
3837-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3837+
mutex_unlock(&fs_info->reclaim_bgs_lock);
38383838
goto loop;
38393839
}
38403840

@@ -3848,15 +3848,15 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)
38483848
ret = btrfs_may_alloc_data_chunk(fs_info,
38493849
found_key.offset);
38503850
if (ret < 0) {
3851-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3851+
mutex_unlock(&fs_info->reclaim_bgs_lock);
38523852
goto error;
38533853
} else if (ret == 1) {
38543854
chunk_reserved = 1;
38553855
}
38563856
}
38573857

38583858
ret = btrfs_relocate_chunk(fs_info, found_key.offset);
3859-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
3859+
mutex_unlock(&fs_info->reclaim_bgs_lock);
38603860
if (ret == -ENOSPC) {
38613861
enospc_errors++;
38623862
} else if (ret == -ETXTBSY) {
@@ -4741,16 +4741,16 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
47414741
key.type = BTRFS_DEV_EXTENT_KEY;
47424742

47434743
do {
4744-
mutex_lock(&fs_info->delete_unused_bgs_mutex);
4744+
mutex_lock(&fs_info->reclaim_bgs_lock);
47454745
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
47464746
if (ret < 0) {
4747-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
4747+
mutex_unlock(&fs_info->reclaim_bgs_lock);
47484748
goto done;
47494749
}
47504750

47514751
ret = btrfs_previous_item(root, path, 0, key.type);
47524752
if (ret) {
4753-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
4753+
mutex_unlock(&fs_info->reclaim_bgs_lock);
47544754
if (ret < 0)
47554755
goto done;
47564756
ret = 0;
@@ -4763,7 +4763,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
47634763
btrfs_item_key_to_cpu(l, &key, path->slots[0]);
47644764

47654765
if (key.objectid != device->devid) {
4766-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
4766+
mutex_unlock(&fs_info->reclaim_bgs_lock);
47674767
btrfs_release_path(path);
47684768
break;
47694769
}
@@ -4772,7 +4772,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
47724772
length = btrfs_dev_extent_length(l, dev_extent);
47734773

47744774
if (key.offset + length <= new_size) {
4775-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
4775+
mutex_unlock(&fs_info->reclaim_bgs_lock);
47764776
btrfs_release_path(path);
47774777
break;
47784778
}
@@ -4788,12 +4788,12 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
47884788
*/
47894789
ret = btrfs_may_alloc_data_chunk(fs_info, chunk_offset);
47904790
if (ret < 0) {
4791-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
4791+
mutex_unlock(&fs_info->reclaim_bgs_lock);
47924792
goto done;
47934793
}
47944794

47954795
ret = btrfs_relocate_chunk(fs_info, chunk_offset);
4796-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
4796+
mutex_unlock(&fs_info->reclaim_bgs_lock);
47974797
if (ret == -ENOSPC) {
47984798
failed++;
47994799
} else if (ret) {
@@ -8068,7 +8068,7 @@ static int relocating_repair_kthread(void *data)
80688068
return -EBUSY;
80698069
}
80708070

8071-
mutex_lock(&fs_info->delete_unused_bgs_mutex);
8071+
mutex_lock(&fs_info->reclaim_bgs_lock);
80728072

80738073
/* Ensure block group still exists */
80748074
cache = btrfs_lookup_block_group(fs_info, target);
@@ -8090,7 +8090,7 @@ static int relocating_repair_kthread(void *data)
80908090
out:
80918091
if (cache)
80928092
btrfs_put_block_group(cache);
8093-
mutex_unlock(&fs_info->delete_unused_bgs_mutex);
8093+
mutex_unlock(&fs_info->reclaim_bgs_lock);
80948094
btrfs_exclop_finish(fs_info);
80958095

80968096
return ret;

0 commit comments

Comments
 (0)