Skip to content

Commit 6a3bd8f

Browse files
author
Darrick J. Wong
committed
xfs: complain about bad file mapping records in the ondisk bmbt
Similar to what we've just done for the other btrees, create a function to log corrupt bmbt records and call it whenever we encounter a bad record in the ondisk btree. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent ee12eaa commit 6a3bd8f

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,34 @@ struct xfs_iread_state {
10831083
xfs_extnum_t loaded;
10841084
};
10851085

1086+
int
1087+
xfs_bmap_complain_bad_rec(
1088+
struct xfs_inode *ip,
1089+
int whichfork,
1090+
xfs_failaddr_t fa,
1091+
const struct xfs_bmbt_irec *irec)
1092+
{
1093+
struct xfs_mount *mp = ip->i_mount;
1094+
const char *forkname;
1095+
1096+
switch (whichfork) {
1097+
case XFS_DATA_FORK: forkname = "data"; break;
1098+
case XFS_ATTR_FORK: forkname = "attr"; break;
1099+
case XFS_COW_FORK: forkname = "CoW"; break;
1100+
default: forkname = "???"; break;
1101+
}
1102+
1103+
xfs_warn(mp,
1104+
"Bmap BTree record corruption in inode 0x%llx %s fork detected at %pS!",
1105+
ip->i_ino, forkname, fa);
1106+
xfs_warn(mp,
1107+
"Offset 0x%llx, start block 0x%llx, block count 0x%llx state 0x%x",
1108+
irec->br_startoff, irec->br_startblock, irec->br_blockcount,
1109+
irec->br_state);
1110+
1111+
return -EFSCORRUPTED;
1112+
}
1113+
10861114
/* Stuff every bmbt record from this block into the incore extent map. */
10871115
static int
10881116
xfs_iread_bmbt_block(
@@ -1125,7 +1153,8 @@ xfs_iread_bmbt_block(
11251153
xfs_inode_verifier_error(ip, -EFSCORRUPTED,
11261154
"xfs_iread_extents(2)", frp,
11271155
sizeof(*frp), fa);
1128-
return -EFSCORRUPTED;
1156+
return xfs_bmap_complain_bad_rec(ip, whichfork, fa,
1157+
&new);
11291158
}
11301159
xfs_iext_insert(ip, &ir->icur, &new,
11311160
xfs_bmap_fork_to_state(whichfork));

fs/xfs/libxfs/xfs_bmap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ static inline uint32_t xfs_bmap_fork_to_state(int whichfork)
265265

266266
xfs_failaddr_t xfs_bmap_validate_extent(struct xfs_inode *ip, int whichfork,
267267
struct xfs_bmbt_irec *irec);
268+
int xfs_bmap_complain_bad_rec(struct xfs_inode *ip, int whichfork,
269+
xfs_failaddr_t fa, const struct xfs_bmbt_irec *irec);
268270

269271
int xfs_bmapi_remap(struct xfs_trans *tp, struct xfs_inode *ip,
270272
xfs_fileoff_t bno, xfs_filblks_t len, xfs_fsblock_t startblock,

fs/xfs/libxfs/xfs_inode_fork.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ xfs_iformat_extents(
140140
xfs_inode_verifier_error(ip, -EFSCORRUPTED,
141141
"xfs_iformat_extents(2)",
142142
dp, sizeof(*dp), fa);
143-
return -EFSCORRUPTED;
143+
return xfs_bmap_complain_bad_rec(ip, whichfork,
144+
fa, &new);
144145
}
145146

146147
xfs_iext_insert(ip, &icur, &new, state);

0 commit comments

Comments
 (0)