Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9654062pxu; Tue, 29 Dec 2020 01:01:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXuLVIAA29PvFYTG26ndaB0T8LGX9B90H5xK69Ol4/BPMICrToFPDAKZ0M+f05N2VOr6Pr X-Received: by 2002:a17:906:8594:: with SMTP id v20mr44291822ejx.470.1609232505573; Tue, 29 Dec 2020 01:01:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609232505; cv=none; d=google.com; s=arc-20160816; b=mvqMBJAY6RHZ10BoXh7ZlrEdSUyk0TOji05vAJYkkY27gMC8CNcHoMO5NU0gdmsoBU 86dn5daYI4iTPQGK1LnP/ughfo9JcxV5R/JjKiYh5zRyZoiPqGgLViS/opxlSLeGzjfc GXGFwGU/1klMNf2z/B8wIQwWAb4a9VQqoUnKmAxCPXgQIAXSOyQcK0M0NEUjqF8ESbCH s3s7Qb51uo4FkBBan8GaLnVOXh/ZbSNLc4pUsZ3Qn7KctBuFzgSt2j42GkHubRtpbsSy cxdEk8SMITGQyOZVYSBdgYDEz5RP1n+WyJE+TO8+zZf9KXT6MS34mZgENqmtrglOQVnY H3sg== 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=rQaa04p0ttoTxl50Cpwb3/uN7k6zAEHEZIIjKojnQec=; b=JIizVIsArbJKBSUF6jCNrpsqLcyDJG+jvCc9tw+or95Id8jlQcEyXTVOgRdTH6gnok NnysVsODK3JbfhJZ9+bI2l3R/rgVXWcmABG17VWKeW/SAnrS9Y8vkjr34LO0hENZnuds uoAXCh3n3JvEItrkBQl4CT7hWW2slcwi1Fgi/JocixNQ75XyHjN4h5eI/5Ov+jDTeTft uc0J3+4MJZiRvLGCSO5mGkeD8FEz7EqiZL2sUhcrpkHNIetZ+rgf9kfWyPoFnQONaPdt h9HsvibbhMBOeP2a5yxxC8wpnxGBaQqfc9Yksgt06sfTZqz15NtAKhTag2ANuUTycIMm CZqA== 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 12si14906942edw.403.2020.12.29.01.01.22; Tue, 29 Dec 2020 01:01:45 -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 S1726277AbgL2JAR (ORCPT + 99 others); Tue, 29 Dec 2020 04:00:17 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10089 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726197AbgL2JAR (ORCPT ); Tue, 29 Dec 2020 04:00:17 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D4pHD6LV4zMBHL; Tue, 29 Dec 2020 16:58:32 +0800 (CST) Received: from code-website.localdomain (10.175.127.227) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Tue, 29 Dec 2020 16:59:26 +0800 From: yangerkun To: , , , CC: , , , , Subject: [PATCH v2] ext4: fix bug for rename with RENAME_WHITEOUT Date: Tue, 29 Dec 2020 17:02:08 +0800 Message-ID: <20201229090208.1113218-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 | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index b17a082b7db1..b3acfd384583 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,17 @@ 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