Skip to contentSkip to conversation

libf2fs: propagate error from f2fs_{finalize, fsync}_device

PATCH New Chao Yu 1 participant 1 message Nov 24, 2017 Library code

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 libf2fs: propagate error from f2fs_{finalize, fsync}_device

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.

---
 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(-)
fsck/main.c +3 -1
index b62fc29e027a..543c10f66406 100644
@@ -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;
fsck/mount.c +2 -1
index 4ad22a136ca9..3efa29813853 100644
@@ -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++);
include/f2fs_fs.h +2 -2
index 05b893a24b66..5a59a7097af6 100644
@@ -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);
lib/libf2fs_io.c +18 -6
index 268dcfae490e..72898b381fcf 100644
@@ -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;
 }
mkfs/f2fs_format_main.c +2 -1
index e61c066a3f3a..691d3863a6c8 100644
@@ -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");
 
Signature · 6 lines
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