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.

Signed-off-by: Yunlei He <[email protected]>
---
 fs/f2fs/node.h          |  8 +++++---
 fs/f2fs/recovery.c      | 22 ++++++++++++++--------
 include/linux/f2fs_fs.h |  3 ++-
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h
index 0ee3e5f..049ff5e 100644
--- a/fs/f2fs/node.h
+++ b/fs/f2fs/node.h
@@ -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)
diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c
index 7d63faf..bfbb3e4 100644
--- a/fs/f2fs/recovery.c
+++ b/fs/f2fs/recovery.c
@@ -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)
 {
diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h
index 43e98d3..9aa85b1 100644
--- a/include/linux/f2fs_fs.h
+++ b/include/linux/f2fs_fs.h
@@ -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 */
-- 
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
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to