Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "xfs_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include "xfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include "xfs_errortag.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "xfs_error.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "xfs_sysfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "xfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static unsigned int xfs_errortag_random_default[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	XFS_RANDOM_DEFAULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	XFS_RANDOM_IFLUSH_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	XFS_RANDOM_IFLUSH_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	XFS_RANDOM_IFLUSH_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	XFS_RANDOM_IFLUSH_4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	XFS_RANDOM_IFLUSH_5,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	XFS_RANDOM_IFLUSH_6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	XFS_RANDOM_DA_READ_BUF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	XFS_RANDOM_BTREE_CHECK_LBLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	XFS_RANDOM_BTREE_CHECK_SBLOCK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	XFS_RANDOM_ALLOC_READ_AGF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	XFS_RANDOM_IALLOC_READ_AGI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	XFS_RANDOM_ITOBP_INOTOBP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	XFS_RANDOM_IUNLINK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	XFS_RANDOM_IUNLINK_REMOVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	XFS_RANDOM_DIR_INO_VALIDATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	XFS_RANDOM_BULKSTAT_READ_CHUNK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	XFS_RANDOM_IODONE_IOERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	XFS_RANDOM_STRATREAD_IOERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	XFS_RANDOM_STRATCMPL_IOERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	XFS_RANDOM_DIOWRITE_IOERR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	XFS_RANDOM_BMAPIFORMAT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	XFS_RANDOM_FREE_EXTENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	XFS_RANDOM_RMAP_FINISH_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	XFS_RANDOM_REFCOUNT_CONTINUE_UPDATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	XFS_RANDOM_REFCOUNT_FINISH_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	XFS_RANDOM_BMAP_FINISH_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	XFS_RANDOM_AG_RESV_CRITICAL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	XFS_RANDOM_DROP_WRITES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	XFS_RANDOM_LOG_BAD_CRC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	XFS_RANDOM_LOG_ITEM_PIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	XFS_RANDOM_BUF_LRU_REF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	XFS_RANDOM_FORCE_SCRUB_REPAIR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	XFS_RANDOM_FORCE_SUMMARY_RECALC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	XFS_RANDOM_IUNLINK_FALLBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	XFS_RANDOM_BUF_IOERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) struct xfs_errortag_attr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	struct attribute	attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	unsigned int		tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static inline struct xfs_errortag_attr *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) to_attr(struct attribute *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	return container_of(attr, struct xfs_errortag_attr, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) static inline struct xfs_mount *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) to_mp(struct kobject *kobject)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct xfs_kobj *kobj = to_kobj(kobject);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	return container_of(kobj, struct xfs_mount, m_errortag_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) STATIC ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) xfs_errortag_attr_store(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	struct kobject		*kobject,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct attribute	*attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	const char		*buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	size_t			count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct xfs_mount	*mp = to_mp(kobject);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct xfs_errortag_attr *xfs_attr = to_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	int			ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	unsigned int		val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (strcmp(buf, "default") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		val = xfs_errortag_random_default[xfs_attr->tag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		ret = kstrtouint(buf, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ret = xfs_errortag_set(mp, xfs_attr->tag, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) STATIC ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) xfs_errortag_attr_show(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct kobject		*kobject,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct attribute	*attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	char			*buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct xfs_mount	*mp = to_mp(kobject);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct xfs_errortag_attr *xfs_attr = to_attr(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	return snprintf(buf, PAGE_SIZE, "%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			xfs_errortag_get(mp, xfs_attr->tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) static const struct sysfs_ops xfs_errortag_sysfs_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	.show = xfs_errortag_attr_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	.store = xfs_errortag_attr_store,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) #define XFS_ERRORTAG_ATTR_RW(_name, _tag) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static struct xfs_errortag_attr xfs_errortag_attr_##_name = {		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	.attr = {.name = __stringify(_name),				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		 .mode = VERIFY_OCTAL_PERMISSIONS(S_IWUSR | S_IRUGO) },	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	.tag	= (_tag),						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #define XFS_ERRORTAG_ATTR_LIST(_name) &xfs_errortag_attr_##_name.attr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) XFS_ERRORTAG_ATTR_RW(noerror,		XFS_ERRTAG_NOERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) XFS_ERRORTAG_ATTR_RW(iflush1,		XFS_ERRTAG_IFLUSH_1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) XFS_ERRORTAG_ATTR_RW(iflush2,		XFS_ERRTAG_IFLUSH_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) XFS_ERRORTAG_ATTR_RW(iflush3,		XFS_ERRTAG_IFLUSH_3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) XFS_ERRORTAG_ATTR_RW(iflush4,		XFS_ERRTAG_IFLUSH_4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) XFS_ERRORTAG_ATTR_RW(iflush5,		XFS_ERRTAG_IFLUSH_5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) XFS_ERRORTAG_ATTR_RW(iflush6,		XFS_ERRTAG_IFLUSH_6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) XFS_ERRORTAG_ATTR_RW(dareadbuf,		XFS_ERRTAG_DA_READ_BUF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) XFS_ERRORTAG_ATTR_RW(btree_chk_lblk,	XFS_ERRTAG_BTREE_CHECK_LBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) XFS_ERRORTAG_ATTR_RW(btree_chk_sblk,	XFS_ERRTAG_BTREE_CHECK_SBLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) XFS_ERRORTAG_ATTR_RW(readagf,		XFS_ERRTAG_ALLOC_READ_AGF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) XFS_ERRORTAG_ATTR_RW(readagi,		XFS_ERRTAG_IALLOC_READ_AGI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) XFS_ERRORTAG_ATTR_RW(itobp,		XFS_ERRTAG_ITOBP_INOTOBP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) XFS_ERRORTAG_ATTR_RW(iunlink,		XFS_ERRTAG_IUNLINK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) XFS_ERRORTAG_ATTR_RW(iunlinkrm,		XFS_ERRTAG_IUNLINK_REMOVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) XFS_ERRORTAG_ATTR_RW(dirinovalid,	XFS_ERRTAG_DIR_INO_VALIDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) XFS_ERRORTAG_ATTR_RW(bulkstat,		XFS_ERRTAG_BULKSTAT_READ_CHUNK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) XFS_ERRORTAG_ATTR_RW(logiodone,		XFS_ERRTAG_IODONE_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) XFS_ERRORTAG_ATTR_RW(stratread,		XFS_ERRTAG_STRATREAD_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) XFS_ERRORTAG_ATTR_RW(stratcmpl,		XFS_ERRTAG_STRATCMPL_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) XFS_ERRORTAG_ATTR_RW(diowrite,		XFS_ERRTAG_DIOWRITE_IOERR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) XFS_ERRORTAG_ATTR_RW(bmapifmt,		XFS_ERRTAG_BMAPIFORMAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) XFS_ERRORTAG_ATTR_RW(free_extent,	XFS_ERRTAG_FREE_EXTENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) XFS_ERRORTAG_ATTR_RW(rmap_finish_one,	XFS_ERRTAG_RMAP_FINISH_ONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) XFS_ERRORTAG_ATTR_RW(refcount_continue_update,	XFS_ERRTAG_REFCOUNT_CONTINUE_UPDATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) XFS_ERRORTAG_ATTR_RW(refcount_finish_one,	XFS_ERRTAG_REFCOUNT_FINISH_ONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) XFS_ERRORTAG_ATTR_RW(bmap_finish_one,	XFS_ERRTAG_BMAP_FINISH_ONE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) XFS_ERRORTAG_ATTR_RW(ag_resv_critical,	XFS_ERRTAG_AG_RESV_CRITICAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) XFS_ERRORTAG_ATTR_RW(drop_writes,	XFS_ERRTAG_DROP_WRITES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) XFS_ERRORTAG_ATTR_RW(log_bad_crc,	XFS_ERRTAG_LOG_BAD_CRC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) XFS_ERRORTAG_ATTR_RW(log_item_pin,	XFS_ERRTAG_LOG_ITEM_PIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) XFS_ERRORTAG_ATTR_RW(buf_lru_ref,	XFS_ERRTAG_BUF_LRU_REF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) XFS_ERRORTAG_ATTR_RW(force_repair,	XFS_ERRTAG_FORCE_SCRUB_REPAIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) XFS_ERRORTAG_ATTR_RW(bad_summary,	XFS_ERRTAG_FORCE_SUMMARY_RECALC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) XFS_ERRORTAG_ATTR_RW(iunlink_fallback,	XFS_ERRTAG_IUNLINK_FALLBACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) XFS_ERRORTAG_ATTR_RW(buf_ioerror,	XFS_ERRTAG_BUF_IOERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static struct attribute *xfs_errortag_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	XFS_ERRORTAG_ATTR_LIST(noerror),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	XFS_ERRORTAG_ATTR_LIST(iflush1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	XFS_ERRORTAG_ATTR_LIST(iflush2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	XFS_ERRORTAG_ATTR_LIST(iflush3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	XFS_ERRORTAG_ATTR_LIST(iflush4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	XFS_ERRORTAG_ATTR_LIST(iflush5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	XFS_ERRORTAG_ATTR_LIST(iflush6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	XFS_ERRORTAG_ATTR_LIST(dareadbuf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	XFS_ERRORTAG_ATTR_LIST(btree_chk_lblk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	XFS_ERRORTAG_ATTR_LIST(btree_chk_sblk),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	XFS_ERRORTAG_ATTR_LIST(readagf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	XFS_ERRORTAG_ATTR_LIST(readagi),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	XFS_ERRORTAG_ATTR_LIST(itobp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	XFS_ERRORTAG_ATTR_LIST(iunlink),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	XFS_ERRORTAG_ATTR_LIST(iunlinkrm),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	XFS_ERRORTAG_ATTR_LIST(dirinovalid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	XFS_ERRORTAG_ATTR_LIST(bulkstat),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	XFS_ERRORTAG_ATTR_LIST(logiodone),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	XFS_ERRORTAG_ATTR_LIST(stratread),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	XFS_ERRORTAG_ATTR_LIST(stratcmpl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	XFS_ERRORTAG_ATTR_LIST(diowrite),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	XFS_ERRORTAG_ATTR_LIST(bmapifmt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	XFS_ERRORTAG_ATTR_LIST(free_extent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	XFS_ERRORTAG_ATTR_LIST(rmap_finish_one),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	XFS_ERRORTAG_ATTR_LIST(refcount_continue_update),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	XFS_ERRORTAG_ATTR_LIST(refcount_finish_one),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	XFS_ERRORTAG_ATTR_LIST(bmap_finish_one),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	XFS_ERRORTAG_ATTR_LIST(ag_resv_critical),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	XFS_ERRORTAG_ATTR_LIST(drop_writes),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	XFS_ERRORTAG_ATTR_LIST(log_bad_crc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	XFS_ERRORTAG_ATTR_LIST(log_item_pin),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	XFS_ERRORTAG_ATTR_LIST(buf_lru_ref),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	XFS_ERRORTAG_ATTR_LIST(force_repair),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	XFS_ERRORTAG_ATTR_LIST(bad_summary),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	XFS_ERRORTAG_ATTR_LIST(iunlink_fallback),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	XFS_ERRORTAG_ATTR_LIST(buf_ioerror),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) static struct kobj_type xfs_errortag_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	.release = xfs_sysfs_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	.sysfs_ops = &xfs_errortag_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	.default_attrs = xfs_errortag_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) xfs_errortag_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct xfs_mount	*mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	mp->m_errortag = kmem_zalloc(sizeof(unsigned int) * XFS_ERRTAG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			KM_MAYFAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (!mp->m_errortag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return xfs_sysfs_init(&mp->m_errortag_kobj, &xfs_errortag_ktype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			       &mp->m_kobj, "errortag");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) xfs_errortag_del(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct xfs_mount	*mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	xfs_sysfs_del(&mp->m_errortag_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	kmem_free(mp->m_errortag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) xfs_errortag_test(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	const char		*expression,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	const char		*file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	int			line,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	unsigned int		error_tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	unsigned int		randfactor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	 * To be able to use error injection anywhere, we need to ensure error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	 * injection mechanism is already initialized.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * Code paths like I/O completion can be called before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 * initialization is complete, but be able to inject errors in such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	 * places is still useful.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	if (!mp->m_errortag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	ASSERT(error_tag < XFS_ERRTAG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	randfactor = mp->m_errortag[error_tag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	if (!randfactor || prandom_u32() % randfactor)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	xfs_warn_ratelimited(mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) "Injecting error (%s) at file %s, line %d, on filesystem \"%s\"",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			expression, file, line, mp->m_super->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) xfs_errortag_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	unsigned int		error_tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (error_tag >= XFS_ERRTAG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return mp->m_errortag[error_tag];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) xfs_errortag_set(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	unsigned int		error_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	unsigned int		tag_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	if (error_tag >= XFS_ERRTAG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	mp->m_errortag[error_tag] = tag_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) xfs_errortag_add(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	unsigned int		error_tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	if (error_tag >= XFS_ERRTAG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return xfs_errortag_set(mp, error_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			xfs_errortag_random_default[error_tag]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) xfs_errortag_clearall(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	struct xfs_mount	*mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	memset(mp->m_errortag, 0, sizeof(unsigned int) * XFS_ERRTAG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) #endif /* DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) xfs_error_report(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	const char		*tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	int			level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	const char		*filename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	int			linenum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	xfs_failaddr_t		failaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	if (level <= xfs_error_level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		xfs_alert_tag(mp, XFS_PTAG_ERROR_REPORT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		"Internal error %s at line %d of file %s.  Caller %pS",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			    tag, linenum, filename, failaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		xfs_stack_trace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) xfs_corruption_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	const char		*tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	int			level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	struct xfs_mount	*mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	const void		*buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	size_t			bufsize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	const char		*filename,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	int			linenum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	xfs_failaddr_t		failaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	if (buf && level <= xfs_error_level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		xfs_hex_dump(buf, bufsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	xfs_error_report(tag, level, mp, filename, linenum, failaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)  * Complain about the kinds of metadata corruption that we can't detect from a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)  * verifier, such as incorrect inter-block relationship data.  Does not set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)  * bp->b_error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)  * Call xfs_buf_mark_corrupt, not this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) xfs_buf_corruption_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	struct xfs_buf		*bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	xfs_failaddr_t		fa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	struct xfs_mount	*mp = bp->b_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		  "Metadata corruption detected at %pS, %s block 0x%llx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		  fa, bp->b_ops->name, bp->b_bn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	xfs_alert(mp, "Unmount and run xfs_repair");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		xfs_stack_trace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)  * Warnings specifically for verifier errors.  Differentiate CRC vs. invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)  * values, and omit the stack trace unless the error level is tuned high.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) xfs_buf_verifier_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	struct xfs_buf		*bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	int			error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	const char		*name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	const void		*buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	size_t			bufsz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	xfs_failaddr_t		failaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	struct xfs_mount	*mp = bp->b_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	xfs_failaddr_t		fa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	int			sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	fa = failaddr ? failaddr : __return_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	__xfs_buf_ioerror(bp, error, fa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 		  "Metadata %s detected at %pS, %s block 0x%llx %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		  bp->b_error == -EFSBADCRC ? "CRC error" : "corruption",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		  fa, bp->b_ops->name, bp->b_bn, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	xfs_alert(mp, "Unmount and run xfs_repair");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	if (xfs_error_level >= XFS_ERRLEVEL_LOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 				sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		xfs_hex_dump(buf, sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 	if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		xfs_stack_trace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)  * Warnings specifically for verifier errors.  Differentiate CRC vs. invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)  * values, and omit the stack trace unless the error level is tuned high.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) xfs_verifier_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	struct xfs_buf		*bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	int			error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	xfs_failaddr_t		failaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	return xfs_buf_verifier_error(bp, error, "", xfs_buf_offset(bp, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 			XFS_CORRUPTION_DUMP_LEN, failaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)  * Warnings for inode corruption problems.  Don't bother with the stack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)  * trace unless the error level is turned up high.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) xfs_inode_verifier_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	struct xfs_inode	*ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	int			error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	const char		*name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 	const void		*buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	size_t			bufsz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 	xfs_failaddr_t		failaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 	struct xfs_mount	*mp = ip->i_mount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 	xfs_failaddr_t		fa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	int			sz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	fa = failaddr ? failaddr : __return_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	xfs_alert(mp, "Metadata %s detected at %pS, inode 0x%llx %s",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 		  error == -EFSBADCRC ? "CRC error" : "corruption",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		  fa, ip->i_ino, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 	xfs_alert(mp, "Unmount and run xfs_repair");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	if (buf && xfs_error_level >= XFS_ERRLEVEL_LOW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		sz = min_t(size_t, XFS_CORRUPTION_DUMP_LEN, bufsz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 		xfs_alert(mp, "First %d bytes of corrupted metadata buffer:",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 				sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 		xfs_hex_dump(buf, sz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		xfs_stack_trace();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }