Rate limit kernel UFS/FFS cylinder group check-hash error messages.

When a large file is deleted or a large number of files are deleted,
even a single cylinder group with a bad check hash can generate
thousands of check-hash warnings. As with other filesystem messages
such as out-of-space, print a maximum of one check-hash error per
second. Note the limit is per filesystem. If two filesystems have
cylinder group(s) with a bad check hash, each will print a maximum
of one check-hash error message per second.

MFC-after:    1 week
Sponsored-by: The FreeBSD Foundation
This commit is contained in:
Kirk McKusick 2023-08-08 17:10:07 -07:00
parent 76f28f656e
commit 6dff61a1d1

View file

@ -2991,15 +2991,6 @@ ffs_mapsearch(struct fs *fs,
return (-1);
}
static const struct statfs *
ffs_getmntstat(struct vnode *devvp)
{
if (devvp->v_type == VCHR)
return (&devvp->v_rdev->si_mountpt->mnt_stat);
return (ffs_getmntstat(VFSTOUFS(devvp->v_mount)->um_devvp));
}
/*
* Fetch and verify a cylinder group.
*/
@ -3013,6 +3004,7 @@ ffs_getcg(struct fs *fs,
{
struct buf *bp;
struct cg *cgp;
struct mount *mp;
const struct statfs *sfs;
daddr_t blkno;
int error;
@ -3021,10 +3013,13 @@ ffs_getcg(struct fs *fs,
*cgpp = NULL;
if ((fs->fs_metackhash & CK_CYLGRP) != 0)
flags |= GB_CKHASH;
if (devvp->v_type == VREG)
blkno = fragstoblks(fs, cgtod(fs, cg));
else
if (devvp->v_type == VCHR) {
blkno = fsbtodb(fs, cgtod(fs, cg));
mp = devvp->v_rdev->si_mountpt;
} else {
blkno = fragstoblks(fs, cgtod(fs, cg));
mp = devvp->v_mount;
}
error = breadn_flags(devvp, blkno, blkno, (int)fs->fs_cgsize, NULL,
NULL, 0, NOCRED, flags, ffs_ckhash_cg, &bp);
if (error != 0)
@ -3033,28 +3028,35 @@ ffs_getcg(struct fs *fs,
if ((fs->fs_metackhash & CK_CYLGRP) != 0 &&
(bp->b_flags & B_CKHASH) != 0 &&
cgp->cg_ckhash != bp->b_ckhash) {
sfs = ffs_getmntstat(devvp);
printf("UFS %s%s (%s) cylinder checksum failed: cg %ju, cgp: "
"0x%x != bp: 0x%jx\n",
devvp->v_type == VCHR ? "" : "snapshot of ",
sfs->f_mntfromname, sfs->f_mntonname,
(intmax_t)cg, cgp->cg_ckhash, (uintmax_t)bp->b_ckhash);
if (ppsratecheck(&VFSTOUFS(mp)->um_last_integritymsg,
&VFSTOUFS(mp)->um_secs_integritymsg, 1)) {
sfs = &mp->mnt_stat;
printf("UFS %s%s (%s) cylinder checkhash failed: "
"cg %ju, cgp: 0x%x != bp: 0x%jx\n",
devvp->v_type == VCHR ? "" : "snapshot of ",
sfs->f_mntfromname, sfs->f_mntonname, (intmax_t)cg,
cgp->cg_ckhash, (uintmax_t)bp->b_ckhash);
}
bp->b_flags &= ~B_CKHASH;
bp->b_flags |= B_INVAL | B_NOCACHE;
brelse(bp);
return (EIO);
}
if (!cg_chkmagic(cgp) || cgp->cg_cgx != cg) {
sfs = ffs_getmntstat(devvp);
printf("UFS %s%s (%s)",
devvp->v_type == VCHR ? "" : "snapshot of ",
sfs->f_mntfromname, sfs->f_mntonname);
if (!cg_chkmagic(cgp))
printf(" cg %ju: bad magic number 0x%x should be "
"0x%x\n", (intmax_t)cg, cgp->cg_magic, CG_MAGIC);
else
printf(": wrong cylinder group cg %ju != cgx %u\n",
(intmax_t)cg, cgp->cg_cgx);
if (ppsratecheck(&VFSTOUFS(mp)->um_last_integritymsg,
&VFSTOUFS(mp)->um_secs_integritymsg, 1)) {
sfs = &mp->mnt_stat;
printf("UFS %s%s (%s)",
devvp->v_type == VCHR ? "" : "snapshot of ",
sfs->f_mntfromname, sfs->f_mntonname);
if (!cg_chkmagic(cgp))
printf(" cg %ju: bad magic number 0x%x should "
"be 0x%x\n", (intmax_t)cg, cgp->cg_magic,
CG_MAGIC);
else
printf(": wrong cylinder group cg %ju != "
"cgx %u\n", (intmax_t)cg, cgp->cg_cgx);
}
bp->b_flags &= ~B_CKHASH;
bp->b_flags |= B_INVAL | B_NOCACHE;
brelse(bp);