2019-07-10 23:12:15 +03:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2017-10-06 01:41:44 +03:00
|
|
|
#ifndef _BCACHEFS_ERROR_H
|
|
|
|
#define _BCACHEFS_ERROR_H
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2018-05-17 10:07:00 +03:00
|
|
|
#include <linux/list.h>
|
2017-01-08 12:13:18 +03:00
|
|
|
#include <linux/printk.h>
|
2024-08-13 05:46:53 +03:00
|
|
|
#include "bkey_types.h"
|
2023-10-27 23:43:11 +03:00
|
|
|
#include "sb-errors.h"
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2017-03-11 00:40:01 +03:00
|
|
|
struct bch_dev;
|
|
|
|
struct bch_fs;
|
2017-03-20 08:39:19 +03:00
|
|
|
struct work_struct;
|
2017-01-08 12:13:18 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2018-05-04 21:04:31 +03:00
|
|
|
bool bch2_inconsistent_error(struct bch_fs *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2024-02-10 05:30:46 +03:00
|
|
|
int bch2_topology_error(struct bch_fs *);
|
2021-04-24 23:33:06 +03:00
|
|
|
|
2024-03-30 05:09:24 +03:00
|
|
|
#define bch2_fs_topology_error(c, ...) \
|
|
|
|
({ \
|
|
|
|
bch_err(c, "btree topology error: " __VA_ARGS__); \
|
|
|
|
bch2_topology_error(c); \
|
|
|
|
})
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
#define bch2_fs_inconsistent(c, ...) \
|
2018-05-04 21:04:31 +03:00
|
|
|
({ \
|
2017-01-08 12:13:18 +03:00
|
|
|
bch_err(c, __VA_ARGS__); \
|
2017-03-20 02:56:34 +03:00
|
|
|
bch2_inconsistent_error(c); \
|
2018-05-04 21:04:31 +03:00
|
|
|
})
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2024-11-30 05:08:00 +03:00
|
|
|
#define bch2_fs_inconsistent_on(cond, ...) \
|
2017-01-08 12:13:18 +03:00
|
|
|
({ \
|
2022-02-26 20:05:28 +03:00
|
|
|
bool _ret = unlikely(!!(cond)); \
|
2017-01-08 12:13:18 +03:00
|
|
|
if (_ret) \
|
2024-11-30 05:08:00 +03:00
|
|
|
bch2_fs_inconsistent(__VA_ARGS__); \
|
2017-01-08 12:13:18 +03:00
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2022-03-14 02:14:01 +03: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-02-10 02:34:08 +03:00
|
|
|
bch2_inconsistent_error(trans->c); \
|
2022-03-14 02:14:01 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
#define bch2_trans_inconsistent_on(cond, trans, ...) \
|
|
|
|
({ \
|
|
|
|
bool _ret = unlikely(!!(cond)); \
|
|
|
|
\
|
|
|
|
if (_ret) \
|
|
|
|
bch2_trans_inconsistent(trans, __VA_ARGS__); \
|
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2017-01-08 12:13:18 +03:00
|
|
|
/*
|
|
|
|
* Fsck errors: inconsistency errors we detect at mount time, and should ideally
|
|
|
|
* be able to repair:
|
|
|
|
*/
|
|
|
|
|
2017-04-15 07:38:49 +03:00
|
|
|
struct fsck_err_state {
|
|
|
|
struct list_head list;
|
|
|
|
const char *fmt;
|
|
|
|
u64 nr;
|
2019-11-10 06:49:03 +03:00
|
|
|
bool ratelimited;
|
2023-02-18 01:51:22 +03:00
|
|
|
int ret;
|
2023-04-10 21:39:18 +03:00
|
|
|
int fix;
|
2023-02-18 01:51:22 +03:00
|
|
|
char *last_msg;
|
2017-04-15 07:38:49 +03:00
|
|
|
};
|
|
|
|
|
2023-10-27 23:43:11 +03:00
|
|
|
#define fsck_err_count(_c, _err) bch2_sb_err_count(_c, BCH_FSCK_ERR_##_err)
|
2017-03-20 08:39:19 +03:00
|
|
|
|
2024-06-04 00:03:54 +03:00
|
|
|
__printf(5, 6) __cold
|
|
|
|
int __bch2_fsck_err(struct bch_fs *, struct btree_trans *,
|
2023-10-27 23:43:11 +03:00
|
|
|
enum bch_fsck_flags,
|
|
|
|
enum bch_sb_error_id,
|
|
|
|
const char *, ...);
|
2024-06-04 00:03:54 +03:00
|
|
|
#define bch2_fsck_err(c, _flags, _err_type, ...) \
|
|
|
|
__bch2_fsck_err(type_is(c, struct bch_fs *) ? (struct bch_fs *) c : NULL,\
|
|
|
|
type_is(c, struct btree_trans *) ? (struct btree_trans *) c : NULL,\
|
|
|
|
_flags, BCH_FSCK_ERR_##_err_type, __VA_ARGS__)
|
|
|
|
|
2017-04-15 07:38:49 +03:00
|
|
|
void bch2_flush_fsck_errs(struct bch_fs *);
|
|
|
|
|
2024-11-30 05:08:00 +03:00
|
|
|
#define fsck_err_wrap(_do) \
|
2017-03-20 08:39:19 +03:00
|
|
|
({ \
|
2024-11-30 05:08:00 +03:00
|
|
|
int _ret = _do; \
|
2022-08-11 03:28:55 +03:00
|
|
|
if (_ret != -BCH_ERR_fsck_fix && \
|
|
|
|
_ret != -BCH_ERR_fsck_ignore) { \
|
|
|
|
ret = _ret; \
|
2017-01-08 12:13:18 +03:00
|
|
|
goto fsck_err; \
|
|
|
|
} \
|
|
|
|
\
|
2022-08-11 03:28:55 +03:00
|
|
|
_ret == -BCH_ERR_fsck_fix; \
|
2017-01-08 12:13:18 +03:00
|
|
|
})
|
2017-02-02 06:16:42 +03:00
|
|
|
|
2024-11-30 05:08:00 +03:00
|
|
|
#define __fsck_err(...) fsck_err_wrap(bch2_fsck_err(__VA_ARGS__))
|
|
|
|
|
2017-04-15 07:38:49 +03:00
|
|
|
/* These macros return true if error should be fixed: */
|
|
|
|
|
|
|
|
/* XXX: mark in superblock that filesystem contains errors, if we ignore: */
|
|
|
|
|
2023-10-27 23:43:11 +03:00
|
|
|
#define __fsck_err_on(cond, c, _flags, _err_type, ...) \
|
2024-06-04 00:03:54 +03:00
|
|
|
({ \
|
2024-06-17 18:31:26 +03:00
|
|
|
might_sleep(); \
|
|
|
|
\
|
2024-06-04 00:03:54 +03:00
|
|
|
if (type_is(c, struct bch_fs *)) \
|
|
|
|
WARN_ON(bch2_current_has_btree_trans((struct bch_fs *) c));\
|
|
|
|
\
|
|
|
|
(unlikely(cond) ? __fsck_err(c, _flags, _err_type, __VA_ARGS__) : false);\
|
|
|
|
})
|
2023-10-27 23:43:11 +03:00
|
|
|
|
|
|
|
#define mustfix_fsck_err(c, _err_type, ...) \
|
|
|
|
__fsck_err(c, FSCK_CAN_FIX, _err_type, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define mustfix_fsck_err_on(cond, c, _err_type, ...) \
|
|
|
|
__fsck_err_on(cond, c, FSCK_CAN_FIX, _err_type, __VA_ARGS__)
|
2017-02-02 06:16:42 +03:00
|
|
|
|
2023-10-27 23:43:11 +03:00
|
|
|
#define fsck_err(c, _err_type, ...) \
|
|
|
|
__fsck_err(c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
|
2017-02-02 06:16:42 +03:00
|
|
|
|
2023-10-27 23:43:11 +03:00
|
|
|
#define fsck_err_on(cond, c, _err_type, ...) \
|
|
|
|
__fsck_err_on(cond, c, FSCK_CAN_FIX|FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
|
2018-07-16 10:58:54 +03:00
|
|
|
|
2024-11-30 05:08:00 +03:00
|
|
|
#define log_fsck_err(c, _err_type, ...) \
|
|
|
|
__fsck_err(c, FSCK_CAN_IGNORE, _err_type, __VA_ARGS__)
|
|
|
|
|
|
|
|
#define log_fsck_err_on(cond, ...) \
|
|
|
|
({ \
|
|
|
|
bool _ret = unlikely(!!(cond)); \
|
|
|
|
if (_ret) \
|
|
|
|
log_fsck_err(__VA_ARGS__); \
|
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2024-10-10 02:49:05 +03:00
|
|
|
enum bch_validate_flags;
|
2024-08-13 05:46:53 +03:00
|
|
|
__printf(5, 6)
|
|
|
|
int __bch2_bkey_fsck_err(struct bch_fs *,
|
|
|
|
struct bkey_s_c,
|
2024-11-30 05:08:00 +03:00
|
|
|
struct bkey_validate_context from,
|
2024-08-13 05:46:53 +03:00
|
|
|
enum bch_sb_error_id,
|
|
|
|
const char *, ...);
|
2017-02-02 06:16:42 +03:00
|
|
|
|
2024-08-13 05:46:53 +03:00
|
|
|
/*
|
|
|
|
* for now, bkey fsck errors are always handled by deleting the entire key -
|
|
|
|
* this will change at some point
|
|
|
|
*/
|
|
|
|
#define bkey_fsck_err(c, _err_type, _err_msg, ...) \
|
2023-10-27 23:43:11 +03:00
|
|
|
do { \
|
2024-11-30 05:08:00 +03:00
|
|
|
int _ret = __bch2_bkey_fsck_err(c, k, from, \
|
2024-08-13 05:46:53 +03:00
|
|
|
BCH_FSCK_ERR_##_err_type, \
|
|
|
|
_err_msg, ##__VA_ARGS__); \
|
|
|
|
if (_ret != -BCH_ERR_fsck_fix && \
|
|
|
|
_ret != -BCH_ERR_fsck_ignore) \
|
|
|
|
ret = _ret; \
|
|
|
|
ret = -BCH_ERR_fsck_delete_bkey; \
|
2023-10-27 23:43:11 +03:00
|
|
|
goto fsck_err; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define bkey_fsck_err_on(cond, ...) \
|
|
|
|
do { \
|
|
|
|
if (unlikely(cond)) \
|
|
|
|
bkey_fsck_err(__VA_ARGS__); \
|
|
|
|
} while (0)
|
2017-01-08 12:13:18 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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:
|
|
|
|
*/
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
void bch2_fatal_error(struct bch_fs *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2024-03-30 05:09:24 +03:00
|
|
|
#define bch2_fs_fatal_error(c, _msg, ...) \
|
2017-01-08 12:13:18 +03:00
|
|
|
do { \
|
2024-03-30 05:09:24 +03:00
|
|
|
bch_err(c, "%s(): fatal error " _msg, __func__, ##__VA_ARGS__); \
|
2017-03-20 02:56:34 +03:00
|
|
|
bch2_fatal_error(c); \
|
2017-01-08 12:13:18 +03:00
|
|
|
} while (0)
|
|
|
|
|
2017-03-20 02:56:34 +03:00
|
|
|
#define bch2_fs_fatal_err_on(cond, c, ...) \
|
2017-01-08 12:13:18 +03:00
|
|
|
({ \
|
2022-02-26 20:05:28 +03:00
|
|
|
bool _ret = unlikely(!!(cond)); \
|
2017-01-08 12:13:18 +03:00
|
|
|
\
|
|
|
|
if (_ret) \
|
2017-03-20 02:56:34 +03:00
|
|
|
bch2_fs_fatal_error(c, __VA_ARGS__); \
|
2017-01-08 12:13:18 +03:00
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
2017-06-14 04:06:05 +03:00
|
|
|
* 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:
|
2017-01-08 12:13:18 +03:00
|
|
|
*/
|
|
|
|
|
2017-06-14 04:06:05 +03:00
|
|
|
void bch2_io_error_work(struct work_struct *);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
|
|
|
/* Does the error handling without logging a message */
|
2023-10-27 23:43:11 +03:00
|
|
|
void bch2_io_error(struct bch_dev *, enum bch_member_error_type);
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2023-10-27 23:43:11 +03:00
|
|
|
#define bch2_dev_io_err_on(cond, ca, _type, ...) \
|
2017-01-08 12:13:18 +03:00
|
|
|
({ \
|
|
|
|
bool _ret = (cond); \
|
|
|
|
\
|
2022-11-19 02:21:11 +03:00
|
|
|
if (_ret) { \
|
|
|
|
bch_err_dev_ratelimited(ca, __VA_ARGS__); \
|
2023-10-27 23:43:11 +03:00
|
|
|
bch2_io_error(ca, _type); \
|
2022-11-19 02:21:11 +03:00
|
|
|
} \
|
2017-01-08 12:13:18 +03:00
|
|
|
_ret; \
|
|
|
|
})
|
|
|
|
|
2023-10-27 23:43:11 +03:00
|
|
|
#define bch2_dev_inum_io_err_on(cond, ca, _type, ...) \
|
2020-12-04 21:41:49 +03:00
|
|
|
({ \
|
|
|
|
bool _ret = (cond); \
|
|
|
|
\
|
2022-11-19 02:21:11 +03:00
|
|
|
if (_ret) { \
|
|
|
|
bch_err_inum_offset_ratelimited(ca, __VA_ARGS__); \
|
2023-10-27 23:43:11 +03:00
|
|
|
bch2_io_error(ca, _type); \
|
2022-11-19 02:21:11 +03:00
|
|
|
} \
|
2020-12-04 21:41:49 +03:00
|
|
|
_ret; \
|
|
|
|
})
|
2017-01-08 12:13:18 +03:00
|
|
|
|
2024-11-30 05:08:00 +03:00
|
|
|
int bch2_inum_err_msg_trans(struct btree_trans *, struct printbuf *, subvol_inum);
|
|
|
|
int bch2_inum_offset_err_msg_trans(struct btree_trans *, struct printbuf *, subvol_inum, u64);
|
|
|
|
|
|
|
|
void bch2_inum_err_msg(struct bch_fs *, struct printbuf *, subvol_inum);
|
|
|
|
void bch2_inum_offset_err_msg(struct bch_fs *, struct printbuf *, subvol_inum, u64);
|
|
|
|
|
2017-10-06 01:41:44 +03:00
|
|
|
#endif /* _BCACHEFS_ERROR_H */
|