From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@google.com>
Subject: [f2fs-dev] [PATCH] f2fs_io: add rename w/ fsync option
Date: Mon, 23 Aug 2021 10:17:22 -0700 [thread overview]
Message-ID: <20210823171722.1705378-1-jaegeuk@kernel.org> (raw)
From: Jaegeuk Kim <jaegeuk@google.com>
e.g., f2fs_io rename source dest 1
1. open(source)
2. rename(source, dest)
3. fsync(source)
4. close(source)
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
tools/f2fs_io/f2fs_io.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 42dbd60c513a..caa77d344f85 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -1169,6 +1169,41 @@ static void do_get_filename_encrypt_mode (int argc, char **argv,
exit(0);
}
+#define rename_desc "rename source to target file with fsync option"
+#define rename_help \
+"f2fs_io rename [src_path] [target_path] [fsync_after_rename]\n\n" \
+"e.g., f2fs_io rename source dest 1\n" \
+" 1. open(source)\n" \
+" 2. rename(source, dest)\n" \
+" 3. fsync(source)\n" \
+" 4. close(source)\n"
+
+static void do_rename(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ int fd = -1;
+ int ret;
+
+ if (argc != 4) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ if (atoi(argv[3]))
+ fd = xopen(argv[1], O_WRONLY, 0);
+
+ ret = rename(argv[1], argv[2]);
+ if (ret < 0)
+ die_errno("rename failed");
+
+ if (fd >= 0) {
+ if (fsync(fd) != 0)
+ die_errno("fsync failed: %s", argv[1]);
+ close(fd);
+ }
+ 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 }
@@ -1199,6 +1234,7 @@ const struct cmd_desc cmd_list[] = {
CMD(decompress),
CMD(compress),
CMD(get_filename_encrypt_mode),
+ CMD(rename),
{ NULL, NULL, NULL, NULL, 0 }
};
--
2.33.0.rc2.250.ged5fa647cd-goog
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
reply other threads:[~2021-08-23 17:17 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=20210823171722.1705378-1-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=jaegeuk@google.com \
--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).