Commit 445883e8 authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

xfs: cleanup xfs_rename error handling

The jump labels are ambiguous and unclear and some of the error
paths are used inconsistently. Rules for error jumps are:

- use out_trans_cancel for unmodified transaction context
- use out_bmap_cancel on ENOSPC errors
- use out_trans_abort when transaction is likely to be dirty.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarEric Sandeen <sandeen@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Signed-off-by: default avatarDave Chinner <david@fromorbit.com>
parent 95afcf5c
...@@ -2788,7 +2788,7 @@ xfs_rename( ...@@ -2788,7 +2788,7 @@ xfs_rename(
int error; int error;
xfs_bmap_free_t free_list; xfs_bmap_free_t free_list;
xfs_fsblock_t first_block; xfs_fsblock_t first_block;
int cancel_flags; int cancel_flags = 0;
int committed; int committed;
xfs_inode_t *inodes[__XFS_SORT_INODES]; xfs_inode_t *inodes[__XFS_SORT_INODES];
int num_inodes = __XFS_SORT_INODES; int num_inodes = __XFS_SORT_INODES;
...@@ -2802,28 +2802,23 @@ xfs_rename( ...@@ -2802,28 +2802,23 @@ xfs_rename(
xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, NULL, xfs_sort_for_rename(src_dp, target_dp, src_ip, target_ip, NULL,
inodes, &num_inodes); inodes, &num_inodes);
xfs_bmap_init(&free_list, &first_block);
tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME); tp = xfs_trans_alloc(mp, XFS_TRANS_RENAME);
cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len); spaceres = XFS_RENAME_SPACE_RES(mp, target_name->len);
error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, spaceres, 0); error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, spaceres, 0);
if (error == -ENOSPC) { if (error == -ENOSPC) {
spaceres = 0; spaceres = 0;
error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, 0, 0); error = xfs_trans_reserve(tp, &M_RES(mp)->tr_rename, 0, 0);
} }
if (error) { if (error)
xfs_trans_cancel(tp, 0); goto out_trans_cancel;
goto std_return; cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
}
/* /*
* 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)
xfs_trans_cancel(tp, cancel_flags); goto out_trans_cancel;
goto std_return;
}
/* /*
* Lock all the participating inodes. Depending upon whether * Lock all the participating inodes. Depending upon whether
...@@ -2853,9 +2848,11 @@ xfs_rename( ...@@ -2853,9 +2848,11 @@ xfs_rename(
if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) && if (unlikely((target_dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
(xfs_get_projid(target_dp) != xfs_get_projid(src_ip)))) { (xfs_get_projid(target_dp) != xfs_get_projid(src_ip)))) {
error = -EXDEV; error = -EXDEV;
goto error_return; goto out_trans_cancel;
} }
xfs_bmap_init(&free_list, &first_block);
/* /*
* Handle RENAME_EXCHANGE flags * Handle RENAME_EXCHANGE flags
*/ */
...@@ -2864,7 +2861,7 @@ xfs_rename( ...@@ -2864,7 +2861,7 @@ xfs_rename(
target_dp, target_name, target_ip, target_dp, target_name, target_ip,
&free_list, &first_block, spaceres); &free_list, &first_block, spaceres);
if (error) if (error)
goto abort_return; goto out_trans_abort;
goto finish_rename; goto finish_rename;
} }
...@@ -2879,7 +2876,7 @@ xfs_rename( ...@@ -2879,7 +2876,7 @@ xfs_rename(
if (!spaceres) { if (!spaceres) {
error = xfs_dir_canenter(tp, target_dp, target_name); error = xfs_dir_canenter(tp, target_dp, target_name);
if (error) if (error)
goto error_return; goto out_trans_cancel;
} }
/* /*
* If target does not exist and the rename crosses * If target does not exist and the rename crosses
...@@ -2890,9 +2887,9 @@ xfs_rename( ...@@ -2890,9 +2887,9 @@ xfs_rename(
src_ip->i_ino, &first_block, src_ip->i_ino, &first_block,
&free_list, spaceres); &free_list, spaceres);
if (error == -ENOSPC) if (error == -ENOSPC)
goto error_return; goto out_bmap_cancel;
if (error) if (error)
goto abort_return; goto out_trans_abort;
xfs_trans_ichgtime(tp, target_dp, xfs_trans_ichgtime(tp, target_dp,
XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
...@@ -2900,7 +2897,7 @@ xfs_rename( ...@@ -2900,7 +2897,7 @@ xfs_rename(
if (new_parent && src_is_directory) { if (new_parent && src_is_directory) {
error = xfs_bumplink(tp, target_dp); error = xfs_bumplink(tp, target_dp);
if (error) if (error)
goto abort_return; goto out_trans_abort;
} }
} else { /* target_ip != NULL */ } else { /* target_ip != NULL */
/* /*
...@@ -2915,7 +2912,7 @@ xfs_rename( ...@@ -2915,7 +2912,7 @@ xfs_rename(
if (!(xfs_dir_isempty(target_ip)) || if (!(xfs_dir_isempty(target_ip)) ||
(target_ip->i_d.di_nlink > 2)) { (target_ip->i_d.di_nlink > 2)) {
error = -EEXIST; error = -EEXIST;
goto error_return; goto out_trans_cancel;
} }
} }
...@@ -2932,7 +2929,7 @@ xfs_rename( ...@@ -2932,7 +2929,7 @@ xfs_rename(
src_ip->i_ino, src_ip->i_ino,
&first_block, &free_list, spaceres); &first_block, &free_list, spaceres);
if (error) if (error)
goto abort_return; goto out_trans_abort;
xfs_trans_ichgtime(tp, target_dp, xfs_trans_ichgtime(tp, target_dp,
XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
...@@ -2943,7 +2940,7 @@ xfs_rename( ...@@ -2943,7 +2940,7 @@ xfs_rename(
*/ */
error = xfs_droplink(tp, target_ip); error = xfs_droplink(tp, target_ip);
if (error) if (error)
goto abort_return; goto out_trans_abort;
if (src_is_directory) { if (src_is_directory) {
/* /*
...@@ -2951,7 +2948,7 @@ xfs_rename( ...@@ -2951,7 +2948,7 @@ xfs_rename(
*/ */
error = xfs_droplink(tp, target_ip); error = xfs_droplink(tp, target_ip);
if (error) if (error)
goto abort_return; goto out_trans_abort;
} }
} /* target_ip != NULL */ } /* target_ip != NULL */
...@@ -2968,7 +2965,7 @@ xfs_rename( ...@@ -2968,7 +2965,7 @@ xfs_rename(
&first_block, &free_list, spaceres); &first_block, &free_list, spaceres);
ASSERT(error != -EEXIST); ASSERT(error != -EEXIST);
if (error) if (error)
goto abort_return; goto out_trans_abort;
} }
/* /*
...@@ -2994,13 +2991,13 @@ xfs_rename( ...@@ -2994,13 +2991,13 @@ xfs_rename(
*/ */
error = xfs_droplink(tp, src_dp); error = xfs_droplink(tp, src_dp);
if (error) if (error)
goto abort_return; goto out_trans_abort;
} }
error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino, error = xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino,
&first_block, &free_list, spaceres); &first_block, &free_list, spaceres);
if (error) if (error)
goto abort_return; goto out_trans_abort;
xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG); xfs_trans_ichgtime(tp, src_dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE); xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE);
...@@ -3018,12 +3015,8 @@ xfs_rename( ...@@ -3018,12 +3015,8 @@ xfs_rename(
} }
error = xfs_bmap_finish(&tp, &free_list, &committed); error = xfs_bmap_finish(&tp, &free_list, &committed);
if (error) { if (error)
xfs_bmap_cancel(&free_list); goto out_trans_abort;
xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES |
XFS_TRANS_ABORT));
goto std_return;
}
/* /*
* trans_commit will unlock src_ip, target_ip & decrement * trans_commit will unlock src_ip, target_ip & decrement
...@@ -3031,12 +3024,12 @@ xfs_rename( ...@@ -3031,12 +3024,12 @@ xfs_rename(
*/ */
return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES); return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
abort_return: out_trans_abort:
cancel_flags |= XFS_TRANS_ABORT; cancel_flags |= XFS_TRANS_ABORT;
error_return: out_bmap_cancel:
xfs_bmap_cancel(&free_list); xfs_bmap_cancel(&free_list);
out_trans_cancel:
xfs_trans_cancel(tp, cancel_flags); xfs_trans_cancel(tp, cancel_flags);
std_return:
return error; return error;
} }
......
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