diff options
| -rw-r--r-- | fs/xfs/xfs_bmap_util.c | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c index bf7e6159cfe2..5d29aa17475e 100644 --- a/fs/xfs/xfs_bmap_util.c +++ b/fs/xfs/xfs_bmap_util.c | |||
| @@ -1686,6 +1686,7 @@ xfs_swap_extents( | |||
| 1686 | int aforkblks = 0; | 1686 | int aforkblks = 0; |
| 1687 | int taforkblks = 0; | 1687 | int taforkblks = 0; |
| 1688 | __uint64_t tmp; | 1688 | __uint64_t tmp; |
| 1689 | int lock_flags; | ||
| 1689 | 1690 | ||
| 1690 | tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL); | 1691 | tempifp = kmem_alloc(sizeof(xfs_ifork_t), KM_MAYFAIL); |
| 1691 | if (!tempifp) { | 1692 | if (!tempifp) { |
| @@ -1694,13 +1695,13 @@ xfs_swap_extents( | |||
| 1694 | } | 1695 | } |
| 1695 | 1696 | ||
| 1696 | /* | 1697 | /* |
| 1697 | * we have to do two separate lock calls here to keep lockdep | 1698 | * Lock up the inodes against other IO and truncate to begin with. |
| 1698 | * happy. If we try to get all the locks in one call, lock will | 1699 | * Then we can ensure the inodes are flushed and have no page cache |
| 1699 | * report false positives when we drop the ILOCK and regain them | 1700 | * safely. Once we have done this we can take the ilocks and do the rest |
| 1700 | * below. | 1701 | * of the checks. |
| 1701 | */ | 1702 | */ |
| 1703 | lock_flags = XFS_IOLOCK_EXCL; | ||
| 1702 | xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL); | 1704 | xfs_lock_two_inodes(ip, tip, XFS_IOLOCK_EXCL); |
| 1703 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); | ||
| 1704 | 1705 | ||
| 1705 | /* Verify that both files have the same format */ | 1706 | /* Verify that both files have the same format */ |
| 1706 | if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) { | 1707 | if ((ip->i_d.di_mode & S_IFMT) != (tip->i_d.di_mode & S_IFMT)) { |
| @@ -1719,6 +1720,9 @@ xfs_swap_extents( | |||
| 1719 | goto out_unlock; | 1720 | goto out_unlock; |
| 1720 | truncate_pagecache_range(VFS_I(tip), 0, -1); | 1721 | truncate_pagecache_range(VFS_I(tip), 0, -1); |
| 1721 | 1722 | ||
| 1723 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); | ||
| 1724 | lock_flags |= XFS_ILOCK_EXCL; | ||
| 1725 | |||
| 1722 | /* Verify O_DIRECT for ftmp */ | 1726 | /* Verify O_DIRECT for ftmp */ |
| 1723 | if (VFS_I(tip)->i_mapping->nrpages) { | 1727 | if (VFS_I(tip)->i_mapping->nrpages) { |
| 1724 | error = -EINVAL; | 1728 | error = -EINVAL; |
| @@ -1773,6 +1777,7 @@ xfs_swap_extents( | |||
| 1773 | 1777 | ||
| 1774 | xfs_iunlock(ip, XFS_ILOCK_EXCL); | 1778 | xfs_iunlock(ip, XFS_ILOCK_EXCL); |
| 1775 | xfs_iunlock(tip, XFS_ILOCK_EXCL); | 1779 | xfs_iunlock(tip, XFS_ILOCK_EXCL); |
| 1780 | lock_flags &= ~XFS_ILOCK_EXCL; | ||
| 1776 | 1781 | ||
| 1777 | /* | 1782 | /* |
| 1778 | * There is a race condition here since we gave up the | 1783 | * There is a race condition here since we gave up the |
| @@ -1785,13 +1790,11 @@ xfs_swap_extents( | |||
| 1785 | 1790 | ||
| 1786 | tp = xfs_trans_alloc(mp, XFS_TRANS_SWAPEXT); | 1791 | tp = xfs_trans_alloc(mp, XFS_TRANS_SWAPEXT); |
| 1787 | error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0); | 1792 | error = xfs_trans_reserve(tp, &M_RES(mp)->tr_ichange, 0, 0); |
| 1788 | if (error) { | 1793 | if (error) |
| 1789 | xfs_iunlock(ip, XFS_IOLOCK_EXCL); | 1794 | goto out_trans_cancel; |
| 1790 | xfs_iunlock(tip, XFS_IOLOCK_EXCL); | 1795 | |
| 1791 | xfs_trans_cancel(tp, 0); | ||
| 1792 | goto out; | ||
| 1793 | } | ||
| 1794 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); | 1796 | xfs_lock_two_inodes(ip, tip, XFS_ILOCK_EXCL); |
| 1797 | lock_flags |= XFS_ILOCK_EXCL; | ||
| 1795 | 1798 | ||
| 1796 | /* | 1799 | /* |
| 1797 | * Count the number of extended attribute blocks | 1800 | * Count the number of extended attribute blocks |
| @@ -1810,8 +1813,8 @@ xfs_swap_extents( | |||
| 1810 | goto out_trans_cancel; | 1813 | goto out_trans_cancel; |
| 1811 | } | 1814 | } |
| 1812 | 1815 | ||
| 1813 | xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); | 1816 | xfs_trans_ijoin(tp, ip, lock_flags); |
| 1814 | xfs_trans_ijoin(tp, tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); | 1817 | xfs_trans_ijoin(tp, tip, lock_flags); |
| 1815 | 1818 | ||
| 1816 | /* | 1819 | /* |
| 1817 | * Before we've swapped the forks, lets set the owners of the forks | 1820 | * Before we've swapped the forks, lets set the owners of the forks |
| @@ -1940,8 +1943,8 @@ out: | |||
| 1940 | return error; | 1943 | return error; |
| 1941 | 1944 | ||
| 1942 | out_unlock: | 1945 | out_unlock: |
| 1943 | xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); | 1946 | xfs_iunlock(ip, lock_flags); |
| 1944 | xfs_iunlock(tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL); | 1947 | xfs_iunlock(tip, lock_flags); |
| 1945 | goto out; | 1948 | goto out; |
| 1946 | 1949 | ||
| 1947 | out_trans_cancel: | 1950 | out_trans_cancel: |
