xfs: more and better verifiers
cover xfs: more and better verifiers
Hi all,
This RFC combines all the random little fixes and improvements to the verifiers that we've been talking about for the past month or so into a single patch series!
We start by refactoring the long format btree block header verifier into a single helper functionn and de-macroing dir block verifiers to make them less shouty. Next, we change verifier functions to return the approximate instruction pointer of the faulting test so that we can report more precise fault information to dmesg/tracepoints. Then, we move on to creating verifiers for all the inline format fork formats, and create a helper function for _iget that can dispatch inline verification. The ability to supply custom verifier functions will be used by xfs_repair to deal with corrupt inodes. The last patch enables us to (re)check the structure of incore metadata buffers to try to detect memory corruption.
--D
PATCH 1/12 xfs: refactor long-format btree header verification routines
From: Darrick J. Wong <[email protected]>
Create two helper functions to verify the headers of a long format btree block. We'll use this later for the realtime rmapbt.
--- fs/xfs/libxfs/xfs_bmap_btree.c | 22 ++----------------- fs/xfs/libxfs/xfs_btree.c | 47 ++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_btree.h | 3 +++ 3 files changed, 52 insertions(+), 20 deletions(-)
fs/xfs/libxfs/xfs_bmap_btree.c +2 -20
@@ -627,17 +627,11 @@ xfs_bmbt_verify(switch (block->bb_magic) {case cpu_to_be32 (XFS_BMAP_CRC_MAGIC ): -if (!xfs_sb_version_hascrc (&mp->m_sb)) -return false; -if (!uuid_equal (&block->bb_u.l.bb_uuid, &mp->m_sb.sb_meta_uuid)) -return false; -if (be64_to_cpu (block->bb_u.l.bb_blkno) != bp->b_bn) -return false;/* * XXX: need a better way of verifying the owner here. Right now * just make sure there has been one set. */ -if (be64_to_cpu (block->bb_u.l.bb_owner) ==0 ) +if (!xfs_btree_lblock_v5hdr_verify (bp,XFS_RMAP_OWN_UNKNOWN ))return false;/* fall through */ case cpu_to_be32 (XFS_BMAP_MAGIC ):
@@ -656,20 +650,8 @@ xfs_bmbt_verify( level =be16_to_cpu (block->bb_level);if (level >max (mp->m_bm_maxlevels[0 ], mp->m_bm_maxlevels[1 ]))return false; -if (be16_to_cpu (block->bb_numrecs) > mp->m_bmap_dmxr[level !=0 ]) -return false; - -/* sibling pointer verification */ -if (!block->bb_u.l.bb_leftsib || - (block->bb_u.l.bb_leftsib !=cpu_to_be64 (NULLFSBLOCK ) && - !XFS_FSB_SANITY_CHECK (mp,be64_to_cpu (block->bb_u.l.bb_leftsib)))) -return false; -if (!block->bb_u.l.bb_rightsib || - (block->bb_u.l.bb_rightsib !=cpu_to_be64 (NULLFSBLOCK ) && - !XFS_FSB_SANITY_CHECK (mp,be64_to_cpu (block->bb_u.l.bb_rightsib)))) -return false; -return true; +return xfs_btree_lblock_verify (bp, mp->m_bmap_dmxr[level !=0 ]); } static void
fs/xfs/libxfs/xfs_btree.c +47 -0
53 lines not on this page · raw message
fs/xfs/libxfs/xfs_btree.h +3 -0
@@ -480,6 +480,9 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block)bool xfs_btree_sblock_v5hdr_verify (struct xfs_buf *bp);bool xfs_btree_sblock_verify (struct xfs_buf *bp,unsigned int max_recs); +bool xfs_btree_lblock_v5hdr_verify (struct xfs_buf *bp,uint64_t owner); +bool xfs_btree_lblock_verify (struct xfs_buf *bp,unsigned int max_recs); +uint xfs_btree_compute_maxlevels (struct xfs_mount *mp,uint *limits,unsigned long len); unsigned long long xfs_btree_calc_size(struct xfs_mount *mp, uint *limits,
PATCH 2/12 xfs: remove XFS_WANT_CORRUPTED_RETURN from dir3 data verifiers
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Since __xfs_dir3_data_check verifies on-disk metadata, we can't have it noisily blowing asserts and hanging the system on corrupt data coming in off the disk. Instead, have it return a boolean like all the other checker functions, and only have it noisily fail if we fail in debug mode.
--- fs/xfs/libxfs/xfs_dir2_block.c | 4 -- fs/xfs/libxfs/xfs_dir2_data.c | 100 +++++++++++++++++++++------------------- fs/xfs/libxfs/xfs_dir2_priv.h | 10 +++- 3 files changed, 61 insertions(+), 53 deletions(-)
fs/xfs/libxfs/xfs_dir2_block.c +1 -3
@@ -78,9 +78,7 @@ xfs_dir3_block_verify(if (hdr3->magic !=cpu_to_be32 (XFS_DIR2_BLOCK_MAGIC ))return false; } -if (__xfs_dir3_data_check (NULL , bp)) -return false; -return true; +return __xfs_dir3_data_check (NULL , bp); } static void
fs/xfs/libxfs/xfs_dir2_data.c +52 -48
177 lines not on this page · raw message
fs/xfs/libxfs/xfs_dir2_priv.h +8 -2
@@ -39,12 +39,18 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,/* xfs_dir2_data.c */ #ifdef DEBUG -#define xfs_dir3_data_check (dp,bp) __xfs_dir3_data_check(dp, bp); +#define xfs_dir3_data_check (dp, bp) \ +do { \ + if (!__xfs_dir3_data_check((dp), (bp))) { \ + XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, \ + (bp)->b_target->bt_mount, (bp)->b_addr); \ + } \ +} while (0)#else #define xfs_dir3_data_check (dp,bp)#endif -extern int __xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp); +extern bool __xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp);extern int xfs_dir3_data_read (struct xfs_trans *tp,struct xfs_inode *dp,xfs_dablk_t bno,xfs_daddr_t mapped_bno,struct xfs_buf **bpp); extern int xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno,
PATCH 3/12 xfs: have buffer verifier functions report failing address
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Modify each function that checks the contents of a metadata buffer to return the instruction address of the failing test so that we can report more precise failure errors to the log.
--- fs/xfs/libxfs/xfs_alloc.c | 43 ++++++++++++----------- fs/xfs/libxfs/xfs_alloc_btree.c | 25 +++++++------- fs/xfs/libxfs/xfs_attr_leaf.c | 20 +++++------ fs/xfs/libxfs/xfs_attr_remote.c | 36 ++++++++++---------- fs/xfs/libxfs/xfs_bmap_btree.c | 16 +++++---- fs/xfs/libxfs/xfs_btree.c | 46 +++++++++++++------------ fs/xfs/libxfs/xfs_btree.h | 8 ++-- fs/xfs/libxfs/xfs_da_btree.c | 26 +++++++------- fs/xfs/libxfs/xfs_dir2_block.c | 16 ++++----- fs/xfs/libxfs/xfs_dir2_data.c | 66 ++++++++++++++++++------------------ fs/xfs/libxfs/xfs_dir2_leaf.c | 30 ++++++++-------- fs/xfs/libxfs/xfs_dir2_node.c | 36 ++++++++++---------- fs/xfs/libxfs/xfs_dir2_priv.h | 6 ++- fs/xfs/libxfs/xfs_ialloc.c | 22 ++++++------ fs/xfs/libxfs/xfs_ialloc_btree.c | 15 ++++---- fs/xfs/libxfs/xfs_inode_buf.c | 30 ++++++++-------- fs/xfs/libxfs/xfs_inode_buf.h | 4 +- fs/xfs/libxfs/xfs_refcount_btree.c | 19 +++++----- fs/xfs/libxfs/xfs_rmap_btree.c | 19 +++++----- fs/xfs/libxfs/xfs_symlink_remote.c | 22 ++++++------ fs/xfs/xfs_linux.h | 1 + 21 files changed, 257 insertions(+), 249 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +22 -21
@@ -519,7 +519,7 @@ xfs_alloc_fixup_trees(return 0 ; } -static bool +static void *xfs_agfl_verify (struct xfs_buf *bp) {
@@ -528,9 +528,9 @@ xfs_agfl_verify(int i;if (!uuid_equal (&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be32_to_cpu (agfl->agfl_magicnum) !=XFS_AGFL_MAGIC ) -return false; +return __this_address;/* * during growfs operations, the perag is not fully initialised, * so we can't use it for any useful checking. growfs ensures we can't
@@ -538,16 +538,17 @@ xfs_agfl_verify(* so we can detect and avoid this problem. */ if (bp->b_pag &&be32_to_cpu (agfl->agfl_seqno) != bp->b_pag->pag_agno) -return false; +return __this_address;for (i =0 ; i <XFS_AGFL_SIZE (mp); i++) {if (be32_to_cpu (agfl->agfl_bno[i]) !=NULLAGBLOCK &&be32_to_cpu (agfl->agfl_bno[i]) >= mp->m_sb.sb_agblocks) -return false; +return __this_address; } -return xfs_log_check_lsn (mp, -be64_to_cpu (XFS_BUF_TO_AGFL (bp)->agfl_lsn)); +if (!xfs_log_check_lsn (mp,be64_to_cpu (XFS_BUF_TO_AGFL (bp)->agfl_lsn))) +return __this_address; +return NULL ; } static void
@@ -567,7 +568,7 @@ xfs_agfl_read_verify(if (!xfs_buf_verify_cksum (bp,XFS_AGFL_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_agfl_verify (bp)) +else if (xfs_agfl_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -585,7 +586,7 @@ xfs_agfl_write_verify(if (!xfs_sb_version_hascrc (&mp->m_sb))return ; -if (!xfs_agfl_verify (bp)) { +if (xfs_agfl_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -2388,7 +2389,7 @@ xfs_alloc_put_freelist(return 0 ; } -static bool +static void *xfs_agf_verify (struct xfs_mount *mp,struct xfs_buf *bp)
@@ -2397,10 +2398,10 @@ xfs_agf_verify(if (xfs_sb_version_hascrc (&mp->m_sb)) {if (!uuid_equal (&agf->agf_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (XFS_BUF_TO_AGF (bp)->agf_lsn))) -return false; +return __this_address; } if (!(agf->agf_magicnum == cpu_to_be32(XFS_AGF_MAGIC) &&
@@ -2409,18 +2410,18 @@ xfs_agf_verify(be32_to_cpu (agf->agf_flfirst) <XFS_AGFL_SIZE (mp) &&be32_to_cpu (agf->agf_fllast) <XFS_AGFL_SIZE (mp) && be32_to_cpu(agf->agf_flcount) <= XFS_AGFL_SIZE(mp))) - return false; + return __this_address;if (be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]) <1 ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]) <1 ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]) >XFS_BTREE_MAXLEVELS ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]) >XFS_BTREE_MAXLEVELS ) -return false; +return __this_address;if (xfs_sb_version_hasrmapbt (&mp->m_sb) && (be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]) <1 ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]) >XFS_BTREE_MAXLEVELS )) -return false; +return __this_address;/* * during growfs operations, the perag is not fully initialised,
@@ -2429,18 +2430,18 @@ xfs_agf_verify(* so we can detect and avoid this problem. */ if (bp->b_pag &&be32_to_cpu (agf->agf_seqno) != bp->b_pag->pag_agno) -return false; +return __this_address;if (xfs_sb_version_haslazysbcount (&mp->m_sb) &&be32_to_cpu (agf->agf_btreeblks) >be32_to_cpu (agf->agf_length)) -return false; +return __this_address;if (xfs_sb_version_hasreflink (&mp->m_sb) && (be32_to_cpu (agf->agf_refcount_level) <1 ||be32_to_cpu (agf->agf_refcount_level) >XFS_BTREE_MAXLEVELS )) -return false; +return __this_address; -return true;; +return NULL ; }
@@ -2453,7 +2454,7 @@ xfs_agf_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_AGF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (XFS_TEST_ERROR (!xfs_agf_verify (mp, bp), mp, +else if (XFS_TEST_ERROR (xfs_agf_verify (mp, bp), mp,XFS_ERRTAG_ALLOC_READ_AGF ))xfs_buf_ioerror (bp, -EFSCORRUPTED );
@@ -2468,7 +2469,7 @@ xfs_agf_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; -if (!xfs_agf_verify (mp, bp)) { +if (xfs_agf_verify (mp, bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_alloc_btree.c +13 -12
@@ -307,13 +307,14 @@ xfs_cntbt_diff_two_keys(be32_to_cpu (k2->alloc.ar_startblock); } -static bool +static void *xfs_allocbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_perag *pag = bp->b_pag; +void *failed_at;unsigned int level;/*
@@ -331,29 +332,29 @@ xfs_allocbt_verify( level =be16_to_cpu (block->bb_level);switch (block->bb_magic) {case cpu_to_be32 (XFS_ABTB_CRC_MAGIC ): -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_ABTB_MAGIC ):if (pag && pag->pagf_init) {if (level >= pag->pagf_levels[XFS_BTNUM_BNOi]) -return false; +return __this_address; }else if (level >= mp->m_ag_maxlevels) -return false; +return __this_address;break ;case cpu_to_be32 (XFS_ABTC_CRC_MAGIC ): -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_ABTC_MAGIC ):if (pag && pag->pagf_init) {if (level >= pag->pagf_levels[XFS_BTNUM_CNTi]) -return false; +return __this_address; }else if (level >= mp->m_ag_maxlevels) -return false; +return __this_address;break ;default : -return false; +return __this_address; }return xfs_btree_sblock_verify (bp, mp->m_alloc_mxr[level !=0 ]);
@@ -365,7 +366,7 @@ xfs_allocbt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_allocbt_verify (bp)) +else if (xfs_allocbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -378,7 +379,7 @@ static voidxfs_allocbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_allocbt_verify (bp)) { +if (xfs_allocbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_attr_leaf.c +10 -10
@@ -247,7 +247,7 @@ xfs_attr3_leaf_hdr_to_disk( } } -static bool +static void *xfs_attr3_leaf_verify (struct xfs_buf *bp) {
@@ -262,17 +262,17 @@ xfs_attr3_leaf_verify(struct xfs_da3_node_hdr *hdr3 = bp->b_addr;if (ichdr.magic !=XFS_ATTR3_LEAF_MAGIC ) -return false; +return __this_address;if (!uuid_equal (&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->info.blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->info.lsn))) -return false; +return __this_address; }else {if (ichdr.magic !=XFS_ATTR_LEAF_MAGIC ) -return false; +return __this_address; }/* * In recovery there is a transient state where count == 0 is valid
@@ -280,12 +280,12 @@ xfs_attr3_leaf_verify(* if the attr didn't fit in shortform. */ if (pag && pag->pagf_init && ichdr.count ==0 ) -return false; +return __this_address;/* XXX: need to range check rest of attr header values */ /* XXX: hash order check? */ -return true; +return NULL ; } static void
@@ -296,7 +296,7 @@ xfs_attr3_leaf_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_attr3_leaf_hdr *hdr3 = bp->b_addr; -if (!xfs_attr3_leaf_verify (bp)) { +if (xfs_attr3_leaf_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -326,7 +326,7 @@ xfs_attr3_leaf_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_ATTR3_LEAF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_attr3_leaf_verify (bp)) +else if (xfs_attr3_leaf_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
fs/xfs/libxfs/xfs_attr_remote.c +18 -18
@@ -65,7 +65,7 @@ xfs_attr3_rmt_blocks(* does CRC, location and bounds checking, the unpacking function checks the * attribute parameters and owner. */ -static bool +static void * xfs_attr3_rmt_hdr_ok( void *ptr, xfs_ino_t ino,
@@ -76,19 +76,19 @@ xfs_attr3_rmt_hdr_ok(struct xfs_attr3_rmt_hdr *rmt = ptr;if (bno !=be64_to_cpu (rmt->rm_blkno)) -return false; +return __this_address;if (offset !=be32_to_cpu (rmt->rm_offset)) -return false; +return __this_address;if (size !=be32_to_cpu (rmt->rm_bytes)) -return false; +return __this_address;if (ino !=be64_to_cpu (rmt->rm_owner)) -return false; +return __this_address;/* ok */ -return true; +return NULL ; } -static bool +static void * xfs_attr3_rmt_verify( struct xfs_mount *mp, void *ptr,
@@ -98,22 +98,22 @@ xfs_attr3_rmt_verify(struct xfs_attr3_rmt_hdr *rmt = ptr;if (!xfs_sb_version_hascrc (&mp->m_sb)) -return false; +return __this_address;if (rmt->rm_magic !=cpu_to_be32 (XFS_ATTR3_RMT_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&rmt->rm_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (rmt->rm_blkno) != bno) -return false; +return __this_address;if (be32_to_cpu (rmt->rm_bytes) > fsbsize -sizeof (*rmt)) -return false; +return __this_address;if (be32_to_cpu (rmt->rm_offset) +be32_to_cpu (rmt->rm_bytes) >XFS_XATTR_SIZE_MAX ) -return false; +return __this_address;if (rmt->rm_owner ==0 ) -return false; +return __this_address; -return true; +return NULL ; } static void
@@ -140,7 +140,7 @@ xfs_attr3_rmt_read_verify(xfs_buf_ioerror (bp, -EFSBADCRC );break ; } -if (!xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) { +if (xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );break ; }
@@ -177,7 +177,7 @@ xfs_attr3_rmt_write_verify(while (len >0 ) {struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr; -if (!xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) { +if (xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -269,7 +269,7 @@ xfs_attr_rmtval_copyout( byte_cnt =min (*valuelen, byte_cnt);if (xfs_sb_version_hascrc (&mp->m_sb)) { -if (!xfs_attr3_rmt_hdr_ok (src, ino, *offset, +if (xfs_attr3_rmt_hdr_ok (src, ino, *offset, byte_cnt, bno)) { xfs_alert(mp, "remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)",
fs/xfs/libxfs/xfs_bmap_btree.c +9 -7
@@ -617,12 +617,13 @@ xfs_bmbt_diff_two_keys(be64_to_cpu (k2->bmbt.br_startoff); } -static bool +static void *xfs_bmbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); +void *failed_at;unsigned int level;switch (block->bb_magic) {
@@ -631,13 +632,14 @@ xfs_bmbt_verify(* XXX: need a better way of verifying the owner here. Right now * just make sure there has been one set. */ -if (!xfs_btree_lblock_v5hdr_verify (bp,XFS_RMAP_OWN_UNKNOWN )) -return false; +if ((failed_at =xfs_btree_lblock_v5hdr_verify (bp, +XFS_RMAP_OWN_UNKNOWN ))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_BMAP_MAGIC ):break ;default : -return false; +return __this_address; }/*
@@ -649,7 +651,7 @@ xfs_bmbt_verify(*/ level =be16_to_cpu (block->bb_level);if (level >max (mp->m_bm_maxlevels[0 ], mp->m_bm_maxlevels[1 ])) -return false; +return __this_address;return xfs_btree_lblock_verify (bp, mp->m_bmap_dmxr[level !=0 ]); }
@@ -660,7 +662,7 @@ xfs_bmbt_read_verify( {if (!xfs_btree_lblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_bmbt_verify (bp)) +else if (xfs_bmbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -673,7 +675,7 @@ static voidxfs_bmbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_bmbt_verify (bp)) { +if (xfs_bmbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_btree.c +23 -23
122 lines not on this page · raw message
fs/xfs/libxfs/xfs_btree.h +4 -4
@@ -478,10 +478,10 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block)#define XFS_BTREE_TRACE_ARGR (c, r)#define XFS_BTREE_TRACE_CURSOR (c, t) -bool xfs_btree_sblock_v5hdr_verify (struct xfs_buf *bp); -bool xfs_btree_sblock_verify (struct xfs_buf *bp,unsigned int max_recs); -bool xfs_btree_lblock_v5hdr_verify (struct xfs_buf *bp,uint64_t owner); -bool xfs_btree_lblock_verify (struct xfs_buf *bp,unsigned int max_recs); +void *xfs_btree_sblock_v5hdr_verify (struct xfs_buf *bp); +void *xfs_btree_sblock_verify (struct xfs_buf *bp,unsigned int max_recs); +void *xfs_btree_lblock_v5hdr_verify (struct xfs_buf *bp,uint64_t owner); +void *xfs_btree_lblock_verify (struct xfs_buf *bp,unsigned int max_recs);uint xfs_btree_compute_maxlevels (struct xfs_mount *mp,uint *limits,unsigned long len);
fs/xfs/libxfs/xfs_da_btree.c +13 -13
@@ -128,7 +128,7 @@ xfs_da_state_free(xfs_da_state_t *state)kmem_zone_free (xfs_da_state_zone, state); } -static bool +static void *xfs_da3_node_verify (struct xfs_buf *bp) {
@@ -145,24 +145,24 @@ xfs_da3_node_verify(struct xfs_da3_node_hdr *hdr3 = bp->b_addr;if (ichdr.magic !=XFS_DA3_NODE_MAGIC ) -return false; +return __this_address;if (!uuid_equal (&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->info.blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->info.lsn))) -return false; +return __this_address; }else {if (ichdr.magic !=XFS_DA_NODE_MAGIC ) -return false; +return __this_address; }if (ichdr.level ==0 ) -return false; +return __this_address;if (ichdr.level >XFS_DA_NODE_MAXDEPTH ) -return false; +return __this_address;if (ichdr.count ==0 ) -return false; +return __this_address;/* * we don't know if the node is for and attribute or directory tree,
@@ -170,11 +170,11 @@ xfs_da3_node_verify(*/ if (ichdr.count > mp->m_dir_geo->node_ents && ichdr.count > mp->m_attr_geo->node_ents) -return false; +return __this_address;/* XXX: hash order check? */ -return true; +return NULL ; } static void
@@ -185,7 +185,7 @@ xfs_da3_node_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_da3_node_hdr *hdr3 = bp->b_addr; -if (!xfs_da3_node_verify (bp)) { +if (xfs_da3_node_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -220,7 +220,7 @@ xfs_da3_node_read_verify( }/* fall through */ case XFS_DA_NODE_MAGIC : -if (!xfs_da3_node_verify (bp)) { +if (xfs_da3_node_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );break ; }
fs/xfs/libxfs/xfs_dir2_block.c +8 -8
@@ -58,7 +58,7 @@ xfs_dir_startup(void) xfs_dir_hash_dotdot =xfs_da_hashname ((unsigned char *)".." ,2 ); } -static bool +static void *xfs_dir3_block_verify (struct xfs_buf *bp) {
@@ -67,16 +67,16 @@ xfs_dir3_block_verify(if (xfs_sb_version_hascrc (&mp->m_sb)) {if (hdr3->magic !=cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->lsn))) -return false; +return __this_address; }else {if (hdr3->magic !=cpu_to_be32 (XFS_DIR2_BLOCK_MAGIC )) -return false; +return __this_address; }return __xfs_dir3_data_check (NULL , bp); }
@@ -90,7 +90,7 @@ xfs_dir3_block_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_DATA_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dir3_block_verify (bp)) +else if (xfs_dir3_block_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -105,7 +105,7 @@ xfs_dir3_block_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; -if (!xfs_dir3_block_verify (bp)) { +if (xfs_dir3_block_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_dir2_data.c +33 -33
179 lines not on this page · raw message
fs/xfs/libxfs/xfs_dir2_leaf.c +15 -15
@@ -73,13 +73,13 @@ xfs_dir3_leaf1_check( } else if (leafhdr.magic != XFS_DIR2_LEAF1_MAGIC)return false; -return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf); +return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf) ==NULL ; }#else #define xfs_dir3_leaf_check (dp, bp)#endif -bool +void * xfs_dir3_leaf_check_int( struct xfs_mount *mp, struct xfs_inode *dp,
@@ -114,27 +114,27 @@ xfs_dir3_leaf_check_int(* We can deduce a value for that from di_size. */ if (hdr->count > ops->leaf_max_ents (geo)) -return false; +return __this_address;/* Leaves and bests don't overlap in leaf format. */ if ((hdr->magic ==XFS_DIR2_LEAF1_MAGIC || hdr->magic ==XFS_DIR3_LEAF1_MAGIC ) && (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) -return false; +return __this_address;/* Check hash value order, count stale entries. */ for (i = stale =0 ; i < hdr->count; i++) {if (i +1 < hdr->count) {if (be32_to_cpu (ents[i].hashval) >be32_to_cpu (ents[i +1 ].hashval)) -return false; +return __this_address; }if (ents[i].address ==cpu_to_be32 (XFS_DIR2_NULL_DATAPTR )) stale++; }if (hdr->stale != stale) -return false; -return true; +return __this_address; +return NULL ; }/*
@@ -142,7 +142,7 @@ xfs_dir3_leaf_check_int(* kernels we don't get assertion failures in xfs_dir3_leaf_hdr_from_disk() due * to incorrect magic numbers. */ -static bool +static void *xfs_dir3_leaf_verify (struct xfs_buf *bp,uint16_t magic)
@@ -160,16 +160,16 @@ xfs_dir3_leaf_verify( : XFS_DIR3_LEAFN_MAGIC;if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) -return false; +return __this_address;if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (leaf3->info.lsn))) -return false; +return __this_address; }else {if (leaf->hdr.info.magic !=cpu_to_be16 (magic)) -return false; +return __this_address; }return xfs_dir3_leaf_check_int (mp,NULL ,NULL , leaf);
@@ -185,7 +185,7 @@ __read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_LEAF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dir3_leaf_verify (bp, magic)) +else if (xfs_dir3_leaf_verify (bp, magic))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -201,7 +201,7 @@ __write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_leaf_hdr *hdr3 = bp->b_addr; -if (!xfs_dir3_leaf_verify (bp, magic)) { +if (xfs_dir3_leaf_verify (bp, magic)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_dir2_node.c +18 -18
@@ -76,13 +76,13 @@ xfs_dir3_leafn_check( } else if (leafhdr.magic != XFS_DIR2_LEAFN_MAGIC)return false; -return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf); +return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf) ==NULL ; }#else #define xfs_dir3_leaf_check (dp, bp)#endif -static bool +static void *xfs_dir3_free_verify (struct xfs_buf *bp) {
@@ -93,21 +93,21 @@ xfs_dir3_free_verify(struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;if (hdr3->magic !=cpu_to_be32 (XFS_DIR3_FREE_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->lsn))) -return false; +return __this_address; }else {if (hdr->magic !=cpu_to_be32 (XFS_DIR2_FREE_MAGIC )) -return false; +return __this_address; }/* XXX: should bounds check the xfs_dir3_icfree_hdr here */ -return true; +return NULL ; } static void
@@ -119,7 +119,7 @@ xfs_dir3_free_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_FREE_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dir3_free_verify (bp)) +else if (xfs_dir3_free_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -134,7 +134,7 @@ xfs_dir3_free_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; -if (!xfs_dir3_free_verify (bp)) { +if (xfs_dir3_free_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -174,22 +174,22 @@ xfs_dir3_free_header_check(struct xfs_dir3_free_hdr *hdr3 = bp->b_addr;if (be32_to_cpu (hdr3->firstdb) != firstdb) -return false; +return __this_address;if (be32_to_cpu (hdr3->nvalid) > maxbests) -return false; +return __this_address;if (be32_to_cpu (hdr3->nvalid) <be32_to_cpu (hdr3->nused)) -return false; +return __this_address; }else {struct xfs_dir2_free_hdr *hdr = bp->b_addr;if (be32_to_cpu (hdr->firstdb) != firstdb) -return false; +return __this_address;if (be32_to_cpu (hdr->nvalid) > maxbests) -return false; +return __this_address;if (be32_to_cpu (hdr->nvalid) <be32_to_cpu (hdr->nused)) -return false; +return __this_address; } -return true; +return NULL ; } static int
@@ -208,7 +208,7 @@ __xfs_dir3_free_read(return err;/* Check things that we can't do in the verifier. */ -if (!xfs_dir3_free_header_check (dp, fbno, *bpp)) { +if (xfs_dir3_free_header_check (dp, fbno, *bpp)) {xfs_buf_ioerror (*bpp, -EFSCORRUPTED );xfs_verifier_error (*bpp);xfs_trans_brelse (tp, *bpp);
fs/xfs/libxfs/xfs_dir2_priv.h +3 -3
@@ -41,7 +41,7 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,#ifdef DEBUG #define xfs_dir3_data_check (dp, bp) \ do { \ - if (!__xfs_dir3_data_check((dp), (bp))) { \ + if (__xfs_dir3_data_check((dp), (bp))) { \ XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, \ (bp)->b_target->bt_mount, (bp)->b_addr); \ } \
@@ -50,7 +50,7 @@ do { \#define xfs_dir3_data_check (dp,bp)#endif -extern bool __xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp); +extern void *__xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp);extern int xfs_dir3_data_read (struct xfs_trans *tp,struct xfs_inode *dp,xfs_dablk_t bno,xfs_daddr_t mapped_bno,struct xfs_buf **bpp); extern int xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno,
@@ -95,7 +95,7 @@ xfs_dir3_leaf_find_entry(struct xfs_dir3_icleaf_hdr *leafhdr, int lowstale, int highstale, int *lfloglow, int *lfloghigh);extern int xfs_dir2_node_to_leaf (struct xfs_da_state *state); -extern bool xfs_dir3_leaf_check_int (struct xfs_mount *mp,struct xfs_inode *dp, +extern void *xfs_dir3_leaf_check_int (struct xfs_mount *mp,struct xfs_inode *dp,struct xfs_dir3_icleaf_hdr *hdr,struct xfs_dir2_leaf *leaf);/* xfs_dir2_node.c */
fs/xfs/libxfs/xfs_ialloc.c +11 -11
@@ -2497,7 +2497,7 @@ xfs_check_agi_unlinked(#define xfs_check_agi_unlinked (agi)#endif -static bool +static void *xfs_agi_verify (struct xfs_buf *bp) {
@@ -2506,28 +2506,28 @@ xfs_agi_verify(if (xfs_sb_version_hascrc (&mp->m_sb)) {if (!uuid_equal (&agi->agi_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (XFS_BUF_TO_AGI (bp)->agi_lsn))) -return false; +return __this_address; }/* * Validate the magic number of the agi block. */ if (agi->agi_magicnum !=cpu_to_be32 (XFS_AGI_MAGIC )) -return false; +return __this_address;if (!XFS_AGI_GOOD_VERSION (be32_to_cpu (agi->agi_versionnum))) -return false; +return __this_address;if (be32_to_cpu (agi->agi_level) <1 ||be32_to_cpu (agi->agi_level) >XFS_BTREE_MAXLEVELS ) -return false; +return __this_address;if (xfs_sb_version_hasfinobt (&mp->m_sb) && (be32_to_cpu (agi->agi_free_level) <1 ||be32_to_cpu (agi->agi_free_level) >XFS_BTREE_MAXLEVELS )) -return false; +return __this_address;/* * during growfs operations, the perag is not fully initialised,
@@ -2536,10 +2536,10 @@ xfs_agi_verify(* so we can detect and avoid this problem. */ if (bp->b_pag &&be32_to_cpu (agi->agi_seqno) != bp->b_pag->pag_agno) -return false; +return __this_address;xfs_check_agi_unlinked (agi); -return true; +return NULL ; } static void
@@ -2551,7 +2551,7 @@ xfs_agi_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_AGI_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (XFS_TEST_ERROR (!xfs_agi_verify (bp), mp, +else if (XFS_TEST_ERROR (xfs_agi_verify (bp), mp,XFS_ERRTAG_IALLOC_READ_AGI ))xfs_buf_ioerror (bp, -EFSCORRUPTED );
@@ -2566,7 +2566,7 @@ xfs_agi_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; -if (!xfs_agi_verify (bp)) { +if (xfs_agi_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_ialloc_btree.c +8 -7
@@ -250,12 +250,13 @@ xfs_inobt_diff_two_keys(be32_to_cpu (k2->inobt.ir_startino); } -static int +static void *xfs_inobt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); +void *failed_at;unsigned int level;/*
@@ -271,20 +272,20 @@ xfs_inobt_verify(switch (block->bb_magic) {case cpu_to_be32 (XFS_IBT_CRC_MAGIC ):case cpu_to_be32 (XFS_FIBT_CRC_MAGIC ): -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_IBT_MAGIC ):case cpu_to_be32 (XFS_FIBT_MAGIC ):break ;default : -return 0 ; +return NULL ; }/* level verification */ level =be16_to_cpu (block->bb_level);if (level >= mp->m_in_maxlevels) -return false; +return __this_address;return xfs_btree_sblock_verify (bp, mp->m_inobt_mxr[level !=0 ]); }
@@ -295,7 +296,7 @@ xfs_inobt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_inobt_verify (bp)) +else if (xfs_inobt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -308,7 +309,7 @@ static voidxfs_inobt_write_verify ( struct xfs_buf *bp) { -if (!xfs_inobt_verify (bp)) { +if (xfs_inobt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_inode_buf.c +15 -15
@@ -380,7 +380,7 @@ xfs_log_dinode_to_disk( } } -bool +void * xfs_dinode_verify( struct xfs_mount *mp, xfs_ino_t ino,
@@ -391,33 +391,33 @@ xfs_dinode_verify(uint64_t flags2;if (dip->di_magic !=cpu_to_be16 (XFS_DINODE_MAGIC )) -return false; +return __this_address;/* don't allow invalid i_size */ if (be64_to_cpu (dip->di_size) & (1ULL <<63 )) -return false; +return __this_address; mode =be16_to_cpu (dip->di_mode);if (mode &&xfs_mode_to_ftype (mode) ==XFS_DIR3_FT_UNKNOWN ) -return false; +return __this_address;/* No zero-length symlinks/dirs. */ if ((S_ISLNK (mode) ||S_ISDIR (mode)) && dip->di_size ==0 ) -return false; +return __this_address;/* only version 3 or greater inodes are extensively verified here */ if (dip->di_version <3 ) -return true; +return NULL ;if (!xfs_sb_version_hascrc (&mp->m_sb)) -return false; +return __this_address;if (!xfs_verify_cksum ((char *)dip, mp->m_sb.sb_inodesize,XFS_DINODE_CRC_OFF )) -return false; +return __this_address;if (be64_to_cpu (dip->di_ino) != ino) -return false; +return __this_address;if (!uuid_equal (&dip->di_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address; flags =be16_to_cpu (dip->di_flags); flags2 =be64_to_cpu (dip->di_flags2);
@@ -425,17 +425,17 @@ xfs_dinode_verify(/* don't allow reflink/cowextsize if we don't have reflink */ if ((flags2 & (XFS_DIFLAG2_REFLINK |XFS_DIFLAG2_COWEXTSIZE )) && !xfs_sb_version_hasreflink (&mp->m_sb)) -return false; +return __this_address;/* don't let reflink and realtime mix */ if ((flags2 &XFS_DIFLAG2_REFLINK ) && (flags &XFS_DIFLAG_REALTIME )) -return false; +return __this_address;/* don't let reflink and dax mix */ if ((flags2 &XFS_DIFLAG2_REFLINK ) && (flags2 &XFS_DIFLAG2_DAX )) -return false; +return __this_address; -return true; +return NULL ; }void
@@ -506,7 +506,7 @@ xfs_iread(return error;/* even unallocated inodes are verified */ -if (!xfs_dinode_verify (mp, ip->i_ino, dip)) { +if (xfs_dinode_verify (mp, ip->i_ino, dip)) {xfs_alert (mp,"%s: validation failed for inode %lld" , __func__, ip->i_ino);
fs/xfs/libxfs/xfs_inode_buf.h +2 -2
@@ -82,7 +82,7 @@ void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);#define xfs_inobp_check (mp, bp)#endif /* DEBUG */ -bool xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino, -struct xfs_dinode *dip); +void *xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino, +struct xfs_dinode *dip);#endif /* __XFS_INODE_BUF_H__ */
fs/xfs/libxfs/xfs_refcount_btree.c +10 -9
@@ -223,29 +223,30 @@ xfs_refcountbt_diff_two_keys(be32_to_cpu (k2->refc.rc_startblock); } -STATIC bool +STATIC void *xfs_refcountbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_perag *pag = bp->b_pag; +void *failed_at;unsigned int level;if (block->bb_magic !=cpu_to_be32 (XFS_REFC_CRC_MAGIC )) -return false; +return __this_address;if (!xfs_sb_version_hasreflink (&mp->m_sb)) -return false; -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +return __this_address; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at; level =be16_to_cpu (block->bb_level);if (pag && pag->pagf_init) {if (level >= pag->pagf_refcount_level) -return false; +return __this_address; }else if (level >= mp->m_refc_maxlevels) -return false; +return __this_address;return xfs_btree_sblock_verify (bp, mp->m_refc_mxr[level !=0 ]); }
@@ -256,7 +257,7 @@ xfs_refcountbt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_refcountbt_verify (bp)) +else if (xfs_refcountbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -269,7 +270,7 @@ STATIC voidxfs_refcountbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_refcountbt_verify (bp)) { +if (xfs_refcountbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_rmap_btree.c +10 -9
@@ -303,13 +303,14 @@ xfs_rmapbt_diff_two_keys(return 0 ; } -static bool +static void *xfs_rmapbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_perag *pag = bp->b_pag; +void *failed_at;unsigned int level;/*
@@ -325,19 +326,19 @@ xfs_rmapbt_verify(* in this case. */ if (block->bb_magic !=cpu_to_be32 (XFS_RMAP_CRC_MAGIC )) -return false; +return __this_address;if (!xfs_sb_version_hasrmapbt (&mp->m_sb)) -return false; -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +return __this_address; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at; level =be16_to_cpu (block->bb_level);if (pag && pag->pagf_init) {if (level >= pag->pagf_levels[XFS_BTNUM_RMAPi]) -return false; +return __this_address; }else if (level >= mp->m_rmap_maxlevels) -return false; +return __this_address;return xfs_btree_sblock_verify (bp, mp->m_rmap_mxr[level !=0 ]); }
@@ -348,7 +349,7 @@ xfs_rmapbt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_rmapbt_verify (bp)) +else if (xfs_rmapbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -361,7 +362,7 @@ static voidxfs_rmapbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_rmapbt_verify (bp)) { +if (xfs_rmapbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_symlink_remote.c +11 -11
@@ -98,7 +98,7 @@ xfs_symlink_hdr_ok(return true; } -static bool +static void *xfs_symlink_verify (struct xfs_buf *bp) {
@@ -106,22 +106,22 @@ xfs_symlink_verify(struct xfs_dsymlink_hdr *dsl = bp->b_addr;if (!xfs_sb_version_hascrc (&mp->m_sb)) -return false; +return __this_address;if (dsl->sl_magic !=cpu_to_be32 (XFS_SYMLINK_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&dsl->sl_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (bp->b_bn !=be64_to_cpu (dsl->sl_blkno)) -return false; +return __this_address;if (be32_to_cpu (dsl->sl_offset) +be32_to_cpu (dsl->sl_bytes) >=XFS_SYMLINK_MAXLEN ) -return false; +return __this_address;if (dsl->sl_owner ==0 ) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (dsl->sl_lsn))) -return false; +return __this_address; -return true; +return NULL ; } static void
@@ -136,7 +136,7 @@ xfs_symlink_read_verify(if (!xfs_buf_verify_cksum (bp,XFS_SYMLINK_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_symlink_verify (bp)) +else if (xfs_symlink_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -154,7 +154,7 @@ xfs_symlink_write_verify(if (!xfs_sb_version_hascrc (&mp->m_sb))return ; -if (!xfs_symlink_verify (bp)) { +if (xfs_symlink_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/xfs_linux.h +1 -0
@@ -141,6 +141,7 @@ typedef __u32 xfs_nlink_t;#define SYNCHRONIZE () barrier()#define __return_address __builtin_return_address(0) +#define __this_address ({ __label__ __here; __here: &&__here; })#define XFS_PROJID_DEFAULT 0
PATCH v2 3/12 xfs: have buffer verifier functions report failing address
From: Darrick J. Wong <[email protected]>
Modify each function that checks the contents of a metadata buffer to return the instruction address of the failing test so that we can report more precise failure errors to the log.
--- fs/xfs/libxfs/xfs_alloc.c | 43 ++++++++++++----------- fs/xfs/libxfs/xfs_alloc_btree.c | 25 +++++++------- fs/xfs/libxfs/xfs_attr_leaf.c | 20 +++++------ fs/xfs/libxfs/xfs_attr_remote.c | 36 ++++++++++---------- fs/xfs/libxfs/xfs_bmap_btree.c | 16 +++++---- fs/xfs/libxfs/xfs_btree.c | 46 +++++++++++++------------ fs/xfs/libxfs/xfs_btree.h | 8 ++-- fs/xfs/libxfs/xfs_da_btree.c | 26 +++++++------- fs/xfs/libxfs/xfs_dir2_block.c | 16 ++++----- fs/xfs/libxfs/xfs_dir2_data.c | 66 ++++++++++++++++++------------------ fs/xfs/libxfs/xfs_dir2_leaf.c | 30 ++++++++-------- fs/xfs/libxfs/xfs_dir2_node.c | 36 ++++++++++---------- fs/xfs/libxfs/xfs_dir2_priv.h | 6 ++- fs/xfs/libxfs/xfs_ialloc.c | 22 ++++++------ fs/xfs/libxfs/xfs_ialloc_btree.c | 15 ++++---- fs/xfs/libxfs/xfs_inode_buf.c | 30 ++++++++-------- fs/xfs/libxfs/xfs_inode_buf.h | 4 +- fs/xfs/libxfs/xfs_refcount_btree.c | 19 +++++----- fs/xfs/libxfs/xfs_rmap_btree.c | 19 +++++----- fs/xfs/libxfs/xfs_symlink_remote.c | 22 ++++++------ fs/xfs/xfs_linux.h | 7 ++++ 21 files changed, 263 insertions(+), 249 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +22 -21
@@ -519,7 +519,7 @@ xfs_alloc_fixup_trees(return 0 ; } -static bool +static void *xfs_agfl_verify (struct xfs_buf *bp) {
@@ -528,9 +528,9 @@ xfs_agfl_verify(int i;if (!uuid_equal (&agfl->agfl_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be32_to_cpu (agfl->agfl_magicnum) !=XFS_AGFL_MAGIC ) -return false; +return __this_address;/* * during growfs operations, the perag is not fully initialised, * so we can't use it for any useful checking. growfs ensures we can't
@@ -538,16 +538,17 @@ xfs_agfl_verify(* so we can detect and avoid this problem. */ if (bp->b_pag &&be32_to_cpu (agfl->agfl_seqno) != bp->b_pag->pag_agno) -return false; +return __this_address;for (i =0 ; i <XFS_AGFL_SIZE (mp); i++) {if (be32_to_cpu (agfl->agfl_bno[i]) !=NULLAGBLOCK &&be32_to_cpu (agfl->agfl_bno[i]) >= mp->m_sb.sb_agblocks) -return false; +return __this_address; } -return xfs_log_check_lsn (mp, -be64_to_cpu (XFS_BUF_TO_AGFL (bp)->agfl_lsn)); +if (!xfs_log_check_lsn (mp,be64_to_cpu (XFS_BUF_TO_AGFL (bp)->agfl_lsn))) +return __this_address; +return NULL ; } static void
@@ -567,7 +568,7 @@ xfs_agfl_read_verify(if (!xfs_buf_verify_cksum (bp,XFS_AGFL_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_agfl_verify (bp)) +else if (xfs_agfl_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -585,7 +586,7 @@ xfs_agfl_write_verify(if (!xfs_sb_version_hascrc (&mp->m_sb))return ; -if (!xfs_agfl_verify (bp)) { +if (xfs_agfl_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -2388,7 +2389,7 @@ xfs_alloc_put_freelist(return 0 ; } -static bool +static void *xfs_agf_verify (struct xfs_mount *mp,struct xfs_buf *bp)
@@ -2397,10 +2398,10 @@ xfs_agf_verify(if (xfs_sb_version_hascrc (&mp->m_sb)) {if (!uuid_equal (&agf->agf_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (XFS_BUF_TO_AGF (bp)->agf_lsn))) -return false; +return __this_address; } if (!(agf->agf_magicnum == cpu_to_be32(XFS_AGF_MAGIC) &&
@@ -2409,18 +2410,18 @@ xfs_agf_verify(be32_to_cpu (agf->agf_flfirst) <XFS_AGFL_SIZE (mp) &&be32_to_cpu (agf->agf_fllast) <XFS_AGFL_SIZE (mp) && be32_to_cpu(agf->agf_flcount) <= XFS_AGFL_SIZE(mp))) - return false; + return __this_address;if (be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]) <1 ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]) <1 ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_BNO ]) >XFS_BTREE_MAXLEVELS ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_CNT ]) >XFS_BTREE_MAXLEVELS ) -return false; +return __this_address;if (xfs_sb_version_hasrmapbt (&mp->m_sb) && (be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]) <1 ||be32_to_cpu (agf->agf_levels[XFS_BTNUM_RMAP ]) >XFS_BTREE_MAXLEVELS )) -return false; +return __this_address;/* * during growfs operations, the perag is not fully initialised,
@@ -2429,18 +2430,18 @@ xfs_agf_verify(* so we can detect and avoid this problem. */ if (bp->b_pag &&be32_to_cpu (agf->agf_seqno) != bp->b_pag->pag_agno) -return false; +return __this_address;if (xfs_sb_version_haslazysbcount (&mp->m_sb) &&be32_to_cpu (agf->agf_btreeblks) >be32_to_cpu (agf->agf_length)) -return false; +return __this_address;if (xfs_sb_version_hasreflink (&mp->m_sb) && (be32_to_cpu (agf->agf_refcount_level) <1 ||be32_to_cpu (agf->agf_refcount_level) >XFS_BTREE_MAXLEVELS )) -return false; +return __this_address; -return true;; +return NULL ; }
@@ -2453,7 +2454,7 @@ xfs_agf_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_AGF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (XFS_TEST_ERROR (!xfs_agf_verify (mp, bp), mp, +else if (XFS_TEST_ERROR (xfs_agf_verify (mp, bp), mp,XFS_ERRTAG_ALLOC_READ_AGF ))xfs_buf_ioerror (bp, -EFSCORRUPTED );
@@ -2468,7 +2469,7 @@ xfs_agf_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; -if (!xfs_agf_verify (mp, bp)) { +if (xfs_agf_verify (mp, bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_alloc_btree.c +13 -12
@@ -307,13 +307,14 @@ xfs_cntbt_diff_two_keys(be32_to_cpu (k2->alloc.ar_startblock); } -static bool +static void *xfs_allocbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_perag *pag = bp->b_pag; +void *failed_at;unsigned int level;/*
@@ -331,29 +332,29 @@ xfs_allocbt_verify( level =be16_to_cpu (block->bb_level);switch (block->bb_magic) {case cpu_to_be32 (XFS_ABTB_CRC_MAGIC ): -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_ABTB_MAGIC ):if (pag && pag->pagf_init) {if (level >= pag->pagf_levels[XFS_BTNUM_BNOi]) -return false; +return __this_address; }else if (level >= mp->m_ag_maxlevels) -return false; +return __this_address;break ;case cpu_to_be32 (XFS_ABTC_CRC_MAGIC ): -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_ABTC_MAGIC ):if (pag && pag->pagf_init) {if (level >= pag->pagf_levels[XFS_BTNUM_CNTi]) -return false; +return __this_address; }else if (level >= mp->m_ag_maxlevels) -return false; +return __this_address;break ;default : -return false; +return __this_address; }return xfs_btree_sblock_verify (bp, mp->m_alloc_mxr[level !=0 ]);
@@ -365,7 +366,7 @@ xfs_allocbt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_allocbt_verify (bp)) +else if (xfs_allocbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -378,7 +379,7 @@ static voidxfs_allocbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_allocbt_verify (bp)) { +if (xfs_allocbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_attr_leaf.c +10 -10
@@ -247,7 +247,7 @@ xfs_attr3_leaf_hdr_to_disk( } } -static bool +static void *xfs_attr3_leaf_verify (struct xfs_buf *bp) {
@@ -262,17 +262,17 @@ xfs_attr3_leaf_verify(struct xfs_da3_node_hdr *hdr3 = bp->b_addr;if (ichdr.magic !=XFS_ATTR3_LEAF_MAGIC ) -return false; +return __this_address;if (!uuid_equal (&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->info.blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->info.lsn))) -return false; +return __this_address; }else {if (ichdr.magic !=XFS_ATTR_LEAF_MAGIC ) -return false; +return __this_address; }/* * In recovery there is a transient state where count == 0 is valid
@@ -280,12 +280,12 @@ xfs_attr3_leaf_verify(* if the attr didn't fit in shortform. */ if (pag && pag->pagf_init && ichdr.count ==0 ) -return false; +return __this_address;/* XXX: need to range check rest of attr header values */ /* XXX: hash order check? */ -return true; +return NULL ; } static void
@@ -296,7 +296,7 @@ xfs_attr3_leaf_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_attr3_leaf_hdr *hdr3 = bp->b_addr; -if (!xfs_attr3_leaf_verify (bp)) { +if (xfs_attr3_leaf_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -326,7 +326,7 @@ xfs_attr3_leaf_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_ATTR3_LEAF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_attr3_leaf_verify (bp)) +else if (xfs_attr3_leaf_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
fs/xfs/libxfs/xfs_attr_remote.c +18 -18
@@ -65,7 +65,7 @@ xfs_attr3_rmt_blocks(* does CRC, location and bounds checking, the unpacking function checks the * attribute parameters and owner. */ -static bool +static void * xfs_attr3_rmt_hdr_ok( void *ptr, xfs_ino_t ino,
@@ -76,19 +76,19 @@ xfs_attr3_rmt_hdr_ok(struct xfs_attr3_rmt_hdr *rmt = ptr;if (bno !=be64_to_cpu (rmt->rm_blkno)) -return false; +return __this_address;if (offset !=be32_to_cpu (rmt->rm_offset)) -return false; +return __this_address;if (size !=be32_to_cpu (rmt->rm_bytes)) -return false; +return __this_address;if (ino !=be64_to_cpu (rmt->rm_owner)) -return false; +return __this_address;/* ok */ -return true; +return NULL ; } -static bool +static void * xfs_attr3_rmt_verify( struct xfs_mount *mp, void *ptr,
@@ -98,22 +98,22 @@ xfs_attr3_rmt_verify(struct xfs_attr3_rmt_hdr *rmt = ptr;if (!xfs_sb_version_hascrc (&mp->m_sb)) -return false; +return __this_address;if (rmt->rm_magic !=cpu_to_be32 (XFS_ATTR3_RMT_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&rmt->rm_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (rmt->rm_blkno) != bno) -return false; +return __this_address;if (be32_to_cpu (rmt->rm_bytes) > fsbsize -sizeof (*rmt)) -return false; +return __this_address;if (be32_to_cpu (rmt->rm_offset) +be32_to_cpu (rmt->rm_bytes) >XFS_XATTR_SIZE_MAX ) -return false; +return __this_address;if (rmt->rm_owner ==0 ) -return false; +return __this_address; -return true; +return NULL ; } static void
@@ -140,7 +140,7 @@ xfs_attr3_rmt_read_verify(xfs_buf_ioerror (bp, -EFSBADCRC );break ; } -if (!xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) { +if (xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );break ; }
@@ -177,7 +177,7 @@ xfs_attr3_rmt_write_verify(while (len >0 ) {struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr; -if (!xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) { +if (xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -269,7 +269,7 @@ xfs_attr_rmtval_copyout( byte_cnt =min (*valuelen, byte_cnt);if (xfs_sb_version_hascrc (&mp->m_sb)) { -if (!xfs_attr3_rmt_hdr_ok (src, ino, *offset, +if (xfs_attr3_rmt_hdr_ok (src, ino, *offset, byte_cnt, bno)) { xfs_alert(mp, "remote attribute header mismatch bno/off/len/owner (0x%llx/0x%x/Ox%x/0x%llx)",
fs/xfs/libxfs/xfs_bmap_btree.c +9 -7
@@ -617,12 +617,13 @@ xfs_bmbt_diff_two_keys(be64_to_cpu (k2->bmbt.br_startoff); } -static bool +static void *xfs_bmbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); +void *failed_at;unsigned int level;switch (block->bb_magic) {
@@ -631,13 +632,14 @@ xfs_bmbt_verify(* XXX: need a better way of verifying the owner here. Right now * just make sure there has been one set. */ -if (!xfs_btree_lblock_v5hdr_verify (bp,XFS_RMAP_OWN_UNKNOWN )) -return false; +if ((failed_at =xfs_btree_lblock_v5hdr_verify (bp, +XFS_RMAP_OWN_UNKNOWN ))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_BMAP_MAGIC ):break ;default : -return false; +return __this_address; }/*
@@ -649,7 +651,7 @@ xfs_bmbt_verify(*/ level =be16_to_cpu (block->bb_level);if (level >max (mp->m_bm_maxlevels[0 ], mp->m_bm_maxlevels[1 ])) -return false; +return __this_address;return xfs_btree_lblock_verify (bp, mp->m_bmap_dmxr[level !=0 ]); }
@@ -660,7 +662,7 @@ xfs_bmbt_read_verify( {if (!xfs_btree_lblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_bmbt_verify (bp)) +else if (xfs_bmbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -673,7 +675,7 @@ static voidxfs_bmbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_bmbt_verify (bp)) { +if (xfs_bmbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_btree.c +23 -23
122 lines not on this page · raw message
fs/xfs/libxfs/xfs_btree.h +4 -4
@@ -478,10 +478,10 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block)#define XFS_BTREE_TRACE_ARGR (c, r)#define XFS_BTREE_TRACE_CURSOR (c, t) -bool xfs_btree_sblock_v5hdr_verify (struct xfs_buf *bp); -bool xfs_btree_sblock_verify (struct xfs_buf *bp,unsigned int max_recs); -bool xfs_btree_lblock_v5hdr_verify (struct xfs_buf *bp,uint64_t owner); -bool xfs_btree_lblock_verify (struct xfs_buf *bp,unsigned int max_recs); +void *xfs_btree_sblock_v5hdr_verify (struct xfs_buf *bp); +void *xfs_btree_sblock_verify (struct xfs_buf *bp,unsigned int max_recs); +void *xfs_btree_lblock_v5hdr_verify (struct xfs_buf *bp,uint64_t owner); +void *xfs_btree_lblock_verify (struct xfs_buf *bp,unsigned int max_recs);uint xfs_btree_compute_maxlevels (struct xfs_mount *mp,uint *limits,unsigned long len);
fs/xfs/libxfs/xfs_da_btree.c +13 -13
@@ -128,7 +128,7 @@ xfs_da_state_free(xfs_da_state_t *state)kmem_zone_free (xfs_da_state_zone, state); } -static bool +static void *xfs_da3_node_verify (struct xfs_buf *bp) {
@@ -145,24 +145,24 @@ xfs_da3_node_verify(struct xfs_da3_node_hdr *hdr3 = bp->b_addr;if (ichdr.magic !=XFS_DA3_NODE_MAGIC ) -return false; +return __this_address;if (!uuid_equal (&hdr3->info.uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->info.blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->info.lsn))) -return false; +return __this_address; }else {if (ichdr.magic !=XFS_DA_NODE_MAGIC ) -return false; +return __this_address; }if (ichdr.level ==0 ) -return false; +return __this_address;if (ichdr.level >XFS_DA_NODE_MAXDEPTH ) -return false; +return __this_address;if (ichdr.count ==0 ) -return false; +return __this_address;/* * we don't know if the node is for and attribute or directory tree,
@@ -170,11 +170,11 @@ xfs_da3_node_verify(*/ if (ichdr.count > mp->m_dir_geo->node_ents && ichdr.count > mp->m_attr_geo->node_ents) -return false; +return __this_address;/* XXX: hash order check? */ -return true; +return NULL ; } static void
@@ -185,7 +185,7 @@ xfs_da3_node_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_da3_node_hdr *hdr3 = bp->b_addr; -if (!xfs_da3_node_verify (bp)) { +if (xfs_da3_node_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -220,7 +220,7 @@ xfs_da3_node_read_verify( }/* fall through */ case XFS_DA_NODE_MAGIC : -if (!xfs_da3_node_verify (bp)) { +if (xfs_da3_node_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );break ; }
fs/xfs/libxfs/xfs_dir2_block.c +8 -8
@@ -58,7 +58,7 @@ xfs_dir_startup(void) xfs_dir_hash_dotdot =xfs_da_hashname ((unsigned char *)".." ,2 ); } -static bool +static void *xfs_dir3_block_verify (struct xfs_buf *bp) {
@@ -67,16 +67,16 @@ xfs_dir3_block_verify(if (xfs_sb_version_hascrc (&mp->m_sb)) {if (hdr3->magic !=cpu_to_be32 (XFS_DIR3_BLOCK_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->lsn))) -return false; +return __this_address; }else {if (hdr3->magic !=cpu_to_be32 (XFS_DIR2_BLOCK_MAGIC )) -return false; +return __this_address; }return __xfs_dir3_data_check (NULL , bp); }
@@ -90,7 +90,7 @@ xfs_dir3_block_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_DATA_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dir3_block_verify (bp)) +else if (xfs_dir3_block_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -105,7 +105,7 @@ xfs_dir3_block_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; -if (!xfs_dir3_block_verify (bp)) { +if (xfs_dir3_block_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_dir2_data.c +33 -33
179 lines not on this page · raw message
fs/xfs/libxfs/xfs_dir2_leaf.c +15 -15
@@ -73,13 +73,13 @@ xfs_dir3_leaf1_check( } else if (leafhdr.magic != XFS_DIR2_LEAF1_MAGIC)return false; -return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf); +return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf) ==NULL ; }#else #define xfs_dir3_leaf_check (dp, bp)#endif -bool +void * xfs_dir3_leaf_check_int( struct xfs_mount *mp, struct xfs_inode *dp,
@@ -114,27 +114,27 @@ xfs_dir3_leaf_check_int(* We can deduce a value for that from di_size. */ if (hdr->count > ops->leaf_max_ents (geo)) -return false; +return __this_address;/* Leaves and bests don't overlap in leaf format. */ if ((hdr->magic ==XFS_DIR2_LEAF1_MAGIC || hdr->magic ==XFS_DIR3_LEAF1_MAGIC ) && (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) -return false; +return __this_address;/* Check hash value order, count stale entries. */ for (i = stale =0 ; i < hdr->count; i++) {if (i +1 < hdr->count) {if (be32_to_cpu (ents[i].hashval) >be32_to_cpu (ents[i +1 ].hashval)) -return false; +return __this_address; }if (ents[i].address ==cpu_to_be32 (XFS_DIR2_NULL_DATAPTR )) stale++; }if (hdr->stale != stale) -return false; -return true; +return __this_address; +return NULL ; }/*
@@ -142,7 +142,7 @@ xfs_dir3_leaf_check_int(* kernels we don't get assertion failures in xfs_dir3_leaf_hdr_from_disk() due * to incorrect magic numbers. */ -static bool +static void *xfs_dir3_leaf_verify (struct xfs_buf *bp,uint16_t magic)
@@ -160,16 +160,16 @@ xfs_dir3_leaf_verify( : XFS_DIR3_LEAFN_MAGIC;if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) -return false; +return __this_address;if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (leaf3->info.lsn))) -return false; +return __this_address; }else {if (leaf->hdr.info.magic !=cpu_to_be16 (magic)) -return false; +return __this_address; }return xfs_dir3_leaf_check_int (mp,NULL ,NULL , leaf);
@@ -185,7 +185,7 @@ __read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_LEAF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dir3_leaf_verify (bp, magic)) +else if (xfs_dir3_leaf_verify (bp, magic))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -201,7 +201,7 @@ __write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_leaf_hdr *hdr3 = bp->b_addr; -if (!xfs_dir3_leaf_verify (bp, magic)) { +if (xfs_dir3_leaf_verify (bp, magic)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_dir2_node.c +18 -18
@@ -76,13 +76,13 @@ xfs_dir3_leafn_check( } else if (leafhdr.magic != XFS_DIR2_LEAFN_MAGIC)return false; -return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf); +return xfs_dir3_leaf_check_int (dp->i_mount, dp, &leafhdr, leaf) ==NULL ; }#else #define xfs_dir3_leaf_check (dp, bp)#endif -static bool +static void *xfs_dir3_free_verify (struct xfs_buf *bp) {
@@ -93,21 +93,21 @@ xfs_dir3_free_verify(struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;if (hdr3->magic !=cpu_to_be32 (XFS_DIR3_FREE_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&hdr3->uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (be64_to_cpu (hdr3->blkno) != bp->b_bn) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (hdr3->lsn))) -return false; +return __this_address; }else {if (hdr->magic !=cpu_to_be32 (XFS_DIR2_FREE_MAGIC )) -return false; +return __this_address; }/* XXX: should bounds check the xfs_dir3_icfree_hdr here */ -return true; +return NULL ; } static void
@@ -119,7 +119,7 @@ xfs_dir3_free_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_FREE_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_dir3_free_verify (bp)) +else if (xfs_dir3_free_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -134,7 +134,7 @@ xfs_dir3_free_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; -if (!xfs_dir3_free_verify (bp)) { +if (xfs_dir3_free_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
@@ -174,22 +174,22 @@ xfs_dir3_free_header_check(struct xfs_dir3_free_hdr *hdr3 = bp->b_addr;if (be32_to_cpu (hdr3->firstdb) != firstdb) -return false; +return __this_address;if (be32_to_cpu (hdr3->nvalid) > maxbests) -return false; +return __this_address;if (be32_to_cpu (hdr3->nvalid) <be32_to_cpu (hdr3->nused)) -return false; +return __this_address; }else {struct xfs_dir2_free_hdr *hdr = bp->b_addr;if (be32_to_cpu (hdr->firstdb) != firstdb) -return false; +return __this_address;if (be32_to_cpu (hdr->nvalid) > maxbests) -return false; +return __this_address;if (be32_to_cpu (hdr->nvalid) <be32_to_cpu (hdr->nused)) -return false; +return __this_address; } -return true; +return NULL ; } static int
@@ -208,7 +208,7 @@ __xfs_dir3_free_read(return err;/* Check things that we can't do in the verifier. */ -if (!xfs_dir3_free_header_check (dp, fbno, *bpp)) { +if (xfs_dir3_free_header_check (dp, fbno, *bpp)) {xfs_buf_ioerror (*bpp, -EFSCORRUPTED );xfs_verifier_error (*bpp);xfs_trans_brelse (tp, *bpp);
fs/xfs/libxfs/xfs_dir2_priv.h +3 -3
@@ -41,7 +41,7 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,#ifdef DEBUG #define xfs_dir3_data_check (dp, bp) \ do { \ - if (!__xfs_dir3_data_check((dp), (bp))) { \ + if (__xfs_dir3_data_check((dp), (bp))) { \ XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, \ (bp)->b_target->bt_mount, (bp)->b_addr); \ } \
@@ -50,7 +50,7 @@ do { \#define xfs_dir3_data_check (dp,bp)#endif -extern bool __xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp); +extern void *__xfs_dir3_data_check (struct xfs_inode *dp,struct xfs_buf *bp);extern int xfs_dir3_data_read (struct xfs_trans *tp,struct xfs_inode *dp,xfs_dablk_t bno,xfs_daddr_t mapped_bno,struct xfs_buf **bpp); extern int xfs_dir3_data_readahead(struct xfs_inode *dp, xfs_dablk_t bno,
@@ -95,7 +95,7 @@ xfs_dir3_leaf_find_entry(struct xfs_dir3_icleaf_hdr *leafhdr, int lowstale, int highstale, int *lfloglow, int *lfloghigh);extern int xfs_dir2_node_to_leaf (struct xfs_da_state *state); -extern bool xfs_dir3_leaf_check_int (struct xfs_mount *mp,struct xfs_inode *dp, +extern void *xfs_dir3_leaf_check_int (struct xfs_mount *mp,struct xfs_inode *dp,struct xfs_dir3_icleaf_hdr *hdr,struct xfs_dir2_leaf *leaf);/* xfs_dir2_node.c */
fs/xfs/libxfs/xfs_ialloc.c +11 -11
@@ -2497,7 +2497,7 @@ xfs_check_agi_unlinked(#define xfs_check_agi_unlinked (agi)#endif -static bool +static void *xfs_agi_verify (struct xfs_buf *bp) {
@@ -2506,28 +2506,28 @@ xfs_agi_verify(if (xfs_sb_version_hascrc (&mp->m_sb)) {if (!uuid_equal (&agi->agi_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (XFS_BUF_TO_AGI (bp)->agi_lsn))) -return false; +return __this_address; }/* * Validate the magic number of the agi block. */ if (agi->agi_magicnum !=cpu_to_be32 (XFS_AGI_MAGIC )) -return false; +return __this_address;if (!XFS_AGI_GOOD_VERSION (be32_to_cpu (agi->agi_versionnum))) -return false; +return __this_address;if (be32_to_cpu (agi->agi_level) <1 ||be32_to_cpu (agi->agi_level) >XFS_BTREE_MAXLEVELS ) -return false; +return __this_address;if (xfs_sb_version_hasfinobt (&mp->m_sb) && (be32_to_cpu (agi->agi_free_level) <1 ||be32_to_cpu (agi->agi_free_level) >XFS_BTREE_MAXLEVELS )) -return false; +return __this_address;/* * during growfs operations, the perag is not fully initialised,
@@ -2536,10 +2536,10 @@ xfs_agi_verify(* so we can detect and avoid this problem. */ if (bp->b_pag &&be32_to_cpu (agi->agi_seqno) != bp->b_pag->pag_agno) -return false; +return __this_address;xfs_check_agi_unlinked (agi); -return true; +return NULL ; } static void
@@ -2551,7 +2551,7 @@ xfs_agi_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_AGI_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (XFS_TEST_ERROR (!xfs_agi_verify (bp), mp, +else if (XFS_TEST_ERROR (xfs_agi_verify (bp), mp,XFS_ERRTAG_IALLOC_READ_AGI ))xfs_buf_ioerror (bp, -EFSCORRUPTED );
@@ -2566,7 +2566,7 @@ xfs_agi_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; -if (!xfs_agi_verify (bp)) { +if (xfs_agi_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/libxfs/xfs_ialloc_btree.c +8 -7
@@ -250,12 +250,13 @@ xfs_inobt_diff_two_keys(be32_to_cpu (k2->inobt.ir_startino); } -static int +static void *xfs_inobt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp); +void *failed_at;unsigned int level;/*
@@ -271,20 +272,20 @@ xfs_inobt_verify(switch (block->bb_magic) {case cpu_to_be32 (XFS_IBT_CRC_MAGIC ):case cpu_to_be32 (XFS_FIBT_CRC_MAGIC ): -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at;/* fall through */ case cpu_to_be32 (XFS_IBT_MAGIC ):case cpu_to_be32 (XFS_FIBT_MAGIC ):break ;default : -return 0 ; +return NULL ; }/* level verification */ level =be16_to_cpu (block->bb_level);if (level >= mp->m_in_maxlevels) -return false; +return __this_address;return xfs_btree_sblock_verify (bp, mp->m_inobt_mxr[level !=0 ]); }
@@ -295,7 +296,7 @@ xfs_inobt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_inobt_verify (bp)) +else if (xfs_inobt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -308,7 +309,7 @@ static voidxfs_inobt_write_verify ( struct xfs_buf *bp) { -if (!xfs_inobt_verify (bp)) { +if (xfs_inobt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_inode_buf.c +15 -15
@@ -380,7 +380,7 @@ xfs_log_dinode_to_disk( } } -bool +void * xfs_dinode_verify( struct xfs_mount *mp, xfs_ino_t ino,
@@ -391,33 +391,33 @@ xfs_dinode_verify(uint64_t flags2;if (dip->di_magic !=cpu_to_be16 (XFS_DINODE_MAGIC )) -return false; +return __this_address;/* don't allow invalid i_size */ if (be64_to_cpu (dip->di_size) & (1ULL <<63 )) -return false; +return __this_address; mode =be16_to_cpu (dip->di_mode);if (mode &&xfs_mode_to_ftype (mode) ==XFS_DIR3_FT_UNKNOWN ) -return false; +return __this_address;/* No zero-length symlinks/dirs. */ if ((S_ISLNK (mode) ||S_ISDIR (mode)) && dip->di_size ==0 ) -return false; +return __this_address;/* only version 3 or greater inodes are extensively verified here */ if (dip->di_version <3 ) -return true; +return NULL ;if (!xfs_sb_version_hascrc (&mp->m_sb)) -return false; +return __this_address;if (!xfs_verify_cksum ((char *)dip, mp->m_sb.sb_inodesize,XFS_DINODE_CRC_OFF )) -return false; +return __this_address;if (be64_to_cpu (dip->di_ino) != ino) -return false; +return __this_address;if (!uuid_equal (&dip->di_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address; flags =be16_to_cpu (dip->di_flags); flags2 =be64_to_cpu (dip->di_flags2);
@@ -425,17 +425,17 @@ xfs_dinode_verify(/* don't allow reflink/cowextsize if we don't have reflink */ if ((flags2 & (XFS_DIFLAG2_REFLINK |XFS_DIFLAG2_COWEXTSIZE )) && !xfs_sb_version_hasreflink (&mp->m_sb)) -return false; +return __this_address;/* don't let reflink and realtime mix */ if ((flags2 &XFS_DIFLAG2_REFLINK ) && (flags &XFS_DIFLAG_REALTIME )) -return false; +return __this_address;/* don't let reflink and dax mix */ if ((flags2 &XFS_DIFLAG2_REFLINK ) && (flags2 &XFS_DIFLAG2_DAX )) -return false; +return __this_address; -return true; +return NULL ; }void
@@ -506,7 +506,7 @@ xfs_iread(return error;/* even unallocated inodes are verified */ -if (!xfs_dinode_verify (mp, ip->i_ino, dip)) { +if (xfs_dinode_verify (mp, ip->i_ino, dip)) {xfs_alert (mp,"%s: validation failed for inode %lld" , __func__, ip->i_ino);
fs/xfs/libxfs/xfs_inode_buf.h +2 -2
@@ -82,7 +82,7 @@ void xfs_inobp_check(struct xfs_mount *, struct xfs_buf *);#define xfs_inobp_check (mp, bp)#endif /* DEBUG */ -bool xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino, -struct xfs_dinode *dip); +void *xfs_dinode_verify (struct xfs_mount *mp,xfs_ino_t ino, +struct xfs_dinode *dip);#endif /* __XFS_INODE_BUF_H__ */
fs/xfs/libxfs/xfs_refcount_btree.c +10 -9
@@ -223,29 +223,30 @@ xfs_refcountbt_diff_two_keys(be32_to_cpu (k2->refc.rc_startblock); } -STATIC bool +STATIC void *xfs_refcountbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_perag *pag = bp->b_pag; +void *failed_at;unsigned int level;if (block->bb_magic !=cpu_to_be32 (XFS_REFC_CRC_MAGIC )) -return false; +return __this_address;if (!xfs_sb_version_hasreflink (&mp->m_sb)) -return false; -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +return __this_address; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at; level =be16_to_cpu (block->bb_level);if (pag && pag->pagf_init) {if (level >= pag->pagf_refcount_level) -return false; +return __this_address; }else if (level >= mp->m_refc_maxlevels) -return false; +return __this_address;return xfs_btree_sblock_verify (bp, mp->m_refc_mxr[level !=0 ]); }
@@ -256,7 +257,7 @@ xfs_refcountbt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_refcountbt_verify (bp)) +else if (xfs_refcountbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -269,7 +270,7 @@ STATIC voidxfs_refcountbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_refcountbt_verify (bp)) { +if (xfs_refcountbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_rmap_btree.c +10 -9
@@ -303,13 +303,14 @@ xfs_rmapbt_diff_two_keys(return 0 ; } -static bool +static void *xfs_rmapbt_verify (struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_btree_block *block =XFS_BUF_TO_BLOCK (bp);struct xfs_perag *pag = bp->b_pag; +void *failed_at;unsigned int level;/*
@@ -325,19 +326,19 @@ xfs_rmapbt_verify(* in this case. */ if (block->bb_magic !=cpu_to_be32 (XFS_RMAP_CRC_MAGIC )) -return false; +return __this_address;if (!xfs_sb_version_hasrmapbt (&mp->m_sb)) -return false; -if (!xfs_btree_sblock_v5hdr_verify (bp)) -return false; +return __this_address; +if ((failed_at =xfs_btree_sblock_v5hdr_verify (bp))) +return failed_at; level =be16_to_cpu (block->bb_level);if (pag && pag->pagf_init) {if (level >= pag->pagf_levels[XFS_BTNUM_RMAPi]) -return false; +return __this_address; }else if (level >= mp->m_rmap_maxlevels) -return false; +return __this_address;return xfs_btree_sblock_verify (bp, mp->m_rmap_mxr[level !=0 ]); }
@@ -348,7 +349,7 @@ xfs_rmapbt_read_verify( {if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_rmapbt_verify (bp)) +else if (xfs_rmapbt_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {
@@ -361,7 +362,7 @@ static voidxfs_rmapbt_write_verify ( struct xfs_buf *bp) { -if (!xfs_rmapbt_verify (bp)) { +if (xfs_rmapbt_verify (bp)) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);
fs/xfs/libxfs/xfs_symlink_remote.c +11 -11
@@ -98,7 +98,7 @@ xfs_symlink_hdr_ok(return true; } -static bool +static void *xfs_symlink_verify (struct xfs_buf *bp) {
@@ -106,22 +106,22 @@ xfs_symlink_verify(struct xfs_dsymlink_hdr *dsl = bp->b_addr;if (!xfs_sb_version_hascrc (&mp->m_sb)) -return false; +return __this_address;if (dsl->sl_magic !=cpu_to_be32 (XFS_SYMLINK_MAGIC )) -return false; +return __this_address;if (!uuid_equal (&dsl->sl_uuid, &mp->m_sb.sb_meta_uuid)) -return false; +return __this_address;if (bp->b_bn !=be64_to_cpu (dsl->sl_blkno)) -return false; +return __this_address;if (be32_to_cpu (dsl->sl_offset) +be32_to_cpu (dsl->sl_bytes) >=XFS_SYMLINK_MAXLEN ) -return false; +return __this_address;if (dsl->sl_owner ==0 ) -return false; +return __this_address;if (!xfs_log_check_lsn (mp,be64_to_cpu (dsl->sl_lsn))) -return false; +return __this_address; -return true; +return NULL ; } static void
@@ -136,7 +136,7 @@ xfs_symlink_read_verify(if (!xfs_buf_verify_cksum (bp,XFS_SYMLINK_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (!xfs_symlink_verify (bp)) +else if (xfs_symlink_verify (bp))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error)
@@ -154,7 +154,7 @@ xfs_symlink_write_verify(if (!xfs_sb_version_hascrc (&mp->m_sb))return ; -if (!xfs_symlink_verify (bp)) { +if (xfs_symlink_verify (bp)) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp);return ;
fs/xfs/xfs_linux.h +7 -0
@@ -142,6 +142,13 @@ typedef __u32 xfs_nlink_t;#define SYNCHRONIZE () barrier()#define __return_address __builtin_return_address(0) +/* +* Return the address of a label. Use asm volatile so that the optimizer +* won't try anything stupid like refactoring the error jumpouts into a +* single return, which throws off the reported address. +*/ +#define __this_address ({ __label__ __here; __here: asm volatile(""); &&__here; }) +#define XFS_PROJID_DEFAULT 0#define MIN (a,b) (min(a,b))
PATCH 4/12 xfs: refactor verifier callers to print address of failing check
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Refactor the callers of verifiers to print the instruction address of a failing check.
--- fs/xfs/libxfs/xfs_alloc.c | 20 ++++++++++++-------- fs/xfs/libxfs/xfs_alloc_btree.c | 12 ++++++++---- fs/xfs/libxfs/xfs_attr_leaf.c | 10 ++++++---- fs/xfs/libxfs/xfs_attr_remote.c | 12 +++++++----- fs/xfs/libxfs/xfs_bmap_btree.c | 12 ++++++++---- fs/xfs/libxfs/xfs_da_btree.c | 11 +++++++---- fs/xfs/libxfs/xfs_dir2_block.c | 10 ++++++---- fs/xfs/libxfs/xfs_dir2_data.c | 12 +++++++----- fs/xfs/libxfs/xfs_dir2_leaf.c | 10 ++++++---- fs/xfs/libxfs/xfs_dir2_node.c | 17 ++++++++++------- fs/xfs/libxfs/xfs_dquot_buf.c | 4 ++-- fs/xfs/libxfs/xfs_ialloc.c | 10 ++++++---- fs/xfs/libxfs/xfs_ialloc_btree.c | 12 ++++++++---- fs/xfs/libxfs/xfs_inode_buf.c | 24 +++++++++++++----------- fs/xfs/libxfs/xfs_refcount_btree.c | 12 ++++++++---- fs/xfs/libxfs/xfs_rmap_btree.c | 12 ++++++++---- fs/xfs/libxfs/xfs_sb.c | 4 ++-- fs/xfs/libxfs/xfs_symlink_remote.c | 10 ++++++---- fs/xfs/xfs_error.c | 6 ++++-- fs/xfs/xfs_error.h | 2 +- 20 files changed, 135 insertions(+), 87 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +12 -8
@@ -556,6 +556,7 @@ xfs_agfl_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;/* * There is no verification of non-crc AGFLs because mkfs does not
@@ -568,11 +569,11 @@ xfs_agfl_read_verify(if (!xfs_buf_verify_cksum (bp,XFS_AGFL_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_agfl_verify (bp)) +else if ((failed_at =xfs_agfl_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -581,14 +582,15 @@ xfs_agfl_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; +void *failed_at;/* no verification of non-crc AGFLs */ if (!xfs_sb_version_hascrc (&mp->m_sb))return ; -if (xfs_agfl_verify (bp)) { +if ((failed_at =xfs_agfl_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
@@ -2450,16 +2452,17 @@ xfs_agf_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_AGF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (XFS_TEST_ERROR (xfs_agf_verify (mp, bp), mp, +else if (XFS_TEST_ERROR ((failed_at =xfs_agf_verify (mp, bp)), mp,XFS_ERRTAG_ALLOC_READ_AGF ))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -2468,10 +2471,11 @@ xfs_agf_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; +void *failed_at; -if (xfs_agf_verify (mp, bp)) { +if ((failed_at =xfs_agf_verify (mp, bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
fs/xfs/libxfs/xfs_alloc_btree.c +8 -4
@@ -364,14 +364,16 @@ static voidxfs_allocbt_read_verify ( struct xfs_buf *bp) { +void *failed_at = __this_address; +if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_allocbt_verify (bp)) +else if ((failed_at =xfs_allocbt_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {trace_xfs_btree_corrupt (bp, _RET_IP_); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } }
@@ -379,10 +381,12 @@ static voidxfs_allocbt_write_verify ( struct xfs_buf *bp) { -if (xfs_allocbt_verify (bp)) { +void *failed_at; + +if ((failed_at =xfs_allocbt_verify (bp))) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }xfs_btree_sblock_calc_crc (bp);
fs/xfs/libxfs/xfs_attr_leaf.c +6 -4
@@ -295,10 +295,11 @@ xfs_attr3_leaf_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_attr3_leaf_hdr *hdr3 = bp->b_addr; +void *failed_at; -if (xfs_attr3_leaf_verify (bp)) { +if ((failed_at =xfs_attr3_leaf_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
@@ -322,15 +323,16 @@ xfs_attr3_leaf_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_ATTR3_LEAF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_attr3_leaf_verify (bp)) +else if ((failed_at =xfs_attr3_leaf_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); }const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = {
fs/xfs/libxfs/xfs_attr_remote.c +7 -5
@@ -122,6 +122,7 @@ xfs_attr3_rmt_read_verify( {struct xfs_mount *mp = bp->b_target->bt_mount;char *ptr; +void *failed_at = __this_address;int len;xfs_daddr_t bno;int blksize = mp->m_attr_geo->blksize;
@@ -140,7 +141,7 @@ xfs_attr3_rmt_read_verify(xfs_buf_ioerror (bp, -EFSBADCRC );break ; } -if (xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) { +if ((failed_at =xfs_attr3_rmt_verify (mp, ptr, blksize, bno))) {xfs_buf_ioerror (bp, -EFSCORRUPTED );break ; }
@@ -150,7 +151,7 @@ xfs_attr3_rmt_read_verify( }if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);else ASSERT (len ==0 ); }
@@ -160,6 +161,7 @@ xfs_attr3_rmt_write_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at;int blksize = mp->m_attr_geo->blksize;char *ptr;int len;
@@ -177,9 +179,9 @@ xfs_attr3_rmt_write_verify(while (len >0 ) {struct xfs_attr3_rmt_hdr *rmt = (struct xfs_attr3_rmt_hdr *)ptr; -if (xfs_attr3_rmt_verify (mp, ptr, blksize, bno)) { +if ((failed_at =xfs_attr3_rmt_verify (mp, ptr, blksize, bno))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
@@ -189,7 +191,7 @@ xfs_attr3_rmt_write_verify(*/ if (rmt->rm_lsn !=cpu_to_be64 (NULLCOMMITLSN )) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, __this_address);return ; }xfs_update_cksum (ptr, blksize,XFS_ATTR3_RMT_CRC_OFF );
fs/xfs/libxfs/xfs_bmap_btree.c +8 -4
@@ -660,14 +660,16 @@ static voidxfs_bmbt_read_verify ( struct xfs_buf *bp) { +void *failed_at = __this_address; +if (!xfs_btree_lblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_bmbt_verify (bp)) +else if ((failed_at =xfs_bmbt_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {trace_xfs_btree_corrupt (bp, _RET_IP_); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } }
@@ -675,10 +677,12 @@ static voidxfs_bmbt_write_verify ( struct xfs_buf *bp) { -if (xfs_bmbt_verify (bp)) { +void *failed_at; + +if ((failed_at =xfs_bmbt_verify (bp))) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }xfs_btree_lblock_calc_crc (bp);
fs/xfs/libxfs/xfs_da_btree.c +7 -4
@@ -184,10 +184,11 @@ xfs_da3_node_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_da3_node_hdr *hdr3 = bp->b_addr; +void *failed_at; -if (xfs_da3_node_verify (bp)) { +if ((failed_at =xfs_da3_node_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
@@ -211,6 +212,7 @@ xfs_da3_node_read_verify( struct xfs_buf *bp) {struct xfs_da_blkinfo *info = bp->b_addr; +void *failed_at = __this_address;switch (be16_to_cpu (info->magic)) {case XFS_DA3_NODE_MAGIC :
@@ -220,7 +222,7 @@ xfs_da3_node_read_verify( }/* fall through */ case XFS_DA_NODE_MAGIC : -if (xfs_da3_node_verify (bp)) { +if ((failed_at =xfs_da3_node_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED );break ; }
@@ -236,12 +238,13 @@ xfs_da3_node_read_verify( bp->b_ops->verify_read (bp);return ;default : + failed_at = __this_address;xfs_buf_ioerror (bp, -EFSCORRUPTED );break ; }/* corrupt block */ -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); }const struct xfs_buf_ops xfs_da3_node_buf_ops = {
fs/xfs/libxfs/xfs_dir2_block.c +6 -4
@@ -86,15 +86,16 @@ xfs_dir3_block_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_DATA_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_dir3_block_verify (bp)) +else if ((failed_at =xfs_dir3_block_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -104,10 +105,11 @@ xfs_dir3_block_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; +void *failed_at; -if (xfs_dir3_block_verify (bp)) { +if ((failed_at =xfs_dir3_block_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
fs/xfs/libxfs/xfs_dir2_data.c +7 -5
@@ -268,7 +268,7 @@ xfs_dir3_data_reada_verify(return ;default :xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, __this_address);break ; } }
@@ -278,15 +278,16 @@ xfs_dir3_data_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_DATA_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_dir3_data_verify (bp)) +else if ((failed_at =xfs_dir3_data_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -296,10 +297,11 @@ xfs_dir3_data_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; +void *failed_at; -if (xfs_dir3_data_verify (bp)) { +if ((failed_at =xfs_dir3_data_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
fs/xfs/libxfs/xfs_dir2_leaf.c +6 -4
@@ -181,15 +181,16 @@ __read_verify( uint16_t magic) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_LEAF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_dir3_leaf_verify (bp, magic)) +else if ((failed_at =xfs_dir3_leaf_verify (bp, magic)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -200,10 +201,11 @@ __write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_leaf_hdr *hdr3 = bp->b_addr; +void *failed_at; -if (xfs_dir3_leaf_verify (bp, magic)) { +if ((failed_at =xfs_dir3_leaf_verify (bp, magic))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
fs/xfs/libxfs/xfs_dir2_node.c +10 -7
@@ -115,15 +115,16 @@ xfs_dir3_free_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_DIR3_FREE_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_dir3_free_verify (bp)) +else if ((failed_at =xfs_dir3_free_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -133,10 +134,11 @@ xfs_dir3_free_write_verify(struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv;struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr; +void *failed_at; -if (xfs_dir3_free_verify (bp)) { +if ((failed_at =xfs_dir3_free_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
@@ -156,7 +158,7 @@ const struct xfs_buf_ops xfs_dir3_free_buf_ops = { };/* Everything ok in the free block header? */ -static bool +static void * xfs_dir3_free_header_check( struct xfs_inode *dp, xfs_dablk_t fbno,
@@ -200,6 +202,7 @@ __xfs_dir3_free_read(xfs_daddr_t mappedbno, struct xfs_buf **bpp) { + void *failed_at;int err; err = xfs_da_read_buf(tp, dp, fbno, mappedbno, bpp,
@@ -208,9 +211,9 @@ __xfs_dir3_free_read(return err;/* Check things that we can't do in the verifier. */ -if (xfs_dir3_free_header_check (dp, fbno, *bpp)) { +if ((failed_at =xfs_dir3_free_header_check (dp, fbno, *bpp))) {xfs_buf_ioerror (*bpp, -EFSCORRUPTED ); -xfs_verifier_error (*bpp); +xfs_verifier_error (*bpp, failed_at);xfs_trans_brelse (tp, *bpp);return -EFSCORRUPTED ; }
fs/xfs/libxfs/xfs_dquot_buf.c +2 -2
@@ -254,7 +254,7 @@ xfs_dquot_buf_read_verify(xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, __this_address); }/*
@@ -289,7 +289,7 @@ xfs_dquot_buf_write_verify(if (!xfs_dquot_buf_verify (mp, bp,XFS_QMOPT_DOWARN )) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, __this_address);return ; } }
fs/xfs/libxfs/xfs_ialloc.c +6 -4
@@ -2547,16 +2547,17 @@ xfs_agi_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_AGI_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (XFS_TEST_ERROR (xfs_agi_verify (bp), mp, +else if (XFS_TEST_ERROR ((failed_at =xfs_agi_verify (bp)), mp,XFS_ERRTAG_IALLOC_READ_AGI ))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -2565,10 +2566,11 @@ xfs_agi_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; +void *failed_at; -if (xfs_agi_verify (bp)) { +if ((failed_at =xfs_agi_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
fs/xfs/libxfs/xfs_ialloc_btree.c +8 -4
@@ -294,14 +294,16 @@ static voidxfs_inobt_read_verify ( struct xfs_buf *bp) { +void *failed_at = __this_address; +if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_inobt_verify (bp)) +else if ((failed_at =xfs_inobt_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {trace_xfs_btree_corrupt (bp, _RET_IP_); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } }
@@ -309,10 +311,12 @@ static voidxfs_inobt_write_verify ( struct xfs_buf *bp) { -if (xfs_inobt_verify (bp)) { +void *failed_at; + +if ((failed_at =xfs_inobt_verify (bp))) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }xfs_btree_sblock_calc_crc (bp);
fs/xfs/libxfs/xfs_inode_buf.c +13 -11
@@ -113,7 +113,7 @@ xfs_inode_buf_verify( }xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, __this_address);#ifdef DEBUG xfs_alert(mp, "bad inode magic/vsn daddr %lld #%d (magic=%x)",
@@ -468,14 +468,15 @@ xfs_dinode_calc_crc(*/ int xfs_iread ( -xfs_mount_t *mp, -xfs_trans_t *tp, -xfs_inode_t *ip, -uint iget_flags) +struct xfs_mount *mp, +struct xfs_trans *tp, +struct xfs_inode *ip, +uint iget_flags) { -xfs_buf_t *bp; -xfs_dinode_t *dip; -int error; +struct xfs_buf *bp; +struct xfs_dinode *dip; +void *failed_at; +int error;/* * Fill in the location information in the in-core inode.
@@ -506,9 +507,10 @@ xfs_iread(return error;/* even unallocated inodes are verified */ -if (xfs_dinode_verify (mp, ip->i_ino, dip)) { -xfs_alert (mp,"%s: validation failed for inode %lld" , - __func__, ip->i_ino); + failed_at =xfs_dinode_verify (mp, ip->i_ino, dip); +if (failed_at) { +xfs_alert (mp,"%s: validation failed for inode %lld at %pF" , + __func__, ip->i_ino, failed_at);XFS_CORRUPTION_ERROR (__func__,XFS_ERRLEVEL_LOW , mp, dip); error = -EFSCORRUPTED ;
fs/xfs/libxfs/xfs_refcount_btree.c +8 -4
@@ -255,14 +255,16 @@ STATIC voidxfs_refcountbt_read_verify ( struct xfs_buf *bp) { +void *failed_at = __this_address; +if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_refcountbt_verify (bp)) +else if ((failed_at =xfs_refcountbt_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {trace_xfs_btree_corrupt (bp, _RET_IP_); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } }
@@ -270,10 +272,12 @@ STATIC voidxfs_refcountbt_write_verify ( struct xfs_buf *bp) { -if (xfs_refcountbt_verify (bp)) { +void *failed_at; + +if ((failed_at =xfs_refcountbt_verify (bp))) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }xfs_btree_sblock_calc_crc (bp);
fs/xfs/libxfs/xfs_rmap_btree.c +8 -4
@@ -347,14 +347,16 @@ static voidxfs_rmapbt_read_verify ( struct xfs_buf *bp) { +void *failed_at = __this_address; +if (!xfs_btree_sblock_verify_crc (bp))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_rmapbt_verify (bp)) +else if ((failed_at =xfs_rmapbt_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) {trace_xfs_btree_corrupt (bp, _RET_IP_); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } }
@@ -362,10 +364,12 @@ static voidxfs_rmapbt_write_verify ( struct xfs_buf *bp) { -if (xfs_rmapbt_verify (bp)) { +void *failed_at; + +if ((failed_at =xfs_rmapbt_verify (bp))) {trace_xfs_btree_corrupt (bp, _RET_IP_);xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }xfs_btree_sblock_calc_crc (bp);
fs/xfs/libxfs/xfs_sb.c +2 -2
@@ -643,7 +643,7 @@ xfs_sb_read_verify(if (error) {xfs_buf_ioerror (bp, error);if (error == -EFSCORRUPTED || error == -EFSBADCRC ) -xfs_verifier_error (bp); +xfs_verifier_error (bp, __this_address); } }
@@ -679,7 +679,7 @@ xfs_sb_write_verify( error =xfs_sb_verify (bp, false);if (error) {xfs_buf_ioerror (bp, error); -xfs_verifier_error (bp); +xfs_verifier_error (bp, __this_address);return ; }
fs/xfs/libxfs/xfs_symlink_remote.c +6 -4
@@ -129,6 +129,7 @@ xfs_symlink_read_verify( struct xfs_buf *bp) {struct xfs_mount *mp = bp->b_target->bt_mount; +void *failed_at = __this_address;/* no verification of non-crc buffers */ if (!xfs_sb_version_hascrc (&mp->m_sb))
@@ -136,11 +137,11 @@ xfs_symlink_read_verify(if (!xfs_buf_verify_cksum (bp,XFS_SYMLINK_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (xfs_symlink_verify (bp)) +else if ((failed_at =xfs_symlink_verify (bp)))xfs_buf_ioerror (bp, -EFSCORRUPTED );if (bp->b_error) -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at); } static void
@@ -149,14 +150,15 @@ xfs_symlink_write_verify( {struct xfs_mount *mp = bp->b_target->bt_mount;struct xfs_buf_log_item *bip = bp->b_fspriv; +void *failed_at;/* no verification of non-crc buffers */ if (!xfs_sb_version_hascrc (&mp->m_sb))return ; -if (xfs_symlink_verify (bp)) { +if ((failed_at =xfs_symlink_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED ); -xfs_verifier_error (bp); +xfs_verifier_error (bp, failed_at);return ; }
fs/xfs/xfs_error.c +4 -2
@@ -345,7 +345,8 @@ xfs_corruption_error(*/ void xfs_verifier_error ( -struct xfs_buf *bp) +struct xfs_buf *bp, +void *failed_at) {struct xfs_mount *mp = bp->b_target->bt_mount;
@@ -354,7 +355,8 @@ xfs_verifier_error(xfs_alert (mp,"Metadata %s detected at %pF, %s block 0x%llx" , bp->b_error == -EFSBADCRC ?"CRC error" :"corruption" , - __return_address, bp->b_ops->name, bp->b_bn); + failed_at ? failed_at : __return_address, bp->b_ops->name, + bp->b_bn);xfs_alert (mp,"Unmount and run xfs_repair" );
fs/xfs/xfs_error.h +1 -1
@@ -25,7 +25,7 @@ extern void xfs_error_report(const char *tag, int level, struct xfs_mount *mp,extern void xfs_corruption_error (const char *tag,int level,struct xfs_mount *mp,void *p,const char *filename,int linenum,void *ra); -extern void xfs_verifier_error (struct xfs_buf *bp); +extern void xfs_verifier_error (struct xfs_buf *bp,void *failed_at);#define XFS_ERROR_REPORT (e, lvl, mp) \ xfs_error_report(e, lvl, mp, __FILE__, __LINE__, __return_address)
PATCH 5/12 xfs: verify dinode header first
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Move the v3 inode integrity information (crc, owner, metauuid) before we look at anything else in the inode so that we don't waste time on a torn write or a totally garbled block. This makes xfs_dinode_verify more consistent with the other verifiers.
--- fs/xfs/libxfs/xfs_inode_buf.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
fs/xfs/libxfs/xfs_inode_buf.c +13 -10
@@ -393,6 +393,19 @@ xfs_dinode_verify(if (dip->di_magic !=cpu_to_be16 (XFS_DINODE_MAGIC ))return __this_address; +/* Verify v3 integrity information first */ +if (dip->di_version >=3 ) { +if (!xfs_sb_version_hascrc (&mp->m_sb)) +return __this_address; +if (!xfs_verify_cksum ((char *)dip, mp->m_sb.sb_inodesize, +XFS_DINODE_CRC_OFF )) +return __this_address; +if (be64_to_cpu (dip->di_ino) != ino) +return __this_address; +if (!uuid_equal (&dip->di_uuid, &mp->m_sb.sb_meta_uuid)) +return __this_address; + } +/* don't allow invalid i_size */ if (be64_to_cpu (dip->di_size) & (1ULL <<63 ))return __this_address;
@@ -409,16 +422,6 @@ xfs_dinode_verify(if (dip->di_version <3 )return NULL ; -if (!xfs_sb_version_hascrc (&mp->m_sb)) -return __this_address; -if (!xfs_verify_cksum ((char *)dip, mp->m_sb.sb_inodesize, -XFS_DINODE_CRC_OFF )) -return __this_address; -if (be64_to_cpu (dip->di_ino) != ino) -return __this_address; -if (!uuid_equal (&dip->di_uuid, &mp->m_sb.sb_meta_uuid)) -return __this_address; - flags =be16_to_cpu (dip->di_flags); flags2 =be64_to_cpu (dip->di_flags2);
PATCH 6/12 xfs: move inode fork verifiers to xfs_dinode_verify
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Consolidate the fork size and format verifiers to xfs_dinode_verify so that we can reject bad inodes earlier and in a single place.
--- fs/xfs/libxfs/xfs_inode_buf.c | 68 ++++++++++++++++++++++++++- fs/xfs/libxfs/xfs_inode_fork.c | 99 ---------------------------------------- 2 files changed, 65 insertions(+), 102 deletions(-)
fs/xfs/libxfs/xfs_inode_buf.c +65 -3
@@ -389,6 +389,7 @@ xfs_dinode_verify(uint16_t mode;uint16_t flags;uint64_t flags2; +uint64_t di_size;if (dip->di_magic !=cpu_to_be16 (XFS_DINODE_MAGIC ))return __this_address;
@@ -407,7 +408,8 @@ xfs_dinode_verify( }/* don't allow invalid i_size */ -if (be64_to_cpu (dip->di_size) & (1ULL <<63 )) + di_size =be64_to_cpu (dip->di_size); +if (di_size & (1ULL <<63 ))return __this_address; mode =be16_to_cpu (dip->di_mode);
@@ -415,14 +417,74 @@ xfs_dinode_verify(return __this_address;/* No zero-length symlinks/dirs. */ -if ((S_ISLNK (mode) ||S_ISDIR (mode)) && dip->di_size ==0 ) +if ((S_ISLNK (mode) ||S_ISDIR (mode)) && di_size ==0 )return __this_address; +/* Fork checks carried over from xfs_iformat_fork */ +if (mode && +be32_to_cpu (dip->di_nextents) +be16_to_cpu (dip->di_anextents) > +be64_to_cpu (dip->di_nblocks)) +return __this_address; + +if (mode && dip->di_forkoff > mp->m_sb.sb_inodesize) +return __this_address; + + flags =be16_to_cpu (dip->di_flags); + +if (mode && (flags &XFS_DIFLAG_REALTIME ) && !mp->m_rtdev_targp) +return __this_address; + +/* Do we have appropriate data fork formats for the mode? */ +switch (mode &S_IFMT ) { +case S_IFIFO : +case S_IFCHR : +case S_IFBLK : +case S_IFSOCK : +if (dip->di_format !=XFS_DINODE_FMT_DEV ) +return __this_address; +break ; +case S_IFREG : +case S_IFLNK : +case S_IFDIR : +switch (dip->di_format) { +case XFS_DINODE_FMT_LOCAL : +/* +* no local regular files yet +*/ +if (S_ISREG (mode)) +return __this_address; +if (di_size >XFS_DFORK_DSIZE (dip, mp)) +return __this_address; +/* fall through */ +case XFS_DINODE_FMT_EXTENTS : +case XFS_DINODE_FMT_BTREE : +break ; +default : +return __this_address; + } +break ; +case 0 : +/* Uninitialized inode ok. */ +break ; +default : +return __this_address; + } + +if (XFS_DFORK_Q (dip)) { +switch (dip->di_aformat) { +case XFS_DINODE_FMT_LOCAL : +case XFS_DINODE_FMT_EXTENTS : +case XFS_DINODE_FMT_BTREE : +break ; +default : +return __this_address; + } + } +/* only version 3 or greater inodes are extensively verified here */ if (dip->di_version <3 )return NULL ; - flags =be16_to_cpu (dip->di_flags); flags2 =be64_to_cpu (dip->di_flags2);/* don't allow reflink/cowextsize if we don't have reflink */
fs/xfs/libxfs/xfs_inode_fork.c +0 -99
134 lines not on this page · raw message
PATCH 7/12 xfs: create structure verifier function for shortform xattrs
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a function to perform structure verification for short form extended attributes.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 70 +++++++++++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_attr_leaf.h | 1 + 2 files changed, 71 insertions(+)
fs/xfs/libxfs/xfs_attr_leaf.c +70 -0
@@ -873,6 +873,76 @@ xfs_attr_shortform_allfit(return xfs_attr_shortform_bytesfit (dp, bytes); } +/* Verify the consistency of an inline attribute fork. */ +void * +xfs_attr_shortform_verify ( +struct xfs_inode *ip) +{ +struct xfs_attr_shortform *sfp; +struct xfs_attr_sf_entry *sfep; +struct xfs_attr_sf_entry *next_sfep; +char *endp; +struct xfs_ifork *ifp; +int i; +int size; + +ASSERT (ip->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ); + ifp =XFS_IFORK_PTR (ip,XFS_ATTR_FORK ); + sfp = (struct xfs_attr_shortform *)ifp->if_u1.if_data; + size = ifp->if_bytes; + +/* +* Give up if the attribute is way too short. +*/ +if (size <sizeof (struct xfs_attr_sf_hdr )) +return __this_address; + + endp = (char *)sfp + size; + +/* Check all reported entries */ + sfep = &sfp->list[0 ]; +for (i =0 ; i < sfp->hdr.count; i++) { +/* +* struct xfs_attr_sf_entry has a variable length. +* Check the fixed-offset parts of the structure are +* within the data buffer. +*/ +if (((char *)sfep +sizeof (*sfep)) >= endp) +return __this_address; + +/* Don't allow names with known bad length. */ +if (sfep->namelen ==0 ) +return __this_address; + +/* +* Check that the variable-length part of the structure is +* within the data buffer. The next entry starts after the +* name component, so nextentry is an acceptable test. +*/ + next_sfep =XFS_ATTR_SF_NEXTENTRY (sfep); +if ((char *)next_sfep > endp) +return __this_address; + +/* +* Check for unknown flags. Short form doesn't support +* the incomplete or local bits. +*/ +if (sfep->flags & ~(XFS_ATTR_ROOT |XFS_ATTR_SECURE )) +return __this_address; + +/* Check for invalid namespace combinations. */ +if ((sfep->flags &XFS_ATTR_ROOT ) && + (sfep->flags &XFS_ATTR_SECURE )) +return __this_address; + + sfep = next_sfep; + } +if ((void *)sfep != (void *)endp) +return __this_address; + +return NULL ; +} +/* * Convert a leaf attribute list to shortform attribute list */
fs/xfs/libxfs/xfs_attr_leaf.h +1 -0
@@ -52,6 +52,7 @@ int xfs_attr_shortform_to_leaf(struct xfs_da_args *args);int xfs_attr_shortform_remove (struct xfs_da_args *args);int xfs_attr_shortform_allfit (struct xfs_buf *bp,struct xfs_inode *dp);int xfs_attr_shortform_bytesfit (struct xfs_inode *dp,int bytes); +void *xfs_attr_shortform_verify (struct xfs_inode *ip);void xfs_attr_fork_remove (struct xfs_inode *ip,struct xfs_trans *tp);/*
PATCH 8/12 xfs: create structure verifier function for short form symlinks
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Create a function to check the structure of short form symlink targets.
--- fs/xfs/libxfs/xfs_shared.h | 1 + fs/xfs/libxfs/xfs_symlink_remote.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
fs/xfs/libxfs/xfs_shared.h +1 -0
@@ -143,5 +143,6 @@ bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset, uint32_t size, struct xfs_buf *bp);void xfs_symlink_local_to_remote (struct xfs_trans *tp,struct xfs_buf *bp,struct xfs_inode *ip,struct xfs_ifork *ifp); +void *xfs_symlink_shortform_verify (struct xfs_inode *ip);#endif /* __XFS_SHARED_H__ */
fs/xfs/libxfs/xfs_symlink_remote.c +36 -0
@@ -209,3 +209,39 @@ xfs_symlink_local_to_remote(xfs_trans_log_buf (tp, bp,0 ,sizeof (struct xfs_dsymlink_hdr ) + ifp->if_bytes -1 ); } + +/* Verify the consistency of an inline symlink. */ +void * +xfs_symlink_shortform_verify ( +struct xfs_inode *ip) +{ +char *sfp; +char *endp; +struct xfs_ifork *ifp; +int size; + +ASSERT (ip->i_d.di_format ==XFS_DINODE_FMT_LOCAL ); + ifp =XFS_IFORK_PTR (ip,XFS_DATA_FORK ); + sfp = (char *)ifp->if_u1.if_data; + size = ifp->if_bytes; + endp = sfp + size; + +/* Zero length symlinks can exist while we're deleting a remote one. */ +if (size ==0 ) +return NULL ; + +/* No negative sizes or overly long symlink targets. */ +if (size <0 || size >XFS_SYMLINK_MAXLEN ) +return __this_address; + +/* No NULLs in the target either. */ +for (; sfp < endp; sfp++) { +if (*sfp ==0 ) +return __this_address; + } + +/* We /did/ null-terminate the buffer, right? */ +if (*endp !=0 ) +return __this_address; +return NULL ; +}
PATCH 9/12 xfs: refactor short form directory structure verifier function
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Change the short form directory structure verifier function to return the instruction pointer of a failing check or NULL if everything's ok.
--- fs/xfs/libxfs/xfs_dir2_priv.h | 2 +- fs/xfs/libxfs/xfs_dir2_sf.c | 26 +++++++++++++------------- fs/xfs/libxfs/xfs_inode_fork.c | 5 ++--- 3 files changed, 16 insertions(+), 17 deletions(-)
fs/xfs/libxfs/xfs_dir2_priv.h +1 -1
@@ -133,7 +133,7 @@ extern int xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);extern int xfs_dir2_sf_lookup (struct xfs_da_args *args);extern int xfs_dir2_sf_removename (struct xfs_da_args *args);extern int xfs_dir2_sf_replace (struct xfs_da_args *args); -extern int xfs_dir2_sf_verify (struct xfs_inode *ip); +extern void *xfs_dir2_sf_verify (struct xfs_inode *ip);/* xfs_dir2_readdir.c */ extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp,
fs/xfs/libxfs/xfs_dir2_sf.c +13 -13
@@ -630,7 +630,7 @@ xfs_dir2_sf_check(#endif /* DEBUG */ /* Verify the consistency of an inline directory. */ -int +void *xfs_dir2_sf_verify (struct xfs_inode *ip) {
@@ -665,7 +665,7 @@ xfs_dir2_sf_verify(*/ if (size <= offsetof(struct xfs_dir2_sf_hdr , parent) || size <xfs_dir2_sf_hdr_size (sfp->i8count)) -return -EFSCORRUPTED ; +return __this_address; endp = (char *)sfp + size;
@@ -674,7 +674,7 @@ xfs_dir2_sf_verify( i8count = ino >XFS_DIR2_MAX_SHORT_INUM ; error =xfs_dir_ino_validate (mp, ino);if (error) -return error; +return __this_address; offset = dops->data_first_offset;/* Check all reported entries */
@@ -686,11 +686,11 @@ xfs_dir2_sf_verify(* within the data buffer. */ if (((char *)sfep +sizeof (*sfep)) >= endp) -return -EFSCORRUPTED ; +return __this_address;/* Don't allow names with known bad length. */ if (sfep->namelen ==0 ) -return -EFSCORRUPTED ; +return __this_address;/* * Check that the variable-length part of the structure is
@@ -699,23 +699,23 @@ xfs_dir2_sf_verify(*/ next_sfep = dops->sf_nextentry (sfp, sfep);if (endp < (char *)next_sfep) -return -EFSCORRUPTED ; +return __this_address;/* Check that the offsets always increase. */ if (xfs_dir2_sf_get_offset (sfep) < offset) -return -EFSCORRUPTED ; +return __this_address;/* Check the inode number. */ ino = dops->sf_get_ino (sfp, sfep); i8count += ino >XFS_DIR2_MAX_SHORT_INUM ; error =xfs_dir_ino_validate (mp, ino);if (error) -return error; +return __this_address;/* Check the file type. */ filetype = dops->sf_get_ftype (sfep);if (filetype >=XFS_DIR3_FT_MAX ) -return -EFSCORRUPTED ; +return __this_address; offset =xfs_dir2_sf_get_offset (sfep) + dops->data_entsize (sfep->namelen);
@@ -723,16 +723,16 @@ xfs_dir2_sf_verify( sfep = next_sfep; }if (i8count != sfp->i8count) -return -EFSCORRUPTED ; +return __this_address;if ((void *)sfep != (void *)endp) -return -EFSCORRUPTED ; +return __this_address;/* Make sure this whole thing ought to be in local format. */ if (offset + (sfp->count +2 ) * (uint )sizeof (xfs_dir2_leaf_entry_t) + (uint )sizeof (xfs_dir2_block_tail_t) > mp->m_dir_geo->blksize) -return -EFSCORRUPTED ; +return __this_address; -return 0 ; +return NULL ; }/*
fs/xfs/libxfs/xfs_inode_fork.c +2 -3
@@ -99,10 +99,9 @@ xfs_iformat_fork(/* Check inline dir contents. */ if (S_ISDIR (VFS_I (ip)->i_mode) && dip->di_format ==XFS_DINODE_FMT_LOCAL ) { - error =xfs_dir2_sf_verify (ip); -if (error) { +if (xfs_dir2_sf_verify (ip)) {xfs_idestroy_fork (ip,XFS_DATA_FORK ); -return error; +return -EFSCORRUPTED ; } }
PATCH 10/12 xfs: provide a centralized method for verifying inline fork data
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Replace the current haphazard dir2 shortform verifier callsites with a centralized verifier function that can be called either with the default verifier functions or with a custom set. This helps us strengthen integrity checking while providing us with flexibility for repair tools.
xfs_repair wants this to be able to supply its own verifier functions when trying to fix possibly corrupt metadata.
--- fs/xfs/libxfs/xfs_inode_fork.c | 62 ++++++++++++++++++++++++++++++++++------ fs/xfs/libxfs/xfs_inode_fork.h | 12 ++++++++ fs/xfs/xfs_icache.c | 6 +++- fs/xfs/xfs_inode.c | 34 +++++++++++++++++++--- fs/xfs/xfs_inode.h | 2 + fs/xfs/xfs_log_recover.c | 4 +++ 6 files changed, 106 insertions(+), 14 deletions(-)
fs/xfs/libxfs/xfs_inode_fork.c +53 -9
@@ -35,6 +35,8 @@#include "xfs_da_format.h" #include "xfs_da_btree.h" #include "xfs_dir2_priv.h" +#include "xfs_attr_leaf.h" +#include "xfs_shared.h" kmem_zone_t *xfs_ifork_zone;
@@ -96,15 +98,6 @@ xfs_iformat_fork(if (error)return error; -/* Check inline dir contents. */ -if (S_ISDIR (VFS_I (ip)->i_mode) && - dip->di_format ==XFS_DINODE_FMT_LOCAL ) { -if (xfs_dir2_sf_verify (ip)) { -xfs_idestroy_fork (ip,XFS_DATA_FORK ); -return -EFSCORRUPTED ; - } - } -if (xfs_is_reflink_inode (ip)) {ASSERT (ip->i_cowfp ==NULL );xfs_ifork_init_cow (ip);
@@ -1923,3 +1916,54 @@ xfs_iext_get_extent(xfs_bmbt_get_all (xfs_iext_get_ext (ifp, idx), gotp);return true; } + +/* Default fork content verifiers. */ +struct xfs_ifork_ops xfs_default_ifork_ops = { + .verify_attr = xfs_attr_shortform_verify, + .verify_dir = xfs_dir2_sf_verify, + .verify_symlink = xfs_symlink_shortform_verify, +}; + +/* Verify the inline contents of the data fork of an inode. */ +void * +xfs_ifork_verify_data ( +struct xfs_inode *ip, +struct xfs_ifork_ops *ops) +{ +xfs_ifork_verifier_t fn =NULL ; + +/* Non-local data fork, we're done. */ +if (ip->i_d.di_format !=XFS_DINODE_FMT_LOCAL ) +return NULL ; + +/* Check the inline data fork if there is one. */ +if (S_ISDIR (VFS_I (ip)->i_mode)) + fn = ops->verify_dir; +else if (S_ISLNK (VFS_I (ip)->i_mode)) + fn = ops->verify_symlink; + +if (fn) +return fn (ip); +return NULL ; +} + +/* Verify the inline contents of the attr fork of an inode. */ +void * +xfs_ifork_verify_attr ( +struct xfs_inode *ip, +struct xfs_ifork_ops *ops) +{ +xfs_ifork_verifier_t fn =NULL ; + +/* There has to be an attr fork allocated if aformat is local. */ +if (ip->i_d.di_aformat ==XFS_DINODE_FMT_LOCAL ) { +if (XFS_IFORK_PTR (ip,XFS_ATTR_FORK )) + fn = ops->verify_attr; +else +return __this_address; + } + +if (fn) +return fn (ip); +return NULL ; +}
fs/xfs/libxfs/xfs_inode_fork.h +12 -0
@@ -192,4 +192,16 @@ extern struct kmem_zone *xfs_ifork_zone;extern void xfs_ifork_init_cow (struct xfs_inode *ip); +typedef void *(*xfs_ifork_verifier_t )(struct xfs_inode *); + +struct xfs_ifork_ops { +xfs_ifork_verifier_t verify_symlink; +xfs_ifork_verifier_t verify_dir; +xfs_ifork_verifier_t verify_attr; +}; +extern struct xfs_ifork_ops xfs_default_ifork_ops; + +void *xfs_ifork_verify_data (struct xfs_inode *ip,struct xfs_ifork_ops *ops); +void *xfs_ifork_verify_attr (struct xfs_inode *ip,struct xfs_ifork_ops *ops); +#endif /* __XFS_INODE_FORK_H__ */
fs/xfs/xfs_icache.c +5 -1
@@ -449,7 +449,6 @@ xfs_iget_cache_hit(return error; } - static int xfs_iget_cache_miss( struct xfs_mount *mp,
@@ -473,6 +472,11 @@ xfs_iget_cache_miss(if (error) goto out_destroy; +if (!xfs_inode_verify_forks (ip)) { + error = -EFSCORRUPTED ; + goto out_destroy; + } +trace_xfs_iget_miss (ip);if ((VFS_I (ip)->i_mode ==0 ) && !(flags &XFS_IGET_CREATE )) {
fs/xfs/xfs_inode.c +30 -4
@@ -3471,6 +3471,34 @@ xfs_iflush(return error; } +/* +* If there are inline format data / attr forks attached to this inode, +* make sure they're not corrupt. +*/ +bool +xfs_inode_verify_forks ( +struct xfs_inode *ip) +{ +void *failed_at; + + failed_at =xfs_ifork_verify_data (ip, &xfs_default_ifork_ops); +if (failed_at) { +xfs_alert (ip->i_mount, +"%s: bad inode %llu inline data fork at %pF" , + __func__, ip->i_ino, failed_at); +return false; + } + + failed_at =xfs_ifork_verify_attr (ip, &xfs_default_ifork_ops); +if (failed_at) { +xfs_alert (ip->i_mount, +"%s: bad inode %llu inline attr fork at %pF" , + __func__, ip->i_ino, failed_at); +return false; + } +return true; +} + STATIC int xfs_iflush_int( struct xfs_inode *ip,
@@ -3549,10 +3577,8 @@ xfs_iflush_int(if (ip->i_d.di_version <3 ) ip->i_d.di_flushiter++; -/* Check the inline directory data. */ -if (S_ISDIR (VFS_I (ip)->i_mode) && - ip->i_d.di_format ==XFS_DINODE_FMT_LOCAL && -xfs_dir2_sf_verify (ip)) +/* Check the inline fork data before we write out. */ +if (!xfs_inode_verify_forks (ip)) goto corrupt_out;/*
fs/xfs/xfs_inode.h +2 -0
@@ -490,4 +490,6 @@ extern struct kmem_zone *xfs_inode_zone;/* The default CoW extent size hint. */ #define XFS_DEFAULT_COWEXTSZ_HINT 32 +bool xfs_inode_verify_forks (struct xfs_inode *ip); +#endif /* __XFS_INODE_H__ */
fs/xfs/xfs_log_recover.c +4 -0
@@ -2920,6 +2920,10 @@ xfs_recover_inode_owner_change(if (error) goto out_free_ip; +if (!xfs_inode_verify_forks (ip)) { + error = -EFSCORRUPTED ; + goto out_free_ip; + }if (in_f->ilf_fields &XFS_ILOG_DOWNER ) {ASSERT (in_f->ilf_fields &XFS_ILOG_DBROOT );
PATCH 11/12 xfs: fail out of xfs_attr3_leaf_lookup_int if it looks corrupt
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If the xattr leaf block looks corrupt, return -EFSCORRUPTED to userspace instead of ASSERTing on debug kernels or running off the end of the buffer on regular kernels.
--- fs/xfs/libxfs/xfs_attr_leaf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/xfs/libxfs/xfs_attr_leaf.c +6 -3
@@ -2246,7 +2246,8 @@ xfs_attr3_leaf_lookup_int( leaf = bp->b_addr;xfs_attr3_leaf_hdr_from_disk (args->geo, &ichdr, leaf); entries =xfs_attr3_leaf_entryp (leaf); -ASSERT (ichdr.count < args->geo->blksize /8 ); +if (ichdr.count >= args->geo->blksize /8 ) +return -EFSCORRUPTED ;/* * Binary search. (note: small blocks will skip this loop)
@@ -2262,8 +2263,10 @@ xfs_attr3_leaf_lookup_int(else break ; } -ASSERT (probe >=0 && (!ichdr.count || probe < ichdr.count)); -ASSERT (span <=4 ||be32_to_cpu (entry->hashval) == hashval); +if (!(probe >=0 && (!ichdr.count || probe < ichdr.count))) +return -EFSCORRUPTED ; +if (!(span <=4 ||be32_to_cpu (entry->hashval) == hashval)) +return -EFSCORRUPTED ;/* * Since we may have duplicate hashval's, find the first matching
PATCH 12/12 xfs: create a new buf_ops pointer to verify structure metadata
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Expose all metadata structure buffer verifier functions via buf_ops. These will be used by the online scrub mechanism to look for problems with buffers that are already sitting around in memory.
--- fs/xfs/libxfs/xfs_alloc.c | 14 ++++++++------ fs/xfs/libxfs/xfs_alloc_btree.c | 1 + fs/xfs/libxfs/xfs_attr_leaf.c | 1 + fs/xfs/libxfs/xfs_attr_remote.c | 32 ++++++++++++++++++++++++++++++++ fs/xfs/libxfs/xfs_bmap_btree.c | 1 + fs/xfs/libxfs/xfs_da_btree.c | 25 +++++++++++++++++++++++++ fs/xfs/libxfs/xfs_dir2_block.c | 1 + fs/xfs/libxfs/xfs_dir2_data.c | 1 + fs/xfs/libxfs/xfs_dir2_leaf.c | 16 ++++++++++++++++ fs/xfs/libxfs/xfs_dir2_node.c | 1 + fs/xfs/libxfs/xfs_dquot_buf.c | 12 ++++++++++++ fs/xfs/libxfs/xfs_ialloc.c | 1 + fs/xfs/libxfs/xfs_ialloc_btree.c | 1 + fs/xfs/libxfs/xfs_refcount_btree.c | 1 + fs/xfs/libxfs/xfs_rmap_btree.c | 1 + fs/xfs/libxfs/xfs_symlink_remote.c | 1 + fs/xfs/xfs_buf.h | 1 + 17 files changed, 105 insertions(+), 6 deletions(-)
fs/xfs/libxfs/xfs_alloc.c +8 -6
@@ -604,6 +604,7 @@ const struct xfs_buf_ops xfs_agfl_buf_ops = { .name = "xfs_agfl", .verify_read = xfs_agfl_read_verify, .verify_write = xfs_agfl_write_verify, + .verify_struct = xfs_agfl_verify, };/*
@@ -2393,10 +2394,10 @@ xfs_alloc_put_freelist(static void *xfs_agf_verify ( -struct xfs_mount *mp, -struct xfs_buf *bp) - { -struct xfs_agf *agf =XFS_BUF_TO_AGF (bp); +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; +struct xfs_agf *agf =XFS_BUF_TO_AGF (bp);if (xfs_sb_version_hascrc (&mp->m_sb)) {if (!uuid_equal (&agf->agf_uuid, &mp->m_sb.sb_meta_uuid))
@@ -2457,7 +2458,7 @@ xfs_agf_read_verify(if (xfs_sb_version_hascrc (&mp->m_sb) && !xfs_buf_verify_cksum (bp,XFS_AGF_CRC_OFF ))xfs_buf_ioerror (bp, -EFSBADCRC ); -else if (XFS_TEST_ERROR ((failed_at =xfs_agf_verify (mp, bp)), mp, +else if (XFS_TEST_ERROR ((failed_at =xfs_agf_verify (bp)), mp,XFS_ERRTAG_ALLOC_READ_AGF ))xfs_buf_ioerror (bp, -EFSCORRUPTED );
@@ -2473,7 +2474,7 @@ xfs_agf_write_verify(struct xfs_buf_log_item *bip = bp->b_fspriv;void *failed_at; -if ((failed_at =xfs_agf_verify (mp, bp))) { +if ((failed_at =xfs_agf_verify (bp))) {xfs_buf_ioerror (bp, -EFSCORRUPTED );xfs_verifier_error (bp, failed_at);return ;
@@ -2492,6 +2493,7 @@ const struct xfs_buf_ops xfs_agf_buf_ops = { .name = "xfs_agf", .verify_read = xfs_agf_read_verify, .verify_write = xfs_agf_write_verify, + .verify_struct = xfs_agf_verify, };/*
fs/xfs/libxfs/xfs_alloc_btree.c +1 -0
@@ -397,6 +397,7 @@ const struct xfs_buf_ops xfs_allocbt_buf_ops = { .name = "xfs_allocbt", .verify_read = xfs_allocbt_read_verify, .verify_write = xfs_allocbt_write_verify, + .verify_struct = xfs_allocbt_verify, };
fs/xfs/libxfs/xfs_attr_leaf.c +1 -0
@@ -339,6 +339,7 @@ const struct xfs_buf_ops xfs_attr3_leaf_buf_ops = { .name = "xfs_attr3_leaf", .verify_read = xfs_attr3_leaf_read_verify, .verify_write = xfs_attr3_leaf_write_verify, + .verify_struct = xfs_attr3_leaf_verify, };int
fs/xfs/libxfs/xfs_attr_remote.c +32 -0
@@ -203,10 +203,42 @@ xfs_attr3_rmt_write_verify(ASSERT (len ==0 ); } +static void * +xfs_attr3_rmt_verify_struct ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; +char *ptr; +void *failed_at; +int len; +xfs_daddr_t bno; +int blksize = mp->m_attr_geo->blksize; + +/* no verification of non-crc buffers */ +if (!xfs_sb_version_hascrc (&mp->m_sb)) +return NULL ; + + ptr = bp->b_addr; + bno = bp->b_bn; + len =BBTOB (bp->b_length); +ASSERT (len >= blksize); + +while (len >0 ) { +if ((failed_at =xfs_attr3_rmt_verify (mp, ptr, blksize, bno))) +return failed_at; + len -= blksize; + ptr += blksize; + bno +=BTOBB (blksize); + } + +return NULL ; +} +const struct xfs_buf_ops xfs_attr3_rmt_buf_ops = { .name ="xfs_attr3_rmt" , .verify_read = xfs_attr3_rmt_read_verify, .verify_write = xfs_attr3_rmt_write_verify, + .verify_struct = xfs_attr3_rmt_verify_struct, };STATIC int
fs/xfs/libxfs/xfs_bmap_btree.c +1 -0
@@ -692,6 +692,7 @@ const struct xfs_buf_ops xfs_bmbt_buf_ops = { .name = "xfs_bmbt", .verify_read = xfs_bmbt_read_verify, .verify_write = xfs_bmbt_write_verify, + .verify_struct = xfs_bmbt_verify, };
fs/xfs/libxfs/xfs_da_btree.c +25 -0
@@ -247,10 +247,35 @@ xfs_da3_node_read_verify(xfs_verifier_error (bp, failed_at); } +/* Verify the structure of a da3 block. */ +static void * +xfs_da3_node_verify_struct ( +struct xfs_buf *bp) +{ +struct xfs_da_blkinfo *info = bp->b_addr; + +switch (be16_to_cpu (info->magic)) { +case XFS_DA3_NODE_MAGIC : +case XFS_DA_NODE_MAGIC : +return xfs_da3_node_verify (bp); +case XFS_ATTR_LEAF_MAGIC : +case XFS_ATTR3_LEAF_MAGIC : + bp->b_ops = &xfs_attr3_leaf_buf_ops; +return bp->b_ops->verify_struct (bp); +case XFS_DIR2_LEAFN_MAGIC : +case XFS_DIR3_LEAFN_MAGIC : + bp->b_ops = &xfs_dir3_leafn_buf_ops; +return bp->b_ops->verify_struct (bp); +default : +return __this_address; + } +} +const struct xfs_buf_ops xfs_da3_node_buf_ops = { .name ="xfs_da3_node" , .verify_read = xfs_da3_node_read_verify, .verify_write = xfs_da3_node_write_verify, + .verify_struct = xfs_da3_node_verify_struct, };int
fs/xfs/libxfs/xfs_dir2_block.c +1 -0
@@ -126,6 +126,7 @@ const struct xfs_buf_ops xfs_dir3_block_buf_ops = { .name = "xfs_dir3_block", .verify_read = xfs_dir3_block_read_verify, .verify_write = xfs_dir3_block_write_verify, + .verify_struct = xfs_dir3_block_verify, };int
fs/xfs/libxfs/xfs_dir2_data.c +1 -0
@@ -318,6 +318,7 @@ const struct xfs_buf_ops xfs_dir3_data_buf_ops = { .name = "xfs_dir3_data", .verify_read = xfs_dir3_data_read_verify, .verify_write = xfs_dir3_data_write_verify, + .verify_struct = xfs_dir3_data_verify, };static const struct xfs_buf_ops xfs_dir3_data_reada_buf_ops = {
fs/xfs/libxfs/xfs_dir2_leaf.c +16 -0
@@ -218,6 +218,13 @@ __write_verify(xfs_buf_update_cksum (bp,XFS_DIR3_LEAF_CRC_OFF ); } +static void * +xfs_dir3_leaf1_verify ( +struct xfs_buf *bp) +{ +return xfs_dir3_leaf_verify (bp,XFS_DIR2_LEAF1_MAGIC ); +} +static void xfs_dir3_leaf1_read_verify (struct xfs_buf *bp)
@@ -232,6 +239,13 @@ xfs_dir3_leaf1_write_verify(__write_verify (bp,XFS_DIR2_LEAF1_MAGIC ); } +static void * +xfs_dir3_leafn_verify ( +struct xfs_buf *bp) +{ +return xfs_dir3_leaf_verify (bp,XFS_DIR2_LEAFN_MAGIC ); +} +static void xfs_dir3_leafn_read_verify (struct xfs_buf *bp)
@@ -250,12 +264,14 @@ const struct xfs_buf_ops xfs_dir3_leaf1_buf_ops = { .name = "xfs_dir3_leaf1", .verify_read = xfs_dir3_leaf1_read_verify, .verify_write = xfs_dir3_leaf1_write_verify, + .verify_struct = xfs_dir3_leaf1_verify, };const struct xfs_buf_ops xfs_dir3_leafn_buf_ops = { .name ="xfs_dir3_leafn" , .verify_read = xfs_dir3_leafn_read_verify, .verify_write = xfs_dir3_leafn_write_verify, + .verify_struct = xfs_dir3_leafn_verify, };int
fs/xfs/libxfs/xfs_dir2_node.c +1 -0
@@ -155,6 +155,7 @@ const struct xfs_buf_ops xfs_dir3_free_buf_ops = { .name = "xfs_dir3_free", .verify_read = xfs_dir3_free_read_verify, .verify_write = xfs_dir3_free_write_verify, + .verify_struct = xfs_dir3_free_verify, };/* Everything ok in the free block header? */
fs/xfs/libxfs/xfs_dquot_buf.c +12 -0
@@ -242,6 +242,17 @@ xfs_dquot_buf_verify(return true; } +static void * +xfs_dquot_buf_verify_struct ( +struct xfs_buf *bp) +{ +struct xfs_mount *mp = bp->b_target->bt_mount; + +if (!xfs_dquot_buf_verify (mp, bp,0 )) +return __this_address; +return NULL ; +} +static void xfs_dquot_buf_read_verify (struct xfs_buf *bp)
@@ -298,6 +309,7 @@ const struct xfs_buf_ops xfs_dquot_buf_ops = { .name = "xfs_dquot", .verify_read = xfs_dquot_buf_read_verify, .verify_write = xfs_dquot_buf_write_verify, + .verify_struct = xfs_dquot_buf_verify_struct, };const struct xfs_buf_ops xfs_dquot_buf_ra_ops = {
fs/xfs/libxfs/xfs_ialloc.c +1 -0
@@ -2586,6 +2586,7 @@ const struct xfs_buf_ops xfs_agi_buf_ops = { .name = "xfs_agi", .verify_read = xfs_agi_read_verify, .verify_write = xfs_agi_write_verify, + .verify_struct = xfs_agi_verify, };/*
fs/xfs/libxfs/xfs_ialloc_btree.c +1 -0
@@ -327,6 +327,7 @@ const struct xfs_buf_ops xfs_inobt_buf_ops = { .name = "xfs_inobt", .verify_read = xfs_inobt_read_verify, .verify_write = xfs_inobt_write_verify, + .verify_struct = xfs_inobt_verify, };STATIC int
fs/xfs/libxfs/xfs_refcount_btree.c +1 -0
@@ -288,6 +288,7 @@ const struct xfs_buf_ops xfs_refcountbt_buf_ops = { .name = "xfs_refcountbt", .verify_read = xfs_refcountbt_read_verify, .verify_write = xfs_refcountbt_write_verify, + .verify_struct = xfs_refcountbt_verify, };STATIC int
fs/xfs/libxfs/xfs_rmap_btree.c +1 -0
@@ -380,6 +380,7 @@ const struct xfs_buf_ops xfs_rmapbt_buf_ops = { .name = "xfs_rmapbt", .verify_read = xfs_rmapbt_read_verify, .verify_write = xfs_rmapbt_write_verify, + .verify_struct = xfs_rmapbt_verify, };STATIC int
fs/xfs/libxfs/xfs_symlink_remote.c +1 -0
@@ -173,6 +173,7 @@ const struct xfs_buf_ops xfs_symlink_buf_ops = { .name = "xfs_symlink", .verify_read = xfs_symlink_read_verify, .verify_write = xfs_symlink_write_verify, + .verify_struct = xfs_symlink_verify, };void
fs/xfs/xfs_buf.h +1 -0
@@ -139,6 +139,7 @@ struct xfs_buf_ops {char *name;void (*verify_read)(struct xfs_buf *);void (*verify_write)(struct xfs_buf *); +void *(*verify_struct)(struct xfs_buf *); }; typedef struct xfs_buf {
Quoted 11 lines · Darrick J. Wong
Hi all,
This RFC combines all the random little fixes and improvements to the verifiers that we've been talking about for the past month or so into a single patch series!
We start by refactoring the long format btree block header verifier into a single helper functionn and de-macroing dir block verifiers to make them less shouty. Next, we change verifier functions to return the approximate instruction pointer of the faulting test so that we can report more precise fault information to dmesg/tracepoints.
Just jumping here quickly because I don't have time for a detailed review:
How good does this instruction pointer thing resolved to the actual issue? I'm currently watching a customer issue where a write verifier triggers, and I gave them a patch to add a debug print to every failing statement, including printing out the mismatch values if it's not simply a binary comparism. I though about preparing that patch as well as others for mainline. Here is the one I have at the moment:
---
Quoted 1 line
From
6c5e2efc6f857228461d439feb3c98be58fb9744Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <[email protected]>
Date: Sat, 5 Aug 2017 16:34:15 +0200
Subject: xfs: print verbose information on dir leaf verifier failures
--- fs/xfs/libxfs/xfs_dir2_leaf.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)
fs/xfs/libxfs/xfs_dir2_leaf.c +26 -7
@@ -113,27 +113,37 @@ xfs_dir3_leaf_check_int(* Should factor in the size of the bests table as well. * We can deduce a value for that from di_size. */ -if (hdr->count > ops->leaf_max_ents (geo)) +if (hdr->count > ops->leaf_max_ents (geo)) { +xfs_warn (mp,"count (%d) above max (%d)\n" , + hdr->count, ops->leaf_max_ents (geo));return false; + }/* Leaves and bests don't overlap in leaf format. */ if ((hdr->magic ==XFS_DIR2_LEAF1_MAGIC || hdr->magic ==XFS_DIR3_LEAF1_MAGIC ) && - (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) + (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) { +xfs_warn (mp,"ents overlappings bests\n" );return false; + }/* Check hash value order, count stale entries. */ for (i = stale =0 ; i < hdr->count; i++) {if (i +1 < hdr->count) {if (be32_to_cpu (ents[i].hashval) > -be32_to_cpu (ents[i +1 ].hashval)) +be32_to_cpu (ents[i +1 ].hashval)) { +xfs_warn (mp,"broken hash order\n" );return false; + } }if (ents[i].address ==cpu_to_be32 (XFS_DIR2_NULL_DATAPTR )) stale++; } -if (hdr->stale != stale) +if (hdr->stale != stale) { +xfs_warn (mp,"incorrect stalte count (%d, expected %d)\n" , + hdr->stale, stale);return false; + }return true; }
@@ -159,12 +169,21 @@ xfs_dir3_leaf_verify( magic3 = (magic ==XFS_DIR2_LEAF1_MAGIC ) ?XFS_DIR3_LEAF1_MAGIC :XFS_DIR3_LEAFN_MAGIC ; -if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) +if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) { +xfs_warn (mp,"incorrect magic number (0x%hx, expected 0x%hx)\n" , + leaf3->info.hdr.magic, magic3);return false; -if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) + } +if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) { +xfs_warn (mp,"incorrect uuid, (%pUb, expected %pUb)\n" , + &leaf3->info.uuid, &mp->m_sb.sb_meta_uuid);return false; -if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) + } +if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) { +xfs_warn (mp,"incorrect blkno, (%lld, expected %lld)\n" , +be64_to_cpu (leaf3->info.blkno), bp->b_bn);return false; + }if (!xfs_log_check_lsn (mp,be64_to_cpu (leaf3->info.lsn)))return false; }else {
Signature · 1 line
2.11.0
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Darrick J. Wong
Hi all,
This RFC combines all the random little fixes and improvements to the verifiers that we've been talking about for the past month or so into a single patch series!
We start by refactoring the long format btree block header verifier into a single helper functionn and de-macroing dir block verifiers to make them less shouty. Next, we change verifier functions to return the approximate instruction pointer of the faulting test so that we can report more precise fault information to dmesg/tracepoints.
Quoted 5 lines
Just jumping here quickly because I don't have time for a detailed review:
How good does this instruction pointer thing resolved to the actual issue?
Ugh, it's terrible once you turn on the optimizer.
if (!xfs_sb_version_hascrc(&mp->m_sb))
return __this_address;
if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
return __this_address;
if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn))
return __this_address;
if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
return __this_address;
return NULL; becomes:
if (!xfs_sb_version_hascrc(&mp->m_sb))
goto out;
if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
goto out;
if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn))
goto out;
if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
goto out;
return NULL;
out:
return __this_address;...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
--D
Quoted 95 lines
I'm currently watching a customer issue where a write verifier triggers, and I gave them a patch to add a debug print to every failing statement, including printing out the mismatch values if it's not simply a binary comparism. I though about preparing that patch as well as others for mainline. Here is the one I have at the moment:
---
From6c5e2efc6f857228461d439feb3c98be58fb9744Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <[email protected]>
Date: Sat, 5 Aug 2017 16:34:15 +0200
Subject: xfs: print verbose information on dir leaf verifier failuresSigned-off-by Christoph Hellwig <[email protected]>--- fs/xfs/libxfs/xfs_dir2_leaf.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)fs/xfs/libxfs/xfs_dir2_leaf.c +26
-7@@ -113,27 +113,37 @@ xfs_dir3_leaf_check_int(* Should factor in the size of the bests table as well. * We can deduce a value for that from di_size. */ -if (hdr->count > ops->leaf_max_ents (geo)) +if (hdr->count > ops->leaf_max_ents (geo)) { +xfs_warn (mp,"count (%d) above max (%d)\n" , + hdr->count, ops->leaf_max_ents (geo));return false; + }/* Leaves and bests don't overlap in leaf format. */ if ((hdr->magic ==XFS_DIR2_LEAF1_MAGIC || hdr->magic ==XFS_DIR3_LEAF1_MAGIC ) && - (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) + (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) { +xfs_warn (mp,"ents overlappings bests\n" );return false; + }/* Check hash value order, count stale entries. */ for (i = stale =0 ; i < hdr->count; i++) {if (i +1 < hdr->count) {if (be32_to_cpu (ents[i].hashval) > -be32_to_cpu (ents[i +1 ].hashval)) +be32_to_cpu (ents[i +1 ].hashval)) { +xfs_warn (mp,"broken hash order\n" );return false; + } }if (ents[i].address ==cpu_to_be32 (XFS_DIR2_NULL_DATAPTR )) stale++; } -if (hdr->stale != stale) +if (hdr->stale != stale) { +xfs_warn (mp,"incorrect stalte count (%d, expected %d)\n" , + hdr->stale, stale);return false; + }return true; }@@ -159,12 +169,21 @@ xfs_dir3_leaf_verify( magic3 = (magic ==XFS_DIR2_LEAF1_MAGIC ) ?XFS_DIR3_LEAF1_MAGIC :XFS_DIR3_LEAFN_MAGIC ; -if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) +if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) { +xfs_warn (mp,"incorrect magic number (0x%hx, expected 0x%hx)\n" , + leaf3->info.hdr.magic, magic3);return false; -if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) + } +if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) { +xfs_warn (mp,"incorrect uuid, (%pUb, expected %pUb)\n" , + &leaf3->info.uuid, &mp->m_sb.sb_meta_uuid);return false; -if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) + } +if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) { +xfs_warn (mp,"incorrect blkno, (%lld, expected %lld)\n" , +be64_to_cpu (leaf3->info.blkno), bp->b_bn);return false; + }if (!xfs_log_check_lsn (mp,be64_to_cpu (leaf3->info.lsn)))return false; }else {Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 46 lines · Darrick J. Wong
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Darrick J. Wong
Hi all,
This RFC combines all the random little fixes and improvements to the verifiers that we've been talking about for the past month or so into a single patch series!
We start by refactoring the long format btree block header verifier into a single helper functionn and de-macroing dir block verifiers to make them less shouty. Next, we change verifier functions to return the approximate instruction pointer of the faulting test so that we can report more precise fault information to dmesg/tracepoints.
Quoted 5 lines
Just jumping here quickly because I don't have time for a detailed review:
How good does this instruction pointer thing resolved to the actual issue?
Ugh, it's terrible once you turn on the optimizer.
if (!xfs_sb_version_hascrc(&mp->m_sb)) return __this_address; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) return __this_address; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) return __this_address; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) return __this_address; return NULL;becomes:
if (!xfs_sb_version_hascrc(&mp->m_sb)) goto out; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) goto out; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) goto out; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) goto out; return NULL; out: return __this_address;
Quoted 4 lines
...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
Ok, there's /slightly/ less awful way to prevent gcc from optimizing the verifier function to the point of imprecise pointer value, but it involves writing to a volatile int:
/* stupidly prevent gcc from over-optimizing getting the instruction ptr */ extern volatile int xfs_lineno;
#define __this_address ({ __label__ __here; __here: xfs_lineno = __LINE__; &&__here; })
<grumble> Yucky, but it more or less works.
--D
Quoted 100 lines
Quoted 96 lines
I'm currently watching a customer issue where a write verifier triggers, and I gave them a patch to add a debug print to every failing statement, including printing out the mismatch values if it's not simply a binary comparism. I though about preparing that patch as well as others for mainline. Here is the one I have at the moment:
---
From6c5e2efc6f857228461d439feb3c98be58fb9744Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <[email protected]>
Date: Sat, 5 Aug 2017 16:34:15 +0200
Subject: xfs: print verbose information on dir leaf verifier failuresSigned-off-by Christoph Hellwig <[email protected]>--- fs/xfs/libxfs/xfs_dir2_leaf.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)fs/xfs/libxfs/xfs_dir2_leaf.c +26
-7@@ -113,27 +113,37 @@ xfs_dir3_leaf_check_int(* Should factor in the size of the bests table as well. * We can deduce a value for that from di_size. */ -if (hdr->count > ops->leaf_max_ents (geo)) +if (hdr->count > ops->leaf_max_ents (geo)) { +xfs_warn (mp,"count (%d) above max (%d)\n" , + hdr->count, ops->leaf_max_ents (geo));return false; + }/* Leaves and bests don't overlap in leaf format. */ if ((hdr->magic ==XFS_DIR2_LEAF1_MAGIC || hdr->magic ==XFS_DIR3_LEAF1_MAGIC ) && - (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) + (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) { +xfs_warn (mp,"ents overlappings bests\n" );return false; + }/* Check hash value order, count stale entries. */ for (i = stale =0 ; i < hdr->count; i++) {if (i +1 < hdr->count) {if (be32_to_cpu (ents[i].hashval) > -be32_to_cpu (ents[i +1 ].hashval)) +be32_to_cpu (ents[i +1 ].hashval)) { +xfs_warn (mp,"broken hash order\n" );return false; + } }if (ents[i].address ==cpu_to_be32 (XFS_DIR2_NULL_DATAPTR )) stale++; } -if (hdr->stale != stale) +if (hdr->stale != stale) { +xfs_warn (mp,"incorrect stalte count (%d, expected %d)\n" , + hdr->stale, stale);return false; + }return true; }@@ -159,12 +169,21 @@ xfs_dir3_leaf_verify( magic3 = (magic ==XFS_DIR2_LEAF1_MAGIC ) ?XFS_DIR3_LEAF1_MAGIC :XFS_DIR3_LEAFN_MAGIC ; -if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) +if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) { +xfs_warn (mp,"incorrect magic number (0x%hx, expected 0x%hx)\n" , + leaf3->info.hdr.magic, magic3);return false; -if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) + } +if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) { +xfs_warn (mp,"incorrect uuid, (%pUb, expected %pUb)\n" , + &leaf3->info.uuid, &mp->m_sb.sb_meta_uuid);return false; -if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) + } +if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) { +xfs_warn (mp,"incorrect blkno, (%lld, expected %lld)\n" , +be64_to_cpu (leaf3->info.blkno), bp->b_bn);return false; + }if (!xfs_log_check_lsn (mp,be64_to_cpu (leaf3->info.lsn)))return false; }else {Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 56 lines · Darrick J. Wong
Quoted 46 lines · Darrick J. Wong
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Darrick J. Wong
Hi all,
This RFC combines all the random little fixes and improvements to the verifiers that we've been talking about for the past month or so into a single patch series!
We start by refactoring the long format btree block header verifier into a single helper functionn and de-macroing dir block verifiers to make them less shouty. Next, we change verifier functions to return the approximate instruction pointer of the faulting test so that we can report more precise fault information to dmesg/tracepoints.
Quoted 5 lines
Just jumping here quickly because I don't have time for a detailed review:
How good does this instruction pointer thing resolved to the actual issue?
Ugh, it's terrible once you turn on the optimizer.
if (!xfs_sb_version_hascrc(&mp->m_sb)) return __this_address; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) return __this_address; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) return __this_address; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) return __this_address; return NULL;becomes:
if (!xfs_sb_version_hascrc(&mp->m_sb)) goto out; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) goto out; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) goto out; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) goto out; return NULL; out: return __this_address;Quoted 4 lines
...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
Ok, there's /slightly/ less awful way to prevent gcc from optimizing the verifier function to the point of imprecise pointer value, but it involves writing to a volatile int:
Quoted 5 lines
/* stupidly prevent gcc from over-optimizing getting the instruction ptr */ extern volatile int
xfs_lineno;
#define__this_address({__label____here;__here:xfs_lineno=__LINE__; &&__here; })<grumble> Yucky, but it more or less works.
Demonstration on a filesystem with a corrupt refcountbt root:
# dmesg & # mount /dev/sdf /opt XFS (sdf): EXPERIMENTAL reverse mapping btree feature enabled. Use at your own risk! XFS (sdf): EXPERIMENTAL reflink feature enabled. Use at your own risk! XFS (sdf): Mounting V5 Filesystem XFS (sdf): Starting recovery (logdev: internal) XFS (sdf): Ending recovery (logdev: internal) XFS (sdf): Metadata corruption detected at xfs_btree_sblock_v5hdr_verify+0x7e/0xc0 [xfs], xfs_refcountbt block 0x230 XFS (sdf): Unmount and run xfs_repair <snip> mount: mount /dev/sdf on /opt failed: Structure needs cleaning
# gdb /usr/lib/debug/lib/modules/4.13.0-rc5-xfsx/vmlinux /proc/kcore <snip> (gdb) l *(xfs_btree_sblock_v5hdr_verify+0x7e) 0xffffffffa021cc4e is in xfs_btree_sblock_v5hdr_verify (fs/xfs/libxfs/xfs_btree.c:4656). 4651 fs/xfs/libxfs/xfs_btree.c: No such file or directory. (gdb) quit
# gdb --args xfs_db /dev/sdf <snip> (gdb) run <snip> xfs_db> agf 0 xfs_db> addr refcntroot Metadata corruption detected at 0x449d68, xfs_refcountbt block 0x230/0x1000 xfs_db> ^Z Program received signal SIGTSTP, Stopped (user). 0x00007f3e83045500 in __read_nocancel () at ../sysdeps/unix/syscall-template.S:84 84 ../sysdeps/unix/syscall-template.S: No such file or directory. (gdb) l *(0x449d68) 0x449d68 is in xfs_btree_sblock_v5hdr_verify (xfs_btree.c:4656). 4651 xfs_btree.c: No such file or directory.
xfs_btree.c:
4645:void *
4646:xfs_btree_sblock_v5hdr_verify(
4647: struct xfs_buf *bp)
4648:{
4649: struct xfs_mount *mp = bp->b_target->bt_mount;
4650: struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp);
4651: struct xfs_perag *pag = bp->b_pag;
4652:
4653: if (!xfs_sb_version_hascrc(&mp->m_sb))
4654: return __this_address;
4655: if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid))
4656: return __this_address;
4657: if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn))
4658: return __this_address;
4659: if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno)
4660: return __this_address;
4661: return NULL;
4662: }
So assuming that the volatile int stuff isn't too horrifyingly gross, it actually /does/ allow us to pinpoint exactly which test tripped the verifier.
--D
Quoted 107 lines
--D
Quoted 92 lines
Quoted 92 lines
I'm currently watching a customer issue where a write verifier triggers, and I gave them a patch to add a debug print to every failing statement, including printing out the mismatch values if it's not simply a binary comparism. I though about preparing that patch as well as others for mainline. Here is the one I have at the moment:
---
From6c5e2efc6f857228461d439feb3c98be58fb9744Mon Sep 17 00:00:00 2001
From: Christoph Hellwig <[email protected]>
Date: Sat, 5 Aug 2017 16:34:15 +0200
Subject: xfs: print verbose information on dir leaf verifier failuresSigned-off-by Christoph Hellwig <[email protected]>--- fs/xfs/libxfs/xfs_dir2_leaf.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-)fs/xfs/libxfs/xfs_dir2_leaf.c +26
-7@@ -113,27 +113,37 @@ xfs_dir3_leaf_check_int(* Should factor in the size of the bests table as well. * We can deduce a value for that from di_size. */ -if (hdr->count > ops->leaf_max_ents (geo)) +if (hdr->count > ops->leaf_max_ents (geo)) { +xfs_warn (mp,"count (%d) above max (%d)\n" , + hdr->count, ops->leaf_max_ents (geo));return false; + }/* Leaves and bests don't overlap in leaf format. */ if ((hdr->magic ==XFS_DIR2_LEAF1_MAGIC || hdr->magic ==XFS_DIR3_LEAF1_MAGIC ) && - (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) + (char *)&ents[hdr->count] > (char *)xfs_dir2_leaf_bests_p (ltp)) { +xfs_warn (mp,"ents overlappings bests\n" );return false; + }/* Check hash value order, count stale entries. */ for (i = stale =0 ; i < hdr->count; i++) {if (i +1 < hdr->count) {if (be32_to_cpu (ents[i].hashval) > -be32_to_cpu (ents[i +1 ].hashval)) +be32_to_cpu (ents[i +1 ].hashval)) { +xfs_warn (mp,"broken hash order\n" );return false; + } }if (ents[i].address ==cpu_to_be32 (XFS_DIR2_NULL_DATAPTR )) stale++; } -if (hdr->stale != stale) +if (hdr->stale != stale) { +xfs_warn (mp,"incorrect stalte count (%d, expected %d)\n" , + hdr->stale, stale);return false; + }return true; }@@ -159,12 +169,21 @@ xfs_dir3_leaf_verify( magic3 = (magic ==XFS_DIR2_LEAF1_MAGIC ) ?XFS_DIR3_LEAF1_MAGIC :XFS_DIR3_LEAFN_MAGIC ; -if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) +if (leaf3->info.hdr.magic !=cpu_to_be16 (magic3)) { +xfs_warn (mp,"incorrect magic number (0x%hx, expected 0x%hx)\n" , + leaf3->info.hdr.magic, magic3);return false; -if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) + } +if (!uuid_equal (&leaf3->info.uuid, &mp->m_sb.sb_meta_uuid)) { +xfs_warn (mp,"incorrect uuid, (%pUb, expected %pUb)\n" , + &leaf3->info.uuid, &mp->m_sb.sb_meta_uuid);return false; -if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) + } +if (be64_to_cpu (leaf3->info.blkno) != bp->b_bn) { +xfs_warn (mp,"incorrect blkno, (%lld, expected %lld)\n" , +be64_to_cpu (leaf3->info.blkno), bp->b_bn);return false; + }if (!xfs_log_check_lsn (mp,be64_to_cpu (leaf3->info.lsn)))return false; }else {Signature · 1 line
2.11.0Quoted 8 lines
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 56 lines · Darrick J. Wong
Quoted 46 lines · Darrick J. Wong
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Darrick J. Wong
Hi all,
This RFC combines all the random little fixes and improvements to the verifiers that we've been talking about for the past month or so into a single patch series!
We start by refactoring the long format btree block header verifier into a single helper functionn and de-macroing dir block verifiers to make them less shouty. Next, we change verifier functions to return the approximate instruction pointer of the faulting test so that we can report more precise fault information to dmesg/tracepoints.
Quoted 5 lines
Just jumping here quickly because I don't have time for a detailed review:
How good does this instruction pointer thing resolved to the actual issue?
Ugh, it's terrible once you turn on the optimizer.
if (!xfs_sb_version_hascrc(&mp->m_sb)) return __this_address; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) return __this_address; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) return __this_address; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) return __this_address; return NULL;becomes:
if (!xfs_sb_version_hascrc(&mp->m_sb)) goto out; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) goto out; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) goto out; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) goto out; return NULL; out: return __this_address;Quoted 4 lines
...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
Ok, there's /slightly/ less awful way to prevent gcc from optimizing the verifier function to the point of imprecise pointer value, but it involves writing to a volatile int:
Quoted 5 lines
/* stupidly prevent gcc from over-optimizing getting the instruction ptr */ extern volatile int
xfs_lineno;
#define__this_address({__label____here;__here:xfs_lineno=__LINE__; &&__here; })<grumble> Yucky, but it more or less works.
Can you declare the label as volatile, like you can an asm statement to prevent the compiler from optimising out asm statements?
Even so, given the yuckiness is very isolated and should only affect the slow path code, I can live with this.
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 61 lines · Dave Chinner
Quoted 60 lines · Darrick J. Wong
Quoted 46 lines · Darrick J. Wong
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Darrick J. Wong
Hi all,
This RFC combines all the random little fixes and improvements to the verifiers that we've been talking about for the past month or so into a single patch series!
We start by refactoring the long format btree block header verifier into a single helper functionn and de-macroing dir block verifiers to make them less shouty. Next, we change verifier functions to return the approximate instruction pointer of the faulting test so that we can report more precise fault information to dmesg/tracepoints.
Quoted 5 lines
Just jumping here quickly because I don't have time for a detailed review:
How good does this instruction pointer thing resolved to the actual issue?
Ugh, it's terrible once you turn on the optimizer.
if (!xfs_sb_version_hascrc(&mp->m_sb)) return __this_address; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) return __this_address; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) return __this_address; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) return __this_address; return NULL;becomes:
if (!xfs_sb_version_hascrc(&mp->m_sb)) goto out; if (!uuid_equal(&block->bb_u.s.bb_uuid, &mp->m_sb.sb_meta_uuid)) goto out; if (block->bb_u.s.bb_blkno != cpu_to_be64(bp->b_bn)) goto out; if (pag && be32_to_cpu(block->bb_u.s.bb_owner) != pag->pag_agno) goto out; return NULL; out: return __this_address;Quoted 4 lines
...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
Ok, there's /slightly/ less awful way to prevent gcc from optimizing the verifier function to the point of imprecise pointer value, but it involves writing to a volatile int:
/* stupidly prevent gcc from over-optimizing getting the instruction ptr */ extern volatile int
xfs_lineno;
#define__this_address({__label____here;__here:xfs_lineno=__LINE__; &&__here; })
Quoted 8 lines
Quoted 1 line
<grumble> Yucky, but it more or less works.
Can you declare the label as volatile, like you can an asm statement to prevent the compiler from optimising out asm statements?
Even so, given the yuckiness is very isolated and should only affect the slow path code, I can live with this.
Hmmm. I can't declare the label as volatile, but I /can/ inject asm volatile("") and that seems to prevent gcc from moving code hunks around:
#define __this_address ({ __label__ __here; __here: asm volatile(""); &&__here; })
--D
Quoted 11 lines
Cheers,
Dave.
Signature · 6 lines
Dave Chinner [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 22 lines · Darrick J. Wong
Quoted 21 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 4 lines · Darrick J. Wong
...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
Ok, there's /slightly/ less awful way to prevent gcc from optimizing the verifier function to the point of imprecise pointer value, but it involves writing to a volatile int:
Quoted 5 lines
/* stupidly prevent gcc from over-optimizing getting the instruction ptr */ extern volatile int
xfs_lineno;
#define__this_address({__label____here;__here:xfs_lineno=__LINE__; &&__here; })<grumble> Yucky, but it more or less works.
Can you declare the label as volatile, like you can an asm statement to prevent the compiler from optimising out asm statements?
Quoted 8 lines
Quoted 2 lines
Even so, given the yuckiness is very isolated and should only affect the slow path code, I can live with this.
Hmmm. I can't declare the label as volatile, but I /can/ inject asm
volatile("")and that seems to prevent gcc from moving code hunks around:#define
__this_address({__label____here;__here: asmvolatile(""); &&__here; })
That seems cleaner to me, and I /think/ the gcc manual says it won't remove such statements, but it also says:
Under certain circumstances, GCC may duplicate (or remove duplicates of) your assembly code when optimizing.
So I have no real idea whether this is going to be robust or not. I'm not a gcc/asm expert at all (that stuff is mostly black magic to me).
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 35 lines · Dave Chinner
Quoted 22 lines · Darrick J. Wong
Quoted 21 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 4 lines · Darrick J. Wong
...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
Ok, there's /slightly/ less awful way to prevent gcc from optimizing the verifier function to the point of imprecise pointer value, but it involves writing to a volatile int:
Quoted 5 lines
/* stupidly prevent gcc from over-optimizing getting the instruction ptr */ extern volatile int
xfs_lineno;
#define__this_address({__label____here;__here:xfs_lineno=__LINE__; &&__here; })<grumble> Yucky, but it more or less works.
Can you declare the label as volatile, like you can an asm statement to prevent the compiler from optimising out asm statements?
Quoted 8 lines
Quoted 2 lines
Even so, given the yuckiness is very isolated and should only affect the slow path code, I can live with this.
Hmmm. I can't declare the label as volatile, but I /can/ inject asm
volatile("")and that seems to prevent gcc from moving code hunks around:#define
__this_address({__label____here;__here: asmvolatile(""); &&__here; })That seems cleaner to me, and I /think/ the gcc manual says it won't remove such statements, but it also says:
Quoted 6 lines
Under certain circumstances, GCC may duplicate (or remove duplicates of) your assembly code when optimizing.
So I have no real idea whether this is going to be robust or not. I'm not a gcc/asm expert at all (that stuff is mostly black magic to me).
Same here. I figure if we start getting complaints about totally wacko function pointers in the dmesg/xfsrepair output, we can put the set-a-volatile-int cobwebs back in.
--D
Quoted 11 lines
Cheers,
Dave.
Signature · 6 lines
Dave Chinner [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 39 lines · Darrick J. Wong
Quoted 38 lines · Dave Chinner
Quoted 22 lines · Darrick J. Wong
Quoted 21 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 4 lines · Darrick J. Wong
...which is totally worthless, unless we want to compile all the verifier functions with __attribute__((optimize("O0"))), which is bogus.
<sigh> Back to the drawing board on that one.
Ok, there's /slightly/ less awful way to prevent gcc from optimizing the verifier function to the point of imprecise pointer value, but it involves writing to a volatile int:
Quoted 5 lines
/* stupidly prevent gcc from over-optimizing getting the instruction ptr */ extern volatile int
xfs_lineno;
#define__this_address({__label____here;__here:xfs_lineno=__LINE__; &&__here; })<grumble> Yucky, but it more or less works.
Can you declare the label as volatile, like you can an asm statement to prevent the compiler from optimising out asm statements?
Quoted 8 lines
Quoted 2 lines
Even so, given the yuckiness is very isolated and should only affect the slow path code, I can live with this.
Hmmm. I can't declare the label as volatile, but I /can/ inject asm
volatile("")and that seems to prevent gcc from moving code hunks around:#define
__this_address({__label____here;__here: asmvolatile(""); &&__here; })That seems cleaner to me, and I /think/ the gcc manual says it won't remove such statements, but it also says:
Under certain circumstances, GCC may duplicate (or remove duplicates of) your assembly code when optimizing.
Quoted 7 lines
Quoted 3 lines
So I have no real idea whether this is going to be robust or not. I'm not a gcc/asm expert at all (that stuff is mostly black magic to me).
Same here. I figure if we start getting complaints about totally wacko function pointers in the dmesg/xfsrepair output, we can put the set-a-volatile-int cobwebs back in.
Doh, it's taking me longer to remember things I forgot 10+ years ago these days...
Quoted 1 line
From
include/linux/gcc-compiler.h:
/* Optimization barrier */
/* The "volatile" is due to gcc bugs */ #define barrier() __asm__ __volatile__("": : :"memory")
So I think we can just dump a barrier() call in the macro and it should work without us having to care about it. Still need a comment to explain why the barrier is there, though...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Oh! Sorry, I lost the thread and forgot to reply. :(
For debug kernels, I think it's definitely valuable to us to enhance the corruption reports by printing out the expected value(s) and the observed value so that we can pinpoint quickly exactly which test failed and why.
I'm not as strongly convinced that it's worth it to put all those strings into release builds and have to carry those around in memory. Then again, on my rc7 dev build the strings only contribute about 120K to a 1.4MB .ko file so it might not be a big deal.
I also think it would be useful for xfs_verifier_error to print more of the corrupted buffer.
--D
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
Perhaps what we should think about here is adding a mode to xfs_db to decode the hexdump into structured output so we don't have to manually decode the hex dumps ever again....
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 6 lines · Dave Chinner
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Quoted 8 lines
Quoted 2 lines
Given that there was another resend of the series I'd be really curious about the answer to this?
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
How much do we increase the size of the hexdump? 64 -> 128? Or whatever the structure header size is? How about if xfs_error_level >= XFS_ERRORLEVEL_HIGH then we dump the entire buffer?
Quoted 3 lines
Perhaps what we should think about here is adding a mode to
xfs_dbto decode the hexdump into structured output so we don't have to manually decode the hex dumps ever again....
Seems useful, yes.
--D
Quoted 11 lines
Cheers,
Dave.
Signature · 6 lines
Dave Chinner [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Quoted 8 lines
Quoted 5 lines
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
How much do we increase the size of the hexdump? 64 -> 128? Or whatever the structure header size is?
I choose 64 because it captured the primary header for most structures for CRC enabled filesystems, so it would have owner/crc/uuid/etc in it. I wasn't really trying to capture the object specific metadata in it, but increasing to 128 bytes would capture most of that block headers, too. Won't really help with inodes, though, as the core is 176 bytes and the owner/crc stuff is at the end....
Quoted 2 lines
How about if
xfs_error_level>=XFS_ERRORLEVEL_HIGHthen we dump the entire buffer?
Excellent idea. We can easily capture the entire output for corruptions the users can easily trip over. Maybe put in the short dump a line "turn error level up to 11 to get a full dump of the corruption"?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 28 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Quoted 8 lines
Quoted 5 lines
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
How much do we increase the size of the hexdump? 64 -> 128? Or whatever the structure header size is?
I choose 64 because it captured the primary header for most structures for CRC enabled filesystems, so it would have owner/crc/uuid/etc in it. I wasn't really trying to capture the object specific metadata in it, but increasing to 128 bytes would capture most of that block headers, too. Won't really help with inodes, though, as the core is 176 bytes and the owner/crc stuff is at the end....
Quoted 7 lines
Quoted 2 lines
How about if
xfs_error_level>=XFS_ERRORLEVEL_HIGHthen we dump the entire buffer?Excellent idea. We can easily capture the entire output for corruptions the users can easily trip over. Maybe put in the short dump a line "turn error level up to 11 to get a full dump of the corruption"?
Yep, the thing about "more info only if you tune it" is that nobody will know to tune it. Unless you printk that info...
Of course nobody will know what "turn error up ..." means, either.
Hm, at one point I had a patch to add object size to the xfs_buf_ops struct and print that many bytes, but can't find it now :/ (not that it was very complicated...)
Anyway, point is making it vary with the size of the object wouldn't be too hard.
-Eric
Quoted 37 lines · Eric Sandeen
Quoted 28 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Quoted 8 lines
Quoted 5 lines
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
How much do we increase the size of the hexdump? 64 -> 128? Or whatever the structure header size is?
I choose 64 because it captured the primary header for most structures for CRC enabled filesystems, so it would have owner/crc/uuid/etc in it. I wasn't really trying to capture the object specific metadata in it, but increasing to 128 bytes would capture most of that block headers, too. Won't really help with inodes, though, as the core is 176 bytes and the owner/crc stuff is at the end....
Quoted 7 lines
Quoted 2 lines
How about if
xfs_error_level>=XFS_ERRORLEVEL_HIGHthen we dump the entire buffer?Excellent idea. We can easily capture the entire output for corruptions the users can easily trip over. Maybe put in the short dump a line "turn error level up to 11 to get a full dump of the corruption"?
Quoted 4 lines
Yep, the thing about "more info only if you tune it" is that nobody will know to tune it. Unless you printk that info...
Of course nobody will know what "turn error up ..." means, either.
Sure, I was just paraphrasing how an error message might look. A few quick coats of paint on the bikeshed will result in something like:
"If this is a recurring error, please set/proc/sys/fs/xfs/error_level to ...."
Quoted 6 lines
Hm, at one point I had a patch to add object size to the
xfs_buf_opsstruct and print that many bytes, but can't find it now :/ (not that it was very complicated...)Anyway, point is making it vary with the size of the object wouldn't be too hard.
Probably not, but it is complicated by the fact we have a couple of different ways of dumping corruption errors. e.g. inode verifier warnings are dumped through XFS_CORRUPTION_ERROR() rather than xfs_verifier_error() as they are not buffer based verifiers. Other things like log record CRC failures are hard coded to dump 32 bytes, as is xlog_print_trans() on transaction overruns....
That's not a show stopper, but it would be nice to have consistent behaviour across all the mechanisms we use to dump object data that failed verification...
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 64 lines · Dave Chinner
Quoted 37 lines · Eric Sandeen
Quoted 28 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Quoted 8 lines
Quoted 5 lines
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
How much do we increase the size of the hexdump? 64 -> 128? Or whatever the structure header size is?
I choose 64 because it captured the primary header for most structures for CRC enabled filesystems, so it would have owner/crc/uuid/etc in it. I wasn't really trying to capture the object specific metadata in it, but increasing to 128 bytes would capture most of that block headers, too. Won't really help with inodes, though, as the core is 176 bytes and the owner/crc stuff is at the end....
Quoted 7 lines
Quoted 2 lines
How about if
xfs_error_level>=XFS_ERRORLEVEL_HIGHthen we dump the entire buffer?Excellent idea. We can easily capture the entire output for corruptions the users can easily trip over. Maybe put in the short dump a line "turn error level up to 11 to get a full dump of the corruption"?
Quoted 4 lines
Yep, the thing about "more info only if you tune it" is that nobody will know to tune it. Unless you printk that info...
Of course nobody will know what "turn error up ..." means, either.
Sure, I was just paraphrasing how an error message might look. A few quick coats of paint on the bikeshed will result in something like:
"If this is a recurring error, please set
/proc/sys/fs/xfs/error_levelto ...."Quoted 6 lines
Hm, at one point I had a patch to add object size to the
xfs_buf_opsstruct and print that many bytes, but can't find it now :/ (not that it was very complicated...)Anyway, point is making it vary with the size of the object wouldn't be too hard.
Probably not, but it is complicated by the fact we have a couple of different ways of dumping corruption errors. e.g. inode verifier warnings are dumped through
XFS_CORRUPTION_ERROR()rather thanxfs_verifier_error()as they are not buffer based verifiers. Other things like log record CRC failures are hard coded to dump 32 bytes, as isxlog_print_trans()on transaction overruns....
Quoted 3 lines
That's not a show stopper, but it would be nice to have consistent behaviour across all the mechanisms we use to dump object data that failed verification...
/me wonders if it'd suffice just to add an xfs_params value in /proc, set its default to 128 bytes, and make the corruption reporters query the xfs_param. Then we could tell users to set it to some magic value (-1? 0?) to get the entire buffer.
I just had another thought -- what if we always dump the whole buffer if the corruption would result in fs shutdown?
--D
Quoted 10 lines
Cheers,
Dave.
Signature · 6 lines
Dave Chinner [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 65 lines · Darrick J. Wong
Quoted 64 lines · Dave Chinner
Quoted 37 lines · Eric Sandeen
Quoted 28 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Quoted 8 lines
Quoted 5 lines
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
How much do we increase the size of the hexdump? 64 -> 128? Or whatever the structure header size is?
I choose 64 because it captured the primary header for most structures for CRC enabled filesystems, so it would have owner/crc/uuid/etc in it. I wasn't really trying to capture the object specific metadata in it, but increasing to 128 bytes would capture most of that block headers, too. Won't really help with inodes, though, as the core is 176 bytes and the owner/crc stuff is at the end....
Quoted 7 lines
Quoted 2 lines
How about if
xfs_error_level>=XFS_ERRORLEVEL_HIGHthen we dump the entire buffer?Excellent idea. We can easily capture the entire output for corruptions the users can easily trip over. Maybe put in the short dump a line "turn error level up to 11 to get a full dump of the corruption"?
Quoted 4 lines
Yep, the thing about "more info only if you tune it" is that nobody will know to tune it. Unless you printk that info...
Of course nobody will know what "turn error up ..." means, either.
Sure, I was just paraphrasing how an error message might look. A few quick coats of paint on the bikeshed will result in something like:
"If this is a recurring error, please set
/proc/sys/fs/xfs/error_levelto ...."Quoted 6 lines
Hm, at one point I had a patch to add object size to the
xfs_buf_opsstruct and print that many bytes, but can't find it now :/ (not that it was very complicated...)Anyway, point is making it vary with the size of the object wouldn't be too hard.
Probably not, but it is complicated by the fact we have a couple of different ways of dumping corruption errors. e.g. inode verifier warnings are dumped through
XFS_CORRUPTION_ERROR()rather thanxfs_verifier_error()as they are not buffer based verifiers. Other things like log record CRC failures are hard coded to dump 32 bytes, as isxlog_print_trans()on transaction overruns....
Quoted 8 lines
Quoted 3 lines
That's not a show stopper, but it would be nice to have consistent behaviour across all the mechanisms we use to dump object data that failed verification...
/me wonders if it'd suffice just to add an
xfs_paramsvalue in /proc, set its default to 128 bytes, and make the corruption reporters query thexfs_param. Then we could tell users to set it to some magic value (-1? 0?) to get the entire buffer.
Let's avoid adding a new proc entries to configure error verbosity when we already have a proc entry that controls error verbosity....
Quoted 2 lines
I just had another thought -- what if we always dump the whole buffer if the corruption would result in fs shutdown?
How do you know that a verifier failure (or any specific call to XFS_CORRUPTION_ERROR) is going to result in a filesystem shutdown?
Cheers,
Dave.
Signature · 2 lines
Dave Chinner [email protected]
Quoted 70 lines · Dave Chinner
Quoted 69 lines · Darrick J. Wong
Quoted 67 lines · Dave Chinner
Quoted 37 lines · Eric Sandeen
Quoted 28 lines · Dave Chinner
Quoted 10 lines · Darrick J. Wong
Quoted 9 lines · Dave Chinner
Quoted 7 lines · Christoph Hellwig
Quoted 3 lines · Christoph Hellwig
So what do you think of the version that adds real printks for each condition including more details like the one verifier I did below? Probably needs some unlikely annotations, though.
Given that there was another resend of the series I'd be really curious about the answer to this?
Quoted 8 lines
Quoted 5 lines
If we increase the size of the hexdump on error, then most of the specific numbers in the print statements can be pulled from the hexdump. And if the verifier tells us exactly what check failed, we don't have to decode the entire hexdump to know what field was out of band.
How much do we increase the size of the hexdump? 64 -> 128? Or whatever the structure header size is?
I choose 64 because it captured the primary header for most structures for CRC enabled filesystems, so it would have owner/crc/uuid/etc in it. I wasn't really trying to capture the object specific metadata in it, but increasing to 128 bytes would capture most of that block headers, too. Won't really help with inodes, though, as the core is 176 bytes and the owner/crc stuff is at the end....
Quoted 7 lines
Quoted 2 lines
How about if
xfs_error_level>=XFS_ERRORLEVEL_HIGHthen we dump the entire buffer?Excellent idea. We can easily capture the entire output for corruptions the users can easily trip over. Maybe put in the short dump a line "turn error level up to 11 to get a full dump of the corruption"?
Quoted 4 lines
Yep, the thing about "more info only if you tune it" is that nobody will know to tune it. Unless you printk that info...
Of course nobody will know what "turn error up ..." means, either.
Sure, I was just paraphrasing how an error message might look. A few quick coats of paint on the bikeshed will result in something like:
"If this is a recurring error, please set
/proc/sys/fs/xfs/error_levelto ...."Quoted 6 lines
Hm, at one point I had a patch to add object size to the
xfs_buf_opsstruct and print that many bytes, but can't find it now :/ (not that it was very complicated...)Anyway, point is making it vary with the size of the object wouldn't be too hard.
Probably not, but it is complicated by the fact we have a couple of different ways of dumping corruption errors. e.g. inode verifier warnings are dumped through
XFS_CORRUPTION_ERROR()rather thanxfs_verifier_error()as they are not buffer based verifiers. Other things like log record CRC failures are hard coded to dump 32 bytes, as isxlog_print_trans()on transaction overruns....That's not a show stopper, but it would be nice to have consistent behaviour across all the mechanisms we use to dump object data that failed verification...
Quoted 7 lines
Quoted 4 lines
/me wonders if it'd suffice just to add an
xfs_paramsvalue in /proc, set its default to 128 bytes, and make the corruption reporters query thexfs_param. Then we could tell users to set it to some magic value (-1? 0?) to get the entire buffer.Let's avoid adding a new proc entries to configure error verbosity when we already have a proc entry that controls error verbosity....
Fair enough.
Quoted 5 lines
Quoted 2 lines
I just had another thought -- what if we always dump the whole buffer if the corruption would result in fs shutdown?
How do you know that a verifier failure (or any specific call to
XFS_CORRUPTION_ERROR) is going to result in a filesystem shutdown?
Nuts. For a minute there I thought that if we were trying to get/read a buffer we'd have assigned it to a transaction before calling the verifier, but that's not true. Oh well. I'll start with a simpler patch to increase the dump size if xfs_error_level is high.
--D
Quoted 10 lines
Cheers,
Dave.
Signature · 6 lines
Dave Chinner [email protected] -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html