xfs: move btree cursor into bmalloca

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Alex Elder <aelder@sgi.com>
This commit is contained in:
Dave Chinner 2011-09-18 20:41:00 +00:00 committed by Alex Elder
parent 963c30cf45
commit 29c8d17a89
2 changed files with 28 additions and 30 deletions

View file

@ -4608,7 +4608,6 @@ STATIC int
xfs_bmapi_allocate( xfs_bmapi_allocate(
struct xfs_bmalloca *bma, struct xfs_bmalloca *bma,
xfs_extnum_t *lastx, xfs_extnum_t *lastx,
struct xfs_btree_cur **cur,
int flags, int flags,
int *nallocs, int *nallocs,
int *logflags) int *logflags)
@ -4668,14 +4667,14 @@ xfs_bmapi_allocate(
if (bma->flist->xbf_low) if (bma->flist->xbf_low)
bma->minleft = 0; bma->minleft = 0;
if (*cur) if (bma->cur)
(*cur)->bc_private.b.firstblock = *bma->firstblock; bma->cur->bc_private.b.firstblock = *bma->firstblock;
if (bma->blkno == NULLFSBLOCK) if (bma->blkno == NULLFSBLOCK)
return 0; return 0;
if ((ifp->if_flags & XFS_IFBROOT) && !*cur) { if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur) {
(*cur) = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork); bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork);
(*cur)->bc_private.b.firstblock = *bma->firstblock; bma->cur->bc_private.b.firstblock = *bma->firstblock;
(*cur)->bc_private.b.flist = bma->flist; bma->cur->bc_private.b.flist = bma->flist;
} }
/* /*
* Bump the number of extents we've allocated * Bump the number of extents we've allocated
@ -4683,8 +4682,8 @@ xfs_bmapi_allocate(
*/ */
(*nallocs)++; (*nallocs)++;
if (*cur) if (bma->cur)
(*cur)->bc_private.b.flags = bma->cur->bc_private.b.flags =
bma->wasdel ? XFS_BTCUR_BPRV_WASDEL : 0; bma->wasdel ? XFS_BTCUR_BPRV_WASDEL : 0;
bma->got.br_startoff = bma->offset; bma->got.br_startoff = bma->offset;
@ -4702,12 +4701,12 @@ xfs_bmapi_allocate(
if (bma->wasdel) { if (bma->wasdel) {
error = xfs_bmap_add_extent_delay_real(bma->tp, bma->ip, lastx, error = xfs_bmap_add_extent_delay_real(bma->tp, bma->ip, lastx,
cur, &bma->got, bma->firstblock, bma->flist, &bma->cur, &bma->got, bma->firstblock,
logflags); bma->flist, logflags);
} else { } else {
error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, lastx, error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, lastx,
cur, &bma->got, bma->firstblock, bma->flist, &bma->cur, &bma->got, bma->firstblock,
logflags, whichfork); bma->flist, logflags, whichfork);
} }
if (error) if (error)
@ -4734,7 +4733,6 @@ xfs_bmapi_convert_unwritten(
struct xfs_bmbt_irec *mval, struct xfs_bmbt_irec *mval,
xfs_filblks_t len, xfs_filblks_t len,
xfs_extnum_t *lastx, xfs_extnum_t *lastx,
struct xfs_btree_cur **cur,
int flags, int flags,
int *logflags) int *logflags)
{ {
@ -4760,17 +4758,17 @@ xfs_bmapi_convert_unwritten(
* Modify (by adding) the state flag, if writing. * Modify (by adding) the state flag, if writing.
*/ */
ASSERT(mval->br_blockcount <= len); ASSERT(mval->br_blockcount <= len);
if ((ifp->if_flags & XFS_IFBROOT) && !*cur) { if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur) {
*cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp, bma->cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp,
bma->ip, whichfork); bma->ip, whichfork);
(*cur)->bc_private.b.firstblock = *bma->firstblock; bma->cur->bc_private.b.firstblock = *bma->firstblock;
(*cur)->bc_private.b.flist = bma->flist; bma->cur->bc_private.b.flist = bma->flist;
} }
mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN)
? XFS_EXT_NORM : XFS_EXT_UNWRITTEN; ? XFS_EXT_NORM : XFS_EXT_UNWRITTEN;
error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, lastx, error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, lastx,
cur, mval, bma->firstblock, bma->flist, logflags); &bma->cur, mval, bma->firstblock, bma->flist, logflags);
if (error) if (error)
return error; return error;
@ -4819,7 +4817,6 @@ xfs_bmapi_write(
struct xfs_mount *mp = ip->i_mount; struct xfs_mount *mp = ip->i_mount;
struct xfs_ifork *ifp; struct xfs_ifork *ifp;
struct xfs_bmalloca bma = { 0 }; /* args for xfs_bmap_alloc */ struct xfs_bmalloca bma = { 0 }; /* args for xfs_bmap_alloc */
struct xfs_btree_cur *cur; /* bmap btree cursor */
xfs_fileoff_t end; /* end of mapped file region */ xfs_fileoff_t end; /* end of mapped file region */
int eof; /* after the end of extents */ int eof; /* after the end of extents */
int error; /* error return */ int error; /* error return */
@ -4875,7 +4872,6 @@ xfs_bmapi_write(
logflags = 0; logflags = 0;
nallocs = 0; nallocs = 0;
cur = NULL;
if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL) { if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL) {
error = xfs_bmap_local_to_extents(tp, ip, firstblock, total, error = xfs_bmap_local_to_extents(tp, ip, firstblock, total,
@ -4927,7 +4923,7 @@ xfs_bmapi_write(
bma.length = len; bma.length = len;
bma.offset = bno; bma.offset = bno;
error = xfs_bmapi_allocate(&bma, &lastx, &cur, flags, error = xfs_bmapi_allocate(&bma, &lastx, flags,
&nallocs, &tmp_logflags); &nallocs, &tmp_logflags);
logflags |= tmp_logflags; logflags |= tmp_logflags;
if (error) if (error)
@ -4942,7 +4938,7 @@ xfs_bmapi_write(
/* Execute unwritten extent conversion if necessary */ /* Execute unwritten extent conversion if necessary */
error = xfs_bmapi_convert_unwritten(&bma, mval, len, &lastx, error = xfs_bmapi_convert_unwritten(&bma, mval, len, &lastx,
&cur, flags, &tmp_logflags); flags, &tmp_logflags);
logflags |= tmp_logflags; logflags |= tmp_logflags;
if (error == EAGAIN) if (error == EAGAIN)
continue; continue;
@ -4974,8 +4970,8 @@ xfs_bmapi_write(
*/ */
if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE && if (XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE &&
XFS_IFORK_NEXTENTS(ip, whichfork) <= ifp->if_ext_max) { XFS_IFORK_NEXTENTS(ip, whichfork) <= ifp->if_ext_max) {
ASSERT(cur); ASSERT(bma.cur);
error = xfs_bmap_btree_to_extents(tp, ip, cur, error = xfs_bmap_btree_to_extents(tp, ip, bma.cur,
&tmp_logflags, whichfork); &tmp_logflags, whichfork);
logflags |= tmp_logflags; logflags |= tmp_logflags;
if (error) if (error)
@ -5005,19 +5001,19 @@ error0:
if (logflags) if (logflags)
xfs_trans_log_inode(tp, ip, logflags); xfs_trans_log_inode(tp, ip, logflags);
if (cur) { if (bma.cur) {
if (!error) { if (!error) {
ASSERT(*firstblock == NULLFSBLOCK || ASSERT(*firstblock == NULLFSBLOCK ||
XFS_FSB_TO_AGNO(mp, *firstblock) == XFS_FSB_TO_AGNO(mp, *firstblock) ==
XFS_FSB_TO_AGNO(mp, XFS_FSB_TO_AGNO(mp,
cur->bc_private.b.firstblock) || bma.cur->bc_private.b.firstblock) ||
(flist->xbf_low && (flist->xbf_low &&
XFS_FSB_TO_AGNO(mp, *firstblock) < XFS_FSB_TO_AGNO(mp, *firstblock) <
XFS_FSB_TO_AGNO(mp, XFS_FSB_TO_AGNO(mp,
cur->bc_private.b.firstblock))); bma.cur->bc_private.b.firstblock)));
*firstblock = cur->bc_private.b.firstblock; *firstblock = bma.cur->bc_private.b.firstblock;
} }
xfs_btree_del_cursor(cur, xfs_btree_del_cursor(bma.cur,
error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR); error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
} }
if (!error) if (!error)

View file

@ -120,6 +120,8 @@ typedef struct xfs_bmalloca {
xfs_extlen_t length; /* i/o length asked/allocated */ xfs_extlen_t length; /* i/o length asked/allocated */
xfs_fsblock_t blkno; /* starting block of new extent */ xfs_fsblock_t blkno; /* starting block of new extent */
struct xfs_btree_cur *cur; /* btree cursor */
xfs_extlen_t total; /* total blocks needed for xaction */ xfs_extlen_t total; /* total blocks needed for xaction */
xfs_extlen_t minlen; /* minimum allocation size (blocks) */ xfs_extlen_t minlen; /* minimum allocation size (blocks) */
xfs_extlen_t minleft; /* amount must be left after alloc */ xfs_extlen_t minleft; /* amount must be left after alloc */