Skip to contentSkip to conversation

f2fs: fix an error case of missing update inode page

RFC PATCH In review Yunlei He 3 participants 9 messages Dec 5, 2017 – Dec 19, 2017 F2FS file system

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

RFC PATCH 1/1 f2fs: fix an error case of missing update inode page

-Thread A Thread B

-write_checkpoint

	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
Signature · 6 lines
1.9.1


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
maintainer
#1 lore raw
Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

BTW, what do you mean wb_writeback is same with fsync?

Thanks,

Quoted 73 lines
---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
Signature · 1 line
1.9.1

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

author
#2 lore raw
Quoted 22 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 08, 2017 1:27 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 5 lines
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

BTW, what do you mean wb_writeback is same with fsync?

Background write back will call f2fs_write_inode, which is same with f2fs_sync_file.

Thanks.

Quoted 73 lines

Thanks,

Quoted 70 lines
---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
Quoted 3 lines
Quoted 3 lines
fs/f2fs/inode.c +0 -1
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
--

1.9.1

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

maintainer Reviewed-by
#3 lore raw
Quoted 22 lines · heyunlei
Quoted 22 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 08, 2017 1:27 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

BTW, what do you mean wb_writeback is same with fsync?

Background write back will call f2fs_write_inode, which is same with f2fs_sync_file.

Can you add related call stack in commit log? Other part looks good to me.

Thanks,

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

maintainer
#4 lore raw
In reply to Yunlei He
Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

Does this patch fix the problem?

-write_checkpoint
-block_operations
-f2fs_unlock_all -f2fs_sync_file
-f2fs_write_inode
-set_page_drity -f2fs_inode_synced
-f2fs_sync_inode_meta
-sync_node_pages

I think, we need to cover f2fs_lock_op() for f2fs_write_inode() again.

Thanks,

Quoted 73 lines
---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
Signature · 1 line
1.9.1

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

author
#5 lore raw
Quoted 22 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 15, 2017 3:46 AM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 6 lines
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

Does this patch fix the problem?

I modify code as below:
@@ -366,7 +366,7 @@ int update_inode(struct inode *inode, struct page *node_page)

        struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
        f2fs_inode_synced(inode);
-
+       msleep(10000);
        f2fs_wait_on_page_writeback(node_page, NODE, true);

shell 1: shell2:
dd if=/dev/zero of=./test bs=1M count=10
sync
echo "hello" >> ./test
fsync test // sleep 10s
sync //return quickly
echo c > /proc/sysrq-trigger //before fsync return
fsck will find iblocks mismatch, and with this patch it 's ok.

Besides,I came across another error like this:

f2fs_inode-> i_xattr_nid is non-zero, but node blkaddr in raw nat entry is NULL.

This case makes sense to this problem also.

Quoted 10 lines

-write_checkpoint

	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-set_page_drity
								-f2fs_inode_synced
			-f2fs_sync_inode_meta
				-sync_node_pages

I think, we need to cover f2fs_lock_op() for f2fs_write_inode() again.

It can also work well with f2fs_lock_op(), I am afraid other cases will update inode like f2fs_write_inode without f2fs_lock_op

Thanks

Quoted 73 lines

Thanks,

Quoted 70 lines
---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
Quoted 3 lines
Quoted 3 lines
fs/f2fs/inode.c +0 -1
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
--

1.9.1

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

maintainer
#6 lore raw
Quoted 37 lines · heyunlei
Quoted 22 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 15, 2017 3:46 AM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 6 lines
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

Does this patch fix the problem?

I modify code as below:

fs/f2fs/inode.c +1 -1
@@ -366,7 +366,7 @@ int update_inode(struct inode *inode, struct page *node_page)
        struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
        f2fs_inode_synced(inode);
-
+       msleep(10000);
        f2fs_wait_on_page_writeback(node_page, NODE, true);
 
Quoted 8 lines

shell 1: shell2:
dd if=/dev/zero of=./test bs=1M count=10
sync
echo "hello" >> ./test
fsync test // sleep 10s
sync //return quickly
echo c > /proc/sysrq-trigger //before fsync return
fsck will find iblocks mismatch, and with this patch it 's ok.

So, do you mean it was fixed by adding msleep() on top of this patch as well? Like:
- f2fs_write_inode()
- set_page_drity
- f2fs_inode_synced
- msleep(10000);

Quoted 95 lines

Besides,I came across another error like this:

f2fs_inode-> i_xattr_nid is non-zero, but node blkaddr in raw nat entry is NULL.

This case makes sense to this problem also.

Quoted 10 lines

-write_checkpoint

	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-set_page_drity
								-f2fs_inode_synced
			-f2fs_sync_inode_meta
				-sync_node_pages

I think, we need to cover f2fs_lock_op() for f2fs_write_inode() again.

It can also work well with f2fs_lock_op(), I am afraid other cases will update inode like f2fs_write_inode without f2fs_lock_op

Thanks

Quoted 73 lines

Thanks,

Quoted 70 lines
---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
fs/f2fs/inode.c +0 -1
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
--

1.9.1

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

author
#7 lore raw
Quoted 47 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 15, 2017 12:21 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 37 lines · heyunlei
Quoted 22 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 15, 2017 3:46 AM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 6 lines
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

Does this patch fix the problem?

I modify code as below:

fs/f2fs/inode.c +1 -1
@@ -366,7 +366,7 @@ int update_inode(struct inode *inode, struct page *node_page)
        struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
        f2fs_inode_synced(inode);
-
+       msleep(10000);
        f2fs_wait_on_page_writeback(node_page, NODE, true);
 
Quoted 16 lines
Quoted 8 lines

shell 1: shell2:
dd if=/dev/zero of=./test bs=1M count=10
sync
echo "hello" >> ./test
fsync test // sleep 10s
sync //return quickly
echo c > /proc/sysrq-trigger //before fsync return
fsck will find iblocks mismatch, and with this patch it 's ok.

So, do you mean it was fixed by adding msleep() on top of this patch as well? Like:
- f2fs_write_inode()
- set_page_drity
- f2fs_inode_synced
- msleep(10000);

Yes, write_checkpoint will be blocked in sync dirty node pages, until fsync update inode page and unlock node page.

Thanks.

Quoted 95 lines
Quoted 95 lines

Besides,I came across another error like this:

f2fs_inode-> i_xattr_nid is non-zero, but node blkaddr in raw nat entry is NULL.

This case makes sense to this problem also.

Quoted 10 lines

-write_checkpoint

	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-set_page_drity
								-f2fs_inode_synced
			-f2fs_sync_inode_meta
				-sync_node_pages

I think, we need to cover f2fs_lock_op() for f2fs_write_inode() again.

It can also work well with f2fs_lock_op(), I am afraid other cases will update inode like f2fs_write_inode without f2fs_lock_op

Thanks

Quoted 73 lines

Thanks,

Quoted 70 lines
---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
fs/f2fs/inode.c +0 -1
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
--

1.9.1

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

maintainer
#8 lore raw
Quoted 63 lines · heyunlei
Quoted 47 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 15, 2017 12:21 PM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 37 lines · heyunlei
Quoted 22 lines

-----Original Message-----
From: Jaegeuk Kim [mailto:[email protected]]
Sent: Friday, December 15, 2017 3:46 AM
To: heyunlei
Cc: Yuchao (T); [email protected]; Wangbintian; Jianing (Euler)
Subject: Re: [f2fs-dev][PATCH RFC] f2fs: fix an error case of missing update inode page

Quoted 12 lines · Yunlei He
(quoted diff) +0 -2
-Thread A					Thread B
 
-write_checkpoint
	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-f2fs_inode_synced

			-f2fs_sync_inode_meta
				-sync_node_pages
									-set_page_drity
Quoted 6 lines
Quoted 3 lines

In this case, if sudden power off without next new checkpoint, the last inode page update will lost. wb_writeback is same with fsync.

Does this patch fix the problem?

I modify code as below:

fs/f2fs/inode.c +1 -1
@@ -366,7 +366,7 @@ int update_inode(struct inode *inode, struct page *node_page)
        struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
        f2fs_inode_synced(inode);
-
+       msleep(10000);
        f2fs_wait_on_page_writeback(node_page, NODE, true);
 
Quoted 16 lines
Quoted 8 lines

shell 1: shell2:
dd if=/dev/zero of=./test bs=1M count=10
sync
echo "hello" >> ./test
fsync test // sleep 10s
sync //return quickly
echo c > /proc/sysrq-trigger //before fsync return
fsck will find iblocks mismatch, and with this patch it 's ok.

So, do you mean it was fixed by adding msleep() on top of this patch as well? Like:
- f2fs_write_inode()
- set_page_drity
- f2fs_inode_synced
- msleep(10000);

Quoted 2 lines

Yes, write_checkpoint will be blocked in sync dirty node pages, until fsync update inode page and unlock node page.

Got it. I've concerned about inversion of PageDirty() and f2fs_inode_synced(), but for now, I can't find any corner case simply. Let me do stress test with this.

Thanks,

Quoted 97 lines

Thanks.

Quoted 95 lines
Quoted 95 lines

Besides,I came across another error like this:

f2fs_inode-> i_xattr_nid is non-zero, but node blkaddr in raw nat entry is NULL.

This case makes sense to this problem also.

Quoted 10 lines

-write_checkpoint

	-block_operations
		-f2fs_unlock_all		-f2fs_sync_file
							-f2fs_write_inode
								-set_page_drity
								-f2fs_inode_synced
			-f2fs_sync_inode_meta
				-sync_node_pages

I think, we need to cover f2fs_lock_op() for f2fs_write_inode() again.

It can also work well with f2fs_lock_op(), I am afraid other cases will update inode like f2fs_write_inode without f2fs_lock_op

Thanks

Quoted 73 lines

Thanks,

Quoted 70 lines
---
 fs/f2fs/f2fs.h  |  4 ++--
 fs/f2fs/inode.c | 15 +++++++--------
 2 files changed, 9 insertions(+), 10 deletions(-)
fs/f2fs/f2fs.h +2 -2
index 82f1dc3..38f9324 100644
@@ -2513,8 +2513,8 @@ int f2fs_getattr(const struct path *path, struct kstat *stat,
 struct inode *f2fs_iget(struct super_block *sb, unsigned long ino);
 struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino);
 int try_to_free_nats(struct f2fs_sb_info *sbi, int nr_shrink);
-int update_inode(struct inode *inode, struct page *node_page);
-int update_inode_page(struct inode *inode);
+void update_inode(struct inode *inode, struct page *node_page);
+void update_inode_page(struct inode *inode);
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc);
 void f2fs_evict_inode(struct inode *inode);
 void handle_failed_inode(struct inode *inode);
fs/f2fs/inode.c +7 -8
index b4c4f2b..10d3c7c 100644
@@ -360,14 +360,15 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino)
 	return inode;
 }
 
-int update_inode(struct inode *inode, struct page *node_page)
+void update_inode(struct inode *inode, struct page *node_page)
 {
 	struct f2fs_inode *ri;
 	struct extent_tree *et = F2FS_I(inode)->extent_tree;
 
-	f2fs_inode_synced(inode);
-
 	f2fs_wait_on_page_writeback(node_page, NODE, true);
+	set_page_dirty(node_page);
+
+	f2fs_inode_synced(inode);
 
 	ri = F2FS_INODE(node_page);
 
@@ -426,10 +427,9 @@ int update_inode(struct inode *inode, struct page *node_page)
 	if (inode->i_nlink == 0)
 		clear_inline_node(node_page);
 
-	return set_page_dirty(node_page);
 }
 
-int update_inode_page(struct inode *inode)
+void update_inode_page(struct inode *inode)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct page *node_page;
@@ -444,11 +444,10 @@ int update_inode_page(struct inode *inode)
 		} else if (err != -ENOENT) {
 			f2fs_stop_checkpoint(sbi, false);
 		}
-		return 0;
+		return;
 	}
-	ret = update_inode(inode, node_page);
+	update_inode(inode, node_page);
 	f2fs_put_page(node_page, 1);
-	return ret;
 }
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
fs/f2fs/inode.c +0 -1
 int f2fs_write_inode(struct inode *inode, struct writeback_control *wbc)
--

1.9.1

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