struct fsmap_info info;
xfs_agnumber_t start_ag;
xfs_agnumber_t end_ag;
- xfs_agnumber_t agno;
xfs_daddr_t eofs;
struct xfs_rmap_irec low = {0};
struct xfs_rmap_irec high = {0};
struct xfs_btree_cur *bt_cur;
struct xfs_buf *agbp;
+ struct xfs_perag *pag;
int error;
eofs = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks);
end_ag = XFS_FSB_TO_AGNO(mp, end_fsb);
info.nr = 0;
- for (agno = start_ag; agno <= end_ag; agno++) {
- if (agno == end_ag)
+ for_each_perag_range(mp, start_ag, end_ag, pag) {
+ if (pag->pag_agno == end_ag)
high.rm_startblock = XFS_FSB_TO_AGBNO(mp, end_fsb);
- error = -libxfs_alloc_read_agf(mp, NULL, agno, 0, &agbp);
+ error = -libxfs_alloc_read_agf(mp, NULL, pag->pag_agno, 0, &agbp);
if (error) {
+ libxfs_perag_put(pag);
dbprintf(_("Error %d while reading AGF.\n"), error);
return;
}
- bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, agno);
+ bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp,
+ pag->pag_agno, pag);
if (!bt_cur) {
libxfs_buf_relse(agbp);
+ libxfs_perag_put(pag);
dbprintf(_("Not enough memory.\n"));
return;
}
- info.agno = agno;
+ info.agno = pag->pag_agno;
error = -libxfs_rmap_query_range(bt_cur, &low, &high,
fsmap_fn, &info);
if (error) {
libxfs_btree_del_cursor(bt_cur, XFS_BTREE_ERROR);
libxfs_buf_relse(agbp);
+ libxfs_perag_put(pag);
dbprintf(_("Error %d while querying fsmap btree.\n"),
error);
return;
libxfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
libxfs_buf_relse(agbp);
- if (agno == start_ag)
+ if (pag->pag_agno == start_ag)
low.rm_startblock = 0;
}
}
{
struct xfs_buf *bp;
struct xfs_agf *agf;
- struct xfs_perag *pag = xfs_perag_get(mp, agno);
+ struct xfs_perag *pag = libxfs_perag_get(mp, agno);
xfs_extlen_t ask = 0;
xfs_extlen_t used = 0;
xfs_extlen_t free = 0;
if (ask - used > free)
printf(" <not enough space>");
printf("\n");
- xfs_perag_put(pag);
+ libxfs_perag_put(pag);
}
static int
*/
if (!acur->cnt)
acur->cnt = xfs_allocbt_init_cursor(args->mp, args->tp,
- args->agbp, args->agno, XFS_BTNUM_CNT);
+ args->agbp, args->agno,
+ args->pag, XFS_BTNUM_CNT);
error = xfs_alloc_lookup_ge(acur->cnt, 0, args->maxlen, &i);
if (error)
return error;
*/
if (!acur->bnolt)
acur->bnolt = xfs_allocbt_init_cursor(args->mp, args->tp,
- args->agbp, args->agno, XFS_BTNUM_BNO);
+ args->agbp, args->agno,
+ args->pag, XFS_BTNUM_BNO);
if (!acur->bnogt)
acur->bnogt = xfs_allocbt_init_cursor(args->mp, args->tp,
- args->agbp, args->agno, XFS_BTNUM_BNO);
+ args->agbp, args->agno,
+ args->pag, XFS_BTNUM_BNO);
return i == 1 ? 0 : -ENOSPC;
}
* Allocate/initialize a cursor for the by-number freespace btree.
*/
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
- args->agno, XFS_BTNUM_BNO);
+ args->agno, args->pag, XFS_BTNUM_BNO);
/*
* Lookup bno and minlen in the btree (minlen is irrelevant, really).
* Allocate/initialize a cursor for the by-size btree.
*/
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
- args->agno, XFS_BTNUM_CNT);
+ args->agno, args->pag, XFS_BTNUM_CNT);
ASSERT(args->agbno + args->len <= be32_to_cpu(agf->agf_length));
error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen, args->agbno,
args->len, XFSA_FIXUP_BNO_OK);
* Allocate and initialize a cursor for the by-size btree.
*/
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
- args->agno, XFS_BTNUM_CNT);
+ args->agno, args->pag, XFS_BTNUM_CNT);
bno_cur = NULL;
busy = false;
* Allocate and initialize a cursor for the by-block tree.
*/
bno_cur = xfs_allocbt_init_cursor(args->mp, args->tp, args->agbp,
- args->agno, XFS_BTNUM_BNO);
+ args->agno, args->pag, XFS_BTNUM_BNO);
if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur, fbno, flen,
rbno, rlen, XFSA_FIXUP_CNT_OK)))
goto error0;
/*
* Allocate and initialize a cursor for the by-block btree.
*/
- bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_BNO);
+ bno_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno,
+ NULL, XFS_BTNUM_BNO);
/*
* Look for a neighboring block on the left (lower block numbers)
* that is contiguous with this space.
/*
* Now allocate and initialize a cursor for the by-size tree.
*/
- cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_CNT);
+ cnt_cur = xfs_allocbt_init_cursor(mp, tp, agbp, agno,
+ NULL, XFS_BTNUM_CNT);
/*
* Have both left and right contiguous neighbors.
* Merge all three into a single free block.
int error = 0;
cnt_cur = xfs_allocbt_init_cursor(args->mp, args->tp, agbp,
- args->agno, XFS_BTNUM_CNT);
+ args->agno, args->pag, XFS_BTNUM_CNT);
error = xfs_alloc_lookup_ge(cnt_cur, 0, args->minlen, stat);
if (error)
goto out;
{
return xfs_allocbt_init_cursor(cur->bc_mp, cur->bc_tp,
cur->bc_ag.agbp, cur->bc_ag.agno,
- cur->bc_btnum);
+ cur->bc_ag.pag, cur->bc_btnum);
}
STATIC void
struct xfs_mount *mp,
struct xfs_trans *tp,
xfs_agnumber_t agno,
+ struct xfs_perag *pag,
xfs_btnum_t btnum)
{
struct xfs_btree_cur *cur;
cur->bc_ag.agno = agno;
cur->bc_ag.abt.active = false;
+ if (pag) {
+ /* take a reference for the cursor */
+ atomic_inc(&pag->pag_ref);
+ }
+ cur->bc_ag.pag = pag;
if (xfs_sb_version_hascrc(&mp->m_sb))
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
struct xfs_trans *tp, /* transaction pointer */
struct xfs_buf *agbp, /* buffer for agf structure */
xfs_agnumber_t agno, /* allocation group number */
+ struct xfs_perag *pag,
xfs_btnum_t btnum) /* btree identifier */
{
struct xfs_agf *agf = agbp->b_addr;
struct xfs_btree_cur *cur;
- cur = xfs_allocbt_init_common(mp, tp, agno, btnum);
+ cur = xfs_allocbt_init_common(mp, tp, agno, pag, btnum);
if (btnum == XFS_BTNUM_CNT)
cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]);
else
{
struct xfs_btree_cur *cur;
- cur = xfs_allocbt_init_common(mp, NULL, agno, btnum);
+ cur = xfs_allocbt_init_common(mp, NULL, agno, NULL, btnum);
xfs_btree_stage_afakeroot(cur, afake);
return cur;
}
struct xfs_buf;
struct xfs_btree_cur;
struct xfs_mount;
+struct xfs_perag;
struct xbtree_afakeroot;
/*
extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *,
struct xfs_trans *, struct xfs_buf *,
- xfs_agnumber_t, xfs_btnum_t);
+ xfs_agnumber_t, struct xfs_perag *pag, xfs_btnum_t);
struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp,
struct xbtree_afakeroot *afake, xfs_agnumber_t agno,
xfs_btnum_t btnum);
XFS_FORCED_SHUTDOWN(cur->bc_mp));
if (unlikely(cur->bc_flags & XFS_BTREE_STAGING))
kmem_free(cur->bc_ops);
+ if (!(cur->bc_flags & XFS_BTREE_LONG_PTRS) && cur->bc_ag.pag)
+ xfs_perag_put(cur->bc_ag.pag);
kmem_cache_free(xfs_btree_cur_zone, cur);
}
struct xfs_mount;
struct xfs_trans;
struct xfs_ifork;
+struct xfs_perag;
extern kmem_zone_t *xfs_btree_cur_zone;
/* Per-AG btree information. */
struct xfs_btree_cur_ag {
+ xfs_agnumber_t agno;
+ struct xfs_perag *pag;
union {
struct xfs_buf *agbp;
struct xbtree_afakeroot *afake; /* for staging cursor */
};
- xfs_agnumber_t agno;
union {
struct {
unsigned long nr_ops; /* # record updates */
uint8_t bc_blocklog; /* log2(blocksize) of btree blocks */
xfs_btnum_t bc_btnum; /* identifies which btree type */
int bc_statoff; /* offset of btre stats array */
+
+ /*
+ * Short btree pointers need an agno to be able to turn the pointers
+ * into physical addresses for IO, so the btree cursor switches between
+ * bc_ino and bc_ag based on whether XFS_BTREE_LONG_PTRS is set for the
+ * cursor.
+ */
union {
struct xfs_btree_cur_ag bc_ag;
struct xfs_btree_cur_ino bc_ino;
int i;
int error;
- cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, btnum);
+ cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, btnum);
for (thisino = newino;
thisino < newino + newlen;
int i;
struct xfs_inobt_rec_incore rec;
- cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, btnum);
+ cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, btnum);
/* the new record is pre-aligned so we know where to look */
error = xfs_inobt_lookup(cur, nrec->ir_startino, XFS_LOOKUP_EQ, &i);
ASSERT(pag->pagi_freecount > 0);
restart_pagno:
- cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
+ cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);
/*
* If pagino is 0 (this is the root inode allocation) use newino.
* This must work because we've just allocated some.
if (!pagino)
pagino = be32_to_cpu(agi->agi_newino);
- cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_FINO);
+ cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_FINO);
error = xfs_check_agi_freecount(cur, agi);
if (error)
* the original freecount. If all is well, make the equivalent update to
* the inobt using the finobt record and offset information.
*/
- icur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
+ icur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);
error = xfs_check_agi_freecount(icur, agi);
if (error)
/*
* Initialize the cursor.
*/
- cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
+ cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);
error = xfs_check_agi_freecount(cur, agi);
if (error)
int error;
int i;
- cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_FINO);
+ cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_FINO);
error = xfs_inobt_lookup(cur, ibtrec->ir_startino, XFS_LOOKUP_EQ, &i);
if (error)
* we have a record, we need to ensure it contains the inode number
* we are looking up.
*/
- cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, XFS_BTNUM_INO);
+ cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, NULL, XFS_BTNUM_INO);
error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i);
if (!error) {
if (i)
{
return xfs_inobt_init_cursor(cur->bc_mp, cur->bc_tp,
cur->bc_ag.agbp, cur->bc_ag.agno,
- cur->bc_btnum);
+ cur->bc_ag.pag, cur->bc_btnum);
}
STATIC void
struct xfs_mount *mp, /* file system mount point */
struct xfs_trans *tp, /* transaction pointer */
xfs_agnumber_t agno, /* allocation group number */
+ struct xfs_perag *pag,
xfs_btnum_t btnum) /* ialloc or free ino btree */
{
struct xfs_btree_cur *cur;
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
cur->bc_ag.agno = agno;
+ if (pag) {
+ /* take a reference for the cursor */
+ atomic_inc(&pag->pag_ref);
+ }
+ cur->bc_ag.pag = pag;
return cur;
}
struct xfs_trans *tp,
struct xfs_buf *agbp,
xfs_agnumber_t agno,
+ struct xfs_perag *pag,
xfs_btnum_t btnum)
{
struct xfs_btree_cur *cur;
struct xfs_agi *agi = agbp->b_addr;
- cur = xfs_inobt_init_common(mp, tp, agno, btnum);
+ cur = xfs_inobt_init_common(mp, tp, agno, pag, btnum);
if (btnum == XFS_BTNUM_INO)
cur->bc_nlevels = be32_to_cpu(agi->agi_level);
else
{
struct xfs_btree_cur *cur;
- cur = xfs_inobt_init_common(mp, NULL, agno, btnum);
+ cur = xfs_inobt_init_common(mp, NULL, agno, NULL, btnum);
xfs_btree_stage_afakeroot(cur, afake);
return cur;
}
if (error)
return error;
- cur = xfs_inobt_init_cursor(mp, tp, *agi_bpp, agno, which);
+ cur = xfs_inobt_init_cursor(mp, tp, *agi_bpp, agno, NULL, which);
*curpp = cur;
return 0;
}
struct xfs_buf;
struct xfs_btree_cur;
struct xfs_mount;
+struct xfs_perag;
/*
* Btree block header size depends on a superblock flag.
(maxrecs) * sizeof(xfs_inobt_key_t) + \
((index) - 1) * sizeof(xfs_inobt_ptr_t)))
-extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *,
- struct xfs_trans *, struct xfs_buf *, xfs_agnumber_t,
- xfs_btnum_t);
+extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *mp,
+ struct xfs_trans *tp, struct xfs_buf *agbp, xfs_agnumber_t agno,
+ struct xfs_perag *pag, xfs_btnum_t btnum);
struct xfs_btree_cur *xfs_inobt_stage_cursor(struct xfs_mount *mp,
struct xbtree_afakeroot *afake, xfs_agnumber_t agno,
xfs_btnum_t btnum);
if (error)
return error;
- rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
+ rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno, NULL);
rcur->bc_ag.refc.nr_ops = nr_ops;
rcur->bc_ag.refc.shape_changes = shape_changes;
}
error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
if (error)
goto out_trans;
- cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno);
+ cur = xfs_refcountbt_init_cursor(mp, tp, agbp, agno, NULL);
/* Find all the leftover CoW staging extents. */
memset(&low, 0, sizeof(low));
struct xfs_btree_cur *cur)
{
return xfs_refcountbt_init_cursor(cur->bc_mp, cur->bc_tp,
- cur->bc_ag.agbp, cur->bc_ag.agno);
+ cur->bc_ag.agbp, cur->bc_ag.agno, cur->bc_ag.pag);
}
STATIC void
xfs_refcountbt_init_common(
struct xfs_mount *mp,
struct xfs_trans *tp,
- xfs_agnumber_t agno)
+ xfs_agnumber_t agno,
+ struct xfs_perag *pag)
{
struct xfs_btree_cur *cur;
cur->bc_ag.agno = agno;
cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
+ if (pag) {
+ /* take a reference for the cursor */
+ atomic_inc(&pag->pag_ref);
+ }
+ cur->bc_ag.pag = pag;
cur->bc_ag.refc.nr_ops = 0;
cur->bc_ag.refc.shape_changes = 0;
struct xfs_mount *mp,
struct xfs_trans *tp,
struct xfs_buf *agbp,
- xfs_agnumber_t agno)
+ xfs_agnumber_t agno,
+ struct xfs_perag *pag)
{
struct xfs_agf *agf = agbp->b_addr;
struct xfs_btree_cur *cur;
- cur = xfs_refcountbt_init_common(mp, tp, agno);
+ cur = xfs_refcountbt_init_common(mp, tp, agno, pag);
cur->bc_nlevels = be32_to_cpu(agf->agf_refcount_level);
cur->bc_ag.agbp = agbp;
return cur;
{
struct xfs_btree_cur *cur;
- cur = xfs_refcountbt_init_common(mp, NULL, agno);
+ cur = xfs_refcountbt_init_common(mp, NULL, agno, NULL);
xfs_btree_stage_afakeroot(cur, afake);
return cur;
}
extern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp,
struct xfs_trans *tp, struct xfs_buf *agbp,
- xfs_agnumber_t agno);
+ xfs_agnumber_t agno, struct xfs_perag *pag);
struct xfs_btree_cur *xfs_refcountbt_stage_cursor(struct xfs_mount *mp,
struct xbtree_afakeroot *afake, xfs_agnumber_t agno);
extern int xfs_refcountbt_maxrecs(int blocklen, bool leaf);
if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
return 0;
- cur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno);
+ cur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno, NULL);
error = xfs_rmap_unmap(cur, bno, len, false, oinfo);
if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
return 0;
- cur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno);
+ cur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno, NULL);
error = xfs_rmap_map(cur, bno, len, false, oinfo);
xfs_btree_del_cursor(cur, error);
goto out_drop;
}
- rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, pag->pag_agno);
+ rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, pag->pag_agno, pag);
}
*pcur = rcur;
struct xfs_btree_cur *cur)
{
return xfs_rmapbt_init_cursor(cur->bc_mp, cur->bc_tp,
- cur->bc_ag.agbp, cur->bc_ag.agno);
+ cur->bc_ag.agbp, cur->bc_ag.agno, cur->bc_ag.pag);
}
STATIC void
xfs_rmapbt_init_common(
struct xfs_mount *mp,
struct xfs_trans *tp,
- xfs_agnumber_t agno)
+ xfs_agnumber_t agno,
+ struct xfs_perag *pag)
{
struct xfs_btree_cur *cur;
cur->bc_statoff = XFS_STATS_CALC_INDEX(xs_rmap_2);
cur->bc_ag.agno = agno;
cur->bc_ops = &xfs_rmapbt_ops;
+ if (pag) {
+ /* take a reference for the cursor */
+ atomic_inc(&pag->pag_ref);
+ }
+ cur->bc_ag.pag = pag;
return cur;
}
struct xfs_mount *mp,
struct xfs_trans *tp,
struct xfs_buf *agbp,
- xfs_agnumber_t agno)
+ xfs_agnumber_t agno,
+ struct xfs_perag *pag)
{
struct xfs_agf *agf = agbp->b_addr;
struct xfs_btree_cur *cur;
- cur = xfs_rmapbt_init_common(mp, tp, agno);
+ cur = xfs_rmapbt_init_common(mp, tp, agno, pag);
cur->bc_nlevels = be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]);
cur->bc_ag.agbp = agbp;
return cur;
{
struct xfs_btree_cur *cur;
- cur = xfs_rmapbt_init_common(mp, NULL, agno);
+ cur = xfs_rmapbt_init_common(mp, NULL, agno, NULL);
xfs_btree_stage_afakeroot(cur, afake);
return cur;
}
struct xfs_btree_cur *xfs_rmapbt_init_cursor(struct xfs_mount *mp,
struct xfs_trans *tp, struct xfs_buf *bp,
- xfs_agnumber_t agno);
+ xfs_agnumber_t agno, struct xfs_perag *pag);
struct xfs_btree_cur *xfs_rmapbt_stage_cursor(struct xfs_mount *mp,
struct xbtree_afakeroot *afake, xfs_agnumber_t agno);
void xfs_rmapbt_commit_staged_btree(struct xfs_btree_cur *cur,
struct xfs_mount *mp,
xfs_agnumber_t agno)
{
+ struct xfs_rmap_irec tmp;
struct xfs_slab_cursor *rm_cur;
struct xfs_btree_cur *bt_cur = NULL;
- int error;
- int have;
struct xfs_buf *agbp = NULL;
struct xfs_rmap_irec *rm_rec;
- struct xfs_rmap_irec tmp;
- struct xfs_perag *pag; /* per allocation group data */
+ struct xfs_perag *pag = NULL;
+ int have;
+ int error;
if (!xfs_sb_version_hasrmapbt(&mp->m_sb))
return 0;
/* Leave the per-ag data "uninitialized" since we rewrite it later */
pag = libxfs_perag_get(mp, agno);
pag->pagf_init = 0;
- libxfs_perag_put(pag);
- bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, agno);
+ bt_cur = libxfs_rmapbt_init_cursor(mp, NULL, agbp, agno, pag);
if (!bt_cur) {
error = -ENOMEM;
goto err;
err:
if (bt_cur)
libxfs_btree_del_cursor(bt_cur, XFS_BTREE_NOERROR);
+ if (pag)
+ libxfs_perag_put(pag);
if (agbp)
libxfs_buf_relse(agbp);
free_slab_cursor(&rm_cur);
*/
int
check_refcounts(
- struct xfs_mount *mp,
- xfs_agnumber_t agno)
+ struct xfs_mount *mp,
+ xfs_agnumber_t agno)
{
- struct xfs_slab_cursor *rl_cur;
- struct xfs_btree_cur *bt_cur = NULL;
- int error;
- int have;
- int i;
- struct xfs_buf *agbp = NULL;
- struct xfs_refcount_irec *rl_rec;
struct xfs_refcount_irec tmp;
- struct xfs_perag *pag; /* per allocation group data */
+ struct xfs_slab_cursor *rl_cur;
+ struct xfs_btree_cur *bt_cur = NULL;
+ struct xfs_buf *agbp = NULL;
+ struct xfs_perag *pag = NULL;
+ struct xfs_refcount_irec *rl_rec;
+ int have;
+ int i;
+ int error;
if (!xfs_sb_version_hasreflink(&mp->m_sb))
return 0;
/* Leave the per-ag data "uninitialized" since we rewrite it later */
pag = libxfs_perag_get(mp, agno);
pag->pagf_init = 0;
- libxfs_perag_put(pag);
- bt_cur = libxfs_refcountbt_init_cursor(mp, NULL, agbp, agno);
+ bt_cur = libxfs_refcountbt_init_cursor(mp, NULL, agbp, agno, pag);
if (!bt_cur) {
error = -ENOMEM;
goto err;
if (bt_cur)
libxfs_btree_del_cursor(bt_cur, error ? XFS_BTREE_ERROR :
XFS_BTREE_NOERROR);
+ if (pag)
+ libxfs_perag_put(pag);
if (agbp)
libxfs_buf_relse(agbp);
free_slab_cursor(&rl_cur);