Skip to contentSkip to conversation

xfs: use inode_init_always_gfp with __GFP_NOFAIL in xfs_inode_alloc

PATCH Applied Christoph Hellwig 3 participants 3 messages Aug 10 – Aug 21 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: use inode_init_always_gfp with __GFP_NOFAIL in xfs_inode_alloc

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")
---
 fs/xfs/xfs_icache.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
fs/xfs/xfs_icache.c +6 -10
index 9d8dd30bd927..a857b8aa255c 100644
@@ -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! */
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Christoph Hellwig

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")

Yeah, that makes sense.

--D

Quoted 43 lines
---
 fs/xfs/xfs_icache.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
fs/xfs/xfs_icache.c +6 -10
index 9d8dd30bd927..a857b8aa255c 100644
@@ -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! */
Signature · 1 line
2.53.0
maintainer Applied
#2 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

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.

[...]

Applied to for-next, thanks!

[1/1] xfs: use inode_init_always_gfp with __GFP_NOFAIL in xfs_inode_alloc

      commit: 4e07cd78e159a8c6b028e5dc5f4e5bf06067d969

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>