Commit 2d69a0f8 authored by Yan Zheng's avatar Yan Zheng Committed by Chris Mason

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: default avatarYan Zheng <zheng.yan@oracle.com>
parent dd3fd8bd
...@@ -1609,6 +1609,8 @@ struct btrfs_root *open_ctree(struct super_block *sb, ...@@ -1609,6 +1609,8 @@ struct btrfs_root *open_ctree(struct super_block *sb,
goto fail_iput; goto fail_iput;
memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy)); memcpy(&fs_info->super_copy, bh->b_data, sizeof(fs_info->super_copy));
memcpy(&fs_info->super_for_commit, &fs_info->super_copy,
sizeof(fs_info->super_for_commit));
brelse(bh); brelse(bh);
memcpy(fs_info->fsid, fs_info->super_copy.fsid, BTRFS_FSID_SIZE); 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,7 +1792,7 @@ struct btrfs_root *open_ctree(struct super_block *sb,
btrfs_read_block_groups(extent_root); btrfs_read_block_groups(extent_root);
fs_info->generation = generation + 1; fs_info->generation = generation;
fs_info->last_trans_committed = generation; fs_info->last_trans_committed = generation;
fs_info->data_alloc_profile = (u64)-1; fs_info->data_alloc_profile = (u64)-1;
fs_info->metadata_alloc_profile = (u64)-1; fs_info->metadata_alloc_profile = (u64)-1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment