Message ID | 20230628132011.650383-1-chengzhihao1@huawei.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8934946vqr; Wed, 28 Jun 2023 06:40:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6wDMcmm5FNsS5pOUrjdRGEIsAnvfJzUFxGf6cQeBShhCzrGUnvzqhd2x/ORSRRV2IiHPi/ X-Received: by 2002:a17:902:d2ca:b0:1b6:89bf:4db7 with SMTP id n10-20020a170902d2ca00b001b689bf4db7mr11441361plc.69.1687959655791; Wed, 28 Jun 2023 06:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687959655; cv=none; d=google.com; s=arc-20160816; b=0l+QH6cAwMCkxL5fHF8xzjlDbNbSthMj5SLPNDc+Fv6+TciK5jv+YgVfxDPSH11k0G raElJqjTwPdwGeCD0PjjQftgOQzjKBOtuEJPg4i5IK2fL6glY0ry2HHEM1lfaE4HRnNK gyrjDXC9o9dTxPEHuRtcEaEoI8z74hioFuepPM2ERouI07sQfZPY4W6hH8M5ndTs7N9h D/CEFKS78T5Q4RaaOC717QuNPfnbyQ8mIVfqLNoMyh8tdp5ScFFvfDsPsOgD1GiKvdv6 My4D61+j7cTtM1SsPFoPNUC0Sd4PKzeoYZUSwoqI54i61LrC0TYS2PIRpuS3M2KxhcS0 sdgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Xy7VcvxK/5qip0HyEXTN/bQCOkUqMPdQGMkIcv91zbE=; fh=R2rSyaVmnHN/Kn8y4r5DLi5P6ZTEoPdVcihN749OKHg=; b=Zj2bIOZAokt2OBeGqTT5RfoE6FGsnYXS0kFWkctU8DtSg0NeTXzJbCwXzERzxoofBe k/SdP8VIQMKNbQPpU/dEZ/D8MWBb1C9V/9cb7Dz/faunxpw0wL7fwfRp6XPSjrgiZzX6 tcdnVJiFppWH0AxkflFO/ZZndWK7a++kfrnqSOfToIH8VldIfak47OkYOyvgteDzZ2Aw CBQnEnuRtlTbhzrHiOZN9T5xcH/BHTX55OsRbIo00F9vqizIP2i9XDj8FHgZu6HsYB46 eqMyrJEjV9nE9ISio8ULH/KZHS3cCz3eS02FH9pJumt6sNfgUyzJUysyt9ku33QGAvkE 5gAw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jn11-20020a170903050b00b001b678a193cfsi8516619plb.123.2023.06.28.06.40.43; Wed, 28 Jun 2023 06:40:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231561AbjF1NVM (ORCPT <rfc822;adanhawthorn@gmail.com> + 99 others); Wed, 28 Jun 2023 09:21:12 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:16306 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231437AbjF1NVK (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 28 Jun 2023 09:21:10 -0400 Received: from kwepemm600013.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4QrhxL56yWzLlkr; Wed, 28 Jun 2023 21:19:02 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 28 Jun 2023 21:21:07 +0800 From: Zhihao Cheng <chengzhihao1@huawei.com> To: <tytso@mit.edu>, <adilger.kernel@dilger.ca>, <jack@suse.cz> CC: <linux-ext4@vger.kernel.org>, <linux-kernel@vger.kernel.org>, <chengzhihao1@huawei.com>, <yi.zhang@huawei.com> Subject: [PATCH] ext4: Fix unttached inode after power cut with orphan file feature enabled Date: Wed, 28 Jun 2023 21:20:11 +0800 Message-ID: <20230628132011.650383-1-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.67] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769953984170796981?= X-GMAIL-MSGID: =?utf-8?q?1769953984170796981?= |
Series |
ext4: Fix unttached inode after power cut with orphan file feature enabled
|
|
Commit Message
Zhihao Cheng
June 28, 2023, 1:20 p.m. UTC
Running generic/475(filesystem consistent tests after power cut) could easily trigger unattached inode error while doing fsck: Unattached zero-length inode 39405. Clear? no Unattached inode 39405 Connect to /lost+found? no Above inconsistence is caused by following process: P1 P2 ext4_create inode = ext4_new_inode_start_handle // itable records nlink=1 ext4_add_nondir err = ext4_add_entry // ENOSPC ext4_append ext4_bread ext4_getblk ext4_map_blocks // returns ENOSPC drop_nlink(inode) // won't be updated into disk inode ext4_orphan_add(handle, inode) ext4_orphan_file_add ext4_journal_stop(handle) jbd2_journal_commit_transaction // commit success >> power cut << ext4_fill_super ext4_load_and_init_journal // itable records nlink=1 ext4_orphan_cleanup ext4_process_orphan if (inode->i_nlink) // true, inode won't be deleted Then, allocated inode will be reserved on disk and corresponds to no dentries, so e2fsck reports 'unattached inode' problem. The problem won't happen if orphan file feature is disabled, because ext4_orphan_add() will update disk inode in orphan list mode. There are several places not updating disk inode while putting inode into orphan area, such as ext4_add_nondir(), ext4_symlink() and whiteout in ext4_rename(). Fix it by updating inode into disk in all error branches of these places. Link: https://bugzilla.kernel.org/show_bug.cgi?id=217605 Fixes: 02f310fcf47f ("ext4: Speedup ext4 orphan inode handling") Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> --- fs/ext4/namei.c | 3 +++ 1 file changed, 3 insertions(+)
Comments
On Wed 28-06-23 21:20:11, Zhihao Cheng wrote: > Running generic/475(filesystem consistent tests after power cut) could > easily trigger unattached inode error while doing fsck: > Unattached zero-length inode 39405. Clear? no > > Unattached inode 39405 > Connect to /lost+found? no > > Above inconsistence is caused by following process: > P1 P2 > ext4_create > inode = ext4_new_inode_start_handle // itable records nlink=1 > ext4_add_nondir > err = ext4_add_entry // ENOSPC > ext4_append > ext4_bread > ext4_getblk > ext4_map_blocks // returns ENOSPC > drop_nlink(inode) // won't be updated into disk inode > ext4_orphan_add(handle, inode) > ext4_orphan_file_add > ext4_journal_stop(handle) > jbd2_journal_commit_transaction // commit success > >> power cut << > ext4_fill_super > ext4_load_and_init_journal // itable records nlink=1 > ext4_orphan_cleanup > ext4_process_orphan > if (inode->i_nlink) // true, inode won't be deleted > > Then, allocated inode will be reserved on disk and corresponds to no > dentries, so e2fsck reports 'unattached inode' problem. > > The problem won't happen if orphan file feature is disabled, because > ext4_orphan_add() will update disk inode in orphan list mode. There > are several places not updating disk inode while putting inode into > orphan area, such as ext4_add_nondir(), ext4_symlink() and whiteout > in ext4_rename(). Fix it by updating inode into disk in all error > branches of these places. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=217605 > Fixes: 02f310fcf47f ("ext4: Speedup ext4 orphan inode handling") > Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com> Nice catch. Thanks for fixing this. Feel free to add: Reviewed-by: Jan Kara <jack@suse.cz> Honza > --- > fs/ext4/namei.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c > index 0caf6c730ce3..6bcc3770ee19 100644 > --- a/fs/ext4/namei.c > +++ b/fs/ext4/namei.c > @@ -2799,6 +2799,7 @@ static int ext4_add_nondir(handle_t *handle, > return err; > } > drop_nlink(inode); > + ext4_mark_inode_dirty(handle, inode); > ext4_orphan_add(handle, inode); > unlock_new_inode(inode); > return err; > @@ -3436,6 +3437,7 @@ static int ext4_symlink(struct mnt_idmap *idmap, struct inode *dir, > > err_drop_inode: > clear_nlink(inode); > + ext4_mark_inode_dirty(handle, inode); > ext4_orphan_add(handle, inode); > unlock_new_inode(inode); > if (handle) > @@ -4021,6 +4023,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir, > ext4_resetent(handle, &old, > old.inode->i_ino, old_file_type); > drop_nlink(whiteout); > + ext4_mark_inode_dirty(handle, whiteout); > ext4_orphan_add(handle, whiteout); > } > unlock_new_inode(whiteout); > -- > 2.39.2 >
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 0caf6c730ce3..6bcc3770ee19 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2799,6 +2799,7 @@ static int ext4_add_nondir(handle_t *handle, return err; } drop_nlink(inode); + ext4_mark_inode_dirty(handle, inode); ext4_orphan_add(handle, inode); unlock_new_inode(inode); return err; @@ -3436,6 +3437,7 @@ static int ext4_symlink(struct mnt_idmap *idmap, struct inode *dir, err_drop_inode: clear_nlink(inode); + ext4_mark_inode_dirty(handle, inode); ext4_orphan_add(handle, inode); unlock_new_inode(inode); if (handle) @@ -4021,6 +4023,7 @@ static int ext4_rename(struct mnt_idmap *idmap, struct inode *old_dir, ext4_resetent(handle, &old, old.inode->i_ino, old_file_type); drop_nlink(whiteout); + ext4_mark_inode_dirty(handle, whiteout); ext4_orphan_add(handle, whiteout); } unlock_new_inode(whiteout);