Skip to contentSkip to conversation

Use new syscalls to set filesystem file attributes on any inode

PATCH Applied Andrey Albershteyn 2 participants 5 messages Aug 4, 2025 – Aug 28, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

v2 cover Use new syscalls to set filesystem file attributes on any inode

With addition of new syscalls file_getattr/file_setattr allow changing filesystem file attributes on special files. Fix project ID inheritance for special files in renames.

---
Changes in v2:
- Swapped patch 2 and 3 as it make more sense to add callback and then allow calling them
- Replace "file extended attributes"/"inode attributes" with "file attributes"
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrey Albershteyn (3):
xfs: allow renames of project-less inodes
xfs: add .fileattr_set and fileattr_get callbacks for symlinks
xfs: allow setting file attributes on special files

 fs/xfs/xfs_inode.c | 64 +++++++++++++++++++++++++++++-------------------------
 fs/xfs/xfs_ioctl.c |  6 -----
 fs/xfs/xfs_iops.c  |  2 ++
 3 files changed, 36 insertions(+), 36 deletions(-)

---
base-commit: 86aa721820952b793a12fc6e5a01734186c0c238
change-id: 20250320-xfs-xattrat-b31a9f5ed284

Best regards,

Signature · 1 line
Andrey Albershteyn <[email protected]>
#1 lore raw

PATCH v2 1/3 xfs: allow renames of project-less inodes

From: Andrey Albershteyn <[email protected]>

Special file inodes cannot have project ID set from userspace and are skipped during initial project setup. Those inodes are left project-less in the project directory. New inodes created after project initialization do have an ID. Creating hard links or renaming those project-less inodes then fails on different ID check.

In commit e23d7e82b707 ("xfs: allow cross-linking special files without project quota"), we relaxed the project id checks to allow hardlinking special files with differing project ids since the projid cannot be changed. Apply the same workaround for renaming operations.

---
 fs/xfs/xfs_inode.c | 64 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 30 deletions(-)
fs/xfs/xfs_inode.c +34 -30
index 9c39251961a3..0ddb9ce0f5e3 100644
@@ -877,6 +877,35 @@ xfs_create_tmpfile(
 	return error;
 }
 
+static inline int
+xfs_projid_differ(
+	struct xfs_inode	*tdp,
+	struct xfs_inode	*sip)
+{
+	/*
+	 * If we are using project inheritance, we only allow hard link/renames
+	 * creation in our tree when the project IDs are the same; else
+	 * the tree quota mechanism could be circumvented.
+	 */
+	if (unlikely((tdp->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
+		     tdp->i_projid != sip->i_projid)) {
+		/*
+		 * Project quota setup skips special files which can
+		 * leave inodes in a PROJINHERIT directory without a
+		 * project ID set. We need to allow links to be made
+		 * to these "project-less" inodes because userspace
+		 * expects them to succeed after project ID setup,
+		 * but everything else should be rejected.
+		 */
+		if (!special_file(VFS_I(sip)->i_mode) ||
+		    sip->i_projid != 0) {
+			return -EXDEV;
+		}
+	}
+
+	return 0;
+}
+
 int
 xfs_link(
 	struct xfs_inode	*tdp,
@@ -930,27 +959,9 @@ xfs_link(
 		goto error_return;
 	}
 
-	/*
-	 * If we are using project inheritance, we only allow hard link
-	 * creation in our tree when the project IDs are the same; else
-	 * the tree quota mechanism could be circumvented.
-	 */
-	if (unlikely((tdp->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
-		     tdp->i_projid != sip->i_projid)) {
-		/*
-		 * Project quota setup skips special files which can
-		 * leave inodes in a PROJINHERIT directory without a
-		 * project ID set. We need to allow links to be made
-		 * to these "project-less" inodes because userspace
-		 * expects them to succeed after project ID setup,
-		 * but everything else should be rejected.
-		 */
-		if (!special_file(VFS_I(sip)->i_mode) ||
-		    sip->i_projid != 0) {
-			error = -EXDEV;
-			goto error_return;
-		}
-	}
+	error = xfs_projid_differ(tdp, sip);
+	if (error)
+		goto error_return;
 
 	error = xfs_dir_add_child(tp, resblks, &du);
 	if (error)
@@ -2227,16 +2238,9 @@ xfs_rename(
 	if (du_wip.ip)
 		xfs_trans_ijoin(tp, du_wip.ip, 0);
 
-	/*
-	 * If we are using project inheritance, we only allow renames
-	 * into our tree when the project IDs are the same; else the
-	 * tree quota mechanism would be circumvented.
-	 */
-	if (unlikely((target_dp->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
-		     target_dp->i_projid != src_ip->i_projid)) {
-		error = -EXDEV;
+	error = xfs_projid_differ(target_dp, src_ip);
+	if (error)
 		goto out_trans_cancel;
-	}
 
 	/* RENAME_EXCHANGE is unique from here on. */
 	if (flags & RENAME_EXCHANGE) {
Signature · 1 line
2.50.0
#2 lore raw

PATCH v2 2/3 xfs: add .fileattr_set and fileattr_get callbacks for symlinks

In reply to Andrey Albershteyn

From: Andrey Albershteyn <[email protected]>

As there are now file_getattr() and file_setattr(), xfs_quota will call them on special files. These new syscalls call ->fileattr_get/set.

Symlink inodes don't have callbacks to set file attributes. This patch adds them. The attribute values combinations are checked in fileattr_set_prepare().

---
 fs/xfs/xfs_iops.c | 2 ++
 1 file changed, 2 insertions(+)
fs/xfs/xfs_iops.c +2 -0
index 149b5460fbfd..c1234aad11e9 100644
@@ -1334,6 +1334,8 @@ static const struct inode_operations xfs_symlink_inode_operations = {
 	.setattr		= xfs_vn_setattr,
 	.listxattr		= xfs_vn_listxattr,
 	.update_time		= xfs_vn_update_time,
+	.fileattr_get		= xfs_fileattr_get,
+	.fileattr_set		= xfs_fileattr_set,
 };
 
 /* Figure out if this file actually supports DAX. */
Signature · 1 line
2.50.0
#3 lore raw

PATCH v2 3/3 xfs: allow setting file attributes on special files

In reply to Andrey Albershteyn

From: Andrey Albershteyn <[email protected]>

XFS does't have file attributes manipulation ioctls for special files. Changing or reading file attributes is rejected for them in xfs_fileattr_*et().

In XFS, this is necessary to work for project quota directories. When project is set up, xfs_quota opens and calls FS_IOC_SETFSXATTR on every inode in the directory. However, special files are skipped due to open() returning a special inode for them. So, they don't even get to this check.

The recently added file_getattr/file_setattr will call xfs_fileattr_*et, on special files. This patch allows reading/changing file attributes on special files.

---
 fs/xfs/xfs_ioctl.c | 6 ------
 1 file changed, 6 deletions(-)
fs/xfs/xfs_ioctl.c +0 -6
index fe1f74a3b6a3..f3c89172cc27 100644
@@ -512,9 +512,6 @@ xfs_fileattr_get(
 {
 	struct xfs_inode	*ip = XFS_I(d_inode(dentry));
 
-	if (d_is_special(dentry))
-		return -ENOTTY;
-
 	xfs_ilock(ip, XFS_ILOCK_SHARED);
 	xfs_fill_fsxattr(ip, XFS_DATA_FORK, fa);
 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
@@ -736,9 +733,6 @@ xfs_fileattr_set(
 
 	trace_xfs_ioctl_setattr(ip);
 
-	if (d_is_special(dentry))
-		return -ENOTTY;
-
 	if (!fa->fsx_valid) {
 		if (fa->flags & ~(FS_IMMUTABLE_FL | FS_APPEND_FL |
 				  FS_NOATIME_FL | FS_NODUMP_FL |
Signature · 1 line
2.50.0
maintainer Applied
#4 lore raw
In reply to Andrey Albershteyn
Quoted 5 lines · Andrey Albershteyn

With addition of new syscalls file_getattr/file_setattr allow changing filesystem file attributes on special files. Fix project ID inheritance for special files in renames.

Applied to for-next, thanks!

[1/3] xfs: allow renames of project-less inodes

      commit: 8d2f9f5c64f16e0717854fb66d795ebe8c30103b
[2/3] xfs: add .fileattr_set and fileattr_get callbacks for symlinks
      commit: 8a221004fe5288b66503699a329a6b623be13f91
[3/3] xfs: allow setting file attributes on special files
      commit: 0239bd9fa445a21def88f7e76fe6e0414b2a4da0

Best regards,

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