xfs: refactor common transaction/inode/quota allocation idiom

Create a new helper xfs_trans_alloc_inode that allocates a transaction,
locks and joins an inode to it, and then reserves the appropriate amount
of quota against that transction.  Then replace all the open-coded
idioms with a single call to this helper.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Brian Foster <bfoster@redhat.com>
This commit is contained in:
Darrick J. Wong
2021-01-26 16:33:29 -08:00
parent 02b7ee4eb6
commit 3a1af6c317
6 changed files with 59 additions and 38 deletions

View File

@@ -458,14 +458,10 @@ xfs_attr_set(
* Root fork attributes can use reserved data blocks for this
* operation if necessary
*/
error = xfs_trans_alloc(mp, &tres, total, 0,
rsvd ? XFS_TRANS_RESERVE : 0, &args->trans);
error = xfs_trans_alloc_inode(dp, &tres, total, rsvd, &args->trans);
if (error)
return error;
xfs_ilock(dp, XFS_ILOCK_EXCL);
xfs_trans_ijoin(args->trans, dp, 0);
if (args->value || xfs_inode_hasattr(dp)) {
error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK,
XFS_IEXT_ATTR_MANIP_CNT(rmt_blks));
@@ -474,11 +470,6 @@ xfs_attr_set(
}
if (args->value) {
error = xfs_trans_reserve_quota_nblks(args->trans, dp,
args->total, 0, rsvd);
if (error)
goto out_trans_cancel;
error = xfs_has_attr(args);
if (error == -EEXIST && (args->attr_flags & XATTR_CREATE))
goto out_trans_cancel;