diff options
author | Yan, Zheng <zheng.yan@oracle.com> | 2010-05-16 10:48:47 -0400 |
---|---|---|
committer | Chris Mason <chris.mason@oracle.com> | 2010-05-25 10:34:51 -0400 |
commit | 0ca1f7ceb1991099ed5273885ebcf4323948c72e (patch) | |
tree | 10758d6a55c529aced177da3f6bf45cf26361913 /fs/btrfs/inode.c | |
parent | a22285a6a32390195235171b89d157ed1a1fe932 (diff) |
Btrfs: Update metadata reservation for delayed allocation
Introduce metadata reservation context for delayed allocation
and update various related functions.
This patch also introduces EXTENT_FIRST_DELALLOC control bit for
set/clear_extent_bit. It tells set/clear_bit_hook whether they
are processing the first extent_state with EXTENT_DELALLOC bit
set. This change is important if set/clear_extent_bit involves
multiple extent_state.
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 131 |
1 files changed, 53 insertions, 78 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index c4b0fd12df6..6e54665d37f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -252,6 +252,7 @@ static noinline int cow_file_range_inline(struct btrfs_trans_handle *trans, | |||
252 | inline_len, compressed_size, | 252 | inline_len, compressed_size, |
253 | compressed_pages); | 253 | compressed_pages); |
254 | BUG_ON(ret); | 254 | BUG_ON(ret); |
255 | btrfs_delalloc_release_metadata(inode, end + 1 - start); | ||
255 | btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0); | 256 | btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0); |
256 | return 0; | 257 | return 0; |
257 | } | 258 | } |
@@ -414,6 +415,7 @@ again: | |||
414 | trans = btrfs_join_transaction(root, 1); | 415 | trans = btrfs_join_transaction(root, 1); |
415 | BUG_ON(!trans); | 416 | BUG_ON(!trans); |
416 | btrfs_set_trans_block_group(trans, inode); | 417 | btrfs_set_trans_block_group(trans, inode); |
418 | trans->block_rsv = &root->fs_info->delalloc_block_rsv; | ||
417 | 419 | ||
418 | /* lets try to make an inline extent */ | 420 | /* lets try to make an inline extent */ |
419 | if (ret || total_in < (actual_end - start)) { | 421 | if (ret || total_in < (actual_end - start)) { |
@@ -439,7 +441,6 @@ again: | |||
439 | start, end, NULL, | 441 | start, end, NULL, |
440 | EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | | 442 | EXTENT_CLEAR_UNLOCK_PAGE | EXTENT_CLEAR_DIRTY | |
441 | EXTENT_CLEAR_DELALLOC | | 443 | EXTENT_CLEAR_DELALLOC | |
442 | EXTENT_CLEAR_ACCOUNTING | | ||
443 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK); | 444 | EXTENT_SET_WRITEBACK | EXTENT_END_WRITEBACK); |
444 | 445 | ||
445 | btrfs_end_transaction(trans, root); | 446 | btrfs_end_transaction(trans, root); |
@@ -734,6 +735,7 @@ static noinline int cow_file_range(struct inode *inode, | |||
734 | trans = btrfs_join_transaction(root, 1); | 735 | trans = btrfs_join_transaction(root, 1); |
735 | BUG_ON(!trans); | 736 | BUG_ON(!trans); |
736 | btrfs_set_trans_block_group(trans, inode); | 737 | btrfs_set_trans_block_group(trans, inode); |
738 | trans->block_rsv = &root->fs_info->delalloc_block_rsv; | ||
737 | 739 | ||
738 | actual_end = min_t(u64, isize, end + 1); | 740 | actual_end = min_t(u64, isize, end + 1); |
739 | 741 | ||
@@ -753,7 +755,6 @@ static noinline int cow_file_range(struct inode *inode, | |||
753 | EXTENT_CLEAR_UNLOCK_PAGE | | 755 | EXTENT_CLEAR_UNLOCK_PAGE | |
754 | EXTENT_CLEAR_UNLOCK | | 756 | EXTENT_CLEAR_UNLOCK | |
755 | EXTENT_CLEAR_DELALLOC | | 757 | EXTENT_CLEAR_DELALLOC | |
756 | EXTENT_CLEAR_ACCOUNTING | | ||
757 | EXTENT_CLEAR_DIRTY | | 758 | EXTENT_CLEAR_DIRTY | |
758 | EXTENT_SET_WRITEBACK | | 759 | EXTENT_SET_WRITEBACK | |
759 | EXTENT_END_WRITEBACK); | 760 | EXTENT_END_WRITEBACK); |
@@ -1226,15 +1227,13 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page, | |||
1226 | } | 1227 | } |
1227 | 1228 | ||
1228 | static int btrfs_split_extent_hook(struct inode *inode, | 1229 | static int btrfs_split_extent_hook(struct inode *inode, |
1229 | struct extent_state *orig, u64 split) | 1230 | struct extent_state *orig, u64 split) |
1230 | { | 1231 | { |
1232 | /* not delalloc, ignore it */ | ||
1231 | if (!(orig->state & EXTENT_DELALLOC)) | 1233 | if (!(orig->state & EXTENT_DELALLOC)) |
1232 | return 0; | 1234 | return 0; |
1233 | 1235 | ||
1234 | spin_lock(&BTRFS_I(inode)->accounting_lock); | 1236 | atomic_inc(&BTRFS_I(inode)->outstanding_extents); |
1235 | BTRFS_I(inode)->outstanding_extents++; | ||
1236 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1237 | |||
1238 | return 0; | 1237 | return 0; |
1239 | } | 1238 | } |
1240 | 1239 | ||
@@ -1252,10 +1251,7 @@ static int btrfs_merge_extent_hook(struct inode *inode, | |||
1252 | if (!(other->state & EXTENT_DELALLOC)) | 1251 | if (!(other->state & EXTENT_DELALLOC)) |
1253 | return 0; | 1252 | return 0; |
1254 | 1253 | ||
1255 | spin_lock(&BTRFS_I(inode)->accounting_lock); | 1254 | atomic_dec(&BTRFS_I(inode)->outstanding_extents); |
1256 | BTRFS_I(inode)->outstanding_extents--; | ||
1257 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | ||
1258 | |||
1259 | return 0; | 1255 | return 0; |
1260 | } | 1256 | } |
1261 | 1257 | ||
@@ -1264,8 +1260,8 @@ static int btrfs_merge_extent_hook(struct inode *inode, | |||
1264 | * bytes in this file, and to maintain the list of inodes that | 1260 | * bytes in this file, and to maintain the list of inodes that |
1265 | * have pending delalloc work to be done. | 1261 | * have pending delalloc work to be done. |
1266 | */ | 1262 | */ |
1267 | static int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end, | 1263 | static int btrfs_set_bit_hook(struct inode *inode, |
1268 | unsigned long old, unsigned long bits) | 1264 | struct extent_state *state, int *bits) |
1269 | { | 1265 | { |
1270 | 1266 | ||
1271 | /* | 1267 | /* |
@@ -1273,17 +1269,18 @@ static int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end, | |||
1273 | * but in this case, we are only testeing for the DELALLOC | 1269 | * but in this case, we are only testeing for the DELALLOC |
1274 | * bit, which is only set or cleared with irqs on | 1270 | * bit, which is only set or cleared with irqs on |
1275 | */ | 1271 | */ |
1276 | if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { | 1272 | if (!(state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { |
1277 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1273 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1274 | u64 len = state->end + 1 - state->start; | ||
1278 | 1275 | ||
1279 | spin_lock(&BTRFS_I(inode)->accounting_lock); | 1276 | if (*bits & EXTENT_FIRST_DELALLOC) |
1280 | BTRFS_I(inode)->outstanding_extents++; | 1277 | *bits &= ~EXTENT_FIRST_DELALLOC; |
1281 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | 1278 | else |
1282 | btrfs_delalloc_reserve_space(root, inode, end - start + 1); | 1279 | atomic_inc(&BTRFS_I(inode)->outstanding_extents); |
1283 | 1280 | ||
1284 | spin_lock(&root->fs_info->delalloc_lock); | 1281 | spin_lock(&root->fs_info->delalloc_lock); |
1285 | BTRFS_I(inode)->delalloc_bytes += end - start + 1; | 1282 | BTRFS_I(inode)->delalloc_bytes += len; |
1286 | root->fs_info->delalloc_bytes += end - start + 1; | 1283 | root->fs_info->delalloc_bytes += len; |
1287 | if (list_empty(&BTRFS_I(inode)->delalloc_inodes)) { | 1284 | if (list_empty(&BTRFS_I(inode)->delalloc_inodes)) { |
1288 | list_add_tail(&BTRFS_I(inode)->delalloc_inodes, | 1285 | list_add_tail(&BTRFS_I(inode)->delalloc_inodes, |
1289 | &root->fs_info->delalloc_inodes); | 1286 | &root->fs_info->delalloc_inodes); |
@@ -1297,45 +1294,32 @@ static int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end, | |||
1297 | * extent_io.c clear_bit_hook, see set_bit_hook for why | 1294 | * extent_io.c clear_bit_hook, see set_bit_hook for why |
1298 | */ | 1295 | */ |
1299 | static int btrfs_clear_bit_hook(struct inode *inode, | 1296 | static int btrfs_clear_bit_hook(struct inode *inode, |
1300 | struct extent_state *state, unsigned long bits) | 1297 | struct extent_state *state, int *bits) |
1301 | { | 1298 | { |
1302 | /* | 1299 | /* |
1303 | * set_bit and clear bit hooks normally require _irqsave/restore | 1300 | * set_bit and clear bit hooks normally require _irqsave/restore |
1304 | * but in this case, we are only testeing for the DELALLOC | 1301 | * but in this case, we are only testeing for the DELALLOC |
1305 | * bit, which is only set or cleared with irqs on | 1302 | * bit, which is only set or cleared with irqs on |
1306 | */ | 1303 | */ |
1307 | if ((state->state & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) { | 1304 | if ((state->state & EXTENT_DELALLOC) && (*bits & EXTENT_DELALLOC)) { |
1308 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1305 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1306 | u64 len = state->end + 1 - state->start; | ||
1309 | 1307 | ||
1310 | if (bits & EXTENT_DO_ACCOUNTING) { | 1308 | if (*bits & EXTENT_FIRST_DELALLOC) |
1311 | spin_lock(&BTRFS_I(inode)->accounting_lock); | 1309 | *bits &= ~EXTENT_FIRST_DELALLOC; |
1312 | WARN_ON(!BTRFS_I(inode)->outstanding_extents); | 1310 | else if (!(*bits & EXTENT_DO_ACCOUNTING)) |
1313 | BTRFS_I(inode)->outstanding_extents--; | 1311 | atomic_dec(&BTRFS_I(inode)->outstanding_extents); |
1314 | spin_unlock(&BTRFS_I(inode)->accounting_lock); | 1312 | |
1315 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | 1313 | if (*bits & EXTENT_DO_ACCOUNTING) |
1316 | } | 1314 | btrfs_delalloc_release_metadata(inode, len); |
1315 | |||
1316 | if (root->root_key.objectid != BTRFS_DATA_RELOC_TREE_OBJECTID) | ||
1317 | btrfs_free_reserved_data_space(inode, len); | ||
1317 | 1318 | ||
1318 | spin_lock(&root->fs_info->delalloc_lock); | 1319 | spin_lock(&root->fs_info->delalloc_lock); |
1319 | if (state->end - state->start + 1 > | 1320 | root->fs_info->delalloc_bytes -= len; |
1320 | root->fs_info->delalloc_bytes) { | 1321 | BTRFS_I(inode)->delalloc_bytes -= len; |
1321 | printk(KERN_INFO "btrfs warning: delalloc account " | 1322 | |
1322 | "%llu %llu\n", | ||
1323 | (unsigned long long) | ||
1324 | state->end - state->start + 1, | ||
1325 | (unsigned long long) | ||
1326 | root->fs_info->delalloc_bytes); | ||
1327 | btrfs_delalloc_free_space(root, inode, (u64)-1); | ||
1328 | root->fs_info->delalloc_bytes = 0; | ||
1329 | BTRFS_I(inode)->delalloc_bytes = 0; | ||
1330 | } else { | ||
1331 | btrfs_delalloc_free_space(root, inode, | ||
1332 | state->end - | ||
1333 | state->start + 1); | ||
1334 | root->fs_info->delalloc_bytes -= state->end - | ||
1335 | state->start + 1; | ||
1336 | BTRFS_I(inode)->delalloc_bytes -= state->end - | ||
1337 | state->start + 1; | ||
1338 | } | ||
1339 | if (BTRFS_I(inode)->delalloc_bytes == 0 && | 1323 | if (BTRFS_I(inode)->delalloc_bytes == 0 && |
1340 | !list_empty(&BTRFS_I(inode)->delalloc_inodes)) { | 1324 | !list_empty(&BTRFS_I(inode)->delalloc_inodes)) { |
1341 | list_del_init(&BTRFS_I(inode)->delalloc_inodes); | 1325 | list_del_init(&BTRFS_I(inode)->delalloc_inodes); |
@@ -1520,6 +1504,7 @@ again: | |||
1520 | goto again; | 1504 | goto again; |
1521 | } | 1505 | } |
1522 | 1506 | ||
1507 | BUG(); | ||
1523 | btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); | 1508 | btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); |
1524 | ClearPageChecked(page); | 1509 | ClearPageChecked(page); |
1525 | out: | 1510 | out: |
@@ -1650,7 +1635,7 @@ static int insert_reserved_file_extent(struct btrfs_trans_handle *trans, | |||
1650 | static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | 1635 | static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) |
1651 | { | 1636 | { |
1652 | struct btrfs_root *root = BTRFS_I(inode)->root; | 1637 | struct btrfs_root *root = BTRFS_I(inode)->root; |
1653 | struct btrfs_trans_handle *trans; | 1638 | struct btrfs_trans_handle *trans = NULL; |
1654 | struct btrfs_ordered_extent *ordered_extent = NULL; | 1639 | struct btrfs_ordered_extent *ordered_extent = NULL; |
1655 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; | 1640 | struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; |
1656 | struct extent_state *cached_state = NULL; | 1641 | struct extent_state *cached_state = NULL; |
@@ -1668,9 +1653,10 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1668 | ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); | 1653 | ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); |
1669 | if (!ret) { | 1654 | if (!ret) { |
1670 | trans = btrfs_join_transaction(root, 1); | 1655 | trans = btrfs_join_transaction(root, 1); |
1656 | btrfs_set_trans_block_group(trans, inode); | ||
1657 | trans->block_rsv = &root->fs_info->delalloc_block_rsv; | ||
1671 | ret = btrfs_update_inode(trans, root, inode); | 1658 | ret = btrfs_update_inode(trans, root, inode); |
1672 | BUG_ON(ret); | 1659 | BUG_ON(ret); |
1673 | btrfs_end_transaction(trans, root); | ||
1674 | } | 1660 | } |
1675 | goto out; | 1661 | goto out; |
1676 | } | 1662 | } |
@@ -1680,6 +1666,8 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1680 | 0, &cached_state, GFP_NOFS); | 1666 | 0, &cached_state, GFP_NOFS); |
1681 | 1667 | ||
1682 | trans = btrfs_join_transaction(root, 1); | 1668 | trans = btrfs_join_transaction(root, 1); |
1669 | btrfs_set_trans_block_group(trans, inode); | ||
1670 | trans->block_rsv = &root->fs_info->delalloc_block_rsv; | ||
1683 | 1671 | ||
1684 | if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered_extent->flags)) | 1672 | if (test_bit(BTRFS_ORDERED_COMPRESSED, &ordered_extent->flags)) |
1685 | compressed = 1; | 1673 | compressed = 1; |
@@ -1711,12 +1699,13 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) | |||
1711 | add_pending_csums(trans, inode, ordered_extent->file_offset, | 1699 | add_pending_csums(trans, inode, ordered_extent->file_offset, |
1712 | &ordered_extent->list); | 1700 | &ordered_extent->list); |
1713 | 1701 | ||
1714 | /* this also removes the ordered extent from the tree */ | ||
1715 | btrfs_ordered_update_i_size(inode, 0, ordered_extent); | 1702 | btrfs_ordered_update_i_size(inode, 0, ordered_extent); |
1716 | ret = btrfs_update_inode(trans, root, inode); | 1703 | ret = btrfs_update_inode(trans, root, inode); |
1717 | BUG_ON(ret); | 1704 | BUG_ON(ret); |
1718 | btrfs_end_transaction(trans, root); | ||
1719 | out: | 1705 | out: |
1706 | btrfs_delalloc_release_metadata(inode, ordered_extent->len); | ||
1707 | if (trans) | ||
1708 | btrfs_end_transaction(trans, root); | ||
1720 | /* once for us */ | 1709 | /* once for us */ |
1721 | btrfs_put_ordered_extent(ordered_extent); | 1710 | btrfs_put_ordered_extent(ordered_extent); |
1722 | /* once for the tree */ | 1711 | /* once for the tree */ |
@@ -3219,11 +3208,7 @@ static int btrfs_truncate_page(struct address_space *mapping, loff_t from) | |||
3219 | 3208 | ||
3220 | if ((offset & (blocksize - 1)) == 0) | 3209 | if ((offset & (blocksize - 1)) == 0) |
3221 | goto out; | 3210 | goto out; |
3222 | ret = btrfs_check_data_free_space(root, inode, PAGE_CACHE_SIZE); | 3211 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); |
3223 | if (ret) | ||
3224 | goto out; | ||
3225 | |||
3226 | ret = btrfs_reserve_metadata_for_delalloc(root, inode, 1); | ||
3227 | if (ret) | 3212 | if (ret) |
3228 | goto out; | 3213 | goto out; |
3229 | 3214 | ||
@@ -3231,8 +3216,7 @@ static int btrfs_truncate_page(struct address_space *mapping, loff_t from) | |||
3231 | again: | 3216 | again: |
3232 | page = grab_cache_page(mapping, index); | 3217 | page = grab_cache_page(mapping, index); |
3233 | if (!page) { | 3218 | if (!page) { |
3234 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | 3219 | btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); |
3235 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
3236 | goto out; | 3220 | goto out; |
3237 | } | 3221 | } |
3238 | 3222 | ||
@@ -3295,8 +3279,7 @@ again: | |||
3295 | 3279 | ||
3296 | out_unlock: | 3280 | out_unlock: |
3297 | if (ret) | 3281 | if (ret) |
3298 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | 3282 | btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); |
3299 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
3300 | unlock_page(page); | 3283 | unlock_page(page); |
3301 | page_cache_release(page); | 3284 | page_cache_release(page); |
3302 | out: | 3285 | out: |
@@ -4878,6 +4861,7 @@ again: | |||
4878 | } | 4861 | } |
4879 | flush_dcache_page(page); | 4862 | flush_dcache_page(page); |
4880 | } else if (create && PageUptodate(page)) { | 4863 | } else if (create && PageUptodate(page)) { |
4864 | WARN_ON(1); | ||
4881 | if (!trans) { | 4865 | if (!trans) { |
4882 | kunmap(page); | 4866 | kunmap(page); |
4883 | free_extent_map(em); | 4867 | free_extent_map(em); |
@@ -5142,7 +5126,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
5142 | u64 page_start; | 5126 | u64 page_start; |
5143 | u64 page_end; | 5127 | u64 page_end; |
5144 | 5128 | ||
5145 | ret = btrfs_check_data_free_space(root, inode, PAGE_CACHE_SIZE); | 5129 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); |
5146 | if (ret) { | 5130 | if (ret) { |
5147 | if (ret == -ENOMEM) | 5131 | if (ret == -ENOMEM) |
5148 | ret = VM_FAULT_OOM; | 5132 | ret = VM_FAULT_OOM; |
@@ -5151,13 +5135,6 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) | |||
5151 | goto out; | 5135 | goto out; |
5152 | } | 5136 | } |
5153 | 5137 | ||
5154 | ret = btrfs_reserve_metadata_for_delalloc(root, inode, 1); | ||
5155 | if (ret) { | ||
5156 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
5157 | ret = VM_FAULT_SIGBUS; | ||
5158 | goto out; | ||
5159 | } | ||
5160 | |||
5161 | ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */ | 5138 | ret = VM_FAULT_NOPAGE; /* make the VM retry the fault */ |
5162 | again: | 5139 | again: |
5163 | lock_page(page); | 5140 | lock_page(page); |
@@ -5167,7 +5144,6 @@ again: | |||
5167 | 5144 | ||
5168 | if ((page->mapping != inode->i_mapping) || | 5145 | if ((page->mapping != inode->i_mapping) || |
5169 | (page_start >= size)) { | 5146 | (page_start >= size)) { |
5170 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
5171 | /* page got truncated out from underneath us */ | 5147 | /* page got truncated out from underneath us */ |
5172 | goto out_unlock; | 5148 | goto out_unlock; |
5173 | } | 5149 | } |
@@ -5208,7 +5184,6 @@ again: | |||
5208 | unlock_extent_cached(io_tree, page_start, page_end, | 5184 | unlock_extent_cached(io_tree, page_start, page_end, |
5209 | &cached_state, GFP_NOFS); | 5185 | &cached_state, GFP_NOFS); |
5210 | ret = VM_FAULT_SIGBUS; | 5186 | ret = VM_FAULT_SIGBUS; |
5211 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
5212 | goto out_unlock; | 5187 | goto out_unlock; |
5213 | } | 5188 | } |
5214 | ret = 0; | 5189 | ret = 0; |
@@ -5235,10 +5210,10 @@ again: | |||
5235 | unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); | 5210 | unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); |
5236 | 5211 | ||
5237 | out_unlock: | 5212 | out_unlock: |
5238 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
5239 | if (!ret) | 5213 | if (!ret) |
5240 | return VM_FAULT_LOCKED; | 5214 | return VM_FAULT_LOCKED; |
5241 | unlock_page(page); | 5215 | unlock_page(page); |
5216 | btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); | ||
5242 | out: | 5217 | out: |
5243 | return ret; | 5218 | return ret; |
5244 | } | 5219 | } |
@@ -5383,7 +5358,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) | |||
5383 | ei->last_unlink_trans = 0; | 5358 | ei->last_unlink_trans = 0; |
5384 | 5359 | ||
5385 | spin_lock_init(&ei->accounting_lock); | 5360 | spin_lock_init(&ei->accounting_lock); |
5386 | ei->outstanding_extents = 0; | 5361 | atomic_set(&ei->outstanding_extents, 0); |
5387 | ei->reserved_extents = 0; | 5362 | ei->reserved_extents = 0; |
5388 | 5363 | ||
5389 | ei->ordered_data_close = 0; | 5364 | ei->ordered_data_close = 0; |
@@ -5411,6 +5386,8 @@ void btrfs_destroy_inode(struct inode *inode) | |||
5411 | 5386 | ||
5412 | WARN_ON(!list_empty(&inode->i_dentry)); | 5387 | WARN_ON(!list_empty(&inode->i_dentry)); |
5413 | WARN_ON(inode->i_data.nrpages); | 5388 | WARN_ON(inode->i_data.nrpages); |
5389 | WARN_ON(atomic_read(&BTRFS_I(inode)->outstanding_extents)); | ||
5390 | WARN_ON(BTRFS_I(inode)->reserved_extents); | ||
5414 | 5391 | ||
5415 | /* | 5392 | /* |
5416 | * This can happen where we create an inode, but somebody else also | 5393 | * This can happen where we create an inode, but somebody else also |
@@ -5970,8 +5947,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
5970 | goto out; | 5947 | goto out; |
5971 | } | 5948 | } |
5972 | 5949 | ||
5973 | ret = btrfs_check_data_free_space(BTRFS_I(inode)->root, inode, | 5950 | ret = btrfs_check_data_free_space(inode, alloc_end - alloc_start); |
5974 | alloc_end - alloc_start); | ||
5975 | if (ret) | 5951 | if (ret) |
5976 | goto out; | 5952 | goto out; |
5977 | 5953 | ||
@@ -6037,8 +6013,7 @@ static long btrfs_fallocate(struct inode *inode, int mode, | |||
6037 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, | 6013 | unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, |
6038 | &cached_state, GFP_NOFS); | 6014 | &cached_state, GFP_NOFS); |
6039 | 6015 | ||
6040 | btrfs_free_reserved_data_space(BTRFS_I(inode)->root, inode, | 6016 | btrfs_free_reserved_data_space(inode, alloc_end - alloc_start); |
6041 | alloc_end - alloc_start); | ||
6042 | out: | 6017 | out: |
6043 | mutex_unlock(&inode->i_mutex); | 6018 | mutex_unlock(&inode->i_mutex); |
6044 | return ret; | 6019 | return ret; |