Skip to content

Commit 642c1aa

Browse files
author
Kent Overstreet
committed
bcachefs: Use bch2_err_matches() for BCH_ERR_fsck_(fix|ignore)
We'll be adding subtypes of these errors, and new error code tracing. Signed-off-by: Kent Overstreet <[email protected]>
1 parent dc43f6a commit 642c1aa

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

fs/bcachefs/alloc_background.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ static int __need_discard_or_freespace_err(struct btree_trans *trans,
709709
set ? "" : "un",
710710
bch2_btree_id_str(btree),
711711
buf.buf);
712-
if (ret == -BCH_ERR_fsck_ignore ||
713-
ret == -BCH_ERR_fsck_errors_not_fixed)
712+
if (bch2_err_matches(ret, BCH_ERR_fsck_ignore) ||
713+
bch2_err_matches(ret, BCH_ERR_fsck_errors_not_fixed))
714714
ret = 0;
715715

716716
printbuf_exit(&buf);

fs/bcachefs/btree_io.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,8 @@ static int __btree_err(int ret,
602602
switch (ret) {
603603
case -BCH_ERR_btree_node_read_err_fixable:
604604
ret2 = bch2_fsck_err_opt(c, FSCK_CAN_FIX, err_type);
605-
if (ret2 != -BCH_ERR_fsck_fix &&
606-
ret2 != -BCH_ERR_fsck_ignore) {
605+
if (!bch2_err_matches(ret2, BCH_ERR_fsck_fix) &&
606+
!bch2_err_matches(ret2, BCH_ERR_fsck_ignore)) {
607607
ret = ret2;
608608
goto fsck_err;
609609
}
@@ -631,8 +631,8 @@ static int __btree_err(int ret,
631631
switch (ret) {
632632
case -BCH_ERR_btree_node_read_err_fixable:
633633
ret2 = __bch2_fsck_err(c, NULL, FSCK_CAN_FIX, err_type, "%s", out.buf);
634-
if (ret2 != -BCH_ERR_fsck_fix &&
635-
ret2 != -BCH_ERR_fsck_ignore) {
634+
if (!bch2_err_matches(ret2, BCH_ERR_fsck_fix) &&
635+
!bch2_err_matches(ret2, BCH_ERR_fsck_ignore)) {
636636
ret = ret2;
637637
goto fsck_err;
638638
}
@@ -660,7 +660,7 @@ static int __btree_err(int ret,
660660
failed, err_msg, \
661661
msg, ##__VA_ARGS__); \
662662
\
663-
if (_ret != -BCH_ERR_fsck_fix) { \
663+
if (!bch2_err_matches(_ret, BCH_ERR_fsck_fix)) { \
664664
ret = _ret; \
665665
goto fsck_err; \
666666
} \

fs/bcachefs/error.c

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ int __bch2_fsck_err(struct bch_fs *c,
444444
{
445445
va_list args;
446446
struct printbuf buf = PRINTBUF, *out = &buf;
447-
int ret = -BCH_ERR_fsck_ignore;
447+
int ret = 0;
448448
const char *action_orig = "fix?", *action = action_orig;
449449

450450
might_sleep();
@@ -573,19 +573,26 @@ int __bch2_fsck_err(struct bch_fs *c,
573573
} else {
574574
prt_str(out, ", not ");
575575
prt_actioning(out, action);
576+
ret = -BCH_ERR_fsck_ignore;
577+
}
578+
} else {
579+
if (flags & FSCK_CAN_IGNORE) {
580+
prt_str(out, ", continuing");
581+
ret = -BCH_ERR_fsck_ignore;
582+
} else {
583+
prt_str(out, " (repair unimplemented)");
584+
ret = -BCH_ERR_fsck_repair_unimplemented;
576585
}
577-
} else if (!(flags & FSCK_CAN_IGNORE)) {
578-
prt_str(out, " (repair unimplemented)");
579586
}
580587

581-
if (ret == -BCH_ERR_fsck_ignore &&
588+
if (bch2_err_matches(ret, BCH_ERR_fsck_ignore) &&
582589
(c->opts.fix_errors == FSCK_FIX_exit ||
583590
!(flags & FSCK_CAN_IGNORE)))
584591
ret = -BCH_ERR_fsck_errors_not_fixed;
585592

586593
if (test_bit(BCH_FS_in_fsck, &c->flags) &&
587-
(ret != -BCH_ERR_fsck_fix &&
588-
ret != -BCH_ERR_fsck_ignore)) {
594+
(!bch2_err_matches(ret, BCH_ERR_fsck_fix) &&
595+
!bch2_err_matches(ret, BCH_ERR_fsck_ignore))) {
589596
exiting = true;
590597
print = true;
591598
}
@@ -613,26 +620,26 @@ int __bch2_fsck_err(struct bch_fs *c,
613620

614621
if (s)
615622
s->ret = ret;
616-
623+
err_unlock:
624+
mutex_unlock(&c->fsck_error_msgs_lock);
625+
err:
617626
/*
618627
* We don't yet track whether the filesystem currently has errors, for
619628
* log_fsck_err()s: that would require us to track for every error type
620629
* which recovery pass corrects it, to get the fsck exit status correct:
621630
*/
622-
if (flags & FSCK_CAN_FIX) {
623-
if (ret == -BCH_ERR_fsck_fix) {
624-
set_bit(BCH_FS_errors_fixed, &c->flags);
625-
} else {
626-
set_bit(BCH_FS_errors_not_fixed, &c->flags);
627-
set_bit(BCH_FS_error, &c->flags);
628-
}
631+
if (bch2_err_matches(ret, BCH_ERR_fsck_fix)) {
632+
set_bit(BCH_FS_errors_fixed, &c->flags);
633+
} else {
634+
set_bit(BCH_FS_errors_not_fixed, &c->flags);
635+
set_bit(BCH_FS_error, &c->flags);
629636
}
630-
err_unlock:
631-
mutex_unlock(&c->fsck_error_msgs_lock);
632-
err:
637+
633638
if (action != action_orig)
634639
kfree(action);
635640
printbuf_exit(&buf);
641+
642+
BUG_ON(!ret);
636643
return ret;
637644
}
638645

fs/bcachefs/error.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ void bch2_free_fsck_errs(struct bch_fs *);
105105
#define fsck_err_wrap(_do) \
106106
({ \
107107
int _ret = _do; \
108-
if (_ret != -BCH_ERR_fsck_fix && \
109-
_ret != -BCH_ERR_fsck_ignore) { \
108+
if (!bch2_err_matches(_ret, BCH_ERR_fsck_fix) && \
109+
!bch2_err_matches(_ret, BCH_ERR_fsck_ignore)) { \
110110
ret = _ret; \
111111
goto fsck_err; \
112112
} \
113113
\
114-
_ret == -BCH_ERR_fsck_fix; \
114+
bch2_err_matches(_ret, BCH_ERR_fsck_fix); \
115115
})
116116

117117
#define __fsck_err(...) fsck_err_wrap(bch2_fsck_err(__VA_ARGS__))
@@ -170,8 +170,8 @@ do { \
170170
int _ret = __bch2_bkey_fsck_err(c, k, from, \
171171
BCH_FSCK_ERR_##_err_type, \
172172
_err_msg, ##__VA_ARGS__); \
173-
if (_ret != -BCH_ERR_fsck_fix && \
174-
_ret != -BCH_ERR_fsck_ignore) \
173+
if (!bch2_err_matches(_ret, BCH_ERR_fsck_fix) && \
174+
!bch2_err_matches(_ret, BCH_ERR_fsck_ignore)) \
175175
ret = _ret; \
176176
ret = -BCH_ERR_fsck_delete_bkey; \
177177
goto fsck_err; \

0 commit comments

Comments
 (0)