Commit d55ddf6e authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: Online fsck can now fix errors

BCH_FS_fsck_done -> BCH_FS_fsck_running; set when we might be fixing
fsck errors. Also; set fix_errors to ask by default when fsck is
running.
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 1f34c21b
...@@ -602,9 +602,6 @@ struct bch_dev { ...@@ -602,9 +602,6 @@ struct bch_dev {
}; };
/* /*
* fsck_done - kill?
*
* replace with something more general from enumated fsck passes/errors:
* initial_gc_unfixed * initial_gc_unfixed
* error * error
* topology error * topology error
...@@ -620,7 +617,7 @@ struct bch_dev { ...@@ -620,7 +617,7 @@ struct bch_dev {
x(going_ro) \ x(going_ro) \
x(write_disable_complete) \ x(write_disable_complete) \
x(clean_shutdown) \ x(clean_shutdown) \
x(fsck_done) \ x(fsck_running) \
x(initial_gc_unfixed) \ x(initial_gc_unfixed) \
x(need_another_gc) \ x(need_another_gc) \
x(need_delete_dead_snapshots) \ x(need_delete_dead_snapshots) \
......
...@@ -774,15 +774,24 @@ static int bch2_fsck_online_thread_fn(void *arg) ...@@ -774,15 +774,24 @@ static int bch2_fsck_online_thread_fn(void *arg)
/* /*
* XXX: can we figure out a way to do this without mucking with c->opts? * XXX: can we figure out a way to do this without mucking with c->opts?
*/ */
unsigned old_fix_errors = c->opts.fix_errors;
if (opt_defined(thr->opts, fix_errors)) if (opt_defined(thr->opts, fix_errors))
c->opts.fix_errors = thr->opts.fix_errors; c->opts.fix_errors = thr->opts.fix_errors;
else
c->opts.fix_errors = FSCK_FIX_ask;
c->opts.fsck = true; c->opts.fsck = true;
set_bit(BCH_FS_fsck_running, &c->flags);
c->curr_recovery_pass = BCH_RECOVERY_PASS_check_alloc_info; c->curr_recovery_pass = BCH_RECOVERY_PASS_check_alloc_info;
bch2_run_online_recovery_passes(c); int ret = bch2_run_online_recovery_passes(c);
clear_bit(BCH_FS_fsck_running, &c->flags);
bch_err_fn(c, ret);
c->stdio = NULL; c->stdio = NULL;
c->stdio_filter = NULL; c->stdio_filter = NULL;
c->opts.fix_errors = old_fix_errors;
thread_with_stdio_done(&thr->thr); thread_with_stdio_done(&thr->thr);
......
...@@ -28,7 +28,7 @@ bool bch2_inconsistent_error(struct bch_fs *c) ...@@ -28,7 +28,7 @@ bool bch2_inconsistent_error(struct bch_fs *c)
void bch2_topology_error(struct bch_fs *c) void bch2_topology_error(struct bch_fs *c)
{ {
set_bit(BCH_FS_topology_error, &c->flags); set_bit(BCH_FS_topology_error, &c->flags);
if (test_bit(BCH_FS_fsck_done, &c->flags)) if (!test_bit(BCH_FS_fsck_running, &c->flags))
bch2_inconsistent_error(c); bch2_inconsistent_error(c);
} }
...@@ -141,7 +141,7 @@ static struct fsck_err_state *fsck_err_get(struct bch_fs *c, const char *fmt) ...@@ -141,7 +141,7 @@ static struct fsck_err_state *fsck_err_get(struct bch_fs *c, const char *fmt)
{ {
struct fsck_err_state *s; struct fsck_err_state *s;
if (test_bit(BCH_FS_fsck_done, &c->flags)) if (!test_bit(BCH_FS_fsck_running, &c->flags))
return NULL; return NULL;
list_for_each_entry(s, &c->fsck_error_msgs, list) list_for_each_entry(s, &c->fsck_error_msgs, list)
...@@ -223,7 +223,7 @@ int bch2_fsck_err(struct bch_fs *c, ...@@ -223,7 +223,7 @@ int bch2_fsck_err(struct bch_fs *c,
prt_printf(out, bch2_log_msg(c, "")); prt_printf(out, bch2_log_msg(c, ""));
#endif #endif
if (test_bit(BCH_FS_fsck_done, &c->flags)) { if (!test_bit(BCH_FS_fsck_running, &c->flags)) {
if (c->opts.errors != BCH_ON_ERROR_continue || if (c->opts.errors != BCH_ON_ERROR_continue ||
!(flags & (FSCK_CAN_FIX|FSCK_CAN_IGNORE))) { !(flags & (FSCK_CAN_FIX|FSCK_CAN_IGNORE))) {
prt_str(out, ", shutting down"); prt_str(out, ", shutting down");
...@@ -290,7 +290,7 @@ int bch2_fsck_err(struct bch_fs *c, ...@@ -290,7 +290,7 @@ int bch2_fsck_err(struct bch_fs *c,
bch2_print_string_as_lines(KERN_ERR, out->buf); bch2_print_string_as_lines(KERN_ERR, out->buf);
} }
if (!test_bit(BCH_FS_fsck_done, &c->flags) && if (test_bit(BCH_FS_fsck_running, &c->flags) &&
(ret != -BCH_ERR_fsck_fix && (ret != -BCH_ERR_fsck_fix &&
ret != -BCH_ERR_fsck_ignore)) ret != -BCH_ERR_fsck_ignore))
bch_err(c, "Unable to continue, halting"); bch_err(c, "Unable to continue, halting");
......
...@@ -832,6 +832,9 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -832,6 +832,9 @@ int bch2_fs_recovery(struct bch_fs *c)
if (c->opts.fsck && IS_ENABLED(CONFIG_BCACHEFS_DEBUG)) if (c->opts.fsck && IS_ENABLED(CONFIG_BCACHEFS_DEBUG))
c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_topology); c->recovery_passes_explicit |= BIT_ULL(BCH_RECOVERY_PASS_check_topology);
if (c->opts.fsck)
set_bit(BCH_FS_fsck_running, &c->flags);
ret = bch2_blacklist_table_initialize(c); ret = bch2_blacklist_table_initialize(c);
if (ret) { if (ret) {
bch_err(c, "error initializing blacklist table"); bch_err(c, "error initializing blacklist table");
...@@ -972,6 +975,8 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -972,6 +975,8 @@ int bch2_fs_recovery(struct bch_fs *c)
if (ret) if (ret)
goto err; goto err;
clear_bit(BCH_FS_fsck_running, &c->flags);
/* If we fixed errors, verify that fs is actually clean now: */ /* If we fixed errors, verify that fs is actually clean now: */
if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG) && if (IS_ENABLED(CONFIG_BCACHEFS_DEBUG) &&
test_bit(BCH_FS_errors_fixed, &c->flags) && test_bit(BCH_FS_errors_fixed, &c->flags) &&
...@@ -1066,7 +1071,6 @@ int bch2_fs_recovery(struct bch_fs *c) ...@@ -1066,7 +1071,6 @@ int bch2_fs_recovery(struct bch_fs *c)
ret = 0; ret = 0;
out: out:
set_bit(BCH_FS_fsck_done, &c->flags);
bch2_flush_fsck_errs(c); bch2_flush_fsck_errs(c);
if (!c->opts.keep_journal && if (!c->opts.keep_journal &&
...@@ -1113,7 +1117,6 @@ int bch2_fs_initialize(struct bch_fs *c) ...@@ -1113,7 +1117,6 @@ int bch2_fs_initialize(struct bch_fs *c)
c->curr_recovery_pass = ARRAY_SIZE(recovery_pass_fns); c->curr_recovery_pass = ARRAY_SIZE(recovery_pass_fns);
set_bit(BCH_FS_may_go_rw, &c->flags); set_bit(BCH_FS_may_go_rw, &c->flags);
set_bit(BCH_FS_fsck_done, &c->flags);
for (unsigned i = 0; i < BTREE_ID_NR; i++) for (unsigned i = 0; i < BTREE_ID_NR; i++)
bch2_btree_root_alloc(c, i); bch2_btree_root_alloc(c, i);
......
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