Skip to content

Commit aececc9

Browse files
Dave Chinnerdjwong
authored andcommitted
xfs: introduce xfs_dialloc_roll()
Introduce a helper to make the on-disk inode allocation rolling logic clearer in preparation of the following cleanup. Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Gao Xiang <hsiangkao@redhat.com> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
1 parent 15574eb commit aececc9

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

fs/xfs/libxfs/xfs_ialloc.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,6 +1682,41 @@ xfs_dialloc_ag(
16821682
return error;
16831683
}
16841684

1685+
int
1686+
xfs_dialloc_roll(
1687+
struct xfs_trans **tpp,
1688+
struct xfs_buf *agibp)
1689+
{
1690+
struct xfs_trans *tp = *tpp;
1691+
struct xfs_dquot_acct *dqinfo;
1692+
int error;
1693+
1694+
/*
1695+
* Hold to on to the agibp across the commit so no other allocation can
1696+
* come in and take the free inodes we just allocated for our caller.
1697+
*/
1698+
xfs_trans_bhold(tp, agibp);
1699+
1700+
/*
1701+
* We want the quota changes to be associated with the next transaction,
1702+
* NOT this one. So, detach the dqinfo from this and attach it to the
1703+
* next transaction.
1704+
*/
1705+
dqinfo = tp->t_dqinfo;
1706+
tp->t_dqinfo = NULL;
1707+
1708+
error = xfs_trans_roll(&tp);
1709+
1710+
/* Re-attach the quota info that we detached from prev trx. */
1711+
tp->t_dqinfo = dqinfo;
1712+
1713+
*tpp = tp;
1714+
if (error)
1715+
return error;
1716+
xfs_trans_bjoin(tp, agibp);
1717+
return 0;
1718+
}
1719+
16851720
/*
16861721
* Allocate an inode on disk.
16871722
*

fs/xfs/libxfs/xfs_ialloc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
3232
return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog);
3333
}
3434

35+
int
36+
xfs_dialloc_roll(
37+
struct xfs_trans **tpp,
38+
struct xfs_buf *agibp);
39+
3540
/*
3641
* Allocate an inode on disk.
3742
* Mode is used to tell whether the new inode will need space, and whether

fs/xfs/xfs_inode.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,6 @@ xfs_dir_ialloc(
958958
xfs_inode_t *ip;
959959
xfs_buf_t *ialloc_context = NULL;
960960
int code;
961-
void *dqinfo;
962961

963962
tp = *tpp;
964963
ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
@@ -1002,41 +1001,13 @@ xfs_dir_ialloc(
10021001
* to succeed the second time.
10031002
*/
10041003
if (ialloc_context) {
1005-
/*
1006-
* Normally, xfs_trans_commit releases all the locks.
1007-
* We call bhold to hang on to the ialloc_context across
1008-
* the commit. Holding this buffer prevents any other
1009-
* processes from doing any allocations in this
1010-
* allocation group.
1011-
*/
1012-
xfs_trans_bhold(tp, ialloc_context);
1013-
1014-
/*
1015-
* We want the quota changes to be associated with the next
1016-
* transaction, NOT this one. So, detach the dqinfo from this
1017-
* and attach it to the next transaction.
1018-
*/
1019-
dqinfo = NULL;
1020-
if (tp->t_dqinfo) {
1021-
dqinfo = (void *)tp->t_dqinfo;
1022-
tp->t_dqinfo = NULL;
1023-
}
1024-
1025-
code = xfs_trans_roll(&tp);
1026-
1027-
/*
1028-
* Re-attach the quota info that we detached from prev trx.
1029-
*/
1030-
if (dqinfo)
1031-
tp->t_dqinfo = dqinfo;
1032-
1004+
code = xfs_dialloc_roll(&tp, ialloc_context);
10331005
if (code) {
10341006
xfs_buf_relse(ialloc_context);
10351007
*tpp = tp;
10361008
*ipp = NULL;
10371009
return code;
10381010
}
1039-
xfs_trans_bjoin(tp, ialloc_context);
10401011

10411012
/*
10421013
* Call ialloc again. Since we've locked out all

0 commit comments

Comments
 (0)