f2fs_io: add get/set compression option

Added new commands, get_coption and set_coption, to support
F2FS_IOC_GET_COMPRESS_OPTION and F2FS_IOC_SET_COMPRESS_OPTION.

Signed-off-by: Daeho Jeong <daehojeong@google.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Daeho Jeong 2020-11-04 08:36:14 +09:00 committed by Jaegeuk Kim
parent 4bd7008291
commit 1d4c7e7ce5
2 changed files with 70 additions and 0 deletions

View File

@ -992,6 +992,65 @@ static void do_reserve_cblocks(int argc, char **argv, const struct cmd_desc *cmd
exit(0);
}
#define get_coption_desc "get compression option of a compressed file"
#define get_coption_help \
"f2fs_io get_coption [file]\n\n" \
" algorithm : compression algorithm (0:lzo, 1: lz4, 2:zstd, 3:lzorle)\n" \
" log_cluster_size : compression cluster log size (2 <= log_size <= 8)\n"
static void do_get_coption(int argc, char **argv, const struct cmd_desc *cmd)
{
struct f2fs_comp_option option;
int ret, fd;
if (argc != 2) {
fputs("Excess arguments\n\n", stderr);
fputs(cmd->cmd_help, stderr);
exit(1);
}
fd = xopen(argv[1], O_RDONLY, 0);
ret = ioctl(fd, F2FS_IOC_GET_COMPRESS_OPTION, &option);
if (ret < 0)
die_errno("F2FS_IOC_GET_COMPRESS_OPTION failed");
printf("compression algorithm:%u\n", option.algorithm);
printf("compression cluster log size:%u\n", option.log_cluster_size);
exit(0);
}
#define set_coption_desc "set compression option of a compressed file"
#define set_coption_help \
"f2fs_io set_coption [algorithm] [log_cluster_size] [file_path]\n\n" \
" algorithm : compression algorithm (0:lzo, 1: lz4, 2:zstd, 3:lzorle)\n" \
" log_cluster_size : compression cluster log size (2 <= log_size <= 8)\n"
static void do_set_coption(int argc, char **argv, const struct cmd_desc *cmd)
{
struct f2fs_comp_option option;
int fd, ret;
if (argc != 4) {
fputs("Excess arguments\n\n", stderr);
fputs(cmd->cmd_help, stderr);
exit(1);
}
option.algorithm = atoi(argv[1]);
option.log_cluster_size = atoi(argv[2]);
fd = xopen(argv[3], O_WRONLY, 0);
ret = ioctl(fd, F2FS_IOC_SET_COMPRESS_OPTION, &option);
if (ret < 0)
die_errno("F2FS_IOC_SET_COMPRESS_OPTION failed");
printf("set compression option: algorithm=%u, log_cluster_size=%u\n",
option.algorithm, option.log_cluster_size);
exit(0);
}
#define CMD_HIDDEN 0x0001
#define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
@ -1018,6 +1077,8 @@ const struct cmd_desc cmd_list[] = {
CMD(get_cblocks),
CMD(release_cblocks),
CMD(reserve_cblocks),
CMD(get_coption),
CMD(set_coption),
{ NULL, NULL, NULL, NULL, 0 }
};

View File

@ -84,6 +84,10 @@ typedef u32 __be32;
_IOR(F2FS_IOCTL_MAGIC, 18, __u64)
#define F2FS_IOC_RESERVE_COMPRESS_BLOCKS \
_IOR(F2FS_IOCTL_MAGIC, 19, __u64)
#define F2FS_IOC_GET_COMPRESS_OPTION _IOR(F2FS_IOCTL_MAGIC, 21, \
struct f2fs_comp_option)
#define F2FS_IOC_SET_COMPRESS_OPTION _IOW(F2FS_IOCTL_MAGIC, 22, \
struct f2fs_comp_option)
#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
@ -164,3 +168,8 @@ struct f2fs_flush_device {
u32 dev_num; /* device number to flush */
u32 segments; /* # of segments to flush */
};
struct f2fs_comp_option {
u8 algorithm;
u8 log_cluster_size;
};