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. Signed-off-by: koraynilay --- 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; + } +} + /* * 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