Skip to content

Commit 7ebc7e5

Browse files
Johannes Thumshirnkdave
authored andcommitted
btrfs: format checksums according to type for printing
Add a small helper for btrfs_print_data_csum_error() which formats the checksum according to it's type for pretty printing. Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: David Sterba <[email protected]> [ shorten macro name ] Signed-off-by: David Sterba <[email protected]>
1 parent 10fe6ca commit 7ebc7e5

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

fs/btrfs/btrfs_inode.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,22 +337,34 @@ static inline void btrfs_inode_resume_unlocked_dio(struct btrfs_inode *inode)
337337
clear_bit(BTRFS_INODE_READDIO_NEED_LOCK, &inode->runtime_flags);
338338
}
339339

340+
/* Array of bytes with variable length, hexadecimal format 0x1234 */
341+
#define CSUM_FMT "0x%*phN"
342+
#define CSUM_FMT_VALUE(size, bytes) size, bytes
343+
340344
static inline void btrfs_print_data_csum_error(struct btrfs_inode *inode,
341345
u64 logical_start, u32 csum, u32 csum_expected, int mirror_num)
342346
{
343347
struct btrfs_root *root = inode->root;
348+
struct btrfs_super_block *sb = root->fs_info->super_copy;
349+
const u16 csum_size = btrfs_super_csum_size(sb);
344350

345351
/* Output minus objectid, which is more meaningful */
346352
if (root->root_key.objectid >= BTRFS_LAST_FREE_OBJECTID)
347353
btrfs_warn_rl(root->fs_info,
348-
"csum failed root %lld ino %lld off %llu csum 0x%08x expected csum 0x%08x mirror %d",
354+
"csum failed root %lld ino %lld off %llu csum " CSUM_FMT " expected csum " CSUM_FMT " mirror %d",
349355
root->root_key.objectid, btrfs_ino(inode),
350-
logical_start, csum, csum_expected, mirror_num);
356+
logical_start,
357+
CSUM_FMT_VALUE(csum_size, &csum),
358+
CSUM_FMT_VALUE(csum_size, &csum_expected),
359+
mirror_num);
351360
else
352361
btrfs_warn_rl(root->fs_info,
353-
"csum failed root %llu ino %llu off %llu csum 0x%08x expected csum 0x%08x mirror %d",
362+
"csum failed root %llu ino %llu off %llu csum " CSUM_FMT " expected csum " CSUM_FMT " mirror %d",
354363
root->root_key.objectid, btrfs_ino(inode),
355-
logical_start, csum, csum_expected, mirror_num);
364+
logical_start,
365+
CSUM_FMT_VALUE(csum_size, &csum),
366+
CSUM_FMT_VALUE(csum_size, &csum_expected),
367+
mirror_num);
356368
}
357369

358370
#endif

0 commit comments

Comments
 (0)