129 lines
3.1 KiB
Diff
129 lines
3.1 KiB
Diff
From 422310542e0699139ceba54439ed022097b55ebd Mon Sep 17 00:00:00 2001
|
|
From: Kent Overstreet <kent.overstreet@linux.dev>
|
|
Date: Thu, 28 Nov 2024 16:25:41 -0500
|
|
Subject: [PATCH 141/233] bcachefs: do_fsck_ask_yn()
|
|
Content-Type: text/plain; charset="utf-8"
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
__bch2_fsck_err() is huge, and badly needs more refactoring
|
|
|
|
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
|
|
Signed-off-by: Alexander Miroshnichenko <alex@millerson.name>
|
|
---
|
|
fs/bcachefs/error.c | 59 ++++++++++++++++++++++++++-------------------
|
|
1 file changed, 34 insertions(+), 25 deletions(-)
|
|
|
|
diff --git a/fs/bcachefs/error.c b/fs/bcachefs/error.c
|
|
index 23b9ecbcf3cf..0517782ca57a 100644
|
|
--- a/fs/bcachefs/error.c
|
|
+++ b/fs/bcachefs/error.c
|
|
@@ -219,6 +219,30 @@ static const u8 fsck_flags_extra[] = {
|
|
#undef x
|
|
};
|
|
|
|
+static int do_fsck_ask_yn(struct bch_fs *c,
|
|
+ struct btree_trans *trans,
|
|
+ struct printbuf *question,
|
|
+ const char *action)
|
|
+{
|
|
+ prt_str(question, ", ");
|
|
+ prt_str(question, action);
|
|
+
|
|
+ if (bch2_fs_stdio_redirect(c))
|
|
+ bch2_print(c, "%s", question->buf);
|
|
+ else
|
|
+ bch2_print_string_as_lines(KERN_ERR, question->buf);
|
|
+
|
|
+ int ask = bch2_fsck_ask_yn(c, trans);
|
|
+
|
|
+ if (trans) {
|
|
+ int ret = bch2_trans_relock(trans);
|
|
+ if (ret)
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ return ask;
|
|
+}
|
|
+
|
|
int __bch2_fsck_err(struct bch_fs *c,
|
|
struct btree_trans *trans,
|
|
enum bch_fsck_flags flags,
|
|
@@ -291,16 +315,14 @@ int __bch2_fsck_err(struct bch_fs *c,
|
|
*/
|
|
if (s->last_msg && !strcmp(buf.buf, s->last_msg)) {
|
|
ret = s->ret;
|
|
- mutex_unlock(&c->fsck_error_msgs_lock);
|
|
- goto err;
|
|
+ goto err_unlock;
|
|
}
|
|
|
|
kfree(s->last_msg);
|
|
s->last_msg = kstrdup(buf.buf, GFP_KERNEL);
|
|
if (!s->last_msg) {
|
|
- mutex_unlock(&c->fsck_error_msgs_lock);
|
|
ret = -ENOMEM;
|
|
- goto err;
|
|
+ goto err_unlock;
|
|
}
|
|
|
|
if (c->opts.ratelimit_errors &&
|
|
@@ -356,31 +378,18 @@ int __bch2_fsck_err(struct bch_fs *c,
|
|
: c->opts.fix_errors;
|
|
|
|
if (fix == FSCK_FIX_ask) {
|
|
- prt_str(out, ", ");
|
|
- prt_str(out, action);
|
|
-
|
|
- if (bch2_fs_stdio_redirect(c))
|
|
- bch2_print(c, "%s", out->buf);
|
|
- else
|
|
- bch2_print_string_as_lines(KERN_ERR, out->buf);
|
|
print = false;
|
|
|
|
- int ask = bch2_fsck_ask_yn(c, trans);
|
|
-
|
|
- if (trans) {
|
|
- ret = bch2_trans_relock(trans);
|
|
- if (ret) {
|
|
- mutex_unlock(&c->fsck_error_msgs_lock);
|
|
- goto err;
|
|
- }
|
|
- }
|
|
+ ret = do_fsck_ask_yn(c, trans, out, action);
|
|
+ if (ret < 0)
|
|
+ goto err_unlock;
|
|
|
|
- if (ask >= YN_ALLNO && s)
|
|
- s->fix = ask == YN_ALLNO
|
|
+ if (ret >= YN_ALLNO && s)
|
|
+ s->fix = ret == YN_ALLNO
|
|
? FSCK_FIX_no
|
|
: FSCK_FIX_yes;
|
|
|
|
- ret = ask & 1
|
|
+ ret = ret & 1
|
|
? -BCH_ERR_fsck_fix
|
|
: -BCH_ERR_fsck_ignore;
|
|
} else if (fix == FSCK_FIX_yes ||
|
|
@@ -424,8 +433,6 @@ int __bch2_fsck_err(struct bch_fs *c,
|
|
if (s)
|
|
s->ret = ret;
|
|
|
|
- mutex_unlock(&c->fsck_error_msgs_lock);
|
|
-
|
|
if (inconsistent)
|
|
bch2_inconsistent_error(c);
|
|
|
|
@@ -442,6 +449,8 @@ int __bch2_fsck_err(struct bch_fs *c,
|
|
set_bit(BCH_FS_error, &c->flags);
|
|
}
|
|
}
|
|
+err_unlock:
|
|
+ mutex_unlock(&c->fsck_error_msgs_lock);
|
|
err:
|
|
if (action != action_orig)
|
|
kfree(action);
|
|
--
|
|
2.45.2
|
|
|