From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [f2fs-dev] [PATCH] f2fs_io: add fadvise support
Date: Tue, 3 Oct 2023 15:28:39 -0700 [thread overview]
Message-ID: <20231003222839.1912717-1-jaegeuk@kernel.org> (raw)
f2fs_io fadvise [advice] [offset] [length] [file]
advice can be "willneed" and "sequential".
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
man/f2fs_io.8 | 3 +++
tools/f2fs_io/f2fs_io.c | 42 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
diff --git a/man/f2fs_io.8 b/man/f2fs_io.8
index 99e31dd5dbd4..ecaab029d48e 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 1f6549b46746..c812aa1458a2 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),
--
2.42.0.582.g8ccd20d70d-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next reply other threads:[~2023-10-03 22:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-03 22:28 Jaegeuk Kim [this message]
2023-10-07 6:38 ` [f2fs-dev] [PATCH] f2fs_io: add fadvise support Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231003222839.1912717-1-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).