Skip to contentSkip to conversation

f2fs: avoid dead loop in function find_fsync_dnodes

PATCH Superseded Yunlei He 2 participants 2 messages Dec 8, 2017 F2FS file system

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH 1/1 f2fs: avoid dead loop in function find_fsync_dnodes

Came across a dead loop in recovery like this:

......

[   24.680480s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597696
[   24.698394s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597697
[   24.724334s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724334s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724365s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724365s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724365s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724426s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698

......

Mount process will block in dead loop and fsck can do nothing with this error, This patch abandon recovery if node chain is cyclical.

---
 fs/f2fs/node.h          |  8 +++++---
 fs/f2fs/recovery.c      | 22 ++++++++++++++--------
 include/linux/f2fs_fs.h |  3 ++-
 3 files changed, 21 insertions(+), 12 deletions(-)
fs/f2fs/node.h +5 -3
index 0ee3e5f..049ff5e 100644
@@ -399,9 +399,10 @@ static inline int is_node(struct page *page, int type)
 	return le32_to_cpu(rn->footer.flag) & (1 << type);
 }
 
-#define is_cold_node(page)	is_node(page, COLD_BIT_SHIFT)
-#define is_fsync_dnode(page)	is_node(page, FSYNC_BIT_SHIFT)
-#define is_dent_dnode(page)	is_node(page, DENT_BIT_SHIFT)
+#define is_cold_node(page)		is_node(page, COLD_BIT_SHIFT)
+#define is_fsync_dnode(page)		is_node(page, FSYNC_BIT_SHIFT)
+#define is_dent_dnode(page)		is_node(page, DENT_BIT_SHIFT)
+#define is_recovered_dnode(page)	is_node(page, RECOVERED_BIT_SHIFT)
 
 static inline int is_inline_node(struct page *page)
 {
@@ -442,3 +443,4 @@ static inline void set_mark(struct page *page, int mark, int type)
 }
 #define set_dentry_mark(page, mark)	set_mark(page, mark, DENT_BIT_SHIFT)
 #define set_fsync_mark(page, mark)	set_mark(page, mark, FSYNC_BIT_SHIFT)
+#define set_recovered_mark(page, mark)	set_mark(page, mark, RECOVERED_BIT_SHIFT)
fs/f2fs/recovery.c +14 -8
index 7d63faf..bfbb3e4 100644
@@ -220,6 +220,14 @@ static void recover_inode(struct inode *inode, struct page *page)
 			ino_of_node(page), name);
 }
 
+static void destroy_fsync_dnodes(struct list_head *head)
+{
+	struct fsync_inode_entry *entry, *tmp;
+
+	list_for_each_entry_safe(entry, tmp, head, list)
+		del_fsync_inode(entry);
+}
+
 static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 				bool check_only)
 {
@@ -239,7 +247,13 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 			return 0;
 
 		page = get_tmp_page(sbi, blkaddr);
+		if (unlikely(is_recovered_dnode(page))) {
+			f2fs_msg(sbi->sb, KERN_ERR, "Abandon dead loop node block list");
+			destroy_fsync_dnodes(head);
+			break;
+		}
 
+		set_recovered_mark(page, RECOVERED_BIT_SHIFT);
 		if (!is_recoverable_dnode(page))
 			break;
 
@@ -288,14 +302,6 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 	return err;
 }
 
-static void destroy_fsync_dnodes(struct list_head *head)
-{
-	struct fsync_inode_entry *entry, *tmp;
-
-	list_for_each_entry_safe(entry, tmp, head, list)
-		del_fsync_inode(entry);
-}
-
 static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
 			block_t blkaddr, struct dnode_of_data *dn)
 {
include/linux/f2fs_fs.h +2 -1
index 43e98d3..9aa85b1 100644
@@ -265,7 +265,8 @@ enum {
 	COLD_BIT_SHIFT = 0,
 	FSYNC_BIT_SHIFT,
 	DENT_BIT_SHIFT,
-	OFFSET_BIT_SHIFT
+	OFFSET_BIT_SHIFT,
+	RECOVERED_BIT_SHIFT
 };
 
 #define OFFSET_BIT_MASK		(0x07)	/* (0x01 << OFFSET_BIT_SHIFT) - 1 */
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

Hi Yunlei,

Quoted 103 lines · Yunlei He

Came across a dead loop in recovery like this:

......

[   24.680480s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597696
[   24.698394s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597697
[   24.724334s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724334s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724365s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724365s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724365s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724395s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698
[   24.724426s][pid:320,cpu0,init]find_fsync_dnodes: blkaddr =13597698

......

Mount process will block in dead loop and fsck can do nothing with this error, This patch abandon recovery if node chain is cyclical.

---
 fs/f2fs/node.h          |  8 +++++---
 fs/f2fs/recovery.c      | 22 ++++++++++++++--------
 include/linux/f2fs_fs.h |  3 ++-
 3 files changed, 21 insertions(+), 12 deletions(-)
fs/f2fs/node.h +5 -3
index 0ee3e5f..049ff5e 100644
@@ -399,9 +399,10 @@ static inline int is_node(struct page *page, int type)
 	return le32_to_cpu(rn->footer.flag) & (1 << type);
 }
 
-#define is_cold_node(page)	is_node(page, COLD_BIT_SHIFT)
-#define is_fsync_dnode(page)	is_node(page, FSYNC_BIT_SHIFT)
-#define is_dent_dnode(page)	is_node(page, DENT_BIT_SHIFT)
+#define is_cold_node(page)		is_node(page, COLD_BIT_SHIFT)
+#define is_fsync_dnode(page)		is_node(page, FSYNC_BIT_SHIFT)
+#define is_dent_dnode(page)		is_node(page, DENT_BIT_SHIFT)
+#define is_recovered_dnode(page)	is_node(page, RECOVERED_BIT_SHIFT)
 
 static inline int is_inline_node(struct page *page)
 {
@@ -442,3 +443,4 @@ static inline void set_mark(struct page *page, int mark, int type)
 }
 #define set_dentry_mark(page, mark)	set_mark(page, mark, DENT_BIT_SHIFT)
 #define set_fsync_mark(page, mark)	set_mark(page, mark, FSYNC_BIT_SHIFT)
+#define set_recovered_mark(page, mark)	set_mark(page, mark, RECOVERED_BIT_SHIFT)
fs/f2fs/recovery.c +14 -8
index 7d63faf..bfbb3e4 100644
@@ -220,6 +220,14 @@ static void recover_inode(struct inode *inode, struct page *page)
 			ino_of_node(page), name);
 }
 
+static void destroy_fsync_dnodes(struct list_head *head)
+{
+	struct fsync_inode_entry *entry, *tmp;
+
+	list_for_each_entry_safe(entry, tmp, head, list)
+		del_fsync_inode(entry);
+}
+
 static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 				bool check_only)
 {
@@ -239,7 +247,13 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 			return 0;
 
 		page = get_tmp_page(sbi, blkaddr);
+		if (unlikely(is_recovered_dnode(page))) {
+			f2fs_msg(sbi->sb, KERN_ERR, "Abandon dead loop node block list");
+			destroy_fsync_dnodes(head);
+			break;
+		}
 
+		set_recovered_mark(page, RECOVERED_BIT_SHIFT);
 		if (!is_recoverable_dnode(page))
 			break;
 
@@ -288,14 +302,6 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 	return err;
 }
 
-static void destroy_fsync_dnodes(struct list_head *head)
-{
-	struct fsync_inode_entry *entry, *tmp;
-
-	list_for_each_entry_safe(entry, tmp, head, list)
-		del_fsync_inode(entry);
-}
-
 static int check_index_in_prev_nodes(struct f2fs_sb_info *sbi,
 			block_t blkaddr, struct dnode_of_data *dn)
 {
include/linux/f2fs_fs.h +0 -0
index 43e98d3..9aa85b1 100644

include/linux/f2fs_fs.h enum { · line 269

Quoted 6 lines
include/linux/f2fs_fs.h +2 -1
@@ -265,7 +265,8 @@ enum {
 	COLD_BIT_SHIFT = 0,
 	FSYNC_BIT_SHIFT,
 	DENT_BIT_SHIFT,
-	OFFSET_BIT_SHIFT
+	OFFSET_BIT_SHIFT,
+	RECOVERED_BIT_SHIFT

This will make adding new bits be difficult in future. Can we get another in-memory one to check block loop?

Thanks,

Quoted 5 lines
include/linux/f2fs_fs.h +0 -0
 };
 
 #define OFFSET_BIT_MASK		(0x07)	/* (0x01 << OFFSET_BIT_SHIFT) - 1 */
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