aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2012-09-07 03:43:32 -0400
committerChris Mason <chris.mason@fusionio.com>2012-10-01 15:19:17 -0400
commit8407aa464331556e4f6784f974030b83fc7585ed (patch)
treea522976de80295edd552d08fd5ff897e05e07d1e /fs/btrfs/inode.c
parent837e197283199de640857192ca32767cb6e24fe8 (diff)
Btrfs: fix corrupted metadata in the snapshot
When we delete a inode, we will remove all the delayed items including delayed inode update, and then truncate all the relative metadata. If there is lots of metadata, we will end the current transaction, and start a new transaction to truncate the left metadata. In this way, we will leave a inode item that its link counter is > 0, and also may leave some directory index items in fs/file tree after the current transaction ends. In other words, the metadata in this fs/file tree is inconsistent. If we create a snapshot for this tree now, we will find a inode with corrupted metadata in the new snapshot, and we won't continue to drop the left metadata, because its link counter is not 0. We fix this problem by updating the inode item before the current transaction ends. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index aae55625aa59..9e9754adf7a4 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3834,15 +3834,10 @@ void btrfs_evict_inode(struct inode *inode)
3834 btrfs_i_size_write(inode, 0); 3834 btrfs_i_size_write(inode, 0);
3835 3835
3836 /* 3836 /*
3837 * This is a bit simpler than btrfs_truncate since 3837 * This is a bit simpler than btrfs_truncate since we've already
3838 * 3838 * reserved our space for our orphan item in the unlink, so we just
3839 * 1) We've already reserved our space for our orphan item in the 3839 * need to reserve some slack space in case we add bytes and update
3840 * unlink. 3840 * inode item when doing the truncate.
3841 * 2) We're going to delete the inode item, so we don't need to update
3842 * it at all.
3843 *
3844 * So we just need to reserve some slack space in case we add bytes when
3845 * doing the truncate.
3846 */ 3841 */
3847 while (1) { 3842 while (1) {
3848 ret = btrfs_block_rsv_refill_noflush(root, rsv, min_size); 3843 ret = btrfs_block_rsv_refill_noflush(root, rsv, min_size);
@@ -3863,7 +3858,7 @@ void btrfs_evict_inode(struct inode *inode)
3863 goto no_delete; 3858 goto no_delete;
3864 } 3859 }
3865 3860
3866 trans = btrfs_start_transaction(root, 0); 3861 trans = btrfs_start_transaction_noflush(root, 1);
3867 if (IS_ERR(trans)) { 3862 if (IS_ERR(trans)) {
3868 btrfs_orphan_del(NULL, inode); 3863 btrfs_orphan_del(NULL, inode);
3869 btrfs_free_block_rsv(root, rsv); 3864 btrfs_free_block_rsv(root, rsv);
@@ -3876,6 +3871,10 @@ void btrfs_evict_inode(struct inode *inode)
3876 if (ret != -ENOSPC) 3871 if (ret != -ENOSPC)
3877 break; 3872 break;
3878 3873
3874 trans->block_rsv = &root->fs_info->trans_block_rsv;
3875 ret = btrfs_update_inode(trans, root, inode);
3876 BUG_ON(ret);
3877
3879 nr = trans->blocks_used; 3878 nr = trans->blocks_used;
3880 btrfs_end_transaction(trans, root); 3879 btrfs_end_transaction(trans, root);
3881 trans = NULL; 3880 trans = NULL;