aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaeho Jeong2020-10-29 23:10:35 -0500
committerJaegeuk Kim2020-12-21 15:33:11 -0600
commit473a98ef92a14d187e09ea0bf40005e2722a1514 (patch)
treed400cb76af5fd34020577d0d555513c648b4c010
parent4a6741771b58570f6a14b603a0885f2a5e2843e4 (diff)
downloadkernel-473a98ef92a14d187e09ea0bf40005e2722a1514.tar.gz
kernel-473a98ef92a14d187e09ea0bf40005e2722a1514.tar.xz
kernel-473a98ef92a14d187e09ea0bf40005e2722a1514.zip
f2fs: add F2FS_IOC_SET_COMPRESS_OPTION ioctl
Added a new F2FS_IOC_SET_COMPRESS_OPTION ioctl to change file compression option of a file. struct f2fs_comp_option { u8 algorithm; => compression algorithm => 0:lzo, 1:lz4, 2:zstd, 3:lzorle u8 log_cluster_size; => log scale cluster size => 2 ~ 8 }; struct f2fs_comp_option option; option.algorithm = 1; option.log_cluster_size = 7; ioctl(fd, F2FS_IOC_SET_COMPRESS_OPTION, &option); Signed-off-by: Daeho Jeong <daehojeong@google.com> [Chao Yu: remove f2fs_is_compress_algorithm_valid()] Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--fs/f2fs/file.c54
-rw-r--r--include/uapi/linux/f2fs.h2
2 files changed, 56 insertions, 0 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index c747f5dd595c..ea2f1ba408c4 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3972,6 +3972,57 @@ static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg)
3972 return 0; 3972 return 0;
3973} 3973}
3974 3974
3975static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg)
3976{
3977 struct inode *inode = file_inode(filp);
3978 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
3979 struct f2fs_comp_option option;
3980 int ret = 0;
3981
3982 if (!f2fs_sb_has_compression(sbi))
3983 return -EOPNOTSUPP;
3984
3985 if (!(filp->f_mode & FMODE_WRITE))
3986 return -EBADF;
3987
3988 if (copy_from_user(&option, (struct f2fs_comp_option __user *)arg,
3989 sizeof(option)))
3990 return -EFAULT;
3991
3992 if (!f2fs_compressed_file(inode) ||
3993 option.log_cluster_size < MIN_COMPRESS_LOG_SIZE ||
3994 option.log_cluster_size > MAX_COMPRESS_LOG_SIZE ||
3995 option.algorithm >= COMPRESS_MAX)
3996 return -EINVAL;
3997
3998 file_start_write(filp);
3999 inode_lock(inode);
4000
4001 if (f2fs_is_mmap_file(inode) || get_dirty_pages(inode)) {
4002 ret = -EBUSY;
4003 goto out;
4004 }
4005
4006 if (inode->i_size != 0) {
4007 ret = -EFBIG;
4008 goto out;
4009 }
4010
4011 F2FS_I(inode)->i_compress_algorithm = option.algorithm;
4012 F2FS_I(inode)->i_log_cluster_size = option.log_cluster_size;
4013 F2FS_I(inode)->i_cluster_size = 1 << option.log_cluster_size;
4014 f2fs_mark_inode_dirty_sync(inode, true);
4015
4016 if (!f2fs_is_compress_backend_ready(inode))
4017 f2fs_warn(sbi, "compression algorithm is successfully set, "
4018 "but current kernel doesn't support this algorithm.");
4019out:
4020 inode_unlock(inode);
4021 file_end_write(filp);
4022
4023 return ret;
4024}
4025
3975long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 4026long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
3976{ 4027{
3977 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) 4028 if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp)))))
@@ -4062,6 +4113,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
4062 return f2fs_sec_trim_file(filp, arg); 4113 return f2fs_sec_trim_file(filp, arg);
4063 case F2FS_IOC_GET_COMPRESS_OPTION: 4114 case F2FS_IOC_GET_COMPRESS_OPTION:
4064 return f2fs_ioc_get_compress_option(filp, arg); 4115 return f2fs_ioc_get_compress_option(filp, arg);
4116 case F2FS_IOC_SET_COMPRESS_OPTION:
4117 return f2fs_ioc_set_compress_option(filp, arg);
4065 default: 4118 default:
4066 return -ENOTTY; 4119 return -ENOTTY;
4067 } 4120 }
@@ -4233,6 +4286,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
4233 case F2FS_IOC_RESERVE_COMPRESS_BLOCKS: 4286 case F2FS_IOC_RESERVE_COMPRESS_BLOCKS:
4234 case F2FS_IOC_SEC_TRIM_FILE: 4287 case F2FS_IOC_SEC_TRIM_FILE:
4235 case F2FS_IOC_GET_COMPRESS_OPTION: 4288 case F2FS_IOC_GET_COMPRESS_OPTION:
4289 case F2FS_IOC_SET_COMPRESS_OPTION:
4236 break; 4290 break;
4237 default: 4291 default:
4238 return -ENOIOCTLCMD; 4292 return -ENOIOCTLCMD;
diff --git a/include/uapi/linux/f2fs.h b/include/uapi/linux/f2fs.h
index 872e61d78f29..f00199a2e38b 100644
--- a/include/uapi/linux/f2fs.h
+++ b/include/uapi/linux/f2fs.h
@@ -38,6 +38,8 @@
38 struct f2fs_sectrim_range) 38 struct f2fs_sectrim_range)
39#define F2FS_IOC_GET_COMPRESS_OPTION _IOR(F2FS_IOCTL_MAGIC, 21, \ 39#define F2FS_IOC_GET_COMPRESS_OPTION _IOR(F2FS_IOCTL_MAGIC, 21, \
40 struct f2fs_comp_option) 40 struct f2fs_comp_option)
41#define F2FS_IOC_SET_COMPRESS_OPTION _IOW(F2FS_IOCTL_MAGIC, 22, \
42 struct f2fs_comp_option)
41 43
42/* 44/*
43 * should be same as XFS_IOC_GOINGDOWN. 45 * should be same as XFS_IOC_GOINGDOWN.