]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: refactor domain and refcount checking
authorDarrick J. Wong <djwong@kernel.org>
Fri, 18 Nov 2022 11:23:57 +0000 (12:23 +0100)
committerCarlos Maiolino <cem@kernel.org>
Mon, 21 Nov 2022 14:26:48 +0000 (15:26 +0100)
Source kernel commit: f492135df0aa0417337f9b8b1cc6d6a994d61d25

Create a helper function to ensure that CoW staging extent records have
a single refcount and that shared extent records have more than 1
refcount.  We'll put this to more use in the next patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_refcount.c
libxfs/xfs_refcount.h

index 7094a27dcebe14a92267da083cd54f311b4cd4b2..f0fc96da6a0cfbbb5623753458b2d4b70e69fa83 100644 (file)
@@ -141,10 +141,7 @@ xfs_refcount_get_rec(
        if (irec->rc_blockcount == 0 || irec->rc_blockcount > MAXREFCEXTLEN)
                goto out_bad_rec;
 
-       /* handle special COW-staging domain */
-       if (irec->rc_domain == XFS_REFC_DOMAIN_COW && irec->rc_refcount != 1)
-               goto out_bad_rec;
-       if (irec->rc_domain == XFS_REFC_DOMAIN_SHARED && irec->rc_refcount < 2)
+       if (!xfs_refcount_check_domain(irec))
                goto out_bad_rec;
 
        /* check for valid extent range, including overflow */
index 3beb5a30a9c9e54b2c33db7cce8ede2970078921..ee32e8eb5a993178fabed2b7a280d59047c3b814 100644 (file)
@@ -55,6 +55,18 @@ struct xfs_refcount_intent {
        xfs_fsblock_t                           ri_startblock;
 };
 
+/* Check that the refcount is appropriate for the record domain. */
+static inline bool
+xfs_refcount_check_domain(
+       const struct xfs_refcount_irec  *irec)
+{
+       if (irec->rc_domain == XFS_REFC_DOMAIN_COW && irec->rc_refcount != 1)
+               return false;
+       if (irec->rc_domain == XFS_REFC_DOMAIN_SHARED && irec->rc_refcount < 2)
+               return false;
+       return true;
+}
+
 void xfs_refcount_increase_extent(struct xfs_trans *tp,
                struct xfs_bmbt_irec *irec);
 void xfs_refcount_decrease_extent(struct xfs_trans *tp,