]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: Replace xfs_isilocked with xfs_assert_ilocked
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 22 Apr 2024 17:00:52 +0000 (10:00 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 3 Jun 2024 18:37:35 +0000 (11:37 -0700)
Source kernel commit: 3fed24fffc76dd1a8105db558e98bc8355d60379

To use the new rwsem_assert_held()/rwsem_assert_held_write(), we can't
use the existing ASSERT macro.  Add a new xfs_assert_ilocked() and
convert all the callers.

Fix an apparent bug in xfs_isilocked(): If the caller specifies
XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL, xfs_assert_ilocked() will check both
the IOLOCK and the ILOCK are held for write.  xfs_isilocked() only
checked that the ILOCK was held for write.

xfs_assert_ilocked() is always on, even if DEBUG or XFS_WARN aren't
defined.  It's a cheap check, so I don't think it's worth defining
it away.

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: "Matthew Wilcox (Oracle)" <willy@infradead.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
libxfs/libxfs_priv.h
libxfs/xfs_attr.c
libxfs/xfs_attr_remote.c
libxfs/xfs_bmap.c
libxfs/xfs_defer.c
libxfs/xfs_inode_fork.c
libxfs/xfs_rtbitmap.c
libxfs/xfs_trans_inode.c

index 705b66bed13f0ee8b8cf63df54f84a54e1607d3c..0a4f686d94551d3c51c47d6b04ffb0aff0cdc11d 100644 (file)
@@ -406,6 +406,7 @@ void __xfs_buf_mark_corrupt(struct xfs_buf *bp, xfs_failaddr_t fa);
        __mode = __mode; /* no set-but-unused warning */        \
 })
 #define xfs_lock_two_inodes(ip0,mode0,ip1,mode1)       ((void) 0)
+#define xfs_assert_ilocked(ip, flags)                  ((void) 0)
 
 /* space allocation */
 #define XFS_EXTENT_BUSY_DISCARDED      0x01    /* undergoing a discard op. */
index 8356d4a3c6793a828f30089ffe9bafabe49fad75..caf04daa73cf4987e9b37c7e73f5e90ca84ffa9d 100644 (file)
@@ -222,7 +222,7 @@ int
 xfs_attr_get_ilocked(
        struct xfs_da_args      *args)
 {
-       ASSERT(xfs_isilocked(args->dp, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(args->dp, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL);
 
        if (!xfs_inode_hasattr(args->dp))
                return -ENOATTR;
index 4f2b93f81bacc5990c3127433933353dee06f75b..12d1ba9c3a341ec4301a4012a9eb3ff4db7b124c 100644 (file)
@@ -544,7 +544,7 @@ xfs_attr_rmtval_stale(
        struct xfs_buf          *bp;
        int                     error;
 
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
 
        if (XFS_IS_CORRUPT(mp, map->br_startblock == DELAYSTARTBLOCK) ||
            XFS_IS_CORRUPT(mp, map->br_startblock == HOLESTARTBLOCK))
index ee4e6c766144680d8a629bea1e9ccd6defcaf534..4f616a5473dfc398fd6a659fd09c8c2824fe29db 100644 (file)
@@ -1183,7 +1183,7 @@ xfs_iread_extents(
        if (!xfs_need_iread_extents(ifp))
                return 0;
 
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
 
        ir.loaded = 0;
        xfs_iext_first(ifp, &ir.icur);
@@ -3892,7 +3892,7 @@ xfs_bmapi_read(
 
        ASSERT(*nmap >= 1);
        ASSERT(!(flags & ~(XFS_BMAPI_ATTRFORK | XFS_BMAPI_ENTIRE)));
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED|XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL);
 
        if (WARN_ON_ONCE(!ifp))
                return -EFSCORRUPTED;
@@ -4363,7 +4363,7 @@ xfs_bmapi_write(
        ASSERT(tp != NULL);
        ASSERT(len > 0);
        ASSERT(ifp->if_format != XFS_DINODE_FMT_LOCAL);
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
        ASSERT(!(flags & XFS_BMAPI_REMAP));
 
        /* zeroing is for currently only for data extents, not metadata */
@@ -4660,7 +4660,7 @@ xfs_bmapi_remap(
        ifp = xfs_ifork_ptr(ip, whichfork);
        ASSERT(len > 0);
        ASSERT(len <= (xfs_filblks_t)XFS_MAX_BMBT_EXTLEN);
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
        ASSERT(!(flags & ~(XFS_BMAPI_ATTRFORK | XFS_BMAPI_PREALLOC |
                           XFS_BMAPI_NORMAP)));
        ASSERT((flags & (XFS_BMAPI_ATTRFORK | XFS_BMAPI_PREALLOC)) !=
@@ -5285,7 +5285,7 @@ __xfs_bunmapi(
        if (xfs_is_shutdown(mp))
                return -EIO;
 
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
        ASSERT(len > 0);
        ASSERT(nexts >= 0);
 
@@ -5629,8 +5629,7 @@ xfs_bmse_merge(
 
        blockcount = left->br_blockcount + got->br_blockcount;
 
-       ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
        ASSERT(xfs_bmse_can_merge(left, got, shift));
 
        new = *left;
@@ -5758,7 +5757,7 @@ xfs_bmap_collapse_extents(
        if (xfs_is_shutdown(mp))
                return -EIO;
 
-       ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
 
        error = xfs_iread_extents(tp, ip, whichfork);
        if (error)
@@ -5831,7 +5830,7 @@ xfs_bmap_can_insert_extents(
        int                     is_empty;
        int                     error = 0;
 
-       ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL);
 
        if (xfs_is_shutdown(ip->i_mount))
                return -EIO;
@@ -5873,7 +5872,7 @@ xfs_bmap_insert_extents(
        if (xfs_is_shutdown(mp))
                return -EIO;
 
-       ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
 
        error = xfs_iread_extents(tp, ip, whichfork);
        if (error)
@@ -6251,7 +6250,7 @@ xfs_bunmapi_range(
        xfs_filblks_t           unmap_len = endoff - startoff + 1;
        int                     error = 0;
 
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
 
        while (unmap_len > 0) {
                ASSERT((*tpp)->t_highest_agno == NULLAGNUMBER);
index 9f960bec48ab78e77a5b758b4c1a326112aed804..b80ac04ab2fb9a290c5f6e73def272223035cdbb 100644 (file)
@@ -1000,7 +1000,7 @@ xfs_defer_ops_capture(
         * transaction.
         */
        for (i = 0; i < dfc->dfc_held.dr_inos; i++) {
-               ASSERT(xfs_isilocked(dfc->dfc_held.dr_ip[i], XFS_ILOCK_EXCL));
+               xfs_assert_ilocked(dfc->dfc_held.dr_ip[i], XFS_ILOCK_EXCL);
                ihold(VFS_I(dfc->dfc_held.dr_ip[i]));
        }
 
index f8f6a7364d57ff9b63af642e316b32de2cd47c73..6d81757239bb1d1d357b2d74d061e52e3ec5c653 100644 (file)
@@ -563,7 +563,7 @@ xfs_iextents_copy(
        struct xfs_bmbt_irec    rec;
        int64_t                 copied = 0;
 
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL | XFS_ILOCK_SHARED));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL | XFS_ILOCK_SHARED);
        ASSERT(ifp->if_bytes > 0);
 
        for_each_xfs_iext(ifp, &icur, &rec) {
index 08a4128fc5249da712b8f378b66761dd19467efa..146e06bd880aa21d4d6add1bb9d4e1457d27ba39 100644 (file)
@@ -932,7 +932,7 @@ xfs_rtfree_extent(
        struct timespec64       atime;
 
        ASSERT(mp->m_rbmip->i_itemp != NULL);
-       ASSERT(xfs_isilocked(mp->m_rbmip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(mp->m_rbmip, XFS_ILOCK_EXCL);
 
        error = xfs_rtcheck_alloc_range(&args, start, len);
        if (error)
index c171a525cefb71e2ff62a6ccaebe0b5852feaf2f..f8484eb20e8257dee5f6956cb18ac09430d1d089 100644 (file)
@@ -28,7 +28,7 @@ xfs_trans_ijoin(
 {
        struct xfs_inode_log_item *iip;
 
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
        if (ip->i_itemp == NULL)
                xfs_inode_item_init(ip, ip->i_mount);
        iip = ip->i_itemp;
@@ -57,7 +57,7 @@ xfs_trans_ichgtime(
        struct timespec64       tv;
 
        ASSERT(tp);
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
 
        tv = current_time(inode);
 
@@ -87,7 +87,7 @@ xfs_trans_log_inode(
        struct inode            *inode = VFS_I(ip);
 
        ASSERT(iip);
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
+       xfs_assert_ilocked(ip, XFS_ILOCK_EXCL);
        ASSERT(!xfs_iflags_test(ip, XFS_ISTALE));
 
        tp->t_flags |= XFS_TRANS_DIRTY;