Skip to contentSkip to conversation

fsck: introduce generic function f2fs_fsync_device

PATCH In review Yunlei He 2 participants 2 messages Oct 17, 2017 Library code

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 fsck: introduce generic function f2fs_fsync_device

We use f2fs_finalize_device to fsync previous data in checkpoint area before write last CP pack, in order to avoid cp corruption in sudden-power-off case. But this function will close the device, so this patch introduce a function to call fsync() only.

---
 fsck/mount.c      |  2 +-
 include/f2fs_fs.h |  1 +
 lib/libf2fs_io.c  | 10 ++++++++++
 3 files changed, 12 insertions(+), 1 deletion(-)
fsck/mount.c +1 -1
index 7a8aeae..e234fe9 100644
@@ -1939,7 +1939,7 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
 		write_nat_bits(sbi, sb, cp, sbi->cur_cp);
 
 	/* in case of sudden power off */
-	f2fs_finalize_device();
+	f2fs_fsync_device();
 
 	/* write the last cp */
 	ret = dev_write_block(cp, cp_blk_no++);
include/f2fs_fs.h +1 -0
index bd609b9..3673817 100644
@@ -1013,6 +1013,7 @@ 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 dev_read(void *, __u64, size_t);
 extern int dev_write(void *, __u64, size_t);
lib/libf2fs_io.c +10 -0
index aa99068..50ff171 100644
@@ -193,6 +193,16 @@ int dev_reada_block(__u64 blk_addr)
 	return dev_readahead(blk_addr << F2FS_BLKSIZE_BITS, F2FS_BLKSIZE);
 }
 
+void f2fs_fsync_device(void)
+{
+	int i;
+
+	for (i = 0; i < c.ndevs; i++) {
+		if (fsync(c.devices[i].fd) < 0)
+			MSG(0, "\tError: Could not conduct fsync!!!\n");
+	}
+}
+
 void f2fs_finalize_device(void)
 {
 	int i;
Signature · 6 lines
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Yunlei He

We use f2fs_finalize_device to fsync previous data in checkpoint area before write last CP pack, in order to avoid cp corruption in sudden-power-off case. But this function will close the device, so this patch introduce a function to call fsync() only.

Thanks,

Quoted 43 lines
---
 fsck/mount.c      |  2 +-
 include/f2fs_fs.h |  1 +
 lib/libf2fs_io.c  | 10 ++++++++++
 3 files changed, 12 insertions(+), 1 deletion(-)
fsck/mount.c +1 -1
index 7a8aeae..e234fe9 100644
@@ -1939,7 +1939,7 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
 		write_nat_bits(sbi, sb, cp, sbi->cur_cp);
 
 	/* in case of sudden power off */
-	f2fs_finalize_device();
+	f2fs_fsync_device();
 
 	/* write the last cp */
 	ret = dev_write_block(cp, cp_blk_no++);
include/f2fs_fs.h +1 -0
index bd609b9..3673817 100644
@@ -1013,6 +1013,7 @@ 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 dev_read(void *, __u64, size_t);
 extern int dev_write(void *, __u64, size_t);
lib/libf2fs_io.c +3 -0
index aa99068..50ff171 100644
@@ -193,6 +193,16 @@ int dev_reada_block(__u64 blk_addr)
 	return dev_readahead(blk_addr << F2FS_BLKSIZE_BITS, F2FS_BLKSIZE);
 }
 
+void f2fs_fsync_device(void)
+{
+	int i;

lib/libf2fs_io.c int dev_reada_block(__u64 blk_addr) · line 208

Quoted 10 lines
lib/libf2fs_io.c +7 -0
+
+	for (i = 0; i < c.ndevs; i++) {
+		if (fsync(c.devices[i].fd) < 0)
+			MSG(0, "\tError: Could not conduct fsync!!!\n");
+	}
+}
+
 void f2fs_finalize_device(void)
 {
 	int i;

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot