Linux XFS filesystem development
 help / color / mirror / Atom feed
* [PATCH] xfs: use inode_init_always_gfp with __GFP_NOFAIL in xfs_inode_alloc
@ 2026-08-10 15:38 Christoph Hellwig
  2026-08-10 18:26 ` Darrick J. Wong
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2026-08-10 15:38 UTC (permalink / raw)
  To: Carlos Maiolino; +Cc: linux-xfs

Just like the inode allocation itself, allocation of the security data
inside of inode_init_always(_gfp) must not fail here as we can be inside
an already dirty transaction context.  Note that we do not have to pass
GFP_NOFS explicitly as we are already in a nofs context when in a
transaction, as seen by the call to alloc_inode_sb.

Also update the comment about this a bit to be more clear.

Fixes: bf904248a2ad ("[XFS] Combine the XFS and Linux inodes")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_icache.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
index 9d8dd30bd927..a857b8aa255c 100644
--- a/fs/xfs/xfs_icache.c
+++ b/fs/xfs/xfs_icache.c
@@ -82,24 +82,20 @@ static inline xa_mark_t ici_tag_to_mark(unsigned int tag)
 
 /*
  * Allocate and initialise an xfs_inode.
+ *
+ * This can happen in context of already dirtied transactions, so the memory
+ * allocations must not fail.
  */
 struct xfs_inode *
 xfs_inode_alloc(
 	struct xfs_mount	*mp,
 	xfs_ino_t		ino)
 {
+	gfp_t			gfp = GFP_KERNEL | __GFP_NOFAIL;
 	struct xfs_inode	*ip;
 
-	/*
-	 * XXX: If this didn't occur in transactions, we could drop GFP_NOFAIL
-	 * and return NULL here on ENOMEM.
-	 */
-	ip = alloc_inode_sb(mp->m_super, xfs_inode_cache, GFP_KERNEL | __GFP_NOFAIL);
-
-	if (inode_init_always(mp->m_super, VFS_I(ip))) {
-		kmem_cache_free(xfs_inode_cache, ip);
-		return NULL;
-	}
+	ip = alloc_inode_sb(mp->m_super, xfs_inode_cache, gfp);
+	inode_init_always_gfp(mp->m_super, VFS_I(ip), gfp);
 
 	VFS_I(ip)->i_ino = ino;
 	/* VFS doesn't initialise i_mode! */
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfs: use inode_init_always_gfp with __GFP_NOFAIL in xfs_inode_alloc
  2026-08-10 15:38 [PATCH] xfs: use inode_init_always_gfp with __GFP_NOFAIL in xfs_inode_alloc Christoph Hellwig
@ 2026-08-10 18:26 ` Darrick J. Wong
  0 siblings, 0 replies; 2+ messages in thread
From: Darrick J. Wong @ 2026-08-10 18:26 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Carlos Maiolino, linux-xfs

On Mon, Aug 10, 2026 at 08:38:38AM -0700, Christoph Hellwig wrote:
> Just like the inode allocation itself, allocation of the security data
> inside of inode_init_always(_gfp) must not fail here as we can be inside
> an already dirty transaction context.  Note that we do not have to pass
> GFP_NOFS explicitly as we are already in a nofs context when in a
> transaction, as seen by the call to alloc_inode_sb.
> 
> Also update the comment about this a bit to be more clear.
> 
> Fixes: bf904248a2ad ("[XFS] Combine the XFS and Linux inodes")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Yeah, that makes sense.
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_icache.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/fs/xfs/xfs_icache.c b/fs/xfs/xfs_icache.c
> index 9d8dd30bd927..a857b8aa255c 100644
> --- a/fs/xfs/xfs_icache.c
> +++ b/fs/xfs/xfs_icache.c
> @@ -82,24 +82,20 @@ static inline xa_mark_t ici_tag_to_mark(unsigned int tag)
>  
>  /*
>   * Allocate and initialise an xfs_inode.
> + *
> + * This can happen in context of already dirtied transactions, so the memory
> + * allocations must not fail.
>   */
>  struct xfs_inode *
>  xfs_inode_alloc(
>  	struct xfs_mount	*mp,
>  	xfs_ino_t		ino)
>  {
> +	gfp_t			gfp = GFP_KERNEL | __GFP_NOFAIL;
>  	struct xfs_inode	*ip;
>  
> -	/*
> -	 * XXX: If this didn't occur in transactions, we could drop GFP_NOFAIL
> -	 * and return NULL here on ENOMEM.
> -	 */
> -	ip = alloc_inode_sb(mp->m_super, xfs_inode_cache, GFP_KERNEL | __GFP_NOFAIL);
> -
> -	if (inode_init_always(mp->m_super, VFS_I(ip))) {
> -		kmem_cache_free(xfs_inode_cache, ip);
> -		return NULL;
> -	}
> +	ip = alloc_inode_sb(mp->m_super, xfs_inode_cache, gfp);
> +	inode_init_always_gfp(mp->m_super, VFS_I(ip), gfp);
>  
>  	VFS_I(ip)->i_ino = ino;
>  	/* VFS doesn't initialise i_mode! */
> -- 
> 2.53.0
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-10 18:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-10 15:38 [PATCH] xfs: use inode_init_always_gfp with __GFP_NOFAIL in xfs_inode_alloc Christoph Hellwig
2026-08-10 18:26 ` Darrick J. Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox