2023-05-29 01:53:50

by Sheng Yong

[permalink] [raw]
Subject: [PATCH 2/2] f2fs_io: convert compression ioctls to [get|set]_attr

Convert compression related ioctls to get extra attr ioctls.

Signed-off-by: Sheng Yong <[email protected]>
---
tools/f2fs_io/f2fs_io.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 70e0347..f6e6057 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1012,7 +1012,9 @@ static void do_copy(int argc, char **argv, const struct cmd_desc *cmd)

static void do_get_cblocks(int argc, char **argv, const struct cmd_desc *cmd)
{
- unsigned long long blkcnt;
+ struct f2fs_extra_attr attr = {
+ .field = F2FS_EXTRA_ATTR_COMPR_BLOCKS,
+ };
int ret, fd;

if (argc != 2) {
@@ -1023,11 +1025,11 @@ static void do_get_cblocks(int argc, char **argv, const struct cmd_desc *cmd)

fd = xopen(argv[1], O_RDONLY, 0);

- ret = ioctl(fd, F2FS_IOC_GET_COMPRESS_BLOCKS, &blkcnt);
+ ret = ioctl(fd, F2FS_IOC_GET_EXTRA_ATTR, &attr);
if (ret < 0)
die_errno("F2FS_IOC_GET_COMPRESS_BLOCKS failed");

- printf("%llu\n", blkcnt);
+ printf("%llu\n", (unsigned long long)attr.attr);

exit(0);
}
@@ -1090,6 +1092,7 @@ static void do_reserve_cblocks(int argc, char **argv, const struct cmd_desc *cmd

static void do_get_coption(int argc, char **argv, const struct cmd_desc *cmd)
{
+ struct f2fs_extra_attr attr = {0};
struct f2fs_comp_option option;
int ret, fd;

@@ -1099,11 +1102,15 @@ static void do_get_coption(int argc, char **argv, const struct cmd_desc *cmd)
exit(1);
}

+ attr.field = F2FS_EXTRA_ATTR_COMPR_OPTION;
+ attr.attr_size = sizeof(option);
+ attr.attr = (unsigned long)&option;
+
fd = xopen(argv[1], O_RDONLY, 0);

- ret = ioctl(fd, F2FS_IOC_GET_COMPRESS_OPTION, &option);
+ ret = ioctl(fd, F2FS_IOC_GET_EXTRA_ATTR, &attr);
if (ret < 0)
- die_errno("F2FS_IOC_GET_COMPRESS_OPTION failed");
+ die_errno("F2FS_IOC_GET_EXTRA_ATTR failed");

printf("compression algorithm:%u\n", option.algorithm);
printf("compression cluster log size:%u\n", option.log_cluster_size);
@@ -1119,6 +1126,7 @@ static void do_get_coption(int argc, char **argv, const struct cmd_desc *cmd)

static void do_set_coption(int argc, char **argv, const struct cmd_desc *cmd)
{
+ struct f2fs_extra_attr attr = {0};
struct f2fs_comp_option option;
int fd, ret;

@@ -1130,12 +1138,15 @@ static void do_set_coption(int argc, char **argv, const struct cmd_desc *cmd)

option.algorithm = atoi(argv[1]);
option.log_cluster_size = atoi(argv[2]);
+ attr.field = F2FS_EXTRA_ATTR_COMPR_OPTION;
+ attr.attr_size = sizeof(option);
+ attr.attr = (unsigned long)&option;

fd = xopen(argv[3], O_WRONLY, 0);

- ret = ioctl(fd, F2FS_IOC_SET_COMPRESS_OPTION, &option);
+ ret = ioctl(fd, F2FS_IOC_SET_EXTRA_ATTR, &attr);
if (ret < 0)
- die_errno("F2FS_IOC_SET_COMPRESS_OPTION failed");
+ die_errno("F2FS_IOC_SET_EXTRA_ATTR failed");

printf("set compression option: algorithm=%u, log_cluster_size=%u\n",
option.algorithm, option.log_cluster_size);
--
2.40.1