Commit 6fc93c4e authored by Eric Biggers's avatar Eric Biggers Committed by Jaegeuk Kim

f2fs: use generic checking function for FS_IOC_FSSETXATTR

Make the f2fs implementation of FS_IOC_FSSETXATTR use the new VFS helper
function vfs_ioc_fssetxattr_check(), and remove the project quota check
since it's now done by the helper function.

This is based on a patch from Darrick Wong, but reworked to apply after
commit 36098557 ("f2fs: separate f2fs i_flags from fs_flags and ext4
i_flags").

Originally-from: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarEric Biggers <ebiggers@google.com>
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent a1f32eec
...@@ -2862,52 +2862,32 @@ static inline u32 f2fs_xflags_to_iflags(u32 xflags) ...@@ -2862,52 +2862,32 @@ static inline u32 f2fs_xflags_to_iflags(u32 xflags)
return iflags; return iflags;
} }
static int f2fs_ioc_fsgetxattr(struct file *filp, unsigned long arg) static void f2fs_fill_fsxattr(struct inode *inode, struct fsxattr *fa)
{ {
struct inode *inode = file_inode(filp);
struct f2fs_inode_info *fi = F2FS_I(inode); struct f2fs_inode_info *fi = F2FS_I(inode);
struct fsxattr fa;
memset(&fa, 0, sizeof(struct fsxattr)); simple_fill_fsxattr(fa, f2fs_iflags_to_xflags(fi->i_flags));
fa.fsx_xflags = f2fs_iflags_to_xflags(fi->i_flags);
if (f2fs_sb_has_project_quota(F2FS_I_SB(inode))) if (f2fs_sb_has_project_quota(F2FS_I_SB(inode)))
fa.fsx_projid = (__u32)from_kprojid(&init_user_ns, fa->fsx_projid = from_kprojid(&init_user_ns, fi->i_projid);
fi->i_projid);
if (copy_to_user((struct fsxattr __user *)arg, &fa, sizeof(fa)))
return -EFAULT;
return 0;
} }
static int f2fs_ioctl_check_project(struct inode *inode, struct fsxattr *fa) static int f2fs_ioc_fsgetxattr(struct file *filp, unsigned long arg)
{ {
/* struct inode *inode = file_inode(filp);
* Project Quota ID state is only allowed to change from within the init struct fsxattr fa;
* namespace. Enforce that restriction only if we are trying to change
* the quota ID state. Everything else is allowed in user namespaces.
*/
if (current_user_ns() == &init_user_ns)
return 0;
if (__kprojid_val(F2FS_I(inode)->i_projid) != fa->fsx_projid)
return -EINVAL;
if (F2FS_I(inode)->i_flags & F2FS_PROJINHERIT_FL) { f2fs_fill_fsxattr(inode, &fa);
if (!(fa->fsx_xflags & FS_XFLAG_PROJINHERIT))
return -EINVAL;
} else {
if (fa->fsx_xflags & FS_XFLAG_PROJINHERIT)
return -EINVAL;
}
if (copy_to_user((struct fsxattr __user *)arg, &fa, sizeof(fa)))
return -EFAULT;
return 0; return 0;
} }
static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg) static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg)
{ {
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
struct fsxattr fa; struct fsxattr fa, old_fa;
u32 iflags; u32 iflags;
int err; int err;
...@@ -2930,9 +2910,12 @@ static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg) ...@@ -2930,9 +2910,12 @@ static int f2fs_ioc_fssetxattr(struct file *filp, unsigned long arg)
return err; return err;
inode_lock(inode); inode_lock(inode);
err = f2fs_ioctl_check_project(inode, &fa);
f2fs_fill_fsxattr(inode, &old_fa);
err = vfs_ioc_fssetxattr_check(inode, &old_fa, &fa);
if (err) if (err)
goto out; goto out;
err = f2fs_setflags_common(inode, iflags, err = f2fs_setflags_common(inode, iflags,
f2fs_xflags_to_iflags(F2FS_SUPPORTED_XFLAGS)); f2fs_xflags_to_iflags(F2FS_SUPPORTED_XFLAGS));
if (err) if (err)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment