Skip to contentSkip to conversation

kernfs: avoid iattr allocation in listxattr

PATCH Applied Yichong Chen 3 participants 3 messages Jul 31 – Aug 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernfs: avoid iattr allocation in listxattr

kernfs_iop_listxattr() only needs to report existing xattrs, but it uses kernfs_iattrs(), which allocates kernfs_iattrs when the node does not have one yet.

This makes a query operation create persistent per-node metadata even when the xattr list is empty.

Use kernfs_iattrs_noalloc() instead and return an empty list when no iattrs exist.

---
 fs/kernfs/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/kernfs/inode.c +2 -2
index 2cb20294aaf5..237dcdd73fc2 100644
@@ -141,9 +141,9 @@ ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)
 	struct kernfs_node *kn = kernfs_dentry_node(dentry);
 	struct kernfs_iattrs *attrs;
 
-	attrs = kernfs_iattrs(kn);
+	attrs = kernfs_iattrs_noalloc(kn);
 	if (!attrs)
-		return -ENOMEM;
+		return 0;
 
 	return simple_xattr_list(d_inode(dentry), &attrs->xattrs, buf, size);
 }
Signature · 1 line
2.51.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Yichong Chen

kernfs_iop_listxattr() only needs to report existing xattrs, but it uses kernfs_iattrs(), which allocates kernfs_iattrs when the node does not have one yet.

This makes a query operation create persistent per-node metadata even when the xattr list is empty.

Use kernfs_iattrs_noalloc() instead and return an empty list when no iattrs exist.

Thanks.

Signature · 1 line
tejun
maintainer Applied
#2 lore raw
In reply to Yichong Chen
Quoted 1 line · Yichong Chen

[PATCH] kernfs: avoid iattr allocation in listxattr

Applied, thanks!

Branch: driver-core-testing
Tree: git://git.kernel.org/pub/scm/linux/kernel/git/driver-core/driver-core.git

[1/1] kernfs: avoid iattr allocation in listxattr

      commit: d5e81a5650b5

The patch will appear in the next linux-next integration (typically within 24 hours on weekdays).

The patch is in the driver-core-testing branch and will be promoted to driver-core-next after validation.