Btrfs: Replace the big fs_mutex with a collection of other locks
Extent alloctions are still protected by a large alloc_mutex.
Objectid allocations are covered by a objectid mutex
Other btree operations are protected by a lock on individual btree nodes
Signed-off-by: Chris Mason <chris.mason@oracle.com>
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index ba39685..869864d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -866,7 +866,8 @@
u64 devid;
int ret = 0;
- mutex_lock(&root->fs_info->fs_mutex);
+ mutex_lock(&root->fs_info->alloc_mutex);
+ mutex_lock(&root->fs_info->chunk_mutex);
mutex_lock(&uuid_mutex);
all_avail = root->fs_info->avail_data_alloc_bits |
@@ -984,7 +985,8 @@
close_bdev_excl(bdev);
out:
mutex_unlock(&uuid_mutex);
- mutex_unlock(&root->fs_info->fs_mutex);
+ mutex_unlock(&root->fs_info->chunk_mutex);
+ mutex_unlock(&root->fs_info->alloc_mutex);
return ret;
}
@@ -1003,7 +1005,10 @@
if (!bdev) {
return -EIO;
}
- mutex_lock(&root->fs_info->fs_mutex);
+
+ mutex_lock(&root->fs_info->alloc_mutex);
+ mutex_lock(&root->fs_info->chunk_mutex);
+
trans = btrfs_start_transaction(root, 1);
devices = &root->fs_info->fs_devices->devices;
list_for_each(cur, devices) {
@@ -1057,7 +1062,9 @@
root->fs_info->fs_devices->open_devices++;
out:
btrfs_end_transaction(trans, root);
- mutex_unlock(&root->fs_info->fs_mutex);
+ mutex_unlock(&root->fs_info->chunk_mutex);
+ mutex_unlock(&root->fs_info->alloc_mutex);
+
return ret;
out_close_bdev:
@@ -1297,9 +1304,10 @@
struct btrfs_key found_key;
+ BUG(); /* FIXME, needs locking */
+
dev_root = dev_root->fs_info->dev_root;
- mutex_lock(&dev_root->fs_info->fs_mutex);
/* step one make some room on all the devices */
list_for_each(cur, devices) {
device = list_entry(cur, struct btrfs_device, dev_list);
@@ -1368,7 +1376,6 @@
ret = 0;
error:
btrfs_free_path(path);
- mutex_unlock(&dev_root->fs_info->fs_mutex);
return ret;
}