2017-03-17 06:18:50 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef _BCACHEFS_ERROR_H
|
|
|
|
#define _BCACHEFS_ERROR_H
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/printk.h>
|
|
|
|
|
|
|
|
struct bch_dev;
|
|
|
|
struct bch_fs;
|
|
|
|
struct work_struct;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: separate out errors that indicate on disk data is inconsistent, and flag
|
|
|
|
* superblock as such
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Error messages: */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inconsistency errors: The on disk data is inconsistent. If these occur during
|
|
|
|
* initial recovery, they don't indicate a bug in the running code - we walk all
|
|
|
|
* the metadata before modifying anything. If they occur at runtime, they
|
|
|
|
* indicate either a bug in the running code or (less likely) data is being
|
|
|
|
* silently corrupted under us.
|
|
|
|
*
|
|
|
|
* XXX: audit all inconsistent errors and make sure they're all recoverable, in
|
|
|
|
* BCH_ON_ERROR_CONTINUE mode
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool bch2_inconsistent_error(struct bch_fs *);
|
|
|
|
|
2021-04-24 20:32:35 +00:00
|
|
|
void bch2_topology_error(struct bch_fs *);
|
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
#define bch2_fs_inconsistent(c, ...) \
|
|
|
|
({ \
|
|
|
|
bch_err(c, __VA_ARGS__); \
|
|
|
|
bch2_inconsistent_error(c); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define bch2_fs_inconsistent_on(cond, c, ...) \
|
|
|
|
({ \
|
2022-02-19 08:56:44 +00:00
|
|
|
bool _ret = unlikely(!!(cond)); \
|
2017-03-17 06:18:50 +00:00
|
|
|
\
|
|
|
|
if (_ret) \
|
|
|
|
bch2_fs_inconsistent(c, __VA_ARGS__); \
|
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Later we might want to mark only the particular device inconsistent, not the
|
|
|
|
* entire filesystem:
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define bch2_dev_inconsistent(ca, ...) \
|
|
|
|
do { \
|
|
|
|
bch_err(ca, __VA_ARGS__); \
|
|
|
|
bch2_inconsistent_error((ca)->fs); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define bch2_dev_inconsistent_on(cond, ca, ...) \
|
|
|
|
({ \
|
2022-02-19 08:56:44 +00:00
|
|
|
bool _ret = unlikely(!!(cond)); \
|
2017-03-17 06:18:50 +00:00
|
|
|
\
|
|
|
|
if (_ret) \
|
|
|
|
bch2_dev_inconsistent(ca, __VA_ARGS__); \
|
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2022-03-03 03:18:56 +00:00
|
|
|
/*
|
|
|
|
* When a transaction update discovers or is causing a fs inconsistency, it's
|
|
|
|
* helpful to also dump the pending updates:
|
|
|
|
*/
|
|
|
|
#define bch2_trans_inconsistent(trans, ...) \
|
|
|
|
({ \
|
|
|
|
bch_err(trans->c, __VA_ARGS__); \
|
|
|
|
bch2_dump_trans_updates(trans); \
|
2023-01-25 15:08:50 +00:00
|
|
|
bch2_inconsistent_error(trans->c); \
|
2022-03-03 03:18:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
#define bch2_trans_inconsistent_on(cond, trans, ...) \
|
|
|
|
({ \
|
|
|
|
bool _ret = unlikely(!!(cond)); \
|
|
|
|
\
|
|
|
|
if (_ret) \
|
|
|
|
bch2_trans_inconsistent(trans, __VA_ARGS__); \
|
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2017-03-17 06:18:50 +00:00
|
|
|
/*
|
|
|
|
* Fsck errors: inconsistency errors we detect at mount time, and should ideally
|
|
|
|
* be able to repair:
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct fsck_err_state {
|
|
|
|
struct list_head list;
|
|
|
|
const char *fmt;
|
|
|
|
u64 nr;
|
2019-11-06 20:32:11 +00:00
|
|
|
bool ratelimited;
|
2023-02-17 02:02:14 +00:00
|
|
|
int ret;
|
2023-04-15 18:26:14 +00:00
|
|
|
int fix;
|
2023-02-17 02:02:14 +00:00
|
|
|
char *last_msg;
|
2017-03-17 06:18:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define FSCK_CAN_FIX (1 << 0)
|
|
|
|
#define FSCK_CAN_IGNORE (1 << 1)
|
|
|
|
#define FSCK_NEED_FSCK (1 << 2)
|
2021-06-21 20:28:43 +00:00
|
|
|
#define FSCK_NO_RATELIMIT (1 << 3)
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2020-06-03 22:27:07 +00:00
|
|
|
__printf(3, 4) __cold
|
2022-07-19 21:20:18 +00:00
|
|
|
int bch2_fsck_err(struct bch_fs *, unsigned, const char *, ...);
|
2017-03-17 06:18:50 +00:00
|
|
|
void bch2_flush_fsck_errs(struct bch_fs *);
|
|
|
|
|
|
|
|
#define __fsck_err(c, _flags, msg, ...) \
|
|
|
|
({ \
|
2022-07-19 21:20:18 +00:00
|
|
|
int _ret = bch2_fsck_err(c, _flags, msg, ##__VA_ARGS__); \
|
2017-03-17 06:18:50 +00:00
|
|
|
\
|
2022-07-19 21:20:18 +00:00
|
|
|
if (_ret != -BCH_ERR_fsck_fix && \
|
|
|
|
_ret != -BCH_ERR_fsck_ignore) { \
|
|
|
|
ret = _ret; \
|
2017-03-17 06:18:50 +00:00
|
|
|
goto fsck_err; \
|
|
|
|
} \
|
|
|
|
\
|
2022-07-19 21:20:18 +00:00
|
|
|
_ret == -BCH_ERR_fsck_fix; \
|
2017-03-17 06:18:50 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
/* These macros return true if error should be fixed: */
|
|
|
|
|
|
|
|
/* XXX: mark in superblock that filesystem contains errors, if we ignore: */
|
|
|
|
|
|
|
|
#define __fsck_err_on(cond, c, _flags, ...) \
|
2022-02-19 08:56:44 +00:00
|
|
|
(unlikely(cond) ? __fsck_err(c, _flags, ##__VA_ARGS__) : false)
|
2017-03-17 06:18:50 +00:00
|
|
|
|
|
|
|
#define need_fsck_err_on(cond, c, ...) \
|
|
|
|
__fsck_err_on(cond, c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define need_fsck_err(c, ...) \
|
|
|
|
__fsck_err(c, FSCK_CAN_IGNORE|FSCK_NEED_FSCK, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define mustfix_fsck_err(c, ...) \
|
|
|
|
__fsck_err(c, FSCK_CAN_FIX, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define mustfix_fsck_err_on(cond, c, ...) \
|
|
|
|
__fsck_err_on(cond, c, FSCK_CAN_FIX, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define fsck_err(c, ...) \
|
|
|
|
__fsck_err(c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define fsck_err_on(cond, c, ...) \
|
|
|
|
__fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fatal errors: these don't indicate a bug, but we can't continue running in RW
|
|
|
|
* mode - pretty much just due to metadata IO errors:
|
|
|
|
*/
|
|
|
|
|
|
|
|
void bch2_fatal_error(struct bch_fs *);
|
|
|
|
|
|
|
|
#define bch2_fs_fatal_error(c, ...) \
|
|
|
|
do { \
|
|
|
|
bch_err(c, __VA_ARGS__); \
|
|
|
|
bch2_fatal_error(c); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define bch2_fs_fatal_err_on(cond, c, ...) \
|
|
|
|
({ \
|
2022-02-19 08:56:44 +00:00
|
|
|
bool _ret = unlikely(!!(cond)); \
|
2017-03-17 06:18:50 +00:00
|
|
|
\
|
|
|
|
if (_ret) \
|
|
|
|
bch2_fs_fatal_error(c, __VA_ARGS__); \
|
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IO errors: either recoverable metadata IO (because we have replicas), or data
|
|
|
|
* IO - we need to log it and print out a message, but we don't (necessarily)
|
|
|
|
* want to shut down the fs:
|
|
|
|
*/
|
|
|
|
|
|
|
|
void bch2_io_error_work(struct work_struct *);
|
|
|
|
|
|
|
|
/* Does the error handling without logging a message */
|
2023-10-25 20:29:37 +00:00
|
|
|
void bch2_io_error(struct bch_dev *, enum bch_member_error_type);
|
2017-03-17 06:18:50 +00:00
|
|
|
|
2023-10-25 20:29:37 +00:00
|
|
|
#define bch2_dev_io_err_on(cond, ca, _type, ...) \
|
2017-03-17 06:18:50 +00:00
|
|
|
({ \
|
|
|
|
bool _ret = (cond); \
|
|
|
|
\
|
2022-11-16 01:25:08 +00:00
|
|
|
if (_ret) { \
|
|
|
|
bch_err_dev_ratelimited(ca, __VA_ARGS__); \
|
2023-10-25 20:29:37 +00:00
|
|
|
bch2_io_error(ca, _type); \
|
2022-11-16 01:25:08 +00:00
|
|
|
} \
|
2017-03-17 06:18:50 +00:00
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2023-10-25 20:29:37 +00:00
|
|
|
#define bch2_dev_inum_io_err_on(cond, ca, _type, ...) \
|
2020-12-03 18:57:22 +00:00
|
|
|
({ \
|
|
|
|
bool _ret = (cond); \
|
|
|
|
\
|
2022-11-16 01:25:08 +00:00
|
|
|
if (_ret) { \
|
|
|
|
bch_err_inum_offset_ratelimited(ca, __VA_ARGS__); \
|
2023-10-25 20:29:37 +00:00
|
|
|
bch2_io_error(ca, _type); \
|
2022-11-16 01:25:08 +00:00
|
|
|
} \
|
2020-12-03 18:57:22 +00:00
|
|
|
_ret; \
|
|
|
|
})
|
2017-03-17 06:18:50 +00:00
|
|
|
|
|
|
|
#endif /* _BCACHEFS_ERROR_H */
|