Commit 64a3f331 authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: clean up xfs_bui_item_recover iget/trans_alloc/ilock ordering

In most places in XFS, we have a specific order in which we gather
resources: grab the inode, allocate a transaction, then lock the inode.
xfs_bui_item_recover doesn't do it in that order, so fix it to be more
consistent.  This also makes the error bailout code a bit less weird.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
parent 919522e8
...@@ -475,25 +475,26 @@ xfs_bui_item_recover( ...@@ -475,25 +475,26 @@ xfs_bui_item_recover(
(bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS)) (bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS))
return -EFSCORRUPTED; return -EFSCORRUPTED;
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK), 0, 0, &tp);
if (error)
return error;
budp = xfs_trans_get_bud(tp, buip);
/* Grab the inode. */ /* Grab the inode. */
error = xfs_iget(mp, tp, bmap->me_owner, 0, XFS_ILOCK_EXCL, &ip); error = xfs_iget(mp, NULL, bmap->me_owner, 0, 0, &ip);
if (error) if (error)
goto err_inode; return error;
error = xfs_qm_dqattach_locked(ip, false); error = xfs_qm_dqattach(ip);
if (error) if (error)
goto err_inode; goto err_rele;
if (VFS_I(ip)->i_nlink == 0) if (VFS_I(ip)->i_nlink == 0)
xfs_iflags_set(ip, XFS_IRECOVERY); xfs_iflags_set(ip, XFS_IRECOVERY);
/* Allocate transaction and do the work. */
error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK), 0, 0, &tp);
if (error)
goto err_rele;
budp = xfs_trans_get_bud(tp, buip);
xfs_ilock(ip, XFS_ILOCK_EXCL);
xfs_trans_ijoin(tp, ip, 0); xfs_trans_ijoin(tp, ip, 0);
count = bmap->me_len; count = bmap->me_len;
...@@ -501,7 +502,7 @@ xfs_bui_item_recover( ...@@ -501,7 +502,7 @@ xfs_bui_item_recover(
whichfork, bmap->me_startoff, bmap->me_startblock, whichfork, bmap->me_startoff, bmap->me_startblock,
&count, state); &count, state);
if (error) if (error)
goto err_inode; goto err_cancel;
if (count > 0) { if (count > 0) {
ASSERT(bui_type == XFS_BMAP_UNMAP); ASSERT(bui_type == XFS_BMAP_UNMAP);
...@@ -512,17 +513,21 @@ xfs_bui_item_recover( ...@@ -512,17 +513,21 @@ xfs_bui_item_recover(
xfs_bmap_unmap_extent(tp, ip, &irec); xfs_bmap_unmap_extent(tp, ip, &irec);
} }
/* Commit transaction, which frees the transaction. */
error = xfs_defer_ops_capture_and_commit(tp, capture_list); error = xfs_defer_ops_capture_and_commit(tp, capture_list);
if (error)
goto err_unlock;
xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_iunlock(ip, XFS_ILOCK_EXCL);
xfs_irele(ip); xfs_irele(ip);
return error; return 0;
err_inode: err_cancel:
xfs_trans_cancel(tp); xfs_trans_cancel(tp);
if (ip) { err_unlock:
xfs_iunlock(ip, XFS_ILOCK_EXCL); xfs_iunlock(ip, XFS_ILOCK_EXCL);
err_rele:
xfs_irele(ip); xfs_irele(ip);
}
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