From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01BBEC433DB for ; Thu, 25 Mar 2021 11:33:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B50F161A35 for ; Thu, 25 Mar 2021 11:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231175AbhCYLdH (ORCPT ); Thu, 25 Mar 2021 07:33:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:35196 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230241AbhCYLat (ORCPT ); Thu, 25 Mar 2021 07:30:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F0A3161A6A; Thu, 25 Mar 2021 11:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616671670; bh=JBTBEfHAMOe0Iw9vcNuPDMGZgAd/rG3rIfRDTWy16XY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kXs37Ni472Emm/OMsLKHPxZiV9tXghoFfAyFmP5PFYRKTnpHCMCvcyqo5xK9qcYLb rf/iY7ImLLP3XYuamtf80P7EJ8uI56WEL0+LT83h7A0eygUxmIwU9VxznatjkJFg4h sn7zzfDByqoCOIFFHst0WtWtaUqzVfCUpiz/9Nd/p/dhiFvjojwyCpyVHxnYBGQKPG OUU/iT81crs1cENAwFC6mOZOoxxRIhpF1RvrVA8L0e6at0XafPL1SK2L+WhOZrn5Th smfANxcUyoHXU6WLelMqb8SF0floCt8mlxMeastgHAT/CQDS/ZaRciCVmQyq5mjCSQ XI5O7nLpXduiA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: "zhangyi (F)" , Theodore Ts'o , Sasha Levin , linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 20/20] ext4: do not iput inode under running transaction in ext4_rename() Date: Thu, 25 Mar 2021 07:27:24 -0400 Message-Id: <20210325112724.1928174-20-sashal@kernel.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210325112724.1928174-1-sashal@kernel.org> References: <20210325112724.1928174-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: "zhangyi (F)" [ Upstream commit 5dccdc5a1916d4266edd251f20bbbb113a5c495f ] In ext4_rename(), when RENAME_WHITEOUT failed to add new entry into directory, it ends up dropping new created whiteout inode under the running transaction. After commit <9b88f9fb0d2> ("ext4: Do not iput inode under running transaction"), we follow the assumptions that evict() does not get called from a transaction context but in ext4_rename() it breaks this suggestion. Although it's not a real problem, better to obey it, so this patch add inode to orphan list and stop transaction before final iput(). Signed-off-by: zhangyi (F) Link: https://lore.kernel.org/r/20210303131703.330415-2-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/namei.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 0dde6385a125..d6cc013098e1 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3599,14 +3599,14 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, */ retval = -ENOENT; if (!old.bh || le32_to_cpu(old.de->inode) != old.inode->i_ino) - goto end_rename; + goto release_bh; new.bh = ext4_find_entry(new.dir, &new.dentry->d_name, &new.de, &new.inlined); if (IS_ERR(new.bh)) { retval = PTR_ERR(new.bh); new.bh = NULL; - goto end_rename; + goto release_bh; } if (new.bh) { if (!new.inode) { @@ -3623,15 +3623,13 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, handle = ext4_journal_start(old.dir, EXT4_HT_DIR, credits); if (IS_ERR(handle)) { retval = PTR_ERR(handle); - handle = NULL; - goto end_rename; + goto release_bh; } } else { whiteout = ext4_whiteout_for_rename(&old, credits, &handle); if (IS_ERR(whiteout)) { retval = PTR_ERR(whiteout); - whiteout = NULL; - goto end_rename; + goto release_bh; } } @@ -3739,16 +3737,18 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, ext4_setent(handle, &old, old.inode->i_ino, old_file_type); drop_nlink(whiteout); + ext4_orphan_add(handle, whiteout); } unlock_new_inode(whiteout); + ext4_journal_stop(handle); iput(whiteout); - + } else { + ext4_journal_stop(handle); } +release_bh: brelse(old.dir_bh); brelse(old.bh); brelse(new.bh); - if (handle) - ext4_journal_stop(handle); return retval; } -- 2.30.1