]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: pass xfs_buf lookup flags to xfs_*read_agi
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:22:34 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:00:59 +0000 (17:00 -0700)
Source kernel commit: 549d3c9a29921f388ef3bcfd1d4f669b7dd4eed2

Allow callers to pass buffer lookup flags to xfs_read_agi and
xfs_ialloc_read_agi.  This will be used in the next patch to fix a
deadlock in the online fsck inode scanner.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
db/iunlink.c
libxfs/xfs_ag.c
libxfs/xfs_ialloc.c
libxfs/xfs_ialloc.h
libxfs/xfs_ialloc_btree.c

index d87562e3b0a2c020b09e9e28e23675e26e3ff2ab..256c85560192b3fd7ce02d944bb43ccd45f7f8ef 100644 (file)
@@ -117,7 +117,7 @@ dump_unlinked(
        xfs_agnumber_t          agno = pag->pag_agno;
        int                     error;
 
-       error = -libxfs_ialloc_read_agi(pag, NULL, &agi_bp);
+       error = -libxfs_ialloc_read_agi(pag, NULL, 0, &agi_bp);
        if (error) {
                dbprintf(_("AGI %u: %s\n"), agno, strerror(errno));
                return;
@@ -295,7 +295,7 @@ iunlink(
        pag = libxfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino));
 
        /* Get the agi buffer first.  It ensures lock ordering on the list. */
-       error = -libxfs_read_agi(pag, tp, &agibp);
+       error = -libxfs_read_agi(pag, tp, 0, &agibp);
        if (error)
                goto out;
 
index a9aae0990d93169bd539beb6cd7942d3dfc2fdeb..ad721c1922df8dc0d643b1190a13a72b3278bbb6 100644 (file)
@@ -192,7 +192,7 @@ xfs_initialize_perag_data(
                pag = xfs_perag_get(mp, index);
                error = xfs_alloc_read_agf(pag, NULL, 0, NULL);
                if (!error)
-                       error = xfs_ialloc_read_agi(pag, NULL, NULL);
+                       error = xfs_ialloc_read_agi(pag, NULL, 0, NULL);
                if (error) {
                        xfs_perag_put(pag);
                        return error;
@@ -929,7 +929,7 @@ xfs_ag_shrink_space(
        int                     error, err2;
 
        ASSERT(pag->pag_agno == mp->m_sb.sb_agcount - 1);
-       error = xfs_ialloc_read_agi(pag, *tpp, &agibp);
+       error = xfs_ialloc_read_agi(pag, *tpp, 0, &agibp);
        if (error)
                return error;
 
@@ -1060,7 +1060,7 @@ xfs_ag_extend_space(
 
        ASSERT(pag->pag_agno == pag->pag_mount->m_sb.sb_agcount - 1);
 
-       error = xfs_ialloc_read_agi(pag, tp, &bp);
+       error = xfs_ialloc_read_agi(pag, tp, 0, &bp);
        if (error)
                return error;
 
@@ -1117,7 +1117,7 @@ xfs_ag_get_geometry(
        int                     error;
 
        /* Lock the AG headers. */
-       error = xfs_ialloc_read_agi(pag, NULL, &agi_bp);
+       error = xfs_ialloc_read_agi(pag, NULL, 0, &agi_bp);
        if (error)
                return error;
        error = xfs_alloc_read_agf(pag, NULL, 0, &agf_bp);
index c30e76830bb1b7f581033ce5b3cd4e6467b5826b..992b8348a45a2d7ec4eb1fea196f40e636adfca6 100644 (file)
@@ -1694,7 +1694,7 @@ xfs_dialloc_good_ag(
                return false;
 
        if (!xfs_perag_initialised_agi(pag)) {
-               error = xfs_ialloc_read_agi(pag, tp, NULL);
+               error = xfs_ialloc_read_agi(pag, tp, 0, NULL);
                if (error)
                        return false;
        }
@@ -1763,7 +1763,7 @@ xfs_dialloc_try_ag(
         * Then read in the AGI buffer and recheck with the AGI buffer
         * lock held.
         */
-       error = xfs_ialloc_read_agi(pag, *tpp, &agbp);
+       error = xfs_ialloc_read_agi(pag, *tpp, 0, &agbp);
        if (error)
                return error;
 
@@ -2281,7 +2281,7 @@ xfs_difree(
        /*
         * Get the allocation group header.
         */
-       error = xfs_ialloc_read_agi(pag, tp, &agbp);
+       error = xfs_ialloc_read_agi(pag, tp, 0, &agbp);
        if (error) {
                xfs_warn(mp, "%s: xfs_ialloc_read_agi() returned error %d.",
                        __func__, error);
@@ -2327,7 +2327,7 @@ xfs_imap_lookup(
        int                     error;
        int                     i;
 
-       error = xfs_ialloc_read_agi(pag, tp, &agbp);
+       error = xfs_ialloc_read_agi(pag, tp, 0, &agbp);
        if (error) {
                xfs_alert(mp,
                        "%s: xfs_ialloc_read_agi() returned error %d, agno %d",
@@ -2670,6 +2670,7 @@ int
 xfs_read_agi(
        struct xfs_perag        *pag,
        struct xfs_trans        *tp,
+       xfs_buf_flags_t         flags,
        struct xfs_buf          **agibpp)
 {
        struct xfs_mount        *mp = pag->pag_mount;
@@ -2679,7 +2680,7 @@ xfs_read_agi(
 
        error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
                        XFS_AG_DADDR(mp, pag->pag_agno, XFS_AGI_DADDR(mp)),
-                       XFS_FSS_TO_BB(mp, 1), 0, agibpp, &xfs_agi_buf_ops);
+                       XFS_FSS_TO_BB(mp, 1), flags, agibpp, &xfs_agi_buf_ops);
        if (xfs_metadata_is_sick(error))
                xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI);
        if (error)
@@ -2699,6 +2700,7 @@ int
 xfs_ialloc_read_agi(
        struct xfs_perag        *pag,
        struct xfs_trans        *tp,
+       int                     flags,
        struct xfs_buf          **agibpp)
 {
        struct xfs_buf          *agibp;
@@ -2707,7 +2709,9 @@ xfs_ialloc_read_agi(
 
        trace_xfs_ialloc_read_agi(pag->pag_mount, pag->pag_agno);
 
-       error = xfs_read_agi(pag, tp, &agibp);
+       error = xfs_read_agi(pag, tp,
+                       (flags & XFS_IALLOC_FLAG_TRYLOCK) ? XBF_TRYLOCK : 0,
+                       &agibp);
        if (error)
                return error;
 
index f1412183bb44bb2578c5929b67d019cfb123d717..b549627e3a6150a66b9381237bdd649599d4675a 100644 (file)
@@ -63,10 +63,11 @@ xfs_ialloc_log_agi(
        struct xfs_buf  *bp,            /* allocation group header buffer */
        uint32_t        fields);        /* bitmask of fields to log */
 
-int xfs_read_agi(struct xfs_perag *pag, struct xfs_trans *tp,
+int xfs_read_agi(struct xfs_perag *pag, struct xfs_trans *tp, xfs_buf_flags_t flags,
                struct xfs_buf **agibpp);
 int xfs_ialloc_read_agi(struct xfs_perag *pag, struct xfs_trans *tp,
-               struct xfs_buf **agibpp);
+               int flags, struct xfs_buf **agibpp);
+#define        XFS_IALLOC_FLAG_TRYLOCK (1U << 0)  /* use trylock for buffer locking */
 
 /*
  * Lookup a record by ino in the btree given by cur.
index 58c520ecba5a57e690c8c8d19aa166a74b952d25..5db9d0b33d66b47b8fad725b44b3d21032dc506a 100644 (file)
@@ -744,7 +744,7 @@ xfs_finobt_count_blocks(
        struct xfs_btree_cur    *cur;
        int                     error;
 
-       error = xfs_ialloc_read_agi(pag, tp, &agbp);
+       error = xfs_ialloc_read_agi(pag, tp, 0, &agbp);
        if (error)
                return error;
 
@@ -767,7 +767,7 @@ xfs_finobt_read_blocks(
        struct xfs_agi          *agi;
        int                     error;
 
-       error = xfs_ialloc_read_agi(pag, tp, &agbp);
+       error = xfs_ialloc_read_agi(pag, tp, 0, &agbp);
        if (error)
                return error;