Skip to contentSkip to conversation

f2fs-tools: don't call fsync on a clean image

PATCH New Chao Yu 1 participant 1 message Jan 23, 2024 Library code

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs-tools: don't call fsync on a clean image

generic/019 50s ... _check_generic_filesystem: filesystem on /dev/vdc is inconsistent (see /media/fstests/results//generic/019.full for details)

[FSCK] Max image size: 16196 MB, Free space: 188 MB

[FSCK] Unreachable nat entries                        [Ok..] [0x0]
[FSCK] SIT valid block bitmap checking                [Ok..]
[FSCK] Hard link checking for regular file            [Ok..] [0x166]
[FSCK] valid_block_count matching with CP             [Ok..] [0x3ecfe7]
[FSCK] valid_node_count matching with CP (de lookup)  [Ok..] [0x4c79]
[FSCK] valid_node_count matching with CP (nat lookup) [Ok..] [0x4c79]
[FSCK] valid_inode_count matched with CP              [Ok..] [0xb46]
[FSCK] free segment_count matched with CP             [Ok..] [0x9d]
[FSCK] next block offset is free                      [Ok..]

[FSCK] fixing SIT types
[FSCK] other corrupted bugs [Ok..]
Error: Could not conduct fsync!!!

Generic/019 will trigger fsync() on a clean image, but it will fail due to simulated failure on disk, result in testcase failure.

Let's add c.need_fsync to record dirty status of image, and only trigger fsync() when there is dirty data in image.

---
 include/f2fs_fs.h |  1 +
 lib/libf2fs_io.c  | 15 +++++++++++----
 2 files changed, 12 insertions(+), 4 deletions(-)
include/f2fs_fs.h +1 -0
index 6df2e73..5e9dfad 100644
@@ -1514,6 +1514,7 @@ struct f2fs_configuration {
 	unsigned int quota_bits;	/* quota bits */
 	time_t fixed_time;
 	int roll_forward;
+	bool need_fsync;
 
 	/* mkfs parameters */
 	int fake_seed;
lib/libf2fs_io.c +11 -4
index d76da83..18a1a3c 100644
@@ -580,6 +580,7 @@ int dev_write(void *buf, __u64 offset, size_t len)
 		return -1;
 	if (write(fd, buf, len) < 0)
 		return -1;
+	c.need_fsync = true;
 	return 0;
 }
 
@@ -616,6 +617,7 @@ int dev_fill(void *buf, __u64 offset, size_t len)
 		return -1;
 	if (write(fd, buf, len) < 0)
 		return -1;
+	c.need_fsync = true;
 	return 0;
 }
 
@@ -639,6 +641,9 @@ int f2fs_fsync_device(void)
 #ifdef HAVE_FSYNC
 	int i;
 
+	if (!c.need_fsync)
+		return 0;
+
 	for (i = 0; i < c.ndevs; i++) {
 		if (fsync(c.devices[i].fd) < 0) {
 			MSG(0, "\tError: Could not conduct fsync!!!\n");
@@ -786,10 +791,12 @@ int f2fs_finalize_device(void)
 	 */
 	for (i = 0; i < c.ndevs; i++) {
 #ifdef HAVE_FSYNC
-		ret = fsync(c.devices[i].fd);
-		if (ret < 0) {
-			MSG(0, "\tError: Could not conduct fsync!!!\n");
-			break;
+		if (c.need_fsync) {
+			ret = fsync(c.devices[i].fd);
+			if (ret < 0) {
+				MSG(0, "\tError: Could not conduct fsync!!!\n");
+				break;
+			}
 		}
 #endif
 		ret = close(c.devices[i].fd);
Signature · 8 lines
2.40.1



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