From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: darrick.wong@oracle.com
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 10/21] xfs: push xfs_ialloc_args creation out of xfs_dir_ialloc
Date: Tue, 31 Dec 2019 17:13:38 -0800 [thread overview]
Message-ID: <157784121815.1365473.16418584721128229029.stgit@magnolia> (raw)
In-Reply-To: <157784115560.1365473.15056496428451670757.stgit@magnolia>
From: Darrick J. Wong <darrick.wong@oracle.com>
Move the initialization of the xfs_ialloc_args structure out of
xfs_dir_ialloc into its callers' callers so that we can set the new
inode's parameters in one place and pass it through instead of open
coding the new uid/gid/prid all over the code. This also prepares us
for moving xfs_dir_ialloc and xfs_create to libxfs.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fs/xfs/xfs_inode.c | 131 +++++++++++++++++++++++---------------------------
fs/xfs/xfs_inode.h | 10 ++--
fs/xfs/xfs_iops.c | 44 ++++++++++-------
fs/xfs/xfs_qm.c | 6 ++
fs/xfs/xfs_symlink.c | 17 ++++--
5 files changed, 107 insertions(+), 101 deletions(-)
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index 00547fdf7c15..eef85fbb6102 100644
--- a/fs/xfs/xfs_inode.c
+++ b/fs/xfs/xfs_inode.c
@@ -644,32 +644,16 @@ xfs_ialloc_iget(
*/
int
xfs_dir_ialloc(
- xfs_trans_t **tpp, /* input: current transaction;
- output: may be a new transaction. */
- xfs_inode_t *dp, /* directory within whose allocate
- the inode. */
- umode_t mode,
- xfs_nlink_t nlink,
- dev_t rdev,
- prid_t prid, /* project id */
- xfs_inode_t **ipp) /* pointer to inode; it will be
- locked. */
+ struct xfs_trans **tpp,
+ const struct xfs_ialloc_args *args,
+ struct xfs_inode **ipp)
{
- struct xfs_ialloc_args args = {
- .pip = dp,
- .uid = xfs_kuid_to_uid(current_fsuid()),
- .gid = xfs_kgid_to_gid(current_fsgid()),
- .prid = prid,
- .nlink = nlink,
- .rdev = rdev,
- .mode = mode,
- };
- xfs_trans_t *tp;
- xfs_inode_t *ip;
- xfs_buf_t *ialloc_context = NULL;
- int code;
- void *dqinfo;
- uint tflags;
+ struct xfs_trans *tp;
+ struct xfs_inode *ip;
+ struct xfs_buf *ialloc_context = NULL;
+ void *dqinfo;
+ uint tflags;
+ int code;
tp = *tpp;
ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
@@ -689,7 +673,7 @@ xfs_dir_ialloc(
* transaction commit so that no other process can steal
* the inode(s) that we've just allocated.
*/
- code = xfs_ialloc(tp, &args, &ialloc_context, &ip);
+ code = xfs_ialloc(tp, args, &ialloc_context, &ip);
/*
* Return an error if we were unable to allocate a new inode.
@@ -758,7 +742,7 @@ xfs_dir_ialloc(
* other allocations in this allocation group,
* this call should always succeed.
*/
- code = xfs_ialloc(tp, &args, &ialloc_context, &ip);
+ code = xfs_ialloc(tp, args, &ialloc_context, &ip);
/*
* If we get an error at this point, return to the caller
@@ -817,38 +801,34 @@ xfs_bumplink(
int
xfs_create(
- xfs_inode_t *dp,
- struct xfs_name *name,
- umode_t mode,
- dev_t rdev,
- xfs_inode_t **ipp)
-{
- int is_dir = S_ISDIR(mode);
- struct xfs_mount *mp = dp->i_mount;
- struct xfs_inode *ip = NULL;
- struct xfs_trans *tp = NULL;
- int error;
- bool unlock_dp_on_error = false;
- prid_t prid;
- struct xfs_dquot *udqp = NULL;
- struct xfs_dquot *gdqp = NULL;
- struct xfs_dquot *pdqp = NULL;
- struct xfs_trans_res *tres;
- bool cleared_space = false;
- uint resblks;
-
+ struct xfs_inode *dp,
+ struct xfs_name *name,
+ const struct xfs_ialloc_args *args,
+ struct xfs_inode **ipp)
+{
+ 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_trans_res *tres;
+ uint resblks;
+ bool unlock_dp_on_error = false;
+ bool is_dir = S_ISDIR(args->mode);
+ bool cleared_space = false;
+ int error;
+
+ ASSERT(args->pip == dp);
trace_xfs_create(dp, name);
if (XFS_FORCED_SHUTDOWN(mp))
return -EIO;
- prid = xfs_get_initial_prid(dp);
-
/*
* Make sure that we have allocated dquot(s) on disk.
*/
- error = xfs_qm_vop_dqalloc(dp, xfs_kuid_to_uid(current_fsuid()),
- xfs_kgid_to_gid(current_fsgid()), prid,
+ error = xfs_qm_vop_dqalloc(dp, args->uid, args->gid, args->prid,
XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
&udqp, &gdqp, &pdqp);
if (error)
@@ -917,7 +897,7 @@ xfs_create(
* entry pointing to them, but a directory also the "." entry
* pointing to itself.
*/
- error = xfs_dir_ialloc(&tp, dp, mode, is_dir ? 2 : 1, rdev, prid, &ip);
+ error = xfs_dir_ialloc(&tp, args, &ip);
if (error)
goto out_trans_cancel;
@@ -999,31 +979,30 @@ xfs_create(
int
xfs_create_tmpfile(
- struct xfs_inode *dp,
- umode_t mode,
- struct xfs_inode **ipp)
-{
- struct xfs_mount *mp = dp->i_mount;
- struct xfs_inode *ip = NULL;
- struct xfs_trans *tp = NULL;
- int error;
- prid_t prid;
- struct xfs_dquot *udqp = NULL;
- struct xfs_dquot *gdqp = NULL;
- struct xfs_dquot *pdqp = NULL;
- struct xfs_trans_res *tres;
- uint resblks;
+ struct xfs_inode *dp,
+ const struct xfs_ialloc_args *args,
+ struct xfs_inode **ipp)
+{
+ 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_trans_res *tres;
+ uint resblks;
+ int error;
+
+ ASSERT(args->nlink == 0);
+ ASSERT(args->pip == dp);
if (XFS_FORCED_SHUTDOWN(mp))
return -EIO;
- prid = xfs_get_initial_prid(dp);
-
/*
* Make sure that we have allocated dquot(s) on disk.
*/
- error = xfs_qm_vop_dqalloc(dp, xfs_kuid_to_uid(current_fsuid()),
- xfs_kgid_to_gid(current_fsgid()), prid,
+ error = xfs_qm_vop_dqalloc(dp, args->uid, args->gid, args->prid,
XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
&udqp, &gdqp, &pdqp);
if (error)
@@ -1041,7 +1020,7 @@ xfs_create_tmpfile(
if (error)
goto out_trans_cancel;
- error = xfs_dir_ialloc(&tp, dp, mode, 0, 0, prid, &ip);
+ error = xfs_dir_ialloc(&tp, args, &ip);
if (error)
goto out_trans_cancel;
@@ -3086,10 +3065,18 @@ xfs_rename_alloc_whiteout(
struct xfs_inode *dp,
struct xfs_inode **wip)
{
+ struct xfs_ialloc_args args = {
+ .pip = dp,
+ .uid = xfs_kuid_to_uid(current_fsuid()),
+ .gid = xfs_kgid_to_gid(current_fsgid()),
+ .prid = xfs_get_initial_prid(dp),
+ .nlink = 0,
+ .mode = S_IFCHR | WHITEOUT_MODE,
+ };
struct xfs_inode *tmpfile;
int error;
- error = xfs_create_tmpfile(dp, S_IFCHR | WHITEOUT_MODE, &tmpfile);
+ error = xfs_create_tmpfile(dp, &args, &tmpfile);
if (error)
return error;
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index 336f2642336a..24e167cd9a72 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -405,8 +405,10 @@ void xfs_inactive(struct xfs_inode *ip);
int xfs_lookup(struct xfs_inode *dp, struct xfs_name *name,
struct xfs_inode **ipp, struct xfs_name *ci_name);
int xfs_create(struct xfs_inode *dp, struct xfs_name *name,
- umode_t mode, dev_t rdev, struct xfs_inode **ipp);
-int xfs_create_tmpfile(struct xfs_inode *dp, umode_t mode,
+ const struct xfs_ialloc_args *iargs,
+ struct xfs_inode **ipp);
+int xfs_create_tmpfile(struct xfs_inode *dp,
+ const struct xfs_ialloc_args *iargs,
struct xfs_inode **ipp);
int xfs_remove(struct xfs_inode *dp, struct xfs_name *name,
struct xfs_inode *ip);
@@ -438,8 +440,8 @@ int xfs_iflush(struct xfs_inode *, struct xfs_buf **);
void xfs_lock_two_inodes(struct xfs_inode *ip0, uint ip0_mode,
struct xfs_inode *ip1, uint ip1_mode);
-int xfs_dir_ialloc(struct xfs_trans **, struct xfs_inode *, umode_t,
- xfs_nlink_t, dev_t, prid_t,
+int xfs_dir_ialloc(struct xfs_trans **,
+ const struct xfs_ialloc_args *,
struct xfs_inode **);
static inline int
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
index e4635b29a20d..9db69b8b8077 100644
--- a/fs/xfs/xfs_iops.c
+++ b/fs/xfs/xfs_iops.c
@@ -123,42 +123,52 @@ xfs_cleanup_inode(
STATIC int
xfs_generic_create(
- struct inode *dir,
- struct dentry *dentry,
- umode_t mode,
- dev_t rdev,
- bool tmpfile) /* unnamed file */
+ struct inode *dir,
+ struct dentry *dentry,
+ umode_t mode,
+ dev_t rdev,
+ bool tmpfile) /* unnamed file */
{
- struct inode *inode;
- struct xfs_inode *ip = NULL;
- struct posix_acl *default_acl, *acl;
- struct xfs_name name;
- int error;
+ struct xfs_ialloc_args args = {
+ .pip = XFS_I(dir),
+ .uid = xfs_kuid_to_uid(current_fsuid()),
+ .gid = xfs_kgid_to_gid(current_fsgid()),
+ .prid = xfs_get_initial_prid(XFS_I(dir)),
+ .nlink = tmpfile ? 0 : (S_ISDIR(mode) ? 2 : 1),
+ .rdev = rdev,
+ .mode = mode,
+ };
+ struct inode *inode;
+ struct xfs_inode *ip = NULL;
+ struct posix_acl *default_acl, *acl;
+ struct xfs_name name;
+ int error;
/*
* Irix uses Missed'em'V split, but doesn't want to see
* the upper 5 bits of (14bit) major.
*/
- if (S_ISCHR(mode) || S_ISBLK(mode)) {
- if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
+ if (S_ISCHR(args.mode) || S_ISBLK(args.mode)) {
+ if (unlikely(!sysv_valid_dev(args.rdev) ||
+ MAJOR(args.rdev) & ~0x1ff))
return -EINVAL;
} else {
- rdev = 0;
+ args.rdev = 0;
}
- error = posix_acl_create(dir, &mode, &default_acl, &acl);
+ error = posix_acl_create(dir, &args.mode, &default_acl, &acl);
if (error)
return error;
/* Verify mode is valid also for tmpfile case */
- error = xfs_dentry_mode_to_name(&name, dentry, mode);
+ error = xfs_dentry_mode_to_name(&name, dentry, args.mode);
if (unlikely(error))
goto out_free_acl;
if (!tmpfile) {
- error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip);
+ error = xfs_create(XFS_I(dir), &name, &args, &ip);
} else {
- error = xfs_create_tmpfile(XFS_I(dir), mode, &ip);
+ error = xfs_create_tmpfile(XFS_I(dir), &args, &ip);
}
if (unlikely(error))
goto out_free_acl;
diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
index fb671be5ca25..22b6d47670a3 100644
--- a/fs/xfs/xfs_qm.c
+++ b/fs/xfs/xfs_qm.c
@@ -757,6 +757,10 @@ xfs_qm_qino_alloc(
xfs_inode_t **ip,
uint flags)
{
+ struct xfs_ialloc_args args = {
+ .nlink = 1,
+ .mode = S_IFREG,
+ };
xfs_trans_t *tp;
int error;
bool need_alloc = true;
@@ -806,7 +810,7 @@ xfs_qm_qino_alloc(
return error;
if (need_alloc) {
- error = xfs_dir_ialloc(&tp, NULL, S_IFREG, 1, 0, 0, ip);
+ error = xfs_dir_ialloc(&tp, &args, ip);
if (error) {
xfs_trans_cancel(tp);
return error;
diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
index bc6cf78a44ef..1c6b1d4040c0 100644
--- a/fs/xfs/xfs_symlink.c
+++ b/fs/xfs/xfs_symlink.c
@@ -235,6 +235,14 @@ xfs_symlink(
umode_t mode,
struct xfs_inode **ipp)
{
+ struct xfs_ialloc_args args = {
+ .pip = dp,
+ .uid = xfs_kuid_to_uid(current_fsuid()),
+ .gid = xfs_kgid_to_gid(current_fsgid()),
+ .prid = xfs_get_initial_prid(dp),
+ .nlink = 1,
+ .mode = S_IFLNK | (mode & ~S_IFMT),
+ };
struct xfs_mount *mp = dp->i_mount;
struct xfs_trans *tp = NULL;
struct xfs_inode *ip = NULL;
@@ -242,7 +250,6 @@ xfs_symlink(
int pathlen;
bool unlock_dp_on_error = false;
xfs_filblks_t fs_blocks;
- prid_t prid;
struct xfs_dquot *udqp = NULL;
struct xfs_dquot *gdqp = NULL;
struct xfs_dquot *pdqp = NULL;
@@ -264,14 +271,11 @@ xfs_symlink(
ASSERT(pathlen > 0);
udqp = gdqp = NULL;
- prid = xfs_get_initial_prid(dp);
/*
* Make sure that we have allocated dquot(s) on disk.
*/
- error = xfs_qm_vop_dqalloc(dp,
- xfs_kuid_to_uid(current_fsuid()),
- xfs_kgid_to_gid(current_fsgid()), prid,
+ error = xfs_qm_vop_dqalloc(dp, args.uid, args.gid, args.prid,
XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT,
&udqp, &gdqp, &pdqp);
if (error)
@@ -313,8 +317,7 @@ xfs_symlink(
/*
* Allocate an inode for the symlink.
*/
- error = xfs_dir_ialloc(&tp, dp, S_IFLNK | (mode & ~S_IFMT), 1, 0,
- prid, &ip);
+ error = xfs_dir_ialloc(&tp, &args, &ip);
if (error)
goto out_trans_cancel;
next prev parent reply other threads:[~2020-01-01 1:13 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-01 1:12 [PATCH v2 00/21] xfs: hoist inode operations to libxfs Darrick J. Wong
2020-01-01 1:12 ` [PATCH 01/21] xfs: hoist extent size helpers " Darrick J. Wong
2020-01-01 1:12 ` [PATCH 02/21] xfs: hoist inode flag conversion functions Darrick J. Wong
2020-01-01 1:12 ` [PATCH 03/21] xfs: hoist project id get/set functions Darrick J. Wong
2020-01-01 1:13 ` [PATCH 04/21] xfs: pack inode allocation parameters into a separate structure Darrick J. Wong
2020-01-01 1:13 ` [PATCH 05/21] xfs: implement atime updates in xfs_trans_ichgtime Darrick J. Wong
2020-01-01 1:13 ` [PATCH 06/21] xfs: use xfs_trans_ichgtime to set times when allocating inode Darrick J. Wong
2020-01-01 1:13 ` [PATCH 07/21] xfs: split inode allocation and initialization Darrick J. Wong
2020-01-01 1:13 ` [PATCH 08/21] xfs: delegate post-allocation iget Darrick J. Wong
2020-01-01 1:13 ` [PATCH 09/21] xfs: hoist inode allocation function Darrick J. Wong
2020-01-01 1:13 ` Darrick J. Wong [this message]
2020-01-01 1:13 ` [PATCH 11/21] xfs: refactor special inode roll out of xfs_dir_ialloc Darrick J. Wong
2020-01-01 1:13 ` [PATCH 12/21] xfs: move xfs_dir_ialloc to libxfs Darrick J. Wong
2020-01-01 1:13 ` [PATCH 13/21] xfs: hoist xfs_iunlink " Darrick J. Wong
2020-01-01 1:14 ` [PATCH 14/21] xfs: hoist xfs_{bump,drop}link " Darrick J. Wong
2020-01-01 1:14 ` [PATCH 15/21] xfs: create libxfs helper to link a new inode into a directory Darrick J. Wong
2020-01-01 1:14 ` [PATCH 16/21] xfs: create libxfs helper to link an existing " Darrick J. Wong
2020-01-01 1:14 ` [PATCH 17/21] xfs: hoist inode free function to libxfs Darrick J. Wong
2020-01-01 1:14 ` [PATCH 18/21] xfs: create libxfs helper to remove an existing inode/name from a directory Darrick J. Wong
2020-01-01 1:14 ` [PATCH 19/21] xfs: create libxfs helper to exchange two directory entries Darrick J. Wong
2020-01-01 1:14 ` [PATCH 20/21] xfs: create libxfs helper to rename " Darrick J. Wong
2020-01-01 1:14 ` [PATCH 21/21] xfs: get rid of cross_rename Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=157784121815.1365473.16418584721128229029.stgit@magnolia \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.