]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - libxfs/xfs_refcount_btree.c
libxfs: refactor manage_zones()
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_refcount_btree.c
index dd3b4d6a2bba5479b46da079741b2c046d357433..09f3045cff78df81951e1090e3d1b51fdd0ede59 100644 (file)
@@ -1,21 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2016 Oracle.  All Rights Reserved.
- *
  * Author: Darrick J. Wong <darrick.wong@oracle.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 #include "libxfs_priv.h"
 #include "xfs_fs.h"
@@ -40,8 +26,7 @@ xfs_refcountbt_dup_cursor(
        struct xfs_btree_cur    *cur)
 {
        return xfs_refcountbt_init_cursor(cur->bc_mp, cur->bc_tp,
-                       cur->bc_private.a.agbp, cur->bc_private.a.agno,
-                       cur->bc_private.a.dfops);
+                       cur->bc_private.a.agbp, cur->bc_private.a.agno);
 }
 
 STATIC void
@@ -78,16 +63,13 @@ xfs_refcountbt_alloc_block(
        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.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.firstblock = args.fsbno;
-       xfs_rmap_ag_owner(&args.oinfo, XFS_RMAP_OWN_REFC);
+       args.oinfo = XFS_RMAP_OINFO_REFC;
        args.minlen = args.maxlen = args.prod = 1;
        args.resv = XFS_AG_RESV_METADATA;
 
@@ -97,7 +79,6 @@ xfs_refcountbt_alloc_block(
        trace_xfs_refcountbt_alloc_block(cur->bc_mp, cur->bc_private.a.agno,
                        args.agbno, 1);
        if (args.fsbno == NULLFSBLOCK) {
-               XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
                *stat = 0;
                return 0;
        }
@@ -108,12 +89,10 @@ xfs_refcountbt_alloc_block(
        be32_add_cpu(&agf->agf_refcount_blocks, 1);
        xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_REFCOUNT_BLOCKS);
 
-       XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
        *stat = 1;
        return 0;
 
 out_error:
-       XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
        return error;
 }
 
@@ -126,15 +105,13 @@ xfs_refcountbt_free_block(
        struct xfs_buf          *agbp = cur->bc_private.a.agbp;
        struct xfs_agf          *agf = XFS_BUF_TO_AGF(agbp);
        xfs_fsblock_t           fsbno = XFS_DADDR_TO_FSB(mp, XFS_BUF_ADDR(bp));
-       struct xfs_owner_info   oinfo;
        int                     error;
 
        trace_xfs_refcountbt_free_block(cur->bc_mp, cur->bc_private.a.agno,
                        XFS_FSB_TO_AGBNO(cur->bc_mp, fsbno), 1);
-       xfs_rmap_ag_owner(&oinfo, XFS_RMAP_OWN_REFC);
        be32_add_cpu(&agf->agf_refcount_blocks, -1);
        xfs_alloc_log_agf(cur->bc_tp, agbp, XFS_AGF_REFCOUNT_BLOCKS);
-       error = xfs_free_extent(cur->bc_tp, fsbno, 1, &oinfo,
+       error = xfs_free_extent(cur->bc_tp, fsbno, 1, &XFS_RMAP_OINFO_REFC,
                        XFS_AG_RESV_METADATA);
        if (error)
                return error;
@@ -196,7 +173,6 @@ xfs_refcountbt_init_ptr_from_cur(
        struct xfs_agf          *agf = XFS_BUF_TO_AGF(cur->bc_private.a.agbp);
 
        ASSERT(cur->bc_private.a.agno == be32_to_cpu(agf->agf_seqno));
-       ASSERT(agf->agf_refcount_root != 0);
 
        ptr->s = agf->agf_refcount_root;
 }
@@ -289,6 +265,7 @@ const struct xfs_buf_ops xfs_refcountbt_buf_ops = {
        .name                   = "xfs_refcountbt",
        .verify_read            = xfs_refcountbt_read_verify,
        .verify_write           = xfs_refcountbt_write_verify,
+       .verify_struct          = xfs_refcountbt_verify,
 };
 
 STATIC int
@@ -341,8 +318,7 @@ xfs_refcountbt_init_cursor(
        struct xfs_mount        *mp,
        struct xfs_trans        *tp,
        struct xfs_buf          *agbp,
-       xfs_agnumber_t          agno,
-       struct xfs_defer_ops    *dfops)
+       xfs_agnumber_t          agno)
 {
        struct xfs_agf          *agf = XFS_BUF_TO_AGF(agbp);
        struct xfs_btree_cur    *cur;
@@ -362,7 +338,6 @@ xfs_refcountbt_init_cursor(
 
        cur->bc_private.a.agbp = agbp;
        cur->bc_private.a.agno = agno;
-       cur->bc_private.a.dfops = dfops;
        cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
 
        cur->bc_private.a.priv.refc.nr_ops = 0;
@@ -376,7 +351,6 @@ xfs_refcountbt_init_cursor(
  */
 int
 xfs_refcountbt_maxrecs(
-       struct xfs_mount        *mp,
        int                     blocklen,
        bool                    leaf)
 {
@@ -393,7 +367,7 @@ void
 xfs_refcountbt_compute_maxlevels(
        struct xfs_mount                *mp)
 {
-       mp->m_refc_maxlevels = xfs_btree_compute_maxlevels(mp,
+       mp->m_refc_maxlevels = xfs_btree_compute_maxlevels(
                        mp->m_refc_mnr, mp->m_sb.sb_agblocks);
 }
 
@@ -403,7 +377,7 @@ xfs_refcountbt_calc_size(
        struct xfs_mount        *mp,
        unsigned long long      len)
 {
-       return xfs_btree_calc_size(mp, mp->m_refc_mnr, len);
+       return xfs_btree_calc_size(mp->m_refc_mnr, len);
 }
 
 /*
@@ -427,6 +401,7 @@ xfs_refcountbt_max_size(
 int
 xfs_refcountbt_calc_reserves(
        struct xfs_mount        *mp,
+       struct xfs_trans        *tp,
        xfs_agnumber_t          agno,
        xfs_extlen_t            *ask,
        xfs_extlen_t            *used)
@@ -441,14 +416,14 @@ xfs_refcountbt_calc_reserves(
                return 0;
 
 
-       error = xfs_alloc_read_agf(mp, NULL, agno, 0, &agbp);
+       error = xfs_alloc_read_agf(mp, tp, agno, 0, &agbp);
        if (error)
                return error;
 
        agf = XFS_BUF_TO_AGF(agbp);
        agblocks = be32_to_cpu(agf->agf_length);
        tree_len = be32_to_cpu(agf->agf_refcount_blocks);
-       xfs_buf_relse(agbp);
+       xfs_trans_brelse(tp, agbp);
 
        *ask += xfs_refcountbt_max_size(mp, agblocks);
        *used += tree_len;