btrfs: Introduce new rescue= mount options
v4 cover btrfs: Introduce new rescue= mount options
There are quite a lot btrfs extent tree corruption report in the mail list.
Since btrfs will do mount time block group item search, one corrupted leaf containing block group item will prevent the whole fs to be mounted.
This patchset will try to address the problem by introducing a new mount option, "rescue=skipbg", as a last-resort rescue.
With "rescue=skipbg", the whole extent tree will be skipped if we hit some problems at mount time.
This brings some side effect that for super large fs, the mount time can be hugely reduced by this mount option.
Of course this option will have a lot of restriction to prevent further screwing up the fs, including:
- Permanent RO
No remount rw is allowed
- No dirty log
Either clean the log or use rescue=no_log_replay mount option
This "rescue=skipbg" has some advantage compared to user space tool like "btrfs-restore":
- Unified recovery tool
User can use any tool they're familiar with, as long as the kernel doesn't panic.
- More info for subvolume.
"btrfs subv list" can work now!
Also move the following mount options to "rescue=" group:
- nologreplay
to rescue=nologreplay
- usebackuproot
to rescue=usebackuproot
Old options are still available for compatibility purpose, but they are deprecated in favor of new 'rescue=' super option.
Different rescue sub options can be separated by ':', like:
"rescue=nologreplay:skipbg:usebackuproot".
Or the traditional but longer way like:
"rescue=nologreplay,rescue=skipbg"
The separation character is chosen by:
- No conflicts with existing character
Especially no conflict with ','.
- No extra escaping/quota
Original plan is ';', but since it'll be interpreted by bash, it's changed to current ':'.
Changelog:
v2:
- Introduce 'rescue=' super option.
- Rename original 'usebackuproot' and 'nologreplay'.
It at least makes my vim spell check happier.
- Remove 'recovery' mount option.
As its successor is now deprecated, not need to keep the predecessor.
v2.1:
- Rebase to v5.1-rc4.
- Fix the typos in the cover letter.
v3:
- Rebased to v5.2-rc2.
- Update commit message to include an example for "rescue=" options.
- Remove unnecessary exclusion of super blocks spaces and block group ro.
This seems to cause incorrect df output.
v4:
- Rebased to v5.3-rc7
Minor conflicts due to some function name and structure change.
- Keep the old 'recovery' mount option
- Keep the old 'usebackuproot' and 'nologreplay' naming for 'rescue=' mount options
So just append 'rescue=' to existing mount option.
Qu Wenruo (2):
btrfs: Introduce "rescue=" mount option
btrfs: Introduce new mount option to skip block group items scan
fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 29 ++++++++++-- fs/btrfs/extent-tree.c | 50 ++++++++++++++++++++ fs/btrfs/super.c | 102 +++++++++++++++++++++++++++++++++++++---- fs/btrfs/volumes.c | 7 +++ 5 files changed, 177 insertions(+), 12 deletions(-)
Signature · 1 line
2.23.0
PATCH v4 1/2 btrfs: Introduce "rescue=" mount option
This patch introduces a new "rescue=" mount option group for all those mount options for data recovery.
Different rescue sub options are seperated by ':'. E.g "ro,rescue=nologreplay:usebackuproot".
(The original plan is to use ';', but ';' needs to be escaped/quoted, or it will be interpreted by bash)
And obviously, user can specify rescue options one by one like:
"ro,rescue=nologreplay,rescue=usebackuproot"
The following mount options are converted to "rescue=", old mount options are deprecated but still available for compatibility purpose:
- usebackuproot
Now it's "rescue=usebackuproot"
- nologreplay
Now it's "rescue=nologreplay"
--- fs/btrfs/super.c | 79 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 8 deletions(-)
fs/btrfs/super.c +71 -8
@@ -311,7 +311,6 @@ enum { Opt_datasum, Opt_nodatasum, Opt_defrag, Opt_nodefrag, Opt_discard, Opt_nodiscard, - Opt_nologreplay, Opt_norecovery, Opt_ratio, Opt_rescan_uuid_tree,
@@ -325,9 +324,13 @@ enum { Opt_subvolid, Opt_thread_pool, Opt_treelog, Opt_notreelog, - Opt_usebackuproot, Opt_user_subvol_rm_allowed, +/* Rescue options */ + Opt_rescue, + Opt_usebackuproot, + Opt_nologreplay, +/* Deprecated options */ Opt_alloc_start, Opt_recovery,
@@ -374,7 +377,6 @@ static const match_table_t tokens = { {Opt_nodefrag, "noautodefrag"}, {Opt_discard, "discard"}, {Opt_nodiscard, "nodiscard"}, - {Opt_nologreplay, "nologreplay"}, {Opt_norecovery, "norecovery"}, {Opt_ratio, "metadata_ratio=%u"}, {Opt_rescan_uuid_tree, "rescan_uuid_tree"},
@@ -392,9 +394,13 @@ static const match_table_t tokens = { {Opt_thread_pool, "thread_pool=%u"}, {Opt_treelog, "treelog"}, {Opt_notreelog, "notreelog"}, - {Opt_usebackuproot, "usebackuproot"}, {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"}, +/* Recovery options */ + {Opt_rescue, "rescue=%s"}, + {Opt_nologreplay, "nologreplay"}, + {Opt_usebackuproot, "usebackuproot"}, +/* Deprecated options */ {Opt_alloc_start, "alloc_start=%s"}, {Opt_recovery, "recovery"},
@@ -417,6 +423,55 @@ static const match_table_t tokens = { {Opt_err, NULL}, }; +static const match_table_t rescue_tokens = { + {Opt_usebackuproot,"usebackuproot" }, + {Opt_nologreplay,"nologreplay" }, + {Opt_err,NULL }, +}; + +static int parse_rescue_options (struct btrfs_fs_info *info,const char *options) +{ +char *opts; +char *orig; +char *p; +substring_t args[MAX_OPT_ARGS ]; +int ret =0 ; + + opts =kstrdup (options,GFP_KERNEL ); +if (!opts) +return -ENOMEM ; + orig = opts; + +while ((p =strsep (&opts,":" )) !=NULL ) { +int token; + +if (!*p) +continue ; + token =match_token (p, rescue_tokens, args); +switch (token){ +case Opt_usebackuproot: +btrfs_info (info, +"trying to use backup root at mount time" ); +btrfs_set_opt (info->mount_opt,USEBACKUPROOT ); +break ; +case Opt_nologreplay: +btrfs_set_and_info (info,NOLOGREPLAY , +"disabling log replay at mount time" ); +break ; +case Opt_err: +btrfs_info (info,"unrecognized rescue option '%s'" , p); + ret = -EINVAL ; + goto out; +default : +break ; + } + + } +out: +kfree (orig); +return ret; +} +/* * Regular mount options parser. Everything that is needed only when * reading in a new superblock is parsed here.
@@ -673,6 +728,8 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,break ;case Opt_norecovery:case Opt_nologreplay: +btrfs_warn (info, +"'nologreplay' is deprecated, use 'rescue=nologreplay' instead" );btrfs_set_and_info (info,NOLOGREPLAY ,"disabling log replay at mount time" );break ;
@@ -761,10 +818,11 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, "disabling auto defrag");break ;case Opt_recovery: -btrfs_warn (info, -"'recovery' is deprecated, use 'usebackuproot' instead" ); -/* fall through */ case Opt_usebackuproot: +btrfs_warn (info, +"'%s' is deprecated, use 'rescue=usebackuproot' instead" , + token == Opt_recovery ?"recovery" : +"usebackuproot" );btrfs_info (info,"trying to use backup root at mount time" );btrfs_set_opt (info->mount_opt,USEBACKUPROOT );
@@ -851,6 +909,11 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,btrfs_set_opt (info->mount_opt,REF_VERIFY );break ;#endif +case Opt_rescue: + ret =parse_rescue_options (info, args[0 ].from); +if (ret <0 ) + goto out; +break ;case Opt_err:btrfs_info (info,"unrecognized mount option '%s'" , p); ret = -EINVAL ;
@@ -1317,7 +1380,7 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)if (btrfs_test_opt (info,NOTREELOG ))seq_puts (seq,",notreelog" );if (btrfs_test_opt (info,NOLOGREPLAY )) -seq_puts (seq,",nologreplay" ); +seq_puts (seq,",rescue=no_log_replay" );if (btrfs_test_opt (info,FLUSHONCOMMIT ))seq_puts (seq,",flushoncommit" );if (btrfs_test_opt (info,DISCARD ))
Signature · 1 line
2.23.0
PATCH v4 2/2 btrfs: Introduce new mount option to skip block group items scan
In reply to Qu Wenruo[PROBLEM]
There are some reports of corrupted fs which can't be mounted due to corrupted extent tree.
However under such situation, it's more likely the fs/subvolume trees are still fine.
For such case we normally go btrfs-restore and salvage as much as we can. However btrfs-restore can't list subvolumes as "btrfs subv list", making it harder to restore a fs.
[ENHANCEMENT]
This patch will introduce a new mount option "rescue=skipbg" to skip the mount time block group scan, and use chunk info solely to populate fake block group cache.
The mount option has the following dependency:
- RO mount
Obviously.
- No dirty log.
Either there is no log, or use rescue=no_log_replay mount option.
- No way to remoutn RW
Similar to rescue=nologreplay option.
This allow kernel to accept all extent tree corruption, even when the whole extent tree is corrupted, and allow user to salvage data and subvolume info.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/disk-io.c | 29 ++++++++++++++++++++---- fs/btrfs/extent-tree.c | 50 ++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/super.c | 25 ++++++++++++++++++++- fs/btrfs/volumes.c | 7 ++++++ 5 files changed, 107 insertions(+), 5 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -1353,6 +1353,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)#define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26)#define BTRFS_MOUNT_NOLOGREPLAY (1 << 27)#define BTRFS_MOUNT_REF_VERIFY (1 << 28) +#define BTRFS_MOUNT_SKIP_BG (1 << 29)#define BTRFS_DEFAULT_COMMIT_INTERVAL (30)#define BTRFS_DEFAULT_MAX_INLINE (2048)
fs/btrfs/disk-io.c +25 -4
@@ -2345,11 +2345,15 @@ static int btrfs_read_roots(struct btrfs_fs_info *fs_info) root =btrfs_read_tree_root (tree_root, &location);if (IS_ERR (root)) { - ret =PTR_ERR (root); - goto out; +if (!btrfs_test_opt (fs_info,SKIP_BG )) { + ret =PTR_ERR (root); + goto out; + } + fs_info->extent_root =NULL ; + }else { +set_bit (BTRFS_ROOT_TRACK_DIRTY , &root->state); + fs_info->extent_root = root; } -set_bit (BTRFS_ROOT_TRACK_DIRTY , &root->state); - fs_info->extent_root = root; location.objectid =BTRFS_DEV_TREE_OBJECTID ; root =btrfs_read_tree_root (tree_root, &location);
@@ -2991,6 +2995,23 @@ int open_ctree(struct super_block *sb, goto fail_csum; } +/* Skip bg needs RO and no log tree replay */ +if (btrfs_test_opt (fs_info,SKIP_BG )) { +if (!sb_rdonly (sb)) { +btrfs_err (fs_info, +"skip_bg mount option can only be used with read-only mount" ); + err = -EINVAL ; + goto fail_alloc; + } +if (btrfs_super_log_root (disk_super) && + !btrfs_test_opt (fs_info,NOTREELOG )) { +btrfs_err (fs_info, +"skip_bg must be used with notreelog mount option for dirty log" ); + err = -EINVAL ; + goto fail_alloc; + } + } + ret =btrfs_init_workqueues (fs_info, fs_devices);if (ret) { err = ret;
fs/btrfs/extent-tree.c +50 -0
62 lines not on this page · raw message
fs/btrfs/super.c +24 -1
@@ -326,10 +326,11 @@ enum { Opt_treelog, Opt_notreelog, Opt_user_subvol_rm_allowed, -/* Rescue options */ +/* Rescue options, Opt_rescue_* is only for rescue= mount options */ Opt_rescue, Opt_usebackuproot, Opt_nologreplay, + Opt_rescue_skip_bg,/* Deprecated options */ Opt_alloc_start,
@@ -426,6 +427,7 @@ static const match_table_t tokens = {static const match_table_t rescue_tokens = { {Opt_usebackuproot,"usebackuproot" }, {Opt_nologreplay,"nologreplay" }, + {Opt_rescue_skip_bg,"skipbg" }, {Opt_err,NULL }, };
@@ -458,6 +460,10 @@ static int parse_rescue_options(struct btrfs_fs_info *info, const char *options)btrfs_set_and_info (info,NOLOGREPLAY ,"disabling log replay at mount time" );break ; +case Opt_rescue_skip_bg: +btrfs_set_and_info (info,SKIP_BG , +"skip mount time block group searching" ); +break ;case Opt_err:btrfs_info (info,"unrecognized rescue option '%s'" , p); ret = -EINVAL ;
@@ -1381,6 +1387,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry)seq_puts (seq,",notreelog" );if (btrfs_test_opt (info,NOLOGREPLAY ))seq_puts (seq,",rescue=no_log_replay" ); +if (btrfs_test_opt (info,SKIP_BG )) +seq_puts (seq,",rescue=skip_bg" );if (btrfs_test_opt (info,FLUSHONCOMMIT ))seq_puts (seq,",flushoncommit" );if (btrfs_test_opt (info,DISCARD ))
@@ -1808,6 +1816,14 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)if (ret) goto restore; +if (btrfs_test_opt (fs_info,SKIP_BG ) != + (old_opts &BTRFS_MOUNT_SKIP_BG )) { +btrfs_err (fs_info, +"rescue=skip_bg mount option can't be changed during remount" ); + ret = -EINVAL ; + goto restore; + } +btrfs_remount_begin (fs_info, old_opts, *flags);btrfs_resize_thread_pool (fs_info, fs_info->thread_pool_size, old_thread_pool_size);
@@ -1869,6 +1885,13 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) goto restore; } +if (btrfs_test_opt (fs_info,SKIP_BG )) { +btrfs_err (fs_info, +"remounting read-write with rescue=skip_bg is not allowed" ); + ret = -EINVAL ; + goto restore; + } + ret =btrfs_cleanup_fs_roots (fs_info);if (ret) goto restore;
fs/btrfs/volumes.c +7 -0
@@ -7769,6 +7769,13 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)u64 prev_dev_ext_end =0 ;int ret =0 ; +/* +* For rescue=skip_bg mount option, we're already RO and are salvaging +* data, no need for such strict check. +*/ +if (btrfs_test_opt (fs_info,SKIP_BG )) +return 0 ; + key.objectid =1 ; key.type =BTRFS_DEV_EXTENT_KEY ; key.offset =0 ;
Signature · 1 line
2.23.0