Commit 34441361 authored by David Sterba's avatar David Sterba

btrfs: opencode chunk locking, remove helpers

The helpers are trivial and we don't use them consistently.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 3a45bb20
...@@ -4003,7 +4003,7 @@ void close_ctree(struct btrfs_fs_info *fs_info) ...@@ -4003,7 +4003,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
__btrfs_free_block_rsv(root->orphan_block_rsv); __btrfs_free_block_rsv(root->orphan_block_rsv);
root->orphan_block_rsv = NULL; root->orphan_block_rsv = NULL;
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
while (!list_empty(&fs_info->pinned_chunks)) { while (!list_empty(&fs_info->pinned_chunks)) {
struct extent_map *em; struct extent_map *em;
...@@ -4012,7 +4012,7 @@ void close_ctree(struct btrfs_fs_info *fs_info) ...@@ -4012,7 +4012,7 @@ void close_ctree(struct btrfs_fs_info *fs_info)
list_del_init(&em->list); list_del_init(&em->list);
free_extent_map(em); free_extent_map(em);
} }
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
} }
int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid, int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid,
......
...@@ -9419,9 +9419,9 @@ int btrfs_inc_block_group_ro(struct btrfs_root *root, ...@@ -9419,9 +9419,9 @@ int btrfs_inc_block_group_ro(struct btrfs_root *root,
out: out:
if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) { if (cache->flags & BTRFS_BLOCK_GROUP_SYSTEM) {
alloc_flags = update_block_group_flags(fs_info, cache->flags); alloc_flags = update_block_group_flags(fs_info, cache->flags);
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
check_system_chunk(trans, fs_info, alloc_flags); check_system_chunk(trans, fs_info, alloc_flags);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
} }
mutex_unlock(&fs_info->ro_block_group_mutex); mutex_unlock(&fs_info->ro_block_group_mutex);
...@@ -10458,7 +10458,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, ...@@ -10458,7 +10458,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
memcpy(&key, &block_group->key, sizeof(key)); memcpy(&key, &block_group->key, sizeof(key));
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
if (!list_empty(&em->list)) { if (!list_empty(&em->list)) {
/* We're in the transaction->pending_chunks list. */ /* We're in the transaction->pending_chunks list. */
free_extent_map(em); free_extent_map(em);
...@@ -10526,7 +10526,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans, ...@@ -10526,7 +10526,7 @@ int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
free_extent_map(em); free_extent_map(em);
} }
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
ret = remove_block_group_free_space(trans, fs_info, block_group); ret = remove_block_group_free_space(trans, fs_info, block_group);
if (ret) if (ret)
......
...@@ -3352,7 +3352,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group) ...@@ -3352,7 +3352,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group)
spin_unlock(&block_group->lock); spin_unlock(&block_group->lock);
if (cleanup) { if (cleanup) {
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
em_tree = &fs_info->mapping_tree.map_tree; em_tree = &fs_info->mapping_tree.map_tree;
write_lock(&em_tree->lock); write_lock(&em_tree->lock);
em = lookup_extent_mapping(em_tree, block_group->key.objectid, em = lookup_extent_mapping(em_tree, block_group->key.objectid,
...@@ -3364,7 +3364,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group) ...@@ -3364,7 +3364,7 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group)
*/ */
remove_extent_mapping(em_tree, em); remove_extent_mapping(em_tree, em);
write_unlock(&em_tree->lock); write_unlock(&em_tree->lock);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
/* once for us and once for the tree */ /* once for us and once for the tree */
free_extent_map(em); free_extent_map(em);
......
...@@ -1890,10 +1890,10 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, char *device_path, u64 devid) ...@@ -1890,10 +1890,10 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, char *device_path, u64 devid)
} }
if (device->writeable) { if (device->writeable) {
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
list_del_init(&device->dev_alloc_list); list_del_init(&device->dev_alloc_list);
device->fs_devices->rw_devices--; device->fs_devices->rw_devices--;
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
clear_super = true; clear_super = true;
} }
...@@ -1982,11 +1982,11 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, char *device_path, u64 devid) ...@@ -1982,11 +1982,11 @@ int btrfs_rm_device(struct btrfs_fs_info *fs_info, char *device_path, u64 devid)
error_undo: error_undo:
if (device->writeable) { if (device->writeable) {
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
list_add(&device->dev_alloc_list, list_add(&device->dev_alloc_list,
&fs_info->fs_devices->alloc_list); &fs_info->fs_devices->alloc_list);
device->fs_devices->rw_devices++; device->fs_devices->rw_devices++;
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
} }
goto out; goto out;
} }
...@@ -2211,9 +2211,9 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info) ...@@ -2211,9 +2211,9 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
list_for_each_entry(device, &seed_devices->devices, dev_list) list_for_each_entry(device, &seed_devices->devices, dev_list)
device->fs_devices = seed_devices; device->fs_devices = seed_devices;
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
list_splice_init(&fs_devices->alloc_list, &seed_devices->alloc_list); list_splice_init(&fs_devices->alloc_list, &seed_devices->alloc_list);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
fs_devices->seeding = 0; fs_devices->seeding = 0;
fs_devices->num_devices = 0; fs_devices->num_devices = 0;
...@@ -2402,7 +2402,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path) ...@@ -2402,7 +2402,7 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
device->fs_devices = fs_info->fs_devices; device->fs_devices = fs_info->fs_devices;
mutex_lock(&fs_info->fs_devices->device_list_mutex); mutex_lock(&fs_info->fs_devices->device_list_mutex);
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
list_add_rcu(&device->dev_list, &fs_info->fs_devices->devices); list_add_rcu(&device->dev_list, &fs_info->fs_devices->devices);
list_add(&device->dev_alloc_list, list_add(&device->dev_alloc_list,
&fs_info->fs_devices->alloc_list); &fs_info->fs_devices->alloc_list);
...@@ -2435,13 +2435,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path) ...@@ -2435,13 +2435,13 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, char *device_path)
*/ */
btrfs_clear_space_info_full(fs_info); btrfs_clear_space_info_full(fs_info);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
mutex_unlock(&fs_info->fs_devices->device_list_mutex); mutex_unlock(&fs_info->fs_devices->device_list_mutex);
if (seeding_dev) { if (seeding_dev) {
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
ret = init_first_rw_device(trans, fs_info, device); ret = init_first_rw_device(trans, fs_info, device);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
if (ret) { if (ret) {
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
goto error_trans; goto error_trans;
...@@ -2684,13 +2684,13 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans, ...@@ -2684,13 +2684,13 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
if (!device->writeable) if (!device->writeable)
return -EACCES; return -EACCES;
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
old_total = btrfs_super_total_bytes(super_copy); old_total = btrfs_super_total_bytes(super_copy);
diff = new_size - device->total_bytes; diff = new_size - device->total_bytes;
if (new_size <= device->total_bytes || if (new_size <= device->total_bytes ||
device->is_tgtdev_for_dev_replace) { device->is_tgtdev_for_dev_replace) {
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
return -EINVAL; return -EINVAL;
} }
...@@ -2705,7 +2705,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans, ...@@ -2705,7 +2705,7 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
if (list_empty(&device->resized_list)) if (list_empty(&device->resized_list))
list_add_tail(&device->resized_list, list_add_tail(&device->resized_list,
&fs_devices->resized_devices); &fs_devices->resized_devices);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
return btrfs_update_device(trans, device); return btrfs_update_device(trans, device);
} }
...@@ -2760,7 +2760,7 @@ static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info, ...@@ -2760,7 +2760,7 @@ static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info,
u32 cur; u32 cur;
struct btrfs_key key; struct btrfs_key key;
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
array_size = btrfs_super_sys_array_size(super_copy); array_size = btrfs_super_sys_array_size(super_copy);
ptr = super_copy->sys_chunk_array; ptr = super_copy->sys_chunk_array;
...@@ -2790,7 +2790,7 @@ static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info, ...@@ -2790,7 +2790,7 @@ static int btrfs_del_sys_chunk(struct btrfs_fs_info *fs_info,
cur += len; cur += len;
} }
} }
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
return ret; return ret;
} }
...@@ -2824,9 +2824,9 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, ...@@ -2824,9 +2824,9 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
return -EINVAL; return -EINVAL;
} }
map = em->map_lookup; map = em->map_lookup;
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
check_system_chunk(trans, fs_info, map->type); check_system_chunk(trans, fs_info, map->type);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
/* /*
* Take the device list mutex to prevent races with the final phase of * Take the device list mutex to prevent races with the final phase of
...@@ -2846,14 +2846,14 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans, ...@@ -2846,14 +2846,14 @@ int btrfs_remove_chunk(struct btrfs_trans_handle *trans,
} }
if (device->bytes_used > 0) { if (device->bytes_used > 0) {
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
btrfs_device_set_bytes_used(device, btrfs_device_set_bytes_used(device,
device->bytes_used - dev_extent_len); device->bytes_used - dev_extent_len);
spin_lock(&fs_info->free_chunk_lock); spin_lock(&fs_info->free_chunk_lock);
fs_info->free_chunk_space += dev_extent_len; fs_info->free_chunk_space += dev_extent_len;
spin_unlock(&fs_info->free_chunk_lock); spin_unlock(&fs_info->free_chunk_lock);
btrfs_clear_space_info_full(fs_info); btrfs_clear_space_info_full(fs_info);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
} }
if (map->stripes[i].dev) { if (map->stripes[i].dev) {
...@@ -4373,7 +4373,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4373,7 +4373,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
path->reada = READA_FORWARD; path->reada = READA_FORWARD;
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
btrfs_device_set_total_bytes(device, new_size); btrfs_device_set_total_bytes(device, new_size);
if (device->writeable) { if (device->writeable) {
...@@ -4382,7 +4382,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4382,7 +4382,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
fs_info->free_chunk_space -= diff; fs_info->free_chunk_space -= diff;
spin_unlock(&fs_info->free_chunk_lock); spin_unlock(&fs_info->free_chunk_lock);
} }
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
again: again:
key.objectid = device->devid; key.objectid = device->devid;
...@@ -4454,7 +4454,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4454,7 +4454,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
goto done; goto done;
} }
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
/* /*
* We checked in the above loop all device extents that were already in * We checked in the above loop all device extents that were already in
...@@ -4474,7 +4474,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4474,7 +4474,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
if (contains_pending_extent(trans->transaction, device, if (contains_pending_extent(trans->transaction, device,
&start, len)) { &start, len)) {
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
checked_pending_chunks = true; checked_pending_chunks = true;
failed = 0; failed = 0;
retried = false; retried = false;
...@@ -4492,7 +4492,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4492,7 +4492,7 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
WARN_ON(diff > old_total); WARN_ON(diff > old_total);
btrfs_set_super_total_bytes(super_copy, old_total - diff); btrfs_set_super_total_bytes(super_copy, old_total - diff);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
/* Now btrfs_update_device() will change the on-disk size. */ /* Now btrfs_update_device() will change the on-disk size. */
ret = btrfs_update_device(trans, device); ret = btrfs_update_device(trans, device);
...@@ -4500,14 +4500,14 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size) ...@@ -4500,14 +4500,14 @@ int btrfs_shrink_device(struct btrfs_device *device, u64 new_size)
done: done:
btrfs_free_path(path); btrfs_free_path(path);
if (ret) { if (ret) {
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
btrfs_device_set_total_bytes(device, old_size); btrfs_device_set_total_bytes(device, old_size);
if (device->writeable) if (device->writeable)
device->fs_devices->total_rw_bytes += diff; device->fs_devices->total_rw_bytes += diff;
spin_lock(&fs_info->free_chunk_lock); spin_lock(&fs_info->free_chunk_lock);
fs_info->free_chunk_space += diff; fs_info->free_chunk_space += diff;
spin_unlock(&fs_info->free_chunk_lock); spin_unlock(&fs_info->free_chunk_lock);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
} }
return ret; return ret;
} }
...@@ -4521,11 +4521,11 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info, ...@@ -4521,11 +4521,11 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
u32 array_size; u32 array_size;
u8 *ptr; u8 *ptr;
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
array_size = btrfs_super_sys_array_size(super_copy); array_size = btrfs_super_sys_array_size(super_copy);
if (array_size + item_size + sizeof(disk_key) if (array_size + item_size + sizeof(disk_key)
> BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) { > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) {
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
return -EFBIG; return -EFBIG;
} }
...@@ -4536,7 +4536,7 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info, ...@@ -4536,7 +4536,7 @@ static int btrfs_add_system_chunk(struct btrfs_fs_info *fs_info,
memcpy(ptr, chunk, item_size); memcpy(ptr, chunk, item_size);
item_size += sizeof(disk_key); item_size += sizeof(disk_key);
btrfs_set_super_sys_array_size(super_copy, array_size + item_size); btrfs_set_super_sys_array_size(super_copy, array_size + item_size);
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
return 0; return 0;
} }
...@@ -6783,7 +6783,7 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info) ...@@ -6783,7 +6783,7 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
return -ENOMEM; return -ENOMEM;
mutex_lock(&uuid_mutex); mutex_lock(&uuid_mutex);
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
/* /*
* Read all device items, and then all the chunk items. All * Read all device items, and then all the chunk items. All
...@@ -6850,7 +6850,7 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info) ...@@ -6850,7 +6850,7 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
} }
ret = 0; ret = 0;
error: error:
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
mutex_unlock(&uuid_mutex); mutex_unlock(&uuid_mutex);
btrfs_free_path(path); btrfs_free_path(path);
...@@ -7149,13 +7149,13 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info) ...@@ -7149,13 +7149,13 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info)
return; return;
mutex_lock(&fs_devices->device_list_mutex); mutex_lock(&fs_devices->device_list_mutex);
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
list_for_each_entry_safe(curr, next, &fs_devices->resized_devices, list_for_each_entry_safe(curr, next, &fs_devices->resized_devices,
resized_list) { resized_list) {
list_del_init(&curr->resized_list); list_del_init(&curr->resized_list);
curr->commit_total_bytes = curr->disk_total_bytes; curr->commit_total_bytes = curr->disk_total_bytes;
} }
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
mutex_unlock(&fs_devices->device_list_mutex); mutex_unlock(&fs_devices->device_list_mutex);
} }
...@@ -7172,7 +7172,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info, ...@@ -7172,7 +7172,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info,
return; return;
/* In order to kick the device replace finish process */ /* In order to kick the device replace finish process */
lock_chunks(fs_info); mutex_lock(&fs_info->chunk_mutex);
list_for_each_entry(em, &transaction->pending_chunks, list) { list_for_each_entry(em, &transaction->pending_chunks, list) {
map = em->map_lookup; map = em->map_lookup;
...@@ -7181,7 +7181,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info, ...@@ -7181,7 +7181,7 @@ void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info,
dev->commit_bytes_used = dev->bytes_used; dev->commit_bytes_used = dev->bytes_used;
} }
} }
unlock_chunks(fs_info); mutex_unlock(&fs_info->chunk_mutex);
} }
void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info) void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info)
......
...@@ -534,16 +534,6 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info); ...@@ -534,16 +534,6 @@ void btrfs_update_commit_device_size(struct btrfs_fs_info *fs_info);
void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info, void btrfs_update_commit_device_bytes_used(struct btrfs_fs_info *fs_info,
struct btrfs_transaction *transaction); struct btrfs_transaction *transaction);
static inline void lock_chunks(struct btrfs_fs_info *fs_info)
{
mutex_lock(&fs_info->chunk_mutex);
}
static inline void unlock_chunks(struct btrfs_fs_info *fs_info)
{
mutex_unlock(&fs_info->chunk_mutex);
}
struct list_head *btrfs_get_fs_uuids(void); struct list_head *btrfs_get_fs_uuids(void);
void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info); void btrfs_set_fs_info_ptr(struct btrfs_fs_info *fs_info);
void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info); void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info);
......
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