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

xfs: spilt xfs_dialloc() into 2 functions

This patch explicitly separates free inode chunk allocation and
inode allocation into two individual high level operations.
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 f3bf6e0f
...@@ -1570,7 +1570,7 @@ xfs_dialloc_ag_update_inobt( ...@@ -1570,7 +1570,7 @@ xfs_dialloc_ag_update_inobt(
* The caller selected an AG for us, and made sure that free inodes are * The caller selected an AG for us, and made sure that free inodes are
* available. * available.
*/ */
STATIC int int
xfs_dialloc_ag( xfs_dialloc_ag(
struct xfs_trans *tp, struct xfs_trans *tp,
struct xfs_buf *agbp, struct xfs_buf *agbp,
...@@ -1718,21 +1718,22 @@ xfs_dialloc_roll( ...@@ -1718,21 +1718,22 @@ xfs_dialloc_roll(
} }
/* /*
* Allocate an inode on disk. * Select and prepare an AG for inode allocation.
* *
* Mode is used to tell whether the new inode will need space, and whether it * Mode is used to tell whether the new inode is a directory and hence where to
* is a directory. * locate it.
* *
* Once we successfully pick an inode its number is returned and the on-disk * This function will ensure that the selected AG has free inodes available to
* data structures are updated. The inode itself is not read in, since doing so * allocate from. The selected AGI will be returned locked to the caller, and it
* would break ordering constraints with xfs_reclaim. * will allocate more free inodes if required. If no free inodes are found or
* can be allocated, no AGI will be returned.
*/ */
int int
xfs_dialloc( xfs_dialloc_select_ag(
struct xfs_trans **tpp, struct xfs_trans **tpp,
xfs_ino_t parent, xfs_ino_t parent,
umode_t mode, umode_t mode,
xfs_ino_t *inop) struct xfs_buf **IO_agbp)
{ {
struct xfs_mount *mp = (*tpp)->t_mountp; struct xfs_mount *mp = (*tpp)->t_mountp;
struct xfs_buf *agbp; struct xfs_buf *agbp;
...@@ -1745,15 +1746,15 @@ xfs_dialloc( ...@@ -1745,15 +1746,15 @@ xfs_dialloc(
struct xfs_ino_geometry *igeo = M_IGEO(mp); struct xfs_ino_geometry *igeo = M_IGEO(mp);
bool okalloc = true; bool okalloc = true;
*IO_agbp = NULL;
/* /*
* 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(*tpp, parent, mode); start_agno = xfs_ialloc_ag_select(*tpp, parent, mode);
if (start_agno == NULLAGNUMBER) { if (start_agno == NULLAGNUMBER)
*inop = NULLFSINO;
return 0; return 0;
}
/* /*
* If we have already hit the ceiling of inode blocks then clear * If we have already hit the ceiling of inode blocks then clear
...@@ -1786,7 +1787,7 @@ xfs_dialloc( ...@@ -1786,7 +1787,7 @@ xfs_dialloc(
if (!pag->pagi_init) { if (!pag->pagi_init) {
error = xfs_ialloc_pagi_init(mp, *tpp, agno); error = xfs_ialloc_pagi_init(mp, *tpp, agno);
if (error) if (error)
goto out_error; break;
} }
/* /*
...@@ -1801,11 +1802,11 @@ xfs_dialloc( ...@@ -1801,11 +1802,11 @@ xfs_dialloc(
*/ */
error = xfs_ialloc_read_agi(mp, *tpp, agno, &agbp); error = xfs_ialloc_read_agi(mp, *tpp, agno, &agbp);
if (error) if (error)
goto out_error; break;
if (pag->pagi_freecount) { if (pag->pagi_freecount) {
xfs_perag_put(pag); xfs_perag_put(pag);
goto out_alloc; goto found_ag;
} }
if (!okalloc) if (!okalloc)
...@@ -1816,12 +1817,9 @@ xfs_dialloc( ...@@ -1816,12 +1817,9 @@ xfs_dialloc(
if (error) { if (error) {
xfs_trans_brelse(*tpp, agbp); xfs_trans_brelse(*tpp, agbp);
if (error != -ENOSPC) if (error == -ENOSPC)
goto out_error; error = 0;
break;
xfs_perag_put(pag);
*inop = NULLFSINO;
return 0;
} }
if (ialloced) { if (ialloced) {
...@@ -1838,9 +1836,7 @@ xfs_dialloc( ...@@ -1838,9 +1836,7 @@ xfs_dialloc(
xfs_buf_relse(agbp); xfs_buf_relse(agbp);
return error; return error;
} }
goto found_ag;
*inop = NULLFSINO;
goto out_alloc;
} }
nextag_relse_buffer: nextag_relse_buffer:
...@@ -1849,17 +1845,15 @@ xfs_dialloc( ...@@ -1849,17 +1845,15 @@ xfs_dialloc(
xfs_perag_put(pag); xfs_perag_put(pag);
if (++agno == mp->m_sb.sb_agcount) if (++agno == mp->m_sb.sb_agcount)
agno = 0; agno = 0;
if (agno == start_agno) { if (agno == start_agno)
*inop = NULLFSINO;
return noroom ? -ENOSPC : 0; return noroom ? -ENOSPC : 0;
}
} }
out_alloc:
return xfs_dialloc_ag(*tpp, agbp, parent, inop);
out_error:
xfs_perag_put(pag); xfs_perag_put(pag);
return error; return error;
found_ag:
*IO_agbp = agbp;
return 0;
} }
/* /*
......
...@@ -37,16 +37,26 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) ...@@ -37,16 +37,26 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
* 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.
* *
* Once we successfully pick an inode its number is returned and the * There are two phases to inode allocation: selecting an AG and ensuring
* on-disk data structures are updated. The inode itself is not read * that it contains free inodes, followed by allocating one of the free
* in, since doing so would break ordering constraints with xfs_reclaim. * inodes. xfs_dialloc_select_ag() does the former and returns a locked AGI
* to the caller, ensuring that followup call to xfs_dialloc_ag() will
* have free inodes to allocate from. xfs_dialloc_ag() will return the inode
* number of the free inode we allocated.
*/ */
int /* error */ int /* error */
xfs_dialloc( xfs_dialloc_select_ag(
struct xfs_trans **tpp, /* double pointer of transaction */ 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 */
xfs_ino_t *inop); /* inode number allocated */ struct xfs_buf **IO_agbp);
int
xfs_dialloc_ag(
struct xfs_trans *tp,
struct xfs_buf *agbp,
xfs_ino_t parent,
xfs_ino_t *inop);
/* /*
* Free disk inode. Carefully avoids touching the incore inode, all * Free disk inode. Carefully avoids touching the incore inode, all
......
...@@ -909,6 +909,7 @@ xfs_dir_ialloc( ...@@ -909,6 +909,7 @@ xfs_dir_ialloc(
prid_t prid, prid_t prid,
struct xfs_inode **ipp) struct xfs_inode **ipp)
{ {
struct xfs_buf *agibp;
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;
...@@ -919,13 +920,19 @@ xfs_dir_ialloc( ...@@ -919,13 +920,19 @@ 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. * allocated.
*/ */
error = xfs_dialloc(tpp, parent_ino, mode, &ino); error = xfs_dialloc_select_ag(tpp, parent_ino, mode, &agibp);
if (error) if (error)
return error; return error;
if (ino == NULLFSINO) if (!agibp)
return -ENOSPC; return -ENOSPC;
/* Allocate an inode from the selected AG */
error = xfs_dialloc_ag(*tpp, agibp, parent_ino, &ino);
if (error)
return error;
ASSERT(ino != NULLFSINO);
return xfs_init_new_inode(*tpp, dp, ino, mode, nlink, rdev, prid, ipp); return xfs_init_new_inode(*tpp, dp, ino, mode, nlink, rdev, prid, ipp);
} }
......
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