aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@kernel.org>2023-10-03 13:08:04 -0700
committerJaegeuk Kim <jaegeuk@kernel.org>2023-10-03 15:29:10 -0700
commit0baf928aa1ec9adcd6a34bcc8cdd968db70a4c98 (patch)
tree32c287534f20787a9965699cac0dcc25475de100
parent220d716f9b3ef579153816990f8498c3eeb2aa19 (diff)
downloadf2fs-tools-0baf928aa1ec9adcd6a34bcc8cdd968db70a4c98.tar.gz
f2fs_io: add fadvise support
f2fs_io fadvise [advice] [offset] [length] [file] advice can be "willneed" and "sequential". Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--man/f2fs_io.83
-rw-r--r--tools/f2fs_io/f2fs_io.c42
2 files changed, 45 insertions, 0 deletions
diff --git a/man/f2fs_io.8 b/man/f2fs_io.8
index 99e31dd..ecaab02 100644
--- a/man/f2fs_io.8
+++ b/man/f2fs_io.8
@@ -47,6 +47,9 @@ going down with fsck mark
\fBpinfile\fR \fI[get|set] [file]\fR
Get or set the pinning status on a file.
.TP
+\fBfadvise\fR \fI[advice] [offset] [length] [file]\fR
+Pass an advice to the specified file. The advice can be willneed and sequential.
+.TP
\fBfallocate\fR \fI[-c] [-i] [-p] [-z] [keep_size] [offset] [length] [file]\fR
Request that space be allocated on a file. The
.I keep_size
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 1f6549b..c812aa1 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -398,6 +398,47 @@ static void do_shutdown(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define fadvise_desc "fadvise"
+#define fadvise_help \
+"f2fs_io fadvise [advice] [offset] [length] [file]\n\n" \
+"fadvice given the file\n" \
+"advice can be\n" \
+" willneed\n" \
+" sequential\n" \
+
+static void do_fadvise(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ int fd, advice;
+ off_t offset, length;
+
+ if (argc != 5) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ fd = xopen(argv[4], O_RDWR, 0);
+
+ if (!strcmp(argv[1], "willneed")) {
+ advice = POSIX_FADV_WILLNEED;
+ } else if (!strcmp(argv[1], "sequential")) {
+ advice = POSIX_FADV_SEQUENTIAL;
+ } else {
+ fputs("Wrong advice\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ offset = atoi(argv[2]);
+ length = atoll(argv[3]);
+
+ if (posix_fadvise(fd, offset, length, advice) != 0)
+ die_errno("fadvise failed");
+
+ printf("fadvice %s to a file: %s\n", argv[1], argv[4]);
+ exit(0);
+}
+
#define pinfile_desc "pin file control"
#define pinfile_help \
"f2fs_io pinfile [get|set] [file]\n\n" \
@@ -1499,6 +1540,7 @@ const struct cmd_desc cmd_list[] = {
CMD(clearflags),
CMD(shutdown),
CMD(pinfile),
+ CMD(fadvise),
CMD(fallocate),
CMD(erase),
CMD(write),