From: Ocean Chen <oceanchen@google.com>
To: jaegeuk@kernel.org, yuchao0@huawei.com,
linux-f2fs-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Cc: oceanchen@google.com
Subject: [PATCH] f2fs_io: add erase option
Date: Wed, 14 Oct 2020 01:22:40 +0800 [thread overview]
Message-ID: <20201013172240.251899-1-oceanchen@google.com> (raw)
f2fs_io erase [block_device_path]
Signed-off-by: Ocean Chen <oceanchen@google.com>
---
tools/f2fs_io/f2fs_io.c | 53 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 52 insertions(+), 1 deletion(-)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 1ca82f1..cef32b1 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -24,13 +24,13 @@
#include <getopt.h>
#include <inttypes.h>
#include <limits.h>
+#include <linux/fs.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <string.h>
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <sys/stat.h>
@@ -432,6 +432,56 @@ static void do_fallocate(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define erase_desc "erase a block device"
+#define erase_help \
+"f2fs_io erase [block_device_path]\n\n" \
+"Send DISCARD | BLKSECDISCARD comamnd to" \
+"block device in block_device_path\n" \
+
+static void do_erase(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ int fd, ret;
+ struct stat st;
+ u64 range[2];
+
+ if (argc != 2) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ if (stat(argv[1], &st) != 0) {
+ fputs("stat error\n", stderr);
+ exit(1);
+ }
+
+ if (!S_ISBLK(st.st_mode)) {
+ fputs(argv[1], stderr);
+ fputs(" is not a block device\n", stderr);
+ exit(1);
+ }
+
+ fd = xopen(argv[1], O_WRONLY, 0);
+
+ range[0] = 0;
+ ret = ioctl(fd, BLKGETSIZE64, &range[1]);
+ if (ret < 0) {
+ fputs("get size failed\n", stderr);
+ exit(1);
+ }
+
+ ret = ioctl(fd, BLKSECDISCARD, &range);
+ if (ret < 0) {
+ ret = ioctl(fd, BLKDISCARD, &range);
+ if (ret < 0) {
+ fputs("Discard failed\n", stderr);
+ exit(1);
+ }
+ }
+
+ exit(0);
+}
+
#define write_desc "write data into file"
#define write_help \
"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path]\n\n" \
@@ -951,6 +1001,7 @@ const struct cmd_desc cmd_list[] = {
CMD(shutdown),
CMD(pinfile),
CMD(fallocate),
+ CMD(erase),
CMD(write),
CMD(read),
CMD(randread),
--
2.28.0.1011.ga647a8990f-goog
reply other threads:[~2020-10-13 17:22 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=20201013172240.251899-1-oceanchen@google.com \
--to=oceanchen@google.com \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=yuchao0@huawei.com \
/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
all inboxes | Powered by JetHome®