summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-05-21 12:04:40 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-06-24 18:12:16 -0700
commit63407afb55f8b501ab3c01cc2d97c3693ca5097d (patch)
treec7542fb8bce0190fd38a427969664cac06371fdc
parent2379832160ee32d3ca3b0d51e89d9b1d42367cfc (diff)
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: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/xfs_bmap_item.c38
1 files changed, 20 insertions, 18 deletions
diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c
index eca3a2108e49..52c273b6d403 100644
--- a/fs/xfs/xfs_bmap_item.c
+++ b/fs/xfs/xfs_bmap_item.c
@@ -474,21 +474,22 @@ xfs_bui_item_recover(
(bmap->me_flags & ~XFS_BMAP_EXTENT_FLAGS))
goto garbage;
- 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. */
- 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)
- goto err_inode;
+ return error;
if (VFS_I(ip)->i_nlink == 0)
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);
count = bmap->me_len;
@@ -496,7 +497,7 @@ xfs_bui_item_recover(
whichfork, bmap->me_startoff, bmap->me_startblock,
&count, state);
if (error)
- goto err_inode;
+ goto err_cancel;
if (count > 0) {
ASSERT(bui_type == XFS_BMAP_UNMAP);
@@ -507,17 +508,18 @@ xfs_bui_item_recover(
xfs_bmap_unmap_extent(tp, ip, &irec);
}
+ /* Commit transaction, which frees tp. */
error = xlog_recover_trans_commit(tp, dfcp);
- xfs_iunlock(ip, XFS_ILOCK_EXCL);
- xfs_irele(ip);
- return error;
+ if (error)
+ goto err_unlock;
+ return 0;
-err_inode:
+err_cancel:
xfs_trans_cancel(tp);
- if (ip) {
- xfs_iunlock(ip, XFS_ILOCK_EXCL);
- xfs_irele(ip);
- }
+err_unlock:
+ xfs_iunlock(ip, XFS_ILOCK_EXCL);
+err_rele:
+ xfs_irele(ip);
return error;
garbage:
xfs_bui_release(buip);