diff options
author | Darrick J. Wong <djwong@kernel.org> | 2024-07-02 11:22:39 -0700 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2024-07-02 11:36:57 -0700 |
commit | c0223b8d66d2b3e8fed86fd80699ef2fef3e53af (patch) | |
tree | e31938ee05e5a598cc51d6bc8eb311e40f1dbfec /fs/xfs/xfs_inode.c | |
parent | dfaf884233ba726bf389cbf6f629b3a3a7a93923 (diff) |
xfs: wrap inode creation dqalloc calls
Create a helper that calls dqalloc to allocate and grab a reference to
dquots for the user, group, and project ids listed in an icreate
structure. This simplifies the creat-related dqalloc callsites
scattered around the code base.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/xfs_inode.c')
-rw-r--r-- | fs/xfs/xfs_inode.c | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 0b4f6cf72bae..5848f7b36cc5 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -728,6 +728,38 @@ xfs_dir_hook_setup( } #endif /* CONFIG_XFS_LIVE_HOOKS */ +/* Return dquots for the ids that will be assigned to a new file. */ +int +xfs_icreate_dqalloc( + const struct xfs_icreate_args *args, + struct xfs_dquot **udqpp, + struct xfs_dquot **gdqpp, + struct xfs_dquot **pdqpp) +{ + struct inode *dir = VFS_I(args->pip); + kuid_t uid = GLOBAL_ROOT_UID; + kgid_t gid = GLOBAL_ROOT_GID; + prid_t prid = 0; + unsigned int flags = XFS_QMOPT_QUOTALL; + + if (args->idmap) { + /* + * The uid/gid computation code must match what the VFS uses to + * assign i_[ug]id. INHERIT adjusts the gid computation for + * setgid/grpid systems. + */ + uid = mapped_fsuid(args->idmap, i_user_ns(dir)); + gid = mapped_fsgid(args->idmap, i_user_ns(dir)); + prid = xfs_get_initial_prid(args->pip); + flags |= XFS_QMOPT_INHERIT; + } + + *udqpp = *gdqpp = *pdqpp = NULL; + + return xfs_qm_vop_dqalloc(args->pip, uid, gid, prid, flags, udqpp, + gdqpp, pdqpp); +} + int xfs_create( const struct xfs_icreate_args *args, @@ -738,13 +770,12 @@ xfs_create( struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; - struct xfs_dquot *udqp = NULL; - struct xfs_dquot *gdqp = NULL; - struct xfs_dquot *pdqp = NULL; + struct xfs_dquot *udqp; + struct xfs_dquot *gdqp; + struct xfs_dquot *pdqp; struct xfs_trans_res *tres; struct xfs_parent_args *ppargs; xfs_ino_t ino; - prid_t prid; bool unlock_dp_on_error = false; bool is_dir = S_ISDIR(args->mode); uint resblks; @@ -757,18 +788,8 @@ xfs_create( if (xfs_ifork_zapped(dp, XFS_DATA_FORK)) return -EIO; - prid = xfs_get_initial_prid(dp); - - /* - * Make sure that we have allocated dquot(s) on disk. The uid/gid - * computation code must match what the VFS uses to assign i_[ug]id. - * INHERIT adjusts the gid computation for setgid/grpid systems. - */ - error = xfs_qm_vop_dqalloc(dp, - mapped_fsuid(args->idmap, i_user_ns(VFS_I(dp))), - mapped_fsgid(args->idmap, i_user_ns(VFS_I(dp))), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + /* Make sure that we have allocated dquot(s) on disk. */ + error = xfs_icreate_dqalloc(args, &udqp, &gdqp, &pdqp); if (error) return error; @@ -920,12 +941,11 @@ xfs_create_tmpfile( struct xfs_mount *mp = dp->i_mount; struct xfs_inode *ip = NULL; struct xfs_trans *tp = NULL; - struct xfs_dquot *udqp = NULL; - struct xfs_dquot *gdqp = NULL; - struct xfs_dquot *pdqp = NULL; + struct xfs_dquot *udqp; + struct xfs_dquot *gdqp; + struct xfs_dquot *pdqp; struct xfs_trans_res *tres; xfs_ino_t ino; - prid_t prid; uint resblks; int error; @@ -934,18 +954,8 @@ xfs_create_tmpfile( if (xfs_is_shutdown(mp)) return -EIO; - prid = xfs_get_initial_prid(dp); - - /* - * Make sure that we have allocated dquot(s) on disk. The uid/gid - * computation code must match what the VFS uses to assign i_[ug]id. - * INHERIT adjusts the gid computation for setgid/grpid systems. - */ - error = xfs_qm_vop_dqalloc(dp, - mapped_fsuid(args->idmap, i_user_ns(VFS_I(dp))), - mapped_fsgid(args->idmap, i_user_ns(VFS_I(dp))), prid, - XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, - &udqp, &gdqp, &pdqp); + /* Make sure that we have allocated dquot(s) on disk. */ + error = xfs_icreate_dqalloc(args, &udqp, &gdqp, &pdqp); if (error) return error; |