diff options
author | Chris Mason <chris.mason@oracle.com> | 2008-06-25 16:01:30 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2008-09-25 11:04:03 -0400 |
commit | a213501153fd66e2359e091b1612841305ba6551 (patch) | |
tree | 1f4c316c9d3cad0eb6d9be14cb0e67e46e815dce /fs/btrfs/inode.c | |
parent | 925baeddc5b0764a53f2214a1253251bab0e0324 (diff) |
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>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 76 |
1 files changed, 6 insertions, 70 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 61bd8953a683..b2251e27ac84 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -79,12 +79,15 @@ static unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { | |||
79 | int btrfs_check_free_space(struct btrfs_root *root, u64 num_required, | 79 | int btrfs_check_free_space(struct btrfs_root *root, u64 num_required, |
80 | int for_del) | 80 | int for_del) |
81 | { | 81 | { |
82 | u64 total = btrfs_super_total_bytes(&root->fs_info->super_copy); | 82 | u64 total; |
83 | u64 used = btrfs_super_bytes_used(&root->fs_info->super_copy); | 83 | u64 used; |
84 | u64 thresh; | 84 | u64 thresh; |
85 | unsigned long flags; | 85 | unsigned long flags; |
86 | int ret = 0; | 86 | int ret = 0; |
87 | 87 | ||
88 | spin_lock_irqsave(&root->fs_info->delalloc_lock, flags); | ||
89 | total = btrfs_super_total_bytes(&root->fs_info->super_copy); | ||
90 | used = btrfs_super_bytes_used(&root->fs_info->super_copy); | ||
88 | if (for_del) | 91 | if (for_del) |
89 | thresh = total * 90; | 92 | thresh = total * 90; |
90 | else | 93 | else |
@@ -92,7 +95,6 @@ int btrfs_check_free_space(struct btrfs_root *root, u64 num_required, | |||
92 | 95 | ||
93 | do_div(thresh, 100); | 96 | do_div(thresh, 100); |
94 | 97 | ||
95 | spin_lock_irqsave(&root->fs_info->delalloc_lock, flags); | ||
96 | if (used + root->fs_info->delalloc_bytes + num_required > thresh) | 98 | if (used + root->fs_info->delalloc_bytes + num_required > thresh) |
97 | ret = -ENOSPC; | 99 | ret = -ENOSPC; |
98 | spin_unlock_irqrestore(&root->fs_info->delalloc_lock, flags); | 100 | spin_unlock_irqrestore(&root->fs_info->delalloc_lock, flags); |
@@ -115,7 +117,6 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end) | |||
115 | trans = btrfs_start_transaction(root, 1); | 117 | trans = btrfs_start_transaction(root, 1); |
116 | BUG_ON(!trans); | 118 | BUG_ON(!trans); |
117 | btrfs_set_trans_block_group(trans, inode); | 119 | btrfs_set_trans_block_group(trans, inode); |
118 | mutex_unlock(&root->fs_info->fs_mutex); | ||
119 | 120 | ||
120 | num_bytes = (end - start + blocksize) & ~(blocksize - 1); | 121 | num_bytes = (end - start + blocksize) & ~(blocksize - 1); |
121 | num_bytes = max(blocksize, num_bytes); | 122 | num_bytes = max(blocksize, num_bytes); |
@@ -160,7 +161,6 @@ static int cow_file_range(struct inode *inode, u64 start, u64 end) | |||
160 | btrfs_add_ordered_inode(inode); | 161 | btrfs_add_ordered_inode(inode); |
161 | btrfs_update_inode(trans, root, inode); | 162 | btrfs_update_inode(trans, root, inode); |
162 | out: | 163 | out: |
163 | mutex_lock(&root->fs_info->fs_mutex); | ||
164 | btrfs_end_transaction(trans, root); | 164 | btrfs_end_transaction(trans, root); |
165 | return ret; | 165 | return ret; |
166 | } | 166 | } |
@@ -269,14 +269,13 @@ static int run_delalloc_range(struct inode *inode, u64 start, u64 end) | |||
269 | { | 269 | { |
270 | struct btrfs_root *root = BTRFS_I(inode)->root; | 270 | struct btrfs_root *root = BTRFS_I(inode)->root; |
271 | int ret; | 271 | int ret; |
272 | mutex_lock(&root->fs_info->fs_mutex); | 272 | |
273 | if (btrfs_test_opt(root, NODATACOW) || | 273 | if (btrfs_test_opt(root, NODATACOW) || |
274 | btrfs_test_flag(inode, NODATACOW)) | 274 | btrfs_test_flag(inode, NODATACOW)) |
275 | ret = run_delalloc_nocow(inode, start, end); | 275 | ret = run_delalloc_nocow(inode, start, end); |
276 | else | 276 | else |
277 | ret = cow_file_range(inode, start, end); | 277 | ret = cow_file_range(inode, start, end); |
278 | 278 | ||
279 | mutex_unlock(&root->fs_info->fs_mutex); | ||
280 | return ret; | 279 | return ret; |
281 | } | 280 | } |
282 | 281 | ||
@@ -349,17 +348,13 @@ int __btrfs_submit_bio_hook(struct inode *inode, int rw, struct bio *bio, | |||
349 | ret = btrfs_csum_one_bio(root, bio, &sums); | 348 | ret = btrfs_csum_one_bio(root, bio, &sums); |
350 | BUG_ON(ret); | 349 | BUG_ON(ret); |
351 | 350 | ||
352 | mutex_lock(&root->fs_info->fs_mutex); | ||
353 | trans = btrfs_start_transaction(root, 1); | 351 | trans = btrfs_start_transaction(root, 1); |
354 | mutex_unlock(&root->fs_info->fs_mutex); | ||
355 | 352 | ||
356 | btrfs_set_trans_block_group(trans, inode); | 353 | btrfs_set_trans_block_group(trans, inode); |
357 | btrfs_csum_file_blocks(trans, root, inode, bio, sums); | 354 | btrfs_csum_file_blocks(trans, root, inode, bio, sums); |
358 | 355 | ||
359 | mutex_lock(&root->fs_info->fs_mutex); | ||
360 | ret = btrfs_end_transaction(trans, root); | 356 | ret = btrfs_end_transaction(trans, root); |
361 | BUG_ON(ret); | 357 | BUG_ON(ret); |
362 | mutex_unlock(&root->fs_info->fs_mutex); | ||
363 | 358 | ||
364 | kfree(sums); | 359 | kfree(sums); |
365 | 360 | ||
@@ -404,7 +399,6 @@ int btrfs_readpage_io_hook(struct page *page, u64 start, u64 end) | |||
404 | btrfs_test_flag(inode, NODATASUM)) | 399 | btrfs_test_flag(inode, NODATASUM)) |
405 | return 0; | 400 | return 0; |
406 | 401 | ||
407 | mutex_lock(&root->fs_info->fs_mutex); | ||
408 | path = btrfs_alloc_path(); | 402 | path = btrfs_alloc_path(); |
409 | item = btrfs_lookup_csum(NULL, root, path, inode->i_ino, start, 0); | 403 | item = btrfs_lookup_csum(NULL, root, path, inode->i_ino, start, 0); |
410 | if (IS_ERR(item)) { | 404 | if (IS_ERR(item)) { |
@@ -422,7 +416,6 @@ int btrfs_readpage_io_hook(struct page *page, u64 start, u64 end) | |||
422 | out: | 416 | out: |
423 | if (path) | 417 | if (path) |
424 | btrfs_free_path(path); | 418 | btrfs_free_path(path); |
425 | mutex_unlock(&root->fs_info->fs_mutex); | ||
426 | return ret; | 419 | return ret; |
427 | } | 420 | } |
428 | 421 | ||
@@ -616,7 +609,6 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
616 | 609 | ||
617 | path = btrfs_alloc_path(); | 610 | path = btrfs_alloc_path(); |
618 | BUG_ON(!path); | 611 | BUG_ON(!path); |
619 | mutex_lock(&root->fs_info->fs_mutex); | ||
620 | memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); | 612 | memcpy(&location, &BTRFS_I(inode)->location, sizeof(location)); |
621 | 613 | ||
622 | ret = btrfs_lookup_inode(NULL, root, path, &location, 0); | 614 | ret = btrfs_lookup_inode(NULL, root, path, &location, 0); |
@@ -662,8 +654,6 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
662 | btrfs_free_path(path); | 654 | btrfs_free_path(path); |
663 | inode_item = NULL; | 655 | inode_item = NULL; |
664 | 656 | ||
665 | mutex_unlock(&root->fs_info->fs_mutex); | ||
666 | |||
667 | switch (inode->i_mode & S_IFMT) { | 657 | switch (inode->i_mode & S_IFMT) { |
668 | case S_IFREG: | 658 | case S_IFREG: |
669 | inode->i_mapping->a_ops = &btrfs_aops; | 659 | inode->i_mapping->a_ops = &btrfs_aops; |
@@ -691,9 +681,7 @@ void btrfs_read_locked_inode(struct inode *inode) | |||
691 | return; | 681 | return; |
692 | 682 | ||
693 | make_bad: | 683 | make_bad: |
694 | btrfs_release_path(root, path); | ||
695 | btrfs_free_path(path); | 684 | btrfs_free_path(path); |
696 | mutex_unlock(&root->fs_info->fs_mutex); | ||
697 | make_bad_inode(inode); | 685 | make_bad_inode(inode); |
698 | } | 686 | } |
699 | 687 | ||
@@ -758,7 +746,6 @@ int btrfs_update_inode(struct btrfs_trans_handle *trans, | |||
758 | btrfs_set_inode_last_trans(trans, inode); | 746 | btrfs_set_inode_last_trans(trans, inode); |
759 | ret = 0; | 747 | ret = 0; |
760 | failed: | 748 | failed: |
761 | btrfs_release_path(root, path); | ||
762 | btrfs_free_path(path); | 749 | btrfs_free_path(path); |
763 | return ret; | 750 | return ret; |
764 | } | 751 | } |
@@ -849,7 +836,6 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) | |||
849 | unsigned long nr = 0; | 836 | unsigned long nr = 0; |
850 | 837 | ||
851 | root = BTRFS_I(dir)->root; | 838 | root = BTRFS_I(dir)->root; |
852 | mutex_lock(&root->fs_info->fs_mutex); | ||
853 | 839 | ||
854 | ret = btrfs_check_free_space(root, 1, 1); | 840 | ret = btrfs_check_free_space(root, 1, 1); |
855 | if (ret) | 841 | if (ret) |
@@ -871,7 +857,6 @@ static int btrfs_unlink(struct inode *dir, struct dentry *dentry) | |||
871 | 857 | ||
872 | btrfs_end_transaction(trans, root); | 858 | btrfs_end_transaction(trans, root); |
873 | fail: | 859 | fail: |
874 | mutex_unlock(&root->fs_info->fs_mutex); | ||
875 | btrfs_btree_balance_dirty(root, nr); | 860 | btrfs_btree_balance_dirty(root, nr); |
876 | btrfs_throttle(root); | 861 | btrfs_throttle(root); |
877 | return ret; | 862 | return ret; |
@@ -890,7 +875,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
890 | return -ENOTEMPTY; | 875 | return -ENOTEMPTY; |
891 | } | 876 | } |
892 | 877 | ||
893 | mutex_lock(&root->fs_info->fs_mutex); | ||
894 | ret = btrfs_check_free_space(root, 1, 1); | 878 | ret = btrfs_check_free_space(root, 1, 1); |
895 | if (ret) | 879 | if (ret) |
896 | goto fail; | 880 | goto fail; |
@@ -907,7 +891,6 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) | |||
907 | nr = trans->blocks_used; | 891 | nr = trans->blocks_used; |
908 | ret = btrfs_end_transaction(trans, root); | 892 | ret = btrfs_end_transaction(trans, root); |
909 | fail: | 893 | fail: |
910 | mutex_unlock(&root->fs_info->fs_mutex); | ||
911 | btrfs_btree_balance_dirty(root, nr); | 894 | btrfs_btree_balance_dirty(root, nr); |
912 | btrfs_throttle(root); | 895 | btrfs_throttle(root); |
913 | 896 | ||
@@ -1129,7 +1112,6 @@ error: | |||
1129 | ret = btrfs_del_items(trans, root, path, pending_del_slot, | 1112 | ret = btrfs_del_items(trans, root, path, pending_del_slot, |
1130 | pending_del_nr); | 1113 | pending_del_nr); |
1131 | } | 1114 | } |
1132 | btrfs_release_path(root, path); | ||
1133 | btrfs_free_path(path); | 1115 | btrfs_free_path(path); |
1134 | inode->i_sb->s_dirt = 1; | 1116 | inode->i_sb->s_dirt = 1; |
1135 | return ret; | 1117 | return ret; |
@@ -1234,9 +1216,7 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
1234 | if (attr->ia_size <= hole_start) | 1216 | if (attr->ia_size <= hole_start) |
1235 | goto out; | 1217 | goto out; |
1236 | 1218 | ||
1237 | mutex_lock(&root->fs_info->fs_mutex); | ||
1238 | err = btrfs_check_free_space(root, 1, 0); | 1219 | err = btrfs_check_free_space(root, 1, 0); |
1239 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1240 | if (err) | 1220 | if (err) |
1241 | goto fail; | 1221 | goto fail; |
1242 | 1222 | ||
@@ -1245,7 +1225,6 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
1245 | lock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); | 1225 | lock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); |
1246 | hole_size = block_end - hole_start; | 1226 | hole_size = block_end - hole_start; |
1247 | 1227 | ||
1248 | mutex_lock(&root->fs_info->fs_mutex); | ||
1249 | trans = btrfs_start_transaction(root, 1); | 1228 | trans = btrfs_start_transaction(root, 1); |
1250 | btrfs_set_trans_block_group(trans, inode); | 1229 | btrfs_set_trans_block_group(trans, inode); |
1251 | err = btrfs_drop_extents(trans, root, inode, | 1230 | err = btrfs_drop_extents(trans, root, inode, |
@@ -1262,7 +1241,6 @@ static int btrfs_setattr(struct dentry *dentry, struct iattr *attr) | |||
1262 | btrfs_check_file(root, inode); | 1241 | btrfs_check_file(root, inode); |
1263 | } | 1242 | } |
1264 | btrfs_end_transaction(trans, root); | 1243 | btrfs_end_transaction(trans, root); |
1265 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1266 | unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); | 1244 | unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); |
1267 | if (err) | 1245 | if (err) |
1268 | return err; | 1246 | return err; |
@@ -1286,7 +1264,6 @@ void btrfs_delete_inode(struct inode *inode) | |||
1286 | } | 1264 | } |
1287 | 1265 | ||
1288 | inode->i_size = 0; | 1266 | inode->i_size = 0; |
1289 | mutex_lock(&root->fs_info->fs_mutex); | ||
1290 | trans = btrfs_start_transaction(root, 1); | 1267 | trans = btrfs_start_transaction(root, 1); |
1291 | 1268 | ||
1292 | btrfs_set_trans_block_group(trans, inode); | 1269 | btrfs_set_trans_block_group(trans, inode); |
@@ -1298,7 +1275,6 @@ void btrfs_delete_inode(struct inode *inode) | |||
1298 | clear_inode(inode); | 1275 | clear_inode(inode); |
1299 | 1276 | ||
1300 | btrfs_end_transaction(trans, root); | 1277 | btrfs_end_transaction(trans, root); |
1301 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1302 | btrfs_btree_balance_dirty(root, nr); | 1278 | btrfs_btree_balance_dirty(root, nr); |
1303 | btrfs_throttle(root); | 1279 | btrfs_throttle(root); |
1304 | return; | 1280 | return; |
@@ -1306,7 +1282,6 @@ void btrfs_delete_inode(struct inode *inode) | |||
1306 | no_delete_lock: | 1282 | no_delete_lock: |
1307 | nr = trans->blocks_used; | 1283 | nr = trans->blocks_used; |
1308 | btrfs_end_transaction(trans, root); | 1284 | btrfs_end_transaction(trans, root); |
1309 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1310 | btrfs_btree_balance_dirty(root, nr); | 1285 | btrfs_btree_balance_dirty(root, nr); |
1311 | btrfs_throttle(root); | 1286 | btrfs_throttle(root); |
1312 | no_delete: | 1287 | no_delete: |
@@ -1402,7 +1377,6 @@ static int fixup_tree_root_location(struct btrfs_root *root, | |||
1402 | 1377 | ||
1403 | path = btrfs_alloc_path(); | 1378 | path = btrfs_alloc_path(); |
1404 | BUG_ON(!path); | 1379 | BUG_ON(!path); |
1405 | mutex_lock(&root->fs_info->fs_mutex); | ||
1406 | 1380 | ||
1407 | *sub_root = btrfs_read_fs_root(root->fs_info, location, | 1381 | *sub_root = btrfs_read_fs_root(root->fs_info, location, |
1408 | dentry->d_name.name, | 1382 | dentry->d_name.name, |
@@ -1416,7 +1390,6 @@ static int fixup_tree_root_location(struct btrfs_root *root, | |||
1416 | location->offset = 0; | 1390 | location->offset = 0; |
1417 | 1391 | ||
1418 | btrfs_free_path(path); | 1392 | btrfs_free_path(path); |
1419 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1420 | return 0; | 1393 | return 0; |
1421 | } | 1394 | } |
1422 | 1395 | ||
@@ -1482,9 +1455,7 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, | |||
1482 | if (dentry->d_name.len > BTRFS_NAME_LEN) | 1455 | if (dentry->d_name.len > BTRFS_NAME_LEN) |
1483 | return ERR_PTR(-ENAMETOOLONG); | 1456 | return ERR_PTR(-ENAMETOOLONG); |
1484 | 1457 | ||
1485 | mutex_lock(&root->fs_info->fs_mutex); | ||
1486 | ret = btrfs_inode_by_name(dir, dentry, &location); | 1458 | ret = btrfs_inode_by_name(dir, dentry, &location); |
1487 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1488 | 1459 | ||
1489 | if (ret < 0) | 1460 | if (ret < 0) |
1490 | return ERR_PTR(ret); | 1461 | return ERR_PTR(ret); |
@@ -1559,7 +1530,6 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir) | |||
1559 | filp->f_pos = 1; | 1530 | filp->f_pos = 1; |
1560 | } | 1531 | } |
1561 | 1532 | ||
1562 | mutex_lock(&root->fs_info->fs_mutex); | ||
1563 | key.objectid = inode->i_ino; | 1533 | key.objectid = inode->i_ino; |
1564 | path = btrfs_alloc_path(); | 1534 | path = btrfs_alloc_path(); |
1565 | path->reada = 2; | 1535 | path->reada = 2; |
@@ -1668,9 +1638,7 @@ read_dir_items: | |||
1668 | nopos: | 1638 | nopos: |
1669 | ret = 0; | 1639 | ret = 0; |
1670 | err: | 1640 | err: |
1671 | btrfs_release_path(root, path); | ||
1672 | btrfs_free_path(path); | 1641 | btrfs_free_path(path); |
1673 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1674 | return ret; | 1642 | return ret; |
1675 | } | 1643 | } |
1676 | 1644 | ||
@@ -1681,11 +1649,9 @@ int btrfs_write_inode(struct inode *inode, int wait) | |||
1681 | int ret = 0; | 1649 | int ret = 0; |
1682 | 1650 | ||
1683 | if (wait) { | 1651 | if (wait) { |
1684 | mutex_lock(&root->fs_info->fs_mutex); | ||
1685 | trans = btrfs_start_transaction(root, 1); | 1652 | trans = btrfs_start_transaction(root, 1); |
1686 | btrfs_set_trans_block_group(trans, inode); | 1653 | btrfs_set_trans_block_group(trans, inode); |
1687 | ret = btrfs_commit_transaction(trans, root); | 1654 | ret = btrfs_commit_transaction(trans, root); |
1688 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1689 | } | 1655 | } |
1690 | return ret; | 1656 | return ret; |
1691 | } | 1657 | } |
@@ -1701,12 +1667,10 @@ void btrfs_dirty_inode(struct inode *inode) | |||
1701 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1667 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1702 | struct btrfs_trans_handle *trans; | 1668 | struct btrfs_trans_handle *trans; |
1703 | 1669 | ||
1704 | mutex_lock(&root->fs_info->fs_mutex); | ||
1705 | trans = btrfs_start_transaction(root, 1); | 1670 | trans = btrfs_start_transaction(root, 1); |
1706 | btrfs_set_trans_block_group(trans, inode); | 1671 | btrfs_set_trans_block_group(trans, inode); |
1707 | btrfs_update_inode(trans, root, inode); | 1672 | btrfs_update_inode(trans, root, inode); |
1708 | btrfs_end_transaction(trans, root); | 1673 | btrfs_end_transaction(trans, root); |
1709 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1710 | } | 1674 | } |
1711 | 1675 | ||
1712 | static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, | 1676 | static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, |
@@ -1874,7 +1838,6 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry, | |||
1874 | if (!new_valid_dev(rdev)) | 1838 | if (!new_valid_dev(rdev)) |
1875 | return -EINVAL; | 1839 | return -EINVAL; |
1876 | 1840 | ||
1877 | mutex_lock(&root->fs_info->fs_mutex); | ||
1878 | err = btrfs_check_free_space(root, 1, 0); | 1841 | err = btrfs_check_free_space(root, 1, 0); |
1879 | if (err) | 1842 | if (err) |
1880 | goto fail; | 1843 | goto fail; |
@@ -1912,8 +1875,6 @@ out_unlock: | |||
1912 | nr = trans->blocks_used; | 1875 | nr = trans->blocks_used; |
1913 | btrfs_end_transaction(trans, root); | 1876 | btrfs_end_transaction(trans, root); |
1914 | fail: | 1877 | fail: |
1915 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1916 | |||
1917 | if (drop_inode) { | 1878 | if (drop_inode) { |
1918 | inode_dec_link_count(inode); | 1879 | inode_dec_link_count(inode); |
1919 | iput(inode); | 1880 | iput(inode); |
@@ -1934,7 +1895,6 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry, | |||
1934 | unsigned long nr = 0; | 1895 | unsigned long nr = 0; |
1935 | u64 objectid; | 1896 | u64 objectid; |
1936 | 1897 | ||
1937 | mutex_lock(&root->fs_info->fs_mutex); | ||
1938 | err = btrfs_check_free_space(root, 1, 0); | 1898 | err = btrfs_check_free_space(root, 1, 0); |
1939 | if (err) | 1899 | if (err) |
1940 | goto fail; | 1900 | goto fail; |
@@ -1980,8 +1940,6 @@ out_unlock: | |||
1980 | nr = trans->blocks_used; | 1940 | nr = trans->blocks_used; |
1981 | btrfs_end_transaction(trans, root); | 1941 | btrfs_end_transaction(trans, root); |
1982 | fail: | 1942 | fail: |
1983 | mutex_unlock(&root->fs_info->fs_mutex); | ||
1984 | |||
1985 | if (drop_inode) { | 1943 | if (drop_inode) { |
1986 | inode_dec_link_count(inode); | 1944 | inode_dec_link_count(inode); |
1987 | iput(inode); | 1945 | iput(inode); |
@@ -2009,7 +1967,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, | |||
2009 | #else | 1967 | #else |
2010 | inc_nlink(inode); | 1968 | inc_nlink(inode); |
2011 | #endif | 1969 | #endif |
2012 | mutex_lock(&root->fs_info->fs_mutex); | ||
2013 | err = btrfs_check_free_space(root, 1, 0); | 1970 | err = btrfs_check_free_space(root, 1, 0); |
2014 | if (err) | 1971 | if (err) |
2015 | goto fail; | 1972 | goto fail; |
@@ -2032,8 +1989,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, | |||
2032 | nr = trans->blocks_used; | 1989 | nr = trans->blocks_used; |
2033 | btrfs_end_transaction(trans, root); | 1990 | btrfs_end_transaction(trans, root); |
2034 | fail: | 1991 | fail: |
2035 | mutex_unlock(&root->fs_info->fs_mutex); | ||
2036 | |||
2037 | if (drop_inode) { | 1992 | if (drop_inode) { |
2038 | inode_dec_link_count(inode); | 1993 | inode_dec_link_count(inode); |
2039 | iput(inode); | 1994 | iput(inode); |
@@ -2053,7 +2008,6 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
2053 | u64 objectid = 0; | 2008 | u64 objectid = 0; |
2054 | unsigned long nr = 1; | 2009 | unsigned long nr = 1; |
2055 | 2010 | ||
2056 | mutex_lock(&root->fs_info->fs_mutex); | ||
2057 | err = btrfs_check_free_space(root, 1, 0); | 2011 | err = btrfs_check_free_space(root, 1, 0); |
2058 | if (err) | 2012 | if (err) |
2059 | goto out_unlock; | 2013 | goto out_unlock; |
@@ -2106,7 +2060,6 @@ out_fail: | |||
2106 | btrfs_end_transaction(trans, root); | 2060 | btrfs_end_transaction(trans, root); |
2107 | 2061 | ||
2108 | out_unlock: | 2062 | out_unlock: |
2109 | mutex_unlock(&root->fs_info->fs_mutex); | ||
2110 | if (drop_on_err) | 2063 | if (drop_on_err) |
2111 | iput(inode); | 2064 | iput(inode); |
2112 | btrfs_btree_balance_dirty(root, nr); | 2065 | btrfs_btree_balance_dirty(root, nr); |
@@ -2199,7 +2152,6 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, | |||
2199 | 2152 | ||
2200 | path = btrfs_alloc_path(); | 2153 | path = btrfs_alloc_path(); |
2201 | BUG_ON(!path); | 2154 | BUG_ON(!path); |
2202 | mutex_lock(&root->fs_info->fs_mutex); | ||
2203 | 2155 | ||
2204 | again: | 2156 | again: |
2205 | spin_lock(&em_tree->lock); | 2157 | spin_lock(&em_tree->lock); |
@@ -2402,7 +2354,6 @@ out: | |||
2402 | if (!err) | 2354 | if (!err) |
2403 | err = ret; | 2355 | err = ret; |
2404 | } | 2356 | } |
2405 | mutex_unlock(&root->fs_info->fs_mutex); | ||
2406 | if (err) { | 2357 | if (err) { |
2407 | free_extent_map(em); | 2358 | free_extent_map(em); |
2408 | WARN_ON(1); | 2359 | WARN_ON(1); |
@@ -2584,9 +2535,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct page *page) | |||
2584 | int ret; | 2535 | int ret; |
2585 | u64 page_start; | 2536 | u64 page_start; |
2586 | 2537 | ||
2587 | mutex_lock(&root->fs_info->fs_mutex); | ||
2588 | ret = btrfs_check_free_space(root, PAGE_CACHE_SIZE, 0); | 2538 | ret = btrfs_check_free_space(root, PAGE_CACHE_SIZE, 0); |
2589 | mutex_unlock(&root->fs_info->fs_mutex); | ||
2590 | if (ret) | 2539 | if (ret) |
2591 | goto out; | 2540 | goto out; |
2592 | 2541 | ||
@@ -2631,7 +2580,6 @@ static void btrfs_truncate(struct inode *inode) | |||
2631 | 2580 | ||
2632 | btrfs_truncate_page(inode->i_mapping, inode->i_size); | 2581 | btrfs_truncate_page(inode->i_mapping, inode->i_size); |
2633 | 2582 | ||
2634 | mutex_lock(&root->fs_info->fs_mutex); | ||
2635 | trans = btrfs_start_transaction(root, 1); | 2583 | trans = btrfs_start_transaction(root, 1); |
2636 | btrfs_set_trans_block_group(trans, inode); | 2584 | btrfs_set_trans_block_group(trans, inode); |
2637 | 2585 | ||
@@ -2643,7 +2591,6 @@ static void btrfs_truncate(struct inode *inode) | |||
2643 | 2591 | ||
2644 | ret = btrfs_end_transaction(trans, root); | 2592 | ret = btrfs_end_transaction(trans, root); |
2645 | BUG_ON(ret); | 2593 | BUG_ON(ret); |
2646 | mutex_unlock(&root->fs_info->fs_mutex); | ||
2647 | btrfs_btree_balance_dirty(root, nr); | 2594 | btrfs_btree_balance_dirty(root, nr); |
2648 | btrfs_throttle(root); | 2595 | btrfs_throttle(root); |
2649 | } | 2596 | } |
@@ -2827,7 +2774,6 @@ static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry, | |||
2827 | struct inode *new_inode = new_dentry->d_inode; | 2774 | struct inode *new_inode = new_dentry->d_inode; |
2828 | struct inode *old_inode = old_dentry->d_inode; | 2775 | struct inode *old_inode = old_dentry->d_inode; |
2829 | struct timespec ctime = CURRENT_TIME; | 2776 | struct timespec ctime = CURRENT_TIME; |
2830 | struct btrfs_path *path; | ||
2831 | int ret; | 2777 | int ret; |
2832 | 2778 | ||
2833 | if (S_ISDIR(old_inode->i_mode) && new_inode && | 2779 | if (S_ISDIR(old_inode->i_mode) && new_inode && |
@@ -2835,7 +2781,6 @@ static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry, | |||
2835 | return -ENOTEMPTY; | 2781 | return -ENOTEMPTY; |
2836 | } | 2782 | } |
2837 | 2783 | ||
2838 | mutex_lock(&root->fs_info->fs_mutex); | ||
2839 | ret = btrfs_check_free_space(root, 1, 0); | 2784 | ret = btrfs_check_free_space(root, 1, 0); |
2840 | if (ret) | 2785 | if (ret) |
2841 | goto out_unlock; | 2786 | goto out_unlock; |
@@ -2843,11 +2788,6 @@ static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry, | |||
2843 | trans = btrfs_start_transaction(root, 1); | 2788 | trans = btrfs_start_transaction(root, 1); |
2844 | 2789 | ||
2845 | btrfs_set_trans_block_group(trans, new_dir); | 2790 | btrfs_set_trans_block_group(trans, new_dir); |
2846 | path = btrfs_alloc_path(); | ||
2847 | if (!path) { | ||
2848 | ret = -ENOMEM; | ||
2849 | goto out_fail; | ||
2850 | } | ||
2851 | 2791 | ||
2852 | old_dentry->d_inode->i_nlink++; | 2792 | old_dentry->d_inode->i_nlink++; |
2853 | old_dir->i_ctime = old_dir->i_mtime = ctime; | 2793 | old_dir->i_ctime = old_dir->i_mtime = ctime; |
@@ -2869,10 +2809,8 @@ static int btrfs_rename(struct inode * old_dir, struct dentry *old_dentry, | |||
2869 | goto out_fail; | 2809 | goto out_fail; |
2870 | 2810 | ||
2871 | out_fail: | 2811 | out_fail: |
2872 | btrfs_free_path(path); | ||
2873 | btrfs_end_transaction(trans, root); | 2812 | btrfs_end_transaction(trans, root); |
2874 | out_unlock: | 2813 | out_unlock: |
2875 | mutex_unlock(&root->fs_info->fs_mutex); | ||
2876 | return ret; | 2814 | return ret; |
2877 | } | 2815 | } |
2878 | 2816 | ||
@@ -2898,7 +2836,6 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry, | |||
2898 | if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root)) | 2836 | if (name_len > BTRFS_MAX_INLINE_DATA_SIZE(root)) |
2899 | return -ENAMETOOLONG; | 2837 | return -ENAMETOOLONG; |
2900 | 2838 | ||
2901 | mutex_lock(&root->fs_info->fs_mutex); | ||
2902 | err = btrfs_check_free_space(root, 1, 0); | 2839 | err = btrfs_check_free_space(root, 1, 0); |
2903 | if (err) | 2840 | if (err) |
2904 | goto out_fail; | 2841 | goto out_fail; |
@@ -2979,7 +2916,6 @@ out_unlock: | |||
2979 | nr = trans->blocks_used; | 2916 | nr = trans->blocks_used; |
2980 | btrfs_end_transaction(trans, root); | 2917 | btrfs_end_transaction(trans, root); |
2981 | out_fail: | 2918 | out_fail: |
2982 | mutex_unlock(&root->fs_info->fs_mutex); | ||
2983 | if (drop_inode) { | 2919 | if (drop_inode) { |
2984 | inode_dec_link_count(inode); | 2920 | inode_dec_link_count(inode); |
2985 | iput(inode); | 2921 | iput(inode); |