Skip to content

Commit

Permalink
xfs: clean up xfs_bui_item_recover iget/trans_alloc/ilock ordering
Browse files Browse the repository at this point in the history
commit 64a3f33 upstream.

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>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
Acked-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
djwong authored and gregkh committed Feb 22, 2023
1 parent abad319 commit efcdc2e
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions fs/xfs/xfs_bmap_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "xfs_bmap_btree.h"
#include "xfs_trans_space.h"
#include "xfs_error.h"
#include "xfs_quota.h"

kmem_zone_t *xfs_bui_zone;
kmem_zone_t *xfs_bud_zone;
Expand Down Expand Up @@ -488,29 +489,34 @@ xfs_bui_recover(
return -EFSCORRUPTED;
}

error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK), 0, 0, &tp);
/* Grab the inode. */
error = xfs_iget(mp, NULL, bmap->me_owner, 0, 0, &ip);
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_qm_dqattach(ip);
if (error)
goto err_inode;
goto err_rele;

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;
error = xfs_trans_log_finish_bmap_update(tp, budp, bui_type, ip,
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);
Expand All @@ -522,16 +528,20 @@ xfs_bui_recover(
}

set_bit(XFS_BUI_RECOVERED, &buip->bui_flags);
/* Commit transaction, which frees the transaction. */
error = xfs_defer_ops_capture_and_commit(tp, capture_list);
if (error)
goto err_unlock;

xfs_iunlock(ip, XFS_ILOCK_EXCL);
xfs_irele(ip);
return error;
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;
}

0 comments on commit efcdc2e

Please sign in to comment.