diff mbox series

[f2fs-dev,v2] f2fs_io: support precache_extents command

Message ID 20230414084728.30534-1-frank.li@vivo.com (mailing list archive)
State New
Headers show
Series [f2fs-dev,v2] f2fs_io: support precache_extents command | expand

Commit Message

Yangtao Li April 14, 2023, 8:47 a.m. UTC
This patch supports a new sub-command 'precache_extents' in f2fs_io
to trigger precache extents via F2FS_IOC_PRECACHE_EXTENTS ioctl.

Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
v2:
-fix precache_extents_help
 man/f2fs_io.8           |  3 +++
 tools/f2fs_io/f2fs_io.c | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/man/f2fs_io.8 b/man/f2fs_io.8
index 33789c2..ce8340c 100644
--- a/man/f2fs_io.8
+++ b/man/f2fs_io.8
@@ -135,6 +135,9 @@  Reserve free blocks to prepare decompressing blocks in the file.
 .TP
 \fBgc\fR \fI[sync_mode] [file]\fR
 Trigger filesystem GC
+.TP
+\fBprecache_extents\fR \fI[file]\fR
+Trigger precache extents
 .SH AUTHOR
 This version of
 .B f2fs_io
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 5bc0baf..e604941 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1311,6 +1311,29 @@  static void do_gc(int argc, char **argv, const struct cmd_desc *cmd)
 	exit(0);
 }
 
+#define precache_extents_desc "trigger precache extents"
+#define precache_extents_help "f2fs_io precache_extents [file_path]\n\n"
+
+static void do_precache_extents(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	int ret, fd;
+
+	if (argc != 2) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	fd = xopen(argv[1], O_WRONLY, 0);
+
+	ret = ioctl(fd, F2FS_IOC_PRECACHE_EXTENTS);
+	if (ret < 0)
+		die_errno("F2FS_IOC_PRECACHE_EXTENTS failed");
+
+	printf("trigger precache extents ret=%d\n", ret);
+	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 }
@@ -1343,6 +1366,7 @@  const struct cmd_desc cmd_list[] = {
 	CMD(get_filename_encrypt_mode),
 	CMD(rename),
 	CMD(gc),
+	CMD(precache_extents),
 	{ NULL, NULL, NULL, NULL, 0 }
 };