Skip to contentSkip to conversation

f2fs: avoid dead loop in function find_fsync_dnodes

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

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Yunlei He

author
#0 lore raw

PATCH v3 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/data.c     |  5 +++++
 fs/f2fs/recovery.c | 23 +++++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)
fs/f2fs/data.c +5 -0
index 7aca6cc..2ac992f 100644
@@ -2146,6 +2146,9 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
 		}
 	}
 
+	if (PageChecked(page))
+		ClearPageChecked(page);
+
 	/* This is atomic written page, keep Private */
 	if (IS_ATOMIC_WRITTEN_PAGE(page))
 		return drop_inmem_page(inode, page);
@@ -2292,6 +2295,8 @@ int f2fs_migrate_page(struct address_space *mapping,
 		SetPagePrivate(newpage);
 	set_page_private(newpage, page_private(page));
 
+	if (PageChecked(page))
+		SetPageChecked(page);
 	if (mode != MIGRATE_SYNC_NO_COPY)
 		migrate_page_copy(newpage, page);
 	else
fs/f2fs/recovery.c +15 -8
index 7d63faf..905be02 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,14 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 			return 0;
 
 		page = get_tmp_page(sbi, blkaddr);
+		if (PageChecked(page)) {
+			f2fs_msg(sbi->sb, KERN_ERR, "Abandon dead loop node block list");
+			destroy_fsync_dnodes(head);
+			break;
+		}
 
+		/* No need ClearPageChecked for page cache truncated */
+		SetPageChecked(page);
 		if (!is_recoverable_dnode(page))
 			break;
 
@@ -288,14 +303,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)
 {
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
#1 lore raw
Quoted 31 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/data.c     |  5 +++++
 fs/f2fs/recovery.c | 23 +++++++++++++++--------
 2 files changed, 20 insertions(+), 8 deletions(-)
fs/f2fs/data.c +0 -0
index 7aca6cc..2ac992f 100644

fs/f2fs/data.c void f2fs_invalidate_page(struct page *page, unsigned int offset, · line 2150

Quoted 5 lines
fs/f2fs/data.c +2 -0
@@ -2146,6 +2146,9 @@ void f2fs_invalidate_page(struct page *page, unsigned int offset,
 		}
 	}
 
+	if (PageChecked(page))
+		ClearPageChecked(page);

IMO, we don't need to care about this flag like most other PG_* flags during truncation.

fs/f2fs/data.c int f2fs_migrate_page(struct address_space *mapping, · line 2299

Quoted 10 lines
fs/f2fs/data.c +3 -0
+
 	/* This is atomic written page, keep Private */
 	if (IS_ATOMIC_WRITTEN_PAGE(page))
 		return drop_inmem_page(inode, page);
@@ -2292,6 +2295,8 @@ int f2fs_migrate_page(struct address_space *mapping,
 		SetPagePrivate(newpage);
 	set_page_private(newpage, page_private(page));
 
+	if (PageChecked(page))
+		SetPageChecked(page);

Actually, migrate_page_copy will do this job.

Quoted 8 lines
fs/f2fs/data.c +0 -0
 	if (mode != MIGRATE_SYNC_NO_COPY)
 		migrate_page_copy(newpage, page);
 	else
fs/f2fs/recovery.c +0 -0
index 7d63faf..905be02 100644

fs/f2fs/recovery.c static void recover_inode(struct inode *inode, struct page *page) · line 229

Quoted 10 lines
fs/f2fs/recovery.c +7 -0
@@ -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);
+}

How about moving this function behind del_fsync_inode?

fs/f2fs/recovery.c static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, · line 251

Quoted 10 lines
fs/f2fs/recovery.c +3 -0
+
 static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 				bool check_only)
 {
@@ -239,7 +247,14 @@ static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head,
 			return 0;
 
 		page = get_tmp_page(sbi, blkaddr);
+		if (PageChecked(page)) {
+			f2fs_msg(sbi->sb, KERN_ERR, "Abandon dead loop node block list");

"Abandon looped node block list"

fs/f2fs/recovery.c static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, · line 256

Quoted 5 lines
fs/f2fs/recovery.c +4 -0
+			destroy_fsync_dnodes(head);
+			break;
+		}
 
+		/* No need ClearPageChecked for page cache truncated */

/*
* it's not needed to clear PG_checked flag in temp page since we
* will truncate all those pages in the end of recovery. */

fs/f2fs/recovery.c static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, · line 257

Quoted 1 line
fs/f2fs/recovery.c +1 -0
+		SetPageChecked(page);

Will looks more neat to leave a blank line here.

Thanks,

Quoted 9 lines
fs/f2fs/recovery.c +0 -1
 		if (!is_recoverable_dnode(page))
 			break;
 
@@ -288,14 +303,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)

fs/f2fs/recovery.c static int find_fsync_dnodes(struct f2fs_sb_info *sbi, struct list_head *head, · line 308

Quoted 10 lines
fs/f2fs/recovery.c +0 -7
-{
-	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)
 {

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