diff options
author | Josef Bacik <josef@redhat.com> | 2011-03-04 14:37:08 -0500 |
---|---|---|
committer | Josef Bacik <josef@redhat.com> | 2011-03-17 14:21:30 -0400 |
commit | f0cd846e9221811d87047f1428cf5226e7236efe (patch) | |
tree | 7621f631bc39b92decaab53ca0fcd2f43b4ab072 /fs/btrfs/inode.c | |
parent | ded5db9de78f963979e1605f859de67626f54693 (diff) |
Btrfs: only add orphan items when truncating
We don't need an orphan item when expanding files, we just need them for
truncating them, so only add the orphan item in btrfs_truncate instead of in
btrfs_setsize. Thanks,
Signed-off-by: Josef Bacik <josef@redhat.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r-- | fs/btrfs/inode.c | 45 |
1 files changed, 18 insertions, 27 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3bd0ff63bf30..206b60362cec 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -3649,22 +3649,6 @@ static int btrfs_setsize(struct inode *inode, loff_t newsize) | |||
3649 | if (newsize == oldsize) | 3649 | if (newsize == oldsize) |
3650 | return 0; | 3650 | return 0; |
3651 | 3651 | ||
3652 | trans = btrfs_start_transaction(root, 5); | ||
3653 | if (IS_ERR(trans)) | ||
3654 | return PTR_ERR(trans); | ||
3655 | |||
3656 | btrfs_set_trans_block_group(trans, inode); | ||
3657 | |||
3658 | ret = btrfs_orphan_add(trans, inode); | ||
3659 | if (ret) { | ||
3660 | btrfs_end_transaction(trans, root); | ||
3661 | return ret; | ||
3662 | } | ||
3663 | |||
3664 | nr = trans->blocks_used; | ||
3665 | btrfs_end_transaction(trans, root); | ||
3666 | btrfs_btree_balance_dirty(root, nr); | ||
3667 | |||
3668 | if (newsize > oldsize) { | 3652 | if (newsize > oldsize) { |
3669 | i_size_write(inode, newsize); | 3653 | i_size_write(inode, newsize); |
3670 | btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL); | 3654 | btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL); |
@@ -3675,25 +3659,15 @@ static int btrfs_setsize(struct inode *inode, loff_t newsize) | |||
3675 | return ret; | 3659 | return ret; |
3676 | } | 3660 | } |
3677 | 3661 | ||
3678 | trans = btrfs_start_transaction(root, 0); | 3662 | trans = btrfs_start_transaction(root, 1); |
3679 | if (IS_ERR(trans)) | 3663 | if (IS_ERR(trans)) |
3680 | return PTR_ERR(trans); | 3664 | return PTR_ERR(trans); |
3681 | 3665 | ||
3682 | btrfs_set_trans_block_group(trans, inode); | ||
3683 | trans->block_rsv = root->orphan_block_rsv; | ||
3684 | BUG_ON(!trans->block_rsv); | ||
3685 | |||
3686 | /* | ||
3687 | * If this fails just leave the orphan item so that it can get | ||
3688 | * cleaned up next time we mount. | ||
3689 | */ | ||
3690 | ret = btrfs_update_inode(trans, root, inode); | 3666 | ret = btrfs_update_inode(trans, root, inode); |
3691 | if (ret) { | 3667 | if (ret) { |
3692 | btrfs_end_transaction(trans, root); | 3668 | btrfs_end_transaction(trans, root); |
3693 | return ret; | 3669 | return ret; |
3694 | } | 3670 | } |
3695 | if (inode->i_nlink > 0) | ||
3696 | ret = btrfs_orphan_del(trans, inode); | ||
3697 | nr = trans->blocks_used; | 3671 | nr = trans->blocks_used; |
3698 | btrfs_end_transaction(trans, root); | 3672 | btrfs_end_transaction(trans, root); |
3699 | btrfs_btree_balance_dirty(root, nr); | 3673 | btrfs_btree_balance_dirty(root, nr); |
@@ -6517,6 +6491,23 @@ static int btrfs_truncate(struct inode *inode) | |||
6517 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); | 6491 | btrfs_wait_ordered_range(inode, inode->i_size & (~mask), (u64)-1); |
6518 | btrfs_ordered_update_i_size(inode, inode->i_size, NULL); | 6492 | btrfs_ordered_update_i_size(inode, inode->i_size, NULL); |
6519 | 6493 | ||
6494 | trans = btrfs_start_transaction(root, 5); | ||
6495 | if (IS_ERR(trans)) | ||
6496 | return PTR_ERR(trans); | ||
6497 | |||
6498 | btrfs_set_trans_block_group(trans, inode); | ||
6499 | |||
6500 | ret = btrfs_orphan_add(trans, inode); | ||
6501 | if (ret) { | ||
6502 | btrfs_end_transaction(trans, root); | ||
6503 | return ret; | ||
6504 | } | ||
6505 | |||
6506 | nr = trans->blocks_used; | ||
6507 | btrfs_end_transaction(trans, root); | ||
6508 | btrfs_btree_balance_dirty(root, nr); | ||
6509 | |||
6510 | /* Now start a transaction for the truncate */ | ||
6520 | trans = btrfs_start_transaction(root, 0); | 6511 | trans = btrfs_start_transaction(root, 0); |
6521 | if (IS_ERR(trans)) | 6512 | if (IS_ERR(trans)) |
6522 | return PTR_ERR(trans); | 6513 | return PTR_ERR(trans); |