Skip to contentSkip to conversation

f2fs_io: support defrag_file

PATCH In review Chao Yu 3 participants 4 messages Jul 27, 2019 – Aug 6, 2019

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH v2 1/1 f2fs_io: support defrag_file

From: Chao Yu <[email protected]>

Support 'defrag_file' sub command to trigger file based defragment via ioctl in f2fs.

---
v2:
- remove unneeded debug info.
- fix compile warning.

 tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/f2fs_io/f2fs_io.c +41 -0
index f087da4..59ef8a7 100644
@@ -442,6 +442,46 @@ static void do_gc_urgent(int argc, char **argv, const struct cmd_desc *cmd)
 	}
 }
 
+#define defrag_file_desc "do defragment on file"
+#define defrag_file_help						\
+"f2fs_io defrag_file [start] [length] [-v] [file_path]\n\n"		\
+"  start     : start offset of defragment region, unit: bytes\n"	\
+"  length    : bytes number of defragment region\n"			\
+"  -v        : be verbose\n"						\
+
+static void do_defrag_file(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	struct f2fs_defragment df;
+	u64 len;
+	int ret, fd;
+
+	if (argc != 5) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	df.start = atoll(argv[1]);
+	df.len = len = atoll(argv[2]);
+
+	fd = open(argv[4], O_RDWR);
+	if (fd == -1) {
+		fputs("Open failed\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+printf("%lu, %lu\n", df.start, df.len);
+	ret = ioctl(fd, F2FS_IOC_DEFRAGMENT, &df);
+	if (ret < 0) {
+		perror("F2FS_IOC_DEFRAGMENT");
+		exit(1);
+	}
+	printf("defrag %s in region[%lu, %lu]\n", argv[3],
+				df.start, df.start + len);
+	exit(0);
+}
+
+
 #define CMD_HIDDEN 	0x0001
 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
 #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -456,6 +496,7 @@ const struct cmd_desc cmd_list[] = {
 	CMD(read),
 	CMD(fiemap),
 	CMD(gc_urgent),
+	CMD(defrag_file),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 
Signature · 8 lines
2.22.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 10 lines · Chao Yu

From: Chao Yu <[email protected]>

Support 'defrag_file' sub command to trigger file based defragment via ioctl in f2fs.

---
v2:
- remove unneeded debug info.
- fix compile warning.

Sorry I sent the old one...

I add -v option, but w/o implement the details, because I just see generic/018 want this, also other filesystem utils have this option, not sure we should remove this option... any thoughts?

"f2fs_io defrag_file [start] [length] [-v] [file_path]\n\n"

Quoted 56 lines
 tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/f2fs_io/f2fs_io.c +40 -0
index f087da4..59ef8a7 100644
@@ -442,6 +442,46 @@ static void do_gc_urgent(int argc, char **argv, const struct cmd_desc *cmd)
 	}
 }
 
+#define defrag_file_desc "do defragment on file"
+#define defrag_file_help						\
+"f2fs_io defrag_file [start] [length] [-v] [file_path]\n\n"		\
+"  start     : start offset of defragment region, unit: bytes\n"	\
+"  length    : bytes number of defragment region\n"			\
+"  -v        : be verbose\n"						\
+
+static void do_defrag_file(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	struct f2fs_defragment df;
+	u64 len;
+	int ret, fd;
+
+	if (argc != 5) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	df.start = atoll(argv[1]);
+	df.len = len = atoll(argv[2]);
+
+	fd = open(argv[4], O_RDWR);
+	if (fd == -1) {
+		fputs("Open failed\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+printf("%lu, %lu\n", df.start, df.len);
+	ret = ioctl(fd, F2FS_IOC_DEFRAGMENT, &df);
+	if (ret < 0) {
+		perror("F2FS_IOC_DEFRAGMENT");
+		exit(1);
+	}
+	printf("defrag %s in region[%lu, %lu]\n", argv[3],
+				df.start, df.start + len);
+	exit(0);
+}
+
+
 #define CMD_HIDDEN 	0x0001
 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
 #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }

tools/f2fs_io/f2fs_io.c const struct cmd_desc cmd_list[] = { · line 502

Quoted 7 lines
tools/f2fs_io/f2fs_io.c +1 -0
@@ -456,6 +496,7 @@ const struct cmd_desc cmd_list[] = {
 	CMD(read),
 	CMD(fiemap),
 	CMD(gc_urgent),
+	CMD(defrag_file),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
Quoted 12 lines · Chao Yu
Quoted 10 lines · Chao Yu

From: Chao Yu <[email protected]>

Support 'defrag_file' sub command to trigger file based defragment via ioctl in f2fs.

---
v2:
- remove unneeded debug info.
- fix compile warning.

Quoted 5 lines

Sorry I sent the old one...

I add -v option, but w/o implement the details, because I just see generic/018 want this, also other filesystem utils have this option, not sure we should remove this option... any thoughts?

Ah, we don't need this option.

Quoted 58 lines

"f2fs_io defrag_file [start] [length] [-v] [file_path]\n\n"

Quoted 55 lines
 tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/f2fs_io/f2fs_io.c +40 -0
index f087da4..59ef8a7 100644
@@ -442,6 +442,46 @@ static void do_gc_urgent(int argc, char **argv, const struct cmd_desc *cmd)
 	}
 }
 
+#define defrag_file_desc "do defragment on file"
+#define defrag_file_help						\
+"f2fs_io defrag_file [start] [length] [-v] [file_path]\n\n"		\
+"  start     : start offset of defragment region, unit: bytes\n"	\
+"  length    : bytes number of defragment region\n"			\
+"  -v        : be verbose\n"						\
+
+static void do_defrag_file(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	struct f2fs_defragment df;
+	u64 len;
+	int ret, fd;
+
+	if (argc != 5) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	df.start = atoll(argv[1]);
+	df.len = len = atoll(argv[2]);
+
+	fd = open(argv[4], O_RDWR);
+	if (fd == -1) {
+		fputs("Open failed\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+printf("%lu, %lu\n", df.start, df.len);
+	ret = ioctl(fd, F2FS_IOC_DEFRAGMENT, &df);
+	if (ret < 0) {
+		perror("F2FS_IOC_DEFRAGMENT");
+		exit(1);
+	}
+	printf("defrag %s in region[%lu, %lu]\n", argv[3],
+				df.start, df.start + len);
+	exit(0);
+}
+
+
 #define CMD_HIDDEN 	0x0001
 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
 #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -456,6 +496,7 @@ const struct cmd_desc cmd_list[] = {
Quoted 8 lines

tools/f2fs_io/f2fs_io.c const struct cmd_desc cmd_list[] = { · line 502

Quoted 8 lines
tools/f2fs_io/f2fs_io.c +1 -0
 	CMD(read),
 	CMD(fiemap),
 	CMD(gc_urgent),
+	CMD(defrag_file),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
Quoted 13 lines · Jaegeuk Kim
Quoted 12 lines · Chao Yu
Quoted 10 lines · Chao Yu

From: Chao Yu <[email protected]>

Support 'defrag_file' sub command to trigger file based defragment via ioctl in f2fs.

---
v2:
- remove unneeded debug info.
- fix compile warning.

Quoted 7 lines
Quoted 5 lines

Sorry I sent the old one...

I add -v option, but w/o implement the details, because I just see generic/018 want this, also other filesystem utils have this option, not sure we should remove this option... any thoughts?

Ah, we don't need this option.

Let me update a new version, and change generic/018 testcase.

Thanks,

Quoted 60 lines
Quoted 60 lines

"f2fs_io defrag_file [start] [length] [-v] [file_path]\n\n"

Quoted 56 lines
 tools/f2fs_io/f2fs_io.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
tools/f2fs_io/f2fs_io.c +40 -0
index f087da4..59ef8a7 100644
@@ -442,6 +442,46 @@ static void do_gc_urgent(int argc, char **argv, const struct cmd_desc *cmd)
 	}
 }
 
+#define defrag_file_desc "do defragment on file"
+#define defrag_file_help						\
+"f2fs_io defrag_file [start] [length] [-v] [file_path]\n\n"		\
+"  start     : start offset of defragment region, unit: bytes\n"	\
+"  length    : bytes number of defragment region\n"			\
+"  -v        : be verbose\n"						\
+
+static void do_defrag_file(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	struct f2fs_defragment df;
+	u64 len;
+	int ret, fd;
+
+	if (argc != 5) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	df.start = atoll(argv[1]);
+	df.len = len = atoll(argv[2]);
+
+	fd = open(argv[4], O_RDWR);
+	if (fd == -1) {
+		fputs("Open failed\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+printf("%lu, %lu\n", df.start, df.len);
+	ret = ioctl(fd, F2FS_IOC_DEFRAGMENT, &df);
+	if (ret < 0) {
+		perror("F2FS_IOC_DEFRAGMENT");
+		exit(1);
+	}
+	printf("defrag %s in region[%lu, %lu]\n", argv[3],
+				df.start, df.start + len);
+	exit(0);
+}
+
+
 #define CMD_HIDDEN 	0x0001
 #define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
 #define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -456,6 +496,7 @@ const struct cmd_desc cmd_list[] = {
 	CMD(read),
Quoted 9 lines
Quoted 7 lines

tools/f2fs_io/f2fs_io.c const struct cmd_desc cmd_list[] = { · line 502

Quoted 7 lines
tools/f2fs_io/f2fs_io.c +1 -0
 	CMD(fiemap),
 	CMD(gc_urgent),
+	CMD(defrag_file),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel