Commit b652afd9 authored by Dave Chinner's avatar Dave Chinner Committed by Dave Chinner

xfs: get rid of xfs_dir_ialloc()

This is just a simple wrapper around the per-ag inode allocation
that doesn't need to exist. The internal mechanism to select and
allocate within an AG does not need to be exposed outside
xfs_ialloc.c, and it being exposed simply makes it harder to follow
the code and simplify it.

This is simplified by internalising xf_dialloc_select_ag() and
xfs_dialloc_ag() into a single xfs_dialloc() function and then
xfs_dir_ialloc() can go away.
Signed-off-by: default avatarDave Chinner <dchinner@redhat.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
Reviewed-by: default avatarDarrick J. Wong <djwong@kernel.org>
parent 89b1f55a
...@@ -1428,7 +1428,7 @@ xfs_dialloc_ag_update_inobt( ...@@ -1428,7 +1428,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.
*/ */
int static int
xfs_dialloc_ag( xfs_dialloc_ag(
struct xfs_trans *tp, struct xfs_trans *tp,
struct xfs_buf *agbp, struct xfs_buf *agbp,
...@@ -1602,24 +1602,23 @@ xfs_ialloc_next_ag( ...@@ -1602,24 +1602,23 @@ xfs_ialloc_next_ag(
* can be allocated, -ENOSPC be returned. * can be allocated, -ENOSPC be returned.
*/ */
int int
xfs_dialloc_select_ag( xfs_dialloc(
struct xfs_trans **tpp, 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 *new_ino)
{ {
struct xfs_mount *mp = (*tpp)->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 = 0;
xfs_agnumber_t start_agno; xfs_agnumber_t start_agno;
struct xfs_perag *pag; struct xfs_perag *pag;
struct xfs_ino_geometry *igeo = M_IGEO(mp); struct xfs_ino_geometry *igeo = M_IGEO(mp);
bool okalloc = true; bool okalloc = true;
int needspace; int needspace;
int flags; int flags;
xfs_ino_t ino;
*IO_agbp = NULL;
/* /*
* Directories, symlinks, and regular files frequently allocate at least * Directories, symlinks, and regular files frequently allocate at least
...@@ -1765,7 +1764,11 @@ xfs_dialloc_select_ag( ...@@ -1765,7 +1764,11 @@ xfs_dialloc_select_ag(
return error ? error : -ENOSPC; return error ? error : -ENOSPC;
found_ag: found_ag:
xfs_perag_put(pag); xfs_perag_put(pag);
*IO_agbp = agbp; /* Allocate an inode in the found AG */
error = xfs_dialloc_ag(*tpp, agbp, parent, &ino);
if (error)
return error;
*new_ino = ino;
return 0; return 0;
} }
......
...@@ -33,30 +33,11 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o) ...@@ -33,30 +33,11 @@ xfs_make_iptr(struct xfs_mount *mp, struct xfs_buf *b, int o)
} }
/* /*
* Allocate an inode on disk. * Allocate an inode on disk. Mode is used to tell whether the new inode will
* Mode is used to tell whether the new inode will need space, and whether * need space, and whether it is a directory.
* it is a directory.
*
* There are two phases to inode allocation: selecting an AG and ensuring
* that it contains free inodes, followed by allocating one of the free
* 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 xfs_dialloc(struct xfs_trans **tpp, xfs_ino_t parent, umode_t mode,
xfs_dialloc_select_ag( xfs_ino_t *new_ino);
struct xfs_trans **tpp, /* double pointer of transaction */
xfs_ino_t parent, /* parent inode (directory) */
umode_t mode, /* mode bits for new inode */
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
......
...@@ -749,7 +749,7 @@ xfs_inode_inherit_flags2( ...@@ -749,7 +749,7 @@ xfs_inode_inherit_flags2(
* Initialise a newly allocated inode and return the in-core inode to the * Initialise a newly allocated inode and return the in-core inode to the
* caller locked exclusively. * caller locked exclusively.
*/ */
static int int
xfs_init_new_inode( xfs_init_new_inode(
struct user_namespace *mnt_userns, struct user_namespace *mnt_userns,
struct xfs_trans *tp, struct xfs_trans *tp,
...@@ -885,54 +885,6 @@ xfs_init_new_inode( ...@@ -885,54 +885,6 @@ xfs_init_new_inode(
return 0; return 0;
} }
/*
* Allocates a new inode from disk and return a pointer to the incore copy. This
* routine will internally commit the current transaction and allocate a new one
* if we needed to allocate more on-disk free inodes to perform the requested
* operation.
*
* If we are allocating quota inodes, we do not have a parent inode to attach to
* or associate with (i.e. dp == NULL) because they are not linked into the
* directory structure - they are attached directly to the superblock - and so
* have no parent.
*/
int
xfs_dir_ialloc(
struct user_namespace *mnt_userns,
struct xfs_trans **tpp,
struct xfs_inode *dp,
umode_t mode,
xfs_nlink_t nlink,
dev_t rdev,
prid_t prid,
bool init_xattrs,
struct xfs_inode **ipp)
{
struct xfs_buf *agibp;
xfs_ino_t parent_ino = dp ? dp->i_ino : 0;
xfs_ino_t ino;
int error;
ASSERT((*tpp)->t_flags & XFS_TRANS_PERM_LOG_RES);
/*
* Call the space management code to pick the on-disk inode to be
* allocated.
*/
error = xfs_dialloc_select_ag(tpp, parent_ino, mode, &agibp);
if (error)
return error;
/* 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(mnt_userns, *tpp, dp, ino, mode, nlink, rdev,
prid, init_xattrs, ipp);
}
/* /*
* Decrement the link count on an inode & log the change. If this causes the * Decrement the link count on an inode & log the change. If this causes the
* link count to go to zero, move the inode to AGI unlinked list so that it can * link count to go to zero, move the inode to AGI unlinked list so that it can
...@@ -990,6 +942,7 @@ xfs_create( ...@@ -990,6 +942,7 @@ xfs_create(
struct xfs_dquot *pdqp = NULL; struct xfs_dquot *pdqp = NULL;
struct xfs_trans_res *tres; struct xfs_trans_res *tres;
uint resblks; uint resblks;
xfs_ino_t ino;
trace_xfs_create(dp, name); trace_xfs_create(dp, name);
...@@ -1046,14 +999,16 @@ xfs_create( ...@@ -1046,14 +999,16 @@ xfs_create(
* entry pointing to them, but a directory also the "." entry * entry pointing to them, but a directory also the "." entry
* pointing to itself. * pointing to itself.
*/ */
error = xfs_dir_ialloc(mnt_userns, &tp, dp, mode, is_dir ? 2 : 1, rdev, error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
prid, init_xattrs, &ip); if (!error)
error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,
is_dir ? 2 : 1, rdev, prid, init_xattrs, &ip);
if (error) if (error)
goto out_trans_cancel; goto out_trans_cancel;
/* /*
* Now we join the directory inode to the transaction. We do not do it * Now we join the directory inode to the transaction. We do not do it
* earlier because xfs_dir_ialloc might commit the previous transaction * earlier because xfs_dialloc might commit the previous transaction
* (and release all the locks). An error from here on will result in * (and release all the locks). An error from here on will result in
* the transaction cancel unlocking dp so don't do it explicitly in the * the transaction cancel unlocking dp so don't do it explicitly in the
* error path. * error path.
...@@ -1143,6 +1098,7 @@ xfs_create_tmpfile( ...@@ -1143,6 +1098,7 @@ xfs_create_tmpfile(
struct xfs_dquot *pdqp = NULL; struct xfs_dquot *pdqp = NULL;
struct xfs_trans_res *tres; struct xfs_trans_res *tres;
uint resblks; uint resblks;
xfs_ino_t ino;
if (XFS_FORCED_SHUTDOWN(mp)) if (XFS_FORCED_SHUTDOWN(mp))
return -EIO; return -EIO;
...@@ -1167,8 +1123,10 @@ xfs_create_tmpfile( ...@@ -1167,8 +1123,10 @@ xfs_create_tmpfile(
if (error) if (error)
goto out_release_dquots; goto out_release_dquots;
error = xfs_dir_ialloc(mnt_userns, &tp, dp, mode, 0, 0, prid, error = xfs_dialloc(&tp, dp->i_ino, mode, &ino);
false, &ip); if (!error)
error = xfs_init_new_inode(mnt_userns, tp, dp, ino, mode,
0, 0, prid, false, &ip);
if (error) if (error)
goto out_trans_cancel; goto out_trans_cancel;
......
...@@ -431,10 +431,9 @@ void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode, ...@@ -431,10 +431,9 @@ void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode,
xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip); xfs_extlen_t xfs_get_extsz_hint(struct xfs_inode *ip);
xfs_extlen_t xfs_get_cowextsz_hint(struct xfs_inode *ip); xfs_extlen_t xfs_get_cowextsz_hint(struct xfs_inode *ip);
int xfs_dir_ialloc(struct user_namespace *mnt_userns, int xfs_init_new_inode(struct user_namespace *mnt_userns, struct xfs_trans *tp,
struct xfs_trans **tpp, struct xfs_inode *dp, struct xfs_inode *pip, xfs_ino_t ino, umode_t mode,
umode_t mode, xfs_nlink_t nlink, dev_t dev, xfs_nlink_t nlink, dev_t rdev, prid_t prid, bool init_xattrs,
prid_t prid, bool need_xattr,
struct xfs_inode **ipp); struct xfs_inode **ipp);
static inline int static inline int
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "xfs_icache.h" #include "xfs_icache.h"
#include "xfs_error.h" #include "xfs_error.h"
#include "xfs_ag.h" #include "xfs_ag.h"
#include "xfs_ialloc.h"
/* /*
* The global quota manager. There is only one of these for the entire * The global quota manager. There is only one of these for the entire
...@@ -788,8 +789,12 @@ xfs_qm_qino_alloc( ...@@ -788,8 +789,12 @@ xfs_qm_qino_alloc(
return error; return error;
if (need_alloc) { if (need_alloc) {
error = xfs_dir_ialloc(&init_user_ns, &tp, NULL, S_IFREG, 1, 0, xfs_ino_t ino;
0, false, ipp);
error = xfs_dialloc(&tp, 0, S_IFREG, &ino);
if (!error)
error = xfs_init_new_inode(&init_user_ns, tp, NULL, ino,
S_IFREG, 1, 0, 0, false, ipp);
if (error) { if (error) {
xfs_trans_cancel(tp); xfs_trans_cancel(tp);
return error; return error;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "xfs_trans_space.h" #include "xfs_trans_space.h"
#include "xfs_trace.h" #include "xfs_trace.h"
#include "xfs_trans.h" #include "xfs_trans.h"
#include "xfs_ialloc.h"
/* ----- Kernel only functions below ----- */ /* ----- Kernel only functions below ----- */
int int
...@@ -161,6 +162,7 @@ xfs_symlink( ...@@ -161,6 +162,7 @@ xfs_symlink(
struct xfs_dquot *gdqp = NULL; struct xfs_dquot *gdqp = NULL;
struct xfs_dquot *pdqp = NULL; struct xfs_dquot *pdqp = NULL;
uint resblks; uint resblks;
xfs_ino_t ino;
*ipp = NULL; *ipp = NULL;
...@@ -223,8 +225,11 @@ xfs_symlink( ...@@ -223,8 +225,11 @@ xfs_symlink(
/* /*
* Allocate an inode for the symlink. * Allocate an inode for the symlink.
*/ */
error = xfs_dir_ialloc(mnt_userns, &tp, dp, S_IFLNK | (mode & ~S_IFMT), error = xfs_dialloc(&tp, dp->i_ino, S_IFLNK, &ino);
1, 0, prid, false, &ip); if (!error)
error = xfs_init_new_inode(mnt_userns, tp, dp, ino,
S_IFLNK | (mode & ~S_IFMT), 1, 0, prid,
false, &ip);
if (error) if (error)
goto out_trans_cancel; goto out_trans_cancel;
......
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