bcachefs: bkey errors are only AUTOFIX during read

Newly generated keys, in the transaction commit path or write path,
should not be AUTOFIX; those indicate bugs that we need to fail fast
for.

Fixes: 5612daafb7 ("bcachefs: Fix fsck warnings from bkey validation")
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2024-10-04 15:05:40 -04:00
parent fda7b1ffde
commit 658c82f41e
2 changed files with 12 additions and 8 deletions

View File

@ -430,10 +430,17 @@ err:
int __bch2_bkey_fsck_err(struct bch_fs *c, int __bch2_bkey_fsck_err(struct bch_fs *c,
struct bkey_s_c k, struct bkey_s_c k,
enum bch_fsck_flags flags, enum bch_validate_flags validate_flags,
enum bch_sb_error_id err, enum bch_sb_error_id err,
const char *fmt, ...) const char *fmt, ...)
{ {
if (validate_flags & BCH_VALIDATE_silent)
return -BCH_ERR_fsck_delete_bkey;
unsigned fsck_flags = 0;
if (!(validate_flags & (BCH_VALIDATE_write|BCH_VALIDATE_commit)))
fsck_flags |= FSCK_AUTOFIX|FSCK_CAN_FIX;
struct printbuf buf = PRINTBUF; struct printbuf buf = PRINTBUF;
va_list args; va_list args;
@ -445,7 +452,7 @@ int __bch2_bkey_fsck_err(struct bch_fs *c,
va_end(args); va_end(args);
prt_str(&buf, ": delete?"); prt_str(&buf, ": delete?");
int ret = __bch2_fsck_err(c, NULL, flags, err, "%s", buf.buf); int ret = __bch2_fsck_err(c, NULL, fsck_flags, err, "%s", buf.buf);
printbuf_exit(&buf); printbuf_exit(&buf);
return ret; return ret;
} }

View File

@ -167,10 +167,11 @@ void bch2_flush_fsck_errs(struct bch_fs *);
#define fsck_err_on(cond, c, _err_type, ...) \ #define fsck_err_on(cond, c, _err_type, ...) \
__fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__) __fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
enum bch_validate_flags;
__printf(5, 6) __printf(5, 6)
int __bch2_bkey_fsck_err(struct bch_fs *, int __bch2_bkey_fsck_err(struct bch_fs *,
struct bkey_s_c, struct bkey_s_c,
enum bch_fsck_flags, enum bch_validate_flags,
enum bch_sb_error_id, enum bch_sb_error_id,
const char *, ...); const char *, ...);
@ -180,11 +181,7 @@ int __bch2_bkey_fsck_err(struct bch_fs *,
*/ */
#define bkey_fsck_err(c, _err_type, _err_msg, ...) \ #define bkey_fsck_err(c, _err_type, _err_msg, ...) \
do { \ do { \
if ((flags & BCH_VALIDATE_silent)) { \ int _ret = __bch2_bkey_fsck_err(c, k, flags, \
ret = -BCH_ERR_fsck_delete_bkey; \
goto fsck_err; \
} \
int _ret = __bch2_bkey_fsck_err(c, k, FSCK_CAN_FIX|FSCK_AUTOFIX,\
BCH_FSCK_ERR_##_err_type, \ BCH_FSCK_ERR_##_err_type, \
_err_msg, ##__VA_ARGS__); \ _err_msg, ##__VA_ARGS__); \
if (_ret != -BCH_ERR_fsck_fix && \ if (_ret != -BCH_ERR_fsck_fix && \