aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_leaf.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_dir2_leaf.c')
-rw-r--r--fs/xfs/xfs_dir2_leaf.c621
1 files changed, 321 insertions, 300 deletions
diff --git a/fs/xfs/xfs_dir2_leaf.c b/fs/xfs/xfs_dir2_leaf.c
index 397ffbcbab1d..0b296253bd01 100644
--- a/fs/xfs/xfs_dir2_leaf.c
+++ b/fs/xfs/xfs_dir2_leaf.c
@@ -38,15 +38,15 @@
38 * Local function declarations. 38 * Local function declarations.
39 */ 39 */
40#ifdef DEBUG 40#ifdef DEBUG
41static void xfs_dir2_leaf_check(xfs_inode_t *dp, xfs_dabuf_t *bp); 41static void xfs_dir2_leaf_check(struct xfs_inode *dp, struct xfs_buf *bp);
42#else 42#else
43#define xfs_dir2_leaf_check(dp, bp) 43#define xfs_dir2_leaf_check(dp, bp)
44#endif 44#endif
45static int xfs_dir2_leaf_lookup_int(xfs_da_args_t *args, xfs_dabuf_t **lbpp, 45static int xfs_dir2_leaf_lookup_int(xfs_da_args_t *args, struct xfs_buf **lbpp,
46 int *indexp, xfs_dabuf_t **dbpp); 46 int *indexp, struct xfs_buf **dbpp);
47static void xfs_dir2_leaf_log_bests(struct xfs_trans *tp, struct xfs_dabuf *bp, 47static void xfs_dir2_leaf_log_bests(struct xfs_trans *tp, struct xfs_buf *bp,
48 int first, int last); 48 int first, int last);
49static void xfs_dir2_leaf_log_tail(struct xfs_trans *tp, struct xfs_dabuf *bp); 49static void xfs_dir2_leaf_log_tail(struct xfs_trans *tp, struct xfs_buf *bp);
50 50
51 51
52/* 52/*
@@ -55,7 +55,7 @@ static void xfs_dir2_leaf_log_tail(struct xfs_trans *tp, struct xfs_dabuf *bp);
55int /* error */ 55int /* error */
56xfs_dir2_block_to_leaf( 56xfs_dir2_block_to_leaf(
57 xfs_da_args_t *args, /* operation arguments */ 57 xfs_da_args_t *args, /* operation arguments */
58 xfs_dabuf_t *dbp) /* input block's buffer */ 58 struct xfs_buf *dbp) /* input block's buffer */
59{ 59{
60 __be16 *bestsp; /* leaf's bestsp entries */ 60 __be16 *bestsp; /* leaf's bestsp entries */
61 xfs_dablk_t blkno; /* leaf block's bno */ 61 xfs_dablk_t blkno; /* leaf block's bno */
@@ -64,7 +64,7 @@ xfs_dir2_block_to_leaf(
64 xfs_dir2_block_tail_t *btp; /* block's tail */ 64 xfs_dir2_block_tail_t *btp; /* block's tail */
65 xfs_inode_t *dp; /* incore directory inode */ 65 xfs_inode_t *dp; /* incore directory inode */
66 int error; /* error return code */ 66 int error; /* error return code */
67 xfs_dabuf_t *lbp; /* leaf block's buffer */ 67 struct xfs_buf *lbp; /* leaf block's buffer */
68 xfs_dir2_db_t ldb; /* leaf block's bno */ 68 xfs_dir2_db_t ldb; /* leaf block's bno */
69 xfs_dir2_leaf_t *leaf; /* leaf structure */ 69 xfs_dir2_leaf_t *leaf; /* leaf structure */
70 xfs_dir2_leaf_tail_t *ltp; /* leaf's tail */ 70 xfs_dir2_leaf_tail_t *ltp; /* leaf's tail */
@@ -95,8 +95,8 @@ xfs_dir2_block_to_leaf(
95 return error; 95 return error;
96 } 96 }
97 ASSERT(lbp != NULL); 97 ASSERT(lbp != NULL);
98 leaf = lbp->data; 98 leaf = lbp->b_addr;
99 hdr = dbp->data; 99 hdr = dbp->b_addr;
100 xfs_dir2_data_check(dp, dbp); 100 xfs_dir2_data_check(dp, dbp);
101 btp = xfs_dir2_block_tail_p(mp, hdr); 101 btp = xfs_dir2_block_tail_p(mp, hdr);
102 blp = xfs_dir2_block_leaf_p(btp); 102 blp = xfs_dir2_block_leaf_p(btp);
@@ -143,7 +143,6 @@ xfs_dir2_block_to_leaf(
143 xfs_dir2_leaf_check(dp, lbp); 143 xfs_dir2_leaf_check(dp, lbp);
144 xfs_dir2_data_check(dp, dbp); 144 xfs_dir2_data_check(dp, dbp);
145 xfs_dir2_leaf_log_bests(tp, lbp, 0, 0); 145 xfs_dir2_leaf_log_bests(tp, lbp, 0, 0);
146 xfs_da_buf_done(lbp);
147 return 0; 146 return 0;
148} 147}
149 148
@@ -282,7 +281,7 @@ xfs_dir2_leaf_addname(
282 __be16 *bestsp; /* freespace table in leaf */ 281 __be16 *bestsp; /* freespace table in leaf */
283 int compact; /* need to compact leaves */ 282 int compact; /* need to compact leaves */
284 xfs_dir2_data_hdr_t *hdr; /* data block header */ 283 xfs_dir2_data_hdr_t *hdr; /* data block header */
285 xfs_dabuf_t *dbp; /* data block buffer */ 284 struct xfs_buf *dbp; /* data block buffer */
286 xfs_dir2_data_entry_t *dep; /* data block entry */ 285 xfs_dir2_data_entry_t *dep; /* data block entry */
287 xfs_inode_t *dp; /* incore directory inode */ 286 xfs_inode_t *dp; /* incore directory inode */
288 xfs_dir2_data_unused_t *dup; /* data unused entry */ 287 xfs_dir2_data_unused_t *dup; /* data unused entry */
@@ -291,7 +290,7 @@ xfs_dir2_leaf_addname(
291 int highstale; /* index of next stale leaf */ 290 int highstale; /* index of next stale leaf */
292 int i; /* temporary, index */ 291 int i; /* temporary, index */
293 int index; /* leaf table position */ 292 int index; /* leaf table position */
294 xfs_dabuf_t *lbp; /* leaf's buffer */ 293 struct xfs_buf *lbp; /* leaf's buffer */
295 xfs_dir2_leaf_t *leaf; /* leaf structure */ 294 xfs_dir2_leaf_t *leaf; /* leaf structure */
296 int length; /* length of new entry */ 295 int length; /* length of new entry */
297 xfs_dir2_leaf_entry_t *lep; /* leaf entry table pointer */ 296 xfs_dir2_leaf_entry_t *lep; /* leaf entry table pointer */
@@ -328,7 +327,7 @@ xfs_dir2_leaf_addname(
328 * But if there are dup hash values the index is of the first of those. 327 * But if there are dup hash values the index is of the first of those.
329 */ 328 */
330 index = xfs_dir2_leaf_search_hash(args, lbp); 329 index = xfs_dir2_leaf_search_hash(args, lbp);
331 leaf = lbp->data; 330 leaf = lbp->b_addr;
332 ltp = xfs_dir2_leaf_tail_p(mp, leaf); 331 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
333 bestsp = xfs_dir2_leaf_bests_p(ltp); 332 bestsp = xfs_dir2_leaf_bests_p(ltp);
334 length = xfs_dir2_data_entsize(args->namelen); 333 length = xfs_dir2_data_entsize(args->namelen);
@@ -402,14 +401,13 @@ xfs_dir2_leaf_addname(
402 */ 401 */
403 if ((args->op_flags & XFS_DA_OP_JUSTCHECK) || 402 if ((args->op_flags & XFS_DA_OP_JUSTCHECK) ||
404 args->total == 0) { 403 args->total == 0) {
405 xfs_da_brelse(tp, lbp); 404 xfs_trans_brelse(tp, lbp);
406 return XFS_ERROR(ENOSPC); 405 return XFS_ERROR(ENOSPC);
407 } 406 }
408 /* 407 /*
409 * Convert to node form. 408 * Convert to node form.
410 */ 409 */
411 error = xfs_dir2_leaf_to_node(args, lbp); 410 error = xfs_dir2_leaf_to_node(args, lbp);
412 xfs_da_buf_done(lbp);
413 if (error) 411 if (error)
414 return error; 412 return error;
415 /* 413 /*
@@ -427,7 +425,7 @@ xfs_dir2_leaf_addname(
427 * a new data block. 425 * a new data block.
428 */ 426 */
429 if (args->op_flags & XFS_DA_OP_JUSTCHECK) { 427 if (args->op_flags & XFS_DA_OP_JUSTCHECK) {
430 xfs_da_brelse(tp, lbp); 428 xfs_trans_brelse(tp, lbp);
431 return use_block == -1 ? XFS_ERROR(ENOSPC) : 0; 429 return use_block == -1 ? XFS_ERROR(ENOSPC) : 0;
432 } 430 }
433 /* 431 /*
@@ -435,7 +433,7 @@ xfs_dir2_leaf_addname(
435 * changed anything. 433 * changed anything.
436 */ 434 */
437 if (args->total == 0 && use_block == -1) { 435 if (args->total == 0 && use_block == -1) {
438 xfs_da_brelse(tp, lbp); 436 xfs_trans_brelse(tp, lbp);
439 return XFS_ERROR(ENOSPC); 437 return XFS_ERROR(ENOSPC);
440 } 438 }
441 /* 439 /*
@@ -466,14 +464,14 @@ xfs_dir2_leaf_addname(
466 */ 464 */
467 if ((error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, 465 if ((error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE,
468 &use_block))) { 466 &use_block))) {
469 xfs_da_brelse(tp, lbp); 467 xfs_trans_brelse(tp, lbp);
470 return error; 468 return error;
471 } 469 }
472 /* 470 /*
473 * Initialize the block. 471 * Initialize the block.
474 */ 472 */
475 if ((error = xfs_dir2_data_init(args, use_block, &dbp))) { 473 if ((error = xfs_dir2_data_init(args, use_block, &dbp))) {
476 xfs_da_brelse(tp, lbp); 474 xfs_trans_brelse(tp, lbp);
477 return error; 475 return error;
478 } 476 }
479 /* 477 /*
@@ -493,7 +491,7 @@ xfs_dir2_leaf_addname(
493 */ 491 */
494 else 492 else
495 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block); 493 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block);
496 hdr = dbp->data; 494 hdr = dbp->b_addr;
497 bestsp[use_block] = hdr->bestfree[0].length; 495 bestsp[use_block] = hdr->bestfree[0].length;
498 grown = 1; 496 grown = 1;
499 } 497 }
@@ -505,10 +503,10 @@ xfs_dir2_leaf_addname(
505 if ((error = 503 if ((error =
506 xfs_da_read_buf(tp, dp, xfs_dir2_db_to_da(mp, use_block), 504 xfs_da_read_buf(tp, dp, xfs_dir2_db_to_da(mp, use_block),
507 -1, &dbp, XFS_DATA_FORK))) { 505 -1, &dbp, XFS_DATA_FORK))) {
508 xfs_da_brelse(tp, lbp); 506 xfs_trans_brelse(tp, lbp);
509 return error; 507 return error;
510 } 508 }
511 hdr = dbp->data; 509 hdr = dbp->b_addr;
512 grown = 0; 510 grown = 0;
513 } 511 }
514 xfs_dir2_data_check(dp, dbp); 512 xfs_dir2_data_check(dp, dbp);
@@ -570,9 +568,7 @@ xfs_dir2_leaf_addname(
570 xfs_dir2_leaf_log_header(tp, lbp); 568 xfs_dir2_leaf_log_header(tp, lbp);
571 xfs_dir2_leaf_log_ents(tp, lbp, lfloglow, lfloghigh); 569 xfs_dir2_leaf_log_ents(tp, lbp, lfloglow, lfloghigh);
572 xfs_dir2_leaf_check(dp, lbp); 570 xfs_dir2_leaf_check(dp, lbp);
573 xfs_da_buf_done(lbp);
574 xfs_dir2_data_check(dp, dbp); 571 xfs_dir2_data_check(dp, dbp);
575 xfs_da_buf_done(dbp);
576 return 0; 572 return 0;
577} 573}
578 574
@@ -583,8 +579,8 @@ xfs_dir2_leaf_addname(
583 */ 579 */
584STATIC void 580STATIC void
585xfs_dir2_leaf_check( 581xfs_dir2_leaf_check(
586 xfs_inode_t *dp, /* incore directory inode */ 582 struct xfs_inode *dp, /* incore directory inode */
587 xfs_dabuf_t *bp) /* leaf's buffer */ 583 struct xfs_buf *bp) /* leaf's buffer */
588{ 584{
589 int i; /* leaf index */ 585 int i; /* leaf index */
590 xfs_dir2_leaf_t *leaf; /* leaf structure */ 586 xfs_dir2_leaf_t *leaf; /* leaf structure */
@@ -592,7 +588,7 @@ xfs_dir2_leaf_check(
592 xfs_mount_t *mp; /* filesystem mount point */ 588 xfs_mount_t *mp; /* filesystem mount point */
593 int stale; /* count of stale leaves */ 589 int stale; /* count of stale leaves */
594 590
595 leaf = bp->data; 591 leaf = bp->b_addr;
596 mp = dp->i_mount; 592 mp = dp->i_mount;
597 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC)); 593 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC));
598 /* 594 /*
@@ -628,14 +624,14 @@ xfs_dir2_leaf_check(
628void 624void
629xfs_dir2_leaf_compact( 625xfs_dir2_leaf_compact(
630 xfs_da_args_t *args, /* operation arguments */ 626 xfs_da_args_t *args, /* operation arguments */
631 xfs_dabuf_t *bp) /* leaf buffer */ 627 struct xfs_buf *bp) /* leaf buffer */
632{ 628{
633 int from; /* source leaf index */ 629 int from; /* source leaf index */
634 xfs_dir2_leaf_t *leaf; /* leaf structure */ 630 xfs_dir2_leaf_t *leaf; /* leaf structure */
635 int loglow; /* first leaf entry to log */ 631 int loglow; /* first leaf entry to log */
636 int to; /* target leaf index */ 632 int to; /* target leaf index */
637 633
638 leaf = bp->data; 634 leaf = bp->b_addr;
639 if (!leaf->hdr.stale) { 635 if (!leaf->hdr.stale) {
640 return; 636 return;
641 } 637 }
@@ -677,7 +673,7 @@ xfs_dir2_leaf_compact(
677 */ 673 */
678void 674void
679xfs_dir2_leaf_compact_x1( 675xfs_dir2_leaf_compact_x1(
680 xfs_dabuf_t *bp, /* leaf buffer */ 676 struct xfs_buf *bp, /* leaf buffer */
681 int *indexp, /* insertion index */ 677 int *indexp, /* insertion index */
682 int *lowstalep, /* out: stale entry before us */ 678 int *lowstalep, /* out: stale entry before us */
683 int *highstalep, /* out: stale entry after us */ 679 int *highstalep, /* out: stale entry after us */
@@ -693,7 +689,7 @@ xfs_dir2_leaf_compact_x1(
693 int newindex=0; /* new insertion index */ 689 int newindex=0; /* new insertion index */
694 int to; /* destination copy index */ 690 int to; /* destination copy index */
695 691
696 leaf = bp->data; 692 leaf = bp->b_addr;
697 ASSERT(be16_to_cpu(leaf->hdr.stale) > 1); 693 ASSERT(be16_to_cpu(leaf->hdr.stale) > 1);
698 index = *indexp; 694 index = *indexp;
699 695
@@ -763,6 +759,218 @@ xfs_dir2_leaf_compact_x1(
763 *highstalep = highstale; 759 *highstalep = highstale;
764} 760}
765 761
762struct xfs_dir2_leaf_map_info {
763 xfs_extlen_t map_blocks; /* number of fsbs in map */
764 xfs_dablk_t map_off; /* last mapped file offset */
765 int map_size; /* total entries in *map */
766 int map_valid; /* valid entries in *map */
767 int nmap; /* mappings to ask xfs_bmapi */
768 xfs_dir2_db_t curdb; /* db for current block */
769 int ra_current; /* number of read-ahead blks */
770 int ra_index; /* *map index for read-ahead */
771 int ra_offset; /* map entry offset for ra */
772 int ra_want; /* readahead count wanted */
773 struct xfs_bmbt_irec map[]; /* map vector for blocks */
774};
775
776STATIC int
777xfs_dir2_leaf_readbuf(
778 struct xfs_inode *dp,
779 size_t bufsize,
780 struct xfs_dir2_leaf_map_info *mip,
781 xfs_dir2_off_t *curoff,
782 struct xfs_buf **bpp)
783{
784 struct xfs_mount *mp = dp->i_mount;
785 struct xfs_buf *bp = *bpp;
786 struct xfs_bmbt_irec *map = mip->map;
787 int error = 0;
788 int length;
789 int i;
790 int j;
791
792 /*
793 * If we have a buffer, we need to release it and
794 * take it out of the mapping.
795 */
796
797 if (bp) {
798 xfs_trans_brelse(NULL, bp);
799 bp = NULL;
800 mip->map_blocks -= mp->m_dirblkfsbs;
801 /*
802 * Loop to get rid of the extents for the
803 * directory block.
804 */
805 for (i = mp->m_dirblkfsbs; i > 0; ) {
806 j = min_t(int, map->br_blockcount, i);
807 map->br_blockcount -= j;
808 map->br_startblock += j;
809 map->br_startoff += j;
810 /*
811 * If mapping is done, pitch it from
812 * the table.
813 */
814 if (!map->br_blockcount && --mip->map_valid)
815 memmove(&map[0], &map[1],
816 sizeof(map[0]) * mip->map_valid);
817 i -= j;
818 }
819 }
820
821 /*
822 * Recalculate the readahead blocks wanted.
823 */
824 mip->ra_want = howmany(bufsize + mp->m_dirblksize,
825 mp->m_sb.sb_blocksize) - 1;
826 ASSERT(mip->ra_want >= 0);
827
828 /*
829 * If we don't have as many as we want, and we haven't
830 * run out of data blocks, get some more mappings.
831 */
832 if (1 + mip->ra_want > mip->map_blocks &&
833 mip->map_off < xfs_dir2_byte_to_da(mp, XFS_DIR2_LEAF_OFFSET)) {
834 /*
835 * Get more bmaps, fill in after the ones
836 * we already have in the table.
837 */
838 mip->nmap = mip->map_size - mip->map_valid;
839 error = xfs_bmapi_read(dp, mip->map_off,
840 xfs_dir2_byte_to_da(mp, XFS_DIR2_LEAF_OFFSET) -
841 mip->map_off,
842 &map[mip->map_valid], &mip->nmap, 0);
843
844 /*
845 * Don't know if we should ignore this or try to return an
846 * error. The trouble with returning errors is that readdir
847 * will just stop without actually passing the error through.
848 */
849 if (error)
850 goto out; /* XXX */
851
852 /*
853 * If we got all the mappings we asked for, set the final map
854 * offset based on the last bmap value received. Otherwise,
855 * we've reached the end.
856 */
857 if (mip->nmap == mip->map_size - mip->map_valid) {
858 i = mip->map_valid + mip->nmap - 1;
859 mip->map_off = map[i].br_startoff + map[i].br_blockcount;
860 } else
861 mip->map_off = xfs_dir2_byte_to_da(mp,
862 XFS_DIR2_LEAF_OFFSET);
863
864 /*
865 * Look for holes in the mapping, and eliminate them. Count up
866 * the valid blocks.
867 */
868 for (i = mip->map_valid; i < mip->map_valid + mip->nmap; ) {
869 if (map[i].br_startblock == HOLESTARTBLOCK) {
870 mip->nmap--;
871 length = mip->map_valid + mip->nmap - i;
872 if (length)
873 memmove(&map[i], &map[i + 1],
874 sizeof(map[i]) * length);
875 } else {
876 mip->map_blocks += map[i].br_blockcount;
877 i++;
878 }
879 }
880 mip->map_valid += mip->nmap;
881 }
882
883 /*
884 * No valid mappings, so no more data blocks.
885 */
886 if (!mip->map_valid) {
887 *curoff = xfs_dir2_da_to_byte(mp, mip->map_off);
888 goto out;
889 }
890
891 /*
892 * Read the directory block starting at the first mapping.
893 */
894 mip->curdb = xfs_dir2_da_to_db(mp, map->br_startoff);
895 error = xfs_da_read_buf(NULL, dp, map->br_startoff,
896 map->br_blockcount >= mp->m_dirblkfsbs ?
897 XFS_FSB_TO_DADDR(mp, map->br_startblock) : -1,
898 &bp, XFS_DATA_FORK);
899
900 /*
901 * Should just skip over the data block instead of giving up.
902 */
903 if (error)
904 goto out; /* XXX */
905
906 /*
907 * Adjust the current amount of read-ahead: we just read a block that
908 * was previously ra.
909 */
910 if (mip->ra_current)
911 mip->ra_current -= mp->m_dirblkfsbs;
912
913 /*
914 * Do we need more readahead?
915 */
916 for (mip->ra_index = mip->ra_offset = i = 0;
917 mip->ra_want > mip->ra_current && i < mip->map_blocks;
918 i += mp->m_dirblkfsbs) {
919 ASSERT(mip->ra_index < mip->map_valid);
920 /*
921 * Read-ahead a contiguous directory block.
922 */
923 if (i > mip->ra_current &&
924 map[mip->ra_index].br_blockcount >= mp->m_dirblkfsbs) {
925 xfs_buf_readahead(mp->m_ddev_targp,
926 XFS_FSB_TO_DADDR(mp,
927 map[mip->ra_index].br_startblock +
928 mip->ra_offset),
929 (int)BTOBB(mp->m_dirblksize));
930 mip->ra_current = i;
931 }
932
933 /*
934 * Read-ahead a non-contiguous directory block. This doesn't
935 * use our mapping, but this is a very rare case.
936 */
937 else if (i > mip->ra_current) {
938 xfs_da_reada_buf(NULL, dp,
939 map[mip->ra_index].br_startoff +
940 mip->ra_offset,
941 XFS_DATA_FORK);
942 mip->ra_current = i;
943 }
944
945 /*
946 * Advance offset through the mapping table.
947 */
948 for (j = 0; j < mp->m_dirblkfsbs; j++) {
949 /*
950 * The rest of this extent but not more than a dir
951 * block.
952 */
953 length = min_t(int, mp->m_dirblkfsbs,
954 map[mip->ra_index].br_blockcount -
955 mip->ra_offset);
956 j += length;
957 mip->ra_offset += length;
958
959 /*
960 * Advance to the next mapping if this one is used up.
961 */
962 if (mip->ra_offset == map[mip->ra_index].br_blockcount) {
963 mip->ra_offset = 0;
964 mip->ra_index++;
965 }
966 }
967 }
968
969out:
970 *bpp = bp;
971 return error;
972}
973
766/* 974/*
767 * Getdents (readdir) for leaf and node directories. 975 * Getdents (readdir) for leaf and node directories.
768 * This reads the data blocks only, so is the same for both forms. 976 * This reads the data blocks only, so is the same for both forms.
@@ -775,30 +983,18 @@ xfs_dir2_leaf_getdents(
775 xfs_off_t *offset, 983 xfs_off_t *offset,
776 filldir_t filldir) 984 filldir_t filldir)
777{ 985{
778 xfs_dabuf_t *bp; /* data block buffer */ 986 struct xfs_buf *bp = NULL; /* data block buffer */
779 int byteoff; /* offset in current block */
780 xfs_dir2_db_t curdb; /* db for current block */
781 xfs_dir2_off_t curoff; /* current overall offset */
782 xfs_dir2_data_hdr_t *hdr; /* data block header */ 987 xfs_dir2_data_hdr_t *hdr; /* data block header */
783 xfs_dir2_data_entry_t *dep; /* data entry */ 988 xfs_dir2_data_entry_t *dep; /* data entry */
784 xfs_dir2_data_unused_t *dup; /* unused entry */ 989 xfs_dir2_data_unused_t *dup; /* unused entry */
785 int error = 0; /* error return value */ 990 int error = 0; /* error return value */
786 int i; /* temporary loop index */
787 int j; /* temporary loop index */
788 int length; /* temporary length value */ 991 int length; /* temporary length value */
789 xfs_bmbt_irec_t *map; /* map vector for blocks */
790 xfs_extlen_t map_blocks; /* number of fsbs in map */
791 xfs_dablk_t map_off; /* last mapped file offset */
792 int map_size; /* total entries in *map */
793 int map_valid; /* valid entries in *map */
794 xfs_mount_t *mp; /* filesystem mount point */ 992 xfs_mount_t *mp; /* filesystem mount point */
993 int byteoff; /* offset in current block */
994 xfs_dir2_off_t curoff; /* current overall offset */
795 xfs_dir2_off_t newoff; /* new curoff after new blk */ 995 xfs_dir2_off_t newoff; /* new curoff after new blk */
796 int nmap; /* mappings to ask xfs_bmapi */
797 char *ptr = NULL; /* pointer to current data */ 996 char *ptr = NULL; /* pointer to current data */
798 int ra_current; /* number of read-ahead blks */ 997 struct xfs_dir2_leaf_map_info *map_info;
799 int ra_index; /* *map index for read-ahead */
800 int ra_offset; /* map entry offset for ra */
801 int ra_want; /* readahead count wanted */
802 998
803 /* 999 /*
804 * If the offset is at or past the largest allowed value, 1000 * If the offset is at or past the largest allowed value,
@@ -814,10 +1010,12 @@ xfs_dir2_leaf_getdents(
814 * buffer size, the directory block size, and the filesystem 1010 * buffer size, the directory block size, and the filesystem
815 * block size. 1011 * block size.
816 */ 1012 */
817 map_size = howmany(bufsize + mp->m_dirblksize, mp->m_sb.sb_blocksize); 1013 length = howmany(bufsize + mp->m_dirblksize,
818 map = kmem_alloc(map_size * sizeof(*map), KM_SLEEP); 1014 mp->m_sb.sb_blocksize);
819 map_valid = ra_index = ra_offset = ra_current = map_blocks = 0; 1015 map_info = kmem_zalloc(offsetof(struct xfs_dir2_leaf_map_info, map) +
820 bp = NULL; 1016 (length * sizeof(struct xfs_bmbt_irec)),
1017 KM_SLEEP);
1018 map_info->map_size = length;
821 1019
822 /* 1020 /*
823 * Inside the loop we keep the main offset value as a byte offset 1021 * Inside the loop we keep the main offset value as a byte offset
@@ -829,7 +1027,9 @@ xfs_dir2_leaf_getdents(
829 * Force this conversion through db so we truncate the offset 1027 * Force this conversion through db so we truncate the offset
830 * down to get the start of the data block. 1028 * down to get the start of the data block.
831 */ 1029 */
832 map_off = xfs_dir2_db_to_da(mp, xfs_dir2_byte_to_db(mp, curoff)); 1030 map_info->map_off = xfs_dir2_db_to_da(mp,
1031 xfs_dir2_byte_to_db(mp, curoff));
1032
833 /* 1033 /*
834 * Loop over directory entries until we reach the end offset. 1034 * Loop over directory entries until we reach the end offset.
835 * Get more blocks and readahead as necessary. 1035 * Get more blocks and readahead as necessary.
@@ -839,191 +1039,17 @@ xfs_dir2_leaf_getdents(
839 * If we have no buffer, or we're off the end of the 1039 * If we have no buffer, or we're off the end of the
840 * current buffer, need to get another one. 1040 * current buffer, need to get another one.
841 */ 1041 */
842 if (!bp || ptr >= (char *)bp->data + mp->m_dirblksize) { 1042 if (!bp || ptr >= (char *)bp->b_addr + mp->m_dirblksize) {
843 /*
844 * If we have a buffer, we need to release it and
845 * take it out of the mapping.
846 */
847 if (bp) {
848 xfs_da_brelse(NULL, bp);
849 bp = NULL;
850 map_blocks -= mp->m_dirblkfsbs;
851 /*
852 * Loop to get rid of the extents for the
853 * directory block.
854 */
855 for (i = mp->m_dirblkfsbs; i > 0; ) {
856 j = MIN((int)map->br_blockcount, i);
857 map->br_blockcount -= j;
858 map->br_startblock += j;
859 map->br_startoff += j;
860 /*
861 * If mapping is done, pitch it from
862 * the table.
863 */
864 if (!map->br_blockcount && --map_valid)
865 memmove(&map[0], &map[1],
866 sizeof(map[0]) *
867 map_valid);
868 i -= j;
869 }
870 }
871 /*
872 * Recalculate the readahead blocks wanted.
873 */
874 ra_want = howmany(bufsize + mp->m_dirblksize,
875 mp->m_sb.sb_blocksize) - 1;
876 ASSERT(ra_want >= 0);
877 1043
878 /* 1044 error = xfs_dir2_leaf_readbuf(dp, bufsize, map_info,
879 * If we don't have as many as we want, and we haven't 1045 &curoff, &bp);
880 * run out of data blocks, get some more mappings. 1046 if (error || !map_info->map_valid)
881 */
882 if (1 + ra_want > map_blocks &&
883 map_off <
884 xfs_dir2_byte_to_da(mp, XFS_DIR2_LEAF_OFFSET)) {
885 /*
886 * Get more bmaps, fill in after the ones
887 * we already have in the table.
888 */
889 nmap = map_size - map_valid;
890 error = xfs_bmapi_read(dp, map_off,
891 xfs_dir2_byte_to_da(mp,
892 XFS_DIR2_LEAF_OFFSET) - map_off,
893 &map[map_valid], &nmap, 0);
894 /*
895 * Don't know if we should ignore this or
896 * try to return an error.
897 * The trouble with returning errors
898 * is that readdir will just stop without
899 * actually passing the error through.
900 */
901 if (error)
902 break; /* XXX */
903 /*
904 * If we got all the mappings we asked for,
905 * set the final map offset based on the
906 * last bmap value received.
907 * Otherwise, we've reached the end.
908 */
909 if (nmap == map_size - map_valid)
910 map_off =
911 map[map_valid + nmap - 1].br_startoff +
912 map[map_valid + nmap - 1].br_blockcount;
913 else
914 map_off =
915 xfs_dir2_byte_to_da(mp,
916 XFS_DIR2_LEAF_OFFSET);
917 /*
918 * Look for holes in the mapping, and
919 * eliminate them. Count up the valid blocks.
920 */
921 for (i = map_valid; i < map_valid + nmap; ) {
922 if (map[i].br_startblock ==
923 HOLESTARTBLOCK) {
924 nmap--;
925 length = map_valid + nmap - i;
926 if (length)
927 memmove(&map[i],
928 &map[i + 1],
929 sizeof(map[i]) *
930 length);
931 } else {
932 map_blocks +=
933 map[i].br_blockcount;
934 i++;
935 }
936 }
937 map_valid += nmap;
938 }
939 /*
940 * No valid mappings, so no more data blocks.
941 */
942 if (!map_valid) {
943 curoff = xfs_dir2_da_to_byte(mp, map_off);
944 break; 1047 break;
945 } 1048
946 /*
947 * Read the directory block starting at the first
948 * mapping.
949 */
950 curdb = xfs_dir2_da_to_db(mp, map->br_startoff);
951 error = xfs_da_read_buf(NULL, dp, map->br_startoff,
952 map->br_blockcount >= mp->m_dirblkfsbs ?
953 XFS_FSB_TO_DADDR(mp, map->br_startblock) :
954 -1,
955 &bp, XFS_DATA_FORK);
956 /*
957 * Should just skip over the data block instead
958 * of giving up.
959 */
960 if (error)
961 break; /* XXX */
962 /*
963 * Adjust the current amount of read-ahead: we just
964 * read a block that was previously ra.
965 */
966 if (ra_current)
967 ra_current -= mp->m_dirblkfsbs;
968 /*
969 * Do we need more readahead?
970 */
971 for (ra_index = ra_offset = i = 0;
972 ra_want > ra_current && i < map_blocks;
973 i += mp->m_dirblkfsbs) {
974 ASSERT(ra_index < map_valid);
975 /*
976 * Read-ahead a contiguous directory block.
977 */
978 if (i > ra_current &&
979 map[ra_index].br_blockcount >=
980 mp->m_dirblkfsbs) {
981 xfs_buf_readahead(mp->m_ddev_targp,
982 XFS_FSB_TO_DADDR(mp,
983 map[ra_index].br_startblock +
984 ra_offset),
985 (int)BTOBB(mp->m_dirblksize));
986 ra_current = i;
987 }
988 /*
989 * Read-ahead a non-contiguous directory block.
990 * This doesn't use our mapping, but this
991 * is a very rare case.
992 */
993 else if (i > ra_current) {
994 (void)xfs_da_reada_buf(NULL, dp,
995 map[ra_index].br_startoff +
996 ra_offset, XFS_DATA_FORK);
997 ra_current = i;
998 }
999 /*
1000 * Advance offset through the mapping table.
1001 */
1002 for (j = 0; j < mp->m_dirblkfsbs; j++) {
1003 /*
1004 * The rest of this extent but not
1005 * more than a dir block.
1006 */
1007 length = MIN(mp->m_dirblkfsbs,
1008 (int)(map[ra_index].br_blockcount -
1009 ra_offset));
1010 j += length;
1011 ra_offset += length;
1012 /*
1013 * Advance to the next mapping if
1014 * this one is used up.
1015 */
1016 if (ra_offset ==
1017 map[ra_index].br_blockcount) {
1018 ra_offset = 0;
1019 ra_index++;
1020 }
1021 }
1022 }
1023 /* 1049 /*
1024 * Having done a read, we need to set a new offset. 1050 * Having done a read, we need to set a new offset.
1025 */ 1051 */
1026 newoff = xfs_dir2_db_off_to_byte(mp, curdb, 0); 1052 newoff = xfs_dir2_db_off_to_byte(mp, map_info->curdb, 0);
1027 /* 1053 /*
1028 * Start of the current block. 1054 * Start of the current block.
1029 */ 1055 */
@@ -1034,8 +1060,8 @@ xfs_dir2_leaf_getdents(
1034 */ 1060 */
1035 else if (curoff > newoff) 1061 else if (curoff > newoff)
1036 ASSERT(xfs_dir2_byte_to_db(mp, curoff) == 1062 ASSERT(xfs_dir2_byte_to_db(mp, curoff) ==
1037 curdb); 1063 map_info->curdb);
1038 hdr = bp->data; 1064 hdr = bp->b_addr;
1039 xfs_dir2_data_check(dp, bp); 1065 xfs_dir2_data_check(dp, bp);
1040 /* 1066 /*
1041 * Find our position in the block. 1067 * Find our position in the block.
@@ -1117,9 +1143,9 @@ xfs_dir2_leaf_getdents(
1117 *offset = XFS_DIR2_MAX_DATAPTR & 0x7fffffff; 1143 *offset = XFS_DIR2_MAX_DATAPTR & 0x7fffffff;
1118 else 1144 else
1119 *offset = xfs_dir2_byte_to_dataptr(mp, curoff) & 0x7fffffff; 1145 *offset = xfs_dir2_byte_to_dataptr(mp, curoff) & 0x7fffffff;
1120 kmem_free(map); 1146 kmem_free(map_info);
1121 if (bp) 1147 if (bp)
1122 xfs_da_brelse(NULL, bp); 1148 xfs_trans_brelse(NULL, bp);
1123 return error; 1149 return error;
1124} 1150}
1125 1151
@@ -1130,10 +1156,10 @@ int
1130xfs_dir2_leaf_init( 1156xfs_dir2_leaf_init(
1131 xfs_da_args_t *args, /* operation arguments */ 1157 xfs_da_args_t *args, /* operation arguments */
1132 xfs_dir2_db_t bno, /* directory block number */ 1158 xfs_dir2_db_t bno, /* directory block number */
1133 xfs_dabuf_t **bpp, /* out: leaf buffer */ 1159 struct xfs_buf **bpp, /* out: leaf buffer */
1134 int magic) /* magic number for block */ 1160 int magic) /* magic number for block */
1135{ 1161{
1136 xfs_dabuf_t *bp; /* leaf buffer */ 1162 struct xfs_buf *bp; /* leaf buffer */
1137 xfs_inode_t *dp; /* incore directory inode */ 1163 xfs_inode_t *dp; /* incore directory inode */
1138 int error; /* error return code */ 1164 int error; /* error return code */
1139 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1165 xfs_dir2_leaf_t *leaf; /* leaf structure */
@@ -1156,7 +1182,7 @@ xfs_dir2_leaf_init(
1156 return error; 1182 return error;
1157 } 1183 }
1158 ASSERT(bp != NULL); 1184 ASSERT(bp != NULL);
1159 leaf = bp->data; 1185 leaf = bp->b_addr;
1160 /* 1186 /*
1161 * Initialize the header. 1187 * Initialize the header.
1162 */ 1188 */
@@ -1186,7 +1212,7 @@ xfs_dir2_leaf_init(
1186static void 1212static void
1187xfs_dir2_leaf_log_bests( 1213xfs_dir2_leaf_log_bests(
1188 xfs_trans_t *tp, /* transaction pointer */ 1214 xfs_trans_t *tp, /* transaction pointer */
1189 xfs_dabuf_t *bp, /* leaf buffer */ 1215 struct xfs_buf *bp, /* leaf buffer */
1190 int first, /* first entry to log */ 1216 int first, /* first entry to log */
1191 int last) /* last entry to log */ 1217 int last) /* last entry to log */
1192{ 1218{
@@ -1195,12 +1221,12 @@ xfs_dir2_leaf_log_bests(
1195 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1221 xfs_dir2_leaf_t *leaf; /* leaf structure */
1196 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ 1222 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */
1197 1223
1198 leaf = bp->data; 1224 leaf = bp->b_addr;
1199 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC)); 1225 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC));
1200 ltp = xfs_dir2_leaf_tail_p(tp->t_mountp, leaf); 1226 ltp = xfs_dir2_leaf_tail_p(tp->t_mountp, leaf);
1201 firstb = xfs_dir2_leaf_bests_p(ltp) + first; 1227 firstb = xfs_dir2_leaf_bests_p(ltp) + first;
1202 lastb = xfs_dir2_leaf_bests_p(ltp) + last; 1228 lastb = xfs_dir2_leaf_bests_p(ltp) + last;
1203 xfs_da_log_buf(tp, bp, (uint)((char *)firstb - (char *)leaf), 1229 xfs_trans_log_buf(tp, bp, (uint)((char *)firstb - (char *)leaf),
1204 (uint)((char *)lastb - (char *)leaf + sizeof(*lastb) - 1)); 1230 (uint)((char *)lastb - (char *)leaf + sizeof(*lastb) - 1));
1205} 1231}
1206 1232
@@ -1210,7 +1236,7 @@ xfs_dir2_leaf_log_bests(
1210void 1236void
1211xfs_dir2_leaf_log_ents( 1237xfs_dir2_leaf_log_ents(
1212 xfs_trans_t *tp, /* transaction pointer */ 1238 xfs_trans_t *tp, /* transaction pointer */
1213 xfs_dabuf_t *bp, /* leaf buffer */ 1239 struct xfs_buf *bp, /* leaf buffer */
1214 int first, /* first entry to log */ 1240 int first, /* first entry to log */
1215 int last) /* last entry to log */ 1241 int last) /* last entry to log */
1216{ 1242{
@@ -1218,12 +1244,12 @@ xfs_dir2_leaf_log_ents(
1218 xfs_dir2_leaf_entry_t *lastlep; /* pointer to last entry */ 1244 xfs_dir2_leaf_entry_t *lastlep; /* pointer to last entry */
1219 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1245 xfs_dir2_leaf_t *leaf; /* leaf structure */
1220 1246
1221 leaf = bp->data; 1247 leaf = bp->b_addr;
1222 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC) || 1248 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC) ||
1223 leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)); 1249 leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC));
1224 firstlep = &leaf->ents[first]; 1250 firstlep = &leaf->ents[first];
1225 lastlep = &leaf->ents[last]; 1251 lastlep = &leaf->ents[last];
1226 xfs_da_log_buf(tp, bp, (uint)((char *)firstlep - (char *)leaf), 1252 xfs_trans_log_buf(tp, bp, (uint)((char *)firstlep - (char *)leaf),
1227 (uint)((char *)lastlep - (char *)leaf + sizeof(*lastlep) - 1)); 1253 (uint)((char *)lastlep - (char *)leaf + sizeof(*lastlep) - 1));
1228} 1254}
1229 1255
@@ -1232,15 +1258,15 @@ xfs_dir2_leaf_log_ents(
1232 */ 1258 */
1233void 1259void
1234xfs_dir2_leaf_log_header( 1260xfs_dir2_leaf_log_header(
1235 xfs_trans_t *tp, /* transaction pointer */ 1261 struct xfs_trans *tp,
1236 xfs_dabuf_t *bp) /* leaf buffer */ 1262 struct xfs_buf *bp)
1237{ 1263{
1238 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1264 xfs_dir2_leaf_t *leaf; /* leaf structure */
1239 1265
1240 leaf = bp->data; 1266 leaf = bp->b_addr;
1241 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC) || 1267 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC) ||
1242 leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)); 1268 leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC));
1243 xfs_da_log_buf(tp, bp, (uint)((char *)&leaf->hdr - (char *)leaf), 1269 xfs_trans_log_buf(tp, bp, (uint)((char *)&leaf->hdr - (char *)leaf),
1244 (uint)(sizeof(leaf->hdr) - 1)); 1270 (uint)(sizeof(leaf->hdr) - 1));
1245} 1271}
1246 1272
@@ -1249,18 +1275,18 @@ xfs_dir2_leaf_log_header(
1249 */ 1275 */
1250STATIC void 1276STATIC void
1251xfs_dir2_leaf_log_tail( 1277xfs_dir2_leaf_log_tail(
1252 xfs_trans_t *tp, /* transaction pointer */ 1278 struct xfs_trans *tp,
1253 xfs_dabuf_t *bp) /* leaf buffer */ 1279 struct xfs_buf *bp)
1254{ 1280{
1255 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1281 xfs_dir2_leaf_t *leaf; /* leaf structure */
1256 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ 1282 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */
1257 xfs_mount_t *mp; /* filesystem mount point */ 1283 xfs_mount_t *mp; /* filesystem mount point */
1258 1284
1259 mp = tp->t_mountp; 1285 mp = tp->t_mountp;
1260 leaf = bp->data; 1286 leaf = bp->b_addr;
1261 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC)); 1287 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAF1_MAGIC));
1262 ltp = xfs_dir2_leaf_tail_p(mp, leaf); 1288 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1263 xfs_da_log_buf(tp, bp, (uint)((char *)ltp - (char *)leaf), 1289 xfs_trans_log_buf(tp, bp, (uint)((char *)ltp - (char *)leaf),
1264 (uint)(mp->m_dirblksize - 1)); 1290 (uint)(mp->m_dirblksize - 1));
1265} 1291}
1266 1292
@@ -1273,12 +1299,12 @@ int
1273xfs_dir2_leaf_lookup( 1299xfs_dir2_leaf_lookup(
1274 xfs_da_args_t *args) /* operation arguments */ 1300 xfs_da_args_t *args) /* operation arguments */
1275{ 1301{
1276 xfs_dabuf_t *dbp; /* data block buffer */ 1302 struct xfs_buf *dbp; /* data block buffer */
1277 xfs_dir2_data_entry_t *dep; /* data block entry */ 1303 xfs_dir2_data_entry_t *dep; /* data block entry */
1278 xfs_inode_t *dp; /* incore directory inode */ 1304 xfs_inode_t *dp; /* incore directory inode */
1279 int error; /* error return code */ 1305 int error; /* error return code */
1280 int index; /* found entry index */ 1306 int index; /* found entry index */
1281 xfs_dabuf_t *lbp; /* leaf buffer */ 1307 struct xfs_buf *lbp; /* leaf buffer */
1282 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1308 xfs_dir2_leaf_t *leaf; /* leaf structure */
1283 xfs_dir2_leaf_entry_t *lep; /* leaf entry */ 1309 xfs_dir2_leaf_entry_t *lep; /* leaf entry */
1284 xfs_trans_t *tp; /* transaction pointer */ 1310 xfs_trans_t *tp; /* transaction pointer */
@@ -1294,7 +1320,7 @@ xfs_dir2_leaf_lookup(
1294 tp = args->trans; 1320 tp = args->trans;
1295 dp = args->dp; 1321 dp = args->dp;
1296 xfs_dir2_leaf_check(dp, lbp); 1322 xfs_dir2_leaf_check(dp, lbp);
1297 leaf = lbp->data; 1323 leaf = lbp->b_addr;
1298 /* 1324 /*
1299 * Get to the leaf entry and contained data entry address. 1325 * Get to the leaf entry and contained data entry address.
1300 */ 1326 */
@@ -1303,15 +1329,15 @@ xfs_dir2_leaf_lookup(
1303 * Point to the data entry. 1329 * Point to the data entry.
1304 */ 1330 */
1305 dep = (xfs_dir2_data_entry_t *) 1331 dep = (xfs_dir2_data_entry_t *)
1306 ((char *)dbp->data + 1332 ((char *)dbp->b_addr +
1307 xfs_dir2_dataptr_to_off(dp->i_mount, be32_to_cpu(lep->address))); 1333 xfs_dir2_dataptr_to_off(dp->i_mount, be32_to_cpu(lep->address)));
1308 /* 1334 /*
1309 * Return the found inode number & CI name if appropriate 1335 * Return the found inode number & CI name if appropriate
1310 */ 1336 */
1311 args->inumber = be64_to_cpu(dep->inumber); 1337 args->inumber = be64_to_cpu(dep->inumber);
1312 error = xfs_dir_cilookup_result(args, dep->name, dep->namelen); 1338 error = xfs_dir_cilookup_result(args, dep->name, dep->namelen);
1313 xfs_da_brelse(tp, dbp); 1339 xfs_trans_brelse(tp, dbp);
1314 xfs_da_brelse(tp, lbp); 1340 xfs_trans_brelse(tp, lbp);
1315 return XFS_ERROR(error); 1341 return XFS_ERROR(error);
1316} 1342}
1317 1343
@@ -1324,17 +1350,17 @@ xfs_dir2_leaf_lookup(
1324static int /* error */ 1350static int /* error */
1325xfs_dir2_leaf_lookup_int( 1351xfs_dir2_leaf_lookup_int(
1326 xfs_da_args_t *args, /* operation arguments */ 1352 xfs_da_args_t *args, /* operation arguments */
1327 xfs_dabuf_t **lbpp, /* out: leaf buffer */ 1353 struct xfs_buf **lbpp, /* out: leaf buffer */
1328 int *indexp, /* out: index in leaf block */ 1354 int *indexp, /* out: index in leaf block */
1329 xfs_dabuf_t **dbpp) /* out: data buffer */ 1355 struct xfs_buf **dbpp) /* out: data buffer */
1330{ 1356{
1331 xfs_dir2_db_t curdb = -1; /* current data block number */ 1357 xfs_dir2_db_t curdb = -1; /* current data block number */
1332 xfs_dabuf_t *dbp = NULL; /* data buffer */ 1358 struct xfs_buf *dbp = NULL; /* data buffer */
1333 xfs_dir2_data_entry_t *dep; /* data entry */ 1359 xfs_dir2_data_entry_t *dep; /* data entry */
1334 xfs_inode_t *dp; /* incore directory inode */ 1360 xfs_inode_t *dp; /* incore directory inode */
1335 int error; /* error return code */ 1361 int error; /* error return code */
1336 int index; /* index in leaf block */ 1362 int index; /* index in leaf block */
1337 xfs_dabuf_t *lbp; /* leaf buffer */ 1363 struct xfs_buf *lbp; /* leaf buffer */
1338 xfs_dir2_leaf_entry_t *lep; /* leaf entry */ 1364 xfs_dir2_leaf_entry_t *lep; /* leaf entry */
1339 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1365 xfs_dir2_leaf_t *leaf; /* leaf structure */
1340 xfs_mount_t *mp; /* filesystem mount point */ 1366 xfs_mount_t *mp; /* filesystem mount point */
@@ -1354,7 +1380,7 @@ xfs_dir2_leaf_lookup_int(
1354 if (error) 1380 if (error)
1355 return error; 1381 return error;
1356 *lbpp = lbp; 1382 *lbpp = lbp;
1357 leaf = lbp->data; 1383 leaf = lbp->b_addr;
1358 xfs_dir2_leaf_check(dp, lbp); 1384 xfs_dir2_leaf_check(dp, lbp);
1359 /* 1385 /*
1360 * Look for the first leaf entry with our hash value. 1386 * Look for the first leaf entry with our hash value.
@@ -1382,12 +1408,12 @@ xfs_dir2_leaf_lookup_int(
1382 */ 1408 */
1383 if (newdb != curdb) { 1409 if (newdb != curdb) {
1384 if (dbp) 1410 if (dbp)
1385 xfs_da_brelse(tp, dbp); 1411 xfs_trans_brelse(tp, dbp);
1386 error = xfs_da_read_buf(tp, dp, 1412 error = xfs_da_read_buf(tp, dp,
1387 xfs_dir2_db_to_da(mp, newdb), 1413 xfs_dir2_db_to_da(mp, newdb),
1388 -1, &dbp, XFS_DATA_FORK); 1414 -1, &dbp, XFS_DATA_FORK);
1389 if (error) { 1415 if (error) {
1390 xfs_da_brelse(tp, lbp); 1416 xfs_trans_brelse(tp, lbp);
1391 return error; 1417 return error;
1392 } 1418 }
1393 xfs_dir2_data_check(dp, dbp); 1419 xfs_dir2_data_check(dp, dbp);
@@ -1396,7 +1422,7 @@ xfs_dir2_leaf_lookup_int(
1396 /* 1422 /*
1397 * Point to the data entry. 1423 * Point to the data entry.
1398 */ 1424 */
1399 dep = (xfs_dir2_data_entry_t *)((char *)dbp->data + 1425 dep = (xfs_dir2_data_entry_t *)((char *)dbp->b_addr +
1400 xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address))); 1426 xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address)));
1401 /* 1427 /*
1402 * Compare name and if it's an exact match, return the index 1428 * Compare name and if it's an exact match, return the index
@@ -1424,12 +1450,12 @@ xfs_dir2_leaf_lookup_int(
1424 if (args->cmpresult == XFS_CMP_CASE) { 1450 if (args->cmpresult == XFS_CMP_CASE) {
1425 ASSERT(cidb != -1); 1451 ASSERT(cidb != -1);
1426 if (cidb != curdb) { 1452 if (cidb != curdb) {
1427 xfs_da_brelse(tp, dbp); 1453 xfs_trans_brelse(tp, dbp);
1428 error = xfs_da_read_buf(tp, dp, 1454 error = xfs_da_read_buf(tp, dp,
1429 xfs_dir2_db_to_da(mp, cidb), 1455 xfs_dir2_db_to_da(mp, cidb),
1430 -1, &dbp, XFS_DATA_FORK); 1456 -1, &dbp, XFS_DATA_FORK);
1431 if (error) { 1457 if (error) {
1432 xfs_da_brelse(tp, lbp); 1458 xfs_trans_brelse(tp, lbp);
1433 return error; 1459 return error;
1434 } 1460 }
1435 } 1461 }
@@ -1441,8 +1467,8 @@ xfs_dir2_leaf_lookup_int(
1441 */ 1467 */
1442 ASSERT(cidb == -1); 1468 ASSERT(cidb == -1);
1443 if (dbp) 1469 if (dbp)
1444 xfs_da_brelse(tp, dbp); 1470 xfs_trans_brelse(tp, dbp);
1445 xfs_da_brelse(tp, lbp); 1471 xfs_trans_brelse(tp, lbp);
1446 return XFS_ERROR(ENOENT); 1472 return XFS_ERROR(ENOENT);
1447} 1473}
1448 1474
@@ -1456,13 +1482,13 @@ xfs_dir2_leaf_removename(
1456 __be16 *bestsp; /* leaf block best freespace */ 1482 __be16 *bestsp; /* leaf block best freespace */
1457 xfs_dir2_data_hdr_t *hdr; /* data block header */ 1483 xfs_dir2_data_hdr_t *hdr; /* data block header */
1458 xfs_dir2_db_t db; /* data block number */ 1484 xfs_dir2_db_t db; /* data block number */
1459 xfs_dabuf_t *dbp; /* data block buffer */ 1485 struct xfs_buf *dbp; /* data block buffer */
1460 xfs_dir2_data_entry_t *dep; /* data entry structure */ 1486 xfs_dir2_data_entry_t *dep; /* data entry structure */
1461 xfs_inode_t *dp; /* incore directory inode */ 1487 xfs_inode_t *dp; /* incore directory inode */
1462 int error; /* error return code */ 1488 int error; /* error return code */
1463 xfs_dir2_db_t i; /* temporary data block # */ 1489 xfs_dir2_db_t i; /* temporary data block # */
1464 int index; /* index into leaf entries */ 1490 int index; /* index into leaf entries */
1465 xfs_dabuf_t *lbp; /* leaf buffer */ 1491 struct xfs_buf *lbp; /* leaf buffer */
1466 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1492 xfs_dir2_leaf_t *leaf; /* leaf structure */
1467 xfs_dir2_leaf_entry_t *lep; /* leaf entry */ 1493 xfs_dir2_leaf_entry_t *lep; /* leaf entry */
1468 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */ 1494 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */
@@ -1483,8 +1509,8 @@ xfs_dir2_leaf_removename(
1483 dp = args->dp; 1509 dp = args->dp;
1484 tp = args->trans; 1510 tp = args->trans;
1485 mp = dp->i_mount; 1511 mp = dp->i_mount;
1486 leaf = lbp->data; 1512 leaf = lbp->b_addr;
1487 hdr = dbp->data; 1513 hdr = dbp->b_addr;
1488 xfs_dir2_data_check(dp, dbp); 1514 xfs_dir2_data_check(dp, dbp);
1489 /* 1515 /*
1490 * Point to the leaf entry, use that to point to the data entry. 1516 * Point to the leaf entry, use that to point to the data entry.
@@ -1541,12 +1567,9 @@ xfs_dir2_leaf_removename(
1541 * Just go on, returning success, leaving the 1567 * Just go on, returning success, leaving the
1542 * empty block in place. 1568 * empty block in place.
1543 */ 1569 */
1544 if (error == ENOSPC && args->total == 0) { 1570 if (error == ENOSPC && args->total == 0)
1545 xfs_da_buf_done(dbp);
1546 error = 0; 1571 error = 0;
1547 }
1548 xfs_dir2_leaf_check(dp, lbp); 1572 xfs_dir2_leaf_check(dp, lbp);
1549 xfs_da_buf_done(lbp);
1550 return error; 1573 return error;
1551 } 1574 }
1552 dbp = NULL; 1575 dbp = NULL;
@@ -1577,10 +1600,9 @@ xfs_dir2_leaf_removename(
1577 /* 1600 /*
1578 * If the data block was not the first one, drop it. 1601 * If the data block was not the first one, drop it.
1579 */ 1602 */
1580 else if (db != mp->m_dirdatablk && dbp != NULL) { 1603 else if (db != mp->m_dirdatablk)
1581 xfs_da_buf_done(dbp);
1582 dbp = NULL; 1604 dbp = NULL;
1583 } 1605
1584 xfs_dir2_leaf_check(dp, lbp); 1606 xfs_dir2_leaf_check(dp, lbp);
1585 /* 1607 /*
1586 * See if we can convert to block form. 1608 * See if we can convert to block form.
@@ -1595,12 +1617,12 @@ int /* error */
1595xfs_dir2_leaf_replace( 1617xfs_dir2_leaf_replace(
1596 xfs_da_args_t *args) /* operation arguments */ 1618 xfs_da_args_t *args) /* operation arguments */
1597{ 1619{
1598 xfs_dabuf_t *dbp; /* data block buffer */ 1620 struct xfs_buf *dbp; /* data block buffer */
1599 xfs_dir2_data_entry_t *dep; /* data block entry */ 1621 xfs_dir2_data_entry_t *dep; /* data block entry */
1600 xfs_inode_t *dp; /* incore directory inode */ 1622 xfs_inode_t *dp; /* incore directory inode */
1601 int error; /* error return code */ 1623 int error; /* error return code */
1602 int index; /* index of leaf entry */ 1624 int index; /* index of leaf entry */
1603 xfs_dabuf_t *lbp; /* leaf buffer */ 1625 struct xfs_buf *lbp; /* leaf buffer */
1604 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1626 xfs_dir2_leaf_t *leaf; /* leaf structure */
1605 xfs_dir2_leaf_entry_t *lep; /* leaf entry */ 1627 xfs_dir2_leaf_entry_t *lep; /* leaf entry */
1606 xfs_trans_t *tp; /* transaction pointer */ 1628 xfs_trans_t *tp; /* transaction pointer */
@@ -1614,7 +1636,7 @@ xfs_dir2_leaf_replace(
1614 return error; 1636 return error;
1615 } 1637 }
1616 dp = args->dp; 1638 dp = args->dp;
1617 leaf = lbp->data; 1639 leaf = lbp->b_addr;
1618 /* 1640 /*
1619 * Point to the leaf entry, get data address from it. 1641 * Point to the leaf entry, get data address from it.
1620 */ 1642 */
@@ -1623,7 +1645,7 @@ xfs_dir2_leaf_replace(
1623 * Point to the data entry. 1645 * Point to the data entry.
1624 */ 1646 */
1625 dep = (xfs_dir2_data_entry_t *) 1647 dep = (xfs_dir2_data_entry_t *)
1626 ((char *)dbp->data + 1648 ((char *)dbp->b_addr +
1627 xfs_dir2_dataptr_to_off(dp->i_mount, be32_to_cpu(lep->address))); 1649 xfs_dir2_dataptr_to_off(dp->i_mount, be32_to_cpu(lep->address)));
1628 ASSERT(args->inumber != be64_to_cpu(dep->inumber)); 1650 ASSERT(args->inumber != be64_to_cpu(dep->inumber));
1629 /* 1651 /*
@@ -1632,9 +1654,8 @@ xfs_dir2_leaf_replace(
1632 dep->inumber = cpu_to_be64(args->inumber); 1654 dep->inumber = cpu_to_be64(args->inumber);
1633 tp = args->trans; 1655 tp = args->trans;
1634 xfs_dir2_data_log_entry(tp, dbp, dep); 1656 xfs_dir2_data_log_entry(tp, dbp, dep);
1635 xfs_da_buf_done(dbp);
1636 xfs_dir2_leaf_check(dp, lbp); 1657 xfs_dir2_leaf_check(dp, lbp);
1637 xfs_da_brelse(tp, lbp); 1658 xfs_trans_brelse(tp, lbp);
1638 return 0; 1659 return 0;
1639} 1660}
1640 1661
@@ -1646,7 +1667,7 @@ xfs_dir2_leaf_replace(
1646int /* index value */ 1667int /* index value */
1647xfs_dir2_leaf_search_hash( 1668xfs_dir2_leaf_search_hash(
1648 xfs_da_args_t *args, /* operation arguments */ 1669 xfs_da_args_t *args, /* operation arguments */
1649 xfs_dabuf_t *lbp) /* leaf buffer */ 1670 struct xfs_buf *lbp) /* leaf buffer */
1650{ 1671{
1651 xfs_dahash_t hash=0; /* hash from this entry */ 1672 xfs_dahash_t hash=0; /* hash from this entry */
1652 xfs_dahash_t hashwant; /* hash value looking for */ 1673 xfs_dahash_t hashwant; /* hash value looking for */
@@ -1656,7 +1677,7 @@ xfs_dir2_leaf_search_hash(
1656 xfs_dir2_leaf_entry_t *lep; /* leaf entry */ 1677 xfs_dir2_leaf_entry_t *lep; /* leaf entry */
1657 int mid=0; /* current leaf index */ 1678 int mid=0; /* current leaf index */
1658 1679
1659 leaf = lbp->data; 1680 leaf = lbp->b_addr;
1660#ifndef __KERNEL__ 1681#ifndef __KERNEL__
1661 if (!leaf->hdr.count) 1682 if (!leaf->hdr.count)
1662 return 0; 1683 return 0;
@@ -1699,11 +1720,11 @@ xfs_dir2_leaf_search_hash(
1699int /* error */ 1720int /* error */
1700xfs_dir2_leaf_trim_data( 1721xfs_dir2_leaf_trim_data(
1701 xfs_da_args_t *args, /* operation arguments */ 1722 xfs_da_args_t *args, /* operation arguments */
1702 xfs_dabuf_t *lbp, /* leaf buffer */ 1723 struct xfs_buf *lbp, /* leaf buffer */
1703 xfs_dir2_db_t db) /* data block number */ 1724 xfs_dir2_db_t db) /* data block number */
1704{ 1725{
1705 __be16 *bestsp; /* leaf bests table */ 1726 __be16 *bestsp; /* leaf bests table */
1706 xfs_dabuf_t *dbp; /* data block buffer */ 1727 struct xfs_buf *dbp; /* data block buffer */
1707 xfs_inode_t *dp; /* incore directory inode */ 1728 xfs_inode_t *dp; /* incore directory inode */
1708 int error; /* error return value */ 1729 int error; /* error return value */
1709 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1730 xfs_dir2_leaf_t *leaf; /* leaf structure */
@@ -1722,12 +1743,12 @@ xfs_dir2_leaf_trim_data(
1722 return error; 1743 return error;
1723 } 1744 }
1724 1745
1725 leaf = lbp->data; 1746 leaf = lbp->b_addr;
1726 ltp = xfs_dir2_leaf_tail_p(mp, leaf); 1747 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1727 1748
1728#ifdef DEBUG 1749#ifdef DEBUG
1729{ 1750{
1730 struct xfs_dir2_data_hdr *hdr = dbp->data; 1751 struct xfs_dir2_data_hdr *hdr = dbp->b_addr;
1731 1752
1732 ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC)); 1753 ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC));
1733 ASSERT(be16_to_cpu(hdr->bestfree[0].length) == 1754 ASSERT(be16_to_cpu(hdr->bestfree[0].length) ==
@@ -1741,7 +1762,7 @@ xfs_dir2_leaf_trim_data(
1741 */ 1762 */
1742 if ((error = xfs_dir2_shrink_inode(args, db, dbp))) { 1763 if ((error = xfs_dir2_shrink_inode(args, db, dbp))) {
1743 ASSERT(error != ENOSPC); 1764 ASSERT(error != ENOSPC);
1744 xfs_da_brelse(tp, dbp); 1765 xfs_trans_brelse(tp, dbp);
1745 return error; 1766 return error;
1746 } 1767 }
1747 /* 1768 /*
@@ -1781,10 +1802,10 @@ xfs_dir2_node_to_leaf(
1781 xfs_da_args_t *args; /* operation arguments */ 1802 xfs_da_args_t *args; /* operation arguments */
1782 xfs_inode_t *dp; /* incore directory inode */ 1803 xfs_inode_t *dp; /* incore directory inode */
1783 int error; /* error return code */ 1804 int error; /* error return code */
1784 xfs_dabuf_t *fbp; /* buffer for freespace block */ 1805 struct xfs_buf *fbp; /* buffer for freespace block */
1785 xfs_fileoff_t fo; /* freespace file offset */ 1806 xfs_fileoff_t fo; /* freespace file offset */
1786 xfs_dir2_free_t *free; /* freespace structure */ 1807 xfs_dir2_free_t *free; /* freespace structure */
1787 xfs_dabuf_t *lbp; /* buffer for leaf block */ 1808 struct xfs_buf *lbp; /* buffer for leaf block */
1788 xfs_dir2_leaf_tail_t *ltp; /* tail of leaf structure */ 1809 xfs_dir2_leaf_tail_t *ltp; /* tail of leaf structure */
1789 xfs_dir2_leaf_t *leaf; /* leaf structure */ 1810 xfs_dir2_leaf_t *leaf; /* leaf structure */
1790 xfs_mount_t *mp; /* filesystem mount point */ 1811 xfs_mount_t *mp; /* filesystem mount point */
@@ -1838,7 +1859,7 @@ xfs_dir2_node_to_leaf(
1838 if (XFS_FSB_TO_B(mp, fo) > XFS_DIR2_LEAF_OFFSET + mp->m_dirblksize) 1859 if (XFS_FSB_TO_B(mp, fo) > XFS_DIR2_LEAF_OFFSET + mp->m_dirblksize)
1839 return 0; 1860 return 0;
1840 lbp = state->path.blk[0].bp; 1861 lbp = state->path.blk[0].bp;
1841 leaf = lbp->data; 1862 leaf = lbp->b_addr;
1842 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC)); 1863 ASSERT(leaf->hdr.info.magic == cpu_to_be16(XFS_DIR2_LEAFN_MAGIC));
1843 /* 1864 /*
1844 * Read the freespace block. 1865 * Read the freespace block.
@@ -1847,7 +1868,7 @@ xfs_dir2_node_to_leaf(
1847 XFS_DATA_FORK))) { 1868 XFS_DATA_FORK))) {
1848 return error; 1869 return error;
1849 } 1870 }
1850 free = fbp->data; 1871 free = fbp->b_addr;
1851 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC)); 1872 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC));
1852 ASSERT(!free->hdr.firstdb); 1873 ASSERT(!free->hdr.firstdb);
1853 1874
@@ -1857,7 +1878,7 @@ xfs_dir2_node_to_leaf(
1857 */ 1878 */
1858 if (xfs_dir2_leaf_size(&leaf->hdr, be32_to_cpu(free->hdr.nvalid)) > 1879 if (xfs_dir2_leaf_size(&leaf->hdr, be32_to_cpu(free->hdr.nvalid)) >
1859 mp->m_dirblksize) { 1880 mp->m_dirblksize) {
1860 xfs_da_brelse(tp, fbp); 1881 xfs_trans_brelse(tp, fbp);
1861 return 0; 1882 return 0;
1862 } 1883 }
1863 1884