mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
Btrfs: Fix uninitialized root flags for subvolumes
root_item->flags and root_item->byte_limit are not initialized when a subvolume is created. This bug is not revealed until we added readonly snapshot support - now you mount a btrfs filesystem and you may find the subvolumes in it are readonly. To work around this problem, we steal a bit from root_item->inode_item->flags, and use it to indicate if those fields have been properly initialized. When we read a tree root from disk, we check if the bit is set, and if not we'll set the flag and initialize the two fields of the root item. Reported-by: Andreas Philipp <philipp.andreas@gmail.com> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com> Tested-by: Andreas Philipp <philipp.andreas@gmail.com> cc: stable@kernel.org Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
adae52b94e
commit
08fe4db170
5 changed files with 30 additions and 1 deletions
|
@ -473,3 +473,21 @@ again:
|
|||
btrfs_free_path(path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Old btrfs forgets to init root_item->flags and root_item->byte_limit
|
||||
* for subvolumes. To work around this problem, we steal a bit from
|
||||
* root_item->inode_item->flags, and use it to indicate if those fields
|
||||
* have been properly initialized.
|
||||
*/
|
||||
void btrfs_check_and_init_root_item(struct btrfs_root_item *root_item)
|
||||
{
|
||||
u64 inode_flags = le64_to_cpu(root_item->inode.flags);
|
||||
|
||||
if (!(inode_flags & BTRFS_INODE_ROOT_ITEM_INIT)) {
|
||||
inode_flags |= BTRFS_INODE_ROOT_ITEM_INIT;
|
||||
root_item->inode.flags = cpu_to_le64(inode_flags);
|
||||
root_item->flags = 0;
|
||||
root_item->byte_limit = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue