xfs: pass bmalloca to xfs_bmap_add_extent_delay_real

All the parameters passed to xfs_bmap_add_extent_delay_real() are in
the xfs_bmalloca structure now. Just pass the bmalloca parameter to
the function instead of 8 separate parameters.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
This commit is contained in:
Christoph Hellwig
2011-09-18 20:41:04 +00:00
committed by Alex Elder
parent c315c90b7d
commit 572a4cf04a

View File

@@ -375,16 +375,9 @@ xfs_bmap_add_attrfork_local(
*/ */
STATIC int /* error */ STATIC int /* error */
xfs_bmap_add_extent_delay_real( xfs_bmap_add_extent_delay_real(
struct xfs_trans *tp, /* transaction pointer */ struct xfs_bmalloca *bma)
xfs_inode_t *ip, /* incore inode pointer */
xfs_extnum_t *idx, /* extent number to update/insert */
xfs_btree_cur_t **curp, /* if *curp is null, not a btree */
xfs_bmbt_irec_t *new, /* new data to add to file extents */
xfs_fsblock_t *first, /* pointer to firstblock variable */
xfs_bmap_free_t *flist, /* list of extents to be freed */
int *logflagsp) /* inode logging flags */
{ {
xfs_btree_cur_t *cur; /* btree cursor */ struct xfs_bmbt_irec *new = &bma->got;
int diff; /* temp value */ int diff; /* temp value */
xfs_bmbt_rec_host_t *ep; /* extent entry for idx */ xfs_bmbt_rec_host_t *ep; /* extent entry for idx */
int error; /* error return value */ int error; /* error return value */
@@ -401,18 +394,16 @@ xfs_bmap_add_extent_delay_real(
xfs_filblks_t temp2=0;/* value for da_new calculations */ xfs_filblks_t temp2=0;/* value for da_new calculations */
int tmp_rval; /* partial logging flags */ int tmp_rval; /* partial logging flags */
ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK); ifp = XFS_IFORK_PTR(bma->ip, XFS_DATA_FORK);
cur = *curp;
ASSERT(*idx >= 0); ASSERT(bma->idx >= 0);
ASSERT(*idx <= ifp->if_bytes / sizeof(struct xfs_bmbt_rec)); ASSERT(bma->idx <= ifp->if_bytes / sizeof(struct xfs_bmbt_rec));
ASSERT(!isnullstartblock(new->br_startblock)); ASSERT(!isnullstartblock(new->br_startblock));
ASSERT(!cur || (cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL)); ASSERT(!bma->cur ||
(bma->cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL));
XFS_STATS_INC(xs_add_exlist); XFS_STATS_INC(xs_add_exlist);
*logflagsp = 0;
#define LEFT r[0] #define LEFT r[0]
#define RIGHT r[1] #define RIGHT r[1]
#define PREV r[2] #define PREV r[2]
@@ -420,7 +411,7 @@ xfs_bmap_add_extent_delay_real(
/* /*
* Set up a bunch of variables to make the tests simpler. * Set up a bunch of variables to make the tests simpler.
*/ */
ep = xfs_iext_get_ext(ifp, *idx); ep = xfs_iext_get_ext(ifp, bma->idx);
xfs_bmbt_get_all(ep, &PREV); xfs_bmbt_get_all(ep, &PREV);
new_endoff = new->br_startoff + new->br_blockcount; new_endoff = new->br_startoff + new->br_blockcount;
ASSERT(PREV.br_startoff <= new->br_startoff); ASSERT(PREV.br_startoff <= new->br_startoff);
@@ -442,9 +433,9 @@ xfs_bmap_add_extent_delay_real(
* Check and set flags if this segment has a left neighbor. * Check and set flags if this segment has a left neighbor.
* Don't set contiguous if the combined extent would be too large. * Don't set contiguous if the combined extent would be too large.
*/ */
if (*idx > 0) { if (bma->idx > 0) {
state |= BMAP_LEFT_VALID; state |= BMAP_LEFT_VALID;
xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx - 1), &LEFT); xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma->idx - 1), &LEFT);
if (isnullstartblock(LEFT.br_startblock)) if (isnullstartblock(LEFT.br_startblock))
state |= BMAP_LEFT_DELAY; state |= BMAP_LEFT_DELAY;
@@ -462,9 +453,9 @@ xfs_bmap_add_extent_delay_real(
* Don't set contiguous if the combined extent would be too large. * Don't set contiguous if the combined extent would be too large.
* Also check for all-three-contiguous being too large. * Also check for all-three-contiguous being too large.
*/ */
if (*idx < ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) { if (bma->idx < bma->ip->i_df.if_bytes / (uint)sizeof(xfs_bmbt_rec_t) - 1) {
state |= BMAP_RIGHT_VALID; state |= BMAP_RIGHT_VALID;
xfs_bmbt_get_all(xfs_iext_get_ext(ifp, *idx + 1), &RIGHT); xfs_bmbt_get_all(xfs_iext_get_ext(ifp, bma->idx + 1), &RIGHT);
if (isnullstartblock(RIGHT.br_startblock)) if (isnullstartblock(RIGHT.br_startblock))
state |= BMAP_RIGHT_DELAY; state |= BMAP_RIGHT_DELAY;
@@ -495,35 +486,39 @@ xfs_bmap_add_extent_delay_real(
* Filling in all of a previously delayed allocation extent. * Filling in all of a previously delayed allocation extent.
* The left and right neighbors are both contiguous with new. * The left and right neighbors are both contiguous with new.
*/ */
--*idx; bma->idx--;
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx), xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, bma->idx),
LEFT.br_blockcount + PREV.br_blockcount + LEFT.br_blockcount + PREV.br_blockcount +
RIGHT.br_blockcount); RIGHT.br_blockcount);
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_iext_remove(ip, *idx + 1, 2, state); xfs_iext_remove(bma->ip, bma->idx + 1, 2, state);
ip->i_d.di_nextents--; bma->ip->i_d.di_nextents--;
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
else { else {
rval = XFS_ILOG_CORE; rval = XFS_ILOG_CORE;
if ((error = xfs_bmbt_lookup_eq(cur, RIGHT.br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, RIGHT.br_startoff,
RIGHT.br_startblock, RIGHT.br_startblock,
RIGHT.br_blockcount, &i))) RIGHT.br_blockcount, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
if ((error = xfs_btree_delete(cur, &i))) error = xfs_btree_delete(bma->cur, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
if ((error = xfs_btree_decrement(cur, 0, &i))) error = xfs_btree_decrement(bma->cur, 0, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, error = xfs_bmbt_update(bma->cur, LEFT.br_startoff,
LEFT.br_startblock, LEFT.br_startblock,
LEFT.br_blockcount + LEFT.br_blockcount +
PREV.br_blockcount + PREV.br_blockcount +
RIGHT.br_blockcount, LEFT.br_state))) RIGHT.br_blockcount, LEFT.br_state);
if (error)
goto done; goto done;
} }
break; break;
@@ -533,27 +528,29 @@ xfs_bmap_add_extent_delay_real(
* Filling in all of a previously delayed allocation extent. * Filling in all of a previously delayed allocation extent.
* The left neighbor is contiguous, the right is not. * The left neighbor is contiguous, the right is not.
*/ */
--*idx; bma->idx--;
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx), xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, bma->idx),
LEFT.br_blockcount + PREV.br_blockcount); LEFT.br_blockcount + PREV.br_blockcount);
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_iext_remove(ip, *idx + 1, 1, state); xfs_iext_remove(bma->ip, bma->idx + 1, 1, state);
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_DEXT; rval = XFS_ILOG_DEXT;
else { else {
rval = 0; rval = 0;
if ((error = xfs_bmbt_lookup_eq(cur, LEFT.br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, LEFT.br_startoff,
LEFT.br_startblock, LEFT.br_blockcount, LEFT.br_startblock, LEFT.br_blockcount,
&i))) &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, error = xfs_bmbt_update(bma->cur, LEFT.br_startoff,
LEFT.br_startblock, LEFT.br_startblock,
LEFT.br_blockcount + LEFT.br_blockcount +
PREV.br_blockcount, LEFT.br_state))) PREV.br_blockcount, LEFT.br_state);
if (error)
goto done; goto done;
} }
break; break;
@@ -563,26 +560,28 @@ xfs_bmap_add_extent_delay_real(
* Filling in all of a previously delayed allocation extent. * Filling in all of a previously delayed allocation extent.
* The right neighbor is contiguous, the left is not. * The right neighbor is contiguous, the left is not.
*/ */
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_startblock(ep, new->br_startblock); xfs_bmbt_set_startblock(ep, new->br_startblock);
xfs_bmbt_set_blockcount(ep, xfs_bmbt_set_blockcount(ep,
PREV.br_blockcount + RIGHT.br_blockcount); PREV.br_blockcount + RIGHT.br_blockcount);
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_iext_remove(ip, *idx + 1, 1, state); xfs_iext_remove(bma->ip, bma->idx + 1, 1, state);
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_DEXT; rval = XFS_ILOG_DEXT;
else { else {
rval = 0; rval = 0;
if ((error = xfs_bmbt_lookup_eq(cur, RIGHT.br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, RIGHT.br_startoff,
RIGHT.br_startblock, RIGHT.br_startblock,
RIGHT.br_blockcount, &i))) RIGHT.br_blockcount, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
if ((error = xfs_bmbt_update(cur, PREV.br_startoff, error = xfs_bmbt_update(bma->cur, PREV.br_startoff,
new->br_startblock, new->br_startblock,
PREV.br_blockcount + PREV.br_blockcount +
RIGHT.br_blockcount, PREV.br_state))) RIGHT.br_blockcount, PREV.br_state);
if (error)
goto done; goto done;
} }
break; break;
@@ -593,22 +592,24 @@ xfs_bmap_add_extent_delay_real(
* Neither the left nor right neighbors are contiguous with * Neither the left nor right neighbors are contiguous with
* the new one. * the new one.
*/ */
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_startblock(ep, new->br_startblock); xfs_bmbt_set_startblock(ep, new->br_startblock);
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
ip->i_d.di_nextents++; bma->ip->i_d.di_nextents++;
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
else { else {
rval = XFS_ILOG_CORE; rval = XFS_ILOG_CORE;
if ((error = xfs_bmbt_lookup_eq(cur, new->br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, new->br_startoff,
new->br_startblock, new->br_blockcount, new->br_startblock, new->br_blockcount,
&i))) &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 0, done); XFS_WANT_CORRUPTED_GOTO(i == 0, done);
cur->bc_rec.b.br_state = XFS_EXT_NORM; bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
if ((error = xfs_btree_insert(cur, &i))) error = xfs_btree_insert(bma->cur, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
} }
@@ -619,38 +620,40 @@ xfs_bmap_add_extent_delay_real(
* Filling in the first part of a previous delayed allocation. * Filling in the first part of a previous delayed allocation.
* The left neighbor is contiguous. * The left neighbor is contiguous.
*/ */
trace_xfs_bmap_pre_update(ip, *idx - 1, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx - 1, state, _THIS_IP_);
xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, *idx - 1), xfs_bmbt_set_blockcount(xfs_iext_get_ext(ifp, bma->idx - 1),
LEFT.br_blockcount + new->br_blockcount); LEFT.br_blockcount + new->br_blockcount);
xfs_bmbt_set_startoff(ep, xfs_bmbt_set_startoff(ep,
PREV.br_startoff + new->br_blockcount); PREV.br_startoff + new->br_blockcount);
trace_xfs_bmap_post_update(ip, *idx - 1, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx - 1, state, _THIS_IP_);
temp = PREV.br_blockcount - new->br_blockcount; temp = PREV.br_blockcount - new->br_blockcount;
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_blockcount(ep, temp); xfs_bmbt_set_blockcount(ep, temp);
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_DEXT; rval = XFS_ILOG_DEXT;
else { else {
rval = 0; rval = 0;
if ((error = xfs_bmbt_lookup_eq(cur, LEFT.br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, LEFT.br_startoff,
LEFT.br_startblock, LEFT.br_blockcount, LEFT.br_startblock, LEFT.br_blockcount,
&i))) &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
if ((error = xfs_bmbt_update(cur, LEFT.br_startoff, error = xfs_bmbt_update(bma->cur, LEFT.br_startoff,
LEFT.br_startblock, LEFT.br_startblock,
LEFT.br_blockcount + LEFT.br_blockcount +
new->br_blockcount, new->br_blockcount,
LEFT.br_state))) LEFT.br_state);
if (error)
goto done; goto done;
} }
da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
startblockval(PREV.br_startblock)); startblockval(PREV.br_startblock));
xfs_bmbt_set_startblock(ep, nullstartblock(da_new)); xfs_bmbt_set_startblock(ep, nullstartblock(da_new));
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
--*idx; bma->idx--;
break; break;
case BMAP_LEFT_FILLING: case BMAP_LEFT_FILLING:
@@ -658,41 +661,43 @@ xfs_bmap_add_extent_delay_real(
* Filling in the first part of a previous delayed allocation. * Filling in the first part of a previous delayed allocation.
* The left neighbor is not contiguous. * The left neighbor is not contiguous.
*/ */
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_startoff(ep, new_endoff); xfs_bmbt_set_startoff(ep, new_endoff);
temp = PREV.br_blockcount - new->br_blockcount; temp = PREV.br_blockcount - new->br_blockcount;
xfs_bmbt_set_blockcount(ep, temp); xfs_bmbt_set_blockcount(ep, temp);
xfs_iext_insert(ip, *idx, 1, new, state); xfs_iext_insert(bma->ip, bma->idx, 1, new, state);
ip->i_d.di_nextents++; bma->ip->i_d.di_nextents++;
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
else { else {
rval = XFS_ILOG_CORE; rval = XFS_ILOG_CORE;
if ((error = xfs_bmbt_lookup_eq(cur, new->br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, new->br_startoff,
new->br_startblock, new->br_blockcount, new->br_startblock, new->br_blockcount,
&i))) &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 0, done); XFS_WANT_CORRUPTED_GOTO(i == 0, done);
cur->bc_rec.b.br_state = XFS_EXT_NORM; bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
if ((error = xfs_btree_insert(cur, &i))) error = xfs_btree_insert(bma->cur, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
} }
if (ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && if (bma->ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS &&
ip->i_d.di_nextents > ip->i_df.if_ext_max) { bma->ip->i_d.di_nextents > bma->ip->i_df.if_ext_max) {
error = xfs_bmap_extents_to_btree(tp, ip, error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
first, flist, &cur, 1, &tmp_rval, bma->firstblock, bma->flist,
XFS_DATA_FORK); &bma->cur, 1, &tmp_rval, XFS_DATA_FORK);
rval |= tmp_rval; rval |= tmp_rval;
if (error) if (error)
goto done; goto done;
} }
da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
startblockval(PREV.br_startblock) - startblockval(PREV.br_startblock) -
(cur ? cur->bc_private.b.allocated : 0)); (bma->cur ? bma->cur->bc_private.b.allocated : 0));
ep = xfs_iext_get_ext(ifp, *idx + 1); ep = xfs_iext_get_ext(ifp, bma->idx + 1);
xfs_bmbt_set_startblock(ep, nullstartblock(da_new)); xfs_bmbt_set_startblock(ep, nullstartblock(da_new));
trace_xfs_bmap_post_update(ip, *idx + 1, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx + 1, state, _THIS_IP_);
break; break;
case BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG: case BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG:
@@ -701,37 +706,39 @@ xfs_bmap_add_extent_delay_real(
* The right neighbor is contiguous with the new allocation. * The right neighbor is contiguous with the new allocation.
*/ */
temp = PREV.br_blockcount - new->br_blockcount; temp = PREV.br_blockcount - new->br_blockcount;
trace_xfs_bmap_pre_update(ip, *idx + 1, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx + 1, state, _THIS_IP_);
xfs_bmbt_set_blockcount(ep, temp); xfs_bmbt_set_blockcount(ep, temp);
xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, *idx + 1), xfs_bmbt_set_allf(xfs_iext_get_ext(ifp, bma->idx + 1),
new->br_startoff, new->br_startblock, new->br_startoff, new->br_startblock,
new->br_blockcount + RIGHT.br_blockcount, new->br_blockcount + RIGHT.br_blockcount,
RIGHT.br_state); RIGHT.br_state);
trace_xfs_bmap_post_update(ip, *idx + 1, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx + 1, state, _THIS_IP_);
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_DEXT; rval = XFS_ILOG_DEXT;
else { else {
rval = 0; rval = 0;
if ((error = xfs_bmbt_lookup_eq(cur, RIGHT.br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, RIGHT.br_startoff,
RIGHT.br_startblock, RIGHT.br_startblock,
RIGHT.br_blockcount, &i))) RIGHT.br_blockcount, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
if ((error = xfs_bmbt_update(cur, new->br_startoff, error = xfs_bmbt_update(bma->cur, new->br_startoff,
new->br_startblock, new->br_startblock,
new->br_blockcount + new->br_blockcount +
RIGHT.br_blockcount, RIGHT.br_blockcount,
RIGHT.br_state))) RIGHT.br_state);
if (error)
goto done; goto done;
} }
da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
startblockval(PREV.br_startblock)); startblockval(PREV.br_startblock));
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_startblock(ep, nullstartblock(da_new)); xfs_bmbt_set_startblock(ep, nullstartblock(da_new));
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
++*idx; bma->idx++;
break; break;
case BMAP_RIGHT_FILLING: case BMAP_RIGHT_FILLING:
@@ -740,41 +747,43 @@ xfs_bmap_add_extent_delay_real(
* The right neighbor is not contiguous. * The right neighbor is not contiguous.
*/ */
temp = PREV.br_blockcount - new->br_blockcount; temp = PREV.br_blockcount - new->br_blockcount;
trace_xfs_bmap_pre_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, state, _THIS_IP_);
xfs_bmbt_set_blockcount(ep, temp); xfs_bmbt_set_blockcount(ep, temp);
xfs_iext_insert(ip, *idx + 1, 1, new, state); xfs_iext_insert(bma->ip, bma->idx + 1, 1, new, state);
ip->i_d.di_nextents++; bma->ip->i_d.di_nextents++;
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
else { else {
rval = XFS_ILOG_CORE; rval = XFS_ILOG_CORE;
if ((error = xfs_bmbt_lookup_eq(cur, new->br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, new->br_startoff,
new->br_startblock, new->br_blockcount, new->br_startblock, new->br_blockcount,
&i))) &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 0, done); XFS_WANT_CORRUPTED_GOTO(i == 0, done);
cur->bc_rec.b.br_state = XFS_EXT_NORM; bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
if ((error = xfs_btree_insert(cur, &i))) error = xfs_btree_insert(bma->cur, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
} }
if (ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && if (bma->ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS &&
ip->i_d.di_nextents > ip->i_df.if_ext_max) { bma->ip->i_d.di_nextents > bma->ip->i_df.if_ext_max) {
error = xfs_bmap_extents_to_btree(tp, ip, error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
first, flist, &cur, 1, &tmp_rval, bma->firstblock, bma->flist, &bma->cur, 1,
XFS_DATA_FORK); &tmp_rval, XFS_DATA_FORK);
rval |= tmp_rval; rval |= tmp_rval;
if (error) if (error)
goto done; goto done;
} }
da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
startblockval(PREV.br_startblock) - startblockval(PREV.br_startblock) -
(cur ? cur->bc_private.b.allocated : 0)); (bma->cur ? bma->cur->bc_private.b.allocated : 0));
ep = xfs_iext_get_ext(ifp, *idx); ep = xfs_iext_get_ext(ifp, bma->idx);
xfs_bmbt_set_startblock(ep, nullstartblock(da_new)); xfs_bmbt_set_startblock(ep, nullstartblock(da_new));
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
++*idx; bma->idx++;
break; break;
case 0: case 0:
@@ -800,46 +809,48 @@ xfs_bmap_add_extent_delay_real(
*/ */
temp = new->br_startoff - PREV.br_startoff; temp = new->br_startoff - PREV.br_startoff;
temp2 = PREV.br_startoff + PREV.br_blockcount - new_endoff; temp2 = PREV.br_startoff + PREV.br_blockcount - new_endoff;
trace_xfs_bmap_pre_update(ip, *idx, 0, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx, 0, _THIS_IP_);
xfs_bmbt_set_blockcount(ep, temp); /* truncate PREV */ xfs_bmbt_set_blockcount(ep, temp); /* truncate PREV */
LEFT = *new; LEFT = *new;
RIGHT.br_state = PREV.br_state; RIGHT.br_state = PREV.br_state;
RIGHT.br_startblock = nullstartblock( RIGHT.br_startblock = nullstartblock(
(int)xfs_bmap_worst_indlen(ip, temp2)); (int)xfs_bmap_worst_indlen(bma->ip, temp2));
RIGHT.br_startoff = new_endoff; RIGHT.br_startoff = new_endoff;
RIGHT.br_blockcount = temp2; RIGHT.br_blockcount = temp2;
/* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */ /* insert LEFT (r[0]) and RIGHT (r[1]) at the same time */
xfs_iext_insert(ip, *idx + 1, 2, &LEFT, state); xfs_iext_insert(bma->ip, bma->idx + 1, 2, &LEFT, state);
ip->i_d.di_nextents++; bma->ip->i_d.di_nextents++;
if (cur == NULL) if (bma->cur == NULL)
rval = XFS_ILOG_CORE | XFS_ILOG_DEXT; rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
else { else {
rval = XFS_ILOG_CORE; rval = XFS_ILOG_CORE;
if ((error = xfs_bmbt_lookup_eq(cur, new->br_startoff, error = xfs_bmbt_lookup_eq(bma->cur, new->br_startoff,
new->br_startblock, new->br_blockcount, new->br_startblock, new->br_blockcount,
&i))) &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 0, done); XFS_WANT_CORRUPTED_GOTO(i == 0, done);
cur->bc_rec.b.br_state = XFS_EXT_NORM; bma->cur->bc_rec.b.br_state = XFS_EXT_NORM;
if ((error = xfs_btree_insert(cur, &i))) error = xfs_btree_insert(bma->cur, &i);
if (error)
goto done; goto done;
XFS_WANT_CORRUPTED_GOTO(i == 1, done); XFS_WANT_CORRUPTED_GOTO(i == 1, done);
} }
if (ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && if (bma->ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS &&
ip->i_d.di_nextents > ip->i_df.if_ext_max) { bma->ip->i_d.di_nextents > bma->ip->i_df.if_ext_max) {
error = xfs_bmap_extents_to_btree(tp, ip, error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
first, flist, &cur, 1, &tmp_rval, bma->firstblock, bma->flist, &bma->cur,
XFS_DATA_FORK); 1, &tmp_rval, XFS_DATA_FORK);
rval |= tmp_rval; rval |= tmp_rval;
if (error) if (error)
goto done; goto done;
} }
temp = xfs_bmap_worst_indlen(ip, temp); temp = xfs_bmap_worst_indlen(bma->ip, temp);
temp2 = xfs_bmap_worst_indlen(ip, temp2); temp2 = xfs_bmap_worst_indlen(bma->ip, temp2);
diff = (int)(temp + temp2 - startblockval(PREV.br_startblock) - diff = (int)(temp + temp2 - startblockval(PREV.br_startblock) -
(cur ? cur->bc_private.b.allocated : 0)); (bma->cur ? bma->cur->bc_private.b.allocated : 0));
if (diff > 0) { if (diff > 0) {
error = xfs_icsb_modify_counters(ip->i_mount, error = xfs_icsb_modify_counters(bma->ip->i_mount,
XFS_SBS_FDBLOCKS, XFS_SBS_FDBLOCKS,
-((int64_t)diff), 0); -((int64_t)diff), 0);
ASSERT(!error); ASSERT(!error);
@@ -847,15 +858,15 @@ xfs_bmap_add_extent_delay_real(
goto done; goto done;
} }
ep = xfs_iext_get_ext(ifp, *idx); ep = xfs_iext_get_ext(ifp, bma->idx);
xfs_bmbt_set_startblock(ep, nullstartblock((int)temp)); xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
trace_xfs_bmap_post_update(ip, *idx, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx, state, _THIS_IP_);
trace_xfs_bmap_pre_update(ip, *idx + 2, state, _THIS_IP_); trace_xfs_bmap_pre_update(bma->ip, bma->idx + 2, state, _THIS_IP_);
xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, *idx + 2), xfs_bmbt_set_startblock(xfs_iext_get_ext(ifp, bma->idx + 2),
nullstartblock((int)temp2)); nullstartblock((int)temp2));
trace_xfs_bmap_post_update(ip, *idx + 2, state, _THIS_IP_); trace_xfs_bmap_post_update(bma->ip, bma->idx + 2, state, _THIS_IP_);
++*idx; bma->idx++;
da_new = temp + temp2; da_new = temp + temp2;
break; break;
@@ -873,14 +884,15 @@ xfs_bmap_add_extent_delay_real(
} }
/* convert to a btree if necessary */ /* convert to a btree if necessary */
if (XFS_IFORK_FORMAT(ip, XFS_DATA_FORK) == XFS_DINODE_FMT_EXTENTS && if (XFS_IFORK_FORMAT(bma->ip, XFS_DATA_FORK) == XFS_DINODE_FMT_EXTENTS &&
XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) > ifp->if_ext_max) { XFS_IFORK_NEXTENTS(bma->ip, XFS_DATA_FORK) > ifp->if_ext_max) {
int tmp_logflags; /* partial log flag return val */ int tmp_logflags; /* partial log flag return val */
ASSERT(cur == NULL); ASSERT(bma->cur == NULL);
error = xfs_bmap_extents_to_btree(tp, ip, first, flist, &cur, error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
bma->firstblock, bma->flist, &bma->cur,
da_old > 0, &tmp_logflags, XFS_DATA_FORK); da_old > 0, &tmp_logflags, XFS_DATA_FORK);
*logflagsp |= tmp_logflags; bma->logflags |= tmp_logflags;
if (error) if (error)
goto done; goto done;
} }
@@ -888,22 +900,22 @@ xfs_bmap_add_extent_delay_real(
/* adjust for changes in reserved delayed indirect blocks */ /* adjust for changes in reserved delayed indirect blocks */
if (da_old || da_new) { if (da_old || da_new) {
temp = da_new; temp = da_new;
if (cur) if (bma->cur)
temp += cur->bc_private.b.allocated; temp += bma->cur->bc_private.b.allocated;
ASSERT(temp <= da_old); ASSERT(temp <= da_old);
if (temp < da_old) if (temp < da_old)
xfs_icsb_modify_counters(ip->i_mount, XFS_SBS_FDBLOCKS, xfs_icsb_modify_counters(bma->ip->i_mount,
(int64_t)(da_old - temp), 0); XFS_SBS_FDBLOCKS,
(int64_t)(da_old - temp), 0);
} }
/* clear out the allocated field, done with it now in any case. */ /* clear out the allocated field, done with it now in any case. */
if (cur) { if (bma->cur)
cur->bc_private.b.allocated = 0; bma->cur->bc_private.b.allocated = 0;
*curp = cur;
} xfs_bmap_check_leaf_extents(bma->cur, bma->ip, XFS_DATA_FORK);
xfs_bmap_check_leaf_extents(cur, ip, XFS_DATA_FORK);
done: done:
*logflagsp |= rval; bma->logflags |= rval;
return error; return error;
#undef LEFT #undef LEFT
#undef RIGHT #undef RIGHT
@@ -4698,9 +4710,7 @@ xfs_bmapi_allocate(
bma->got.br_state = XFS_EXT_UNWRITTEN; bma->got.br_state = XFS_EXT_UNWRITTEN;
if (bma->wasdel) { if (bma->wasdel) {
error = xfs_bmap_add_extent_delay_real(bma->tp, bma->ip, error = xfs_bmap_add_extent_delay_real(bma);
&bma->idx, &bma->cur, &bma->got,
bma->firstblock, bma->flist, &tmp_logflags);
} else { } else {
error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip,
&bma->idx, &bma->cur, &bma->got, &bma->idx, &bma->cur, &bma->got,