From patchwork Tue Aug 11 10:42:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ?? X-Patchwork-Id: 6991401 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 451619F344 for ; Tue, 11 Aug 2015 10:43:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F8EC2068F for ; Tue, 11 Aug 2015 10:43:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 400F820676 for ; Tue, 11 Aug 2015 10:43:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933981AbbHKKn0 (ORCPT ); Tue, 11 Aug 2015 06:43:26 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:46423 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933919AbbHKKnZ (ORCPT ); Tue, 11 Aug 2015 06:43:25 -0400 Received: from epcpsbgm2new.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NSW0122QZ4A1R00@mailout3.samsung.com>; Tue, 11 Aug 2015 19:43:22 +0900 (KST) X-AuditID: cbfee61b-f79706d000001b96-f5-55c9d1ca0a86 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2new.samsung.com (EPCPMTA) with SMTP id DE.C7.07062.AC1D9C55; Tue, 11 Aug 2015 19:43:22 +0900 (KST) Received: from yuchao ([109.123.105.89]) by mmp1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NSW00EWMZ2KXG00@mmp1.samsung.com>; Tue, 11 Aug 2015 19:43:22 +0900 (KST) From: Chao Yu To: 'Jaegeuk Kim' Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org References: <018001d0d0fd$a8f47240$fadd56c0$@samsung.com> <20150810193201.GB3815@jaegeuk-mac02.mot.com> In-reply-to: <20150810193201.GB3815@jaegeuk-mac02.mot.com> Subject: RE: [PATCH 3/4] f2fs: handle error of f2fs_iget correctly Date: Tue, 11 Aug 2015 18:42:19 +0800 Message-id: <008c01d0d422$88810dc0$99832940$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AQJA3R/N6LEbtBuYl1rTfDSCrmudPgEizHXznR1ZPfA= Content-language: zh-cn X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrBLMWRmVeSWpSXmKPExsVy+t9jAd1TF0+GGmzfbWnxZP0sZotLi9wt 9uw9yWJxedccNgcWj02rOtk8di/4zOTxeZNcAHMUl01Kak5mWWqRvl0CV8aOr8/YC7arVFz8 dISlgfGZbBcjJ4eEgInEpNcT2SBsMYkL99YD2VwcQgJLGSW+zZjIDuG8YpR4tPkFC0gVm4CK xPKO/0wgtoiAmkTvvilgNrNApsSE/fPBaoSA7AuNk8CmcgpYSTRu3c0IYgsLOEms2rabHcRm EVCVmH3nCVANBwevgKXEvF0uIGFeAUGJH5PvsUCM1JJYv/M41Hh5ic1r3jJDHKogsePsa0aI E6wk2qceYoSoEZfYeOQWywRGoVlIRs1CMmoWklGzkLQsYGRZxSiRWpBcUJyUnmuUl1quV5yY W1yal66XnJ+7iREc/s+kdzAe3uV+iFGAg1GJh1fA82SoEGtiWXFl7iFGCQ5mJRFejtNAId6U xMqq1KL8+KLSnNTiQ4zSHCxK4rz6JptChQTSE0tSs1NTC1KLYLJMHJxSDYxberc/rq9teay2 jFHHeEFESNHCCgVbx5mbpn+6flfZ3/SbpuafI7sWGbYe02yRmq15IcDU0DqB6aD5xL73JTt+ tE1RK1hx947Dk75QD7VldpNENVNu2tdrJe4MXP370zXp74vquntl1zJqdBemhQTs8PlwY/V/ a0HPWz4cbrNfmF1+snsLz2wlluKMREMt5qLiRACFyOTdewIAAA== Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi Jaegeuk, > -----Original Message----- > From: Jaegeuk Kim [mailto:jaegeuk@kernel.org] > Sent: Tuesday, August 11, 2015 3:32 AM > To: Chao Yu > Cc: linux-f2fs-devel@lists.sourceforge.net; linux-kernel@vger.kernel.org; > linux-fsdevel@vger.kernel.org > Subject: Re: [PATCH 3/4] f2fs: handle error of f2fs_iget correctly > > Hi Chao, > > On Fri, Aug 07, 2015 at 06:41:02PM +0800, Chao Yu wrote: > > In recover_orphan_inode, if f2fs_iget failed, we change to report the > > error number to its caller instead of bug_on. > > Let's keep this in order to catch any bugs. > Or, is there another issue on this? f2fs_iget can fail due to a lot of reason, like out of memory, IMO, it's better to report such error number to user instead of make kernel panic. So how about keeping bug_on when finding no entry for orphan inode, otherwise reporting error to caller? From 05068a0068a9d0a60296c492967ef2433ad0e35f Mon Sep 17 00:00:00 2001 From: Chao Yu Date: Fri, 7 Aug 2015 17:58:43 +0800 Subject: [PATCH v2 3/4] f2fs: handle error of f2fs_iget correctly In recover_orphan_inode, whenever f2fs_iget fail, we will make kernel panic, but it's not reasonable, because f2fs_iget can fail due to a lot of reasons including out of memory. So we change error handling method as below: a) when finding no entry for the orphan inode, bug_on for catching bugs; b) for other reasons, report it to caller. Signed-off-by: Chao Yu --- fs/f2fs/checkpoint.c | 31 ++++++++++++++++++++++++------- fs/f2fs/f2fs.h | 2 +- fs/f2fs/super.c | 4 +++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index c311176..0958c83 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -468,22 +468,34 @@ void remove_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) __remove_ino_entry(sbi, ino, ORPHAN_INO); } -static void recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) +static int recover_orphan_inode(struct f2fs_sb_info *sbi, nid_t ino) { - struct inode *inode = f2fs_iget(sbi->sb, ino); - f2fs_bug_on(sbi, IS_ERR(inode)); + struct inode *inode; + + inode = f2fs_iget(sbi->sb, ino); + if (IS_ERR(inode)) { + /* + * there should be a bug that we can't find the entry + * to orphan inode. + */ + f2fs_bug_on(sbi, PTR_ERR(inode) == -ENOENT); + return PTR_ERR(inode); + } + clear_nlink(inode); /* truncate all the data during iput */ iput(inode); + return 0; } -void recover_orphan_inodes(struct f2fs_sb_info *sbi) +int recover_orphan_inodes(struct f2fs_sb_info *sbi) { block_t start_blk, orphan_blocks, i, j; + int err; if (!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG)) - return; + return 0; set_sbi_flag(sbi, SBI_POR_DOING); @@ -499,14 +511,19 @@ void recover_orphan_inodes(struct f2fs_sb_info *sbi) orphan_blk = (struct f2fs_orphan_block *)page_address(page); for (j = 0; j < le32_to_cpu(orphan_blk->entry_count); j++) { nid_t ino = le32_to_cpu(orphan_blk->ino[j]); - recover_orphan_inode(sbi, ino); + err = recover_orphan_inode(sbi, ino); + if (err) { + f2fs_put_page(page, 1); + clear_sbi_flag(sbi, SBI_POR_DOING); + return err; + } } f2fs_put_page(page, 1); } /* clear Orphan Flag */ clear_ckpt_flags(F2FS_CKPT(sbi), CP_ORPHAN_PRESENT_FLAG); clear_sbi_flag(sbi, SBI_POR_DOING); - return; + return 0; } static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f18d31e..d0e9b70 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1748,7 +1748,7 @@ int acquire_orphan_inode(struct f2fs_sb_info *); void release_orphan_inode(struct f2fs_sb_info *); void add_orphan_inode(struct f2fs_sb_info *, nid_t); void remove_orphan_inode(struct f2fs_sb_info *, nid_t); -void recover_orphan_inodes(struct f2fs_sb_info *); +int recover_orphan_inodes(struct f2fs_sb_info *); int get_valid_checkpoint(struct f2fs_sb_info *); void update_dirty_page(struct inode *, struct page *); void add_dirty_dir_inode(struct inode *); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a79b6b5..4db5cd9 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1245,7 +1245,9 @@ try_onemore: f2fs_join_shrinker(sbi); /* if there are nt orphan nodes free them */ - recover_orphan_inodes(sbi); + err = recover_orphan_inodes(sbi); + if (err) + goto free_node_inode; /* read root inode and dentry */ root = f2fs_iget(sb, F2FS_ROOT_INO(sbi));