]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: cleanup xfs_ilock_iocb_for_write
authorChristoph Hellwig <hch@lst.de>
Sun, 23 Jun 2024 05:44:27 +0000 (07:44 +0200)
committerChandan Babu R <chandanbabu@kernel.org>
Mon, 1 Jul 2024 04:02:29 +0000 (09:32 +0530)
Move the relock path out of the straight line and add a comment
explaining why it exists.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
fs/xfs/xfs_file.c

index b240ea5241dc9d3e9782d181c965078771362592..74c2c8d253e69b1ee755252baaf14c2ccb6e5170 100644 (file)
@@ -213,14 +213,18 @@ xfs_ilock_iocb_for_write(
        if (ret)
                return ret;
 
-       if (*lock_mode == XFS_IOLOCK_EXCL)
-               return 0;
-       if (!xfs_iflags_test(ip, XFS_IREMAPPING))
-               return 0;
+       /*
+        * If a reflink remap is in progress we always need to take the iolock
+        * exclusively to wait for it to finish.
+        */
+       if (*lock_mode == XFS_IOLOCK_SHARED &&
+           xfs_iflags_test(ip, XFS_IREMAPPING)) {
+               xfs_iunlock(ip, *lock_mode);
+               *lock_mode = XFS_IOLOCK_EXCL;
+               return xfs_ilock_iocb(iocb, *lock_mode);
+       }
 
-       xfs_iunlock(ip, *lock_mode);
-       *lock_mode = XFS_IOLOCK_EXCL;
-       return xfs_ilock_iocb(iocb, *lock_mode);
+       return 0;
 }
 
 static unsigned int