Re: [PATCH v5 03/12] fs: move fileattr sizes out of uapi and factor out set_preserve()

From: koraynilay

Date: Sat Dec 05 2026 - 18:39:45 EST


On Sat Dec 5, 2026 at 11:15 PM CET, Amir Goldstein wrote:
> On Sat, Dec 5, 2026 at 3:24 PM koraynilay <koray.fra@xxxxxxxxx> wrote:
>>
>> Move FILE_ATTR_SIZE_* constants from the user-facing
>> include/uapi/linux/fs.h to the internal include/linux/fileattr.h.
>>
>> Move old flags preservation from vfs_fileattr_set() to a dedicated
>> helper in preparation for the addition of masks to the fileattr API.
>
> This is a combination of two very random unrelated things so no.
Fair.
> Please move the move of flags to the definition of VER1 unless
> you have a good reason otherwise.
Yeah, I did it like this because the robot suggested it and I thought it
was a fine since it's a preparatory patch.
(Moved the SIZE changes to the uapi patch now)

>
>>
>> Signed-off-by: koraynilay <koray.fra@xxxxxxxxx>
>> ---
>> fs/file_attr.c | 26 +++++++++++++++++---------
>> include/linux/fileattr.h | 4 ++++
>> include/uapi/linux/fs.h | 3 ---
>> 3 files changed, 21 insertions(+), 12 deletions(-)
>>
>> diff --git a/fs/file_attr.c b/fs/file_attr.c
>> index cc1621d3b710..77e2f1bc22ad 100644
>> --- a/fs/file_attr.c
>> +++ b/fs/file_attr.c
>> @@ -175,6 +175,22 @@ static int copy_fsxattr_from_user(struct file_kattr *fa,
>> return 0;
>> }
>>
>> +static void fileattr_set_preserve(struct file_kattr *fa,
>> + const struct file_kattr *old_ma)
>> +{
>> + if (fa->flags_valid) {
>> + /* FS_IOC_SETFLAGS */
>> + fa->fsx_xflags |= old_ma->fsx_xflags & ~FSX_COMMON;
>> + fa->fsx_extsize = old_ma->fsx_extsize;
>> + fa->fsx_nextents = old_ma->fsx_nextents;
>> + fa->fsx_projid = old_ma->fsx_projid;
>> + fa->fsx_cowextsize = old_ma->fsx_cowextsize;
>> + } else {
>> + /* FS_IOC_FSSETXATTR or file_setattr */
>> + fa->flags |= old_ma->flags & ~FS_COMMON_FL;
>> + }
>> +}
>> +
>
>
> Excellent way to make the code more readable and break into
Nice.
> understandable pieces but this non trivial helpers needs a comment to
> explain what it does, similar to the not trivial comment that you added
> above FSX_COMMON.
Ah yeah, makes sense.

Thanks,
koraynilay
>
> Thanks,
> Amir.
>
>> /*
>> * Generic function to check FS_IOC_FSSETXATTR/FS_IOC_SETFLAGS values and reject
>> * any invalid configurations.
>> @@ -289,15 +305,7 @@ int vfs_fileattr_set(const struct mnt_idmap *idmap, struct dentry *dentry,
>> goto out;
>>
>> /* initialize missing bits from old_ma */
>> - if (fa->flags_valid) {
>> - fa->fsx_xflags |= old_ma.fsx_xflags & ~FSX_COMMON;
>> - fa->fsx_extsize = old_ma.fsx_extsize;
>> - fa->fsx_nextents = old_ma.fsx_nextents;
>> - fa->fsx_projid = old_ma.fsx_projid;
>> - fa->fsx_cowextsize = old_ma.fsx_cowextsize;
>> - } else {
>> - fa->flags |= old_ma.flags & ~FS_COMMON_FL;
>> - }
>> + fileattr_set_preserve(fa, &old_ma);
>>
>> err = fileattr_set_prepare(inode, &old_ma, fa);
>> if (err)
>> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
>> index 79371aa93a61..d9e89e171f3e 100644
>> --- a/include/linux/fileattr.h
>> +++ b/include/linux/fileattr.h
>> @@ -3,6 +3,10 @@
>> #ifndef _LINUX_FILEATTR_H
>> #define _LINUX_FILEATTR_H
>>
>> +/* Version UAPI's struct file_attr based on size */
>> +#define FILE_ATTR_SIZE_VER0 24
>> +#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
>> +
>> /*
>> * FS_COMMON_FL/FSX_COMMON are preserved through an RMW cycle via either UAPI
>> * flavor. They must NOT include flags that are read-write via one API flavor
>> diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h
>> index a13c7b32a1bd..f77e2b929f6d 100644
>> --- a/include/uapi/linux/fs.h
>> +++ b/include/uapi/linux/fs.h
>> @@ -240,9 +240,6 @@ struct file_attr {
>> __u32 fa_cowextsize; /* CoW extsize field value (get/set) */
>> };
>>
>> -#define FILE_ATTR_SIZE_VER0 24
>> -#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
>> -
>> /*
>> * Flags for the fsx_xflags field
>> */
>> --
>> 2.56.1.dirty
>>


Attachment: signature.asc
Description: PGP signature