xfs
[Top] [All Lists]

[PATCH 2/3] xfs: refactor xfs_refcountbt_alloc_block

To: darrick.wong@xxxxxxxxxx
Subject: [PATCH 2/3] xfs: refactor xfs_refcountbt_alloc_block
From: Christoph Hellwig <hch@xxxxxx>
Date: Thu, 2 Jun 2016 16:19:09 +0200
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <1464877150-20457-1-git-send-email-hch@xxxxxx>
References: <1464877150-20457-1-git-send-email-hch@xxxxxx>
Split out a low level helper that we can use for enabling the reflink
btree at mount time.

Signed-off-by: Christoph Hellwig <hch@xxxxxx>
---
 fs/xfs/libxfs/xfs_refcount_btree.c | 54 +++++++++++++++++++++++---------------
 1 file changed, 33 insertions(+), 21 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_refcount_btree.c 
b/fs/xfs/libxfs/xfs_refcount_btree.c
index f83cb4b..7ae3ad7 100644
--- a/fs/xfs/libxfs/xfs_refcount_btree.c
+++ b/fs/xfs/libxfs/xfs_refcount_btree.c
@@ -66,49 +66,61 @@ xfs_refcountbt_set_root(
 }
 
 STATIC int
-xfs_refcountbt_alloc_block(
-       struct xfs_btree_cur    *cur,
-       union xfs_btree_ptr     *start,
-       union xfs_btree_ptr     *new,
+__xfs_refcountbt_alloc_block(
+       struct xfs_trans        *tp,
+       xfs_agnumber_t          agno,
+       enum xfs_ag_resv_type   resv,
+       __be32                  *agbno,
        int                     *stat)
 {
+       struct xfs_mount        *mp = tp->t_mountp;
        struct xfs_alloc_arg    args;           /* block allocation args */
        int                     error;          /* error return value */
 
-       XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY);
-
        memset(&args, 0, sizeof(args));
-       args.tp = cur->bc_tp;
-       args.mp = cur->bc_mp;
+       args.tp = tp;
+       args.mp = mp;
        args.type = XFS_ALLOCTYPE_NEAR_BNO;
-       args.fsbno = XFS_AGB_TO_FSB(cur->bc_mp, cur->bc_private.a.agno,
-                       xfs_refc_block(args.mp));
+       args.fsbno = XFS_AGB_TO_FSB(mp, agno, xfs_refc_block(mp));
        args.firstblock = args.fsbno;
        xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_REFC);
        args.minlen = args.maxlen = args.prod = 1;
-       args.resv = XFS_AG_RESV_METADATA;
+       args.resv = resv;
 
        error = xfs_alloc_vextent(&args);
        if (error)
-               goto out_error;
-       trace_xfs_refcountbt_alloc_block(cur->bc_mp, cur->bc_private.a.agno,
-                       args.agbno, 1);
+               return error;
+       trace_xfs_refcountbt_alloc_block(mp, agno, args.agbno, 1);
        if (args.fsbno == NULLFSBLOCK) {
-               XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
                *stat = 0;
                return 0;
        }
-       ASSERT(args.agno == cur->bc_private.a.agno);
+       ASSERT(args.agno == agno);
        ASSERT(args.len == 1);
 
-       new->s = cpu_to_be32(args.agbno);
-
-       XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
+       *agbno = cpu_to_be32(args.agbno);
        *stat = 1;
        return 0;
+}
+
+STATIC int
+xfs_refcountbt_alloc_block(
+       struct xfs_btree_cur    *cur,
+       union xfs_btree_ptr     *start,
+       union xfs_btree_ptr     *new,
+       int                     *stat)
+{
+       int                     error;
+
+       XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY);
+
+       error = __xfs_refcountbt_alloc_block(cur->bc_tp, cur->bc_private.a.agno,
+                       XFS_AG_RESV_METADATA, &new->s, stat);
+       if (error)
+               XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
+       else
+               XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
 
-out_error:
-       XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
        return error;
 }
 
-- 
2.1.4

<Prev in Thread] Current Thread [Next in Thread>