diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2008-12-30 20:48:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-12-30 20:48:25 -0500 |
commit | 6a94cb73064c952255336cc57731904174b2c58f (patch) | |
tree | d19cc835db0a21e01909a92772868e1ad96f99ff /fs/xfs/xfs_bmap.c | |
parent | f57fa1d6a6b3414e853d3d17e339ac48816e4406 (diff) | |
parent | 0a8c5395f90f06d128247844b2515c8bf3f2826b (diff) |
Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
* 'for-linus' of git://oss.sgi.com/xfs/xfs: (184 commits)
[XFS] Fix race in xfs_write() between direct and buffered I/O with DMAPI
[XFS] handle unaligned data in xfs_bmbt_disk_get_all
[XFS] avoid memory allocations in xfs_fs_vcmn_err
[XFS] Fix speculative allocation beyond eof
[XFS] Remove XFS_BUF_SHUT() and friends
[XFS] Use the incore inode size in xfs_file_readdir()
[XFS] set b_error from bio error in xfs_buf_bio_end_io
[XFS] use inode_change_ok for setattr permission checking
[XFS] add a FMODE flag to make XFS invisible I/O less hacky
[XFS] resync headers with libxfs
[XFS] simplify projid check in xfs_rename
[XFS] replace b_fspriv with b_mount
[XFS] Remove unused tracing code
[XFS] Remove unnecessary assertion
[XFS] Remove unused variable in ktrace_free()
[XFS] Check return value of xfs_buf_get_noaddr()
[XFS] Fix hang after disallowed rename across directory quota domains
[XFS] Fix compile with CONFIG_COMPAT enabled
move inode tracing out of xfs_vnode.
move vn_iowait / vn_iowake into xfs_aops.c
...
Diffstat (limited to 'fs/xfs/xfs_bmap.c')
-rw-r--r-- | fs/xfs/xfs_bmap.c | 410 |
1 files changed, 241 insertions, 169 deletions
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c index a1aab9275d5a..138308e70d14 100644 --- a/fs/xfs/xfs_bmap.c +++ b/fs/xfs/xfs_bmap.c | |||
@@ -393,8 +393,8 @@ xfs_bmap_count_leaves( | |||
393 | 393 | ||
394 | STATIC void | 394 | STATIC void |
395 | xfs_bmap_disk_count_leaves( | 395 | xfs_bmap_disk_count_leaves( |
396 | xfs_extnum_t idx, | 396 | struct xfs_mount *mp, |
397 | xfs_bmbt_block_t *block, | 397 | struct xfs_btree_block *block, |
398 | int numrecs, | 398 | int numrecs, |
399 | int *count); | 399 | int *count); |
400 | 400 | ||
@@ -402,6 +402,53 @@ xfs_bmap_disk_count_leaves( | |||
402 | * Bmap internal routines. | 402 | * Bmap internal routines. |
403 | */ | 403 | */ |
404 | 404 | ||
405 | STATIC int /* error */ | ||
406 | xfs_bmbt_lookup_eq( | ||
407 | struct xfs_btree_cur *cur, | ||
408 | xfs_fileoff_t off, | ||
409 | xfs_fsblock_t bno, | ||
410 | xfs_filblks_t len, | ||
411 | int *stat) /* success/failure */ | ||
412 | { | ||
413 | cur->bc_rec.b.br_startoff = off; | ||
414 | cur->bc_rec.b.br_startblock = bno; | ||
415 | cur->bc_rec.b.br_blockcount = len; | ||
416 | return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat); | ||
417 | } | ||
418 | |||
419 | STATIC int /* error */ | ||
420 | xfs_bmbt_lookup_ge( | ||
421 | struct xfs_btree_cur *cur, | ||
422 | xfs_fileoff_t off, | ||
423 | xfs_fsblock_t bno, | ||
424 | xfs_filblks_t len, | ||
425 | int *stat) /* success/failure */ | ||
426 | { | ||
427 | cur->bc_rec.b.br_startoff = off; | ||
428 | cur->bc_rec.b.br_startblock = bno; | ||
429 | cur->bc_rec.b.br_blockcount = len; | ||
430 | return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat); | ||
431 | } | ||
432 | |||
433 | /* | ||
434 | * Update the record referred to by cur to the value given | ||
435 | * by [off, bno, len, state]. | ||
436 | * This either works (return 0) or gets an EFSCORRUPTED error. | ||
437 | */ | ||
438 | STATIC int | ||
439 | xfs_bmbt_update( | ||
440 | struct xfs_btree_cur *cur, | ||
441 | xfs_fileoff_t off, | ||
442 | xfs_fsblock_t bno, | ||
443 | xfs_filblks_t len, | ||
444 | xfs_exntst_t state) | ||
445 | { | ||
446 | union xfs_btree_rec rec; | ||
447 | |||
448 | xfs_bmbt_disk_set_allf(&rec.bmbt, off, bno, len, state); | ||
449 | return xfs_btree_update(cur, &rec); | ||
450 | } | ||
451 | |||
405 | /* | 452 | /* |
406 | * Called from xfs_bmap_add_attrfork to handle btree format files. | 453 | * Called from xfs_bmap_add_attrfork to handle btree format files. |
407 | */ | 454 | */ |
@@ -422,15 +469,14 @@ xfs_bmap_add_attrfork_btree( | |||
422 | if (ip->i_df.if_broot_bytes <= XFS_IFORK_DSIZE(ip)) | 469 | if (ip->i_df.if_broot_bytes <= XFS_IFORK_DSIZE(ip)) |
423 | *flags |= XFS_ILOG_DBROOT; | 470 | *flags |= XFS_ILOG_DBROOT; |
424 | else { | 471 | else { |
425 | cur = xfs_btree_init_cursor(mp, tp, NULL, 0, XFS_BTNUM_BMAP, ip, | 472 | cur = xfs_bmbt_init_cursor(mp, tp, ip, XFS_DATA_FORK); |
426 | XFS_DATA_FORK); | ||
427 | cur->bc_private.b.flist = flist; | 473 | cur->bc_private.b.flist = flist; |
428 | cur->bc_private.b.firstblock = *firstblock; | 474 | cur->bc_private.b.firstblock = *firstblock; |
429 | if ((error = xfs_bmbt_lookup_ge(cur, 0, 0, 0, &stat))) | 475 | if ((error = xfs_bmbt_lookup_ge(cur, 0, 0, 0, &stat))) |
430 | goto error0; | 476 | goto error0; |
431 | /* must be at least one entry */ | 477 | /* must be at least one entry */ |
432 | XFS_WANT_CORRUPTED_GOTO(stat == 1, error0); | 478 | XFS_WANT_CORRUPTED_GOTO(stat == 1, error0); |
433 | if ((error = xfs_bmbt_newroot(cur, flags, &stat))) | 479 | if ((error = xfs_btree_new_iroot(cur, flags, &stat))) |
434 | goto error0; | 480 | goto error0; |
435 | if (stat == 0) { | 481 | if (stat == 0) { |
436 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); | 482 | xfs_btree_del_cursor(cur, XFS_BTREE_NOERROR); |
@@ -818,10 +864,10 @@ xfs_bmap_add_extent_delay_real( | |||
818 | RIGHT.br_blockcount, &i))) | 864 | RIGHT.br_blockcount, &i))) |
819 | goto done; | 865 | goto done; |
820 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 866 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
821 | if ((error = xfs_bmbt_delete(cur, &i))) | 867 | if ((error = xfs_btree_delete(cur, &i))) |
822 | goto done; | 868 | goto done; |
823 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 869 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
824 | if ((error = xfs_bmbt_decrement(cur, 0, &i))) | 870 | if ((error = xfs_btree_decrement(cur, 0, &i))) |
825 | goto done; | 871 | goto done; |
826 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 872 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
827 | if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, | 873 | if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, |
@@ -931,7 +977,7 @@ xfs_bmap_add_extent_delay_real( | |||
931 | goto done; | 977 | goto done; |
932 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); | 978 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); |
933 | cur->bc_rec.b.br_state = XFS_EXT_NORM; | 979 | cur->bc_rec.b.br_state = XFS_EXT_NORM; |
934 | if ((error = xfs_bmbt_insert(cur, &i))) | 980 | if ((error = xfs_btree_insert(cur, &i))) |
935 | goto done; | 981 | goto done; |
936 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 982 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
937 | } | 983 | } |
@@ -1007,7 +1053,7 @@ xfs_bmap_add_extent_delay_real( | |||
1007 | goto done; | 1053 | goto done; |
1008 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); | 1054 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); |
1009 | cur->bc_rec.b.br_state = XFS_EXT_NORM; | 1055 | cur->bc_rec.b.br_state = XFS_EXT_NORM; |
1010 | if ((error = xfs_bmbt_insert(cur, &i))) | 1056 | if ((error = xfs_btree_insert(cur, &i))) |
1011 | goto done; | 1057 | goto done; |
1012 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1058 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1013 | } | 1059 | } |
@@ -1097,7 +1143,7 @@ xfs_bmap_add_extent_delay_real( | |||
1097 | goto done; | 1143 | goto done; |
1098 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); | 1144 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); |
1099 | cur->bc_rec.b.br_state = XFS_EXT_NORM; | 1145 | cur->bc_rec.b.br_state = XFS_EXT_NORM; |
1100 | if ((error = xfs_bmbt_insert(cur, &i))) | 1146 | if ((error = xfs_btree_insert(cur, &i))) |
1101 | goto done; | 1147 | goto done; |
1102 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1148 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1103 | } | 1149 | } |
@@ -1152,7 +1198,7 @@ xfs_bmap_add_extent_delay_real( | |||
1152 | goto done; | 1198 | goto done; |
1153 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); | 1199 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); |
1154 | cur->bc_rec.b.br_state = XFS_EXT_NORM; | 1200 | cur->bc_rec.b.br_state = XFS_EXT_NORM; |
1155 | if ((error = xfs_bmbt_insert(cur, &i))) | 1201 | if ((error = xfs_btree_insert(cur, &i))) |
1156 | goto done; | 1202 | goto done; |
1157 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1203 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1158 | } | 1204 | } |
@@ -1379,16 +1425,16 @@ xfs_bmap_add_extent_unwritten_real( | |||
1379 | RIGHT.br_blockcount, &i))) | 1425 | RIGHT.br_blockcount, &i))) |
1380 | goto done; | 1426 | goto done; |
1381 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1427 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1382 | if ((error = xfs_bmbt_delete(cur, &i))) | 1428 | if ((error = xfs_btree_delete(cur, &i))) |
1383 | goto done; | 1429 | goto done; |
1384 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1430 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1385 | if ((error = xfs_bmbt_decrement(cur, 0, &i))) | 1431 | if ((error = xfs_btree_decrement(cur, 0, &i))) |
1386 | goto done; | 1432 | goto done; |
1387 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1433 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1388 | if ((error = xfs_bmbt_delete(cur, &i))) | 1434 | if ((error = xfs_btree_delete(cur, &i))) |
1389 | goto done; | 1435 | goto done; |
1390 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1436 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1391 | if ((error = xfs_bmbt_decrement(cur, 0, &i))) | 1437 | if ((error = xfs_btree_decrement(cur, 0, &i))) |
1392 | goto done; | 1438 | goto done; |
1393 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1439 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1394 | if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, | 1440 | if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, |
@@ -1428,10 +1474,10 @@ xfs_bmap_add_extent_unwritten_real( | |||
1428 | &i))) | 1474 | &i))) |
1429 | goto done; | 1475 | goto done; |
1430 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1476 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1431 | if ((error = xfs_bmbt_delete(cur, &i))) | 1477 | if ((error = xfs_btree_delete(cur, &i))) |
1432 | goto done; | 1478 | goto done; |
1433 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1479 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1434 | if ((error = xfs_bmbt_decrement(cur, 0, &i))) | 1480 | if ((error = xfs_btree_decrement(cur, 0, &i))) |
1435 | goto done; | 1481 | goto done; |
1436 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1482 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1437 | if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, | 1483 | if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, |
@@ -1471,10 +1517,10 @@ xfs_bmap_add_extent_unwritten_real( | |||
1471 | RIGHT.br_blockcount, &i))) | 1517 | RIGHT.br_blockcount, &i))) |
1472 | goto done; | 1518 | goto done; |
1473 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1519 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1474 | if ((error = xfs_bmbt_delete(cur, &i))) | 1520 | if ((error = xfs_btree_delete(cur, &i))) |
1475 | goto done; | 1521 | goto done; |
1476 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1522 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1477 | if ((error = xfs_bmbt_decrement(cur, 0, &i))) | 1523 | if ((error = xfs_btree_decrement(cur, 0, &i))) |
1478 | goto done; | 1524 | goto done; |
1479 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1525 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1480 | if ((error = xfs_bmbt_update(cur, new->br_startoff, | 1526 | if ((error = xfs_bmbt_update(cur, new->br_startoff, |
@@ -1557,7 +1603,7 @@ xfs_bmap_add_extent_unwritten_real( | |||
1557 | PREV.br_blockcount - new->br_blockcount, | 1603 | PREV.br_blockcount - new->br_blockcount, |
1558 | oldext))) | 1604 | oldext))) |
1559 | goto done; | 1605 | goto done; |
1560 | if ((error = xfs_bmbt_decrement(cur, 0, &i))) | 1606 | if ((error = xfs_btree_decrement(cur, 0, &i))) |
1561 | goto done; | 1607 | goto done; |
1562 | if (xfs_bmbt_update(cur, LEFT.br_startoff, | 1608 | if (xfs_bmbt_update(cur, LEFT.br_startoff, |
1563 | LEFT.br_startblock, | 1609 | LEFT.br_startblock, |
@@ -1605,7 +1651,7 @@ xfs_bmap_add_extent_unwritten_real( | |||
1605 | oldext))) | 1651 | oldext))) |
1606 | goto done; | 1652 | goto done; |
1607 | cur->bc_rec.b = *new; | 1653 | cur->bc_rec.b = *new; |
1608 | if ((error = xfs_bmbt_insert(cur, &i))) | 1654 | if ((error = xfs_btree_insert(cur, &i))) |
1609 | goto done; | 1655 | goto done; |
1610 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1656 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1611 | } | 1657 | } |
@@ -1647,7 +1693,7 @@ xfs_bmap_add_extent_unwritten_real( | |||
1647 | PREV.br_blockcount - new->br_blockcount, | 1693 | PREV.br_blockcount - new->br_blockcount, |
1648 | oldext))) | 1694 | oldext))) |
1649 | goto done; | 1695 | goto done; |
1650 | if ((error = xfs_bmbt_increment(cur, 0, &i))) | 1696 | if ((error = xfs_btree_increment(cur, 0, &i))) |
1651 | goto done; | 1697 | goto done; |
1652 | if ((error = xfs_bmbt_update(cur, new->br_startoff, | 1698 | if ((error = xfs_bmbt_update(cur, new->br_startoff, |
1653 | new->br_startblock, | 1699 | new->br_startblock, |
@@ -1695,7 +1741,7 @@ xfs_bmap_add_extent_unwritten_real( | |||
1695 | goto done; | 1741 | goto done; |
1696 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); | 1742 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); |
1697 | cur->bc_rec.b.br_state = XFS_EXT_NORM; | 1743 | cur->bc_rec.b.br_state = XFS_EXT_NORM; |
1698 | if ((error = xfs_bmbt_insert(cur, &i))) | 1744 | if ((error = xfs_btree_insert(cur, &i))) |
1699 | goto done; | 1745 | goto done; |
1700 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1746 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1701 | } | 1747 | } |
@@ -1743,7 +1789,7 @@ xfs_bmap_add_extent_unwritten_real( | |||
1743 | cur->bc_rec.b = PREV; | 1789 | cur->bc_rec.b = PREV; |
1744 | cur->bc_rec.b.br_blockcount = | 1790 | cur->bc_rec.b.br_blockcount = |
1745 | new->br_startoff - PREV.br_startoff; | 1791 | new->br_startoff - PREV.br_startoff; |
1746 | if ((error = xfs_bmbt_insert(cur, &i))) | 1792 | if ((error = xfs_btree_insert(cur, &i))) |
1747 | goto done; | 1793 | goto done; |
1748 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1794 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1749 | /* | 1795 | /* |
@@ -1758,7 +1804,7 @@ xfs_bmap_add_extent_unwritten_real( | |||
1758 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); | 1804 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); |
1759 | /* new middle extent - newext */ | 1805 | /* new middle extent - newext */ |
1760 | cur->bc_rec.b.br_state = new->br_state; | 1806 | cur->bc_rec.b.br_state = new->br_state; |
1761 | if ((error = xfs_bmbt_insert(cur, &i))) | 1807 | if ((error = xfs_btree_insert(cur, &i))) |
1762 | goto done; | 1808 | goto done; |
1763 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 1809 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
1764 | } | 1810 | } |
@@ -2106,10 +2152,10 @@ xfs_bmap_add_extent_hole_real( | |||
2106 | right.br_blockcount, &i))) | 2152 | right.br_blockcount, &i))) |
2107 | goto done; | 2153 | goto done; |
2108 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 2154 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
2109 | if ((error = xfs_bmbt_delete(cur, &i))) | 2155 | if ((error = xfs_btree_delete(cur, &i))) |
2110 | goto done; | 2156 | goto done; |
2111 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 2157 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
2112 | if ((error = xfs_bmbt_decrement(cur, 0, &i))) | 2158 | if ((error = xfs_btree_decrement(cur, 0, &i))) |
2113 | goto done; | 2159 | goto done; |
2114 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 2160 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
2115 | if ((error = xfs_bmbt_update(cur, left.br_startoff, | 2161 | if ((error = xfs_bmbt_update(cur, left.br_startoff, |
@@ -2218,7 +2264,7 @@ xfs_bmap_add_extent_hole_real( | |||
2218 | goto done; | 2264 | goto done; |
2219 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); | 2265 | XFS_WANT_CORRUPTED_GOTO(i == 0, done); |
2220 | cur->bc_rec.b.br_state = new->br_state; | 2266 | cur->bc_rec.b.br_state = new->br_state; |
2221 | if ((error = xfs_bmbt_insert(cur, &i))) | 2267 | if ((error = xfs_btree_insert(cur, &i))) |
2222 | goto done; | 2268 | goto done; |
2223 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 2269 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
2224 | } | 2270 | } |
@@ -2996,24 +3042,24 @@ xfs_bmap_btree_to_extents( | |||
2996 | int whichfork) /* data or attr fork */ | 3042 | int whichfork) /* data or attr fork */ |
2997 | { | 3043 | { |
2998 | /* REFERENCED */ | 3044 | /* REFERENCED */ |
2999 | xfs_bmbt_block_t *cblock;/* child btree block */ | 3045 | struct xfs_btree_block *cblock;/* child btree block */ |
3000 | xfs_fsblock_t cbno; /* child block number */ | 3046 | xfs_fsblock_t cbno; /* child block number */ |
3001 | xfs_buf_t *cbp; /* child block's buffer */ | 3047 | xfs_buf_t *cbp; /* child block's buffer */ |
3002 | int error; /* error return value */ | 3048 | int error; /* error return value */ |
3003 | xfs_ifork_t *ifp; /* inode fork data */ | 3049 | xfs_ifork_t *ifp; /* inode fork data */ |
3004 | xfs_mount_t *mp; /* mount point structure */ | 3050 | xfs_mount_t *mp; /* mount point structure */ |
3005 | __be64 *pp; /* ptr to block address */ | 3051 | __be64 *pp; /* ptr to block address */ |
3006 | xfs_bmbt_block_t *rblock;/* root btree block */ | 3052 | struct xfs_btree_block *rblock;/* root btree block */ |
3007 | 3053 | ||
3054 | mp = ip->i_mount; | ||
3008 | ifp = XFS_IFORK_PTR(ip, whichfork); | 3055 | ifp = XFS_IFORK_PTR(ip, whichfork); |
3009 | ASSERT(ifp->if_flags & XFS_IFEXTENTS); | 3056 | ASSERT(ifp->if_flags & XFS_IFEXTENTS); |
3010 | ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE); | 3057 | ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE); |
3011 | rblock = ifp->if_broot; | 3058 | rblock = ifp->if_broot; |
3012 | ASSERT(be16_to_cpu(rblock->bb_level) == 1); | 3059 | ASSERT(be16_to_cpu(rblock->bb_level) == 1); |
3013 | ASSERT(be16_to_cpu(rblock->bb_numrecs) == 1); | 3060 | ASSERT(be16_to_cpu(rblock->bb_numrecs) == 1); |
3014 | ASSERT(XFS_BMAP_BROOT_MAXRECS(ifp->if_broot_bytes) == 1); | 3061 | ASSERT(xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0) == 1); |
3015 | mp = ip->i_mount; | 3062 | pp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, ifp->if_broot_bytes); |
3016 | pp = XFS_BMAP_BROOT_PTR_ADDR(rblock, 1, ifp->if_broot_bytes); | ||
3017 | cbno = be64_to_cpu(*pp); | 3063 | cbno = be64_to_cpu(*pp); |
3018 | *logflagsp = 0; | 3064 | *logflagsp = 0; |
3019 | #ifdef DEBUG | 3065 | #ifdef DEBUG |
@@ -3023,8 +3069,8 @@ xfs_bmap_btree_to_extents( | |||
3023 | if ((error = xfs_btree_read_bufl(mp, tp, cbno, 0, &cbp, | 3069 | if ((error = xfs_btree_read_bufl(mp, tp, cbno, 0, &cbp, |
3024 | XFS_BMAP_BTREE_REF))) | 3070 | XFS_BMAP_BTREE_REF))) |
3025 | return error; | 3071 | return error; |
3026 | cblock = XFS_BUF_TO_BMBT_BLOCK(cbp); | 3072 | cblock = XFS_BUF_TO_BLOCK(cbp); |
3027 | if ((error = xfs_btree_check_lblock(cur, cblock, 0, cbp))) | 3073 | if ((error = xfs_btree_check_block(cur, cblock, 0, cbp))) |
3028 | return error; | 3074 | return error; |
3029 | xfs_bmap_add_free(cbno, 1, cur->bc_private.b.flist, mp); | 3075 | xfs_bmap_add_free(cbno, 1, cur->bc_private.b.flist, mp); |
3030 | ip->i_d.di_nblocks--; | 3076 | ip->i_d.di_nblocks--; |
@@ -3170,7 +3216,7 @@ xfs_bmap_del_extent( | |||
3170 | flags |= XFS_ILOG_FEXT(whichfork); | 3216 | flags |= XFS_ILOG_FEXT(whichfork); |
3171 | break; | 3217 | break; |
3172 | } | 3218 | } |
3173 | if ((error = xfs_bmbt_delete(cur, &i))) | 3219 | if ((error = xfs_btree_delete(cur, &i))) |
3174 | goto done; | 3220 | goto done; |
3175 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); | 3221 | XFS_WANT_CORRUPTED_GOTO(i == 1, done); |
3176 | break; | 3222 | break; |
@@ -3254,10 +3300,10 @@ xfs_bmap_del_extent( | |||
3254 | got.br_startblock, temp, | 3300 | got.br_startblock, temp, |
3255 | got.br_state))) | 3301 | got.br_state))) |
3256 | goto done; | 3302 | goto done; |
3257 | if ((error = xfs_bmbt_increment(cur, 0, &i))) | 3303 | if ((error = xfs_btree_increment(cur, 0, &i))) |
3258 | goto done; | 3304 | goto done; |
3259 | cur->bc_rec.b = new; | 3305 | cur->bc_rec.b = new; |
3260 | error = xfs_bmbt_insert(cur, &i); | 3306 | error = xfs_btree_insert(cur, &i); |
3261 | if (error && error != ENOSPC) | 3307 | if (error && error != ENOSPC) |
3262 | goto done; | 3308 | goto done; |
3263 | /* | 3309 | /* |
@@ -3404,11 +3450,11 @@ xfs_bmap_extents_to_btree( | |||
3404 | int *logflagsp, /* inode logging flags */ | 3450 | int *logflagsp, /* inode logging flags */ |
3405 | int whichfork) /* data or attr fork */ | 3451 | int whichfork) /* data or attr fork */ |
3406 | { | 3452 | { |
3407 | xfs_bmbt_block_t *ablock; /* allocated (child) bt block */ | 3453 | struct xfs_btree_block *ablock; /* allocated (child) bt block */ |
3408 | xfs_buf_t *abp; /* buffer for ablock */ | 3454 | xfs_buf_t *abp; /* buffer for ablock */ |
3409 | xfs_alloc_arg_t args; /* allocation arguments */ | 3455 | xfs_alloc_arg_t args; /* allocation arguments */ |
3410 | xfs_bmbt_rec_t *arp; /* child record pointer */ | 3456 | xfs_bmbt_rec_t *arp; /* child record pointer */ |
3411 | xfs_bmbt_block_t *block; /* btree root block */ | 3457 | struct xfs_btree_block *block; /* btree root block */ |
3412 | xfs_btree_cur_t *cur; /* bmap btree cursor */ | 3458 | xfs_btree_cur_t *cur; /* bmap btree cursor */ |
3413 | xfs_bmbt_rec_host_t *ep; /* extent record pointer */ | 3459 | xfs_bmbt_rec_host_t *ep; /* extent record pointer */ |
3414 | int error; /* error return value */ | 3460 | int error; /* error return value */ |
@@ -3428,6 +3474,7 @@ xfs_bmap_extents_to_btree( | |||
3428 | */ | 3474 | */ |
3429 | xfs_iroot_realloc(ip, 1, whichfork); | 3475 | xfs_iroot_realloc(ip, 1, whichfork); |
3430 | ifp->if_flags |= XFS_IFBROOT; | 3476 | ifp->if_flags |= XFS_IFBROOT; |
3477 | |||
3431 | /* | 3478 | /* |
3432 | * Fill in the root. | 3479 | * Fill in the root. |
3433 | */ | 3480 | */ |
@@ -3435,14 +3482,14 @@ xfs_bmap_extents_to_btree( | |||
3435 | block->bb_magic = cpu_to_be32(XFS_BMAP_MAGIC); | 3482 | block->bb_magic = cpu_to_be32(XFS_BMAP_MAGIC); |
3436 | block->bb_level = cpu_to_be16(1); | 3483 | block->bb_level = cpu_to_be16(1); |
3437 | block->bb_numrecs = cpu_to_be16(1); | 3484 | block->bb_numrecs = cpu_to_be16(1); |
3438 | block->bb_leftsib = cpu_to_be64(NULLDFSBNO); | 3485 | block->bb_u.l.bb_leftsib = cpu_to_be64(NULLDFSBNO); |
3439 | block->bb_rightsib = cpu_to_be64(NULLDFSBNO); | 3486 | block->bb_u.l.bb_rightsib = cpu_to_be64(NULLDFSBNO); |
3487 | |||
3440 | /* | 3488 | /* |
3441 | * Need a cursor. Can't allocate until bb_level is filled in. | 3489 | * Need a cursor. Can't allocate until bb_level is filled in. |
3442 | */ | 3490 | */ |
3443 | mp = ip->i_mount; | 3491 | mp = ip->i_mount; |
3444 | cur = xfs_btree_init_cursor(mp, tp, NULL, 0, XFS_BTNUM_BMAP, ip, | 3492 | cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); |
3445 | whichfork); | ||
3446 | cur->bc_private.b.firstblock = *firstblock; | 3493 | cur->bc_private.b.firstblock = *firstblock; |
3447 | cur->bc_private.b.flist = flist; | 3494 | cur->bc_private.b.flist = flist; |
3448 | cur->bc_private.b.flags = wasdel ? XFS_BTCUR_BPRV_WASDEL : 0; | 3495 | cur->bc_private.b.flags = wasdel ? XFS_BTCUR_BPRV_WASDEL : 0; |
@@ -3489,12 +3536,12 @@ xfs_bmap_extents_to_btree( | |||
3489 | /* | 3536 | /* |
3490 | * Fill in the child block. | 3537 | * Fill in the child block. |
3491 | */ | 3538 | */ |
3492 | ablock = XFS_BUF_TO_BMBT_BLOCK(abp); | 3539 | ablock = XFS_BUF_TO_BLOCK(abp); |
3493 | ablock->bb_magic = cpu_to_be32(XFS_BMAP_MAGIC); | 3540 | ablock->bb_magic = cpu_to_be32(XFS_BMAP_MAGIC); |
3494 | ablock->bb_level = 0; | 3541 | ablock->bb_level = 0; |
3495 | ablock->bb_leftsib = cpu_to_be64(NULLDFSBNO); | 3542 | ablock->bb_u.l.bb_leftsib = cpu_to_be64(NULLDFSBNO); |
3496 | ablock->bb_rightsib = cpu_to_be64(NULLDFSBNO); | 3543 | ablock->bb_u.l.bb_rightsib = cpu_to_be64(NULLDFSBNO); |
3497 | arp = XFS_BMAP_REC_IADDR(ablock, 1, cur); | 3544 | arp = XFS_BMBT_REC_ADDR(mp, ablock, 1); |
3498 | nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); | 3545 | nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); |
3499 | for (cnt = i = 0; i < nextents; i++) { | 3546 | for (cnt = i = 0; i < nextents; i++) { |
3500 | ep = xfs_iext_get_ext(ifp, i); | 3547 | ep = xfs_iext_get_ext(ifp, i); |
@@ -3505,21 +3552,24 @@ xfs_bmap_extents_to_btree( | |||
3505 | } | 3552 | } |
3506 | } | 3553 | } |
3507 | ASSERT(cnt == XFS_IFORK_NEXTENTS(ip, whichfork)); | 3554 | ASSERT(cnt == XFS_IFORK_NEXTENTS(ip, whichfork)); |
3508 | ablock->bb_numrecs = cpu_to_be16(cnt); | 3555 | xfs_btree_set_numrecs(ablock, cnt); |
3556 | |||
3509 | /* | 3557 | /* |
3510 | * Fill in the root key and pointer. | 3558 | * Fill in the root key and pointer. |
3511 | */ | 3559 | */ |
3512 | kp = XFS_BMAP_KEY_IADDR(block, 1, cur); | 3560 | kp = XFS_BMBT_KEY_ADDR(mp, block, 1); |
3513 | arp = XFS_BMAP_REC_IADDR(ablock, 1, cur); | 3561 | arp = XFS_BMBT_REC_ADDR(mp, ablock, 1); |
3514 | kp->br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(arp)); | 3562 | kp->br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(arp)); |
3515 | pp = XFS_BMAP_PTR_IADDR(block, 1, cur); | 3563 | pp = XFS_BMBT_PTR_ADDR(mp, block, 1, xfs_bmbt_get_maxrecs(cur, |
3564 | be16_to_cpu(block->bb_level))); | ||
3516 | *pp = cpu_to_be64(args.fsbno); | 3565 | *pp = cpu_to_be64(args.fsbno); |
3566 | |||
3517 | /* | 3567 | /* |
3518 | * Do all this logging at the end so that | 3568 | * Do all this logging at the end so that |
3519 | * the root is at the right level. | 3569 | * the root is at the right level. |
3520 | */ | 3570 | */ |
3521 | xfs_bmbt_log_block(cur, abp, XFS_BB_ALL_BITS); | 3571 | xfs_btree_log_block(cur, abp, XFS_BB_ALL_BITS); |
3522 | xfs_bmbt_log_recs(cur, abp, 1, be16_to_cpu(ablock->bb_numrecs)); | 3572 | xfs_btree_log_recs(cur, abp, 1, be16_to_cpu(ablock->bb_numrecs)); |
3523 | ASSERT(*curp == NULL); | 3573 | ASSERT(*curp == NULL); |
3524 | *curp = cur; | 3574 | *curp = cur; |
3525 | *logflagsp = XFS_ILOG_CORE | XFS_ILOG_FBROOT(whichfork); | 3575 | *logflagsp = XFS_ILOG_CORE | XFS_ILOG_FBROOT(whichfork); |
@@ -4176,7 +4226,7 @@ xfs_bmap_compute_maxlevels( | |||
4176 | maxleafents = MAXAEXTNUM; | 4226 | maxleafents = MAXAEXTNUM; |
4177 | sz = XFS_BMDR_SPACE_CALC(MINABTPTRS); | 4227 | sz = XFS_BMDR_SPACE_CALC(MINABTPTRS); |
4178 | } | 4228 | } |
4179 | maxrootrecs = (int)XFS_BTREE_BLOCK_MAXRECS(sz, xfs_bmdr, 0); | 4229 | maxrootrecs = xfs_bmdr_maxrecs(mp, sz, 0); |
4180 | minleafrecs = mp->m_bmap_dmnr[0]; | 4230 | minleafrecs = mp->m_bmap_dmnr[0]; |
4181 | minnoderecs = mp->m_bmap_dmnr[1]; | 4231 | minnoderecs = mp->m_bmap_dmnr[1]; |
4182 | maxblocks = (maxleafents + minleafrecs - 1) / minleafrecs; | 4232 | maxblocks = (maxleafents + minleafrecs - 1) / minleafrecs; |
@@ -4242,9 +4292,15 @@ xfs_bmap_finish( | |||
4242 | * We have a new transaction, so we should return committed=1, | 4292 | * We have a new transaction, so we should return committed=1, |
4243 | * even though we're returning an error. | 4293 | * even though we're returning an error. |
4244 | */ | 4294 | */ |
4245 | if (error) { | 4295 | if (error) |
4246 | return error; | 4296 | return error; |
4247 | } | 4297 | |
4298 | /* | ||
4299 | * transaction commit worked ok so we can drop the extra ticket | ||
4300 | * reference that we gained in xfs_trans_dup() | ||
4301 | */ | ||
4302 | xfs_log_ticket_put(ntp->t_ticket); | ||
4303 | |||
4248 | if ((error = xfs_trans_reserve(ntp, 0, logres, 0, XFS_TRANS_PERM_LOG_RES, | 4304 | if ((error = xfs_trans_reserve(ntp, 0, logres, 0, XFS_TRANS_PERM_LOG_RES, |
4249 | logcount))) | 4305 | logcount))) |
4250 | return error; | 4306 | return error; |
@@ -4474,6 +4530,22 @@ xfs_bmap_one_block( | |||
4474 | return rval; | 4530 | return rval; |
4475 | } | 4531 | } |
4476 | 4532 | ||
4533 | STATIC int | ||
4534 | xfs_bmap_sanity_check( | ||
4535 | struct xfs_mount *mp, | ||
4536 | struct xfs_buf *bp, | ||
4537 | int level) | ||
4538 | { | ||
4539 | struct xfs_btree_block *block = XFS_BUF_TO_BLOCK(bp); | ||
4540 | |||
4541 | if (be32_to_cpu(block->bb_magic) != XFS_BMAP_MAGIC || | ||
4542 | be16_to_cpu(block->bb_level) != level || | ||
4543 | be16_to_cpu(block->bb_numrecs) == 0 || | ||
4544 | be16_to_cpu(block->bb_numrecs) > mp->m_bmap_dmxr[level != 0]) | ||
4545 | return 0; | ||
4546 | return 1; | ||
4547 | } | ||
4548 | |||
4477 | /* | 4549 | /* |
4478 | * Read in the extents to if_extents. | 4550 | * Read in the extents to if_extents. |
4479 | * All inode fields are set up by caller, we just traverse the btree | 4551 | * All inode fields are set up by caller, we just traverse the btree |
@@ -4486,7 +4558,7 @@ xfs_bmap_read_extents( | |||
4486 | xfs_inode_t *ip, /* incore inode */ | 4558 | xfs_inode_t *ip, /* incore inode */ |
4487 | int whichfork) /* data or attr fork */ | 4559 | int whichfork) /* data or attr fork */ |
4488 | { | 4560 | { |
4489 | xfs_bmbt_block_t *block; /* current btree block */ | 4561 | struct xfs_btree_block *block; /* current btree block */ |
4490 | xfs_fsblock_t bno; /* block # of "block" */ | 4562 | xfs_fsblock_t bno; /* block # of "block" */ |
4491 | xfs_buf_t *bp; /* buffer for "block" */ | 4563 | xfs_buf_t *bp; /* buffer for "block" */ |
4492 | int error; /* error return value */ | 4564 | int error; /* error return value */ |
@@ -4510,7 +4582,7 @@ xfs_bmap_read_extents( | |||
4510 | */ | 4582 | */ |
4511 | level = be16_to_cpu(block->bb_level); | 4583 | level = be16_to_cpu(block->bb_level); |
4512 | ASSERT(level > 0); | 4584 | ASSERT(level > 0); |
4513 | pp = XFS_BMAP_BROOT_PTR_ADDR(block, 1, ifp->if_broot_bytes); | 4585 | pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes); |
4514 | bno = be64_to_cpu(*pp); | 4586 | bno = be64_to_cpu(*pp); |
4515 | ASSERT(bno != NULLDFSBNO); | 4587 | ASSERT(bno != NULLDFSBNO); |
4516 | ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount); | 4588 | ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount); |
@@ -4523,13 +4595,13 @@ xfs_bmap_read_extents( | |||
4523 | if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, | 4595 | if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, |
4524 | XFS_BMAP_BTREE_REF))) | 4596 | XFS_BMAP_BTREE_REF))) |
4525 | return error; | 4597 | return error; |
4526 | block = XFS_BUF_TO_BMBT_BLOCK(bp); | 4598 | block = XFS_BUF_TO_BLOCK(bp); |
4527 | XFS_WANT_CORRUPTED_GOTO( | 4599 | XFS_WANT_CORRUPTED_GOTO( |
4528 | XFS_BMAP_SANITY_CHECK(mp, block, level), | 4600 | xfs_bmap_sanity_check(mp, bp, level), |
4529 | error0); | 4601 | error0); |
4530 | if (level == 0) | 4602 | if (level == 0) |
4531 | break; | 4603 | break; |
4532 | pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, 1, mp->m_bmap_dmxr[1]); | 4604 | pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]); |
4533 | bno = be64_to_cpu(*pp); | 4605 | bno = be64_to_cpu(*pp); |
4534 | XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); | 4606 | XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); |
4535 | xfs_trans_brelse(tp, bp); | 4607 | xfs_trans_brelse(tp, bp); |
@@ -4549,7 +4621,7 @@ xfs_bmap_read_extents( | |||
4549 | xfs_extnum_t start; | 4621 | xfs_extnum_t start; |
4550 | 4622 | ||
4551 | 4623 | ||
4552 | num_recs = be16_to_cpu(block->bb_numrecs); | 4624 | num_recs = xfs_btree_get_numrecs(block); |
4553 | if (unlikely(i + num_recs > room)) { | 4625 | if (unlikely(i + num_recs > room)) { |
4554 | ASSERT(i + num_recs <= room); | 4626 | ASSERT(i + num_recs <= room); |
4555 | xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount, | 4627 | xfs_fs_repair_cmn_err(CE_WARN, ip->i_mount, |
@@ -4561,18 +4633,18 @@ xfs_bmap_read_extents( | |||
4561 | goto error0; | 4633 | goto error0; |
4562 | } | 4634 | } |
4563 | XFS_WANT_CORRUPTED_GOTO( | 4635 | XFS_WANT_CORRUPTED_GOTO( |
4564 | XFS_BMAP_SANITY_CHECK(mp, block, 0), | 4636 | xfs_bmap_sanity_check(mp, bp, 0), |
4565 | error0); | 4637 | error0); |
4566 | /* | 4638 | /* |
4567 | * Read-ahead the next leaf block, if any. | 4639 | * Read-ahead the next leaf block, if any. |
4568 | */ | 4640 | */ |
4569 | nextbno = be64_to_cpu(block->bb_rightsib); | 4641 | nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); |
4570 | if (nextbno != NULLFSBLOCK) | 4642 | if (nextbno != NULLFSBLOCK) |
4571 | xfs_btree_reada_bufl(mp, nextbno, 1); | 4643 | xfs_btree_reada_bufl(mp, nextbno, 1); |
4572 | /* | 4644 | /* |
4573 | * Copy records into the extent records. | 4645 | * Copy records into the extent records. |
4574 | */ | 4646 | */ |
4575 | frp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, 1); | 4647 | frp = XFS_BMBT_REC_ADDR(mp, block, 1); |
4576 | start = i; | 4648 | start = i; |
4577 | for (j = 0; j < num_recs; j++, i++, frp++) { | 4649 | for (j = 0; j < num_recs; j++, i++, frp++) { |
4578 | xfs_bmbt_rec_host_t *trp = xfs_iext_get_ext(ifp, i); | 4650 | xfs_bmbt_rec_host_t *trp = xfs_iext_get_ext(ifp, i); |
@@ -4603,7 +4675,7 @@ xfs_bmap_read_extents( | |||
4603 | if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, | 4675 | if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, |
4604 | XFS_BMAP_BTREE_REF))) | 4676 | XFS_BMAP_BTREE_REF))) |
4605 | return error; | 4677 | return error; |
4606 | block = XFS_BUF_TO_BMBT_BLOCK(bp); | 4678 | block = XFS_BUF_TO_BLOCK(bp); |
4607 | } | 4679 | } |
4608 | ASSERT(i == (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t))); | 4680 | ASSERT(i == (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t))); |
4609 | ASSERT(i == XFS_IFORK_NEXTENTS(ip, whichfork)); | 4681 | ASSERT(i == XFS_IFORK_NEXTENTS(ip, whichfork)); |
@@ -5029,8 +5101,7 @@ xfs_bmapi( | |||
5029 | if (abno == NULLFSBLOCK) | 5101 | if (abno == NULLFSBLOCK) |
5030 | break; | 5102 | break; |
5031 | if ((ifp->if_flags & XFS_IFBROOT) && !cur) { | 5103 | if ((ifp->if_flags & XFS_IFBROOT) && !cur) { |
5032 | cur = xfs_btree_init_cursor(mp, | 5104 | cur = xfs_bmbt_init_cursor(mp, tp, |
5033 | tp, NULL, 0, XFS_BTNUM_BMAP, | ||
5034 | ip, whichfork); | 5105 | ip, whichfork); |
5035 | cur->bc_private.b.firstblock = | 5106 | cur->bc_private.b.firstblock = |
5036 | *firstblock; | 5107 | *firstblock; |
@@ -5147,9 +5218,8 @@ xfs_bmapi( | |||
5147 | */ | 5218 | */ |
5148 | ASSERT(mval->br_blockcount <= len); | 5219 | ASSERT(mval->br_blockcount <= len); |
5149 | if ((ifp->if_flags & XFS_IFBROOT) && !cur) { | 5220 | if ((ifp->if_flags & XFS_IFBROOT) && !cur) { |
5150 | cur = xfs_btree_init_cursor(mp, | 5221 | cur = xfs_bmbt_init_cursor(mp, |
5151 | tp, NULL, 0, XFS_BTNUM_BMAP, | 5222 | tp, ip, whichfork); |
5152 | ip, whichfork); | ||
5153 | cur->bc_private.b.firstblock = | 5223 | cur->bc_private.b.firstblock = |
5154 | *firstblock; | 5224 | *firstblock; |
5155 | cur->bc_private.b.flist = flist; | 5225 | cur->bc_private.b.flist = flist; |
@@ -5440,8 +5510,7 @@ xfs_bunmapi( | |||
5440 | logflags = 0; | 5510 | logflags = 0; |
5441 | if (ifp->if_flags & XFS_IFBROOT) { | 5511 | if (ifp->if_flags & XFS_IFBROOT) { |
5442 | ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE); | 5512 | ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE); |
5443 | cur = xfs_btree_init_cursor(mp, tp, NULL, 0, XFS_BTNUM_BMAP, ip, | 5513 | cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); |
5444 | whichfork); | ||
5445 | cur->bc_private.b.firstblock = *firstblock; | 5514 | cur->bc_private.b.firstblock = *firstblock; |
5446 | cur->bc_private.b.flist = flist; | 5515 | cur->bc_private.b.flist = flist; |
5447 | cur->bc_private.b.flags = 0; | 5516 | cur->bc_private.b.flags = 0; |
@@ -5742,14 +5811,17 @@ error0: | |||
5742 | STATIC int | 5811 | STATIC int |
5743 | xfs_getbmapx_fix_eof_hole( | 5812 | xfs_getbmapx_fix_eof_hole( |
5744 | xfs_inode_t *ip, /* xfs incore inode pointer */ | 5813 | xfs_inode_t *ip, /* xfs incore inode pointer */ |
5745 | struct getbmap *out, /* output structure */ | 5814 | struct getbmapx *out, /* output structure */ |
5746 | int prealloced, /* this is a file with | 5815 | int prealloced, /* this is a file with |
5747 | * preallocated data space */ | 5816 | * preallocated data space */ |
5748 | __int64_t end, /* last block requested */ | 5817 | __int64_t end, /* last block requested */ |
5749 | xfs_fsblock_t startblock) | 5818 | xfs_fsblock_t startblock) |
5750 | { | 5819 | { |
5751 | __int64_t fixlen; | 5820 | __int64_t fixlen; |
5752 | xfs_mount_t *mp; /* file system mount point */ | 5821 | xfs_mount_t *mp; /* file system mount point */ |
5822 | xfs_ifork_t *ifp; /* inode fork pointer */ | ||
5823 | xfs_extnum_t lastx; /* last extent pointer */ | ||
5824 | xfs_fileoff_t fileblock; | ||
5753 | 5825 | ||
5754 | if (startblock == HOLESTARTBLOCK) { | 5826 | if (startblock == HOLESTARTBLOCK) { |
5755 | mp = ip->i_mount; | 5827 | mp = ip->i_mount; |
@@ -5763,21 +5835,33 @@ xfs_getbmapx_fix_eof_hole( | |||
5763 | out->bmv_length = fixlen; | 5835 | out->bmv_length = fixlen; |
5764 | } | 5836 | } |
5765 | } else { | 5837 | } else { |
5766 | out->bmv_block = XFS_FSB_TO_DB(ip, startblock); | 5838 | if (startblock == DELAYSTARTBLOCK) |
5839 | out->bmv_block = -2; | ||
5840 | else | ||
5841 | out->bmv_block = XFS_FSB_TO_DB(ip, startblock); | ||
5842 | fileblock = XFS_BB_TO_FSB(ip->i_mount, out->bmv_offset); | ||
5843 | ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); | ||
5844 | if (xfs_iext_bno_to_ext(ifp, fileblock, &lastx) && | ||
5845 | (lastx == (ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t))-1)) | ||
5846 | out->bmv_oflags |= BMV_OF_LAST; | ||
5767 | } | 5847 | } |
5768 | 5848 | ||
5769 | return 1; | 5849 | return 1; |
5770 | } | 5850 | } |
5771 | 5851 | ||
5772 | /* | 5852 | /* |
5773 | * Fcntl interface to xfs_bmapi. | 5853 | * Get inode's extents as described in bmv, and format for output. |
5854 | * Calls formatter to fill the user's buffer until all extents | ||
5855 | * are mapped, until the passed-in bmv->bmv_count slots have | ||
5856 | * been filled, or until the formatter short-circuits the loop, | ||
5857 | * if it is tracking filled-in extents on its own. | ||
5774 | */ | 5858 | */ |
5775 | int /* error code */ | 5859 | int /* error code */ |
5776 | xfs_getbmap( | 5860 | xfs_getbmap( |
5777 | xfs_inode_t *ip, | 5861 | xfs_inode_t *ip, |
5778 | struct getbmap *bmv, /* user bmap structure */ | 5862 | struct getbmapx *bmv, /* user bmap structure */ |
5779 | void __user *ap, /* pointer to user's array */ | 5863 | xfs_bmap_format_t formatter, /* format to user */ |
5780 | int interface) /* interface flags */ | 5864 | void *arg) /* formatter arg */ |
5781 | { | 5865 | { |
5782 | __int64_t bmvend; /* last block requested */ | 5866 | __int64_t bmvend; /* last block requested */ |
5783 | int error; /* return value */ | 5867 | int error; /* return value */ |
@@ -5790,19 +5874,17 @@ xfs_getbmap( | |||
5790 | int nexleft; /* # of user extents left */ | 5874 | int nexleft; /* # of user extents left */ |
5791 | int subnex; /* # of bmapi's can do */ | 5875 | int subnex; /* # of bmapi's can do */ |
5792 | int nmap; /* number of map entries */ | 5876 | int nmap; /* number of map entries */ |
5793 | struct getbmap out; /* output structure */ | 5877 | struct getbmapx out; /* output structure */ |
5794 | int whichfork; /* data or attr fork */ | 5878 | int whichfork; /* data or attr fork */ |
5795 | int prealloced; /* this is a file with | 5879 | int prealloced; /* this is a file with |
5796 | * preallocated data space */ | 5880 | * preallocated data space */ |
5797 | int sh_unwritten; /* true, if unwritten */ | 5881 | int iflags; /* interface flags */ |
5798 | /* extents listed separately */ | ||
5799 | int bmapi_flags; /* flags for xfs_bmapi */ | 5882 | int bmapi_flags; /* flags for xfs_bmapi */ |
5800 | __int32_t oflags; /* getbmapx bmv_oflags field */ | ||
5801 | 5883 | ||
5802 | mp = ip->i_mount; | 5884 | mp = ip->i_mount; |
5885 | iflags = bmv->bmv_iflags; | ||
5803 | 5886 | ||
5804 | whichfork = interface & BMV_IF_ATTRFORK ? XFS_ATTR_FORK : XFS_DATA_FORK; | 5887 | whichfork = iflags & BMV_IF_ATTRFORK ? XFS_ATTR_FORK : XFS_DATA_FORK; |
5805 | sh_unwritten = (interface & BMV_IF_PREALLOC) != 0; | ||
5806 | 5888 | ||
5807 | /* If the BMV_IF_NO_DMAPI_READ interface bit specified, do not | 5889 | /* If the BMV_IF_NO_DMAPI_READ interface bit specified, do not |
5808 | * generate a DMAPI read event. Otherwise, if the DM_EVENT_READ | 5890 | * generate a DMAPI read event. Otherwise, if the DM_EVENT_READ |
@@ -5817,7 +5899,7 @@ xfs_getbmap( | |||
5817 | * could misinterpret holes in a DMAPI file as true holes, | 5899 | * could misinterpret holes in a DMAPI file as true holes, |
5818 | * when in fact they may represent offline user data. | 5900 | * when in fact they may represent offline user data. |
5819 | */ | 5901 | */ |
5820 | if ((interface & BMV_IF_NO_DMAPI_READ) == 0 && | 5902 | if ((iflags & BMV_IF_NO_DMAPI_READ) == 0 && |
5821 | DM_EVENT_ENABLED(ip, DM_EVENT_READ) && | 5903 | DM_EVENT_ENABLED(ip, DM_EVENT_READ) && |
5822 | whichfork == XFS_DATA_FORK) { | 5904 | whichfork == XFS_DATA_FORK) { |
5823 | error = XFS_SEND_DATA(mp, DM_EVENT_READ, ip, 0, 0, 0, NULL); | 5905 | error = XFS_SEND_DATA(mp, DM_EVENT_READ, ip, 0, 0, 0, NULL); |
@@ -5873,8 +5955,9 @@ xfs_getbmap( | |||
5873 | 5955 | ||
5874 | xfs_ilock(ip, XFS_IOLOCK_SHARED); | 5956 | xfs_ilock(ip, XFS_IOLOCK_SHARED); |
5875 | 5957 | ||
5876 | if (whichfork == XFS_DATA_FORK && | 5958 | if (((iflags & BMV_IF_DELALLOC) == 0) && |
5877 | (ip->i_delayed_blks || ip->i_size > ip->i_d.di_size)) { | 5959 | (whichfork == XFS_DATA_FORK) && |
5960 | (ip->i_delayed_blks || ip->i_size > ip->i_d.di_size)) { | ||
5878 | /* xfs_fsize_t last_byte = xfs_file_last_byte(ip); */ | 5961 | /* xfs_fsize_t last_byte = xfs_file_last_byte(ip); */ |
5879 | error = xfs_flush_pages(ip, (xfs_off_t)0, | 5962 | error = xfs_flush_pages(ip, (xfs_off_t)0, |
5880 | -1, 0, FI_REMAPF); | 5963 | -1, 0, FI_REMAPF); |
@@ -5884,7 +5967,8 @@ xfs_getbmap( | |||
5884 | } | 5967 | } |
5885 | } | 5968 | } |
5886 | 5969 | ||
5887 | ASSERT(whichfork == XFS_ATTR_FORK || ip->i_delayed_blks == 0); | 5970 | ASSERT(whichfork == XFS_ATTR_FORK || (iflags & BMV_IF_DELALLOC) || |
5971 | ip->i_delayed_blks == 0); | ||
5888 | 5972 | ||
5889 | lock = xfs_ilock_map_shared(ip); | 5973 | lock = xfs_ilock_map_shared(ip); |
5890 | 5974 | ||
@@ -5896,7 +5980,7 @@ xfs_getbmap( | |||
5896 | nex = XFS_IFORK_NEXTENTS(ip, whichfork) * 2 + 1; | 5980 | nex = XFS_IFORK_NEXTENTS(ip, whichfork) * 2 + 1; |
5897 | 5981 | ||
5898 | bmapi_flags = XFS_BMAPI_AFLAG(whichfork) | | 5982 | bmapi_flags = XFS_BMAPI_AFLAG(whichfork) | |
5899 | ((sh_unwritten) ? 0 : XFS_BMAPI_IGSTATE); | 5983 | ((iflags & BMV_IF_PREALLOC) ? 0 : XFS_BMAPI_IGSTATE); |
5900 | 5984 | ||
5901 | /* | 5985 | /* |
5902 | * Allocate enough space to handle "subnex" maps at a time. | 5986 | * Allocate enough space to handle "subnex" maps at a time. |
@@ -5906,9 +5990,12 @@ xfs_getbmap( | |||
5906 | 5990 | ||
5907 | bmv->bmv_entries = 0; | 5991 | bmv->bmv_entries = 0; |
5908 | 5992 | ||
5909 | if (XFS_IFORK_NEXTENTS(ip, whichfork) == 0) { | 5993 | if ((XFS_IFORK_NEXTENTS(ip, whichfork) == 0)) { |
5910 | error = 0; | 5994 | if (((iflags & BMV_IF_DELALLOC) == 0) || |
5911 | goto unlock_and_return; | 5995 | whichfork == XFS_ATTR_FORK) { |
5996 | error = 0; | ||
5997 | goto unlock_and_return; | ||
5998 | } | ||
5912 | } | 5999 | } |
5913 | 6000 | ||
5914 | nexleft = nex; | 6001 | nexleft = nex; |
@@ -5924,52 +6011,40 @@ xfs_getbmap( | |||
5924 | ASSERT(nmap <= subnex); | 6011 | ASSERT(nmap <= subnex); |
5925 | 6012 | ||
5926 | for (i = 0; i < nmap && nexleft && bmv->bmv_length; i++) { | 6013 | for (i = 0; i < nmap && nexleft && bmv->bmv_length; i++) { |
5927 | nexleft--; | 6014 | out.bmv_oflags = 0; |
5928 | oflags = (map[i].br_state == XFS_EXT_UNWRITTEN) ? | 6015 | if (map[i].br_state == XFS_EXT_UNWRITTEN) |
5929 | BMV_OF_PREALLOC : 0; | 6016 | out.bmv_oflags |= BMV_OF_PREALLOC; |
6017 | else if (map[i].br_startblock == DELAYSTARTBLOCK) | ||
6018 | out.bmv_oflags |= BMV_OF_DELALLOC; | ||
5930 | out.bmv_offset = XFS_FSB_TO_BB(mp, map[i].br_startoff); | 6019 | out.bmv_offset = XFS_FSB_TO_BB(mp, map[i].br_startoff); |
5931 | out.bmv_length = XFS_FSB_TO_BB(mp, map[i].br_blockcount); | 6020 | out.bmv_length = XFS_FSB_TO_BB(mp, map[i].br_blockcount); |
5932 | ASSERT(map[i].br_startblock != DELAYSTARTBLOCK); | 6021 | out.bmv_unused1 = out.bmv_unused2 = 0; |
6022 | ASSERT(((iflags & BMV_IF_DELALLOC) != 0) || | ||
6023 | (map[i].br_startblock != DELAYSTARTBLOCK)); | ||
5933 | if (map[i].br_startblock == HOLESTARTBLOCK && | 6024 | if (map[i].br_startblock == HOLESTARTBLOCK && |
5934 | whichfork == XFS_ATTR_FORK) { | 6025 | whichfork == XFS_ATTR_FORK) { |
5935 | /* came to the end of attribute fork */ | 6026 | /* came to the end of attribute fork */ |
6027 | out.bmv_oflags |= BMV_OF_LAST; | ||
5936 | goto unlock_and_return; | 6028 | goto unlock_and_return; |
5937 | } else { | 6029 | } else { |
6030 | int full = 0; /* user array is full */ | ||
6031 | |||
5938 | if (!xfs_getbmapx_fix_eof_hole(ip, &out, | 6032 | if (!xfs_getbmapx_fix_eof_hole(ip, &out, |
5939 | prealloced, bmvend, | 6033 | prealloced, bmvend, |
5940 | map[i].br_startblock)) { | 6034 | map[i].br_startblock)) { |
5941 | goto unlock_and_return; | 6035 | goto unlock_and_return; |
5942 | } | 6036 | } |
5943 | 6037 | ||
5944 | /* return either getbmap/getbmapx structure. */ | 6038 | /* format results & advance arg */ |
5945 | if (interface & BMV_IF_EXTENDED) { | 6039 | error = formatter(&arg, &out, &full); |
5946 | struct getbmapx outx; | 6040 | if (error || full) |
5947 | 6041 | goto unlock_and_return; | |
5948 | GETBMAP_CONVERT(out,outx); | 6042 | nexleft--; |
5949 | outx.bmv_oflags = oflags; | ||
5950 | outx.bmv_unused1 = outx.bmv_unused2 = 0; | ||
5951 | if (copy_to_user(ap, &outx, | ||
5952 | sizeof(outx))) { | ||
5953 | error = XFS_ERROR(EFAULT); | ||
5954 | goto unlock_and_return; | ||
5955 | } | ||
5956 | } else { | ||
5957 | if (copy_to_user(ap, &out, | ||
5958 | sizeof(out))) { | ||
5959 | error = XFS_ERROR(EFAULT); | ||
5960 | goto unlock_and_return; | ||
5961 | } | ||
5962 | } | ||
5963 | bmv->bmv_offset = | 6043 | bmv->bmv_offset = |
5964 | out.bmv_offset + out.bmv_length; | 6044 | out.bmv_offset + out.bmv_length; |
5965 | bmv->bmv_length = MAX((__int64_t)0, | 6045 | bmv->bmv_length = MAX((__int64_t)0, |
5966 | (__int64_t)(bmvend - bmv->bmv_offset)); | 6046 | (__int64_t)(bmvend - bmv->bmv_offset)); |
5967 | bmv->bmv_entries++; | 6047 | bmv->bmv_entries++; |
5968 | ap = (interface & BMV_IF_EXTENDED) ? | ||
5969 | (void __user *) | ||
5970 | ((struct getbmapx __user *)ap + 1) : | ||
5971 | (void __user *) | ||
5972 | ((struct getbmap __user *)ap + 1); | ||
5973 | } | 6048 | } |
5974 | } | 6049 | } |
5975 | } while (nmap && nexleft && bmv->bmv_length); | 6050 | } while (nmap && nexleft && bmv->bmv_length); |
@@ -6131,7 +6206,7 @@ xfs_bmap_get_bp( | |||
6131 | 6206 | ||
6132 | void | 6207 | void |
6133 | xfs_check_block( | 6208 | xfs_check_block( |
6134 | xfs_bmbt_block_t *block, | 6209 | struct xfs_btree_block *block, |
6135 | xfs_mount_t *mp, | 6210 | xfs_mount_t *mp, |
6136 | int root, | 6211 | int root, |
6137 | short sz) | 6212 | short sz) |
@@ -6143,36 +6218,29 @@ xfs_check_block( | |||
6143 | ASSERT(be16_to_cpu(block->bb_level) > 0); | 6218 | ASSERT(be16_to_cpu(block->bb_level) > 0); |
6144 | 6219 | ||
6145 | prevp = NULL; | 6220 | prevp = NULL; |
6146 | for( i = 1; i <= be16_to_cpu(block->bb_numrecs); i++) { | 6221 | for( i = 1; i <= xfs_btree_get_numrecs(block); i++) { |
6147 | dmxr = mp->m_bmap_dmxr[0]; | 6222 | dmxr = mp->m_bmap_dmxr[0]; |
6148 | 6223 | keyp = XFS_BMBT_KEY_ADDR(mp, block, i); | |
6149 | if (root) { | ||
6150 | keyp = XFS_BMAP_BROOT_KEY_ADDR(block, i, sz); | ||
6151 | } else { | ||
6152 | keyp = XFS_BTREE_KEY_ADDR(xfs_bmbt, block, i); | ||
6153 | } | ||
6154 | 6224 | ||
6155 | if (prevp) { | 6225 | if (prevp) { |
6156 | xfs_btree_check_key(XFS_BTNUM_BMAP, prevp, keyp); | 6226 | ASSERT(be64_to_cpu(prevp->br_startoff) < |
6227 | be64_to_cpu(keyp->br_startoff)); | ||
6157 | } | 6228 | } |
6158 | prevp = keyp; | 6229 | prevp = keyp; |
6159 | 6230 | ||
6160 | /* | 6231 | /* |
6161 | * Compare the block numbers to see if there are dups. | 6232 | * Compare the block numbers to see if there are dups. |
6162 | */ | 6233 | */ |
6234 | if (root) | ||
6235 | pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, i, sz); | ||
6236 | else | ||
6237 | pp = XFS_BMBT_PTR_ADDR(mp, block, i, dmxr); | ||
6163 | 6238 | ||
6164 | if (root) { | ||
6165 | pp = XFS_BMAP_BROOT_PTR_ADDR(block, i, sz); | ||
6166 | } else { | ||
6167 | pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, i, dmxr); | ||
6168 | } | ||
6169 | for (j = i+1; j <= be16_to_cpu(block->bb_numrecs); j++) { | 6239 | for (j = i+1; j <= be16_to_cpu(block->bb_numrecs); j++) { |
6170 | if (root) { | 6240 | if (root) |
6171 | thispa = XFS_BMAP_BROOT_PTR_ADDR(block, j, sz); | 6241 | thispa = XFS_BMAP_BROOT_PTR_ADDR(mp, block, j, sz); |
6172 | } else { | 6242 | else |
6173 | thispa = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, j, | 6243 | thispa = XFS_BMBT_PTR_ADDR(mp, block, j, dmxr); |
6174 | dmxr); | ||
6175 | } | ||
6176 | if (*thispa == *pp) { | 6244 | if (*thispa == *pp) { |
6177 | cmn_err(CE_WARN, "%s: thispa(%d) == pp(%d) %Ld", | 6245 | cmn_err(CE_WARN, "%s: thispa(%d) == pp(%d) %Ld", |
6178 | __func__, j, i, | 6246 | __func__, j, i, |
@@ -6195,7 +6263,7 @@ xfs_bmap_check_leaf_extents( | |||
6195 | xfs_inode_t *ip, /* incore inode pointer */ | 6263 | xfs_inode_t *ip, /* incore inode pointer */ |
6196 | int whichfork) /* data or attr fork */ | 6264 | int whichfork) /* data or attr fork */ |
6197 | { | 6265 | { |
6198 | xfs_bmbt_block_t *block; /* current btree block */ | 6266 | struct xfs_btree_block *block; /* current btree block */ |
6199 | xfs_fsblock_t bno; /* block # of "block" */ | 6267 | xfs_fsblock_t bno; /* block # of "block" */ |
6200 | xfs_buf_t *bp; /* buffer for "block" */ | 6268 | xfs_buf_t *bp; /* buffer for "block" */ |
6201 | int error; /* error return value */ | 6269 | int error; /* error return value */ |
@@ -6223,7 +6291,7 @@ xfs_bmap_check_leaf_extents( | |||
6223 | level = be16_to_cpu(block->bb_level); | 6291 | level = be16_to_cpu(block->bb_level); |
6224 | ASSERT(level > 0); | 6292 | ASSERT(level > 0); |
6225 | xfs_check_block(block, mp, 1, ifp->if_broot_bytes); | 6293 | xfs_check_block(block, mp, 1, ifp->if_broot_bytes); |
6226 | pp = XFS_BMAP_BROOT_PTR_ADDR(block, 1, ifp->if_broot_bytes); | 6294 | pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes); |
6227 | bno = be64_to_cpu(*pp); | 6295 | bno = be64_to_cpu(*pp); |
6228 | 6296 | ||
6229 | ASSERT(bno != NULLDFSBNO); | 6297 | ASSERT(bno != NULLDFSBNO); |
@@ -6245,9 +6313,9 @@ xfs_bmap_check_leaf_extents( | |||
6245 | if (!bp && (error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp, | 6313 | if (!bp && (error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp, |
6246 | XFS_BMAP_BTREE_REF))) | 6314 | XFS_BMAP_BTREE_REF))) |
6247 | goto error_norelse; | 6315 | goto error_norelse; |
6248 | block = XFS_BUF_TO_BMBT_BLOCK(bp); | 6316 | block = XFS_BUF_TO_BLOCK(bp); |
6249 | XFS_WANT_CORRUPTED_GOTO( | 6317 | XFS_WANT_CORRUPTED_GOTO( |
6250 | XFS_BMAP_SANITY_CHECK(mp, block, level), | 6318 | xfs_bmap_sanity_check(mp, bp, level), |
6251 | error0); | 6319 | error0); |
6252 | if (level == 0) | 6320 | if (level == 0) |
6253 | break; | 6321 | break; |
@@ -6258,7 +6326,7 @@ xfs_bmap_check_leaf_extents( | |||
6258 | */ | 6326 | */ |
6259 | 6327 | ||
6260 | xfs_check_block(block, mp, 0, 0); | 6328 | xfs_check_block(block, mp, 0, 0); |
6261 | pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, 1, mp->m_bmap_dmxr[1]); | 6329 | pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]); |
6262 | bno = be64_to_cpu(*pp); | 6330 | bno = be64_to_cpu(*pp); |
6263 | XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); | 6331 | XFS_WANT_CORRUPTED_GOTO(XFS_FSB_SANITY_CHECK(mp, bno), error0); |
6264 | if (bp_release) { | 6332 | if (bp_release) { |
@@ -6280,13 +6348,13 @@ xfs_bmap_check_leaf_extents( | |||
6280 | xfs_extnum_t num_recs; | 6348 | xfs_extnum_t num_recs; |
6281 | 6349 | ||
6282 | 6350 | ||
6283 | num_recs = be16_to_cpu(block->bb_numrecs); | 6351 | num_recs = xfs_btree_get_numrecs(block); |
6284 | 6352 | ||
6285 | /* | 6353 | /* |
6286 | * Read-ahead the next leaf block, if any. | 6354 | * Read-ahead the next leaf block, if any. |
6287 | */ | 6355 | */ |
6288 | 6356 | ||
6289 | nextbno = be64_to_cpu(block->bb_rightsib); | 6357 | nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); |
6290 | 6358 | ||
6291 | /* | 6359 | /* |
6292 | * Check all the extents to make sure they are OK. | 6360 | * Check all the extents to make sure they are OK. |
@@ -6294,13 +6362,17 @@ xfs_bmap_check_leaf_extents( | |||
6294 | * conform with the first entry in this one. | 6362 | * conform with the first entry in this one. |
6295 | */ | 6363 | */ |
6296 | 6364 | ||
6297 | ep = XFS_BTREE_REC_ADDR(xfs_bmbt, block, 1); | 6365 | ep = XFS_BMBT_REC_ADDR(mp, block, 1); |
6298 | if (i) { | 6366 | if (i) { |
6299 | xfs_btree_check_rec(XFS_BTNUM_BMAP, &last, ep); | 6367 | ASSERT(xfs_bmbt_disk_get_startoff(&last) + |
6368 | xfs_bmbt_disk_get_blockcount(&last) <= | ||
6369 | xfs_bmbt_disk_get_startoff(ep)); | ||
6300 | } | 6370 | } |
6301 | for (j = 1; j < num_recs; j++) { | 6371 | for (j = 1; j < num_recs; j++) { |
6302 | nextp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, j + 1); | 6372 | nextp = XFS_BMBT_REC_ADDR(mp, block, j + 1); |
6303 | xfs_btree_check_rec(XFS_BTNUM_BMAP, ep, nextp); | 6373 | ASSERT(xfs_bmbt_disk_get_startoff(ep) + |
6374 | xfs_bmbt_disk_get_blockcount(ep) <= | ||
6375 | xfs_bmbt_disk_get_startoff(nextp)); | ||
6304 | ep = nextp; | 6376 | ep = nextp; |
6305 | } | 6377 | } |
6306 | 6378 | ||
@@ -6326,7 +6398,7 @@ xfs_bmap_check_leaf_extents( | |||
6326 | if (!bp && (error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp, | 6398 | if (!bp && (error = xfs_btree_read_bufl(mp, NULL, bno, 0, &bp, |
6327 | XFS_BMAP_BTREE_REF))) | 6399 | XFS_BMAP_BTREE_REF))) |
6328 | goto error_norelse; | 6400 | goto error_norelse; |
6329 | block = XFS_BUF_TO_BMBT_BLOCK(bp); | 6401 | block = XFS_BUF_TO_BLOCK(bp); |
6330 | } | 6402 | } |
6331 | if (bp_release) { | 6403 | if (bp_release) { |
6332 | bp_release = 0; | 6404 | bp_release = 0; |
@@ -6356,7 +6428,7 @@ xfs_bmap_count_blocks( | |||
6356 | int whichfork, /* data or attr fork */ | 6428 | int whichfork, /* data or attr fork */ |
6357 | int *count) /* out: count of blocks */ | 6429 | int *count) /* out: count of blocks */ |
6358 | { | 6430 | { |
6359 | xfs_bmbt_block_t *block; /* current btree block */ | 6431 | struct xfs_btree_block *block; /* current btree block */ |
6360 | xfs_fsblock_t bno; /* block # of "block" */ | 6432 | xfs_fsblock_t bno; /* block # of "block" */ |
6361 | xfs_ifork_t *ifp; /* fork structure */ | 6433 | xfs_ifork_t *ifp; /* fork structure */ |
6362 | int level; /* btree level, for checking */ | 6434 | int level; /* btree level, for checking */ |
@@ -6379,7 +6451,7 @@ xfs_bmap_count_blocks( | |||
6379 | block = ifp->if_broot; | 6451 | block = ifp->if_broot; |
6380 | level = be16_to_cpu(block->bb_level); | 6452 | level = be16_to_cpu(block->bb_level); |
6381 | ASSERT(level > 0); | 6453 | ASSERT(level > 0); |
6382 | pp = XFS_BMAP_BROOT_PTR_ADDR(block, 1, ifp->if_broot_bytes); | 6454 | pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes); |
6383 | bno = be64_to_cpu(*pp); | 6455 | bno = be64_to_cpu(*pp); |
6384 | ASSERT(bno != NULLDFSBNO); | 6456 | ASSERT(bno != NULLDFSBNO); |
6385 | ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount); | 6457 | ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount); |
@@ -6413,29 +6485,29 @@ xfs_bmap_count_tree( | |||
6413 | __be64 *pp; | 6485 | __be64 *pp; |
6414 | xfs_fsblock_t bno = blockno; | 6486 | xfs_fsblock_t bno = blockno; |
6415 | xfs_fsblock_t nextbno; | 6487 | xfs_fsblock_t nextbno; |
6416 | xfs_bmbt_block_t *block, *nextblock; | 6488 | struct xfs_btree_block *block, *nextblock; |
6417 | int numrecs; | 6489 | int numrecs; |
6418 | 6490 | ||
6419 | if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, XFS_BMAP_BTREE_REF))) | 6491 | if ((error = xfs_btree_read_bufl(mp, tp, bno, 0, &bp, XFS_BMAP_BTREE_REF))) |
6420 | return error; | 6492 | return error; |
6421 | *count += 1; | 6493 | *count += 1; |
6422 | block = XFS_BUF_TO_BMBT_BLOCK(bp); | 6494 | block = XFS_BUF_TO_BLOCK(bp); |
6423 | 6495 | ||
6424 | if (--level) { | 6496 | if (--level) { |
6425 | /* Not at node above leafs, count this level of nodes */ | 6497 | /* Not at node above leafs, count this level of nodes */ |
6426 | nextbno = be64_to_cpu(block->bb_rightsib); | 6498 | nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); |
6427 | while (nextbno != NULLFSBLOCK) { | 6499 | while (nextbno != NULLFSBLOCK) { |
6428 | if ((error = xfs_btree_read_bufl(mp, tp, nextbno, | 6500 | if ((error = xfs_btree_read_bufl(mp, tp, nextbno, |
6429 | 0, &nbp, XFS_BMAP_BTREE_REF))) | 6501 | 0, &nbp, XFS_BMAP_BTREE_REF))) |
6430 | return error; | 6502 | return error; |
6431 | *count += 1; | 6503 | *count += 1; |
6432 | nextblock = XFS_BUF_TO_BMBT_BLOCK(nbp); | 6504 | nextblock = XFS_BUF_TO_BLOCK(nbp); |
6433 | nextbno = be64_to_cpu(nextblock->bb_rightsib); | 6505 | nextbno = be64_to_cpu(nextblock->bb_u.l.bb_rightsib); |
6434 | xfs_trans_brelse(tp, nbp); | 6506 | xfs_trans_brelse(tp, nbp); |
6435 | } | 6507 | } |
6436 | 6508 | ||
6437 | /* Dive to the next level */ | 6509 | /* Dive to the next level */ |
6438 | pp = XFS_BTREE_PTR_ADDR(xfs_bmbt, block, 1, mp->m_bmap_dmxr[1]); | 6510 | pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]); |
6439 | bno = be64_to_cpu(*pp); | 6511 | bno = be64_to_cpu(*pp); |
6440 | if (unlikely((error = | 6512 | if (unlikely((error = |
6441 | xfs_bmap_count_tree(mp, tp, ifp, bno, level, count)) < 0)) { | 6513 | xfs_bmap_count_tree(mp, tp, ifp, bno, level, count)) < 0)) { |
@@ -6448,9 +6520,9 @@ xfs_bmap_count_tree( | |||
6448 | } else { | 6520 | } else { |
6449 | /* count all level 1 nodes and their leaves */ | 6521 | /* count all level 1 nodes and their leaves */ |
6450 | for (;;) { | 6522 | for (;;) { |
6451 | nextbno = be64_to_cpu(block->bb_rightsib); | 6523 | nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); |
6452 | numrecs = be16_to_cpu(block->bb_numrecs); | 6524 | numrecs = be16_to_cpu(block->bb_numrecs); |
6453 | xfs_bmap_disk_count_leaves(0, block, numrecs, count); | 6525 | xfs_bmap_disk_count_leaves(mp, block, numrecs, count); |
6454 | xfs_trans_brelse(tp, bp); | 6526 | xfs_trans_brelse(tp, bp); |
6455 | if (nextbno == NULLFSBLOCK) | 6527 | if (nextbno == NULLFSBLOCK) |
6456 | break; | 6528 | break; |
@@ -6459,7 +6531,7 @@ xfs_bmap_count_tree( | |||
6459 | XFS_BMAP_BTREE_REF))) | 6531 | XFS_BMAP_BTREE_REF))) |
6460 | return error; | 6532 | return error; |
6461 | *count += 1; | 6533 | *count += 1; |
6462 | block = XFS_BUF_TO_BMBT_BLOCK(bp); | 6534 | block = XFS_BUF_TO_BLOCK(bp); |
6463 | } | 6535 | } |
6464 | } | 6536 | } |
6465 | return 0; | 6537 | return 0; |
@@ -6489,8 +6561,8 @@ xfs_bmap_count_leaves( | |||
6489 | */ | 6561 | */ |
6490 | STATIC void | 6562 | STATIC void |
6491 | xfs_bmap_disk_count_leaves( | 6563 | xfs_bmap_disk_count_leaves( |
6492 | xfs_extnum_t idx, | 6564 | struct xfs_mount *mp, |
6493 | xfs_bmbt_block_t *block, | 6565 | struct xfs_btree_block *block, |
6494 | int numrecs, | 6566 | int numrecs, |
6495 | int *count) | 6567 | int *count) |
6496 | { | 6568 | { |
@@ -6498,7 +6570,7 @@ xfs_bmap_disk_count_leaves( | |||
6498 | xfs_bmbt_rec_t *frp; | 6570 | xfs_bmbt_rec_t *frp; |
6499 | 6571 | ||
6500 | for (b = 1; b <= numrecs; b++) { | 6572 | for (b = 1; b <= numrecs; b++) { |
6501 | frp = XFS_BTREE_REC_ADDR(xfs_bmbt, block, idx + b); | 6573 | frp = XFS_BMBT_REC_ADDR(mp, block, b); |
6502 | *count += xfs_bmbt_disk_get_blockcount(frp); | 6574 | *count += xfs_bmbt_disk_get_blockcount(frp); |
6503 | } | 6575 | } |
6504 | } | 6576 | } |