Linux NFS development
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API
@ 2026-11-29  2:42 koraynilay
  2026-11-29  2:42 ` [PATCH v3 1/5] vfs: use goto out on error in vfs_fileattr_set() koraynilay
                   ` (5 more replies)
  0 siblings, 6 replies; 26+ messages in thread
From: koraynilay @ 2026-11-29  2:42 UTC (permalink / raw)
  To: Namjae Jeon, Hyunchul Lee, Jonathan Corbet, Eric Biggers,
	Theodore Y . Ts'o, Jaegeuk Kim, Alexander Viro,
	Christian Brauner
  Cc: Shuah Khan, Randy Dunlap, Chuck Lever, Jeff Layton, Jan Kara,
	Alexander Aring, Darrick J . Wong, Andrey Albershteyn,
	Amir Goldstein, Miklos Szeredi, Pali Rohár, Lauri Gates,
	Christoph Hellwig, Dave Chinner, linux-btrfs, linux-xfs,
	linux-kernel, linux-fsdevel, ntfs, linux-nfs, linux-api,
	linux-doc, linux-unionfs, koraynilay

This is a follow up patch series stemmed from [1] and [2], splitting the
_mask change for the fileattr API into its own separate patch series.

Patch 1 is a preparatory cleanup so that the code in the later
patches can be formatted better.

Patch 2 is the actual implementation, which introduces:
- fa_xflags_{rw,ro}_mask fields to struct file_attr
- fsx_xflags_{rw,ro}_mask fields and has_masks selector to struct file_kattr
- AT_FILEATTR_MASKS at_flag for file_[gs]etattr()

These masks have the following semantics:
- rw_mask:
  * for filesystems: advertise which xflags they support changing
  * for userspace: specify which xflags it wants to modify
- ro_mask:
  * for filesystems: advertise which xflags they support only reading
  * for userspace: ignored

(More details available in Patch 5)

This allows userspace to not have to do a RMW cycle when using the
file_[gs]etattr() syscalls, avoiding possible race conditions and
simplifying their usage.

This patch also introduces the missing FS_XFLAG_PROJID flag so that
programs like chattr can leverage the new mask API.
FS_XFLAG_PROJID is kept out of the legacy FS_XFLAGS_MASK and so it's
defined as part of a new FS_FILE_ATTR_XFLAGS_MASK group of xflags that
will be used moving forward for any new xflag (like the one proposed in [2]).

Patch 3 adds FS_XFLAG_COMPR and FS_XFLAG_ENCRYPT (as FS_COMPR_FL and
FS_ENCRYPT_FL counterparts), which are needed for Patch 4. This means
that old programs will also get these new flags, but that should be fine
since xflags were made to be expandable.

Patch 4 converts fs/ntfs to this new API, to show how it can benefit
filesystem drivers too.

Patch 5 adds the Documentation/filesystems/fileattr.rst page that
explains well how this API can be used by both userspace and by
filesystems and the various semantics.
(It doesn't go into *too much* detail though, since that would mean
writing the code itself).
The rendered page can be found at [4].

The series has been tested with custom xfstests [3] (generic/816-835,
xfs/611, xfs/673) across NTFS, ext4 (project quotas), XFS (project
quotas and extent size hints), Btrfs, and F2FS.
Note: these tests were written by gemini and not manually checked,
before sending them upstream (if needed) I'll have to review/rewrite
them manually.

IMPORTANT NOTE: there are quite a few bugs with overlayfs
(generic/832-835 above) when using a masks filesystem, I haven't
investigated them deeply yet since I would first need to understand a
lot more how overlayfs works, but the robot's report is in [5].

v3 changes:
- refactor the big if/else in vfs_fileattr_set() to a
  fileattr_set_convert() helper and simplify (hopefully?) its code;
- drop fscrypt flags -> xflags patch and just use xflags_to_flags() in
  vfs;
- add FS_XFLAG_COMPR/ENCRYPT in a separate patch instead of in the ntfs
  one ([6]);
- move FILE_ATTR_SIZE_VER* variables from the uapi header to the
  internal header ([7]);
- rename AT_FILE_ATTR_MASKS to AT_FILEATTR_MASKS ([8]);
- change "legacy" references to "rmw" references in both comments and
  helper names ([8]);
- add docs.

v2 changes:
- make fa_xflags_{rw,ro}_mask in struct file_attr __u64;
- add AT_FILE_ATTR_MASKS to opt in to mask semantics instead of needing
  unreliable heuristics on usize and mask values;
- reject intermediate sizes between VER0 and VER1;
- reject non-zero masks on SET without AT_FILE_ATTR_MASKS;
- add patch 2/4 for fscrypt_prepare_setflags;
- add xflags_to_flags() / flags_to_xflags() and
  fileattr_set_{legacy_to_mask,mask_to_legacy}() to translate between
  legacy RMW callers/filesystems and _mask callers/filesystems;
- clamp fa->fsx_xflags to rw_user_mask in file_attr_to_fileattr();
- update fileattr_set_prepare() to validate capabilities and projid
  changes against rw_user_mask / xflags;
- move the rw_mask == 0 early-return no-op from file_setattr() into
  vfs_fileattr_set();
- put FS_XFLAG_COMPR in FS_XFLAG_RDONLY_MASK only (keep FS_XFLAG_ENCRYPT
  in both FS_XFLAG_COMMON and FS_XFLAG_RDONLY_MASK);
- update ntfs_fileattr_set() to apply only bits selected in
  fsx_xflags_rw_mask;

Thanks,
koraynilay

[1]: https://lore.kernel.org/CAOQ4uxg8aVcWyNiFDk8djdn-M3xJcu_7-kRxVq9jjFsbcGp1ew@mail.gmail.com/
[2]: https://lore.kernel.org/CAOQ4uxjVQ9cjV=_jBjQtNg9zCuWUEJT9KNYMKV+1jwBkHen5OA@mail.gmail.com/
[3]: https://github.com/koraynilay/xfstests/tree/patches-in-queue
[4]: https://koraynilay.neocities.org/linuxdocs/fileattr
[5]: https://koraynilay.neocities.org/vfs-masks/overlayfs-fileattr-bugs
[6]: https://lore.kernel.org/CAOQ4uxgJjy3TaORBkMOdef-JvzX2uA5K2sbMDEcLqmpkedsESw@mail.gmail.com/
[7]: https://lore.kernel.org/CAOQ4uxi6oyFj_A9nPbgGeSufGo11L2N=QxLi2DW=ZKy25YQ5Tw@mail.gmail.com/
[8]: https://lore.kernel.org/CAOQ4uxhA+93bo5WseLxe7cAvJHJ8eQodoQHLwh=iToyEVkeXEA@mail.gmail.com/

koraynilay (5):
  vfs: use goto out on error in vfs_fileattr_set()
  vfs: add xflags masks to fileattr API
  vfs: add COMPR/ENCRYPT xflags from FS_COMPR_FL/FS_ENCRYPT_FL
  ntfs: switch to the new xflags fileattr API
  docs: add fileattr API documentation

 Documentation/filesystems/fileattr.rst | 530 +++++++++++++++++++++++++
 Documentation/filesystems/index.rst    |   1 +
 Documentation/filesystems/vfs.rst      |  19 +-
 fs/file_attr.c                         | 379 +++++++++++++++---
 fs/ntfs/file.c                         | 109 ++---
 include/linux/fileattr.h               |  19 +-
 include/uapi/linux/fcntl.h             |   6 +
 include/uapi/linux/fs.h                |  37 +-
 8 files changed, 985 insertions(+), 115 deletions(-)
 create mode 100644 Documentation/filesystems/fileattr.rst


base-commit: 3857587d9d6fa44d40d1c73bde6a39f6f7a5216c
-- 
2.56.0


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

end of thread, other threads:[~2026-11-29 22:22 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29  2:42 [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-11-29  2:42 ` [PATCH v3 1/5] vfs: use goto out on error in vfs_fileattr_set() koraynilay
2026-11-29  9:32   ` Amir Goldstein
2026-11-29 13:23     ` koraynilay
2026-11-29  2:42 ` [PATCH v3 2/5] vfs: add xflags masks to fileattr API koraynilay
2026-11-29 13:10   ` Lauri Gates
2026-11-29 13:57     ` Amir Goldstein
2026-11-29 14:23   ` Amir Goldstein
2026-11-29 21:44     ` koraynilay
2026-11-29 22:22       ` koraynilay
2026-11-29  2:42 ` [PATCH v3 3/5] vfs: add COMPR/ENCRYPT xflags from FS_COMPR_FL/FS_ENCRYPT_FL koraynilay
2026-11-29 10:11   ` Amir Goldstein
2026-11-29 18:20     ` koraynilay
2026-11-29 21:30       ` Amir Goldstein
2026-11-29 21:55         ` koraynilay
2026-11-29  2:42 ` [PATCH v3 4/5] ntfs: switch to the new xflags fileattr API koraynilay
2026-11-29  9:12   ` Amir Goldstein
2026-11-29 17:51     ` koraynilay
2026-11-29 21:18       ` Amir Goldstein
2026-11-29 22:05         ` koraynilay
2026-11-29 22:20           ` Amir Goldstein
2026-11-29  2:42 ` [PATCH v3 5/5] docs: add fileattr API documentation koraynilay
2026-11-29 11:32   ` Amir Goldstein
2026-11-29 14:19     ` koraynilay
2026-11-29 22:11       ` Amir Goldstein
2026-11-29  2:47 ` [PATCH v3 0/5] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay

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