Skip to content

Commit

Permalink
f2fs-tools: don't call fsync on a clean image
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
chaseyu authored and Jaegeuk Kim committed Jan 26, 2024
1 parent 54f637a commit dff4893
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/f2fs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 11 additions & 4 deletions lib/libf2fs_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit dff4893

Please sign in to comment.