* [PATCH] libf2fs: propagate error from f2fs_{finalize, fsync}_device
@ 2017-11-24 9:33 Chao Yu
0 siblings, 0 replies; only message in thread
From: Chao Yu @ 2017-11-24 9:33 UTC (permalink / raw)
To: jaegeuk; +Cc: linux-f2fs-devel
tests/generic/405 of fstest suit expects that mkfs will return error
when it hits EIO, so let's propagate error from
f2fs_{finalize,fsync}_device, then mkfs can be aware of fsync error.
Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
fsck/main.c | 4 +++-
fsck/mount.c | 3 ++-
include/f2fs_fs.h | 4 ++--
lib/libf2fs_io.c | 24 ++++++++++++++++++------
mkfs/f2fs_format_main.c | 3 ++-
5 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/fsck/main.c b/fsck/main.c
index b62fc29e027a..543c10f66406 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -676,7 +676,9 @@ retry:
goto fsck_again;
}
}
- f2fs_finalize_device();
+ ret = f2fs_finalize_device();
+ if (ret < 0)
+ return ret;
printf("\nDone.\n");
return 0;
diff --git a/fsck/mount.c b/fsck/mount.c
index 4ad22a136ca9..3efa29813853 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -2098,7 +2098,8 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
write_nat_bits(sbi, sb, cp, sbi->cur_cp);
/* in case of sudden power off */
- f2fs_fsync_device();
+ ret = f2fs_fsync_device();
+ ASSERT(ret >= 0);
/* write the last cp */
ret = dev_write_block(cp, cp_blk_no++);
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 05b893a24b66..5a59a7097af6 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1056,8 +1056,8 @@ extern int f2fs_devs_are_umounted(void);
extern int f2fs_dev_is_umounted(char *);
extern int f2fs_get_device_info(void);
extern int get_device_info(int);
-extern void f2fs_finalize_device(void);
-extern void f2fs_fsync_device(void);
+extern int f2fs_finalize_device(void);
+extern int f2fs_fsync_device(void);
extern int dev_read(void *, __u64, size_t);
extern int dev_write(void *, __u64, size_t);
diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c
index 268dcfae490e..72898b381fcf 100644
--- a/lib/libf2fs_io.c
+++ b/lib/libf2fs_io.c
@@ -213,19 +213,23 @@ int dev_reada_block(__u64 blk_addr)
return dev_readahead(blk_addr << F2FS_BLKSIZE_BITS, F2FS_BLKSIZE);
}
-void f2fs_fsync_device(void)
+int f2fs_fsync_device(void)
{
int i;
for (i = 0; i < c.ndevs; i++) {
- if (fsync(c.devices[i].fd) < 0)
+ if (fsync(c.devices[i].fd) < 0) {
MSG(0, "\tError: Could not conduct fsync!!!\n");
+ return -1;
+ }
}
+
+ return 0;
}
-void f2fs_finalize_device(void)
+int f2fs_finalize_device(void)
{
- int i;
+ int i, ret;
#ifdef WITH_ANDROID
if (c.sparse_mode) {
@@ -246,11 +250,19 @@ void f2fs_finalize_device(void)
* in the block device page cache.
*/
for (i = 0; i < c.ndevs; i++) {
- if (fsync(c.devices[i].fd) < 0)
+ ret = fsync(c.devices[i].fd);
+ if (ret < 0) {
MSG(0, "\tError: Could not conduct fsync!!!\n");
+ break;
+ }
- if (close(c.devices[i].fd) < 0)
+ ret = close(c.devices[i].fd);
+ if (ret < 0) {
MSG(0, "\tError: Failed to close device file!!!\n");
+ break;
+ }
}
close(c.kd);
+
+ return ret;
}
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index e61c066a3f3a..691d3863a6c8 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -333,7 +333,8 @@ int main(int argc, char *argv[])
if (f2fs_format_device() < 0)
return -1;
- f2fs_finalize_device();
+ if (f2fs_finalize_device() < 0)
+ return -1;
MSG(0, "Info: format successful\n");
--
2.15.0.55.gc2ece9dc4de6
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2017-11-24 9:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-24 9:33 [PATCH] libf2fs: propagate error from f2fs_{finalize, fsync}_device Chao Yu
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).