]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: consolidate the xfs_alloc_lookup_* helpers
authorChristoph Hellwig <hch@lst.de>
Mon, 22 Apr 2024 17:00:57 +0000 (10:00 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 3 Jun 2024 18:37:37 +0000 (11:37 -0700)
Source kernel commit: 73a8fd93c421c4a6ac2c581c4d3478d3d68a0def

Add a single xfs_alloc_lookup helper to sort out the argument passing and
setting of the active flag instead of duplicating the logic three times.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
libxfs/xfs_alloc.c

index 3d7686eadab2ed99511f52ccaf38debf2e6aff49..45843616647d78e851f92b6ba2c977ddf4939622 100644 (file)
@@ -147,23 +147,35 @@ xfs_alloc_ag_max_usable(
        return mp->m_sb.sb_agblocks - blocks;
 }
 
+
+static int
+xfs_alloc_lookup(
+       struct xfs_btree_cur    *cur,
+       xfs_lookup_t            dir,
+       xfs_agblock_t           bno,
+       xfs_extlen_t            len,
+       int                     *stat)
+{
+       int                     error;
+
+       cur->bc_rec.a.ar_startblock = bno;
+       cur->bc_rec.a.ar_blockcount = len;
+       error = xfs_btree_lookup(cur, dir, stat);
+       cur->bc_ag.abt.active = (*stat == 1);
+       return error;
+}
+
 /*
  * Lookup the record equal to [bno, len] in the btree given by cur.
  */
-STATIC int                             /* error */
+static inline int                              /* error */
 xfs_alloc_lookup_eq(
        struct xfs_btree_cur    *cur,   /* btree cursor */
        xfs_agblock_t           bno,    /* starting block of extent */
        xfs_extlen_t            len,    /* length of extent */
        int                     *stat)  /* success/failure */
 {
-       int                     error;
-
-       cur->bc_rec.a.ar_startblock = bno;
-       cur->bc_rec.a.ar_blockcount = len;
-       error = xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
-       cur->bc_ag.abt.active = (*stat == 1);
-       return error;
+       return xfs_alloc_lookup(cur, XFS_LOOKUP_EQ, bno, len, stat);
 }
 
 /*
@@ -177,13 +189,7 @@ xfs_alloc_lookup_ge(
        xfs_extlen_t            len,    /* length of extent */
        int                     *stat)  /* success/failure */
 {
-       int                     error;
-
-       cur->bc_rec.a.ar_startblock = bno;
-       cur->bc_rec.a.ar_blockcount = len;
-       error = xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
-       cur->bc_ag.abt.active = (*stat == 1);
-       return error;
+       return xfs_alloc_lookup(cur, XFS_LOOKUP_GE, bno, len, stat);
 }
 
 /*
@@ -197,12 +203,7 @@ xfs_alloc_lookup_le(
        xfs_extlen_t            len,    /* length of extent */
        int                     *stat)  /* success/failure */
 {
-       int                     error;
-       cur->bc_rec.a.ar_startblock = bno;
-       cur->bc_rec.a.ar_blockcount = len;
-       error = xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
-       cur->bc_ag.abt.active = (*stat == 1);
-       return error;
+       return xfs_alloc_lookup(cur, XFS_LOOKUP_LE, bno, len, stat);
 }
 
 static inline bool