Linux XFS filesystem development
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org
Cc: linux-xfs@vger.kernel.org, hch@lst.de
Subject: [PATCH 12/24] xfs: wrap inode creation dqalloc calls
Date: Thu, 20 Jun 2024 16:01:31 -0700	[thread overview]
Message-ID: <171892418102.3183075.3384829090907441660.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <171892417831.3183075.10759987417835165626.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

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>
---
 fs/xfs/scrub/tempfile.c |    9 +++---
 fs/xfs/xfs_inode.c      |   74 +++++++++++++++++++++++++++--------------------
 fs/xfs/xfs_inode.h      |    4 +++
 fs/xfs/xfs_symlink.c    |   20 +++----------
 4 files changed, 55 insertions(+), 52 deletions(-)


diff --git a/fs/xfs/scrub/tempfile.c b/fs/xfs/scrub/tempfile.c
index ee6f93e9f7cba..523971a15a72a 100644
--- a/fs/xfs/scrub/tempfile.c
+++ b/fs/xfs/scrub/tempfile.c
@@ -47,9 +47,9 @@ xrep_tempfile_create(
 	};
 	struct xfs_mount	*mp = sc->mp;
 	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_inode	*dp = mp->m_rootip;
 	xfs_ino_t		ino;
@@ -70,8 +70,7 @@ xrep_tempfile_create(
 	 * inode should be completely root owned so that we don't fail due to
 	 * quota limits.
 	 */
-	error = xfs_qm_vop_dqalloc(dp, GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, 0,
-			XFS_QMOPT_QUOTALL, &udqp, &gdqp, &pdqp);
+	error = xfs_icreate_dqalloc(&args, &udqp, &gdqp, &pdqp);
 	if (error)
 		return error;
 
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
index d026e377fcafa..1d7febda38c16 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;
 
diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h
index bc48e81829b5a..a905929494bd5 100644
--- a/fs/xfs/xfs_inode.h
+++ b/fs/xfs/xfs_inode.h
@@ -660,4 +660,8 @@ void xfs_dir_hook_setup(struct xfs_dir_hook *hook, notifier_fn_t mod_fn);
 # define xfs_dir_update_hook(dp, ip, delta, name)	((void)0)
 #endif /* CONFIG_XFS_LIVE_HOOKS */
 
+int xfs_icreate_dqalloc(const struct xfs_icreate_args *args,
+		struct xfs_dquot **udqpp, struct xfs_dquot **gdqpp,
+		struct xfs_dquot **pdqpp);
+
 #endif	/* __XFS_INODE_H__ */
diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c
index 3b797a39950d5..6ff736e5c4e7f 100644
--- a/fs/xfs/xfs_symlink.c
+++ b/fs/xfs/xfs_symlink.c
@@ -101,10 +101,9 @@ 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;
+	struct xfs_dquot	*udqp;
+	struct xfs_dquot	*gdqp;
+	struct xfs_dquot	*pdqp;
 	uint			resblks;
 	xfs_ino_t		ino;
 	struct xfs_parent_args	*ppargs;
@@ -127,17 +126,8 @@ xfs_symlink(
 		return -ENAMETOOLONG;
 	ASSERT(pathlen > 0);
 
-	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(idmap, i_user_ns(VFS_I(dp))),
-			mapped_fsgid(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;
 


  parent reply	other threads:[~2024-06-20 23:01 UTC|newest]

Thread overview: 114+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-20 22:50 [PATCHBOMB 6.11] xfs: inode cleanups for metadata directories Darrick J. Wong
2024-06-20 22:57 ` [PATCHSET v3.0 1/5] xfs: hoist inode operations to libxfs Darrick J. Wong
2024-06-20 22:58   ` [PATCH 01/24] xfs: use consistent uid/gid when grabbing dquots for inodes Darrick J. Wong
2024-06-21  4:37     ` Christoph Hellwig
2024-06-20 22:58   ` [PATCH 02/24] xfs: move inode copy-on-write predicates to xfs_inode.[ch] Darrick J. Wong
2024-06-21  4:37     ` Christoph Hellwig
2024-06-20 22:59   ` [PATCH 03/24] xfs: hoist extent size helpers to libxfs Darrick J. Wong
2024-06-21  4:37     ` Christoph Hellwig
2024-06-20 22:59   ` [PATCH 04/24] xfs: hoist inode flag conversion functions " Darrick J. Wong
2024-06-21  4:38     ` Christoph Hellwig
2024-06-20 22:59   ` [PATCH 05/24] xfs: hoist project id get/set " Darrick J. Wong
2024-06-21  4:38     ` Christoph Hellwig
2024-06-20 22:59   ` [PATCH 06/24] xfs: pack icreate initialization parameters into a separate structure Darrick J. Wong
2024-06-21  4:39     ` Christoph Hellwig
2024-06-20 23:00   ` [PATCH 07/24] xfs: implement atime updates in xfs_trans_ichgtime Darrick J. Wong
2024-06-21  4:39     ` Christoph Hellwig
2024-06-20 23:00   ` [PATCH 08/24] xfs: use xfs_trans_ichgtime to set times when allocating inode Darrick J. Wong
2024-06-21  4:39     ` Christoph Hellwig
2024-06-20 23:00   ` [PATCH 09/24] xfs: split new inode creation into two pieces Darrick J. Wong
2024-06-21  4:40     ` Christoph Hellwig
2024-06-20 23:01   ` [PATCH 10/24] xfs: hoist new inode initialization functions to libxfs Darrick J. Wong
2024-06-21  4:40     ` Christoph Hellwig
2024-06-20 23:01   ` [PATCH 11/24] xfs: push xfs_icreate_args creation out of xfs_create* Darrick J. Wong
2024-06-21  4:40     ` Christoph Hellwig
2024-06-20 23:01   ` Darrick J. Wong [this message]
2024-06-21  4:41     ` [PATCH 12/24] xfs: wrap inode creation dqalloc calls Christoph Hellwig
2024-06-20 23:01   ` [PATCH 13/24] xfs: hoist xfs_iunlink to libxfs Darrick J. Wong
2024-06-21  4:41     ` Christoph Hellwig
2024-06-20 23:02   ` [PATCH 14/24] xfs: hoist xfs_{bump,drop}link " Darrick J. Wong
2024-06-21  4:41     ` Christoph Hellwig
2024-06-20 23:02   ` [PATCH 15/24] xfs: separate the icreate logic around INIT_XATTRS Darrick J. Wong
2024-06-21  4:42     ` Christoph Hellwig
2024-06-20 23:02   ` [PATCH 16/24] xfs: create libxfs helper to link a new inode into a directory Darrick J. Wong
2024-06-21  4:42     ` Christoph Hellwig
2024-06-20 23:02   ` [PATCH 17/24] xfs: create libxfs helper to link an existing " Darrick J. Wong
2024-06-21  4:44     ` Christoph Hellwig
2024-06-20 23:03   ` [PATCH 18/24] xfs: hoist inode free function to libxfs Darrick J. Wong
2024-06-21  4:44     ` Christoph Hellwig
2024-06-20 23:03   ` [PATCH 19/24] xfs: create libxfs helper to remove an existing inode/name from a directory Darrick J. Wong
2024-06-21  4:44     ` Christoph Hellwig
2024-06-20 23:03   ` [PATCH 20/24] xfs: create libxfs helper to exchange two directory entries Darrick J. Wong
2024-06-21  4:45     ` Christoph Hellwig
2024-06-20 23:03   ` [PATCH 21/24] xfs: create libxfs helper to rename " Darrick J. Wong
2024-06-21  4:45     ` Christoph Hellwig
2024-06-20 23:04   ` [PATCH 22/24] xfs: move dirent update hooks to xfs_dir2.c Darrick J. Wong
2024-06-21  4:45     ` Christoph Hellwig
2024-06-20 23:04   ` [PATCH 23/24] xfs: get rid of trivial rename helpers Darrick J. Wong
2024-06-21  4:45     ` Christoph Hellwig
2024-06-20 23:04   ` [PATCH 24/24] xfs: don't use the incore struct xfs_sb for offsets into struct xfs_dsb Darrick J. Wong
2024-06-21  4:46     ` Christoph Hellwig
2024-06-20 22:57 ` [PATCHSET v3.0 2/5] xfs: extent free log intent cleanups Darrick J. Wong
2024-06-20 23:04   ` [PATCH 1/9] xfs: clean up extent free log intent item tracepoint callsites Darrick J. Wong
2024-06-21  4:46     ` Christoph Hellwig
2024-06-20 23:05   ` [PATCH 2/9] xfs: convert "skip_discard" to a proper flags bitset Darrick J. Wong
2024-06-21  4:47     ` Christoph Hellwig
2024-06-20 23:05   ` [PATCH 3/9] xfs: pass the fsbno to xfs_perag_intent_get Darrick J. Wong
2024-06-20 23:05   ` [PATCH 4/9] xfs: add a xefi_entry helper Darrick J. Wong
2024-06-20 23:05   ` [PATCH 5/9] xfs: reuse xfs_extent_free_cancel_item Darrick J. Wong
2024-06-20 23:06   ` [PATCH 6/9] xfs: factor out a xfs_efd_add_extent helper Darrick J. Wong
2024-06-20 23:06   ` [PATCH 7/9] xfs: remove duplicate asserts in xfs_defer_extent_free Darrick J. Wong
2024-06-20 23:06   ` [PATCH 8/9] xfs: remove xfs_defer_agfl_block Darrick J. Wong
2024-07-03  8:07     ` kernel test robot
2024-06-20 23:07   ` [PATCH 9/9] xfs: move xfs_extent_free_defer_add to xfs_extfree_item.c Darrick J. Wong
2024-06-21  4:48     ` Christoph Hellwig
2024-06-20 22:57 ` [PATCHSET v3.0 3/5] xfs: rmap log intent cleanups Darrick J. Wong
2024-06-20 23:07   ` [PATCH 1/9] xfs: give rmap btree cursor error tracepoints their own class Darrick J. Wong
2024-06-21  4:48     ` Christoph Hellwig
2024-06-20 23:07   ` [PATCH 2/9] xfs: prepare rmap btree tracepoints for widening Darrick J. Wong
2024-06-21  4:49     ` Christoph Hellwig
2024-06-21 18:07       ` Darrick J. Wong
2024-06-20 23:07   ` [PATCH 3/9] xfs: clean up rmap log intent item tracepoint callsites Darrick J. Wong
2024-06-21  4:50     ` Christoph Hellwig
2024-06-20 23:08   ` [PATCH 4/9] xfs: remove xfs_trans_set_rmap_flags Darrick J. Wong
2024-06-21  4:50     ` Christoph Hellwig
2024-06-20 23:08   ` [PATCH 5/9] xfs: add a ri_entry helper Darrick J. Wong
2024-06-20 23:08   ` [PATCH 6/9] xfs: reuse xfs_rmap_update_cancel_item Darrick J. Wong
2024-06-20 23:08   ` [PATCH 7/9] xfs: don't bother calling xfs_rmap_finish_one_cleanup in xfs_rmap_finish_one Darrick J. Wong
2024-06-20 23:09   ` [PATCH 8/9] xfs: simplify usage of the rcur local variable " Darrick J. Wong
2024-06-20 23:09   ` [PATCH 9/9] xfs: move xfs_rmap_update_defer_add to xfs_rmap_item.c Darrick J. Wong
2024-06-21  4:51     ` Christoph Hellwig
2024-06-20 22:58 ` [PATCHSET v3.0 4/5] xfs: refcount log intent cleanups Darrick J. Wong
2024-06-20 23:09   ` [PATCH 01/10] xfs: give refcount btree cursor error tracepoints their own class Darrick J. Wong
2024-06-21  4:51     ` Christoph Hellwig
2024-06-20 23:09   ` [PATCH 02/10] xfs: create specialized classes for refcount tracepoints Darrick J. Wong
2024-06-21  4:51     ` Christoph Hellwig
2024-06-20 23:10   ` [PATCH 03/10] xfs: prepare refcount btree tracepoints for widening Darrick J. Wong
2024-06-21  4:52     ` Christoph Hellwig
2024-06-20 23:10   ` [PATCH 04/10] xfs: clean up refcount log intent item tracepoint callsites Darrick J. Wong
2024-06-21  4:52     ` Christoph Hellwig
2024-06-20 23:10   ` [PATCH 05/10] xfs: remove xfs_trans_set_refcount_flags Darrick J. Wong
2024-06-21  4:53     ` Christoph Hellwig
2024-06-20 23:10   ` [PATCH 06/10] xfs: add a ci_entry helper Darrick J. Wong
2024-06-21  4:53     ` Christoph Hellwig
2024-06-20 23:11   ` [PATCH 07/10] xfs: reuse xfs_refcount_update_cancel_item Darrick J. Wong
2024-06-21  4:54     ` Christoph Hellwig
2024-06-20 23:11   ` [PATCH 08/10] xfs: don't bother calling xfs_refcount_finish_one_cleanup in xfs_refcount_finish_one Darrick J. Wong
2024-06-21  4:54     ` Christoph Hellwig
2024-06-20 23:11   ` [PATCH 09/10] xfs: simplify usage of the rcur local variable " Darrick J. Wong
2024-06-21  4:54     ` Christoph Hellwig
2024-06-20 23:11   ` [PATCH 10/10] xfs: move xfs_refcount_update_defer_add to xfs_refcount_item.c Darrick J. Wong
2024-06-21  4:54     ` Christoph Hellwig
2024-06-20 22:58 ` [PATCHSET v3.0 5/5] xfs: enable FITRIM for the realtime section Darrick J. Wong
2024-06-20 23:12   ` [PATCH 1/1] xfs: enable FITRIM on the realtime device Darrick J. Wong
2024-06-21  5:00     ` Christoph Hellwig
2024-06-21 18:23       ` Darrick J. Wong
2024-06-24 15:04     ` [PATCH v2 " Darrick J. Wong
2024-06-24 15:12       ` Christoph Hellwig
2024-06-27  6:13       ` Chandan Babu R
2024-06-27  6:35         ` Christoph Hellwig
2024-06-27  6:38           ` Christoph Hellwig
2024-06-27 20:54             ` Darrick J. Wong
     [not found]     ` <2O52BJOH5Y79X.3A332GBFVJ9K7@gmail.com>
     [not found]       ` <20240723032327.GU1998502@frogsfrogsfrogs>
     [not found]         ` <2NTNQAOVQB88C.3NX279FOIEOI0@gmail.com>
     [not found]           ` <20240723232805.GX1998502@frogsfrogsfrogs>
     [not found]             ` <1YL3BJOD4E6EC.2JWNIADIUU7OD@gmail.com>
     [not found]               ` <20240724235707.GG1646003@frogsfrogsfrogs>
     [not found]                 ` <3UKNEUV4T2OLQ.30FMK239EJTGG@gmail.com>
     [not found]                   ` <20240806163246.GD623936@frogsfrogsfrogs>
     [not found]                     ` <20240806230656.GD623922@frogsfrogsfrogs>
2024-08-19 16:01                       ` [PATCH " Konst Mayer
2024-06-21  3:09   ` [PATCHSET v3.0 5/5] xfs: enable FITRIM for the realtime section Konst Mayer
2024-06-21 18:26     ` 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=171892418102.3183075.3384829090907441660.stgit@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=hch@lst.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox