linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] f2fs_io: add get/set compression option
@ 2020-11-02  0:29 Daeho Jeong
  2020-11-02 16:16 ` Jaegeuk Kim
  0 siblings, 1 reply; 2+ messages in thread
From: Daeho Jeong @ 2020-11-02  0:29 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Daeho Jeong

From: Daeho Jeong <daehojeong@google.com>

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>
---
 tools/f2fs_io/f2fs_io.c | 61 +++++++++++++++++++++++++++++++++++++++++
 tools/f2fs_io/f2fs_io.h |  9 ++++++
 2 files changed, 70 insertions(+)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 5a2d06e..dab0d14 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -905,6 +905,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_RDONLY, 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 }
@@ -930,6 +989,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 }
 };
 
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index 05d4cfe..cb56e8c 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -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;
+};
-- 
2.29.1.341.ge80a0c044ae-goog



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [f2fs-dev] [PATCH] f2fs_io: add get/set compression option
  2020-11-02  0:29 [f2fs-dev] [PATCH] f2fs_io: add get/set compression option Daeho Jeong
@ 2020-11-02 16:16 ` Jaegeuk Kim
  0 siblings, 0 replies; 2+ messages in thread
From: Jaegeuk Kim @ 2020-11-02 16:16 UTC (permalink / raw)
  To: Daeho Jeong; +Cc: Daeho Jeong, linux-f2fs-devel

On 11/02, Daeho Jeong wrote:
> From: Daeho Jeong <daehojeong@google.com>
> 
> 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>
> ---
>  tools/f2fs_io/f2fs_io.c | 61 +++++++++++++++++++++++++++++++++++++++++
>  tools/f2fs_io/f2fs_io.h |  9 ++++++
>  2 files changed, 70 insertions(+)
> 
> diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
> index 5a2d06e..dab0d14 100644
> --- a/tools/f2fs_io/f2fs_io.c
> +++ b/tools/f2fs_io/f2fs_io.c
> @@ -905,6 +905,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_RDONLY, 0);

O_WRONLY?

> +
> +	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 }
> @@ -930,6 +989,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 }
>  };
>  
> diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
> index 05d4cfe..cb56e8c 100644
> --- a/tools/f2fs_io/f2fs_io.h
> +++ b/tools/f2fs_io/f2fs_io.h
> @@ -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;
> +};
> -- 
> 2.29.1.341.ge80a0c044ae-goog
> 
> 
> 
> _______________________________________________
> Linux-f2fs-devel mailing list
> Linux-f2fs-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-02 16:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-02  0:29 [f2fs-dev] [PATCH] f2fs_io: add get/set compression option Daeho Jeong
2020-11-02 16:16 ` Jaegeuk Kim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).