Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1049915pxb; Thu, 4 Mar 2021 01:45:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRjFmVfjfZiz1SFRcKGCFTLFZaUAeYUj+W7j9QtdC23PaCSxZwqaJkRLJq82jDw8NhzAyq X-Received: by 2002:aa7:cf02:: with SMTP id a2mr3294457edy.59.1614851158470; Thu, 04 Mar 2021 01:45:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614851158; cv=none; d=google.com; s=arc-20160816; b=0+Pdw1r7O64StUPhlGkW/1hXiav5Cb7g7bepvHL9w5sULX8YWryg7rLJhBZAiFxhsY yKZOnJUCujgH827YH2GcL+aYBsjv1hW3dilwlUAX8clDmBoFNed8++cy0eux99+oTFXt sjVo//b2mPC+R0JeiFnzU/nUe0oRlgZqPCFKxZwdWfygH1A8eYFGDCCC8rGcl393P43f 4whPWQU6aHT8K8WC2BUAiiDkU+dfbnudPHdILr93sQdCYKX/XgDLXA+lxt5S1PpjuWbt ZRScc7ZlXL6hp3KWTBV1b55e0Z8LRI/OSTya/5ydIAXn/lTfBar1Oc2HEFuqc2+gWfRM XauQ== 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=H5R8J20hs49b7pB0WOuQDdmAcsezQbjiKIfwTgYjCTM=; b=PaV8+A+TmBHnFwy/twptewMe4x2mvj6/d5cXy/UY4lSZDgbnmCV5pnzC6T852krrBU 43TcT3Cz/mW2CsLpCRKZUEhIimW82/TTHld2zFNFg57jj1QtemHty3Px4f54XJTyDx8p keTLWaYyenZl4ixKgWHjd0HYurlgnApCoy4PRf3PLdQNSnzuE8QtFNn3uekZj0s0a79I j1loBfbCGDkNnY9tLljNT29OOcmSV5dqK5MaE0+LRROgTYD8HHzJ7cmiaPBaXoYpKDHU q3tXIDRAXFzfKDvh81I+8+z8qI2+u+qHx5HifIzn+cK/WO3TlMe+XL5WY6A3u1SRv4Xg ORzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd18si8364018edb.609.2021.03.04.01.45.35; Thu, 04 Mar 2021 01:45:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383639AbhCCPc1 (ORCPT + 99 others); Wed, 3 Mar 2021 10:32:27 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:13426 "EHLO szxga06-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346386AbhCCNKv (ORCPT ); Wed, 3 Mar 2021 08:10:51 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4DrDpH5by9zjTHv; Wed, 3 Mar 2021 21:08:39 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.498.0; Wed, 3 Mar 2021 21:09:54 +0800 From: "zhangyi (F)" To: CC: , , , Subject: [PATCH v1 1/2] ext4: find old entry again if failed to rename whiteout Date: Wed, 3 Mar 2021 21:17:02 +0800 Message-ID: <20210303131703.330415-1-yi.zhang@huawei.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If we failed to add new entry on rename whiteout, we cannot reset the old->de entry directly, because the old->de could have moved from under us during make indexed dir. So find the old entry again before reset is needed, otherwise it may corrupt the filesystem as below. /dev/sda: Entry '00000001' in ??? (12) has deleted/unused inode 15. CLEARED. /dev/sda: Unattached inode 75 /dev/sda: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY. Fixes: 6b4b8e6b4ad ("ext4: fix bug for rename with RENAME_WHITEOUT") Cc: stable@vger.kernel.org Signed-off-by: zhangyi (F) --- fs/ext4/namei.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index cf652ba3e74d..17d9400563fa 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3602,6 +3602,31 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent, return retval; } +static void ext4_resetent(handle_t *handle, struct ext4_renament *ent, + unsigned ino, unsigned file_type) +{ + struct ext4_renament old = *ent; + int retval = 0; + + /* + * old->de could have moved from under us during make indexed dir, + * so the old->de may no longer valid and need to find it again + * before reset old inode info. + */ + old.bh = ext4_find_entry(old.dir, &old.dentry->d_name, &old.de, NULL); + if (IS_ERR(old.bh)) + retval = PTR_ERR(old.bh); + if (!old.bh) + retval = -ENOENT; + if (retval) { + ext4_std_error(old.dir->i_sb, retval); + return; + } + + ext4_setent(handle, &old, ino, file_type); + brelse(old.bh); +} + static int ext4_find_delete_entry(handle_t *handle, struct inode *dir, const struct qstr *d_name) { @@ -3924,8 +3949,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, end_rename: if (whiteout) { if (retval) { - ext4_setent(handle, &old, - old.inode->i_ino, old_file_type); + ext4_resetent(handle, &old, + old.inode->i_ino, old_file_type); drop_nlink(whiteout); } unlock_new_inode(whiteout); -- 2.25.4