aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChao Yu <chao@kernel.org>2024-01-23 21:53:49 +0800
committerJaegeuk Kim <jaegeuk@kernel.org>2024-01-26 00:40:27 -0800
commitdff4893b4923305a1f5e71c724d945e150f38265 (patch)
tree5b5da034cb951f80accf00881289494974822f68
parent54f637a965419e828e05f910c24213b59291adab (diff)
downloadf2fs-tools-dff4893b4923305a1f5e71c724d945e150f38265.tar.gz
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. Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--include/f2fs_fs.h1
-rw-r--r--lib/libf2fs_io.c15
2 files changed, 12 insertions, 4 deletions
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 6df2e73..5e9dfad 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -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;
diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c
index d76da83..18a1a3c 100644
--- a/lib/libf2fs_io.c
+++ b/lib/libf2fs_io.c
@@ -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);