linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <chao@kernel.org>
To: jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH] f2fs_io: support triggering filesystem GC via ioctl
Date: Wed, 27 Jul 2022 23:09:25 +0800	[thread overview]
Message-ID: <20220727150925.1983251-1-chao@kernel.org> (raw)

From: Chao Yu <chao.yu@oppo.com>

Support 'gc' sub command to trigger filesystem GC via ioctl in f2fs.

Signed-off-by: Chao Yu <chao.yu@oppo.com>
---
 man/f2fs_io.8           |  3 +++
 tools/f2fs_io/f2fs_io.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/man/f2fs_io.8 b/man/f2fs_io.8
index af7325a..33789c2 100644
--- a/man/f2fs_io.8
+++ b/man/f2fs_io.8
@@ -132,6 +132,9 @@ Release compressed blocks to get free space.
 .TP
 \fBreserve_cblocks\fR \fI[file]\fR
 Reserve free blocks to prepare decompressing blocks in the file.
+.TP
+\fBgc\fR \fI[sync_mode] [file]\fR
+Trigger filesystem GC
 .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 e735983..5be7b9e 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1270,6 +1270,33 @@ static void do_rename(int argc, char **argv, const struct cmd_desc *cmd)
 	exit(0);
 }
 
+#define gc_desc "trigger filesystem GC"
+#define gc_help "f2fs_io gc sync_mode [file_path]\n\n"
+
+static void do_gc(int argc, char **argv, const struct cmd_desc *cmd)
+{
+	u32 sync;
+	int ret, fd;
+
+	if (argc != 3) {
+		fputs("Excess arguments\n\n", stderr);
+		fputs(cmd->cmd_help, stderr);
+		exit(1);
+	}
+
+	sync = atoi(argv[1]);
+
+	fd = xopen(argv[2], O_RDONLY, 0);
+
+	ret = ioctl(fd, F2FS_IOC_GARBAGE_COLLECT, &sync);
+	if (ret < 0)
+		die_errno("F2FS_IOC_GARBAGE_COLLECT failed");
+
+	printf("trigger %s gc ret=%d\n",
+		sync ? "synchronous" : "asynchronous", 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 }
@@ -1301,6 +1328,7 @@ const struct cmd_desc cmd_list[] = {
 	CMD(compress),
 	CMD(get_filename_encrypt_mode),
 	CMD(rename),
+	CMD(gc),
 	{ NULL, NULL, NULL, NULL, 0 }
 };
 
-- 
2.25.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

                 reply	other threads:[~2022-07-27 15:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20220727150925.1983251-1-chao@kernel.org \
    --to=chao@kernel.org \
    --cc=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).