xfs: track active state of allocation btree cursors
authorBrian Foster <bfoster@redhat.com>
Mon, 14 Oct 2019 00:10:31 +0000 (17:10 -0700)
committerDarrick J. Wong <darrick.wong@oracle.com>
Mon, 21 Oct 2019 16:04:58 +0000 (09:04 -0700)
The upcoming allocation algorithm update searches multiple
allocation btree cursors concurrently. As such, it requires an
active state to track when a particular cursor should continue
searching. While active state will be modified based on higher level
logic, we can define base functionality based on the result of
allocation btree lookups.

Define an active flag in the private area of the btree cursor.
Update it based on the result of lookups in the existing allocation
btree helpers. Finally, provide a new helper to query the current
state.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
fs/xfs/libxfs/xfs_alloc.c
fs/xfs/libxfs/xfs_alloc_btree.c
fs/xfs/libxfs/xfs_btree.h

index 533b04aaf6f6b73759fda9565475a8eca1a0f4e1..0ecc142c833bfa97cb4c0d4ef20dcf26844f4b94 100644 (file)
@@ -146,9 +146,13 @@ xfs_alloc_lookup_eq(
        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;
-       return xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
+       error = xfs_btree_lookup(cur, XFS_LOOKUP_EQ, stat);
+       cur->bc_private.a.priv.abt.active = (*stat == 1);
+       return error;
 }
 
 /*
@@ -162,9 +166,13 @@ 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;
-       return xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
+       error = xfs_btree_lookup(cur, XFS_LOOKUP_GE, stat);
+       cur->bc_private.a.priv.abt.active = (*stat == 1);
+       return error;
 }
 
 /*
@@ -178,9 +186,19 @@ 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;
-       return xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
+       error = xfs_btree_lookup(cur, XFS_LOOKUP_LE, stat);
+       cur->bc_private.a.priv.abt.active = (*stat == 1);
+       return error;
+}
+
+static inline bool
+xfs_alloc_cur_active(
+       struct xfs_btree_cur    *cur)
+{
+       return cur && cur->bc_private.a.priv.abt.active;
 }
 
 /*
index 2a94543857a195e55cd96bc2026075ec7559dc7b..279694d73e4e0d8b070e519f722715f29be684da 100644 (file)
@@ -507,6 +507,7 @@ xfs_allocbt_init_cursor(
 
        cur->bc_private.a.agbp = agbp;
        cur->bc_private.a.agno = agno;
+       cur->bc_private.a.priv.abt.active = false;
 
        if (xfs_sb_version_hascrc(&mp->m_sb))
                cur->bc_flags |= XFS_BTREE_CRC_BLOCKS;
index ced1e65d1483f175041d0f3ecbf0b1fbbcd5cbc8..b4e3ec1d7ff95231d8022081805fa42cd7adfe0c 100644 (file)
@@ -183,6 +183,9 @@ union xfs_btree_cur_private {
                unsigned long   nr_ops;         /* # record updates */
                int             shape_changes;  /* # of extent splits */
        } refc;
+       struct {
+               bool            active;         /* allocation cursor state */
+       } abt;
 };
 
 /*