diff options
| author | Dave Chinner <dchinner@redhat.com> | 2012-11-12 06:54:14 -0500 |
|---|---|---|
| committer | Ben Myers <bpm@sgi.com> | 2012-11-15 22:34:45 -0500 |
| commit | e4813572640e27d3a5cce3f06751a9f54f77aaa5 (patch) | |
| tree | f181db296dace8bac868f89a0a016f5973c18ba1 /fs | |
| parent | 2025207ca6738a1217126ef14af9d104433f9824 (diff) | |
xfs: factor out dir2 data block reading
And add a verifier callback function while there.
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Phil White <pwhite@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
Diffstat (limited to 'fs')
| -rw-r--r-- | fs/xfs/xfs_dir2_block.c | 3 | ||||
| -rw-r--r-- | fs/xfs/xfs_dir2_data.c | 32 | ||||
| -rw-r--r-- | fs/xfs/xfs_dir2_leaf.c | 38 | ||||
| -rw-r--r-- | fs/xfs/xfs_dir2_node.c | 8 | ||||
| -rw-r--r-- | fs/xfs/xfs_dir2_priv.h | 2 |
5 files changed, 56 insertions, 27 deletions
diff --git a/fs/xfs/xfs_dir2_block.c b/fs/xfs/xfs_dir2_block.c index 57351b868861..ca03b109772d 100644 --- a/fs/xfs/xfs_dir2_block.c +++ b/fs/xfs/xfs_dir2_block.c | |||
| @@ -970,8 +970,7 @@ xfs_dir2_leaf_to_block( | |||
| 970 | * Read the data block if we don't already have it, give up if it fails. | 970 | * Read the data block if we don't already have it, give up if it fails. |
| 971 | */ | 971 | */ |
| 972 | if (!dbp) { | 972 | if (!dbp) { |
| 973 | error = xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, &dbp, | 973 | error = xfs_dir2_data_read(tp, dp, mp->m_dirdatablk, -1, &dbp); |
| 974 | XFS_DATA_FORK, NULL); | ||
| 975 | if (error) | 974 | if (error) |
| 976 | return error; | 975 | return error; |
| 977 | } | 976 | } |
diff --git a/fs/xfs/xfs_dir2_data.c b/fs/xfs/xfs_dir2_data.c index cb117234e32e..0ef04f1bf511 100644 --- a/fs/xfs/xfs_dir2_data.c +++ b/fs/xfs/xfs_dir2_data.c | |||
| @@ -185,6 +185,38 @@ __xfs_dir2_data_check( | |||
| 185 | return 0; | 185 | return 0; |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | static void | ||
| 189 | xfs_dir2_data_verify( | ||
| 190 | struct xfs_buf *bp) | ||
| 191 | { | ||
| 192 | struct xfs_mount *mp = bp->b_target->bt_mount; | ||
| 193 | struct xfs_dir2_data_hdr *hdr = bp->b_addr; | ||
| 194 | int block_ok = 0; | ||
| 195 | |||
| 196 | block_ok = hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC); | ||
| 197 | block_ok = block_ok && __xfs_dir2_data_check(NULL, bp) == 0; | ||
| 198 | |||
| 199 | if (!block_ok) { | ||
| 200 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, hdr); | ||
| 201 | xfs_buf_ioerror(bp, EFSCORRUPTED); | ||
| 202 | } | ||
| 203 | |||
| 204 | bp->b_iodone = NULL; | ||
| 205 | xfs_buf_ioend(bp, 0); | ||
| 206 | } | ||
| 207 | |||
| 208 | int | ||
| 209 | xfs_dir2_data_read( | ||
| 210 | struct xfs_trans *tp, | ||
| 211 | struct xfs_inode *dp, | ||
| 212 | xfs_dablk_t bno, | ||
| 213 | xfs_daddr_t mapped_bno, | ||
| 214 | struct xfs_buf **bpp) | ||
| 215 | { | ||
| 216 | return xfs_da_read_buf(tp, dp, bno, mapped_bno, bpp, | ||
| 217 | XFS_DATA_FORK, xfs_dir2_data_verify); | ||
| 218 | } | ||
| 219 | |||
| 188 | /* | 220 | /* |
| 189 | * Given a data block and an unused entry from that block, | 221 | * Given a data block and an unused entry from that block, |
| 190 | * return the bestfree entry if any that corresponds to it. | 222 | * return the bestfree entry if any that corresponds to it. |
diff --git a/fs/xfs/xfs_dir2_leaf.c b/fs/xfs/xfs_dir2_leaf.c index 6c1359dc9898..0fdf765c917f 100644 --- a/fs/xfs/xfs_dir2_leaf.c +++ b/fs/xfs/xfs_dir2_leaf.c | |||
| @@ -493,14 +493,14 @@ xfs_dir2_leaf_addname( | |||
| 493 | hdr = dbp->b_addr; | 493 | hdr = dbp->b_addr; |
| 494 | bestsp[use_block] = hdr->bestfree[0].length; | 494 | bestsp[use_block] = hdr->bestfree[0].length; |
| 495 | grown = 1; | 495 | grown = 1; |
| 496 | } | 496 | } else { |
| 497 | /* | 497 | /* |
| 498 | * Already had space in some data block. | 498 | * Already had space in some data block. |
| 499 | * Just read that one in. | 499 | * Just read that one in. |
| 500 | */ | 500 | */ |
| 501 | else { | 501 | error = xfs_dir2_data_read(tp, dp, |
| 502 | error = xfs_da_read_buf(tp, dp, xfs_dir2_db_to_da(mp, use_block), | 502 | xfs_dir2_db_to_da(mp, use_block), |
| 503 | -1, &dbp, XFS_DATA_FORK, NULL); | 503 | -1, &dbp); |
| 504 | if (error) { | 504 | if (error) { |
| 505 | xfs_trans_brelse(tp, lbp); | 505 | xfs_trans_brelse(tp, lbp); |
| 506 | return error; | 506 | return error; |
| @@ -508,7 +508,6 @@ xfs_dir2_leaf_addname( | |||
| 508 | hdr = dbp->b_addr; | 508 | hdr = dbp->b_addr; |
| 509 | grown = 0; | 509 | grown = 0; |
| 510 | } | 510 | } |
| 511 | xfs_dir2_data_check(dp, dbp); | ||
| 512 | /* | 511 | /* |
| 513 | * Point to the biggest freespace in our data block. | 512 | * Point to the biggest freespace in our data block. |
| 514 | */ | 513 | */ |
| @@ -891,10 +890,9 @@ xfs_dir2_leaf_readbuf( | |||
| 891 | * Read the directory block starting at the first mapping. | 890 | * Read the directory block starting at the first mapping. |
| 892 | */ | 891 | */ |
| 893 | mip->curdb = xfs_dir2_da_to_db(mp, map->br_startoff); | 892 | mip->curdb = xfs_dir2_da_to_db(mp, map->br_startoff); |
| 894 | error = xfs_da_read_buf(NULL, dp, map->br_startoff, | 893 | error = xfs_dir2_data_read(NULL, dp, map->br_startoff, |
| 895 | map->br_blockcount >= mp->m_dirblkfsbs ? | 894 | map->br_blockcount >= mp->m_dirblkfsbs ? |
| 896 | XFS_FSB_TO_DADDR(mp, map->br_startblock) : -1, | 895 | XFS_FSB_TO_DADDR(mp, map->br_startblock) : -1, &bp); |
| 897 | &bp, XFS_DATA_FORK, NULL); | ||
| 898 | 896 | ||
| 899 | /* | 897 | /* |
| 900 | * Should just skip over the data block instead of giving up. | 898 | * Should just skip over the data block instead of giving up. |
| @@ -1408,14 +1406,13 @@ xfs_dir2_leaf_lookup_int( | |||
| 1408 | if (newdb != curdb) { | 1406 | if (newdb != curdb) { |
| 1409 | if (dbp) | 1407 | if (dbp) |
| 1410 | xfs_trans_brelse(tp, dbp); | 1408 | xfs_trans_brelse(tp, dbp); |
| 1411 | error = xfs_da_read_buf(tp, dp, | 1409 | error = xfs_dir2_data_read(tp, dp, |
| 1412 | xfs_dir2_db_to_da(mp, newdb), | 1410 | xfs_dir2_db_to_da(mp, newdb), |
| 1413 | -1, &dbp, XFS_DATA_FORK, NULL); | 1411 | -1, &dbp); |
| 1414 | if (error) { | 1412 | if (error) { |
| 1415 | xfs_trans_brelse(tp, lbp); | 1413 | xfs_trans_brelse(tp, lbp); |
| 1416 | return error; | 1414 | return error; |
| 1417 | } | 1415 | } |
| 1418 | xfs_dir2_data_check(dp, dbp); | ||
| 1419 | curdb = newdb; | 1416 | curdb = newdb; |
| 1420 | } | 1417 | } |
| 1421 | /* | 1418 | /* |
| @@ -1450,9 +1447,9 @@ xfs_dir2_leaf_lookup_int( | |||
| 1450 | ASSERT(cidb != -1); | 1447 | ASSERT(cidb != -1); |
| 1451 | if (cidb != curdb) { | 1448 | if (cidb != curdb) { |
| 1452 | xfs_trans_brelse(tp, dbp); | 1449 | xfs_trans_brelse(tp, dbp); |
| 1453 | error = xfs_da_read_buf(tp, dp, | 1450 | error = xfs_dir2_data_read(tp, dp, |
| 1454 | xfs_dir2_db_to_da(mp, cidb), | 1451 | xfs_dir2_db_to_da(mp, cidb), |
| 1455 | -1, &dbp, XFS_DATA_FORK, NULL); | 1452 | -1, &dbp); |
| 1456 | if (error) { | 1453 | if (error) { |
| 1457 | xfs_trans_brelse(tp, lbp); | 1454 | xfs_trans_brelse(tp, lbp); |
| 1458 | return error; | 1455 | return error; |
| @@ -1737,8 +1734,7 @@ xfs_dir2_leaf_trim_data( | |||
| 1737 | /* | 1734 | /* |
| 1738 | * Read the offending data block. We need its buffer. | 1735 | * Read the offending data block. We need its buffer. |
| 1739 | */ | 1736 | */ |
| 1740 | error = xfs_da_read_buf(tp, dp, xfs_dir2_db_to_da(mp, db), -1, &dbp, | 1737 | error = xfs_dir2_data_read(tp, dp, xfs_dir2_db_to_da(mp, db), -1, &dbp); |
| 1741 | XFS_DATA_FORK, NULL); | ||
| 1742 | if (error) | 1738 | if (error) |
| 1743 | return error; | 1739 | return error; |
| 1744 | 1740 | ||
diff --git a/fs/xfs/xfs_dir2_node.c b/fs/xfs/xfs_dir2_node.c index d7f899dfbff5..67b811c17eaa 100644 --- a/fs/xfs/xfs_dir2_node.c +++ b/fs/xfs/xfs_dir2_node.c | |||
| @@ -583,9 +583,9 @@ xfs_dir2_leafn_lookup_for_entry( | |||
| 583 | ASSERT(state->extravalid); | 583 | ASSERT(state->extravalid); |
| 584 | curbp = state->extrablk.bp; | 584 | curbp = state->extrablk.bp; |
| 585 | } else { | 585 | } else { |
| 586 | error = xfs_da_read_buf(tp, dp, | 586 | error = xfs_dir2_data_read(tp, dp, |
| 587 | xfs_dir2_db_to_da(mp, newdb), | 587 | xfs_dir2_db_to_da(mp, newdb), |
| 588 | -1, &curbp, XFS_DATA_FORK, NULL); | 588 | -1, &curbp); |
| 589 | if (error) | 589 | if (error) |
| 590 | return error; | 590 | return error; |
| 591 | } | 591 | } |
| @@ -1692,8 +1692,8 @@ xfs_dir2_node_addname_int( | |||
| 1692 | /* | 1692 | /* |
| 1693 | * Read the data block in. | 1693 | * Read the data block in. |
| 1694 | */ | 1694 | */ |
| 1695 | error = xfs_da_read_buf(tp, dp, xfs_dir2_db_to_da(mp, dbno), | 1695 | error = xfs_dir2_data_read(tp, dp, xfs_dir2_db_to_da(mp, dbno), |
| 1696 | -1, &dbp, XFS_DATA_FORK, NULL); | 1696 | -1, &dbp); |
| 1697 | if (error) | 1697 | if (error) |
| 1698 | return error; | 1698 | return error; |
| 1699 | hdr = dbp->b_addr; | 1699 | hdr = dbp->b_addr; |
diff --git a/fs/xfs/xfs_dir2_priv.h b/fs/xfs/xfs_dir2_priv.h index 263a63287910..71ec82839107 100644 --- a/fs/xfs/xfs_dir2_priv.h +++ b/fs/xfs/xfs_dir2_priv.h | |||
| @@ -46,6 +46,8 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args, | |||
| 46 | #define xfs_dir2_data_check(dp,bp) | 46 | #define xfs_dir2_data_check(dp,bp) |
| 47 | #endif | 47 | #endif |
| 48 | extern int __xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_buf *bp); | 48 | extern int __xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_buf *bp); |
| 49 | extern int xfs_dir2_data_read(struct xfs_trans *tp, struct xfs_inode *dp, | ||
| 50 | xfs_dablk_t bno, xfs_daddr_t mapped_bno, struct xfs_buf **bpp); | ||
| 49 | 51 | ||
| 50 | extern struct xfs_dir2_data_free * | 52 | extern struct xfs_dir2_data_free * |
| 51 | xfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr, | 53 | xfs_dir2_data_freeinsert(struct xfs_dir2_data_hdr *hdr, |
