Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9650940pxu; Tue, 29 Dec 2020 00:55:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXY8Qo0Tn9sUbisX8sN18ewsca/AGGExVRQMiIYLUXeWF89WwcgtUqKilazLcEw73a9nJN X-Received: by 2002:a17:906:8152:: with SMTP id z18mr46143620ejw.317.1609232120317; Tue, 29 Dec 2020 00:55:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609232120; cv=none; d=google.com; s=arc-20160816; b=OcsFyw0MOgoQA0uDeHfyF5Zpg3mgQPf0I2jDNqgDm+fZNz9sO4d1gogHLeVR3bh5y5 sCb/hpRvMdkeXL6HBFlRsa5vi9NziUz2Ivxy8TMka5ha0ImikmqHak7uqMVFM6bMFjqN w3hp7orC5O2VbxGtDAQ/Dux2FHAIZ5hyFKpye26vAoaOPG43vGdErV1tFuLvLaGL+HIq wHTunr1n0dltAxyuMJNkjIVKxZUjSoMzPV8TUlsG31q6TMuPdjEBhOfXtAmBkk1wV6Ad pelesvLIo9Jv13fHL7m1ctdtnHRoFMCRXMGOck7NKkWnF8gyvPjo01/1vKEpLFKJhiev E1ZQ== 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=lJ5pnHA0VK9xrH+WdPzyWkoBltebwrJ30/3vuLRMqaU=; b=cjEQ5UPtC4F7kqRQ0BXFt6pZh5hj4rAzNOg9gUbDVV4U2l4dh3UGJxi8yQfue9zwaK lWSC4rR5N4vm32ktkGfc3zsiIwq7cWlYRM9koLdAGD1ndrrZgianG+1+qbxqsA0gGszw xjuNUFKGAraf3MPUSwBtpCnCVvU2efFrie6AZ0yxUtlTK8UA3GIOPcb2bqD8+wR7geb9 qP5SlNnx/l7TIaQE2bJl5l1RsP7KWNIaTwGRL5uclZ6R0FmYYaUN5GoN+VghV7Nn7RWj jdrJp6vVWIarkxltWG2AAgBZnbRUHwelWJ/uCIxk8RsUGDhilGUouKdh+XcMvAcOHycv FXtg== 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 v25si20233357ejx.201.2020.12.29.00.54.52; Tue, 29 Dec 2020 00:55:20 -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 S1726021AbgL2IyX (ORCPT + 99 others); Tue, 29 Dec 2020 03:54:23 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10088 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725986AbgL2IyW (ORCPT ); Tue, 29 Dec 2020 03:54:22 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D4p8K5B1fzM9wm; Tue, 29 Dec 2020 16:52:33 +0800 (CST) Received: from code-website.localdomain (10.175.127.227) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.498.0; Tue, 29 Dec 2020 16:53:27 +0800 From: yangerkun To: , , , CC: , , , , Subject: [PATCH] ext4: fix bug for rename with RENAME_WHITEOUT Date: Tue, 29 Dec 2020 16:56:09 +0800 Message-ID: <20201229085609.1109598-1-yangerkun@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 ext4_rename will create a special inode for whiteout and use this 'ino' to replace the source file's dir entry 'ino'. Once error happens latter(small ext4 img, and consume all space, so the rename with dst path not exist will fail due to the ENOSPC return from ext4_add_entry in ext4_rename), the cleanup do drop the nlink for whiteout, but forget to restore 'ino' with source file. This will lead to "deleted inode referenced". Signed-off-by: yangerkun --- fs/ext4/namei.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index b17a082b7db1..0e89e5a0c758 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3593,9 +3593,6 @@ static int ext4_setent(handle_t *handle, struct ext4_renament *ent, return retval2; } } - brelse(ent->bh); - ent->bh = NULL; - return retval; } @@ -3794,6 +3791,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, } } + old_file_type = old.de->file_type; if (IS_DIRSYNC(old.dir) || IS_DIRSYNC(new.dir)) ext4_handle_sync(handle); @@ -3821,7 +3819,6 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, force_reread = (new.dir->i_ino == old.dir->i_ino && ext4_test_inode_flag(new.dir, EXT4_INODE_INLINE_DATA)); - old_file_type = old.de->file_type; if (whiteout) { /* * Do this before adding a new entry, so the old entry is sure @@ -3919,15 +3916,18 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry, retval = 0; end_rename: - brelse(old.dir_bh); - brelse(old.bh); - brelse(new.bh); if (whiteout) { + ext4_setent(handle, &old, + old.inode->i_ino, old_file_type); if (retval) drop_nlink(whiteout); unlock_new_inode(whiteout); iput(whiteout); + } + brelse(old.dir_bh); + brelse(old.bh); + brelse(new.bh); if (handle) ext4_journal_stop(handle); return retval; -- 2.25.4