aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorYan Zheng <zheng.yan@oracle.com>2009-01-05 15:43:42 -0500
committerChris Mason <chris.mason@oracle.com>2009-01-05 15:43:42 -0500
commit2d69a0f88459fae35df3ddef4934a2dad67e2765 (patch)
tree20901742766992c0b1a00e56c5c5535daa8be35b /fs
parentdd3fd8bdf7238f99561ee236060b04d5b9a84953 (diff)
Btrfs: avoid potential super block corruption
The data in fs_info->super_for_commit are zeros before the first transaction commit. If tree log sync and system crash both occur before the first transaction commit, super block will get corrupted. This fixes it by properly filling in the super_for_commit field at open time. Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/disk-io.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 40a540f31161..dae25e78a6b7 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1609,6 +1609,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1609 goto fail_iput; 1609 goto fail_iput;
1610 1610
1611 memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy)); 1611 memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy));
1612 memcpy(&fs_info->super_for_commit, &fs_info->super_copy,
1613 sizeof(fs_info->super_for_commit));
1612 brelse(bh); 1614 brelse(bh);
1613 1615
1614 memcpy(fs_info->fsid, fs_info->super_copy.fsid, BTRFS_FSID_SIZE); 1616 memcpy(fs_info->fsid, fs_info->super_copy.fsid, BTRFS_FSID_SIZE);
@@ -1790,7 +1792,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
1790 1792
1791 btrfs_read_block_groups(extent_root); 1793 btrfs_read_block_groups(extent_root);
1792 1794
1793 fs_info->generation = generation + 1; 1795 fs_info->generation = generation;
1794 fs_info->last_trans_committed = generation; 1796 fs_info->last_trans_committed = generation;
1795 fs_info->data_alloc_profile = (u64)-1; 1797 fs_info->data_alloc_profile = (u64)-1;
1796 fs_info->metadata_alloc_profile = (u64)-1; 1798 fs_info->metadata_alloc_profile = (u64)-1;