Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758457Ab3E1BVH (ORCPT ); Mon, 27 May 2013 21:21:07 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:63331 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754803Ab3E1BVD (ORCPT ); Mon, 27 May 2013 21:21:03 -0400 X-AuditID: cbfee690-b7f6f6d00000740c-ef-51a4067c2a5c From: Jaegeuk Kim Cc: Jaegeuk Kim , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: [PATCH 2/3] f2fs: fix dentry recovery routine Date: Tue, 28 May 2013 10:19:44 +0900 Message-id: <1369703985-26284-2-git-send-email-jaegeuk.kim@samsung.com> X-Mailer: git-send-email 1.8.1.3.566.gaa39828 In-reply-to: <1369703985-26284-1-git-send-email-jaegeuk.kim@samsung.com> References: <1369703985-26284-1-git-send-email-jaegeuk.kim@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrJLMWRmVeSWpSXmKPExsVy+t8zfd0atiWBBpNms1pc3/WXyeLSIneL PXtPslhc3jWHzYHFY/eCz0wefVtWMXp83iQXwBzFZZOSmpNZllqkb5fAlXFs1SuWgg38FUse 7WRpYNzM08XIwSEhYCLxcEFhFyMnkCkmceHeerYuRi4OIYFljBJbFz1mgqn59T4ZIj6dUeLq 0VusEE4bk8SnCTeYQYrYBLQlNu83ABkkIsAssWDqeUaQGmaBCYwS/xe9ZwFJCAuYSWy/+x2s nkVAVeL28hqQMK+Au8SuDwdYII7QlVj9/zk7SAmngIfEgRZZkLAQUMm3G0/B1koIfGeTuLph CVg9i4CAxLfJh1gg7pSV2HSAGWKMpMTBFTdYJjAKL2BkWMUomlqQXFCclF5kolecmFtcmpeu l5yfu4kREqwTdjDeO2B9iDEZaNxEZinR5HxgsOeVxBsamxlZmJqYGhuZW5qRJqwkzqveYh0o JJCeWJKanZpakFoUX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filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected To: unlisted-recipients:; (no To-header on input) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2146 Lines: 72 The error scenario is: 1. create /a (1.a link /a /b) 2. sync 3. unlinke /a 4. create /a 5. fsync /a 6. Sudden power-off When the f2fs recovers the fsynced dentry, /a, we discover an exsiting dentry at f2fs_find_entry() in recover_dentry(). In such the case, we should unlink the existing dentry and its inode and then recover newly created dentry. Signed-off-by: Jaegeuk Kim --- fs/f2fs/recovery.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index 0dd2ce1..85f5e54 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -44,9 +44,10 @@ static int recover_dentry(struct page *ipage, struct inode *inode) struct f2fs_node *raw_node = (struct f2fs_node *)kaddr; struct f2fs_inode *raw_inode = &(raw_node->i); nid_t pino = le32_to_cpu(raw_inode->i_pino); + struct f2fs_dir_entry *de; struct qstr name; struct page *page; - struct inode *dir; + struct inode *dir, *einode; int err = 0; dir = check_dirty_dir_inode(F2FS_SB(inode->i_sb), pino); @@ -61,13 +62,21 @@ static int recover_dentry(struct page *ipage, struct inode *inode) name.len = le32_to_cpu(raw_inode->i_namelen); name.name = raw_inode->i_name; - - if (f2fs_find_entry(dir, &name, &page)) { - kunmap(page); - f2fs_put_page(page, 0); - } else { - err = __f2fs_add_link(dir, &name, inode); +retry: + de = f2fs_find_entry(dir, &name, &page); + if (de) { + einode = f2fs_iget(inode->i_sb, le32_to_cpu(de->ino)); + if (IS_ERR(einode)) { + WARN_ON(1); + if (PTR_ERR(einode) == -ENOENT) + err = -EEXIST; + goto out; + } + f2fs_delete_entry(de, page, einode); + iput(einode); + goto retry; } + err = __f2fs_add_link(dir, &name, inode); out: f2fs_msg(inode->i_sb, KERN_NOTICE, "recover_inode and its dentry: " "ino = %x, name = %s, dir = %lx, err = %d", -- 1.8.1.3.566.gaa39828 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/