aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-04-05 16:21:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-04-05 16:21:15 -0400
commit795d580baec0d5386b83a8b557df47c20810e86b (patch)
treed0387c37562e9e27a4f43cf7ae425319cbdad359 /fs/btrfs/inode.c
parent449cedf099b23a250e7d61982e35555ccb871182 (diff)
parent109f6aef5fc436f355ad027f4d97bd696df2049a (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable
* git://git.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable: Btrfs: add check for changed leaves in setup_leaf_for_split Btrfs: create snapshot references in same commit as snapshot Btrfs: fix small race with delalloc flushing waitqueue's Btrfs: use add_to_page_cache_lru, use __page_cache_alloc Btrfs: fix chunk allocate size calculation Btrfs: kill max_extent mount option Btrfs: fail to mount if we have problems reading the block groups Btrfs: check btrfs_get_extent return for IS_ERR() Btrfs: handle kmalloc() failure in inode lookup ioctl Btrfs: dereferencing freed memory Btrfs: Simplify num_stripes's calculation logical for __btrfs_alloc_chunk() Btrfs: Add error handle for btrfs_search_slot() in btrfs_read_chunk_tree() Btrfs: Remove unnecessary finish_wait() in wait_current_trans() Btrfs: add NULL check for do_walk_down() Btrfs: remove duplicate include in ioctl.c Fix trivial conflict in fs/btrfs/compression.c due to slab.h include cleanups.
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c59
1 files changed, 4 insertions, 55 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2fe494c84e60..2bfdc641d4e3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -797,7 +797,7 @@ static noinline int cow_file_range(struct inode *inode,
797 while (disk_num_bytes > 0) { 797 while (disk_num_bytes > 0) {
798 unsigned long op; 798 unsigned long op;
799 799
800 cur_alloc_size = min(disk_num_bytes, root->fs_info->max_extent); 800 cur_alloc_size = disk_num_bytes;
801 ret = btrfs_reserve_extent(trans, root, cur_alloc_size, 801 ret = btrfs_reserve_extent(trans, root, cur_alloc_size,
802 root->sectorsize, 0, alloc_hint, 802 root->sectorsize, 0, alloc_hint,
803 (u64)-1, &ins, 1); 803 (u64)-1, &ins, 1);
@@ -1228,30 +1228,9 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page,
1228static int btrfs_split_extent_hook(struct inode *inode, 1228static int btrfs_split_extent_hook(struct inode *inode,
1229 struct extent_state *orig, u64 split) 1229 struct extent_state *orig, u64 split)
1230{ 1230{
1231 struct btrfs_root *root = BTRFS_I(inode)->root;
1232 u64 size;
1233
1234 if (!(orig->state & EXTENT_DELALLOC)) 1231 if (!(orig->state & EXTENT_DELALLOC))
1235 return 0; 1232 return 0;
1236 1233
1237 size = orig->end - orig->start + 1;
1238 if (size > root->fs_info->max_extent) {
1239 u64 num_extents;
1240 u64 new_size;
1241
1242 new_size = orig->end - split + 1;
1243 num_extents = div64_u64(size + root->fs_info->max_extent - 1,
1244 root->fs_info->max_extent);
1245
1246 /*
1247 * if we break a large extent up then leave oustanding_extents
1248 * be, since we've already accounted for the large extent.
1249 */
1250 if (div64_u64(new_size + root->fs_info->max_extent - 1,
1251 root->fs_info->max_extent) < num_extents)
1252 return 0;
1253 }
1254
1255 spin_lock(&BTRFS_I(inode)->accounting_lock); 1234 spin_lock(&BTRFS_I(inode)->accounting_lock);
1256 BTRFS_I(inode)->outstanding_extents++; 1235 BTRFS_I(inode)->outstanding_extents++;
1257 spin_unlock(&BTRFS_I(inode)->accounting_lock); 1236 spin_unlock(&BTRFS_I(inode)->accounting_lock);
@@ -1269,38 +1248,10 @@ static int btrfs_merge_extent_hook(struct inode *inode,
1269 struct extent_state *new, 1248 struct extent_state *new,
1270 struct extent_state *other) 1249 struct extent_state *other)
1271{ 1250{
1272 struct btrfs_root *root = BTRFS_I(inode)->root;
1273 u64 new_size, old_size;
1274 u64 num_extents;
1275
1276 /* not delalloc, ignore it */ 1251 /* not delalloc, ignore it */
1277 if (!(other->state & EXTENT_DELALLOC)) 1252 if (!(other->state & EXTENT_DELALLOC))
1278 return 0; 1253 return 0;
1279 1254
1280 old_size = other->end - other->start + 1;
1281 if (new->start < other->start)
1282 new_size = other->end - new->start + 1;
1283 else
1284 new_size = new->end - other->start + 1;
1285
1286 /* we're not bigger than the max, unreserve the space and go */
1287 if (new_size <= root->fs_info->max_extent) {
1288 spin_lock(&BTRFS_I(inode)->accounting_lock);
1289 BTRFS_I(inode)->outstanding_extents--;
1290 spin_unlock(&BTRFS_I(inode)->accounting_lock);
1291 return 0;
1292 }
1293
1294 /*
1295 * If we grew by another max_extent, just return, we want to keep that
1296 * reserved amount.
1297 */
1298 num_extents = div64_u64(old_size + root->fs_info->max_extent - 1,
1299 root->fs_info->max_extent);
1300 if (div64_u64(new_size + root->fs_info->max_extent - 1,
1301 root->fs_info->max_extent) > num_extents)
1302 return 0;
1303
1304 spin_lock(&BTRFS_I(inode)->accounting_lock); 1255 spin_lock(&BTRFS_I(inode)->accounting_lock);
1305 BTRFS_I(inode)->outstanding_extents--; 1256 BTRFS_I(inode)->outstanding_extents--;
1306 spin_unlock(&BTRFS_I(inode)->accounting_lock); 1257 spin_unlock(&BTRFS_I(inode)->accounting_lock);
@@ -1329,6 +1280,7 @@ static int btrfs_set_bit_hook(struct inode *inode, u64 start, u64 end,
1329 BTRFS_I(inode)->outstanding_extents++; 1280 BTRFS_I(inode)->outstanding_extents++;
1330 spin_unlock(&BTRFS_I(inode)->accounting_lock); 1281 spin_unlock(&BTRFS_I(inode)->accounting_lock);
1331 btrfs_delalloc_reserve_space(root, inode, end - start + 1); 1282 btrfs_delalloc_reserve_space(root, inode, end - start + 1);
1283
1332 spin_lock(&root->fs_info->delalloc_lock); 1284 spin_lock(&root->fs_info->delalloc_lock);
1333 BTRFS_I(inode)->delalloc_bytes += end - start + 1; 1285 BTRFS_I(inode)->delalloc_bytes += end - start + 1;
1334 root->fs_info->delalloc_bytes += end - start + 1; 1286 root->fs_info->delalloc_bytes += end - start + 1;
@@ -1357,6 +1309,7 @@ static int btrfs_clear_bit_hook(struct inode *inode,
1357 1309
1358 if (bits & EXTENT_DO_ACCOUNTING) { 1310 if (bits & EXTENT_DO_ACCOUNTING) {
1359 spin_lock(&BTRFS_I(inode)->accounting_lock); 1311 spin_lock(&BTRFS_I(inode)->accounting_lock);
1312 WARN_ON(!BTRFS_I(inode)->outstanding_extents);
1360 BTRFS_I(inode)->outstanding_extents--; 1313 BTRFS_I(inode)->outstanding_extents--;
1361 spin_unlock(&BTRFS_I(inode)->accounting_lock); 1314 spin_unlock(&BTRFS_I(inode)->accounting_lock);
1362 btrfs_unreserve_metadata_for_delalloc(root, inode, 1); 1315 btrfs_unreserve_metadata_for_delalloc(root, inode, 1);
@@ -5385,7 +5338,6 @@ free:
5385void btrfs_drop_inode(struct inode *inode) 5338void btrfs_drop_inode(struct inode *inode)
5386{ 5339{
5387 struct btrfs_root *root = BTRFS_I(inode)->root; 5340 struct btrfs_root *root = BTRFS_I(inode)->root;
5388
5389 if (inode->i_nlink > 0 && btrfs_root_refs(&root->root_item) == 0) 5341 if (inode->i_nlink > 0 && btrfs_root_refs(&root->root_item) == 0)
5390 generic_delete_inode(inode); 5342 generic_delete_inode(inode);
5391 else 5343 else
@@ -5789,18 +5741,15 @@ static int prealloc_file_range(struct inode *inode, u64 start, u64 end,
5789 struct btrfs_trans_handle *trans; 5741 struct btrfs_trans_handle *trans;
5790 struct btrfs_root *root = BTRFS_I(inode)->root; 5742 struct btrfs_root *root = BTRFS_I(inode)->root;
5791 struct btrfs_key ins; 5743 struct btrfs_key ins;
5792 u64 alloc_size;
5793 u64 cur_offset = start; 5744 u64 cur_offset = start;
5794 u64 num_bytes = end - start; 5745 u64 num_bytes = end - start;
5795 int ret = 0; 5746 int ret = 0;
5796 u64 i_size; 5747 u64 i_size;
5797 5748
5798 while (num_bytes > 0) { 5749 while (num_bytes > 0) {
5799 alloc_size = min(num_bytes, root->fs_info->max_extent);
5800
5801 trans = btrfs_start_transaction(root, 1); 5750 trans = btrfs_start_transaction(root, 1);
5802 5751
5803 ret = btrfs_reserve_extent(trans, root, alloc_size, 5752 ret = btrfs_reserve_extent(trans, root, num_bytes,
5804 root->sectorsize, 0, alloc_hint, 5753 root->sectorsize, 0, alloc_hint,
5805 (u64)-1, &ins, 1); 5754 (u64)-1, &ins, 1);
5806 if (ret) { 5755 if (ret) {