]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: inobt can use perags in many more places than it does
authorDave Chinner <dchinner@redhat.com>
Tue, 9 May 2023 09:29:47 +0000 (11:29 +0200)
committerCarlos Maiolino <cem@kernel.org>
Wed, 10 May 2023 07:04:59 +0000 (09:04 +0200)
Source kernel commit: bab8b795185bf37801a4f7ee5c321eee288c2f10

Lots of code in the inobt infrastructure is passed both xfs_mount
and perags. We only need perags for the per-ag inode allocation
code, so reduce the duplication by passing only the perags as the
primary object.

This ends up reducing the code size by a bit:

text    data     bss     dec     hex filename
orig    1138878  323979     548 1463405  16546d (TOTALS)
patched 1138709  323979     548 1463236  1653c4 (TOTALS)

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
db/info.c
libxfs/xfs_ag_resv.c
libxfs/xfs_ialloc.c
libxfs/xfs_ialloc_btree.c
libxfs/xfs_ialloc_btree.h
repair/agbtree.c

index 5f67adcc6ae188e365b154c9bd4d63b840720d1a..0f6c2942933bb62cbbca2166d2cc2f0018d5a1be 100644 (file)
--- a/db/info.c
+++ b/db/info.c
@@ -76,7 +76,7 @@ print_agresv_info(
        error = -libxfs_refcountbt_calc_reserves(mp, NULL, pag, &ask, &used);
        if (error)
                xfrog_perror(error, "refcountbt");
-       error = -libxfs_finobt_calc_reserves(mp, NULL, pag, &ask, &used);
+       error = -libxfs_finobt_calc_reserves(pag, NULL, &ask, &used);
        if (error)
                xfrog_perror(error, "finobt");
        error = -libxfs_rmapbt_calc_reserves(mp, NULL, pag, &ask, &used);
index 294d2ae22e90689b2304447700a9ce92c4a5fa45..29bbcb55d7318d0f4db49156061c3906789e00fc 100644 (file)
@@ -263,7 +263,7 @@ xfs_ag_resv_init(
                if (error)
                        goto out;
 
-               error = xfs_finobt_calc_reserves(mp, tp, pag, &ask, &used);
+               error = xfs_finobt_calc_reserves(pag, tp, &ask, &used);
                if (error)
                        goto out;
 
index 2add26eb46d4ae81a8e753fa803ab506aa2e12aa..c04cc7cc76cce25d5e3eb05193284467eaf32313 100644 (file)
@@ -171,13 +171,12 @@ xfs_inobt_insert(
        xfs_agino_t             newlen,
        xfs_btnum_t             btnum)
 {
-       struct xfs_mount        *mp = pag->pag_mount;
        struct xfs_btree_cur    *cur;
        xfs_agino_t             thisino;
        int                     i;
        int                     error;
 
-       cur = xfs_inobt_init_cursor(mp, tp, agbp, pag, btnum);
+       cur = xfs_inobt_init_cursor(pag, tp, agbp, btnum);
 
        for (thisino = newino;
             thisino < newino + newlen;
@@ -522,7 +521,7 @@ xfs_inobt_insert_sprec(
        int                             i;
        struct xfs_inobt_rec_incore     rec;
 
-       cur = xfs_inobt_init_cursor(mp, tp, agbp, pag, btnum);
+       cur = xfs_inobt_init_cursor(pag, tp, agbp, 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);
@@ -999,7 +998,7 @@ xfs_dialloc_ag_inobt(
        ASSERT(pag->pagi_freecount > 0);
 
  restart_pagno:
-       cur = xfs_inobt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_INO);
+       cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
        /*
         * If pagino is 0 (this is the root inode allocation) use newino.
         * This must work because we've just allocated some.
@@ -1452,7 +1451,7 @@ xfs_dialloc_ag(
        if (!pagino)
                pagino = be32_to_cpu(agi->agi_newino);
 
-       cur = xfs_inobt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_FINO);
+       cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO);
 
        error = xfs_check_agi_freecount(cur);
        if (error)
@@ -1495,7 +1494,7 @@ xfs_dialloc_ag(
         * 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, pag, XFS_BTNUM_INO);
+       icur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
 
        error = xfs_check_agi_freecount(icur);
        if (error)
@@ -1921,7 +1920,7 @@ xfs_difree_inobt(
        /*
         * Initialize the cursor.
         */
-       cur = xfs_inobt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_INO);
+       cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
 
        error = xfs_check_agi_freecount(cur);
        if (error)
@@ -2046,7 +2045,7 @@ xfs_difree_finobt(
        int                             error;
        int                             i;
 
-       cur = xfs_inobt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_FINO);
+       cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_FINO);
 
        error = xfs_inobt_lookup(cur, ibtrec->ir_startino, XFS_LOOKUP_EQ, &i);
        if (error)
@@ -2243,7 +2242,7 @@ xfs_imap_lookup(
         * 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, pag, XFS_BTNUM_INO);
+       cur = xfs_inobt_init_cursor(pag, tp, agbp, XFS_BTNUM_INO);
        error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &i);
        if (!error) {
                if (i)
@@ -2932,17 +2931,17 @@ xfs_ialloc_check_shrink(
 {
        struct xfs_inobt_rec_incore rec;
        struct xfs_btree_cur    *cur;
-       struct xfs_mount        *mp = tp->t_mountp;
-       xfs_agino_t             agino = XFS_AGB_TO_AGINO(mp, new_length);
+       xfs_agino_t             agino;
        int                     has;
        int                     error;
 
-       if (!xfs_has_sparseinodes(mp))
+       if (!xfs_has_sparseinodes(pag->pag_mount))
                return 0;
 
-       cur = xfs_inobt_init_cursor(mp, tp, agibp, pag, XFS_BTNUM_INO);
+       cur = xfs_inobt_init_cursor(pag, tp, agibp, XFS_BTNUM_INO);
 
        /* Look up the inobt record that would correspond to the new EOFS. */
+       agino = XFS_AGB_TO_AGINO(pag->pag_mount, new_length);
        error = xfs_inobt_lookup(cur, agino, XFS_LOOKUP_LE, &has);
        if (error || !has)
                goto out;
index b230a5827ab141f1d00b79bc62fd598c79fc8fae..1f0840883e2c7cd8e71002ab37c303003b31c7c7 100644 (file)
@@ -35,8 +35,8 @@ STATIC struct xfs_btree_cur *
 xfs_inobt_dup_cursor(
        struct xfs_btree_cur    *cur)
 {
-       return xfs_inobt_init_cursor(cur->bc_mp, cur->bc_tp,
-                       cur->bc_ag.agbp, cur->bc_ag.pag, cur->bc_btnum);
+       return xfs_inobt_init_cursor(cur->bc_ag.pag, cur->bc_tp,
+                       cur->bc_ag.agbp, cur->bc_btnum);
 }
 
 STATIC void
@@ -426,11 +426,11 @@ static const struct xfs_btree_ops xfs_finobt_ops = {
  */
 static struct xfs_btree_cur *
 xfs_inobt_init_common(
-       struct xfs_mount        *mp,            /* file system mount point */
-       struct xfs_trans        *tp,            /* transaction pointer */
        struct xfs_perag        *pag,
+       struct xfs_trans        *tp,            /* transaction pointer */
        xfs_btnum_t             btnum)          /* ialloc or free ino btree */
 {
+       struct xfs_mount        *mp = pag->pag_mount;
        struct xfs_btree_cur    *cur;
 
        cur = xfs_btree_alloc_cursor(mp, tp, btnum,
@@ -455,16 +455,15 @@ xfs_inobt_init_common(
 /* Create an inode btree cursor. */
 struct xfs_btree_cur *
 xfs_inobt_init_cursor(
-       struct xfs_mount        *mp,
+       struct xfs_perag        *pag,
        struct xfs_trans        *tp,
        struct xfs_buf          *agbp,
-       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, pag, btnum);
+       cur = xfs_inobt_init_common(pag, tp, btnum);
        if (btnum == XFS_BTNUM_INO)
                cur->bc_nlevels = be32_to_cpu(agi->agi_level);
        else
@@ -476,14 +475,13 @@ xfs_inobt_init_cursor(
 /* Create an inode btree cursor with a fake root for staging. */
 struct xfs_btree_cur *
 xfs_inobt_stage_cursor(
-       struct xfs_mount        *mp,
-       struct xbtree_afakeroot *afake,
        struct xfs_perag        *pag,
+       struct xbtree_afakeroot *afake,
        xfs_btnum_t             btnum)
 {
        struct xfs_btree_cur    *cur;
 
-       cur = xfs_inobt_init_common(mp, NULL, pag, btnum);
+       cur = xfs_inobt_init_common(pag, NULL, btnum);
        xfs_btree_stage_afakeroot(cur, afake);
        return cur;
 }
@@ -707,9 +705,8 @@ xfs_inobt_max_size(
 /* Read AGI and create inobt cursor. */
 int
 xfs_inobt_cur(
-       struct xfs_mount        *mp,
-       struct xfs_trans        *tp,
        struct xfs_perag        *pag,
+       struct xfs_trans        *tp,
        xfs_btnum_t             which,
        struct xfs_btree_cur    **curpp,
        struct xfs_buf          **agi_bpp)
@@ -724,16 +721,15 @@ xfs_inobt_cur(
        if (error)
                return error;
 
-       cur = xfs_inobt_init_cursor(mp, tp, *agi_bpp, pag, which);
+       cur = xfs_inobt_init_cursor(pag, tp, *agi_bpp, which);
        *curpp = cur;
        return 0;
 }
 
 static int
 xfs_inobt_count_blocks(
-       struct xfs_mount        *mp,
-       struct xfs_trans        *tp,
        struct xfs_perag        *pag,
+       struct xfs_trans        *tp,
        xfs_btnum_t             btnum,
        xfs_extlen_t            *tree_blocks)
 {
@@ -741,7 +737,7 @@ xfs_inobt_count_blocks(
        struct xfs_btree_cur    *cur = NULL;
        int                     error;
 
-       error = xfs_inobt_cur(mp, tp, pag, btnum, &cur, &agbp);
+       error = xfs_inobt_cur(pag, tp, btnum, &cur, &agbp);
        if (error)
                return error;
 
@@ -778,22 +774,21 @@ xfs_finobt_read_blocks(
  */
 int
 xfs_finobt_calc_reserves(
-       struct xfs_mount        *mp,
-       struct xfs_trans        *tp,
        struct xfs_perag        *pag,
+       struct xfs_trans        *tp,
        xfs_extlen_t            *ask,
        xfs_extlen_t            *used)
 {
        xfs_extlen_t            tree_len = 0;
        int                     error;
 
-       if (!xfs_has_finobt(mp))
+       if (!xfs_has_finobt(pag->pag_mount))
                return 0;
 
-       if (xfs_has_inobtcounts(mp))
+       if (xfs_has_inobtcounts(pag->pag_mount))
                error = xfs_finobt_read_blocks(pag, tp, &tree_len);
        else
-               error = xfs_inobt_count_blocks(mp, tp, pag, XFS_BTNUM_FINO,
+               error = xfs_inobt_count_blocks(pag, tp, XFS_BTNUM_FINO,
                                &tree_len);
        if (error)
                return error;
index 26451cb76b98bb306d6d50d13b2f290ec1d58b52..e859a6e0523096d56b7b8cef0e6b6c743f40e6a3 100644 (file)
@@ -46,12 +46,10 @@ struct xfs_perag;
                 (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 *mp,
-               struct xfs_trans *tp, struct xfs_buf *agbp,
-               struct xfs_perag *pag, xfs_btnum_t btnum);
-struct xfs_btree_cur *xfs_inobt_stage_cursor(struct xfs_mount *mp,
-               struct xbtree_afakeroot *afake, struct xfs_perag *pag,
-               xfs_btnum_t btnum);
+extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_perag *pag,
+               struct xfs_trans *tp, struct xfs_buf *agbp, xfs_btnum_t btnum);
+struct xfs_btree_cur *xfs_inobt_stage_cursor(struct xfs_perag *pag,
+               struct xbtree_afakeroot *afake, xfs_btnum_t btnum);
 extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int);
 
 /* ir_holemask to inode allocation bitmap conversion */
@@ -64,13 +62,13 @@ int xfs_inobt_rec_check_count(struct xfs_mount *,
 #define xfs_inobt_rec_check_count(mp, rec)     0
 #endif /* DEBUG */
 
-int xfs_finobt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp,
-               struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used);
+int xfs_finobt_calc_reserves(struct xfs_perag *perag, struct xfs_trans *tp,
+               xfs_extlen_t *ask, xfs_extlen_t *used);
 extern xfs_extlen_t xfs_iallocbt_calc_size(struct xfs_mount *mp,
                unsigned long long len);
-int xfs_inobt_cur(struct xfs_mount *mp, struct xfs_trans *tp,
-               struct xfs_perag *pag, xfs_btnum_t btnum,
-               struct xfs_btree_cur **curpp, struct xfs_buf **agi_bpp);
+int xfs_inobt_cur(struct xfs_perag *pag, struct xfs_trans *tp,
+               xfs_btnum_t btnum, struct xfs_btree_cur **curpp,
+               struct xfs_buf **agi_bpp);
 
 void xfs_inobt_commit_staged_btree(struct xfs_btree_cur *cur,
                struct xfs_trans *tp, struct xfs_buf *agbp);
index 0fd7ef5d351b866cf76bd603a53803106155984d..1993d6371bc4579aaeaf33aeaf6b71f349c87ac8 100644 (file)
@@ -487,8 +487,8 @@ init_ino_cursors(
                        fino_recs++;
        }
 
-       btr_ino->cur = libxfs_inobt_stage_cursor(sc->mp, &btr_ino->newbt.afake,
-                       pag, XFS_BTNUM_INO);
+       btr_ino->cur = libxfs_inobt_stage_cursor(pag, &btr_ino->newbt.afake,
+                       XFS_BTNUM_INO);
 
        btr_ino->bload.get_record = get_inobt_record;
        btr_ino->bload.claim_block = rebuild_claim_block;
@@ -507,8 +507,8 @@ _("Unable to compute inode btree geometry, error %d.\n"), error);
                return;
 
        init_rebuild(sc, &XFS_RMAP_OINFO_INOBT, free_space, btr_fino);
-       btr_fino->cur = libxfs_inobt_stage_cursor(sc->mp,
-                       &btr_fino->newbt.afake, pag, XFS_BTNUM_FINO);
+       btr_fino->cur = libxfs_inobt_stage_cursor(pag,
+                       &btr_fino->newbt.afake, XFS_BTNUM_FINO);
 
        btr_fino->bload.get_record = get_inobt_record;
        btr_fino->bload.claim_block = rebuild_claim_block;