Linux Btrfs 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 07/12] fs: add missing FS_XFLAG_PROJID xflag
Date: Sun, 06 Dec 2026 00:34:54 +0100	[thread overview]
Message-ID: <DND6YDOL0ZNG.R3W78UPSIB7@gmail.com> (raw)
In-Reply-To: <CAOQ4uxhX6jOwMJ=NEi25QvUG2Rb4LVg2zFO7nKqYLDUoB1SR8A@mail.gmail.com>

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

On Sat Dec 5, 2026 at 11:08 PM CET, Amir Goldstein wrote:
> On Sat, Dec 5, 2026 at 3:25 PM koraynilay <koray.fra@gmail.com> wrote:
>>
>> Add FS_XFLAG_PROJID to the UAPI header and include it in
>> FSX_FILEATTR_MASK so file_[gs]etattr() with AT_FILEATTR_MASKS can
>> advertise, set and clear the project ID using masks, while keeping it
>> out of FS_IOC_FS[GS]ETXATTR and non-AT_FILEATTR_MASKS callers.
>>
>> Add FSX_FSXATTR_SET_MASK to specify xflags that are settable by
>> file_setattr with masks on non-masks filesystems. This macro is then
>> used to validate input xflags in fileattr_set_from_masks().
>>
>> Signed-off-by: koraynilay <koray.fra@gmail.com>
>> ---
>>  fs/file_attr.c           | 32 ++++++++++++++++++++++++++------
>>  include/linux/fileattr.h | 12 +++++++++++-
>>  include/uapi/linux/fs.h  |  6 ++++--
>>  3 files changed, 41 insertions(+), 9 deletions(-)
>>
>> diff --git a/fs/file_attr.c b/fs/file_attr.c
>> index 8b9785447e72..7bfd7651d1d8 100644
>> --- a/fs/file_attr.c
>> +++ b/fs/file_attr.c
>> @@ -138,6 +138,8 @@ static void fileattr_to_file_attr(const struct file_kattr *fa,
>>         fattr->fa_extsize = fa->fsx_extsize;
>>         fattr->fa_nextents = fa->fsx_nextents;
>>         fattr->fa_projid = fa->fsx_projid;
>> +       if (fa->fsx_projid)
>> +               fattr->fa_xflags |= FS_XFLAG_PROJID;
>>         fattr->fa_cowextsize = fa->fsx_cowextsize;
>>  }
>>
>> @@ -208,6 +210,13 @@ static int file_attr_to_fileattr(const struct file_attr *fattr,
>>         else
>>                 fa->fsx_extsize = 0;
>>
>> +       if (fa->fsx_xflags & FS_XFLAG_PROJID)
>> +               fa->fsx_projid = fattr->fa_projid;
>> +       else if ((rw_user_mask & FS_XFLAG_PROJID) && fattr->fa_projid)
>> +               return -EINVAL;
>> +       else
>> +               fa->fsx_projid = 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)
>> @@ -290,8 +299,11 @@ static int fileattr_set_to_masks(struct file_kattr *fa,
>>                 if (fa->fsx_extsize != old_ma->fsx_extsize)
>>                         new_rw_mask |= new_xflags & FSX_EXTSIZE_MASK;
>>
>> -               if (fa->fsx_projid != old_ma->fsx_projid)
>> -                       return -EOPNOTSUPP;
>> +               if (fa->fsx_projid != old_ma->fsx_projid) {
>> +                       new_rw_mask |= FS_XFLAG_PROJID;
>> +                       if (fa->fsx_projid > 0)
>> +                               new_xflags |= FS_XFLAG_PROJID;
>
> Where did this > 0 come from
It came from me checking > 0 for all 3 fields, which then I removed but
didn't think of changing this one.
> All other places including fileattr_fsx_ok() treat this as
> if (fa->fsx_projid) or
Yes I agree that's better, changed.
> if (fa->fsx_projid != 0)
> if you want the uglier version of fileattr_has_fsx()
> which I anyway suggested to convert to use fileattr_fsx_ok().
>
> Other than this nit, nice readable patch, so:
>
> Reviewed-by: Amir Goldstein <amir73il@gmail.com>

Thanks,
koraynilay

> Thanks,
> Amir.
>
>
>> +               }
>>
>>                 if ((new_xflags & FS_XFLAG_COWEXTSIZE) &&
>>                     fa->fsx_cowextsize != old_ma->fsx_cowextsize)
>> @@ -326,14 +338,14 @@ static int fileattr_set_from_masks(struct file_kattr *fa,
>>         u32 new_xflags = fa->fsx_xflags;
>>         u32 new_flags = 0;
>>
>> -       if (rw_user_mask & ~(FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK))
>> +       if (rw_user_mask & ~FSX_FSXATTR_SET_MASK)
>>                 return -EOPNOTSUPP;
>>
>>         /* Do RMW. */
>>         new_xflags |= old_ma->fsx_xflags & ~rw_user_mask;
>>
>>         /* RMW filesystems only expect writable fsxattr xflags. */
>> -       new_xflags &= FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK;
>> +       new_xflags &= FSX_FSXATTR_SET_MASK;
>>
>>         new_flags = xflags_to_flags(new_xflags);
>>         new_flags |= old_ma->flags & ~FS_COMMON_FL;
>> @@ -357,7 +369,12 @@ static int fileattr_set_from_masks(struct file_kattr *fa,
>>                 }
>>         }
>>
>> -       fa->fsx_projid = old_ma->fsx_projid;
>> +       if (!(rw_user_mask & FS_XFLAG_PROJID))
>> +               fa->fsx_projid = old_ma->fsx_projid;
>> +       else if (!(fa->fsx_xflags & FS_XFLAG_PROJID))
>> +               fa->fsx_projid = 0;
>> +       /* Strip PROJID now that we've used it, old format doesn't have it. */
>> +       new_xflags &= ~FS_XFLAG_PROJID;
>>
>>         if (!(rw_user_mask & FS_XFLAG_COWEXTSIZE))
>>                 fa->fsx_cowextsize = old_ma->fsx_cowextsize;
>> @@ -443,7 +460,8 @@ static int fileattr_set_prepare(struct inode *inode,
>>          * namespace. Enforce that restriction only if we are trying to change
>>          * the quota ID state. Everything else is allowed in user namespaces.
>>          */
>> -       if (!fa->has_masks && old_ma->fsx_projid != fa->fsx_projid) {
>> +       if ((rw_user_mask & FS_XFLAG_PROJID) &&
>> +           old_ma->fsx_projid != fa->fsx_projid) {
>>                 /* Caller is not allowed to change the project ID. */
>>                 if (current_user_ns() != &init_user_ns)
>>                         return -EINVAL;
>> @@ -488,6 +506,8 @@ static int fileattr_set_prepare(struct inode *inode,
>>                 fa->fsx_xflags &= ~FSX_EXTSIZE_MASK;
>>         if (fa->fsx_cowextsize == 0)
>>                 fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
>> +       if (fa->fsx_projid == 0)
>> +               fa->fsx_xflags &= ~FS_XFLAG_PROJID;
>>
>>         return 0;
>>  }
>> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
>> index adb586e21fd5..8dcabbb294fa 100644
>> --- a/include/linux/fileattr.h
>> +++ b/include/linux/fileattr.h
>> @@ -52,9 +52,19 @@
>>         (FSX_COMMON | FSX_RDONLY_MASK | FSX_VALUES_MASK | \
>>          FSX_DIRONLY_MASK | FSX_MISC_MASK)
>>
>> +/*
>> + * Writable xflags for filesystems that don't support masks.
>> + * The VFS converts masked requests to FS_IOC_FSSETXATTR format, which lacks
>> + * FS_XFLAG_PROJID and uses only file_kattr.fsx_projid instead.
>> + * Include FS_XFLAG_PROJID here so masked callers can use it to select project
>> + * ID changes on unmasked filesystems.
>> + */
>> +#define FSX_FSXATTR_SET_MASK \
>> +       ((FSX_FSXATTR_MASK & ~FSX_RDONLY_MASK) | FS_XFLAG_PROJID)
>> +
>>  /* All xflags supported by VER1+ file_[gs]etattr() with AT_FILEATTR_MASKS */
>>  #define FSX_FILEATTR_MASK \
>> -       (FSX_FSXATTR_MASK)
>> +       (FSX_FSXATTR_MASK | FS_XFLAG_PROJID)
>>
>>  /*
>>   * Merged interface for miscellaneous file attributes.  'flags' originates from
>> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
>> index d402db1a2254..337bb00b0e64 100644
>> --- a/include/uapi/linux/fs.h
>> +++ b/include/uapi/linux/fs.h
>> @@ -236,8 +236,8 @@ struct fsxattr {
>>   *              suggests a preferred extent size for new allocations. (in/out)
>>   * @fa_nextents: Number of data extents in the file, read-only. Filled in by
>>   *               file_getattr(2) and ignored by file_setattr(2). (out)
>> - * @fa_projid: Project identifier. Used by quota systems quotactl(2) to group
>> - *             related files. (in/out)
>> + * @fa_projid: Project identifier, value of FS_XFLAG_PROJID. Used by quota
>> + *             systems quotactl(2) to group related files. (in/out)
>>   * @fa_cowextsize: Copy-on-Write (CoW) extent size hint in bytes, value of
>>   *                 FS_XFLAG_COWEXTSIZE. This value suggests a preferred extent
>>   *                 size for CoW operations. (in/out)
>> @@ -294,6 +294,8 @@ struct file_attr {
>>   */
>>  #define FS_XFLAG_CASEFOLD      0x00040000      /* case-insensitive lookups */
>>  #define FS_XFLAG_CASENONPRESERVING 0x00080000  /* case not preserved */
>> +#define FS_XFLAG_PROJID                0x00100000      /* project ID */
>> +
>>  #define FS_XFLAG_HASATTR       0x80000000      /* no DIFLAG for this   */
>>
>>  /* the read-only stuff doesn't really belong here, but any other place is
>> --
>> 2.56.1.dirty
>>



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

  reply	other threads:[~2026-12-05 23:34 UTC|newest]

Thread overview: 27+ 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-05 14:24 ` [PATCH v5 04/12] fs: switch fileattr_set_prepare() to xflags and refactor projid check koraynilay
2026-12-05 14:24 ` [PATCH v5 05/12] fs: add initial implementation of xflags masks to fileattr API koraynilay
2026-12-05 14:24 ` [PATCH v5 06/12] fs: add UAPI " koraynilay
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 [this message]
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

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=DND6YDOL0ZNG.R3W78UPSIB7@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