Skip to content

Commit 81d5d61

Browse files
adam900710kdave
authored andcommitted
btrfs: enhance unsupported compat RO flags handling
Currently there are two corner cases not handling compat RO flags correctly: - Remount We can still mount the fs RO with compat RO flags, then remount it RW. We should not allow any write into a fs with unsupported RO flags. - Still try to search block group items In fact, behavior/on-disk format change to extent tree should not need a full incompat flag. And since we can ensure fs with unsupported RO flags never got any writes (with above case fixed), then we can even skip block group items search at mount time. This patch will enhance the unsupported RO compat flags by: - Reject read-write remount if there are unsupported RO compat flags - Go dummy block group items directly for unsupported RO compat flags In fact, only changes to chunk/subvolume/root/csum trees should go incompat flags. The latter part should allow future change to extent tree to be compat RO flags. Thus this patch also needs to be backported to all stable trees. CC: [email protected] # 4.9+ Reviewed-by: Nikolay Borisov <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 8e327b9 commit 81d5d61

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

fs/btrfs/block-group.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -2164,7 +2164,16 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
21642164
int need_clear = 0;
21652165
u64 cache_gen;
21662166

2167-
if (!root)
2167+
/*
2168+
* Either no extent root (with ibadroots rescue option) or we have
2169+
* unsupported RO options. The fs can never be mounted read-write, so no
2170+
* need to waste time searching block group items.
2171+
*
2172+
* This also allows new extent tree related changes to be RO compat,
2173+
* no need for a full incompat flag.
2174+
*/
2175+
if (!root || (btrfs_super_compat_ro_flags(info->super_copy) &
2176+
~BTRFS_FEATURE_COMPAT_RO_SUPP))
21682177
return fill_dummy_bgs(info);
21692178

21702179
key.objectid = 0;

fs/btrfs/super.c

+9
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,15 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
21172117
ret = -EINVAL;
21182118
goto restore;
21192119
}
2120+
if (btrfs_super_compat_ro_flags(fs_info->super_copy) &
2121+
~BTRFS_FEATURE_COMPAT_RO_SUPP) {
2122+
btrfs_err(fs_info,
2123+
"can not remount read-write due to unsupported optional flags 0x%llx",
2124+
btrfs_super_compat_ro_flags(fs_info->super_copy) &
2125+
~BTRFS_FEATURE_COMPAT_RO_SUPP);
2126+
ret = -EINVAL;
2127+
goto restore;
2128+
}
21202129
if (fs_info->fs_devices->rw_devices == 0) {
21212130
ret = -EACCES;
21222131
goto restore;

0 commit comments

Comments
 (0)