Commit f3bf6e0f authored by Dave Chinner's avatar Dave Chinner Committed by Darrick J. Wong

xfs: move xfs_dialloc_roll() into xfs_dialloc()

Get rid of the confusing ialloc_context and failure handling around
xfs_dialloc() by moving xfs_dialloc_roll() into xfs_dialloc().
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Signed-off-by: default avatarGao Xiang <hsiangkao@redhat.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 1abcf261
...@@ -1682,7 +1682,7 @@ xfs_dialloc_ag( ...@@ -1682,7 +1682,7 @@ xfs_dialloc_ag(
return error; return error;
} }
int static int
xfs_dialloc_roll( xfs_dialloc_roll(
struct xfs_trans **tpp, struct xfs_trans **tpp,
struct xfs_buf *agibp) struct xfs_buf *agibp)
...@@ -1723,30 +1723,18 @@ xfs_dialloc_roll( ...@@ -1723,30 +1723,18 @@ xfs_dialloc_roll(
* Mode is used to tell whether the new inode will need space, and whether it * Mode is used to tell whether the new inode will need space, and whether it
* is a directory. * is a directory.
* *
* This function is designed to be called twice if it has to do an allocation
* to make more free inodes. On the first call, *IO_agbp should be set to NULL.
* If an inode is available without having to performn an allocation, an inode
* number is returned. In this case, *IO_agbp is set to NULL. If an allocation
* needs to be done, xfs_dialloc returns the current AGI buffer in *IO_agbp.
* The caller should then commit the current transaction, allocate a
* new transaction, and call xfs_dialloc() again, passing in the previous value
* of *IO_agbp. IO_agbp should be held across the transactions. Since the AGI
* buffer is locked across the two calls, the second call is guaranteed to have
* a free inode available.
*
* Once we successfully pick an inode its number is returned and the on-disk * Once we successfully pick an inode its number is returned and the on-disk
* data structures are updated. The inode itself is not read in, since doing so * data structures are updated. The inode itself is not read in, since doing so
* would break ordering constraints with xfs_reclaim. * would break ordering constraints with xfs_reclaim.
*/ */
int int
xfs_dialloc( xfs_dialloc(
struct xfs_trans *tp, struct xfs_trans **tpp,
xfs_ino_t parent, xfs_ino_t parent,
umode_t mode, umode_t mode,
struct xfs_buf **IO_agbp,
xfs_ino_t *inop) xfs_ino_t *inop)
{ {
struct xfs_mount *mp = tp->t_mountp; struct xfs_mount *mp = (*tpp)->t_mountp;
struct xfs_buf *agbp; struct xfs_buf *agbp;
xfs_agnumber_t agno; xfs_agnumber_t agno;
int error; int error;
...@@ -1757,21 +1745,11 @@ xfs_dialloc( ...@@ -1757,21 +1745,11 @@ xfs_dialloc(
struct xfs_ino_geometry *igeo = M_IGEO(mp); struct xfs_ino_geometry *igeo = M_IGEO(mp);
bool okalloc = true; bool okalloc = true;
if (*IO_agbp) {
/*
* If the caller passes in a pointer to the AGI buffer,
* continue where we left off before. In this case, we
* know that the allocation group has free inodes.
*/
agbp = *IO_agbp;
goto out_alloc;
}
/* /*
* We do not have an agbp, so select an initial allocation * We do not have an agbp, so select an initial allocation
* group for inode allocation. * group for inode allocation.
*/ */
start_agno = xfs_ialloc_ag_select(tp, parent, mode); start_agno = xfs_ialloc_ag_select(*tpp, parent, mode);
if (start_agno == NULLAGNUMBER) { if (start_agno == NULLAGNUMBER) {
*inop = NULLFSINO; *inop = NULLFSINO;
return 0; return 0;
...@@ -1806,7 +1784,7 @@ xfs_dialloc( ...@@ -1806,7 +1784,7 @@ xfs_dialloc(
} }
if (!pag->pagi_init) { if (!pag->pagi_init) {
error = xfs_ialloc_pagi_init(mp, tp, agno); error = xfs_ialloc_pagi_init(mp, *tpp, agno);
if (error) if (error)
goto out_error; goto out_error;
} }
...@@ -1821,7 +1799,7 @@ xfs_dialloc( ...@@ -1821,7 +1799,7 @@ xfs_dialloc(
* Then read in the AGI buffer and recheck with the AGI buffer * Then read in the AGI buffer and recheck with the AGI buffer
* lock held. * lock held.
*/ */
error = xfs_ialloc_read_agi(mp, tp, agno, &agbp); error = xfs_ialloc_read_agi(mp, *tpp, agno, &agbp);
if (error) if (error)
goto out_error; goto out_error;
...@@ -1834,9 +1812,9 @@ xfs_dialloc( ...@@ -1834,9 +1812,9 @@ xfs_dialloc(
goto nextag_relse_buffer; goto nextag_relse_buffer;
error = xfs_ialloc_ag_alloc(tp, agbp, &ialloced); error = xfs_ialloc_ag_alloc(*tpp, agbp, &ialloced);
if (error) { if (error) {
xfs_trans_brelse(tp, agbp); xfs_trans_brelse(*tpp, agbp);
if (error != -ENOSPC) if (error != -ENOSPC)
goto out_error; goto out_error;
...@@ -1848,21 +1826,25 @@ xfs_dialloc( ...@@ -1848,21 +1826,25 @@ xfs_dialloc(
if (ialloced) { if (ialloced) {
/* /*
* We successfully allocated some inodes, return * We successfully allocated space for an inode cluster
* the current context to the caller so that it * in this AG. Roll the transaction so that we can
* can commit the current transaction and call * allocate one of the new inodes.
* us again where we left off.
*/ */
ASSERT(pag->pagi_freecount > 0); ASSERT(pag->pagi_freecount > 0);
xfs_perag_put(pag); xfs_perag_put(pag);
*IO_agbp = agbp; error = xfs_dialloc_roll(tpp, agbp);
if (error) {
xfs_buf_relse(agbp);
return error;
}
*inop = NULLFSINO; *inop = NULLFSINO;
return 0; goto out_alloc;
} }
nextag_relse_buffer: nextag_relse_buffer:
xfs_trans_brelse(tp, agbp); xfs_trans_brelse(*tpp, agbp);
nextag: nextag:
xfs_perag_put(pag); xfs_perag_put(pag);
if (++agno == mp->m_sb.sb_agcount) if (++agno == mp->m_sb.sb_agcount)
...@@ -1874,8 +1856,7 @@ xfs_dialloc( ...@@ -1874,8 +1856,7 @@ xfs_dialloc(
} }
out_alloc: out_alloc:
*IO_agbp = NULL; return xfs_dialloc_ag(*tpp, agbp, parent, inop);
return xfs_dialloc_ag(tp, agbp, parent, inop);
out_error: out_error:
xfs_perag_put(pag); xfs_perag_put(pag);
return error; return error;
......
...@@ -32,39 +32,20 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) ...@@ -32,39 +32,20 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog); return xfs_buf_offset(b, o << (mp)->m_sb.sb_inodelog);
} }
int
xfs_dialloc_roll(
struct xfs_trans **tpp,
struct xfs_buf *agibp);
/* /*
* Allocate an inode on disk. * Allocate an inode on disk.
* Mode is used to tell whether the new inode will need space, and whether * Mode is used to tell whether the new inode will need space, and whether
* it is a directory. * it is a directory.
* *
* To work within the constraint of one allocation per transaction,
* xfs_dialloc() is designed to be called twice if it has to do an
* allocation to make more free inodes. If an inode is
* available without an allocation, agbp would be set to the current
* agbp and alloc_done set to false.
* If an allocation needed to be done, agbp would be set to the
* inode header of the allocation group and alloc_done set to true.
* The caller should then commit the current transaction and allocate a new
* transaction. xfs_dialloc() should then be called again with
* the agbp value returned from the previous call.
*
* Once we successfully pick an inode its number is returned and the * Once we successfully pick an inode its number is returned and the
* on-disk data structures are updated. The inode itself is not read * on-disk data structures are updated. The inode itself is not read
* in, since doing so would break ordering constraints with xfs_reclaim. * in, since doing so would break ordering constraints with xfs_reclaim.
*
* *agbp should be set to NULL on the first call, *alloc_done set to FALSE.
*/ */
int /* error */ int /* error */
xfs_dialloc( xfs_dialloc(
struct xfs_trans *tp, /* transaction pointer */ struct xfs_trans **tpp, /* double pointer of transaction */
xfs_ino_t parent, /* parent inode (directory) */ xfs_ino_t parent, /* parent inode (directory) */
umode_t mode, /* mode bits for new inode */ umode_t mode, /* mode bits for new inode */
struct xfs_buf **agbp, /* buf for a.g. inode header */
xfs_ino_t *inop); /* inode number allocated */ xfs_ino_t *inop); /* inode number allocated */
/* /*
......
...@@ -909,7 +909,6 @@ xfs_dir_ialloc( ...@@ -909,7 +909,6 @@ xfs_dir_ialloc(
prid_t prid, prid_t prid,
struct xfs_inode **ipp) struct xfs_inode **ipp)
{ {
struct xfs_buf *ialloc_context = NULL;
xfs_ino_t parent_ino = dp ? dp->i_ino : 0; xfs_ino_t parent_ino = dp ? dp->i_ino : 0;
xfs_ino_t ino; xfs_ino_t ino;
int error; int error;
...@@ -918,43 +917,12 @@ xfs_dir_ialloc( ...@@ -918,43 +917,12 @@ xfs_dir_ialloc(
/* /*
* Call the space management code to pick the on-disk inode to be * Call the space management code to pick the on-disk inode to be
* allocated and replenish the freelist. Since we can only do one * allocated.
* allocation per transaction without deadlocks, we will need to */
* commit the current transaction and start a new one. error = xfs_dialloc(tpp, parent_ino, mode, &ino);
* If xfs_dialloc did an allocation to replenish the freelist, it
* returns the bp containing the head of the freelist as
* ialloc_context. We will hold a lock on it across the transaction
* commit so that no other process can steal the inode(s) that we've
* just allocated.
*/
error = xfs_dialloc(*tpp, parent_ino, mode, &ialloc_context, &ino);
if (error) if (error)
return error; return error;
/*
* If the AGI buffer is non-NULL, then we were unable to get an
* inode in one operation. We need to commit the current
* transaction and call xfs_dialloc() again. It is guaranteed
* to succeed the second time.
*/
if (ialloc_context) {
error = xfs_dialloc_roll(tpp, ialloc_context);
if (error) {
xfs_buf_relse(ialloc_context);
return error;
}
/*
* Call dialloc again. Since we've locked out all other
* allocations in this allocation group, this call should
* always succeed.
*/
error = xfs_dialloc(*tpp, parent_ino, mode, &ialloc_context,
&ino);
if (error)
return error;
ASSERT(!ialloc_context);
}
if (ino == NULLFSINO) if (ino == NULLFSINO)
return -ENOSPC; return -ENOSPC;
......
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