aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_bmap.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2011-05-23 04:52:53 -0400
committerAlex Elder <aelder@sgi.com>2011-05-25 11:48:37 -0400
commitec90c5563413ba6d29607397c54958d49c3461a3 (patch)
tree7ee1bb9428858d2f43b426ae71bab6a4703af6f7 /fs/xfs/xfs_bmap.c
parent548932739b16e623601f6d7dfb31a1fe28cda050 (diff)
xfs: remove if_lastex
The if_lastex field in struct xfs_ifork is only used as a temporary index during xfs_bmapi and xfs_bunmapi. Instead of using the inode fork to store it keep it local in the callchain. Fortunately this is very easy as we already pass a stack copy of it down the whole chain which can simplify be changed to be passed by reference. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Alex Elder <aelder@sgi.com>
Diffstat (limited to 'fs/xfs/xfs_bmap.c')
-rw-r--r--fs/xfs/xfs_bmap.c423
1 files changed, 203 insertions, 220 deletions
diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
index d4fc8ccafa08..8f586df8ff8d 100644
--- a/fs/xfs/xfs_bmap.c
+++ b/fs/xfs/xfs_bmap.c
@@ -89,28 +89,13 @@ xfs_bmap_add_attrfork_local(
89 int *flags); /* inode logging flags */ 89 int *flags); /* inode logging flags */
90 90
91/* 91/*
92 * Called by xfs_bmapi to update file extent records and the btree
93 * after allocating space (or doing a delayed allocation).
94 */
95STATIC int /* error */
96xfs_bmap_add_extent(
97 xfs_inode_t *ip, /* incore inode pointer */
98 xfs_extnum_t idx, /* extent number to update/insert */
99 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */
100 xfs_bmbt_irec_t *new, /* new data to add to file extents */
101 xfs_fsblock_t *first, /* pointer to firstblock variable */
102 xfs_bmap_free_t *flist, /* list of extents to be freed */
103 int *logflagsp, /* inode logging flags */
104 int whichfork); /* data or attr fork */
105
106/*
107 * Called by xfs_bmap_add_extent to handle cases converting a delayed 92 * Called by xfs_bmap_add_extent to handle cases converting a delayed
108 * allocation to a real allocation. 93 * allocation to a real allocation.
109 */ 94 */
110STATIC int /* error */ 95STATIC int /* error */
111xfs_bmap_add_extent_delay_real( 96xfs_bmap_add_extent_delay_real(
112 xfs_inode_t *ip, /* incore inode pointer */ 97 xfs_inode_t *ip, /* incore inode pointer */
113 xfs_extnum_t idx, /* extent number to update/insert */ 98 xfs_extnum_t *idx, /* extent number to update/insert */
114 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */ 99 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */
115 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 100 xfs_bmbt_irec_t *new, /* new data to add to file extents */
116 xfs_filblks_t *dnew, /* new delayed-alloc indirect blocks */ 101 xfs_filblks_t *dnew, /* new delayed-alloc indirect blocks */
@@ -125,7 +110,7 @@ xfs_bmap_add_extent_delay_real(
125STATIC int /* error */ 110STATIC int /* error */
126xfs_bmap_add_extent_hole_delay( 111xfs_bmap_add_extent_hole_delay(
127 xfs_inode_t *ip, /* incore inode pointer */ 112 xfs_inode_t *ip, /* incore inode pointer */
128 xfs_extnum_t idx, /* extent number to update/insert */ 113 xfs_extnum_t *idx, /* extent number to update/insert */
129 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 114 xfs_bmbt_irec_t *new, /* new data to add to file extents */
130 int *logflagsp); /* inode logging flags */ 115 int *logflagsp); /* inode logging flags */
131 116
@@ -136,7 +121,7 @@ xfs_bmap_add_extent_hole_delay(
136STATIC int /* error */ 121STATIC int /* error */
137xfs_bmap_add_extent_hole_real( 122xfs_bmap_add_extent_hole_real(
138 xfs_inode_t *ip, /* incore inode pointer */ 123 xfs_inode_t *ip, /* incore inode pointer */
139 xfs_extnum_t idx, /* extent number to update/insert */ 124 xfs_extnum_t *idx, /* extent number to update/insert */
140 xfs_btree_cur_t *cur, /* if null, not a btree */ 125 xfs_btree_cur_t *cur, /* if null, not a btree */
141 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 126 xfs_bmbt_irec_t *new, /* new data to add to file extents */
142 int *logflagsp, /* inode logging flags */ 127 int *logflagsp, /* inode logging flags */
@@ -149,7 +134,7 @@ xfs_bmap_add_extent_hole_real(
149STATIC int /* error */ 134STATIC int /* error */
150xfs_bmap_add_extent_unwritten_real( 135xfs_bmap_add_extent_unwritten_real(
151 xfs_inode_t *ip, /* incore inode pointer */ 136 xfs_inode_t *ip, /* incore inode pointer */
152 xfs_extnum_t idx, /* extent number to update/insert */ 137 xfs_extnum_t *idx, /* extent number to update/insert */
153 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */ 138 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */
154 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 139 xfs_bmbt_irec_t *new, /* new data to add to file extents */
155 int *logflagsp); /* inode logging flags */ 140 int *logflagsp); /* inode logging flags */
@@ -455,7 +440,7 @@ xfs_bmap_add_attrfork_local(
455STATIC int /* error */ 440STATIC int /* error */
456xfs_bmap_add_extent( 441xfs_bmap_add_extent(
457 xfs_inode_t *ip, /* incore inode pointer */ 442 xfs_inode_t *ip, /* incore inode pointer */
458 xfs_extnum_t idx, /* extent number to update/insert */ 443 xfs_extnum_t *idx, /* extent number to update/insert */
459 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */ 444 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */
460 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 445 xfs_bmbt_irec_t *new, /* new data to add to file extents */
461 xfs_fsblock_t *first, /* pointer to firstblock variable */ 446 xfs_fsblock_t *first, /* pointer to firstblock variable */
@@ -472,23 +457,27 @@ xfs_bmap_add_extent(
472 xfs_extnum_t nextents; /* number of extents in file now */ 457 xfs_extnum_t nextents; /* number of extents in file now */
473 458
474 XFS_STATS_INC(xs_add_exlist); 459 XFS_STATS_INC(xs_add_exlist);
460
475 cur = *curp; 461 cur = *curp;
476 ifp = XFS_IFORK_PTR(ip, whichfork); 462 ifp = XFS_IFORK_PTR(ip, whichfork);
477 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 463 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
478 ASSERT(idx <= nextents);
479 da_old = da_new = 0; 464 da_old = da_new = 0;
480 error = 0; 465 error = 0;
466
467 ASSERT(*idx >= 0);
468 ASSERT(*idx <= nextents);
469
481 /* 470 /*
482 * This is the first extent added to a new/empty file. 471 * This is the first extent added to a new/empty file.
483 * Special case this one, so other routines get to assume there are 472 * Special case this one, so other routines get to assume there are
484 * already extents in the list. 473 * already extents in the list.
485 */ 474 */
486 if (nextents == 0) { 475 if (nextents == 0) {
487 xfs_iext_insert(ip, 0, 1, new, 476 xfs_iext_insert(ip, *idx, 1, new,
488 whichfork == XFS_ATTR_FORK ? BMAP_ATTRFORK : 0); 477 whichfork == XFS_ATTR_FORK ? BMAP_ATTRFORK : 0);
489 478
490 ASSERT(cur == NULL); 479 ASSERT(cur == NULL);
491 ifp->if_lastex = 0; 480
492 if (!isnullstartblock(new->br_startblock)) { 481 if (!isnullstartblock(new->br_startblock)) {
493 XFS_IFORK_NEXT_SET(ip, whichfork, 1); 482 XFS_IFORK_NEXT_SET(ip, whichfork, 1);
494 logflags = XFS_ILOG_CORE | xfs_ilog_fext(whichfork); 483 logflags = XFS_ILOG_CORE | xfs_ilog_fext(whichfork);
@@ -502,27 +491,25 @@ xfs_bmap_add_extent(
502 if (cur) 491 if (cur)
503 ASSERT((cur->bc_private.b.flags & 492 ASSERT((cur->bc_private.b.flags &
504 XFS_BTCUR_BPRV_WASDEL) == 0); 493 XFS_BTCUR_BPRV_WASDEL) == 0);
505 error = xfs_bmap_add_extent_hole_delay(ip, idx, new, &logflags); 494 error = xfs_bmap_add_extent_hole_delay(ip, idx, new,
506 if (error) 495 &logflags);
507 goto done;
508 } 496 }
509 /* 497 /*
510 * Real allocation off the end of the file. 498 * Real allocation off the end of the file.
511 */ 499 */
512 else if (idx == nextents) { 500 else if (*idx == nextents) {
513 if (cur) 501 if (cur)
514 ASSERT((cur->bc_private.b.flags & 502 ASSERT((cur->bc_private.b.flags &
515 XFS_BTCUR_BPRV_WASDEL) == 0); 503 XFS_BTCUR_BPRV_WASDEL) == 0);
516 if ((error = xfs_bmap_add_extent_hole_real(ip, idx, cur, new, 504 error = xfs_bmap_add_extent_hole_real(ip, idx, cur, new,
517 &logflags, whichfork))) 505 &logflags, whichfork);
518 goto done;
519 } else { 506 } else {
520 xfs_bmbt_irec_t prev; /* old extent at offset idx */ 507 xfs_bmbt_irec_t prev; /* old extent at offset idx */
521 508
522 /* 509 /*
523 * Get the record referred to by idx. 510 * Get the record referred to by idx.
524 */ 511 */
525 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx), &prev); 512 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx), &prev);
526 /* 513 /*
527 * If it's a real allocation record, and the new allocation ends 514 * If it's a real allocation record, and the new allocation ends
528 * after the start of the referred to record, then we're filling 515 * after the start of the referred to record, then we're filling
@@ -537,23 +524,18 @@ xfs_bmap_add_extent(
537 if (cur) 524 if (cur)
538 ASSERT(cur->bc_private.b.flags & 525 ASSERT(cur->bc_private.b.flags &
539 XFS_BTCUR_BPRV_WASDEL); 526 XFS_BTCUR_BPRV_WASDEL);
540 error = xfs_bmap_add_extent_delay_real(ip, idx, 527 error = xfs_bmap_add_extent_delay_real(ip,
541 &cur, new, &da_new, first, 528 idx, &cur, new, &da_new,
542 flist, &logflags); 529 first, flist, &logflags);
543 if (error)
544 goto done;
545 } else if (new->br_state == XFS_EXT_NORM) {
546 ASSERT(new->br_state == XFS_EXT_NORM);
547 if ((error = xfs_bmap_add_extent_unwritten_real(
548 ip, idx, &cur, new, &logflags)))
549 goto done;
550 } else { 530 } else {
551 ASSERT(new->br_state == XFS_EXT_UNWRITTEN); 531 ASSERT(new->br_state == XFS_EXT_NORM ||
552 if ((error = xfs_bmap_add_extent_unwritten_real( 532 new->br_state == XFS_EXT_UNWRITTEN);
553 ip, idx, &cur, new, &logflags))) 533
534 error = xfs_bmap_add_extent_unwritten_real(ip,
535 idx, &cur, new, &logflags);
536 if (error)
554 goto done; 537 goto done;
555 } 538 }
556 ASSERT(*curp == cur || *curp == NULL);
557 } 539 }
558 /* 540 /*
559 * Otherwise we're filling in a hole with an allocation. 541 * Otherwise we're filling in a hole with an allocation.
@@ -562,13 +544,15 @@ xfs_bmap_add_extent(
562 if (cur) 544 if (cur)
563 ASSERT((cur->bc_private.b.flags & 545 ASSERT((cur->bc_private.b.flags &
564 XFS_BTCUR_BPRV_WASDEL) == 0); 546 XFS_BTCUR_BPRV_WASDEL) == 0);
565 if ((error = xfs_bmap_add_extent_hole_real(ip, idx, cur, 547 error = xfs_bmap_add_extent_hole_real(ip, idx, cur,
566 new, &logflags, whichfork))) 548 new, &logflags, whichfork);
567 goto done;
568 } 549 }
569 } 550 }
570 551
552 if (error)
553 goto done;
571 ASSERT(*curp == cur || *curp == NULL); 554 ASSERT(*curp == cur || *curp == NULL);
555
572 /* 556 /*
573 * Convert to a btree if necessary. 557 * Convert to a btree if necessary.
574 */ 558 */
@@ -621,7 +605,7 @@ done:
621STATIC int /* error */ 605STATIC int /* error */
622xfs_bmap_add_extent_delay_real( 606xfs_bmap_add_extent_delay_real(
623 xfs_inode_t *ip, /* incore inode pointer */ 607 xfs_inode_t *ip, /* incore inode pointer */
624 xfs_extnum_t idx, /* extent number to update/insert */ 608 xfs_extnum_t *idx, /* extent number to update/insert */
625 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */ 609 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */
626 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 610 xfs_bmbt_irec_t *new, /* new data to add to file extents */
627 xfs_filblks_t *dnew, /* new delayed-alloc indirect blocks */ 611 xfs_filblks_t *dnew, /* new delayed-alloc indirect blocks */
@@ -653,7 +637,7 @@ xfs_bmap_add_extent_delay_real(
653 */ 637 */
654 cur = *curp; 638 cur = *curp;
655 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); 639 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
656 ep = xfs_iext_get_ext(ifp, idx); 640 ep = xfs_iext_get_ext(ifp, *idx);
657 xfs_bmbt_get_all(ep, &PREV); 641 xfs_bmbt_get_all(ep, &PREV);
658 new_endoff = new->br_startoff + new->br_blockcount; 642 new_endoff = new->br_startoff + new->br_blockcount;
659 ASSERT(PREV.br_startoff <= new->br_startoff); 643 ASSERT(PREV.br_startoff <= new->br_startoff);
@@ -672,9 +656,9 @@ xfs_bmap_add_extent_delay_real(
672 * Check and set flags if this segment has a left neighbor. 656 * Check and set flags if this segment has a left neighbor.
673 * Don't set contiguous if the combined extent would be too large. 657 * Don't set contiguous if the combined extent would be too large.
674 */ 658 */
675 if (idx > 0) { 659 if (*idx > 0) {
676 state |= BMAP_LEFT_VALID; 660 state |= BMAP_LEFT_VALID;
677 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx - 1), &LEFT); 661 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx - 1), &LEFT);
678 662
679 if (isnullstartblock(LEFT.br_startblock)) 663 if (isnullstartblock(LEFT.br_startblock))
680 state |= BMAP_LEFT_DELAY; 664 state |= BMAP_LEFT_DELAY;
@@ -692,9 +676,9 @@ xfs_bmap_add_extent_delay_real(
692 * Don't set contiguous if the combined extent would be too large. 676 * Don't set contiguous if the combined extent would be too large.
693 * Also check for all-three-contiguous being too large. 677 * Also check for all-three-contiguous being too large.
694 */ 678 */
695 if (idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) { 679 if (*idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) {
696 state |= BMAP_RIGHT_VALID; 680 state |= BMAP_RIGHT_VALID;
697 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx + 1), &RIGHT); 681 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx + 1), &RIGHT);
698 682
699 if (isnullstartblock(RIGHT.br_startblock)) 683 if (isnullstartblock(RIGHT.br_startblock))
700 state |= BMAP_RIGHT_DELAY; 684 state |= BMAP_RIGHT_DELAY;
@@ -725,14 +709,14 @@ xfs_bmap_add_extent_delay_real(
725 * Filling in all of a previously delayed allocation extent. 709 * Filling in all of a previously delayed allocation extent.
726 * The left and right neighbors are both contiguous with new. 710 * The left and right neighbors are both contiguous with new.
727 */ 711 */
728 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 712 --*idx;
729 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 713 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
714 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx),
730 LEFT.br_blockcount + PREV.br_blockcount + 715 LEFT.br_blockcount + PREV.br_blockcount +
731 RIGHT.br_blockcount); 716 RIGHT.br_blockcount);
732 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 717 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
733 718
734 xfs_iext_remove(ip, idx, 2, state); 719 xfs_iext_remove(ip, *idx + 1, 2, state);
735 ip->i_df.if_lastex = idx - 1;
736 ip->i_d.di_nextents--; 720 ip->i_d.di_nextents--;
737 if (cur == NULL) 721 if (cur == NULL)
738 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 722 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -764,13 +748,14 @@ xfs_bmap_add_extent_delay_real(
764 * Filling in all of a previously delayed allocation extent. 748 * Filling in all of a previously delayed allocation extent.
765 * The left neighbor is contiguous, the right is not. 749 * The left neighbor is contiguous, the right is not.
766 */ 750 */
767 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 751 --*idx;
768 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 752
753 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
754 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx),
769 LEFT.br_blockcount + PREV.br_blockcount); 755 LEFT.br_blockcount + PREV.br_blockcount);
770 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 756 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
771 757
772 ip->i_df.if_lastex = idx - 1; 758 xfs_iext_remove(ip, *idx + 1, 1, state);
773 xfs_iext_remove(ip, idx, 1, state);
774 if (cur == NULL) 759 if (cur == NULL)
775 rval = XFS_ILOG_DEXT; 760 rval = XFS_ILOG_DEXT;
776 else { 761 else {
@@ -794,14 +779,13 @@ xfs_bmap_add_extent_delay_real(
794 * Filling in all of a previously delayed allocation extent. 779 * Filling in all of a previously delayed allocation extent.
795 * The right neighbor is contiguous, the left is not. 780 * The right neighbor is contiguous, the left is not.
796 */ 781 */
797 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 782 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
798 xfs_bmbt_set_startblock(ep, new->br_startblock); 783 xfs_bmbt_set_startblock(ep, new->br_startblock);
799 xfs_bmbt_set_blockcount(ep, 784 xfs_bmbt_set_blockcount(ep,
800 PREV.br_blockcount + RIGHT.br_blockcount); 785 PREV.br_blockcount + RIGHT.br_blockcount);
801 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 786 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
802 787
803 ip->i_df.if_lastex = idx; 788 xfs_iext_remove(ip, *idx + 1, 1, state);
804 xfs_iext_remove(ip, idx + 1, 1, state);
805 if (cur == NULL) 789 if (cur == NULL)
806 rval = XFS_ILOG_DEXT; 790 rval = XFS_ILOG_DEXT;
807 else { 791 else {
@@ -817,6 +801,7 @@ xfs_bmap_add_extent_delay_real(
817 RIGHT.br_blockcount, PREV.br_state))) 801 RIGHT.br_blockcount, PREV.br_state)))
818 goto done; 802 goto done;
819 } 803 }
804
820 *dnew = 0; 805 *dnew = 0;
821 break; 806 break;
822 807
@@ -826,11 +811,10 @@ xfs_bmap_add_extent_delay_real(
826 * Neither the left nor right neighbors are contiguous with 811 * Neither the left nor right neighbors are contiguous with
827 * the new one. 812 * the new one.
828 */ 813 */
829 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 814 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
830 xfs_bmbt_set_startblock(ep, new->br_startblock); 815 xfs_bmbt_set_startblock(ep, new->br_startblock);
831 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 816 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
832 817
833 ip->i_df.if_lastex = idx;
834 ip->i_d.di_nextents++; 818 ip->i_d.di_nextents++;
835 if (cur == NULL) 819 if (cur == NULL)
836 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 820 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -846,6 +830,7 @@ xfs_bmap_add_extent_delay_real(
846 goto done; 830 goto done;
847 XFS_WANT_CORRUPTED_GOTO(i == 1, done); 831 XFS_WANT_CORRUPTED_GOTO(i == 1, done);
848 } 832 }
833
849 *dnew = 0; 834 *dnew = 0;
850 break; 835 break;
851 836
@@ -854,17 +839,16 @@ xfs_bmap_add_extent_delay_real(
854 * Filling in the first part of a previous delayed allocation. 839 * Filling in the first part of a previous delayed allocation.
855 * The left neighbor is contiguous. 840 * The left neighbor is contiguous.
856 */ 841 */
857 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 842 trace_xfs_bmap_pre_update(ip, *idx - 1, state, _THIS_IP_);
858 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 843 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx - 1),
859 LEFT.br_blockcount + new->br_blockcount); 844 LEFT.br_blockcount + new->br_blockcount);
860 xfs_bmbt_set_startoff(ep, 845 xfs_bmbt_set_startoff(ep,
861 PREV.br_startoff + new->br_blockcount); 846 PREV.br_startoff + new->br_blockcount);
862 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 847 trace_xfs_bmap_post_update(ip, *idx - 1, state, _THIS_IP_);
863 848
864 temp = PREV.br_blockcount - new->br_blockcount; 849 temp = PREV.br_blockcount - new->br_blockcount;
865 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 850 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
866 xfs_bmbt_set_blockcount(ep, temp); 851 xfs_bmbt_set_blockcount(ep, temp);
867 ip->i_df.if_lastex = idx - 1;
868 if (cur == NULL) 852 if (cur == NULL)
869 rval = XFS_ILOG_DEXT; 853 rval = XFS_ILOG_DEXT;
870 else { 854 else {
@@ -884,7 +868,9 @@ xfs_bmap_add_extent_delay_real(
884 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), 868 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
885 startblockval(PREV.br_startblock)); 869 startblockval(PREV.br_startblock));
886 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); 870 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
887 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 871 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
872
873 --*idx;
888 *dnew = temp; 874 *dnew = temp;
889 break; 875 break;
890 876
@@ -893,12 +879,11 @@ xfs_bmap_add_extent_delay_real(
893 * Filling in the first part of a previous delayed allocation. 879 * Filling in the first part of a previous delayed allocation.
894 * The left neighbor is not contiguous. 880 * The left neighbor is not contiguous.
895 */ 881 */
896 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 882 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
897 xfs_bmbt_set_startoff(ep, new_endoff); 883 xfs_bmbt_set_startoff(ep, new_endoff);
898 temp = PREV.br_blockcount - new->br_blockcount; 884 temp = PREV.br_blockcount - new->br_blockcount;
899 xfs_bmbt_set_blockcount(ep, temp); 885 xfs_bmbt_set_blockcount(ep, temp);
900 xfs_iext_insert(ip, idx, 1, new, state); 886 xfs_iext_insert(ip, *idx, 1, new, state);
901 ip->i_df.if_lastex = idx;
902 ip->i_d.di_nextents++; 887 ip->i_d.di_nextents++;
903 if (cur == NULL) 888 if (cur == NULL)
904 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 889 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -926,9 +911,10 @@ xfs_bmap_add_extent_delay_real(
926 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), 911 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
927 startblockval(PREV.br_startblock) - 912 startblockval(PREV.br_startblock) -
928 (cur ? cur->bc_private.b.allocated : 0)); 913 (cur ? cur->bc_private.b.allocated : 0));
929 ep = xfs_iext_get_ext(ifp, idx + 1); 914 ep = xfs_iext_get_ext(ifp, *idx + 1);
930 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); 915 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
931 trace_xfs_bmap_post_update(ip, idx + 1, state, _THIS_IP_); 916 trace_xfs_bmap_post_update(ip, *idx + 1, state, _THIS_IP_);
917
932 *dnew = temp; 918 *dnew = temp;
933 break; 919 break;
934 920
@@ -938,15 +924,13 @@ xfs_bmap_add_extent_delay_real(
938 * The right neighbor is contiguous with the new allocation. 924 * The right neighbor is contiguous with the new allocation.
939 */ 925 */
940 temp = PREV.br_blockcount - new->br_blockcount; 926 temp = PREV.br_blockcount - new->br_blockcount;
941 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 927 trace_xfs_bmap_pre_update(ip, *idx + 1, state, _THIS_IP_);
942 trace_xfs_bmap_pre_update(ip, idx + 1, state, _THIS_IP_);
943 xfs_bmbt_set_blockcount(ep, temp); 928 xfs_bmbt_set_blockcount(ep, temp);
944 xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, idx + 1), 929 xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, *idx + 1),
945 new->br_startoff, new->br_startblock, 930 new->br_startoff, new->br_startblock,
946 new->br_blockcount + RIGHT.br_blockcount, 931 new->br_blockcount + RIGHT.br_blockcount,
947 RIGHT.br_state); 932 RIGHT.br_state);
948 trace_xfs_bmap_post_update(ip, idx + 1, state, _THIS_IP_); 933 trace_xfs_bmap_post_update(ip, *idx + 1, state, _THIS_IP_);
949 ip->i_df.if_lastex = idx + 1;
950 if (cur == NULL) 934 if (cur == NULL)
951 rval = XFS_ILOG_DEXT; 935 rval = XFS_ILOG_DEXT;
952 else { 936 else {
@@ -963,10 +947,14 @@ xfs_bmap_add_extent_delay_real(
963 RIGHT.br_state))) 947 RIGHT.br_state)))
964 goto done; 948 goto done;
965 } 949 }
950
966 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), 951 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
967 startblockval(PREV.br_startblock)); 952 startblockval(PREV.br_startblock));
953 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
968 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); 954 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
969 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 955 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
956
957 ++*idx;
970 *dnew = temp; 958 *dnew = temp;
971 break; 959 break;
972 960
@@ -976,10 +964,9 @@ xfs_bmap_add_extent_delay_real(
976 * The right neighbor is not contiguous. 964 * The right neighbor is not contiguous.
977 */ 965 */
978 temp = PREV.br_blockcount - new->br_blockcount; 966 temp = PREV.br_blockcount - new->br_blockcount;
979 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 967 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
980 xfs_bmbt_set_blockcount(ep, temp); 968 xfs_bmbt_set_blockcount(ep, temp);
981 xfs_iext_insert(ip, idx + 1, 1, new, state); 969 xfs_iext_insert(ip, *idx + 1, 1, new, state);
982 ip->i_df.if_lastex = idx + 1;
983 ip->i_d.di_nextents++; 970 ip->i_d.di_nextents++;
984 if (cur == NULL) 971 if (cur == NULL)
985 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 972 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1007,9 +994,11 @@ xfs_bmap_add_extent_delay_real(
1007 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), 994 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
1008 startblockval(PREV.br_startblock) - 995 startblockval(PREV.br_startblock) -
1009 (cur ? cur->bc_private.b.allocated : 0)); 996 (cur ? cur->bc_private.b.allocated : 0));
1010 ep = xfs_iext_get_ext(ifp, idx); 997 ep = xfs_iext_get_ext(ifp, *idx);
1011 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); 998 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
1012 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 999 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1000
1001 ++*idx;
1013 *dnew = temp; 1002 *dnew = temp;
1014 break; 1003 break;
1015 1004
@@ -1036,7 +1025,7 @@ xfs_bmap_add_extent_delay_real(
1036 */ 1025 */
1037 temp = new->br_startoff - PREV.br_startoff; 1026 temp = new->br_startoff - PREV.br_startoff;
1038 temp2 = PREV.br_startoff + PREV.br_blockcount - new_endoff; 1027 temp2 = PREV.br_startoff + PREV.br_blockcount - new_endoff;
1039 trace_xfs_bmap_pre_update(ip, idx, 0, _THIS_IP_); 1028 trace_xfs_bmap_pre_update(ip, *idx, 0, _THIS_IP_);
1040 xfs_bmbt_set_blockcount(ep, temp); /* truncate PREV */ 1029 xfs_bmbt_set_blockcount(ep, temp); /* truncate PREV */
1041 LEFT = *new; 1030 LEFT = *new;
1042 RIGHT.br_state = PREV.br_state; 1031 RIGHT.br_state = PREV.br_state;
@@ -1045,8 +1034,7 @@ xfs_bmap_add_extent_delay_real(
1045 RIGHT.br_startoff = new_endoff; 1034 RIGHT.br_startoff = new_endoff;
1046 RIGHT.br_blockcount = temp2; 1035 RIGHT.br_blockcount = temp2;
1047 /* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */ 1036 /* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */
1048 xfs_iext_insert(ip, idx + 1, 2, &LEFT, state); 1037 xfs_iext_insert(ip, *idx + 1, 2, &LEFT, state);
1049 ip->i_df.if_lastex = idx + 1;
1050 ip->i_d.di_nextents++; 1038 ip->i_d.di_nextents++;
1051 if (cur == NULL) 1039 if (cur == NULL)
1052 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 1040 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1103,13 +1091,15 @@ xfs_bmap_add_extent_delay_real(
1103 } 1091 }
1104 } 1092 }
1105 } 1093 }
1106 ep = xfs_iext_get_ext(ifp, idx); 1094 ep = xfs_iext_get_ext(ifp, *idx);
1107 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); 1095 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
1108 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1096 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1109 trace_xfs_bmap_pre_update(ip, idx + 2, state, _THIS_IP_); 1097 trace_xfs_bmap_pre_update(ip, *idx + 2, state, _THIS_IP_);
1110 xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, idx + 2), 1098 xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, *idx + 2),
1111 nullstartblock((int)temp2)); 1099 nullstartblock((int)temp2));
1112 trace_xfs_bmap_post_update(ip, idx + 2, state, _THIS_IP_); 1100 trace_xfs_bmap_post_update(ip, *idx + 2, state, _THIS_IP_);
1101
1102 ++*idx;
1113 *dnew = temp + temp2; 1103 *dnew = temp + temp2;
1114 break; 1104 break;
1115 1105
@@ -1141,7 +1131,7 @@ done:
1141STATIC int /* error */ 1131STATIC int /* error */
1142xfs_bmap_add_extent_unwritten_real( 1132xfs_bmap_add_extent_unwritten_real(
1143 xfs_inode_t *ip, /* incore inode pointer */ 1133 xfs_inode_t *ip, /* incore inode pointer */
1144 xfs_extnum_t idx, /* extent number to update/insert */ 1134 xfs_extnum_t *idx, /* extent number to update/insert */
1145 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */ 1135 xfs_btree_cur_t **curp, /* if *curp is null, not a btree */
1146 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 1136 xfs_bmbt_irec_t *new, /* new data to add to file extents */
1147 int *logflagsp) /* inode logging flags */ 1137 int *logflagsp) /* inode logging flags */
@@ -1168,7 +1158,7 @@ xfs_bmap_add_extent_unwritten_real(
1168 error = 0; 1158 error = 0;
1169 cur = *curp; 1159 cur = *curp;
1170 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); 1160 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
1171 ep = xfs_iext_get_ext(ifp, idx); 1161 ep = xfs_iext_get_ext(ifp, *idx);
1172 xfs_bmbt_get_all(ep, &PREV); 1162 xfs_bmbt_get_all(ep, &PREV);
1173 newext = new->br_state; 1163 newext = new->br_state;
1174 oldext = (newext == XFS_EXT_UNWRITTEN) ? 1164 oldext = (newext == XFS_EXT_UNWRITTEN) ?
@@ -1191,9 +1181,9 @@ xfs_bmap_add_extent_unwritten_real(
1191 * Check and set flags if this segment has a left neighbor. 1181 * Check and set flags if this segment has a left neighbor.
1192 * Don't set contiguous if the combined extent would be too large. 1182 * Don't set contiguous if the combined extent would be too large.
1193 */ 1183 */
1194 if (idx > 0) { 1184 if (*idx > 0) {
1195 state |= BMAP_LEFT_VALID; 1185 state |= BMAP_LEFT_VALID;
1196 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx - 1), &LEFT); 1186 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx - 1), &LEFT);
1197 1187
1198 if (isnullstartblock(LEFT.br_startblock)) 1188 if (isnullstartblock(LEFT.br_startblock))
1199 state |= BMAP_LEFT_DELAY; 1189 state |= BMAP_LEFT_DELAY;
@@ -1211,9 +1201,9 @@ xfs_bmap_add_extent_unwritten_real(
1211 * Don't set contiguous if the combined extent would be too large. 1201 * Don't set contiguous if the combined extent would be too large.
1212 * Also check for all-three-contiguous being too large. 1202 * Also check for all-three-contiguous being too large.
1213 */ 1203 */
1214 if (idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) { 1204 if (*idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) {
1215 state |= BMAP_RIGHT_VALID; 1205 state |= BMAP_RIGHT_VALID;
1216 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx + 1), &RIGHT); 1206 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx + 1), &RIGHT);
1217 if (isnullstartblock(RIGHT.br_startblock)) 1207 if (isnullstartblock(RIGHT.br_startblock))
1218 state |= BMAP_RIGHT_DELAY; 1208 state |= BMAP_RIGHT_DELAY;
1219 } 1209 }
@@ -1242,14 +1232,15 @@ xfs_bmap_add_extent_unwritten_real(
1242 * Setting all of a previous oldext extent to newext. 1232 * Setting all of a previous oldext extent to newext.
1243 * The left and right neighbors are both contiguous with new. 1233 * The left and right neighbors are both contiguous with new.
1244 */ 1234 */
1245 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 1235 --*idx;
1246 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 1236
1237 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1238 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx),
1247 LEFT.br_blockcount + PREV.br_blockcount + 1239 LEFT.br_blockcount + PREV.br_blockcount +
1248 RIGHT.br_blockcount); 1240 RIGHT.br_blockcount);
1249 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 1241 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1250 1242
1251 xfs_iext_remove(ip, idx, 2, state); 1243 xfs_iext_remove(ip, *idx + 1, 2, state);
1252 ip->i_df.if_lastex = idx - 1;
1253 ip->i_d.di_nextents -= 2; 1244 ip->i_d.di_nextents -= 2;
1254 if (cur == NULL) 1245 if (cur == NULL)
1255 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 1246 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1285,13 +1276,14 @@ xfs_bmap_add_extent_unwritten_real(
1285 * Setting all of a previous oldext extent to newext. 1276 * Setting all of a previous oldext extent to newext.
1286 * The left neighbor is contiguous, the right is not. 1277 * The left neighbor is contiguous, the right is not.
1287 */ 1278 */
1288 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 1279 --*idx;
1289 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 1280
1281 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1282 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx),
1290 LEFT.br_blockcount + PREV.br_blockcount); 1283 LEFT.br_blockcount + PREV.br_blockcount);
1291 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 1284 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1292 1285
1293 ip->i_df.if_lastex = idx - 1; 1286 xfs_iext_remove(ip, *idx + 1, 1, state);
1294 xfs_iext_remove(ip, idx, 1, state);
1295 ip->i_d.di_nextents--; 1287 ip->i_d.di_nextents--;
1296 if (cur == NULL) 1288 if (cur == NULL)
1297 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 1289 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1321,13 +1313,12 @@ xfs_bmap_add_extent_unwritten_real(
1321 * Setting all of a previous oldext extent to newext. 1313 * Setting all of a previous oldext extent to newext.
1322 * The right neighbor is contiguous, the left is not. 1314 * The right neighbor is contiguous, the left is not.
1323 */ 1315 */
1324 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1316 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1325 xfs_bmbt_set_blockcount(ep, 1317 xfs_bmbt_set_blockcount(ep,
1326 PREV.br_blockcount + RIGHT.br_blockcount); 1318 PREV.br_blockcount + RIGHT.br_blockcount);
1327 xfs_bmbt_set_state(ep, newext); 1319 xfs_bmbt_set_state(ep, newext);
1328 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1320 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1329 ip->i_df.if_lastex = idx; 1321 xfs_iext_remove(ip, *idx + 1, 1, state);
1330 xfs_iext_remove(ip, idx + 1, 1, state);
1331 ip->i_d.di_nextents--; 1322 ip->i_d.di_nextents--;
1332 if (cur == NULL) 1323 if (cur == NULL)
1333 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 1324 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1358,11 +1349,10 @@ xfs_bmap_add_extent_unwritten_real(
1358 * Neither the left nor right neighbors are contiguous with 1349 * Neither the left nor right neighbors are contiguous with
1359 * the new one. 1350 * the new one.
1360 */ 1351 */
1361 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1352 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1362 xfs_bmbt_set_state(ep, newext); 1353 xfs_bmbt_set_state(ep, newext);
1363 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1354 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1364 1355
1365 ip->i_df.if_lastex = idx;
1366 if (cur == NULL) 1356 if (cur == NULL)
1367 rval = XFS_ILOG_DEXT; 1357 rval = XFS_ILOG_DEXT;
1368 else { 1358 else {
@@ -1384,21 +1374,22 @@ xfs_bmap_add_extent_unwritten_real(
1384 * Setting the first part of a previous oldext extent to newext. 1374 * Setting the first part of a previous oldext extent to newext.
1385 * The left neighbor is contiguous. 1375 * The left neighbor is contiguous.
1386 */ 1376 */
1387 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 1377 trace_xfs_bmap_pre_update(ip, *idx - 1, state, _THIS_IP_);
1388 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 1378 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx - 1),
1389 LEFT.br_blockcount + new->br_blockcount); 1379 LEFT.br_blockcount + new->br_blockcount);
1390 xfs_bmbt_set_startoff(ep, 1380 xfs_bmbt_set_startoff(ep,
1391 PREV.br_startoff + new->br_blockcount); 1381 PREV.br_startoff + new->br_blockcount);
1392 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 1382 trace_xfs_bmap_post_update(ip, *idx - 1, state, _THIS_IP_);
1393 1383
1394 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1384 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1395 xfs_bmbt_set_startblock(ep, 1385 xfs_bmbt_set_startblock(ep,
1396 new->br_startblock + new->br_blockcount); 1386 new->br_startblock + new->br_blockcount);
1397 xfs_bmbt_set_blockcount(ep, 1387 xfs_bmbt_set_blockcount(ep,
1398 PREV.br_blockcount - new->br_blockcount); 1388 PREV.br_blockcount - new->br_blockcount);
1399 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1389 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1390
1391 --*idx;
1400 1392
1401 ip->i_df.if_lastex = idx - 1;
1402 if (cur == NULL) 1393 if (cur == NULL)
1403 rval = XFS_ILOG_DEXT; 1394 rval = XFS_ILOG_DEXT;
1404 else { 1395 else {
@@ -1429,17 +1420,16 @@ xfs_bmap_add_extent_unwritten_real(
1429 * Setting the first part of a previous oldext extent to newext. 1420 * Setting the first part of a previous oldext extent to newext.
1430 * The left neighbor is not contiguous. 1421 * The left neighbor is not contiguous.
1431 */ 1422 */
1432 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1423 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1433 ASSERT(ep && xfs_bmbt_get_state(ep) == oldext); 1424 ASSERT(ep && xfs_bmbt_get_state(ep) == oldext);
1434 xfs_bmbt_set_startoff(ep, new_endoff); 1425 xfs_bmbt_set_startoff(ep, new_endoff);
1435 xfs_bmbt_set_blockcount(ep, 1426 xfs_bmbt_set_blockcount(ep,
1436 PREV.br_blockcount - new->br_blockcount); 1427 PREV.br_blockcount - new->br_blockcount);
1437 xfs_bmbt_set_startblock(ep, 1428 xfs_bmbt_set_startblock(ep,
1438 new->br_startblock + new->br_blockcount); 1429 new->br_startblock + new->br_blockcount);
1439 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1430 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1440 1431
1441 xfs_iext_insert(ip, idx, 1, new, state); 1432 xfs_iext_insert(ip, *idx, 1, new, state);
1442 ip->i_df.if_lastex = idx;
1443 ip->i_d.di_nextents++; 1433 ip->i_d.di_nextents++;
1444 if (cur == NULL) 1434 if (cur == NULL)
1445 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 1435 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1468,17 +1458,19 @@ xfs_bmap_add_extent_unwritten_real(
1468 * Setting the last part of a previous oldext extent to newext. 1458 * Setting the last part of a previous oldext extent to newext.
1469 * The right neighbor is contiguous with the new allocation. 1459 * The right neighbor is contiguous with the new allocation.
1470 */ 1460 */
1471 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1461 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1472 trace_xfs_bmap_pre_update(ip, idx + 1, state, _THIS_IP_);
1473 xfs_bmbt_set_blockcount(ep, 1462 xfs_bmbt_set_blockcount(ep,
1474 PREV.br_blockcount - new->br_blockcount); 1463 PREV.br_blockcount - new->br_blockcount);
1475 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1464 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1476 xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, idx + 1), 1465
1466 ++*idx;
1467
1468 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1469 xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, *idx),
1477 new->br_startoff, new->br_startblock, 1470 new->br_startoff, new->br_startblock,
1478 new->br_blockcount + RIGHT.br_blockcount, newext); 1471 new->br_blockcount + RIGHT.br_blockcount, newext);
1479 trace_xfs_bmap_post_update(ip, idx + 1, state, _THIS_IP_); 1472 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1480 1473
1481 ip->i_df.if_lastex = idx + 1;
1482 if (cur == NULL) 1474 if (cur == NULL)
1483 rval = XFS_ILOG_DEXT; 1475 rval = XFS_ILOG_DEXT;
1484 else { 1476 else {
@@ -1508,13 +1500,14 @@ xfs_bmap_add_extent_unwritten_real(
1508 * Setting the last part of a previous oldext extent to newext. 1500 * Setting the last part of a previous oldext extent to newext.
1509 * The right neighbor is not contiguous. 1501 * The right neighbor is not contiguous.
1510 */ 1502 */
1511 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1503 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1512 xfs_bmbt_set_blockcount(ep, 1504 xfs_bmbt_set_blockcount(ep,
1513 PREV.br_blockcount - new->br_blockcount); 1505 PREV.br_blockcount - new->br_blockcount);
1514 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1506 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1507
1508 ++*idx;
1509 xfs_iext_insert(ip, *idx, 1, new, state);
1515 1510
1516 xfs_iext_insert(ip, idx + 1, 1, new, state);
1517 ip->i_df.if_lastex = idx + 1;
1518 ip->i_d.di_nextents++; 1511 ip->i_d.di_nextents++;
1519 if (cur == NULL) 1512 if (cur == NULL)
1520 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 1513 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1548,10 +1541,10 @@ xfs_bmap_add_extent_unwritten_real(
1548 * newext. Contiguity is impossible here. 1541 * newext. Contiguity is impossible here.
1549 * One extent becomes three extents. 1542 * One extent becomes three extents.
1550 */ 1543 */
1551 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1544 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1552 xfs_bmbt_set_blockcount(ep, 1545 xfs_bmbt_set_blockcount(ep,
1553 new->br_startoff - PREV.br_startoff); 1546 new->br_startoff - PREV.br_startoff);
1554 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1547 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1555 1548
1556 r[0] = *new; 1549 r[0] = *new;
1557 r[1].br_startoff = new_endoff; 1550 r[1].br_startoff = new_endoff;
@@ -1559,8 +1552,10 @@ xfs_bmap_add_extent_unwritten_real(
1559 PREV.br_startoff + PREV.br_blockcount - new_endoff; 1552 PREV.br_startoff + PREV.br_blockcount - new_endoff;
1560 r[1].br_startblock = new->br_startblock + new->br_blockcount; 1553 r[1].br_startblock = new->br_startblock + new->br_blockcount;
1561 r[1].br_state = oldext; 1554 r[1].br_state = oldext;
1562 xfs_iext_insert(ip, idx + 1, 2, &r[0], state); 1555
1563 ip->i_df.if_lastex = idx + 1; 1556 ++*idx;
1557 xfs_iext_insert(ip, *idx, 2, &r[0], state);
1558
1564 ip->i_d.di_nextents += 2; 1559 ip->i_d.di_nextents += 2;
1565 if (cur == NULL) 1560 if (cur == NULL)
1566 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; 1561 rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1630,7 +1625,7 @@ done:
1630STATIC int /* error */ 1625STATIC int /* error */
1631xfs_bmap_add_extent_hole_delay( 1626xfs_bmap_add_extent_hole_delay(
1632 xfs_inode_t *ip, /* incore inode pointer */ 1627 xfs_inode_t *ip, /* incore inode pointer */
1633 xfs_extnum_t idx, /* extent number to update/insert */ 1628 xfs_extnum_t *idx, /* extent number to update/insert */
1634 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 1629 xfs_bmbt_irec_t *new, /* new data to add to file extents */
1635 int *logflagsp) /* inode logging flags */ 1630 int *logflagsp) /* inode logging flags */
1636{ 1631{
@@ -1644,16 +1639,16 @@ xfs_bmap_add_extent_hole_delay(
1644 xfs_filblks_t temp=0; /* temp for indirect calculations */ 1639 xfs_filblks_t temp=0; /* temp for indirect calculations */
1645 1640
1646 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); 1641 ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
1647 ep = xfs_iext_get_ext(ifp, idx); 1642 ep = xfs_iext_get_ext(ifp, *idx);
1648 state = 0; 1643 state = 0;
1649 ASSERT(isnullstartblock(new->br_startblock)); 1644 ASSERT(isnullstartblock(new->br_startblock));
1650 1645
1651 /* 1646 /*
1652 * Check and set flags if this segment has a left neighbor 1647 * Check and set flags if this segment has a left neighbor
1653 */ 1648 */
1654 if (idx > 0) { 1649 if (*idx > 0) {
1655 state |= BMAP_LEFT_VALID; 1650 state |= BMAP_LEFT_VALID;
1656 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx - 1), &left); 1651 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx - 1), &left);
1657 1652
1658 if (isnullstartblock(left.br_startblock)) 1653 if (isnullstartblock(left.br_startblock))
1659 state |= BMAP_LEFT_DELAY; 1654 state |= BMAP_LEFT_DELAY;
@@ -1663,7 +1658,7 @@ xfs_bmap_add_extent_hole_delay(
1663 * Check and set flags if the current (right) segment exists. 1658 * Check and set flags if the current (right) segment exists.
1664 * If it doesn't exist, we're converting the hole at end-of-file. 1659 * If it doesn't exist, we're converting the hole at end-of-file.
1665 */ 1660 */
1666 if (idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t)) { 1661 if (*idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t)) {
1667 state |= BMAP_RIGHT_VALID; 1662 state |= BMAP_RIGHT_VALID;
1668 xfs_bmbt_get_all(ep, &right); 1663 xfs_bmbt_get_all(ep, &right);
1669 1664
@@ -1698,21 +1693,21 @@ xfs_bmap_add_extent_hole_delay(
1698 * on the left and on the right. 1693 * on the left and on the right.
1699 * Merge all three into a single extent record. 1694 * Merge all three into a single extent record.
1700 */ 1695 */
1696 --*idx;
1701 temp = left.br_blockcount + new->br_blockcount + 1697 temp = left.br_blockcount + new->br_blockcount +
1702 right.br_blockcount; 1698 right.br_blockcount;
1703 1699
1704 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 1700 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1705 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), temp); 1701 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx), temp);
1706 oldlen = startblockval(left.br_startblock) + 1702 oldlen = startblockval(left.br_startblock) +
1707 startblockval(new->br_startblock) + 1703 startblockval(new->br_startblock) +
1708 startblockval(right.br_startblock); 1704 startblockval(right.br_startblock);
1709 newlen = xfs_bmap_worst_indlen(ip, temp); 1705 newlen = xfs_bmap_worst_indlen(ip, temp);
1710 xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, idx - 1), 1706 xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, *idx),
1711 nullstartblock((int)newlen)); 1707 nullstartblock((int)newlen));
1712 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 1708 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1713 1709
1714 xfs_iext_remove(ip, idx, 1, state); 1710 xfs_iext_remove(ip, *idx + 1, 1, state);
1715 ip->i_df.if_lastex = idx - 1;
1716 break; 1711 break;
1717 1712
1718 case BMAP_LEFT_CONTIG: 1713 case BMAP_LEFT_CONTIG:
@@ -1721,17 +1716,17 @@ xfs_bmap_add_extent_hole_delay(
1721 * on the left. 1716 * on the left.
1722 * Merge the new allocation with the left neighbor. 1717 * Merge the new allocation with the left neighbor.
1723 */ 1718 */
1719 --*idx;
1724 temp = left.br_blockcount + new->br_blockcount; 1720 temp = left.br_blockcount + new->br_blockcount;
1725 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 1721
1726 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), temp); 1722 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1723 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx), temp);
1727 oldlen = startblockval(left.br_startblock) + 1724 oldlen = startblockval(left.br_startblock) +
1728 startblockval(new->br_startblock); 1725 startblockval(new->br_startblock);
1729 newlen = xfs_bmap_worst_indlen(ip, temp); 1726 newlen = xfs_bmap_worst_indlen(ip, temp);
1730 xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, idx - 1), 1727 xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, *idx),
1731 nullstartblock((int)newlen)); 1728 nullstartblock((int)newlen));
1732 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 1729 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1733
1734 ip->i_df.if_lastex = idx - 1;
1735 break; 1730 break;
1736 1731
1737 case BMAP_RIGHT_CONTIG: 1732 case BMAP_RIGHT_CONTIG:
@@ -1740,16 +1735,14 @@ xfs_bmap_add_extent_hole_delay(
1740 * on the right. 1735 * on the right.
1741 * Merge the new allocation with the right neighbor. 1736 * Merge the new allocation with the right neighbor.
1742 */ 1737 */
1743 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1738 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1744 temp = new->br_blockcount + right.br_blockcount; 1739 temp = new->br_blockcount + right.br_blockcount;
1745 oldlen = startblockval(new->br_startblock) + 1740 oldlen = startblockval(new->br_startblock) +
1746 startblockval(right.br_startblock); 1741 startblockval(right.br_startblock);
1747 newlen = xfs_bmap_worst_indlen(ip, temp); 1742 newlen = xfs_bmap_worst_indlen(ip, temp);
1748 xfs_bmbt_set_allf(ep, new->br_startoff, 1743 xfs_bmbt_set_allf(ep, new->br_startoff,
1749 nullstartblock((int)newlen), temp, right.br_state); 1744 nullstartblock((int)newlen), temp, right.br_state);
1750 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1745 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1751
1752 ip->i_df.if_lastex = idx;
1753 break; 1746 break;
1754 1747
1755 case 0: 1748 case 0:
@@ -1759,8 +1752,7 @@ xfs_bmap_add_extent_hole_delay(
1759 * Insert a new entry. 1752 * Insert a new entry.
1760 */ 1753 */
1761 oldlen = newlen = 0; 1754 oldlen = newlen = 0;
1762 xfs_iext_insert(ip, idx, 1, new, state); 1755 xfs_iext_insert(ip, *idx, 1, new, state);
1763 ip->i_df.if_lastex = idx;
1764 break; 1756 break;
1765 } 1757 }
1766 if (oldlen != newlen) { 1758 if (oldlen != newlen) {
@@ -1782,7 +1774,7 @@ xfs_bmap_add_extent_hole_delay(
1782STATIC int /* error */ 1774STATIC int /* error */
1783xfs_bmap_add_extent_hole_real( 1775xfs_bmap_add_extent_hole_real(
1784 xfs_inode_t *ip, /* incore inode pointer */ 1776 xfs_inode_t *ip, /* incore inode pointer */
1785 xfs_extnum_t idx, /* extent number to update/insert */ 1777 xfs_extnum_t *idx, /* extent number to update/insert */
1786 xfs_btree_cur_t *cur, /* if null, not a btree */ 1778 xfs_btree_cur_t *cur, /* if null, not a btree */
1787 xfs_bmbt_irec_t *new, /* new data to add to file extents */ 1779 xfs_bmbt_irec_t *new, /* new data to add to file extents */
1788 int *logflagsp, /* inode logging flags */ 1780 int *logflagsp, /* inode logging flags */
@@ -1798,8 +1790,8 @@ xfs_bmap_add_extent_hole_real(
1798 int state; /* state bits, accessed thru macros */ 1790 int state; /* state bits, accessed thru macros */
1799 1791
1800 ifp = XFS_IFORK_PTR(ip, whichfork); 1792 ifp = XFS_IFORK_PTR(ip, whichfork);
1801 ASSERT(idx <= ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t)); 1793 ASSERT(*idx <= ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t));
1802 ep = xfs_iext_get_ext(ifp, idx); 1794 ep = xfs_iext_get_ext(ifp, *idx);
1803 state = 0; 1795 state = 0;
1804 1796
1805 if (whichfork == XFS_ATTR_FORK) 1797 if (whichfork == XFS_ATTR_FORK)
@@ -1808,9 +1800,9 @@ xfs_bmap_add_extent_hole_real(
1808 /* 1800 /*
1809 * Check and set flags if this segment has a left neighbor. 1801 * Check and set flags if this segment has a left neighbor.
1810 */ 1802 */
1811 if (idx > 0) { 1803 if (*idx > 0) {
1812 state |= BMAP_LEFT_VALID; 1804 state |= BMAP_LEFT_VALID;
1813 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, idx - 1), &left); 1805 xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx - 1), &left);
1814 if (isnullstartblock(left.br_startblock)) 1806 if (isnullstartblock(left.br_startblock))
1815 state |= BMAP_LEFT_DELAY; 1807 state |= BMAP_LEFT_DELAY;
1816 } 1808 }
@@ -1819,7 +1811,7 @@ xfs_bmap_add_extent_hole_real(
1819 * Check and set flags if this segment has a current value. 1811 * Check and set flags if this segment has a current value.
1820 * Not true if we're inserting into the "hole" at eof. 1812 * Not true if we're inserting into the "hole" at eof.
1821 */ 1813 */
1822 if (idx < ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t)) { 1814 if (*idx < ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t)) {
1823 state |= BMAP_RIGHT_VALID; 1815 state |= BMAP_RIGHT_VALID;
1824 xfs_bmbt_get_all(ep, &right); 1816 xfs_bmbt_get_all(ep, &right);
1825 if (isnullstartblock(right.br_startblock)) 1817 if (isnullstartblock(right.br_startblock))
@@ -1858,14 +1850,15 @@ xfs_bmap_add_extent_hole_real(
1858 * left and on the right. 1850 * left and on the right.
1859 * Merge all three into a single extent record. 1851 * Merge all three into a single extent record.
1860 */ 1852 */
1861 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 1853 --*idx;
1862 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 1854 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1855 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx),
1863 left.br_blockcount + new->br_blockcount + 1856 left.br_blockcount + new->br_blockcount +
1864 right.br_blockcount); 1857 right.br_blockcount);
1865 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 1858 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1859
1860 xfs_iext_remove(ip, *idx + 1, 1, state);
1866 1861
1867 xfs_iext_remove(ip, idx, 1, state);
1868 ifp->if_lastex = idx - 1;
1869 XFS_IFORK_NEXT_SET(ip, whichfork, 1862 XFS_IFORK_NEXT_SET(ip, whichfork,
1870 XFS_IFORK_NEXTENTS(ip, whichfork) - 1); 1863 XFS_IFORK_NEXTENTS(ip, whichfork) - 1);
1871 if (cur == NULL) { 1864 if (cur == NULL) {
@@ -1900,12 +1893,12 @@ xfs_bmap_add_extent_hole_real(
1900 * on the left. 1893 * on the left.
1901 * Merge the new allocation with the left neighbor. 1894 * Merge the new allocation with the left neighbor.
1902 */ 1895 */
1903 trace_xfs_bmap_pre_update(ip, idx - 1, state, _THIS_IP_); 1896 --*idx;
1904 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, idx - 1), 1897 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1898 xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx),
1905 left.br_blockcount + new->br_blockcount); 1899 left.br_blockcount + new->br_blockcount);
1906 trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_); 1900 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1907 1901
1908 ifp->if_lastex = idx - 1;
1909 if (cur == NULL) { 1902 if (cur == NULL) {
1910 rval = xfs_ilog_fext(whichfork); 1903 rval = xfs_ilog_fext(whichfork);
1911 } else { 1904 } else {
@@ -1931,13 +1924,12 @@ xfs_bmap_add_extent_hole_real(
1931 * on the right. 1924 * on the right.
1932 * Merge the new allocation with the right neighbor. 1925 * Merge the new allocation with the right neighbor.
1933 */ 1926 */
1934 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 1927 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
1935 xfs_bmbt_set_allf(ep, new->br_startoff, new->br_startblock, 1928 xfs_bmbt_set_allf(ep, new->br_startoff, new->br_startblock,
1936 new->br_blockcount + right.br_blockcount, 1929 new->br_blockcount + right.br_blockcount,
1937 right.br_state); 1930 right.br_state);
1938 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 1931 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
1939 1932
1940 ifp->if_lastex = idx;
1941 if (cur == NULL) { 1933 if (cur == NULL) {
1942 rval = xfs_ilog_fext(whichfork); 1934 rval = xfs_ilog_fext(whichfork);
1943 } else { 1935 } else {
@@ -1963,8 +1955,7 @@ xfs_bmap_add_extent_hole_real(
1963 * real allocation. 1955 * real allocation.
1964 * Insert a new entry. 1956 * Insert a new entry.
1965 */ 1957 */
1966 xfs_iext_insert(ip, idx, 1, new, state); 1958 xfs_iext_insert(ip, *idx, 1, new, state);
1967 ifp->if_lastex = idx;
1968 XFS_IFORK_NEXT_SET(ip, whichfork, 1959 XFS_IFORK_NEXT_SET(ip, whichfork,
1969 XFS_IFORK_NEXTENTS(ip, whichfork) + 1); 1960 XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
1970 if (cur == NULL) { 1961 if (cur == NULL) {
@@ -2812,7 +2803,7 @@ STATIC int /* error */
2812xfs_bmap_del_extent( 2803xfs_bmap_del_extent(
2813 xfs_inode_t *ip, /* incore inode pointer */ 2804 xfs_inode_t *ip, /* incore inode pointer */
2814 xfs_trans_t *tp, /* current transaction pointer */ 2805 xfs_trans_t *tp, /* current transaction pointer */
2815 xfs_extnum_t idx, /* extent number to update/delete */ 2806 xfs_extnum_t *idx, /* extent number to update/delete */
2816 xfs_bmap_free_t *flist, /* list of extents to be freed */ 2807 xfs_bmap_free_t *flist, /* list of extents to be freed */
2817 xfs_btree_cur_t *cur, /* if null, not a btree */ 2808 xfs_btree_cur_t *cur, /* if null, not a btree */
2818 xfs_bmbt_irec_t *del, /* data to remove from extents */ 2809 xfs_bmbt_irec_t *del, /* data to remove from extents */
@@ -2848,10 +2839,10 @@ xfs_bmap_del_extent(
2848 2839
2849 mp = ip->i_mount; 2840 mp = ip->i_mount;
2850 ifp = XFS_IFORK_PTR(ip, whichfork); 2841 ifp = XFS_IFORK_PTR(ip, whichfork);
2851 ASSERT((idx >= 0) && (idx < ifp->if_bytes / 2842 ASSERT((*idx >= 0) && (*idx < ifp->if_bytes /
2852 (uint)sizeof(xfs_bmbt_rec_t))); 2843 (uint)sizeof(xfs_bmbt_rec_t)));
2853 ASSERT(del->br_blockcount > 0); 2844 ASSERT(del->br_blockcount > 0);
2854 ep = xfs_iext_get_ext(ifp, idx); 2845 ep = xfs_iext_get_ext(ifp, *idx);
2855 xfs_bmbt_get_all(ep, &got); 2846 xfs_bmbt_get_all(ep, &got);
2856 ASSERT(got.br_startoff <= del->br_startoff); 2847 ASSERT(got.br_startoff <= del->br_startoff);
2857 del_endoff = del->br_startoff + del->br_blockcount; 2848 del_endoff = del->br_startoff + del->br_blockcount;
@@ -2925,9 +2916,8 @@ xfs_bmap_del_extent(
2925 /* 2916 /*
2926 * Matches the whole extent. Delete the entry. 2917 * Matches the whole extent. Delete the entry.
2927 */ 2918 */
2928 xfs_iext_remove(ip, idx, 1, 2919 xfs_iext_remove(ip, *idx, 1,
2929 whichfork == XFS_ATTR_FORK ? BMAP_ATTRFORK : 0); 2920 whichfork == XFS_ATTR_FORK ? BMAP_ATTRFORK : 0);
2930 ifp->if_lastex = idx;
2931 if (delay) 2921 if (delay)
2932 break; 2922 break;
2933 XFS_IFORK_NEXT_SET(ip, whichfork, 2923 XFS_IFORK_NEXT_SET(ip, whichfork,
@@ -2946,21 +2936,20 @@ xfs_bmap_del_extent(
2946 /* 2936 /*
2947 * Deleting the first part of the extent. 2937 * Deleting the first part of the extent.
2948 */ 2938 */
2949 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 2939 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
2950 xfs_bmbt_set_startoff(ep, del_endoff); 2940 xfs_bmbt_set_startoff(ep, del_endoff);
2951 temp = got.br_blockcount - del->br_blockcount; 2941 temp = got.br_blockcount - del->br_blockcount;
2952 xfs_bmbt_set_blockcount(ep, temp); 2942 xfs_bmbt_set_blockcount(ep, temp);
2953 ifp->if_lastex = idx;
2954 if (delay) { 2943 if (delay) {
2955 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), 2944 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
2956 da_old); 2945 da_old);
2957 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); 2946 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
2958 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 2947 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
2959 da_new = temp; 2948 da_new = temp;
2960 break; 2949 break;
2961 } 2950 }
2962 xfs_bmbt_set_startblock(ep, del_endblock); 2951 xfs_bmbt_set_startblock(ep, del_endblock);
2963 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 2952 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
2964 if (!cur) { 2953 if (!cur) {
2965 flags |= xfs_ilog_fext(whichfork); 2954 flags |= xfs_ilog_fext(whichfork);
2966 break; 2955 break;
@@ -2976,18 +2965,17 @@ xfs_bmap_del_extent(
2976 * Deleting the last part of the extent. 2965 * Deleting the last part of the extent.
2977 */ 2966 */
2978 temp = got.br_blockcount - del->br_blockcount; 2967 temp = got.br_blockcount - del->br_blockcount;
2979 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 2968 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
2980 xfs_bmbt_set_blockcount(ep, temp); 2969 xfs_bmbt_set_blockcount(ep, temp);
2981 ifp->if_lastex = idx;
2982 if (delay) { 2970 if (delay) {
2983 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), 2971 temp = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp),
2984 da_old); 2972 da_old);
2985 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); 2973 xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
2986 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 2974 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
2987 da_new = temp; 2975 da_new = temp;
2988 break; 2976 break;
2989 } 2977 }
2990 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 2978 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
2991 if (!cur) { 2979 if (!cur) {
2992 flags |= xfs_ilog_fext(whichfork); 2980 flags |= xfs_ilog_fext(whichfork);
2993 break; 2981 break;
@@ -3004,7 +2992,7 @@ xfs_bmap_del_extent(
3004 * Deleting the middle of the extent. 2992 * Deleting the middle of the extent.
3005 */ 2993 */
3006 temp = del->br_startoff - got.br_startoff; 2994 temp = del->br_startoff - got.br_startoff;
3007 trace_xfs_bmap_pre_update(ip, idx, state, _THIS_IP_); 2995 trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_);
3008 xfs_bmbt_set_blockcount(ep, temp); 2996 xfs_bmbt_set_blockcount(ep, temp);
3009 new.br_startoff = del_endoff; 2997 new.br_startoff = del_endoff;
3010 temp2 = got_endoff - del_endoff; 2998 temp2 = got_endoff - del_endoff;
@@ -3091,9 +3079,9 @@ xfs_bmap_del_extent(
3091 } 3079 }
3092 } 3080 }
3093 } 3081 }
3094 trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_); 3082 trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_);
3095 xfs_iext_insert(ip, idx + 1, 1, &new, state); 3083 xfs_iext_insert(ip, *idx + 1, 1, &new, state);
3096 ifp->if_lastex = idx + 1; 3084 ++*idx;
3097 break; 3085 break;
3098 } 3086 }
3099 /* 3087 /*
@@ -4674,13 +4662,12 @@ xfs_bmapi(
4674 if (!wasdelay && (flags & XFS_BMAPI_PREALLOC)) 4662 if (!wasdelay && (flags & XFS_BMAPI_PREALLOC))
4675 got.br_state = XFS_EXT_UNWRITTEN; 4663 got.br_state = XFS_EXT_UNWRITTEN;
4676 } 4664 }
4677 error = xfs_bmap_add_extent(ip, lastx, &cur, &got, 4665 error = xfs_bmap_add_extent(ip, &lastx, &cur, &got,
4678 firstblock, flist, &tmp_logflags, 4666 firstblock, flist, &tmp_logflags,
4679 whichfork); 4667 whichfork);
4680 logflags |= tmp_logflags; 4668 logflags |= tmp_logflags;
4681 if (error) 4669 if (error)
4682 goto error0; 4670 goto error0;
4683 lastx = ifp->if_lastex;
4684 ep = xfs_iext_get_ext(ifp, lastx); 4671 ep = xfs_iext_get_ext(ifp, lastx);
4685 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 4672 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
4686 xfs_bmbt_get_all(ep, &got); 4673 xfs_bmbt_get_all(ep, &got);
@@ -4776,13 +4763,12 @@ xfs_bmapi(
4776 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) 4763 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN)
4777 ? XFS_EXT_NORM 4764 ? XFS_EXT_NORM
4778 : XFS_EXT_UNWRITTEN; 4765 : XFS_EXT_UNWRITTEN;
4779 error = xfs_bmap_add_extent(ip, lastx, &cur, mval, 4766 error = xfs_bmap_add_extent(ip, &lastx, &cur, mval,
4780 firstblock, flist, &tmp_logflags, 4767 firstblock, flist, &tmp_logflags,
4781 whichfork); 4768 whichfork);
4782 logflags |= tmp_logflags; 4769 logflags |= tmp_logflags;
4783 if (error) 4770 if (error)
4784 goto error0; 4771 goto error0;
4785 lastx = ifp->if_lastex;
4786 ep = xfs_iext_get_ext(ifp, lastx); 4772 ep = xfs_iext_get_ext(ifp, lastx);
4787 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t); 4773 nextents = ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t);
4788 xfs_bmbt_get_all(ep, &got); 4774 xfs_bmbt_get_all(ep, &got);
@@ -4848,7 +4834,6 @@ xfs_bmapi(
4848 else 4834 else
4849 xfs_bmbt_get_all(ep, &got); 4835 xfs_bmbt_get_all(ep, &got);
4850 } 4836 }
4851 ifp->if_lastex = lastx;
4852 *nmap = n; 4837 *nmap = n;
4853 /* 4838 /*
4854 * Transform from btree to extents, give it cur. 4839 * Transform from btree to extents, give it cur.
@@ -4957,7 +4942,6 @@ xfs_bmapi_single(
4957 ASSERT(!isnullstartblock(got.br_startblock)); 4942 ASSERT(!isnullstartblock(got.br_startblock));
4958 ASSERT(bno < got.br_startoff + got.br_blockcount); 4943 ASSERT(bno < got.br_startoff + got.br_blockcount);
4959 *fsb = got.br_startblock + (bno - got.br_startoff); 4944 *fsb = got.br_startblock + (bno - got.br_startoff);
4960 ifp->if_lastex = lastx;
4961 return 0; 4945 return 0;
4962} 4946}
4963 4947
@@ -5132,7 +5116,7 @@ xfs_bunmapi(
5132 del.br_blockcount = mod; 5116 del.br_blockcount = mod;
5133 } 5117 }
5134 del.br_state = XFS_EXT_UNWRITTEN; 5118 del.br_state = XFS_EXT_UNWRITTEN;
5135 error = xfs_bmap_add_extent(ip, lastx, &cur, &del, 5119 error = xfs_bmap_add_extent(ip, &lastx, &cur, &del,
5136 firstblock, flist, &logflags, 5120 firstblock, flist, &logflags,
5137 XFS_DATA_FORK); 5121 XFS_DATA_FORK);
5138 if (error) 5122 if (error)
@@ -5186,7 +5170,8 @@ xfs_bunmapi(
5186 prev.br_startoff = start; 5170 prev.br_startoff = start;
5187 } 5171 }
5188 prev.br_state = XFS_EXT_UNWRITTEN; 5172 prev.br_state = XFS_EXT_UNWRITTEN;
5189 error = xfs_bmap_add_extent(ip, lastx - 1, &cur, 5173 lastx--;
5174 error = xfs_bmap_add_extent(ip, &lastx, &cur,
5190 &prev, firstblock, flist, &logflags, 5175 &prev, firstblock, flist, &logflags,
5191 XFS_DATA_FORK); 5176 XFS_DATA_FORK);
5192 if (error) 5177 if (error)
@@ -5195,7 +5180,7 @@ xfs_bunmapi(
5195 } else { 5180 } else {
5196 ASSERT(del.br_state == XFS_EXT_NORM); 5181 ASSERT(del.br_state == XFS_EXT_NORM);
5197 del.br_state = XFS_EXT_UNWRITTEN; 5182 del.br_state = XFS_EXT_UNWRITTEN;
5198 error = xfs_bmap_add_extent(ip, lastx, &cur, 5183 error = xfs_bmap_add_extent(ip, &lastx, &cur,
5199 &del, firstblock, flist, &logflags, 5184 &del, firstblock, flist, &logflags,
5200 XFS_DATA_FORK); 5185 XFS_DATA_FORK);
5201 if (error) 5186 if (error)
@@ -5249,14 +5234,13 @@ xfs_bunmapi(
5249 error = XFS_ERROR(ENOSPC); 5234 error = XFS_ERROR(ENOSPC);
5250 goto error0; 5235 goto error0;
5251 } 5236 }
5252 error = xfs_bmap_del_extent(ip, tp, lastx, flist, cur, &del, 5237 error = xfs_bmap_del_extent(ip, tp, &lastx, flist, cur, &del,
5253 &tmp_logflags, whichfork); 5238 &tmp_logflags, whichfork);
5254 logflags |= tmp_logflags; 5239 logflags |= tmp_logflags;
5255 if (error) 5240 if (error)
5256 goto error0; 5241 goto error0;
5257 bno = del.br_startoff - 1; 5242 bno = del.br_startoff - 1;
5258nodelete: 5243nodelete:
5259 lastx = ifp->if_lastex;
5260 /* 5244 /*
5261 * If not done go on to the next (previous) record. 5245 * If not done go on to the next (previous) record.
5262 * Reset ep in case the extents array was re-alloced. 5246 * Reset ep in case the extents array was re-alloced.
@@ -5273,7 +5257,6 @@ nodelete:
5273 extno++; 5257 extno++;
5274 } 5258 }
5275 } 5259 }
5276 ifp->if_lastex = lastx;
5277 *done = bno == (xfs_fileoff_t)-1 || bno < start || lastx < 0; 5260 *done = bno == (xfs_fileoff_t)-1 || bno < start || lastx < 0;
5278 ASSERT(ifp->if_ext_max == 5261 ASSERT(ifp->if_ext_max ==
5279 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t)); 5262 XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));