Skip to contentSkip to conversation

f2fs_io: add rename w/ fsync option

PATCH New Jaegeuk Kim 1 participant 1 message Aug 23, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs_io: add rename w/ fsync option

From: Jaegeuk Kim <[email protected]>

e.g., f2fs_io rename source dest 1
1. open(source)
2. rename(source, dest)
3. fsync(source)
4. close(source)

---
 tools/f2fs_io/f2fs_io.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
tools/f2fs_io/f2fs_io.c +36 -0
index 42dbd60c513a..caa77d344f85 100644
@@ -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 }
 };
 
Signature · 8 lines
2.33.0.rc2.250.ged5fa647cd-goog



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel