xfs
[Top] [All Lists]

[PATCH] xfs: don't hold the XFS_ILOCK while flushing pages in swapext

To: xfs@xxxxxxxxxxx
Subject: [PATCH] xfs: don't hold the XFS_ILOCK while flushing pages in swapext
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Tue, 27 Jul 2010 15:47:31 +1000
From: Dave Chinner <dchinner@xxxxxxxxxx>

Otherwise it'll deadlock during allocation/block mapping.

Signed-off-by: Dave Chinner <dchinner@xxxxxxxxxx>
---
 fs/xfs/xfs_dfrag.c |   31 ++++++++++++++++++-------------
 1 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/fs/xfs/xfs_dfrag.c b/fs/xfs/xfs_dfrag.c
index 3b9582c..f04a79a 100644
--- a/fs/xfs/xfs_dfrag.c
+++ b/fs/xfs/xfs_dfrag.c
@@ -229,29 +229,34 @@ xfs_swap_extents(
         * below.
         */
        xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL);
+
+       /*
+        * can't hold the ILOCK while flushing pages, so flush now we won't get
+        * new pages cached as we hold the XFS_IOLOCK_EXCL.
+        */
+       if (VN_CACHED(VFS_I(tip)) != 0) {
+               error = xfs_flushinval_pages(tip, 0, -1,
+                               FI_REMAPF_LOCKED);
+               if (error)
+                       goto out_unlock;
+       }
+
        xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL);
 
-       /* Verify that both files have the same format */
-       if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {
+       /* Verify we have no cached pages for ftmp */
+       if (VN_CACHED(VFS_I(tip)) != 0) {
                error = XFS_ERROR(EINVAL);
                goto out_unlock;
        }
 
-       /* Verify both files are either real-time or non-realtime */
-       if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) {
+       /* Verify that both files have the same format */
+       if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) {
                error = XFS_ERROR(EINVAL);
                goto out_unlock;
        }
 
-       if (VN_CACHED(VFS_I(tip)) != 0) {
-               error = xfs_flushinval_pages(tip, 0, -1,
-                               FI_REMAPF_LOCKED);
-               if (error)
-                       goto out_unlock;
-       }
-
-       /* Verify O_DIRECT for ftmp */
-       if (VN_CACHED(VFS_I(tip)) != 0) {
+       /* Verify both files are either real-time or non-realtime */
+       if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) {
                error = XFS_ERROR(EINVAL);
                goto out_unlock;
        }
-- 
1.7.1

<Prev in Thread] Current Thread [Next in Thread>