Linux Overlay Filesystem development
 help / color / mirror / Atom feed
From: "koraynilay" <koray.fra@gmail.com>
To: "Amir Goldstein" <amir73il@gmail.com>,
	"koraynilay" <koray.fra@gmail.com>
Cc: "Namjae Jeon" <linkinjeon@kernel.org>,
	"Hyunchul Lee" <hyc.lee@gmail.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Theodore Y . Ts'o" <tytso@mit.edu>,
	"Jaegeuk Kim" <jaegeuk@kernel.org>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Christian Brauner" <brauner@kernel.org>,
	"Shuah Khan" <skhan@linuxfoundation.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"Chuck Lever" <cel@kernel.org>,
	"Jeff Layton" <jlayton@kernel.org>, "Jan Kara" <jack@suse.cz>,
	"Alexander Aring" <alex.aring@gmail.com>,
	"Darrick J . Wong" <djwong@kernel.org>,
	"Andrey Albershteyn" <aalbersh@kernel.org>,
	"Miklos Szeredi" <miklos@szeredi.hu>,
	"Pali Rohár" <pali@kernel.org>,
	"Lauri Gates" <lauri.gates@gmail.com>,
	"Christoph Hellwig" <hch@infradead.org>,
	"Dave Chinner" <dgc@kernel.org>,
	linux-btrfs@vger.kernel.org, linux-xfs@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	ntfs@lists.linux.dev, linux-nfs@vger.kernel.org,
	linux-api@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-unionfs@vger.kernel.org
Subject: Re: [PATCH v5 06/12] fs: add UAPI implementation of xflags masks to fileattr API
Date: Sun, 06 Dec 2026 16:08:47 +0100	[thread overview]
Message-ID: <DNDQTER17V4M.2U3K414GUIMNV@gmail.com> (raw)
In-Reply-To: <CAOQ4uxg00KrZjvDTOiA16treyPU2cqGVERD10+fOj8TJzcgFQA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 10649 bytes --]

On Sun Dec 6, 2026 at 2:40 PM CET, Amir Goldstein wrote:
> On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>>
>> Add fa_xflags_rw_mask and fa_xflags_ro_mask to struct file_attr, both
>> __u64 to match fa_xflags' size, and bump FILE_ATTR_SIZE_LATEST to
>> FILE_ATTR_SIZE_VER1.
>>
>> Add FSX_FILEATTR_MASK macro to define VER1+ xflags, even though we have
>> none yet, since it makes the code clearer.
>>
>> Add AT_FILEATTR_MASKS at_flags option that userspace needs to pass
>> (with usize >= FILE_ATTR_SIZE_VER1) in order to be able to use masks,
>> otherwise normal FS_IOC_FSSETXATTR semantics are used.
>>
>> Without AT_FILEATTR_MASKS:
>> - on GET: set fa_xflags_rw_mask and fa_xflags_ro_mask to 0 and strip new
>>   xflags added in or after VER1, so older programs doing RMW don't pass
>>   them back on SET;
>> - on SET: reject the operation with -EINVAL if fa_xflags_rw_mask or
>>   fa_xflags_ro_mask is non-zero; if they're zero, convert the input as
>>   necessary for masks filesystems or do normal RMW for non-masks
>>   filesystems.
>>
>> With AT_FILEATTR_MASKS:
>> - on GET: if the filesystem supports masks, they will be filled,
>>   otherwise they will be zero, either way return the full struct;
>> - on SET: convert the input as necessary for non-masks filesystems or
>>   pass the input directly to the filesystem if it supports masks; if the
>>   rw_mask is 0, reject it with -EINVAL; also reject with -EINVAL if a
>>   value xflag is in fa_xflags_rw_mask and it's cleared in fa_xflags, but
>>   the value field is non-zero.
>>
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>>  fs/file_attr.c             | 104 ++++++++++++++++++++++++++++++-------
>>  include/linux/fileattr.h   |   9 +++-
>>  include/uapi/linux/fcntl.h |   6 +++
>>  include/uapi/linux/fs.h    |  31 ++++++++++-
>>  4 files changed, 127 insertions(+), 23 deletions(-)
>>
>> diff --git a/fs/file_attr.c b/fs/file_attr.c
>> index 2cc06b5117f8..8b9785447e72 100644
>> --- a/fs/file_attr.c
>> +++ b/fs/file_attr.c
>> @@ -116,10 +116,10 @@ int vfs_fileattr_get(struct dentry *dentry, struct file_kattr *fa)
>>                 return error;
>>
>>         if (fa->has_masks) {
>> -               fa->fsx_xflags_rw_mask &= FSX_FSXATTR_MASK;
>> -               fa->fsx_xflags_ro_mask &= FSX_FSXATTR_MASK;
>> +               fa->fsx_xflags_rw_mask &= FSX_FILEATTR_MASK;
>> +               fa->fsx_xflags_ro_mask &= FSX_FILEATTR_MASK;
>>         }
>> -       fa->fsx_xflags &= FSX_FSXATTR_MASK;
>> +       fa->fsx_xflags &= FSX_FILEATTR_MASK;
>>
>>         return 0;
>>  }
>> @@ -128,10 +128,13 @@ EXPORT_SYMBOL(vfs_fileattr_get);
>>  static void fileattr_to_file_attr(const struct file_kattr *fa,
>>                                   struct file_attr *fattr)
>>  {
>> -       __u32 mask = FSX_FSXATTR_MASK;
>> -
>>         memset(fattr, 0, sizeof(struct file_attr));
>> -       fattr->fa_xflags = fa->fsx_xflags & mask;
>> +       /* Pass the masks to userspace if underlying fs uses them. */
>> +       if (fa->has_masks) {
>> +               fattr->fa_xflags_rw_mask = fa->fsx_xflags_rw_mask;
>> +               fattr->fa_xflags_ro_mask = fa->fsx_xflags_ro_mask;
>> +       }
>> +       fattr->fa_xflags = fa->fsx_xflags;
>>         fattr->fa_extsize = fa->fsx_extsize;
>>         fattr->fa_nextents = fa->fsx_nextents;
>>         fattr->fa_projid = fa->fsx_projid;
>> @@ -167,15 +170,50 @@ EXPORT_SYMBOL(copy_fsxattr_to_user);
>>  static int file_attr_to_fileattr(const struct file_attr *fattr,
>>                                  struct file_kattr *fa)
>>  {
>> -       __u64 mask = FSX_FSXATTR_MASK;
>> +       bool use_masks = fa->use_masks && fa->has_masks;
>> +       u64 mask = use_masks ? FSX_FILEATTR_MASK : FSX_FSXATTR_MASK;
>> +       u64 rw_user_mask = fattr->fa_xflags_rw_mask;
>>
>>         if (fattr->fa_xflags & ~mask)
>>                 return -EINVAL;
>>
>> -       fileattr_fill_xflags(fa, fattr->fa_xflags & ~FSX_RDONLY_MASK);
>> -       fa->fsx_extsize = fattr->fa_extsize;
>> -       fa->fsx_projid = fattr->fa_projid;
>> -       fa->fsx_cowextsize = fattr->fa_cowextsize;
>> +       if (!use_masks) {
>> +               fileattr_fill_xflags(fa, fattr->fa_xflags & ~FSX_RDONLY_MASK);
>> +               fa->fsx_extsize = fattr->fa_extsize;
>> +               fa->fsx_projid = fattr->fa_projid;
>> +               fa->fsx_cowextsize = fattr->fa_cowextsize;
>> +               return 0;
>> +       }
>> +
>> +       if (rw_user_mask & ~FSX_FILEATTR_MASK)
>> +               return -EINVAL;
>> +
>> +       /*
>> +        * Pass xflags clamped to the rw_mask, so the rest of the code can
>> +        * assume that if a flag is not in fsx_xflags, it isn't being changed.
>> +        */
>> +       fileattr_fill_xflags(fa, fattr->fa_xflags & rw_user_mask);
>> +       fa->fsx_xflags_rw_mask = rw_user_mask;
>> +
>> +       /*
>> +        * For value attributes, clearing the xflag bit in fa_xflags while
>> +        * selecting it in rw_mask requires the field value to be 0, to prevent
>> +        * accidental resets.
>> +        */
>> +       if (fa->fsx_xflags & FSX_EXTSIZE_MASK)
>> +               fa->fsx_extsize = fattr->fa_extsize;
>> +       else if ((rw_user_mask & FSX_EXTSIZE_MASK) &&
>> +                fattr->fa_extsize)
>
> nit: this line break seems unneeded and break the flow
> FS_XFLAG_COWEXTSIZE doesn't do it
>
>> +               return -EINVAL;
>> +       else
>> +               fa->fsx_extsize = 0;
>> +
>> +       if (fa->fsx_xflags & FS_XFLAG_COWEXTSIZE)
>> +               fa->fsx_cowextsize = fattr->fa_cowextsize;
>> +       else if ((rw_user_mask & FS_XFLAG_COWEXTSIZE) && fattr->fa_cowextsize)
>> +               return -EINVAL;
>> +       else
>> +               fa->fsx_cowextsize = 0;
>>
>>         return 0;
>>  }
>> @@ -377,7 +415,7 @@ static int fileattr_set_prepare(struct inode *inode,
>>                               struct file_kattr *fa)
>>  {
>>         u32 rw_user_mask = fa->has_masks ?
>> -                          fa->fsx_xflags_rw_mask : FSX_FSXATTR_MASK;
>> +                          fa->fsx_xflags_rw_mask : FSX_FILEATTR_MASK;
>>         u32 changed = 0;
>>         int err;
>>
>> @@ -593,7 +631,8 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
>>         BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
>>         BUILD_BUG_ON(sizeof(struct file_attr) != FILE_ATTR_SIZE_LATEST);
>>
>> -       if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
>> +       if ((at_flags &
>> +            ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH | AT_FILEATTR_MASKS)) != 0)
>>                 return -EINVAL;
>>
>>         if (!(at_flags & AT_SYMLINK_NOFOLLOW))
>> @@ -602,7 +641,10 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
>>         if (usize > PAGE_SIZE)
>>                 return -E2BIG;
>>
>> -       if (usize < FILE_ATTR_SIZE_VER0)
>> +       if (usize != FILE_ATTR_SIZE_VER0 && usize < FILE_ATTR_SIZE_VER1)
>> +               return -EINVAL;
>> +
>> +       if ((at_flags & AT_FILEATTR_MASKS) && usize < FILE_ATTR_SIZE_VER1)
>>                 return -EINVAL;
>>
>>         CLASS(filename_maybe_null, name)(filename, at_flags);
>> @@ -627,6 +669,17 @@ SYSCALL_DEFINE5(file_getattr, int, dfd, const char __user *, filename,
>>                 return error;
>>
>>         fileattr_to_file_attr(&fa, &fattr);
>> +       /*
>> +        * Caller doesn't know about masks, so it also doesn't know about
>> +        * xflags added in or after VER1.
>> +        * Zero out the masks and strip VER1+ xflags.
>> +        */
>> +       if (!(at_flags & AT_FILEATTR_MASKS)) {
>> +               fattr.fa_xflags &= FSX_FSXATTR_MASK;
>> +               fattr.fa_xflags_rw_mask = 0;
>> +               fattr.fa_xflags_ro_mask = 0;
>> +       }
>> +
>>         error = copy_struct_to_user(ufattr, usize, &fattr,
>>                                     sizeof(struct file_attr), NULL);
>>
>> @@ -646,7 +699,8 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
>>         BUILD_BUG_ON(sizeof(struct file_attr) < FILE_ATTR_SIZE_VER0);
>>         BUILD_BUG_ON(sizeof(struct file_attr) != FILE_ATTR_SIZE_LATEST);
>>
>> -       if ((at_flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
>> +       if ((at_flags &
>> +            ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH | AT_FILEATTR_MASKS)) != 0)
>>                 return -EINVAL;
>>
>>         if (!(at_flags & AT_SYMLINK_NOFOLLOW))
>> @@ -655,7 +709,10 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
>>         if (usize > PAGE_SIZE)
>>                 return -E2BIG;
>>
>> -       if (usize < FILE_ATTR_SIZE_VER0)
>> +       if (usize != FILE_ATTR_SIZE_VER0 && usize < FILE_ATTR_SIZE_VER1)
>> +               return -EINVAL;
>> +
>> +       if ((at_flags & AT_FILEATTR_MASKS) && usize < FILE_ATTR_SIZE_VER1)
>>                 return -EINVAL;
>>
>>         error = copy_struct_from_user(&fattr, sizeof(struct file_attr), ufattr,
>> @@ -663,9 +720,9 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
>>         if (error)
>>                 return error;
>>
>> -       error = file_attr_to_fileattr(&fattr, &fa);
>> -       if (error)
>> -               return error;
>> +       if (!(at_flags & AT_FILEATTR_MASKS) &&
>> +           (fattr.fa_xflags_rw_mask || fattr.fa_xflags_ro_mask))
>> +               return -EINVAL;
>>
>>         CLASS(filename_maybe_null, name)(filename, at_flags);
>>         if (!name && dfd >= 0) {
>> @@ -682,6 +739,15 @@ SYSCALL_DEFINE5(file_setattr, int, dfd, const char __user *, filename,
>>                         return error;
>>         }
>>
>> +       if (at_flags & AT_FILEATTR_MASKS) {
>> +               fa.has_masks = true;
>> +               fa.use_masks = true;
>> +       }
>> +
>> +       error = file_attr_to_fileattr(&fattr, &fa);
>> +       if (error)
>> +               return error;
>> +
>
> What is the reason to move this call after the path lookup?
> It changes the user visible error for invalid input, e.g. invalid
> fa_xflags on a non-existing path now returns ENOENT instead of EINVAL.
>
> I see no reason to do it and it is inconsistent with the get syscall.

Right, it was leftover from before adding AT_FILEATTR_MASKS, removed.

> With those monir comments fixed you may add
>
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>
>

Thanks,
koraynilay

> Thanks,
> Amir.



[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

  reply	other threads:[~2026-12-06 15:08 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 14:23 [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API koraynilay
2026-12-05 14:24 ` [PATCH v5 01/12] fs: use goto out on error in vfs_fileattr_set() koraynilay
2026-12-05 14:24 ` [PATCH v5 02/12] fs,overlayfs: rename FS_XFLAGS_MASK and shorten other internal macro names koraynilay
2026-12-05 20:09   ` Amir Goldstein
2026-12-05 22:42     ` koraynilay
2026-12-05 14:24 ` [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve() koraynilay
2026-12-05 22:15   ` Amir Goldstein
2026-12-05 23:39     ` koraynilay
2026-12-06 13:49       ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 04/12] fs: switch fileattr_set_prepare() to xflags and refactor projid check koraynilay
2026-12-06 12:19   ` Amir Goldstein
2026-12-06 14:00     ` koraynilay
2026-12-06 14:04       ` Amir Goldstein
2026-12-06 14:07         ` koraynilay
2026-12-05 14:24 ` [PATCH v5 05/12] fs: add initial implementation of xflags masks to fileattr API koraynilay
2026-12-06 13:22   ` Amir Goldstein
2026-12-06 13:47     ` Amir Goldstein
2026-12-06 14:05     ` koraynilay
2026-12-06 14:12       ` Amir Goldstein
2026-12-06 14:29         ` koraynilay
2026-12-05 14:24 ` [PATCH v5 06/12] fs: add UAPI " koraynilay
2026-12-06 13:40   ` Amir Goldstein
2026-12-06 15:08     ` koraynilay [this message]
2026-12-05 14:24 ` [PATCH v5 07/12] fs: add missing FS_XFLAG_PROJID xflag koraynilay
2026-12-05 22:08   ` Amir Goldstein
2026-12-05 23:34     ` koraynilay
2026-12-05 14:24 ` [PATCH v5 08/12] fs,overlayfs: add fileattr masks support on get koraynilay
2026-12-05 21:42   ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 09/12] fs,ntfs: advertise COMPR/ENCRYPT xflags in file_getattr() koraynilay
2026-12-05 20:21   ` Amir Goldstein
2026-12-05 20:41     ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 10/12] ntfs: switch from flags to xflags in ntfs_fileattr_get/set() koraynilay
2026-12-05 20:25   ` Amir Goldstein
2026-12-05 21:31     ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 11/12] ntfs: support the fileattr API masks " koraynilay
2026-12-05 21:15   ` Amir Goldstein
2026-12-05 14:24 ` [PATCH v5 12/12] docs: add fileattr API documentation koraynilay
2026-12-05 21:14   ` Amir Goldstein
2026-12-05 22:24     ` koraynilay
2026-12-06 14:08       ` Amir Goldstein
2026-12-06 14:01 ` [PATCH v5 00/12] Add f*_xflags_{rw,ro}_mask flags to the fileattr API Amir Goldstein
2026-12-06 14:18   ` koraynilay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DNDQTER17V4M.2U3K414GUIMNV@gmail.com \
    --to=koray.fra@gmail.com \
    --cc=aalbersh@kernel.org \
    --cc=alex.aring@gmail.com \
    --cc=amir73il@gmail.com \
    --cc=brauner@kernel.org \
    --cc=cel@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dgc@kernel.org \
    --cc=djwong@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=hch@infradead.org \
    --cc=hyc.lee@gmail.com \
    --cc=jack@suse.cz \
    --cc=jaegeuk@kernel.org \
    --cc=jlayton@kernel.org \
    --cc=lauri.gates@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=ntfs@lists.linux.dev \
    --cc=pali@kernel.org \
    --cc=rdunlap@infradead.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox