Skip to contentSkip to conversation

Use new syscalls to set filesystem inode attributes on any inode

PATCH Superseded Andrey Albershteyn 2 participants 9 messages Jul 29, 2025 XFS filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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

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

---
Darrick, I left your reviewed-by tags, as the code didn't changed, I just updated the commit messages. Let me know if you have any new feedback on this.

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

 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 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.49.0
#2 lore raw

PATCH 2/3 xfs: allow setting xattrs on special files

In reply to Andrey Albershteyn

From: Andrey Albershteyn <[email protected]>

XFS does't have extended attributes manipulation ioctls for special files. Changing or reading file extended 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 extended 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.49.0
#3 lore raw

Re: [PATCH 2/3] xfs: allow setting xattrs on special files

Quoted 4 lines · Andrey Albershteyn

From: Andrey Albershteyn <[email protected]>

XFS does't have extended attributes manipulation ioctls for special files. Changing or reading file extended attributes is rejected for them

"extended file attributes" or "fileattrs" as Amir suggested, but never "extended attributes" because that's a separate thing.

(no need to drop the rvb over this)

--D

Quoted 47 lines

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 extended 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 · 2 lines
-- 
2.49.0
#4 lore raw

Re: [PATCH 2/3] xfs: allow setting xattrs on special files

Quoted 8 lines · Darrick J. Wong
Quoted 4 lines · Andrey Albershteyn

From: Andrey Albershteyn <[email protected]>

XFS does't have extended attributes manipulation ioctls for special files. Changing or reading file extended attributes is rejected for them

"extended file attributes" or "fileattrs" as Amir suggested, but never "extended attributes" because that's a separate thing.

sure

Quoted 3 lines

(no need to drop the rvb over this)

Thanks!

Signature · 1 line
- Andrey
#5 lore raw

PATCH 3/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 extended attributes. This patch adds them. The attribute value 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.49.0
#6 lore raw
In reply to Andrey Albershteyn
Quoted 10 lines · Andrey Albershteyn

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

---
Darrick, I left your reviewed-by tags, as the code didn't changed, I just updated the commit messages. Let me know if you have any new feedback on this.

It all looks ok except for s/(file| )extended attribute/fileattr/

Seeing as the VFS part just went in for 6.17 this should probably get merged soonish, right?

--D

Quoted 19 lines

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

 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]>
#7 lore raw
Quoted 12 lines · Darrick J. Wong
Quoted 10 lines · Andrey Albershteyn

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

---
Darrick, I left your reviewed-by tags, as the code didn't changed, I just updated the commit messages. Let me know if you have any new feedback on this.

Quoted 4 lines

It all looks ok except for s/(file| )extended attribute/fileattr/

Seeing as the VFS part just went in for 6.17 this should probably get merged soonish, right?

Without this special files won't be able to use these syscalls, but otherwise, for regular files nothing changes. So, I think it not necessary for this to get into this merge window.

Quoted 23 lines

--D

Quoted 19 lines

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

 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]>
Signature · 1 line
- Andrey
#8 lore raw
Quoted 13 lines · Andrey Albershteyn
Quoted 12 lines · Darrick J. Wong
Quoted 10 lines · Andrey Albershteyn

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

---
Darrick, I left your reviewed-by tags, as the code didn't changed, I just updated the commit messages. Let me know if you have any new feedback on this.

Quoted 8 lines
Quoted 4 lines

It all looks ok except for s/(file| )extended attribute/fileattr/

Seeing as the VFS part just went in for 6.17 this should probably get merged soonish, right?

Without this special files won't be able to use these syscalls, but otherwise, for regular files nothing changes. So, I think it not necessary for this to get into this merge window.

<nod> Ok.

--D

Quoted 27 lines
Quoted 23 lines

--D

Quoted 19 lines

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

 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]>
Signature · 1 line
- Andrey