Commit 69291726 authored by Allison Henderson's avatar Allison Henderson Committed by Darrick J. Wong

xfs: Hold inode locks in xfs_rename

Modify xfs_rename to hold all inode locks across a rename operation
We will need this later when we add parent pointers
Signed-off-by: default avatarAllison Henderson <allison.henderson@oracle.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarCatherine Hoang <catherine.hoang@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
parent bd556211
...@@ -2804,6 +2804,21 @@ xfs_remove( ...@@ -2804,6 +2804,21 @@ xfs_remove(
return error; return error;
} }
static inline void
xfs_iunlock_rename(
struct xfs_inode **i_tab,
int num_inodes)
{
int i;
for (i = num_inodes - 1; i >= 0; i--) {
/* Skip duplicate inodes if src and target dps are the same */
if (!i_tab[i] || (i > 0 && i_tab[i] == i_tab[i - 1]))
continue;
xfs_iunlock(i_tab[i], XFS_ILOCK_EXCL);
}
}
/* /*
* Enter all inodes for a rename transaction into a sorted array. * Enter all inodes for a rename transaction into a sorted array.
*/ */
...@@ -3113,8 +3128,10 @@ xfs_rename( ...@@ -3113,8 +3128,10 @@ xfs_rename(
* Attach the dquots to the inodes * Attach the dquots to the inodes
*/ */
error = xfs_qm_vop_rename_dqattach(inodes); error = xfs_qm_vop_rename_dqattach(inodes);
if (error) if (error) {
goto out_trans_cancel; xfs_trans_cancel(tp);
goto out_release_wip;
}
/* /*
* Lock all the participating inodes. Depending upon whether * Lock all the participating inodes. Depending upon whether
...@@ -3125,18 +3142,16 @@ xfs_rename( ...@@ -3125,18 +3142,16 @@ xfs_rename(
xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL); xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL);
/* /*
* Join all the inodes to the transaction. From this point on, * Join all the inodes to the transaction.
* we can rely on either trans_commit or trans_cancel to unlock
* them.
*/ */
xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, src_dp, 0);
if (new_parent) if (new_parent)
xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, target_dp, 0);
xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, src_ip, 0);
if (target_ip) if (target_ip)
xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, target_ip, 0);
if (wip) if (wip)
xfs_trans_ijoin(tp, wip, XFS_ILOCK_EXCL); xfs_trans_ijoin(tp, wip, 0);
/* /*
* If we are using project inheritance, we only allow renames * If we are using project inheritance, we only allow renames
...@@ -3150,10 +3165,13 @@ xfs_rename( ...@@ -3150,10 +3165,13 @@ xfs_rename(
} }
/* RENAME_EXCHANGE is unique from here on. */ /* RENAME_EXCHANGE is unique from here on. */
if (flags & RENAME_EXCHANGE) if (flags & RENAME_EXCHANGE) {
return xfs_cross_rename(tp, src_dp, src_name, src_ip, error = xfs_cross_rename(tp, src_dp, src_name, src_ip,
target_dp, target_name, target_ip, target_dp, target_name, target_ip,
spaceres); spaceres);
xfs_iunlock_rename(inodes, num_inodes);
return error;
}
/* /*
* Try to reserve quota to handle an expansion of the target directory. * Try to reserve quota to handle an expansion of the target directory.
...@@ -3167,6 +3185,7 @@ xfs_rename( ...@@ -3167,6 +3185,7 @@ xfs_rename(
if (error == -EDQUOT || error == -ENOSPC) { if (error == -EDQUOT || error == -ENOSPC) {
if (!retried) { if (!retried) {
xfs_trans_cancel(tp); xfs_trans_cancel(tp);
xfs_iunlock_rename(inodes, num_inodes);
xfs_blockgc_free_quota(target_dp, 0); xfs_blockgc_free_quota(target_dp, 0);
retried = true; retried = true;
goto retry; goto retry;
...@@ -3393,12 +3412,14 @@ xfs_rename( ...@@ -3393,12 +3412,14 @@ xfs_rename(
xfs_dir_update_hook(src_dp, wip, 1, src_name); xfs_dir_update_hook(src_dp, wip, 1, src_name);
error = xfs_finish_rename(tp); error = xfs_finish_rename(tp);
xfs_iunlock_rename(inodes, num_inodes);
if (wip) if (wip)
xfs_irele(wip); xfs_irele(wip);
return error; return error;
out_trans_cancel: out_trans_cancel:
xfs_trans_cancel(tp); xfs_trans_cancel(tp);
xfs_iunlock_rename(inodes, num_inodes);
out_release_wip: out_release_wip:
if (wip) if (wip)
xfs_irele(wip); xfs_irele(wip);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment