* [f2fs-dev] [PATCH] f2fs_io: add rename w/ fsync option
@ 2021-08-23 17:17 Jaegeuk Kim
0 siblings, 0 replies; only message in thread
From: Jaegeuk Kim @ 2021-08-23 17:17 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2021-08-23 17:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 17:17 [f2fs-dev] [PATCH] f2fs_io: add rename w/ fsync option Jaegeuk Kim
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).