From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A82F3C092; Wed, 10 Jul 2024 04:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; cv=none; b=YsbtfZKYlPpqqdGnD8yHRrBk6jpB6k2kU7q/4E5jXMH7mHyplyTyUZxl/4zMsrmraX/Z7n5qp7TrdQr7njJgEgEm1J8p7tTqcQj7RldjzRFbOsJnBR0zLITlY66y/DqbACKLfF8ZwAcuNtam5szjibVTNniu8/Xl/YswDUPxzCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; c=relaxed/simple; bh=ykysJ0jIu2v2r6KTy4ZJ2qVAlIx9thwidx8uspBQ5RE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=RpI6bV2GX1D4J0KqKnt5ZIH2fnH8yol0lztofYnnXg5vZEf77yWva6KMejaTob92VTuKfMRi8npi/zN99ri8bC6Ueqkl9EB/n1+gX2H60bt8H/dme1S4/nJAQ7yZj+cdk4fKdaW1PZZe7IrS7R3+//Ocz02TEthVya3KtjfY//c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkr41RP3z4f3m7Y; Wed, 10 Jul 2024 12:08:52 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 0E9111A0181; Wed, 10 Jul 2024 12:09:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S5; Wed, 10 Jul 2024 12:09:04 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 01/20] ext4: refactor ext4_ext_rm_idx() to index 'path' Date: Wed, 10 Jul 2024 12:06:35 +0800 Message-Id: <20240710040654.1714672-2-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S5 X-Coremail-Antispam: 1UD129KBjvJXoWxWr43GFy7tryrWr18Jw48tFb_yoW5WrWkpF 1ayrn5Cr4jgrWj9FZ7GF47Ar1293W2934xGrWSk34ruFyxXrnYqFyxtFZYyFWfAFWrWaya qFWrt3W5t342y37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPG14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r1I6r4UM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l x2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14 v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IY x2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87 Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIF yTuYvjfUe9N3UUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IIQAAs+ From: Baokun Li As suggested by Honza in Link=EF=BC=8Cmodify ext4_ext_rm_idx() to leave 'pa= th' alone and just index it like ext4_ext_correct_indexes() does it. This facilitates adding error handling later. No functional changes. Suggested-by: Jan Kara Link: https://lore.kernel.org/all/20230216130305.nrbtd42tppxhbynn@quack3/ Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index e067f2dd0335..bff3666c891a 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2279,27 +2279,26 @@ static int ext4_ext_rm_idx(handle_t *handle, struct= inode *inode, { int err; ext4_fsblk_t leaf; + int k =3D depth - 1; =20 /* free index block */ - depth--; - path =3D path + depth; - leaf =3D ext4_idx_pblock(path->p_idx); - if (unlikely(path->p_hdr->eh_entries =3D=3D 0)) { - EXT4_ERROR_INODE(inode, "path->p_hdr->eh_entries =3D=3D 0"); + leaf =3D ext4_idx_pblock(path[k].p_idx); + if (unlikely(path[k].p_hdr->eh_entries =3D=3D 0)) { + EXT4_ERROR_INODE(inode, "path[%d].p_hdr->eh_entries =3D=3D 0", k); return -EFSCORRUPTED; } - err =3D ext4_ext_get_access(handle, inode, path); + err =3D ext4_ext_get_access(handle, inode, path + k); if (err) return err; =20 - if (path->p_idx !=3D EXT_LAST_INDEX(path->p_hdr)) { - int len =3D EXT_LAST_INDEX(path->p_hdr) - path->p_idx; + if (path[k].p_idx !=3D EXT_LAST_INDEX(path[k].p_hdr)) { + int len =3D EXT_LAST_INDEX(path[k].p_hdr) - path[k].p_idx; len *=3D sizeof(struct ext4_extent_idx); - memmove(path->p_idx, path->p_idx + 1, len); + memmove(path[k].p_idx, path[k].p_idx + 1, len); } =20 - le16_add_cpu(&path->p_hdr->eh_entries, -1); - err =3D ext4_ext_dirty(handle, inode, path); + le16_add_cpu(&path[k].p_hdr->eh_entries, -1); + err =3D ext4_ext_dirty(handle, inode, path + k); if (err) return err; ext_debug(inode, "index is empty, remove it, free block %llu\n", leaf); @@ -2308,15 +2307,14 @@ static int ext4_ext_rm_idx(handle_t *handle, struct= inode *inode, ext4_free_blocks(handle, inode, NULL, leaf, 1, EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET); =20 - while (--depth >=3D 0) { - if (path->p_idx !=3D EXT_FIRST_INDEX(path->p_hdr)) + while (--k >=3D 0) { + if (path[k + 1].p_idx !=3D EXT_FIRST_INDEX(path[k + 1].p_hdr)) break; - path--; - err =3D ext4_ext_get_access(handle, inode, path); + err =3D ext4_ext_get_access(handle, inode, path + k); if (err) break; - path->p_idx->ei_block =3D (path+1)->p_idx->ei_block; - err =3D ext4_ext_dirty(handle, inode, path); + path[k].p_idx->ei_block =3D path[k + 1].p_idx->ei_block; + err =3D ext4_ext_dirty(handle, inode, path + k); if (err) break; } --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E22FB15D1; Wed, 10 Jul 2024 04:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; cv=none; b=BC45zDeYIpF94txhsssNdbwMXB2bBvTJI6XqfueODG28fzG9iaLKlfO4Rqr7vKu+MyHorBoK4sTPCZJbYsdZCZbpvblAy7sHeqP9VEL8VQ1QN0GscNXO5bZxSfLwrUNP/x8ZmqqiWn8V7eFkFPYFAjmWSUnpMoQvsFbw+u9YSW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; c=relaxed/simple; bh=gwRcVK2dLKOaYtOn17+khUsO6T+UH8dmKwhGcmf0u1c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JAzWkdR38HWZzQS5y7cBf8UZEU2WrURdi6BfEBo6eA/zNmNpCjL6SLXsT8I/iQR6VbvobpP5sosgBslDEgZ+j21pecM3VUpcH8CfrcBDNHCRfvCwTQzLVq0U3pJFGQpL++kS3c6TLwBb7Ql+X+KG6NVTV/mOo3Yx3QMa66xtNB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkr564hLz4f3mJX; Wed, 10 Jul 2024 12:08:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 761C11A0189; Wed, 10 Jul 2024 12:09:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S6; Wed, 10 Jul 2024 12:09:05 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li , zhanchengbin Subject: [PATCH 02/20] ext4: prevent partial update of the extents path Date: Wed, 10 Jul 2024 12:06:36 +0800 Message-Id: <20240710040654.1714672-3-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S6 X-Coremail-Antispam: 1UD129KBjvJXoW7KF15tFWUJF15Jr4ftF4DCFg_yoW5JF1xpr nIkrn5Gr48Way3uFW3tFWUZFy3K3Wkuw4xGrWxC343WFy5ZryFqryxKF13CFyrJrWxWa4f XrW8tw1UKw1DGa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPG14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l x2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14 v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IY x2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87 Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIF yTuYvjfU1GQDUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAPBV1jkIIt0wAEsd Content-Type: text/plain; charset="utf-8" From: Baokun Li In ext4_ext_rm_idx() and ext4_ext_correct_indexes(), there is no proper rollback of already executed updates when updating a level of the extents path fails, so we may get an inconsistent extents tree, which may trigger some bad things in errors=3Dcontinue mode. Hence clear the verified bit of modified extents buffers if the tree fails to be updated in ext4_ext_rm_idx() or ext4_ext_correct_indexes(), which forces the extents buffers to be checked in ext4_valid_extent_entries(), ensuring that the extents tree is consistent. Signed-off-by: zhanchengbin Link: https://lore.kernel.org/r/20230213080514.535568-3-zhanchengbin1@huawe= i.com/ Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index bff3666c891a..4d589d34b30e 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1749,12 +1749,23 @@ static int ext4_ext_correct_indexes(handle_t *handl= e, struct inode *inode, break; err =3D ext4_ext_get_access(handle, inode, path + k); if (err) - break; + goto clean; path[k].p_idx->ei_block =3D border; err =3D ext4_ext_dirty(handle, inode, path + k); if (err) - break; + goto clean; } + return 0; + +clean: + /* + * The path[k].p_bh is either unmodified or with no verified bit + * set (see ext4_ext_get_access()). So just clear the verified bit + * of the successfully modified extents buffers, which will force + * these extents to be checked to avoid using inconsistent data. + */ + while (++k < depth) + clear_buffer_verified(path[k].p_bh); =20 return err; } @@ -2312,12 +2323,24 @@ static int ext4_ext_rm_idx(handle_t *handle, struct= inode *inode, break; err =3D ext4_ext_get_access(handle, inode, path + k); if (err) - break; + goto clean; path[k].p_idx->ei_block =3D path[k + 1].p_idx->ei_block; err =3D ext4_ext_dirty(handle, inode, path + k); if (err) - break; + goto clean; } + return 0; + +clean: + /* + * The path[k].p_bh is either unmodified or with no verified bit + * set (see ext4_ext_get_access()). So just clear the verified bit + * of the successfully modified extents buffers, which will force + * these extents to be checked to avoid using inconsistent data. + */ + while (++k < depth) + clear_buffer_verified(path[k].p_bh); + return err; } =20 --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F7B53D96D; Wed, 10 Jul 2024 04:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; cv=none; b=iJzHUEMfdrPFDFMreOXf+vBkNS6/yZJfN0lM2JmNw3CL1D8HjDNJJnDzLAxt//5NX+Wy3pHwFpAxeDuzwxKegqKkGmKbEcOFJNR3petNctbfaVs/yJLcnPDnZMP5tOWMTqECEq1gar4WR2PpU2eljzxlDnTP75VhB1srM7E9HEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; c=relaxed/simple; bh=dG9CFH2mnaAi3k/Ik6GZklICo+ygmHf+tl6LKKkgQko=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nKI+DJjXbnc9pC9mZyU8WlwcsAziVE6mZTRnly3s5ekTpMXObXt0vfIKsGOJg9AMAlN4Jglbtjt80VVWYfm2QFMWVlTPGaQyxW2OGAmUftA/wJQuubtX0TyOPYZE4yOn/Wvqed8bOQV5g6CxhpzC0piEuA9B5Vv67RNGMwFUJZQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrB238Lz4f3kp6; Wed, 10 Jul 2024 12:08:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id E21C21A0CE8; Wed, 10 Jul 2024 12:09:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S7; Wed, 10 Jul 2024 12:09:05 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li , stable@kernel.org Subject: [PATCH 03/20] ext4: fix double brelse() the buffer of the extents path Date: Wed, 10 Jul 2024 12:06:37 +0800 Message-Id: <20240710040654.1714672-4-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S7 X-Coremail-Antispam: 1UD129KBjvJXoWxWF43AFyfJw1rWr48XFyftFb_yoW5Gw1rpr sIkryxGr1rt3yq9FWDXa1UWr18C3W7Gw47JFWfG3WjkFyDAr4kXFyxt3WFvFyUuFW8uFWY vrW8t34UW3Z8Ga7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPG14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JrWl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1l x2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14 v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0I7IY x2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87 Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIF yTuYvjfUOOJ5UUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IIgAAs9 Content-Type: text/plain; charset="utf-8" From: Baokun Li In ext4_ext_try_to_merge_up(), set path[1].p_bh to NULL after it has been released, otherwise it may be released twice. An example of what triggers this is as follows: split2 map split1 |--------|-------|--------| ext4_ext_map_blocks ext4_ext_handle_unwritten_extents ext4_split_convert_extents // path->p_depth =3D=3D 0 ext4_split_extent // 1. do split1 ext4_split_extent_at ext4_ext_insert_extent ext4_ext_create_new_leaf ext4_ext_grow_indepth le16_add_cpu(&neh->eh_depth, 1) ext4_find_extent path->p_depth =3D 1 ext4_ext_try_to_merge ext4_ext_try_to_merge_up path->p_depth =3D 0 brelse(path[1].p_bh) ---> not set to NULL here // 2. update path ext4_find_extent // 3. do split2 ext4_split_extent_at ext4_ext_insert_extent ext4_ext_create_new_leaf ext4_ext_grow_indepth le16_add_cpu(&neh->eh_depth, 1) ext4_find_extent path[0].p_bh =3D NULL; path->p_depth =3D 1 read_extent_tree_block ---> return err // path[1].p_bh is still the old value ext4_free_ext_path ext4_ext_drop_refs // path->p_depth =3D=3D 1 brelse(path[1].p_bh) ---> brelse a buffer twice Finally got the following WARRNING when removing the buffer from lru: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D VFS: brelse: Trying to free free buffer WARNING: CPU: 2 PID: 72 at fs/buffer.c:1241 __brelse+0x58/0x90 CPU: 2 PID: 72 Comm: kworker/u19:1 Not tainted 6.9.0-dirty #716 RIP: 0010:__brelse+0x58/0x90 Call Trace: __find_get_block+0x6e7/0x810 bdev_getblk+0x2b/0x480 __ext4_get_inode_loc+0x48a/0x1240 ext4_get_inode_loc+0xb2/0x150 ext4_reserve_inode_write+0xb7/0x230 __ext4_mark_inode_dirty+0x144/0x6a0 ext4_ext_insert_extent+0x9c8/0x3230 ext4_ext_map_blocks+0xf45/0x2dc0 ext4_map_blocks+0x724/0x1700 ext4_do_writepages+0x12d6/0x2a70 [...] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Fixes: ecb94f5fdf4b ("ext4: collapse a single extent tree block into the in= ode if possible") Cc: stable@kernel.org Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 4d589d34b30e..657baf3991c1 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1888,6 +1888,7 @@ static void ext4_ext_try_to_merge_up(handle_t *handle, path[0].p_hdr->eh_max =3D cpu_to_le16(max_root); =20 brelse(path[1].p_bh); + path[1].p_bh =3D NULL; ext4_free_blocks(handle, inode, NULL, blk, 1, EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET); } --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0DE53F9EC; Wed, 10 Jul 2024 04:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584557; cv=none; b=tEi3TbwiDVA1unMJlRwax6QRQ7n0g8OiTN0B76cTGOrE6e8eACqU1VFS0JC+ix+C7Cnf4xDoHfVcvh4eoE74N9448adMEyMW/OlDtus93exgDykueVfBFywCl7xuccPlikg5mB5azXt0o7boW6dIPNlwdshmWHuuyEyhdebRshc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584557; c=relaxed/simple; bh=bpDgBwlCisGlUCSLJiZf56AS4PsdoeU+BCn9dasP3xU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WtSCKi5gAiWMXukrcES9fgEEnYNTE34Yu9P9znOOBv+LYm8kwfwMfSqjaTOvgDw2MLlTYpb8VPChPwVK3O/xmzOmdJLgZn4Martxz5SEM0vosbkoxH3fGaBRLxRX2Q5a25MHV/QXw4oou7mEyP6YTVzqx/S3RovuPbrs1zBx24U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrB4ktXz4f3kpB; Wed, 10 Jul 2024 12:08:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 4D8581A0181; Wed, 10 Jul 2024 12:09:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S8; Wed, 10 Jul 2024 12:09:06 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 04/20] ext4: add new ext4_ext_path_brelse() helper Date: Wed, 10 Jul 2024 12:06:38 +0800 Message-Id: <20240710040654.1714672-5-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S8 X-Coremail-Antispam: 1UD129KBjvJXoW7ArW3Cw45uFWkZr4fJw1xAFb_yoW5JrW8pF 4ayrn8CrWrtayagFZ7Xr4UZw1Sy3Z3Cw48JrWSkryvk3WUJr1FqFyxtF40vFy3tFW8WFya vFW8tw1Utr45taDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0 I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7VUbfcTJUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IIwABs9 Content-Type: text/plain; charset="utf-8" From: Baokun Li Add ext4_ext_path_brelse() helper function to reduce duplicate code and ensure that path->p_bh is set to NULL after it is released. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 657baf3991c1..6e5b5baf3aa6 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -106,6 +106,12 @@ static int ext4_ext_trunc_restart_fn(struct inode *ino= de, int *dropped) return 0; } =20 +static inline void ext4_ext_path_brelse(struct ext4_ext_path *path) +{ + brelse(path->p_bh); + path->p_bh =3D NULL; +} + static void ext4_ext_drop_refs(struct ext4_ext_path *path) { int depth, i; @@ -113,10 +119,8 @@ static void ext4_ext_drop_refs(struct ext4_ext_path *p= ath) if (!path) return; depth =3D path->p_depth; - for (i =3D 0; i <=3D depth; i++, path++) { - brelse(path->p_bh); - path->p_bh =3D NULL; - } + for (i =3D 0; i <=3D depth; i++, path++) + ext4_ext_path_brelse(path); } =20 void ext4_free_ext_path(struct ext4_ext_path *path) @@ -635,8 +639,7 @@ int ext4_ext_precache(struct inode *inode) */ if ((i =3D=3D depth) || path[i].p_idx > EXT_LAST_INDEX(path[i].p_hdr)) { - brelse(path[i].p_bh); - path[i].p_bh =3D NULL; + ext4_ext_path_brelse(path + i); i--; continue; } @@ -1887,8 +1890,7 @@ static void ext4_ext_try_to_merge_up(handle_t *handle, (path[1].p_ext - EXT_FIRST_EXTENT(path[1].p_hdr)); path[0].p_hdr->eh_max =3D cpu_to_le16(max_root); =20 - brelse(path[1].p_bh); - path[1].p_bh =3D NULL; + ext4_ext_path_brelse(path + 1); ext4_free_blocks(handle, inode, NULL, blk, 1, EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET); } @@ -2956,8 +2958,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_l= blk_t start, err =3D ext4_ext_rm_leaf(handle, inode, path, &partial, start, end); /* root level has p_bh =3D=3D NULL, brelse() eats this */ - brelse(path[i].p_bh); - path[i].p_bh =3D NULL; + ext4_ext_path_brelse(path + i); i--; continue; } @@ -3019,8 +3020,7 @@ int ext4_ext_remove_space(struct inode *inode, ext4_l= blk_t start, err =3D ext4_ext_rm_idx(handle, inode, path, i); } /* root level has p_bh =3D=3D NULL, brelse() eats this */ - brelse(path[i].p_bh); - path[i].p_bh =3D NULL; + ext4_ext_path_brelse(path + i); i--; ext_debug(inode, "return to level %d\n", i); } --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D435842076; Wed, 10 Jul 2024 04:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; cv=none; b=OXbSV+4774Hq5TxUOlOeoLSOYv7bEt2FR1E5gyPKBruubdPqBIl/nii1A5ReP0RYFRiWe5vZqaFrvchft9n45+WyvBtqrxyIKo+gLYq7eVZBbAis0OTkBf3IfSGUW7JNNdT1I+7WkiAWrpXgqHNOij/JQRCGQ6PKTDFBy+E4r/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; c=relaxed/simple; bh=mQYDFf6JBOTOGC4piSSnkGkF+HocS4v7qN1kwlgBW/c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=IEz0aF+KSCqZixZdcHPuyCYo5tQ8mWXSG8vQw11GJ+06BYX5SwDMd9fW2mbjwMdxyNJ5UVA4KZhcQMEDCE61bP567IYLAAzZRWBIsQ20f3hJY2ZYe9uxjcn++KoFvvjPGbgqnoSpM8yU17epnmBAPHm02taeSVhj77NInsCvwkQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkr56QsXz4f3mHb; Wed, 10 Jul 2024 12:08:53 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id B7B111A016E; Wed, 10 Jul 2024 12:09:06 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S9; Wed, 10 Jul 2024 12:09:06 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li , stable@kernel.org Subject: [PATCH 05/20] ext4: fix slab-use-after-free in ext4_split_extent_at() Date: Wed, 10 Jul 2024 12:06:39 +0800 Message-Id: <20240710040654.1714672-6-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S9 X-Coremail-Antispam: 1UD129KBjvJXoWxZFyftr13Zr47Ary3Gw48WFg_yoWrXF43pr ykCryfGrn8t3srWrZrJ3WDZr1Ika1UGr4UJrWfGw12gFyUJ348WFyvyF15tF98KrW8Za45 Zr48tryUGa4qkFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7VUbfcTJUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHmAABs3 Content-Type: text/plain; charset="utf-8" From: Baokun Li We hit the following use-after-free: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D BUG: KASAN: slab-use-after-free in ext4_split_extent_at+0xba8/0xcc0 Read of size 2 at addr ffff88810548ed08 by task kworker/u20:0/40 CPU: 0 PID: 40 Comm: kworker/u20:0 Not tainted 6.9.0-dirty #724 Call Trace: kasan_report+0x93/0xc0 ext4_split_extent_at+0xba8/0xcc0 ext4_split_extent.isra.0+0x18f/0x500 ext4_split_convert_extents+0x275/0x750 ext4_ext_handle_unwritten_extents+0x73e/0x1580 ext4_ext_map_blocks+0xe20/0x2dc0 ext4_map_blocks+0x724/0x1700 ext4_do_writepages+0x12d6/0x2a70 [...] Allocated by task 40: __kmalloc_noprof+0x1ac/0x480 ext4_find_extent+0xf3b/0x1e70 ext4_ext_map_blocks+0x188/0x2dc0 ext4_map_blocks+0x724/0x1700 ext4_do_writepages+0x12d6/0x2a70 [...] Freed by task 40: kfree+0xf1/0x2b0 ext4_find_extent+0xa71/0x1e70 ext4_ext_insert_extent+0xa22/0x3260 ext4_split_extent_at+0x3ef/0xcc0 ext4_split_extent.isra.0+0x18f/0x500 ext4_split_convert_extents+0x275/0x750 ext4_ext_handle_unwritten_extents+0x73e/0x1580 ext4_ext_map_blocks+0xe20/0x2dc0 ext4_map_blocks+0x724/0x1700 ext4_do_writepages+0x12d6/0x2a70 [...] =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The flow of issue triggering is as follows: ext4_split_extent_at path =3D *ppath ext4_ext_insert_extent(ppath) ext4_ext_create_new_leaf(ppath) ext4_find_extent(orig_path) path =3D *orig_path read_extent_tree_block // return -ENOMEM or -EIO ext4_free_ext_path(path) kfree(path) *orig_path =3D NULL a. If err is -ENOMEM: ext4_ext_dirty(path + path->p_depth) // path use-after-free !!! b. If err is -EIO and we have EXT_DEBUG defined: ext4_ext_show_leaf(path) eh =3D path[depth].p_hdr // path also use-after-free !!! So when trying to zeroout or fix the extent length, call ext4_find_extent() to update the path. In addition we use *ppath directly as an ext4_ext_show_leaf() input to avoid possible use-after-free when EXT_DEBUG is defined, and to avoid unnecessary path updates. Fixes: dfe5080939ea ("ext4: drop EXT4_EX_NOFREE_ON_ERR from rest of extents= handling code") Cc: stable@kernel.org Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 6e5b5baf3aa6..3a70a0739af8 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3252,6 +3252,25 @@ static int ext4_split_extent_at(handle_t *handle, if (err !=3D -ENOSPC && err !=3D -EDQUOT && err !=3D -ENOMEM) goto out; =20 + /* + * Update path is required because previous ext4_ext_insert_extent() + * may have freed or reallocated the path. Using EXT4_EX_NOFAIL + * guarantees that ext4_find_extent() will not return -ENOMEM, + * otherwise -ENOMEM will cause a retry in do_writepages(), and a + * WARN_ON may be triggered in ext4_da_update_reserve_space() due to + * an incorrect ee_len causing the i_reserved_data_blocks exception. + */ + path =3D ext4_find_extent(inode, ee_block, ppath, + flags | EXT4_EX_NOFAIL); + if (IS_ERR(path)) { + EXT4_ERROR_INODE(inode, "Failed split extent on %u, err %ld", + split, PTR_ERR(path)); + return PTR_ERR(path); + } + depth =3D ext_depth(inode); + ex =3D path[depth].p_ext; + *ppath =3D path; + if (EXT4_EXT_MAY_ZEROOUT & split_flag) { if (split_flag & (EXT4_EXT_DATA_VALID1|EXT4_EXT_DATA_VALID2)) { if (split_flag & EXT4_EXT_DATA_VALID1) { @@ -3304,7 +3323,7 @@ static int ext4_split_extent_at(handle_t *handle, ext4_ext_dirty(handle, inode, path + path->p_depth); return err; out: - ext4_ext_show_leaf(inode, path); + ext4_ext_show_leaf(inode, *ppath); return err; } =20 --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1E5841C92; Wed, 10 Jul 2024 04:09:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; cv=none; b=b0ir2KP1OO+HNlQ/nWBo1Y+G8M5XAja5/CP4lyw0Y6pX+NVJJMV8tJgdVXb1Uc0SXCokMgGzoi8ulahB7RBe9P5IKJ/BfifZqKNjuzQ7YaUoZmRgMKZ0IZTdHHEL2E42d0s5z1KxXG03JmbwtPUFfkHwXthpJCu6kXlF0y+Eq0U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; c=relaxed/simple; bh=7OuiPW9+jHiQ71uVr5UCY09AfFNkHTbSqOYdMWKBSKI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qwcVpNXSMEDewwBfpqeBMkTNk63ieIcspRJUEDQShCoC7/2geYEi7GrLCT3cp7OYlka3i0oe4KYELlo49xCzvkLhTn9JweKOXXEHBdEmMR1cC9KkZDEqd4NGExLtUtcpJTuNQ8DTwiY3YJn4JwABMxbq1EB5rjx7XEcPbVj1I+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkr73rD6z4f3mJY; Wed, 10 Jul 2024 12:08:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 278801A0199; Wed, 10 Jul 2024 12:09:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S10; Wed, 10 Jul 2024 12:09:06 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 06/20] ext4: avoid use-after-free in ext4_ext_show_leaf() Date: Wed, 10 Jul 2024 12:06:40 +0800 Message-Id: <20240710040654.1714672-7-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S10 X-Coremail-Antispam: 1UD129KBjvJXoWxWF4xAr48XryDJr4UGrykKrg_yoW5GFy7pw nxur1DKr45JanFgFWDXa1kAr12ka1UGr47GrW7Krya9FW5Ja4FgFyxt3WFvFWrXFW8Xasx trW8ta4UGa43CaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7VUbfcTJUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IJAABs6 Content-Type: text/plain; charset="utf-8" From: Baokun Li In ext4_find_extent(), path may be freed by error or be reallocated, so using a previously saved *ppath may have been freed and thus may trigger use-after-free, as follows: ext4_split_extent path =3D *ppath; ext4_split_extent_at(ppath) path =3D ext4_find_extent(ppath) ext4_split_extent_at(ppath) // ext4_find_extent fails to free path // but zeroout succeeds ext4_ext_show_leaf(inode, path) eh =3D path[depth].p_hdr // path use-after-free !!! Similar to ext4_split_extent_at(), we use *ppath directly as an input to ext4_ext_show_leaf(). Fix a spelling error by the way. Same problem in ext4_ext_handle_unwritten_extents(). Since 'path' is only used in ext4_ext_show_leaf(), remove 'path' and use *ppath directly. This issue is triggered only when EXT_DEBUG is defined and therefore does not affect functionality. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 3a70a0739af8..1660434fbfc7 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3328,7 +3328,7 @@ static int ext4_split_extent_at(handle_t *handle, } =20 /* - * ext4_split_extents() splits an extent and mark extent which is covered + * ext4_split_extent() splits an extent and mark extent which is covered * by @map as split_flags indicates * * It may result in splitting the extent into multiple extents (up to thre= e) @@ -3404,7 +3404,7 @@ static int ext4_split_extent(handle_t *handle, goto out; } =20 - ext4_ext_show_leaf(inode, path); + ext4_ext_show_leaf(inode, *ppath); out: return err ? err : allocated; } @@ -3869,14 +3869,13 @@ ext4_ext_handle_unwritten_extents(handle_t *handle,= struct inode *inode, struct ext4_ext_path **ppath, int flags, unsigned int allocated, ext4_fsblk_t newblock) { - struct ext4_ext_path __maybe_unused *path =3D *ppath; int ret =3D 0; int err =3D 0; =20 ext_debug(inode, "logical block %llu, max_blocks %u, flags 0x%x, allocate= d %u\n", (unsigned long long)map->m_lblk, map->m_len, flags, allocated); - ext4_ext_show_leaf(inode, path); + ext4_ext_show_leaf(inode, *ppath); =20 /* * When writing into unwritten space, we should not fail to @@ -3973,7 +3972,7 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, s= truct inode *inode, if (allocated > map->m_len) allocated =3D map->m_len; map->m_len =3D allocated; - ext4_ext_show_leaf(inode, path); + ext4_ext_show_leaf(inode, *ppath); out2: return err ? err : allocated; } --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9B6A84AEF4; Wed, 10 Jul 2024 04:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; cv=none; b=PTSEENlpIqigMCbuZX75FD0vqJjCjv9ZxVpuIBX714SJ5H41bltLqpBrzIuAIqPj7OhO85TQvieeLKg4XQwZoIGWnjc01p3C56YutKk9WTQj41DbpyQ4/KumrwbVkTt5OMGgS0rlcTgne32z0QntzaelIS81zf3GNQZV7n7tA/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584558; c=relaxed/simple; bh=kfC6F5VKWvb7rFGpDlMAVkw2sN3aGZ381I6aoHA/4eE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iXvbc4b5TeBJF/28cGUW2CnbJ9r9hn9cRSaWPOcnLqdV4oQB67mp6Pqp6ElNZlhV3R9qRCVre3LW80bC9ScQ+Fw9Ke426Lg3rIhqHjzUAoXvEcByroMmdBP2Nd9X1f5x1J1qTJhgbD32NVZTOCMVdYzP93n0QbA2zoDriI4QATM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkr775c0z4f3mJc; Wed, 10 Jul 2024 12:08:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 96EDD1A016E; Wed, 10 Jul 2024 12:09:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S11; Wed, 10 Jul 2024 12:09:07 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li , stable@kernel.org Subject: [PATCH 07/20] ext4: drop ppath from ext4_ext_replay_update_ex() to avoid double-free Date: Wed, 10 Jul 2024 12:06:41 +0800 Message-Id: <20240710040654.1714672-8-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S11 X-Coremail-Antispam: 1UD129KBjvJXoWxGry3Jr1UuFW7uFW3Kry3urg_yoW5AryUpF nrCF1Fgr15Xw1kWrZ7Xa17ZF1Ska1UGr4UGrZ3Cayj9FyUXw109FyIyF1ftFy5XrW8GFya yrW8tr15Ww17K37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7VUbfcTJUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHmQAAs3 Content-Type: text/plain; charset="utf-8" From: Baokun Li When calling ext4_force_split_extent_at() in ext4_ext_replay_update_ex(), the 'ppath' is updated but it is the 'path' that is freed, thus potentially triggering a double-free in the following process: ext4_ext_replay_update_ex ppath =3D path ext4_force_split_extent_at(&ppath) ext4_split_extent_at ext4_ext_insert_extent ext4_ext_create_new_leaf ext4_ext_grow_indepth ext4_find_extent if (depth > path[0].p_maxdepth) kfree(path) ---> path First freed *orig_path =3D path =3D NULL ---> null ppath kfree(path) ---> path double-free !!! So drop the unnecessary ppath and use path directly to avoid this problem. And use ext4_find_extent() directly to update path, avoiding unnecessary memory allocation and freeing. Also, propagate the error returned by ext4_find_extent() instead of using strange error codes. Fixes: 8016e29f4362 ("ext4: fast commit recovery path") Cc: stable@kernel.org Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 1660434fbfc7..b1cfce5b57d2 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -5920,7 +5920,7 @@ int ext4_clu_mapped(struct inode *inode, ext4_lblk_t = lclu) int ext4_ext_replay_update_ex(struct inode *inode, ext4_lblk_t start, int len, int unwritten, ext4_fsblk_t pblk) { - struct ext4_ext_path *path =3D NULL, *ppath; + struct ext4_ext_path *path; struct ext4_extent *ex; int ret; =20 @@ -5936,30 +5936,29 @@ int ext4_ext_replay_update_ex(struct inode *inode, = ext4_lblk_t start, if (le32_to_cpu(ex->ee_block) !=3D start || ext4_ext_get_actual_len(ex) !=3D len) { /* We need to split this extent to match our extent first */ - ppath =3D path; down_write(&EXT4_I(inode)->i_data_sem); - ret =3D ext4_force_split_extent_at(NULL, inode, &ppath, start, 1); + ret =3D ext4_force_split_extent_at(NULL, inode, &path, start, 1); up_write(&EXT4_I(inode)->i_data_sem); if (ret) goto out; - kfree(path); - path =3D ext4_find_extent(inode, start, NULL, 0); + + path =3D ext4_find_extent(inode, start, &path, 0); if (IS_ERR(path)) - return -1; - ppath =3D path; + return PTR_ERR(path); ex =3D path[path->p_depth].p_ext; WARN_ON(le32_to_cpu(ex->ee_block) !=3D start); + if (ext4_ext_get_actual_len(ex) !=3D len) { down_write(&EXT4_I(inode)->i_data_sem); - ret =3D ext4_force_split_extent_at(NULL, inode, &ppath, + ret =3D ext4_force_split_extent_at(NULL, inode, &path, start + len, 1); up_write(&EXT4_I(inode)->i_data_sem); if (ret) goto out; - kfree(path); - path =3D ext4_find_extent(inode, start, NULL, 0); + + path =3D ext4_find_extent(inode, start, &path, 0); if (IS_ERR(path)) - return -EINVAL; + return PTR_ERR(path); ex =3D path[path->p_depth].p_ext; } } --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C8EC4BAA6; Wed, 10 Jul 2024 04:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584559; cv=none; b=a9bEmPp7aKAyIiUjLybn9XwyP0RXBMTf8g/W6cYctxlANPs4bsKskepKQ4EJTq2JtcLoPnvxCaCgPECWb+kvxbOxV25DjkGj3/d9qkjwkbBDvqa62nySm27SxdcKQtKkrbs4XGyeZlkhyF/pI724gGkl8dbDwG5W3WWKeFyaOuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584559; c=relaxed/simple; bh=Dj83D9OXUefnDnSK1/Jq3bZj56hYipewJ2TdXZISs5M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=KDxzdFm14BUhhVMLS2A9yx9hCDpodTzYPzdgJVNL/XNGJbYxl4q93vxTnJ2KH2/8qi945NelbkHWurbirhN9ZkI/00/i+dfhdMeTJZ16JtXq5ksZb5I4bFH1qnbyPt8hQhT2ryckE5Vwai6cV42ATVcT5JyN4KxGKqobo4ZquOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkr82hR5z4f3mJg; Wed, 10 Jul 2024 12:08:56 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 006CE1A0D00; Wed, 10 Jul 2024 12:09:07 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S12; Wed, 10 Jul 2024 12:09:07 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 08/20] ext4: get rid of ppath in ext4_find_extent() Date: Wed, 10 Jul 2024 12:06:42 +0800 Message-Id: <20240710040654.1714672-9-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S12 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar4rGw1DGFy5Kr18Kr1Utrb_yoWxKrWDpr 4qyF1Fgw15XwsF9rZ7Wa17Zr13K3WUJr4UGFWfG3409Fyjqr1FgFyIy3WYyFWYgFW8Wa4a yr40yr1UGa47KrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmj14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26F4j6r4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcV C2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2Kfnx nUUI43ZEXa7VUbfcTJUUUUU== X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHmgABs1 Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. Getting rid of ppath in ext4_find_extent() requires its caller to update ppath. These ppaths will also be dropped later. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 2 +- fs/ext4/extents.c | 52 +++++++++++++++++++++++-------------------- fs/ext4/move_extent.c | 6 ++--- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 8007abd4972d..cbe8d6062c52 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3714,7 +3714,7 @@ extern int ext4_ext_insert_extent(handle_t *, struct = inode *, struct ext4_ext_path **, struct ext4_extent *, int); extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t, - struct ext4_ext_path **, + struct ext4_ext_path *, int flags); extern void ext4_free_ext_path(struct ext4_ext_path *); extern int ext4_ext_check_inode(struct inode *inode); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index b1cfce5b57d2..5217e6f53467 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -884,11 +884,10 @@ void ext4_ext_tree_init(handle_t *handle, struct inod= e *inode) =20 struct ext4_ext_path * ext4_find_extent(struct inode *inode, ext4_lblk_t block, - struct ext4_ext_path **orig_path, int flags) + struct ext4_ext_path *path, int flags) { struct ext4_extent_header *eh; struct buffer_head *bh; - struct ext4_ext_path *path =3D orig_path ? *orig_path : NULL; short int depth, i, ppos =3D 0; int ret; gfp_t gfp_flags =3D GFP_NOFS; @@ -909,7 +908,7 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block, ext4_ext_drop_refs(path); if (depth > path[0].p_maxdepth) { kfree(path); - *orig_path =3D path =3D NULL; + path =3D NULL; } } if (!path) { @@ -964,8 +963,6 @@ ext4_find_extent(struct inode *inode, ext4_lblk_t block, =20 err: ext4_free_ext_path(path); - if (orig_path) - *orig_path =3D NULL; return ERR_PTR(ret); } =20 @@ -1430,7 +1427,7 @@ static int ext4_ext_create_new_leaf(handle_t *handle,= struct inode *inode, /* refill path */ path =3D ext4_find_extent(inode, (ext4_lblk_t)le32_to_cpu(newext->ee_block), - ppath, gb_flags); + path, gb_flags); if (IS_ERR(path)) err =3D PTR_ERR(path); } else { @@ -1442,7 +1439,7 @@ static int ext4_ext_create_new_leaf(handle_t *handle,= struct inode *inode, /* refill path */ path =3D ext4_find_extent(inode, (ext4_lblk_t)le32_to_cpu(newext->ee_block), - ppath, gb_flags); + path, gb_flags); if (IS_ERR(path)) { err =3D PTR_ERR(path); goto out; @@ -1458,8 +1455,8 @@ static int ext4_ext_create_new_leaf(handle_t *handle,= struct inode *inode, goto repeat; } } - out: + *ppath =3D IS_ERR(path) ? NULL : path; return err; } =20 @@ -3260,11 +3257,12 @@ static int ext4_split_extent_at(handle_t *handle, * WARN_ON may be triggered in ext4_da_update_reserve_space() due to * an incorrect ee_len causing the i_reserved_data_blocks exception. */ - path =3D ext4_find_extent(inode, ee_block, ppath, + path =3D ext4_find_extent(inode, ee_block, *ppath, flags | EXT4_EX_NOFAIL); if (IS_ERR(path)) { EXT4_ERROR_INODE(inode, "Failed split extent on %u, err %ld", split, PTR_ERR(path)); + *ppath =3D NULL; return PTR_ERR(path); } depth =3D ext_depth(inode); @@ -3379,9 +3377,12 @@ static int ext4_split_extent(handle_t *handle, * Update path is required because previous ext4_split_extent_at() may * result in split of original leaf or extent zeroout. */ - path =3D ext4_find_extent(inode, map->m_lblk, ppath, flags); - if (IS_ERR(path)) + path =3D ext4_find_extent(inode, map->m_lblk, *ppath, flags); + if (IS_ERR(path)) { + *ppath =3D NULL; return PTR_ERR(path); + } + *ppath =3D path; depth =3D ext_depth(inode); ex =3D path[depth].p_ext; if (!ex) { @@ -3767,9 +3768,12 @@ static int ext4_convert_unwritten_extents_endio(hand= le_t *handle, EXT4_GET_BLOCKS_CONVERT); if (err < 0) return err; - path =3D ext4_find_extent(inode, map->m_lblk, ppath, 0); - if (IS_ERR(path)) + path =3D ext4_find_extent(inode, map->m_lblk, *ppath, 0); + if (IS_ERR(path)) { + *ppath =3D NULL; return PTR_ERR(path); + } + *ppath =3D path; depth =3D ext_depth(inode); ex =3D path[depth].p_ext; } @@ -3825,9 +3829,12 @@ convert_initialized_extent(handle_t *handle, struct = inode *inode, EXT4_GET_BLOCKS_CONVERT_UNWRITTEN); if (err < 0) return err; - path =3D ext4_find_extent(inode, map->m_lblk, ppath, 0); - if (IS_ERR(path)) + path =3D ext4_find_extent(inode, map->m_lblk, *ppath, 0); + if (IS_ERR(path)) { + *ppath =3D NULL; return PTR_ERR(path); + } + *ppath =3D path; depth =3D ext_depth(inode); ex =3D path[depth].p_ext; if (!ex) { @@ -5224,7 +5231,7 @@ ext4_ext_shift_extents(struct inode *inode, handle_t = *handle, * won't be shifted beyond EXT_MAX_BLOCKS. */ if (SHIFT =3D=3D SHIFT_LEFT) { - path =3D ext4_find_extent(inode, start - 1, &path, + path =3D ext4_find_extent(inode, start - 1, path, EXT4_EX_NOCACHE); if (IS_ERR(path)) return PTR_ERR(path); @@ -5273,7 +5280,7 @@ ext4_ext_shift_extents(struct inode *inode, handle_t = *handle, * becomes NULL to indicate the end of the loop. */ while (iterator && start <=3D stop) { - path =3D ext4_find_extent(inode, *iterator, &path, + path =3D ext4_find_extent(inode, *iterator, path, EXT4_EX_NOCACHE); if (IS_ERR(path)) return PTR_ERR(path); @@ -5854,11 +5861,8 @@ int ext4_clu_mapped(struct inode *inode, ext4_lblk_t= lclu) =20 /* search for the extent closest to the first block in the cluster */ path =3D ext4_find_extent(inode, EXT4_C2B(sbi, lclu), NULL, 0); - if (IS_ERR(path)) { - err =3D PTR_ERR(path); - path =3D NULL; - goto out; - } + if (IS_ERR(path)) + return PTR_ERR(path); =20 depth =3D ext_depth(inode); =20 @@ -5942,7 +5946,7 @@ int ext4_ext_replay_update_ex(struct inode *inode, ex= t4_lblk_t start, if (ret) goto out; =20 - path =3D ext4_find_extent(inode, start, &path, 0); + path =3D ext4_find_extent(inode, start, path, 0); if (IS_ERR(path)) return PTR_ERR(path); ex =3D path[path->p_depth].p_ext; @@ -5956,7 +5960,7 @@ int ext4_ext_replay_update_ex(struct inode *inode, ex= t4_lblk_t start, if (ret) goto out; =20 - path =3D ext4_find_extent(inode, start, &path, 0); + path =3D ext4_find_extent(inode, start, path, 0); if (IS_ERR(path)) return PTR_ERR(path); ex =3D path[path->p_depth].p_ext; diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index 204f53b23622..b0ab19a913bf 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -26,14 +26,14 @@ static inline int get_ext_path(struct inode *inode, ext4_lblk_t lblock, struct ext4_ext_path **ppath) { - struct ext4_ext_path *path; + struct ext4_ext_path *path =3D *ppath; =20 - path =3D ext4_find_extent(inode, lblock, ppath, EXT4_EX_NOCACHE); + *ppath =3D NULL; + path =3D ext4_find_extent(inode, lblock, path, EXT4_EX_NOCACHE); if (IS_ERR(path)) return PTR_ERR(path); if (path[ext_depth(inode)].p_ext =3D=3D NULL) { ext4_free_ext_path(path); - *ppath =3D NULL; return -ENODATA; } *ppath =3D path; --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE1644F8BB; Wed, 10 Jul 2024 04:09:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584559; cv=none; b=TBsnFiuBFFJSM53xx4mjCyFEvRgl3s9i5mnD8mxfonbg6VVB5BNdt3pu4+O9hW41mup1g8nfA2y26D0n2pl9T972WvK3QA2cQ1Jd2vaFvoDxkzVo1WeWWPa85RiFy152bWMenjMAYiITuDItKYJLl/hjKP6ya+YIQpPYXw0s7f0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584559; c=relaxed/simple; bh=ImlY1QsnFPM1kaHQzMg8KnrlyADTGAiVLYEmnGSnjIc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=bjumKhJ4nnmBrWSd5GL8EdjmKJSnXJnfsLpKmYphrKkJEUUrv6Y67W/AnX5quhf4jnIzlLsCtkDyyrREdrlBSZF6B/zQh8iHdqj41qlmjiPCPF0Yn1cUa0Iu8ZdMBQFygl4Fxpm0pzLRtFs60moeuNCKuWStV6ioTrY/7NQ4JUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkr73tZFz4f3m7J; Wed, 10 Jul 2024 12:08:55 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 62FEB1A0D00; Wed, 10 Jul 2024 12:09:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S13; Wed, 10 Jul 2024 12:09:08 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 09/20] ext4: get rid of ppath in get_ext_path() Date: Wed, 10 Jul 2024 12:06:43 +0800 Message-Id: <20240710040654.1714672-10-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S13 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4kJrW7Kr48uw47XryfXrb_yoW5Kr4rpF sayr1Ygr48XanFkrZ7Ka1UZr15Ka1rG3y7WryfGw109ay7Xr1F9F1Iy3WYvFyrKFW8WrWa vFWrtr1UC34UKFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IJQAAs6 Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. After getting rid of ppath in get_ext_path(), its caller may pass an error pointer to ext4_free_ext_path(), so it needs to teach ext4_free_ext_path() and ext4_ext_drop_refs() to skip the error pointer. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 5 +++-- fs/ext4/move_extent.c | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 5217e6f53467..6dfb5d03e197 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -116,7 +116,7 @@ static void ext4_ext_drop_refs(struct ext4_ext_path *pa= th) { int depth, i; =20 - if (!path) + if (IS_ERR_OR_NULL(path)) return; depth =3D path->p_depth; for (i =3D 0; i <=3D depth; i++, path++) @@ -125,6 +125,8 @@ static void ext4_ext_drop_refs(struct ext4_ext_path *pa= th) =20 void ext4_free_ext_path(struct ext4_ext_path *path) { + if (IS_ERR_OR_NULL(path)) + return; ext4_ext_drop_refs(path); kfree(path); } @@ -4191,7 +4193,6 @@ int ext4_ext_map_blocks(handle_t *handle, struct inod= e *inode, path =3D ext4_find_extent(inode, map->m_lblk, NULL, 0); if (IS_ERR(path)) { err =3D PTR_ERR(path); - path =3D NULL; goto out; } =20 diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c index b0ab19a913bf..a7186d63725a 100644 --- a/fs/ext4/move_extent.c +++ b/fs/ext4/move_extent.c @@ -17,27 +17,23 @@ * get_ext_path() - Find an extent path for designated logical block numbe= r. * @inode: inode to be searched * @lblock: logical block number to find an extent path - * @ppath: pointer to an extent path pointer (for output) + * @path: pointer to an extent path * - * ext4_find_extent wrapper. Return 0 on success, or a negative error value - * on failure. + * ext4_find_extent wrapper. Return an extent path pointer on success, + * or an error pointer on failure. */ -static inline int +static inline struct ext4_ext_path * get_ext_path(struct inode *inode, ext4_lblk_t lblock, - struct ext4_ext_path **ppath) + struct ext4_ext_path *path) { - struct ext4_ext_path *path =3D *ppath; - - *ppath =3D NULL; path =3D ext4_find_extent(inode, lblock, path, EXT4_EX_NOCACHE); if (IS_ERR(path)) - return PTR_ERR(path); + return path; if (path[ext_depth(inode)].p_ext =3D=3D NULL) { ext4_free_ext_path(path); - return -ENODATA; + return ERR_PTR(-ENODATA); } - *ppath =3D path; - return 0; + return path; } =20 /** @@ -95,9 +91,11 @@ mext_check_coverage(struct inode *inode, ext4_lblk_t fro= m, ext4_lblk_t count, int ret =3D 0; ext4_lblk_t last =3D from + count; while (from < last) { - *err =3D get_ext_path(inode, from, &path); - if (*err) - goto out; + path =3D get_ext_path(inode, from, path); + if (IS_ERR(path)) { + *err =3D PTR_ERR(path); + return ret; + } ext =3D path[ext_depth(inode)].p_ext; if (unwritten !=3D ext4_ext_is_unwritten(ext)) goto out; @@ -624,9 +622,11 @@ ext4_move_extents(struct file *o_filp, struct file *d_= filp, __u64 orig_blk, int offset_in_page; int unwritten, cur_len; =20 - ret =3D get_ext_path(orig_inode, o_start, &path); - if (ret) + path =3D get_ext_path(orig_inode, o_start, path); + if (IS_ERR(path)) { + ret =3D PTR_ERR(path); goto out; + } ex =3D path[path->p_depth].p_ext; cur_blk =3D le32_to_cpu(ex->ee_block); cur_len =3D ext4_ext_get_actual_len(ex); --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EEA157CB6; Wed, 10 Jul 2024 04:09:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584559; cv=none; b=QhH45wxb7W14cgFcuzk/4njJtooN98hkdUsq/mcwFZhHOVi3RevS6OFd/0thW6uyW7328nvU4zMOLmZ61zm7xsqE57EhP0pRntnugWVzYSTpJLUa+SFA5EutwzvEkfOP2EHA/XT8121bUOlc8souIQpt22b9lObDKn31cG1u8F8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584559; c=relaxed/simple; bh=uOG/Vr3MCFNJjRWImReFrc5J4cRS5yRX7UqDM2T4jLY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=F3biqC0zzsqZVX2ZLXlqjgqvs3bYSR8lspaXO2m/kONaouRVcWoulh9RvaH4hvB8EgD+pSSLnSfsHZ9KaJDf+XF/wiGawD/UIQP8v5N5KY2h6WmFTumsX7SrgkHb7Pq+mq+ijOHns6/4jP4Np39InL5DfExYIsrlX0STm2ayeJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkr91NFrz4f3mJM; Wed, 10 Jul 2024 12:08:57 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id C79571A0184; Wed, 10 Jul 2024 12:09:08 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S14; Wed, 10 Jul 2024 12:09:08 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 10/20] ext4: get rid of ppath in ext4_ext_create_new_leaf() Date: Wed, 10 Jul 2024 12:06:44 +0800 Message-Id: <20240710040654.1714672-11-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S14 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4DAr4rCF1DuFyDAr4ktFb_yoW5CF1fpr 4FyFy8KF45WasF9rZ2va1UZr1ak3W8Gw4UAFWfCr9Y9Fy7ZF1FqFyfta4FyFW5JFW8ua4a qFW8tw1UXw12g3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IJgAAs5 Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_ext_create_new_leaf(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 6dfb5d03e197..0d6ce9e74b01 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1397,13 +1397,12 @@ static int ext4_ext_grow_indepth(handle_t *handle, = struct inode *inode, * finds empty index and adds new leaf. * if no free index is found, then it requests in-depth growing. */ -static int ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode, - unsigned int mb_flags, - unsigned int gb_flags, - struct ext4_ext_path **ppath, - struct ext4_extent *newext) +static struct ext4_ext_path * +ext4_ext_create_new_leaf(handle_t *handle, struct inode *inode, + unsigned int mb_flags, unsigned int gb_flags, + struct ext4_ext_path *path, + struct ext4_extent *newext) { - struct ext4_ext_path *path =3D *ppath; struct ext4_ext_path *curp; int depth, i, err =3D 0; =20 @@ -1424,28 +1423,24 @@ static int ext4_ext_create_new_leaf(handle_t *handl= e, struct inode *inode, * entry: create all needed subtree and add new leaf */ err =3D ext4_ext_split(handle, inode, mb_flags, path, newext, i); if (err) - goto out; + goto errout; =20 /* refill path */ path =3D ext4_find_extent(inode, (ext4_lblk_t)le32_to_cpu(newext->ee_block), path, gb_flags); - if (IS_ERR(path)) - err =3D PTR_ERR(path); } else { /* tree is full, time to grow in depth */ err =3D ext4_ext_grow_indepth(handle, inode, mb_flags); if (err) - goto out; + goto errout; =20 /* refill path */ path =3D ext4_find_extent(inode, (ext4_lblk_t)le32_to_cpu(newext->ee_block), path, gb_flags); - if (IS_ERR(path)) { - err =3D PTR_ERR(path); - goto out; - } + if (IS_ERR(path)) + return path; =20 /* * only first (depth 0 -> 1) produces free space; @@ -1457,9 +1452,11 @@ static int ext4_ext_create_new_leaf(handle_t *handle= , struct inode *inode, goto repeat; } } -out: - *ppath =3D IS_ERR(path) ? NULL : path; - return err; + return path; + +errout: + ext4_free_ext_path(path); + return ERR_PTR(err); } =20 /* @@ -2112,10 +2109,14 @@ int ext4_ext_insert_extent(handle_t *handle, struct= inode *inode, */ if (gb_flags & EXT4_GET_BLOCKS_METADATA_NOFAIL) mb_flags |=3D EXT4_MB_USE_RESERVED; - err =3D ext4_ext_create_new_leaf(handle, inode, mb_flags, gb_flags, - ppath, newext); - if (err) + path =3D ext4_ext_create_new_leaf(handle, inode, mb_flags, gb_flags, + path, newext); + if (IS_ERR(path)) { + *ppath =3D NULL; + err =3D PTR_ERR(path); goto cleanup; + } + *ppath =3D path; depth =3D ext_depth(inode); eh =3D path[depth].p_hdr; =20 --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BDE25BAF0; Wed, 10 Jul 2024 04:09:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584560; cv=none; b=h7jTJTwLcmiU1TlF/5729j0GUUiKmGqsyvHxkUGMmnkYjf8qy14K06tI8VvfQUep5ninGZg4sJm4+ybzNgMU5kl3bHer0Rh5pGPBAh8x6SJHmEGXIE2eSv3UAOD+jTOVggmx8OTMEv2H7DTOz7OxI1zfP3A6CHn6GB+2gHfzhYg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584560; c=relaxed/simple; bh=lTT4gpcxKhfKcPamxYQl7cDONxRudh3LR6kF5uPuq48=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r7CvCgy/74gLO1d0Y6TFPNARIJLcJcnrm4t5amxSm2QnLq2Ag9zb7s69OsUz9XJFgdpjoCT6CpVMwXA4MpV8PI71vc18h8tUR+i2YxTtWZYm2xDuN9URMChiemcYotVVSHos1Ktrykjeplud5xRV54ghLx23pDV3VXX83SABEZE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrF4Bxdz4f3kpB; Wed, 10 Jul 2024 12:09:01 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 38E9C1A0D10; Wed, 10 Jul 2024 12:09:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S15; Wed, 10 Jul 2024 12:09:09 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 11/20] ext4: get rid of ppath in ext4_ext_insert_extent() Date: Wed, 10 Jul 2024 12:06:45 +0800 Message-Id: <20240710040654.1714672-12-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S15 X-Coremail-Antispam: 1UD129KBjvJXoW3tr48Ww4UZrWktw45urWDCFg_yoWDAFW7pF ZakF1kCr1YqanruFZ7Xa1UZr1a9a15G3yUGrWfG34FkFy2qF1FgFyft3WYvFW5WFW8Wa4a vFWrt34UGa47KaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IJwAAs4 Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_ext_insert_extent(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. * Free path when npath is used, free npath when it is not used. * The got_allocated_blocks label in ext4_ext_map_blocks() does not update err now, so err is updated to 0 if the err returned by ext4_ext_search_right() is greater than 0 and is about to enter got_allocated_blocks. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/ext4.h | 7 ++-- fs/ext4/extents.c | 88 ++++++++++++++++++++++++------------------- fs/ext4/fast_commit.c | 8 ++-- fs/ext4/migrate.c | 5 ++- 4 files changed, 61 insertions(+), 47 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index cbe8d6062c52..53b4c1f454e6 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3710,9 +3710,10 @@ extern int ext4_map_blocks(handle_t *handle, struct = inode *inode, extern int ext4_ext_calc_credits_for_single_extent(struct inode *inode, int num, struct ext4_ext_path *path); -extern int ext4_ext_insert_extent(handle_t *, struct inode *, - struct ext4_ext_path **, - struct ext4_extent *, int); +extern struct ext4_ext_path *ext4_ext_insert_extent( + handle_t *handle, struct inode *inode, + struct ext4_ext_path *path, + struct ext4_extent *newext, int gb_flags); extern struct ext4_ext_path *ext4_find_extent(struct inode *, ext4_lblk_t, struct ext4_ext_path *, int flags); diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 0d6ce9e74b01..fc75390d591a 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -1974,16 +1974,15 @@ static unsigned int ext4_ext_check_overlap(struct e= xt4_sb_info *sbi, * inserts requested extent as new one into the tree, * creating new leaf in the no-space case. */ -int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, - struct ext4_ext_path **ppath, - struct ext4_extent *newext, int gb_flags) +struct ext4_ext_path * +ext4_ext_insert_extent(handle_t *handle, struct inode *inode, + struct ext4_ext_path *path, + struct ext4_extent *newext, int gb_flags) { - struct ext4_ext_path *path =3D *ppath; struct ext4_extent_header *eh; struct ext4_extent *ex, *fex; struct ext4_extent *nearex; /* nearest extent */ - struct ext4_ext_path *npath =3D NULL; - int depth, len, err; + int depth, len, err =3D 0; ext4_lblk_t next; int mb_flags =3D 0, unwritten; =20 @@ -1991,14 +1990,16 @@ int ext4_ext_insert_extent(handle_t *handle, struct= inode *inode, mb_flags |=3D EXT4_MB_DELALLOC_RESERVED; if (unlikely(ext4_ext_get_actual_len(newext) =3D=3D 0)) { EXT4_ERROR_INODE(inode, "ext4_ext_get_actual_len(newext) =3D=3D 0"); - return -EFSCORRUPTED; + err =3D -EFSCORRUPTED; + goto errout; } depth =3D ext_depth(inode); ex =3D path[depth].p_ext; eh =3D path[depth].p_hdr; if (unlikely(path[depth].p_hdr =3D=3D NULL)) { EXT4_ERROR_INODE(inode, "path[%d].p_hdr =3D=3D NULL", depth); - return -EFSCORRUPTED; + err =3D -EFSCORRUPTED; + goto errout; } =20 /* try to insert block into found extent and return */ @@ -2036,7 +2037,7 @@ int ext4_ext_insert_extent(handle_t *handle, struct i= node *inode, err =3D ext4_ext_get_access(handle, inode, path + depth); if (err) - return err; + goto errout; unwritten =3D ext4_ext_is_unwritten(ex); ex->ee_len =3D cpu_to_le16(ext4_ext_get_actual_len(ex) + ext4_ext_get_actual_len(newext)); @@ -2061,7 +2062,7 @@ int ext4_ext_insert_extent(handle_t *handle, struct i= node *inode, err =3D ext4_ext_get_access(handle, inode, path + depth); if (err) - return err; + goto errout; =20 unwritten =3D ext4_ext_is_unwritten(ex); ex->ee_block =3D newext->ee_block; @@ -2086,21 +2087,26 @@ int ext4_ext_insert_extent(handle_t *handle, struct= inode *inode, if (le32_to_cpu(newext->ee_block) > le32_to_cpu(fex->ee_block)) next =3D ext4_ext_next_leaf_block(path); if (next !=3D EXT_MAX_BLOCKS) { + struct ext4_ext_path *npath; + ext_debug(inode, "next leaf block - %u\n", next); - BUG_ON(npath !=3D NULL); npath =3D ext4_find_extent(inode, next, NULL, gb_flags); - if (IS_ERR(npath)) - return PTR_ERR(npath); + if (IS_ERR(npath)) { + err =3D PTR_ERR(npath); + goto errout; + } BUG_ON(npath->p_depth !=3D path->p_depth); eh =3D npath[depth].p_hdr; if (le16_to_cpu(eh->eh_entries) < le16_to_cpu(eh->eh_max)) { ext_debug(inode, "next leaf isn't full(%d)\n", le16_to_cpu(eh->eh_entries)); + ext4_free_ext_path(path); path =3D npath; goto has_space; } ext_debug(inode, "next leaf has no free space(%d,%d)\n", le16_to_cpu(eh->eh_entries), le16_to_cpu(eh->eh_max)); + ext4_free_ext_path(npath); } =20 /* @@ -2111,12 +2117,8 @@ int ext4_ext_insert_extent(handle_t *handle, struct = inode *inode, mb_flags |=3D EXT4_MB_USE_RESERVED; path =3D ext4_ext_create_new_leaf(handle, inode, mb_flags, gb_flags, path, newext); - if (IS_ERR(path)) { - *ppath =3D NULL; - err =3D PTR_ERR(path); - goto cleanup; - } - *ppath =3D path; + if (IS_ERR(path)) + return path; depth =3D ext_depth(inode); eh =3D path[depth].p_hdr; =20 @@ -2125,7 +2127,7 @@ int ext4_ext_insert_extent(handle_t *handle, struct i= node *inode, =20 err =3D ext4_ext_get_access(handle, inode, path + depth); if (err) - goto cleanup; + goto errout; =20 if (!nearex) { /* there is no extent in this leaf, create first one */ @@ -2183,17 +2185,20 @@ int ext4_ext_insert_extent(handle_t *handle, struct= inode *inode, if (!(gb_flags & EXT4_GET_BLOCKS_PRE_IO)) ext4_ext_try_to_merge(handle, inode, path, nearex); =20 - /* time to correct all indexes above */ err =3D ext4_ext_correct_indexes(handle, inode, path); if (err) - goto cleanup; + goto errout; =20 err =3D ext4_ext_dirty(handle, inode, path + path->p_depth); + if (err) + goto errout; =20 -cleanup: - ext4_free_ext_path(npath); - return err; + return path; + +errout: + ext4_free_ext_path(path); + return ERR_PTR(err); } =20 static int ext4_fill_es_cache_info(struct inode *inode, @@ -3248,24 +3253,29 @@ static int ext4_split_extent_at(handle_t *handle, if (split_flag & EXT4_EXT_MARK_UNWRIT2) ext4_ext_mark_unwritten(ex2); =20 - err =3D ext4_ext_insert_extent(handle, inode, ppath, &newex, flags); - if (err !=3D -ENOSPC && err !=3D -EDQUOT && err !=3D -ENOMEM) + path =3D ext4_ext_insert_extent(handle, inode, path, &newex, flags); + if (!IS_ERR(path)) { + *ppath =3D path; goto out; + } + *ppath =3D NULL; + err =3D PTR_ERR(path); + if (err !=3D -ENOSPC && err !=3D -EDQUOT && err !=3D -ENOMEM) + return err; =20 /* - * Update path is required because previous ext4_ext_insert_extent() - * may have freed or reallocated the path. Using EXT4_EX_NOFAIL - * guarantees that ext4_find_extent() will not return -ENOMEM, - * otherwise -ENOMEM will cause a retry in do_writepages(), and a - * WARN_ON may be triggered in ext4_da_update_reserve_space() due to - * an incorrect ee_len causing the i_reserved_data_blocks exception. + * Get a new path to try to zeroout or fix the extent length. + * Using EXT4_EX_NOFAIL guarantees that ext4_find_extent() + * will not return -ENOMEM, otherwise -ENOMEM will cause a + * retry in do_writepages(), and a WARN_ON may be triggered + * in ext4_da_update_reserve_space() due to an incorrect + * ee_len causing the i_reserved_data_blocks exception. */ - path =3D ext4_find_extent(inode, ee_block, *ppath, + path =3D ext4_find_extent(inode, ee_block, NULL, flags | EXT4_EX_NOFAIL); if (IS_ERR(path)) { EXT4_ERROR_INODE(inode, "Failed split extent on %u, err %ld", split, PTR_ERR(path)); - *ppath =3D NULL; return PTR_ERR(path); } depth =3D ext_depth(inode); @@ -3324,7 +3334,7 @@ static int ext4_split_extent_at(handle_t *handle, ext4_ext_dirty(handle, inode, path + path->p_depth); return err; out: - ext4_ext_show_leaf(inode, *ppath); + ext4_ext_show_leaf(inode, path); return err; } =20 @@ -4313,6 +4323,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inod= e *inode, get_implied_cluster_alloc(inode->i_sb, map, &ex2, path)) { ar.len =3D allocated =3D map->m_len; newblock =3D map->m_pblk; + err =3D 0; goto got_allocated_blocks; } =20 @@ -4385,8 +4396,9 @@ int ext4_ext_map_blocks(handle_t *handle, struct inod= e *inode, map->m_flags |=3D EXT4_MAP_UNWRITTEN; } =20 - err =3D ext4_ext_insert_extent(handle, inode, &path, &newex, flags); - if (err) { + path =3D ext4_ext_insert_extent(handle, inode, path, &newex, flags); + if (IS_ERR(path)) { + err =3D PTR_ERR(path); if (allocated_clusters) { int fb_flags =3D 0; =20 diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 87c009e0c59a..1dee40477727 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1777,12 +1777,12 @@ static int ext4_fc_replay_add_range(struct super_bl= ock *sb, if (ext4_ext_is_unwritten(ex)) ext4_ext_mark_unwritten(&newex); down_write(&EXT4_I(inode)->i_data_sem); - ret =3D ext4_ext_insert_extent( - NULL, inode, &path, &newex, 0); + path =3D ext4_ext_insert_extent(NULL, inode, + path, &newex, 0); up_write((&EXT4_I(inode)->i_data_sem)); - ext4_free_ext_path(path); - if (ret) + if (IS_ERR(path)) goto out; + ext4_free_ext_path(path); goto next; } =20 diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index d98ac2af8199..0f68b8a14560 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c @@ -37,7 +37,6 @@ static int finish_range(handle_t *handle, struct inode *i= node, path =3D ext4_find_extent(inode, lb->first_block, NULL, 0); if (IS_ERR(path)) { retval =3D PTR_ERR(path); - path =3D NULL; goto err_out; } =20 @@ -53,7 +52,9 @@ static int finish_range(handle_t *handle, struct inode *i= node, retval =3D ext4_datasem_ensure_credits(handle, inode, needed, needed, 0); if (retval < 0) goto err_out; - retval =3D ext4_ext_insert_extent(handle, inode, &path, &newext, 0); + path =3D ext4_ext_insert_extent(handle, inode, path, &newext, 0); + if (IS_ERR(path)) + retval =3D PTR_ERR(path); err_out: up_write((&EXT4_I(inode)->i_data_sem)); ext4_free_ext_path(path); --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB6666AFAE; Wed, 10 Jul 2024 04:09:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584560; cv=none; b=gxEBuIVYUpj3TMyRxmue8leL6XNejz0rnBQw17+kD3lUt37ZmuQyITK8o9Ap6lHnqlwilU94gTCcEbT80WO0aLKunbUCsKmz3yVKiGVufK81Xga9ah6PmNFUatV8fXscB3dTkwWYpGlpJMrSQ3mYxdn6wQZ3RGO8BnUC6DUcg2I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584560; c=relaxed/simple; bh=2d31sUOtKNS+XBVK8uowHH3gbqHRJ+Vinv3y8v4j9/Q=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nXxbUC9bgRagCEpq5ytseo3XrATY9A+3fWD5cziepGLomgw6LKy+qPRwKALbYQugiyvi1yBWyZDrTnkQrkSH5uYOwwz1WnjVlNzgsWtN6pOHC52wyPBZ+rLz6ll57TrAwauVSkxBcO4hjULuWBHvhlfSE/oZYb2PCv4uw76G3MM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkrB0DGyz4f3mJX; Wed, 10 Jul 2024 12:08:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 9D33C1A016E; Wed, 10 Jul 2024 12:09:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S16; Wed, 10 Jul 2024 12:09:09 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 12/20] ext4: get rid of ppath in ext4_split_extent_at() Date: Wed, 10 Jul 2024 12:06:46 +0800 Message-Id: <20240710040654.1714672-13-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S16 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar45Zr1UKFyDKryftF18Xwb_yoWxZF4xpr sI9F18Grn8GasFgrWxJanrZr1a9a1UG3yUGFW7G3sYk3WjqryYgF1xta45tFW5KrW8Wa43 Ar4Fyry5Wa47J37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHmgAGsy Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_split_extent_at(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. * Teach ext4_ext_show_leaf() to skip error pointer. * Propagate ext4_find_extent() error return value in ext4_insert_range(). No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 86 ++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 38 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index fc75390d591a..c86b1bb7720f 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -84,12 +84,11 @@ static void ext4_extent_block_csum_set(struct inode *in= ode, et->et_checksum =3D ext4_extent_block_csum(inode, eh); } =20 -static int ext4_split_extent_at(handle_t *handle, - struct inode *inode, - struct ext4_ext_path **ppath, - ext4_lblk_t split, - int split_flag, - int flags); +static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle, + struct inode *inode, + struct ext4_ext_path *path, + ext4_lblk_t split, + int split_flag, int flags); =20 static int ext4_ext_trunc_restart_fn(struct inode *inode, int *dropped) { @@ -341,9 +340,15 @@ ext4_force_split_extent_at(handle_t *handle, struct in= ode *inode, if (nofail) flags |=3D EXT4_GET_BLOCKS_METADATA_NOFAIL | EXT4_EX_NOFAIL; =20 - return ext4_split_extent_at(handle, inode, ppath, lblk, unwritten ? + path =3D ext4_split_extent_at(handle, inode, path, lblk, unwritten ? EXT4_EXT_MARK_UNWRIT1|EXT4_EXT_MARK_UNWRIT2 : 0, flags); + if (IS_ERR(path)) { + *ppath =3D NULL; + return PTR_ERR(path); + } + *ppath =3D path; + return 0; } =20 static int @@ -694,7 +699,7 @@ static void ext4_ext_show_leaf(struct inode *inode, str= uct ext4_ext_path *path) struct ext4_extent *ex; int i; =20 - if (!path) + if (IS_ERR_OR_NULL(path)) return; =20 eh =3D path[depth].p_hdr; @@ -3174,16 +3179,14 @@ static int ext4_ext_zeroout(struct inode *inode, st= ruct ext4_extent *ex) * a> the extent are splitted into two extent. * b> split is not needed, and just mark the extent. * - * return 0 on success. + * Return an extent path pointer on success, or an error pointer on failur= e. */ -static int ext4_split_extent_at(handle_t *handle, - struct inode *inode, - struct ext4_ext_path **ppath, - ext4_lblk_t split, - int split_flag, - int flags) +static struct ext4_ext_path *ext4_split_extent_at(handle_t *handle, + struct inode *inode, + struct ext4_ext_path *path, + ext4_lblk_t split, + int split_flag, int flags) { - struct ext4_ext_path *path =3D *ppath; ext4_fsblk_t newblock; ext4_lblk_t ee_block; struct ext4_extent *ex, newex, orig_ex, zero_ex; @@ -3254,14 +3257,12 @@ static int ext4_split_extent_at(handle_t *handle, ext4_ext_mark_unwritten(ex2); =20 path =3D ext4_ext_insert_extent(handle, inode, path, &newex, flags); - if (!IS_ERR(path)) { - *ppath =3D path; + if (!IS_ERR(path)) goto out; - } - *ppath =3D NULL; + err =3D PTR_ERR(path); if (err !=3D -ENOSPC && err !=3D -EDQUOT && err !=3D -ENOMEM) - return err; + return path; =20 /* * Get a new path to try to zeroout or fix the extent length. @@ -3271,16 +3272,14 @@ static int ext4_split_extent_at(handle_t *handle, * in ext4_da_update_reserve_space() due to an incorrect * ee_len causing the i_reserved_data_blocks exception. */ - path =3D ext4_find_extent(inode, ee_block, NULL, - flags | EXT4_EX_NOFAIL); + path =3D ext4_find_extent(inode, ee_block, NULL, flags | EXT4_EX_NOFAIL); if (IS_ERR(path)) { EXT4_ERROR_INODE(inode, "Failed split extent on %u, err %ld", split, PTR_ERR(path)); - return PTR_ERR(path); + return path; } depth =3D ext_depth(inode); ex =3D path[depth].p_ext; - *ppath =3D path; =20 if (EXT4_EXT_MAY_ZEROOUT & split_flag) { if (split_flag & (EXT4_EXT_DATA_VALID1|EXT4_EXT_DATA_VALID2)) { @@ -3332,10 +3331,13 @@ static int ext4_split_extent_at(handle_t *handle, * and err is a non-zero error code. */ ext4_ext_dirty(handle, inode, path + path->p_depth); - return err; out: + if (err) { + ext4_free_ext_path(path); + path =3D ERR_PTR(err); + } ext4_ext_show_leaf(inode, path); - return err; + return path; } =20 /* @@ -3379,10 +3381,14 @@ static int ext4_split_extent(handle_t *handle, EXT4_EXT_MARK_UNWRIT2; if (split_flag & EXT4_EXT_DATA_VALID2) split_flag1 |=3D EXT4_EXT_DATA_VALID1; - err =3D ext4_split_extent_at(handle, inode, ppath, + path =3D ext4_split_extent_at(handle, inode, path, map->m_lblk + map->m_len, split_flag1, flags1); - if (err) + if (IS_ERR(path)) { + err =3D PTR_ERR(path); + *ppath =3D NULL; goto out; + } + *ppath =3D path; } else { allocated =3D ee_len - (map->m_lblk - ee_block); } @@ -3390,7 +3396,7 @@ static int ext4_split_extent(handle_t *handle, * Update path is required because previous ext4_split_extent_at() may * result in split of original leaf or extent zeroout. */ - path =3D ext4_find_extent(inode, map->m_lblk, *ppath, flags); + path =3D ext4_find_extent(inode, map->m_lblk, path, flags); if (IS_ERR(path)) { *ppath =3D NULL; return PTR_ERR(path); @@ -3412,13 +3418,17 @@ static int ext4_split_extent(handle_t *handle, split_flag1 |=3D split_flag & (EXT4_EXT_MAY_ZEROOUT | EXT4_EXT_MARK_UNWRIT2); } - err =3D ext4_split_extent_at(handle, inode, ppath, + path =3D ext4_split_extent_at(handle, inode, path, map->m_lblk, split_flag1, flags); - if (err) + if (IS_ERR(path)) { + err =3D PTR_ERR(path); + *ppath =3D NULL; goto out; + } + *ppath =3D path; } =20 - ext4_ext_show_leaf(inode, *ppath); + ext4_ext_show_leaf(inode, path); out: return err ? err : allocated; } @@ -5596,6 +5606,7 @@ static int ext4_insert_range(struct file *file, loff_= t offset, loff_t len) path =3D ext4_find_extent(inode, offset_lblk, NULL, 0); if (IS_ERR(path)) { up_write(&EXT4_I(inode)->i_data_sem); + ret =3D PTR_ERR(path); goto out_stop; } =20 @@ -5614,22 +5625,21 @@ static int ext4_insert_range(struct file *file, lof= f_t offset, loff_t len) if (ext4_ext_is_unwritten(extent)) split_flag =3D EXT4_EXT_MARK_UNWRIT1 | EXT4_EXT_MARK_UNWRIT2; - ret =3D ext4_split_extent_at(handle, inode, &path, + path =3D ext4_split_extent_at(handle, inode, path, offset_lblk, split_flag, EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_PRE_IO | EXT4_GET_BLOCKS_METADATA_NOFAIL); } =20 - ext4_free_ext_path(path); - if (ret < 0) { + if (IS_ERR(path)) { up_write(&EXT4_I(inode)->i_data_sem); + ret =3D PTR_ERR(path); goto out_stop; } - } else { - ext4_free_ext_path(path); } =20 + ext4_free_ext_path(path); ext4_es_remove_extent(inode, offset_lblk, EXT_MAX_BLOCKS - offset_lblk); =20 /* --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB624679E5; Wed, 10 Jul 2024 04:09:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584561; cv=none; b=oyISzFI3wqEr7xfz6pOCHMk/ZF69yokhiZ+sNOjzJ8ltXRvDhbUhVNuN8RBlDYzXJc6JYf44eFo3eUT9NjEVcr3diwCeNX4eUuVM9TIO1yNhBDudT/gAE2CgJJZYXHZI7+vNNnXGtJocUn3sFK782qzAS9zE9S4x4oeJ/TNQb0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584561; c=relaxed/simple; bh=h7WaqXVeQnk6U1fKBr3xAO1Vc51WGwoJwbuSPTD3Yoo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oi+iKXh5ucBJQ8DYQxD8B5bADA4UnHhCXrqx1hdLx41QbkNifYIo+wnVhfMfEXWWZ8B2dw/jsX/GSIX6mDIXof93W/09dv0JLM9dl7l/+jsxKZT+syXgYTmw20DE7Tkzbe3P2fD30BFR5ki4jKGV5Prz1BHJyk8MvstXeocPFlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkrB3SMxz4f3mJc; Wed, 10 Jul 2024 12:08:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 186F71A0181; Wed, 10 Jul 2024 12:09:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S17; Wed, 10 Jul 2024 12:09:09 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 13/20] ext4: get rid of ppath in ext4_force_split_extent_at() Date: Wed, 10 Jul 2024 12:06:47 +0800 Message-Id: <20240710040654.1714672-14-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S17 X-Coremail-Antispam: 1UD129KBjvJXoW3GF1kKF1xuFyUuF4rtFy8Grg_yoW3JFy5pF 129F1DGr95tF90gryIqw17Xr1aka15GrWUGF93Gas5A3Wqqr1Y9F1xt3WSyF45KrWrWaya yr4S9ry5uw1DX37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7IKgAAs1 Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_force_split_extent_at(), the following is done here: * The ext4_find_extent() can update the extent path so it doesn't have to allocate and free path repeatedly, thus reducing the consumption of memory allocation and freeing in ext4_swap_extents(). No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 117 ++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index c86b1bb7720f..0bd068ed324f 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -328,27 +328,20 @@ static inline int ext4_ext_space_root_idx(struct inod= e *inode, int check) return size; } =20 -static inline int +static inline struct ext4_ext_path * ext4_force_split_extent_at(handle_t *handle, struct inode *inode, - struct ext4_ext_path **ppath, ext4_lblk_t lblk, + struct ext4_ext_path *path, ext4_lblk_t lblk, int nofail) { - struct ext4_ext_path *path =3D *ppath; int unwritten =3D ext4_ext_is_unwritten(path[path->p_depth].p_ext); int flags =3D EXT4_EX_NOCACHE | EXT4_GET_BLOCKS_PRE_IO; =20 if (nofail) flags |=3D EXT4_GET_BLOCKS_METADATA_NOFAIL | EXT4_EX_NOFAIL; =20 - path =3D ext4_split_extent_at(handle, inode, path, lblk, unwritten ? + return ext4_split_extent_at(handle, inode, path, lblk, unwritten ? EXT4_EXT_MARK_UNWRIT1|EXT4_EXT_MARK_UNWRIT2 : 0, flags); - if (IS_ERR(path)) { - *ppath =3D NULL; - return PTR_ERR(path); - } - *ppath =3D path; - return 0; } =20 static int @@ -2906,11 +2899,12 @@ int ext4_ext_remove_space(struct inode *inode, ext4= _lblk_t start, * fail removing space due to ENOSPC so try to use * reserved block if that happens. */ - err =3D ext4_force_split_extent_at(handle, inode, &path, - end + 1, 1); - if (err < 0) + path =3D ext4_force_split_extent_at(handle, inode, path, + end + 1, 1); + if (IS_ERR(path)) { + err =3D PTR_ERR(path); goto out; - + } } else if (sbi->s_cluster_ratio > 1 && end >=3D ex_end && partial.state =3D=3D initial) { /* @@ -5707,25 +5701,21 @@ ext4_swap_extents(handle_t *handle, struct inode *i= node1, int e1_len, e2_len, len; int split =3D 0; =20 - path1 =3D ext4_find_extent(inode1, lblk1, NULL, EXT4_EX_NOCACHE); + path1 =3D ext4_find_extent(inode1, lblk1, path1, EXT4_EX_NOCACHE); if (IS_ERR(path1)) { *erp =3D PTR_ERR(path1); - path1 =3D NULL; - finish: - count =3D 0; - goto repeat; + goto errout; } - path2 =3D ext4_find_extent(inode2, lblk2, NULL, EXT4_EX_NOCACHE); + path2 =3D ext4_find_extent(inode2, lblk2, path2, EXT4_EX_NOCACHE); if (IS_ERR(path2)) { *erp =3D PTR_ERR(path2); - path2 =3D NULL; - goto finish; + goto errout; } ex1 =3D path1[path1->p_depth].p_ext; ex2 =3D path2[path2->p_depth].p_ext; /* Do we have something to swap ? */ if (unlikely(!ex2 || !ex1)) - goto finish; + goto errout; =20 e1_blk =3D le32_to_cpu(ex1->ee_block); e2_blk =3D le32_to_cpu(ex2->ee_block); @@ -5747,7 +5737,7 @@ ext4_swap_extents(handle_t *handle, struct inode *ino= de1, next2 =3D e2_blk; /* Do we have something to swap */ if (next1 =3D=3D EXT_MAX_BLOCKS || next2 =3D=3D EXT_MAX_BLOCKS) - goto finish; + goto errout; /* Move to the rightest boundary */ len =3D next1 - lblk1; if (len < next2 - lblk2) @@ -5757,28 +5747,32 @@ ext4_swap_extents(handle_t *handle, struct inode *i= node1, lblk1 +=3D len; lblk2 +=3D len; count -=3D len; - goto repeat; + continue; } =20 /* Prepare left boundary */ if (e1_blk < lblk1) { split =3D 1; - *erp =3D ext4_force_split_extent_at(handle, inode1, - &path1, lblk1, 0); - if (unlikely(*erp)) - goto finish; + path1 =3D ext4_force_split_extent_at(handle, inode1, + path1, lblk1, 0); + if (IS_ERR(path1)) { + *erp =3D PTR_ERR(path1); + goto errout; + } } if (e2_blk < lblk2) { split =3D 1; - *erp =3D ext4_force_split_extent_at(handle, inode2, - &path2, lblk2, 0); - if (unlikely(*erp)) - goto finish; + path2 =3D ext4_force_split_extent_at(handle, inode2, + path2, lblk2, 0); + if (IS_ERR(path2)) { + *erp =3D PTR_ERR(path2); + goto errout; + } } /* ext4_split_extent_at() may result in leaf extent split, * path must to be revalidated. */ if (split) - goto repeat; + continue; =20 /* Prepare right boundary */ len =3D count; @@ -5789,30 +5783,34 @@ ext4_swap_extents(handle_t *handle, struct inode *i= node1, =20 if (len !=3D e1_len) { split =3D 1; - *erp =3D ext4_force_split_extent_at(handle, inode1, - &path1, lblk1 + len, 0); - if (unlikely(*erp)) - goto finish; + path1 =3D ext4_force_split_extent_at(handle, inode1, + path1, lblk1 + len, 0); + if (IS_ERR(path1)) { + *erp =3D PTR_ERR(path1); + goto errout; + } } if (len !=3D e2_len) { split =3D 1; - *erp =3D ext4_force_split_extent_at(handle, inode2, - &path2, lblk2 + len, 0); - if (*erp) - goto finish; + path2 =3D ext4_force_split_extent_at(handle, inode2, + path2, lblk2 + len, 0); + if (IS_ERR(path2)) { + *erp =3D PTR_ERR(path2); + goto errout; + } } /* ext4_split_extent_at() may result in leaf extent split, * path must to be revalidated. */ if (split) - goto repeat; + continue; =20 BUG_ON(e2_len !=3D e1_len); *erp =3D ext4_ext_get_access(handle, inode1, path1 + path1->p_depth); if (unlikely(*erp)) - goto finish; + goto errout; *erp =3D ext4_ext_get_access(handle, inode2, path2 + path2->p_depth); if (unlikely(*erp)) - goto finish; + goto errout; =20 /* Both extents are fully inside boundaries. Swap it now */ tmp_ex =3D *ex1; @@ -5830,7 +5828,7 @@ ext4_swap_extents(handle_t *handle, struct inode *ino= de1, *erp =3D ext4_ext_dirty(handle, inode2, path2 + path2->p_depth); if (unlikely(*erp)) - goto finish; + goto errout; *erp =3D ext4_ext_dirty(handle, inode1, path1 + path1->p_depth); /* @@ -5840,17 +5838,17 @@ ext4_swap_extents(handle_t *handle, struct inode *i= node1, * aborted anyway. */ if (unlikely(*erp)) - goto finish; + goto errout; + lblk1 +=3D len; lblk2 +=3D len; replaced_count +=3D len; count -=3D len; - - repeat: - ext4_free_ext_path(path1); - ext4_free_ext_path(path2); - path1 =3D path2 =3D NULL; } + +errout: + ext4_free_ext_path(path1); + ext4_free_ext_path(path2); return replaced_count; } =20 @@ -5965,24 +5963,29 @@ int ext4_ext_replay_update_ex(struct inode *inode, = ext4_lblk_t start, ext4_ext_get_actual_len(ex) !=3D len) { /* We need to split this extent to match our extent first */ down_write(&EXT4_I(inode)->i_data_sem); - ret =3D ext4_force_split_extent_at(NULL, inode, &path, start, 1); + path =3D ext4_force_split_extent_at(NULL, inode, path, start, 1); up_write(&EXT4_I(inode)->i_data_sem); - if (ret) + if (IS_ERR(path)) { + ret =3D PTR_ERR(path); goto out; + } =20 path =3D ext4_find_extent(inode, start, path, 0); if (IS_ERR(path)) return PTR_ERR(path); + ex =3D path[path->p_depth].p_ext; WARN_ON(le32_to_cpu(ex->ee_block) !=3D start); =20 if (ext4_ext_get_actual_len(ex) !=3D len) { down_write(&EXT4_I(inode)->i_data_sem); - ret =3D ext4_force_split_extent_at(NULL, inode, &path, - start + len, 1); + path =3D ext4_force_split_extent_at(NULL, inode, path, + start + len, 1); up_write(&EXT4_I(inode)->i_data_sem); - if (ret) + if (IS_ERR(path)) { + ret =3D PTR_ERR(path); goto out; + } =20 path =3D ext4_find_extent(inode, start, path, 0); if (IS_ERR(path)) --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C59F984A5B; Wed, 10 Jul 2024 04:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584563; cv=none; b=ejDsYG363ffmfqzcqj9+LiyYlGm4oOsYSikKxOiYG3qrSdn2ca8VhJvch/3Z7v0X0cO5GB7PIo1M4yyrXgT2Emp0liTHowXE923vxhVb0oeAXB+iB+v2HAhGzaSt+sAcXkIw1gZdCDY7Adl2MpdckcPmFe3M2TXtOzTt0Gqcx3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584563; c=relaxed/simple; bh=t8RewoS1wKL0Jubkxb9fUFLq82yDackMBvCxH2n8tSU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tZUqftxA2ZII43JtcPs7mkvlRWDNZEYDs5VgZV7vUQOSr1lZUEg5myTDRxQVH9UNZvbGVJlyIGngQaf3zMxZYqpMb+H+0n08HKolHkid6xAoq0X9EAtdpzyOVjBvmdcK+WeUS0hrAdsbWvpEQ9DmcLfabas8C7hK+jdRc0zkWJc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkrB66jbz4f3mJf; Wed, 10 Jul 2024 12:08:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 75FF31A0181; Wed, 10 Jul 2024 12:09:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S18; Wed, 10 Jul 2024 12:09:10 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 14/20] ext4: get rid of ppath in ext4_split_extent() Date: Wed, 10 Jul 2024 12:06:48 +0800 Message-Id: <20240710040654.1714672-15-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S18 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4kAF4fKF1UCryDuw1DAwb_yoW7Jw4xpr s3ur1UKw1DKwnF9rWxJ3W8ur1aka15Gay7CFW3tr9Yv3WqqFyagFyxt3WFqFWrtrW8WFya yr40yry5Ca13JaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHoAAAsO Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_split_extent(), the following is done here: * The 'allocated' is changed from passing a value to passing an address. * Its caller needs to update ppath if it uses ppath. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 97 ++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 47 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 0bd068ed324f..2a4f6c89858c 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3345,21 +3345,18 @@ static struct ext4_ext_path *ext4_split_extent_at(h= andle_t *handle, * c> Splits in three extents: Somone is splitting in middle of the exte= nt * */ -static int ext4_split_extent(handle_t *handle, - struct inode *inode, - struct ext4_ext_path **ppath, - struct ext4_map_blocks *map, - int split_flag, - int flags) +static struct ext4_ext_path *ext4_split_extent(handle_t *handle, + struct inode *inode, + struct ext4_ext_path *path, + struct ext4_map_blocks *map, + int split_flag, int flags, + unsigned int *allocated) { - struct ext4_ext_path *path =3D *ppath; ext4_lblk_t ee_block; struct ext4_extent *ex; unsigned int ee_len, depth; - int err =3D 0; int unwritten; int split_flag1, flags1; - int allocated =3D map->m_len; =20 depth =3D ext_depth(inode); ex =3D path[depth].p_ext; @@ -3377,33 +3374,25 @@ static int ext4_split_extent(handle_t *handle, split_flag1 |=3D EXT4_EXT_DATA_VALID1; path =3D ext4_split_extent_at(handle, inode, path, map->m_lblk + map->m_len, split_flag1, flags1); - if (IS_ERR(path)) { - err =3D PTR_ERR(path); - *ppath =3D NULL; - goto out; + if (IS_ERR(path)) + return path; + /* + * Update path is required because previous ext4_split_extent_at + * may result in split of original leaf or extent zeroout. + */ + path =3D ext4_find_extent(inode, map->m_lblk, path, flags); + if (IS_ERR(path)) + return path; + depth =3D ext_depth(inode); + ex =3D path[depth].p_ext; + if (!ex) { + EXT4_ERROR_INODE(inode, "unexpected hole at %lu", + (unsigned long) map->m_lblk); + ext4_free_ext_path(path); + return ERR_PTR(-EFSCORRUPTED); } - *ppath =3D path; - } else { - allocated =3D ee_len - (map->m_lblk - ee_block); - } - /* - * Update path is required because previous ext4_split_extent_at() may - * result in split of original leaf or extent zeroout. - */ - path =3D ext4_find_extent(inode, map->m_lblk, path, flags); - if (IS_ERR(path)) { - *ppath =3D NULL; - return PTR_ERR(path); - } - *ppath =3D path; - depth =3D ext_depth(inode); - ex =3D path[depth].p_ext; - if (!ex) { - EXT4_ERROR_INODE(inode, "unexpected hole at %lu", - (unsigned long) map->m_lblk); - return -EFSCORRUPTED; + unwritten =3D ext4_ext_is_unwritten(ex); } - unwritten =3D ext4_ext_is_unwritten(ex); =20 if (map->m_lblk >=3D ee_block) { split_flag1 =3D split_flag & EXT4_EXT_DATA_VALID2; @@ -3414,17 +3403,18 @@ static int ext4_split_extent(handle_t *handle, } path =3D ext4_split_extent_at(handle, inode, path, map->m_lblk, split_flag1, flags); - if (IS_ERR(path)) { - err =3D PTR_ERR(path); - *ppath =3D NULL; - goto out; - } - *ppath =3D path; + if (IS_ERR(path)) + return path; } =20 + if (allocated) { + if (map->m_lblk + map->m_len > ee_block + ee_len) + *allocated =3D ee_len - (map->m_lblk - ee_block); + else + *allocated =3D map->m_len; + } ext4_ext_show_leaf(inode, path); -out: - return err ? err : allocated; + return path; } =20 /* @@ -3669,10 +3659,15 @@ static int ext4_ext_convert_to_initialized(handle_t= *handle, } =20 fallback: - err =3D ext4_split_extent(handle, inode, ppath, &split_map, split_flag, - flags); - if (err > 0) - err =3D 0; + path =3D ext4_split_extent(handle, inode, path, &split_map, split_flag, + flags, NULL); + if (IS_ERR(path)) { + err =3D PTR_ERR(path); + *ppath =3D NULL; + goto out; + } + err =3D 0; + *ppath =3D path; out: /* If we have gotten a failure, don't zero out status tree */ if (!err) { @@ -3718,6 +3713,7 @@ static int ext4_split_convert_extents(handle_t *handl= e, struct ext4_extent *ex; unsigned int ee_len; int split_flag =3D 0, depth; + unsigned int allocated =3D 0; =20 ext_debug(inode, "logical block %llu, max_blocks %u\n", (unsigned long long)map->m_lblk, map->m_len); @@ -3745,7 +3741,14 @@ static int ext4_split_convert_extents(handle_t *hand= le, split_flag |=3D (EXT4_EXT_MARK_UNWRIT2 | EXT4_EXT_DATA_VALID2); } flags |=3D EXT4_GET_BLOCKS_PRE_IO; - return ext4_split_extent(handle, inode, ppath, map, split_flag, flags); + path =3D ext4_split_extent(handle, inode, path, map, split_flag, flags, + &allocated); + if (IS_ERR(path)) { + *ppath =3D NULL; + return PTR_ERR(path); + } + *ppath =3D path; + return allocated; } =20 static int ext4_convert_unwritten_extents_endio(handle_t *handle, --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 190523BBD8; Wed, 10 Jul 2024 04:09:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; cv=none; b=g5BdVunO+nyynzQASdugojQfv5v7PUcRXU4ohDBSP+i3F9/2NxXaDR1z8ZjjxYy+rIwjajJ7BI2ft5y+PWbiBPji/Ga6GHfKYm56tLg1rQv2+rSuv2aEuPrmGS5kUCbaZxWXbNRFFc38vnrv4jnb7wWW6+cLQlf0g99/Hu8F1gw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; c=relaxed/simple; bh=F4SlUeedvrKX/83s62XbxoouHtJ8shl+IPI8h/OpYIs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nD98VeGFpKze+JGsKPa/7nwLtqJjYN43fqOdThnpTKuAzTZEWZ45bJShmjc6bDaE94nYc8M6b4ZOJGRh6Uebt1rFCHMYhzMxp18uV+ssoCRwVePOtAU4mmpDFhBI5fhwFZ1t9BPWDb7QYMhZhOrEMUYda+v9obsCGw29xkM7rOk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrH1d9fz4f3kp4; Wed, 10 Jul 2024 12:09:03 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id D79121A0184; Wed, 10 Jul 2024 12:09:10 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S19; Wed, 10 Jul 2024 12:09:10 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 15/20] ext4: get rid of ppath in ext4_split_convert_extents() Date: Wed, 10 Jul 2024 12:06:49 +0800 Message-Id: <20240710040654.1714672-16-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S19 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4kAF4DAryUArW3Xr13Jwb_yoW7JF1kpF 17Zr1rCr1UKwnIgFWxu3W8Zr1aka1UGFW7CrWft34Fva1qqrnYgF17t3WrtFWrtrW8ua4a yr40yFyUC3ZxAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHoQABsO Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_split_convert_extents(), the following is done here: * Its caller needs to update ppath if it uses ppath. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 65 ++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 2a4f6c89858c..a41cbb8c4475 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3699,21 +3699,21 @@ static int ext4_ext_convert_to_initialized(handle_t= *handle, * being filled will be convert to initialized by the end_io callback func= tion * via ext4_convert_unwritten_extents(). * - * Returns the size of unwritten extent to be written on success. + * The size of unwritten extent to be written is passed to the caller via = the + * allocated pointer. Return an extent path pointer on success, or an error + * pointer on failure. */ -static int ext4_split_convert_extents(handle_t *handle, +static struct ext4_ext_path *ext4_split_convert_extents(handle_t *handle, struct inode *inode, struct ext4_map_blocks *map, - struct ext4_ext_path **ppath, - int flags) + struct ext4_ext_path *path, + int flags, unsigned int *allocated) { - struct ext4_ext_path *path =3D *ppath; ext4_lblk_t eof_block; ext4_lblk_t ee_block; struct ext4_extent *ex; unsigned int ee_len; int split_flag =3D 0, depth; - unsigned int allocated =3D 0; =20 ext_debug(inode, "logical block %llu, max_blocks %u\n", (unsigned long long)map->m_lblk, map->m_len); @@ -3741,14 +3741,8 @@ static int ext4_split_convert_extents(handle_t *hand= le, split_flag |=3D (EXT4_EXT_MARK_UNWRIT2 | EXT4_EXT_DATA_VALID2); } flags |=3D EXT4_GET_BLOCKS_PRE_IO; - path =3D ext4_split_extent(handle, inode, path, map, split_flag, flags, - &allocated); - if (IS_ERR(path)) { - *ppath =3D NULL; - return PTR_ERR(path); - } - *ppath =3D path; - return allocated; + return ext4_split_extent(handle, inode, path, map, split_flag, flags, + allocated); } =20 static int ext4_convert_unwritten_extents_endio(handle_t *handle, @@ -3784,11 +3778,14 @@ static int ext4_convert_unwritten_extents_endio(han= dle_t *handle, inode->i_ino, (unsigned long long)ee_block, ee_len, (unsigned long long)map->m_lblk, map->m_len); #endif - err =3D ext4_split_convert_extents(handle, inode, map, ppath, - EXT4_GET_BLOCKS_CONVERT); - if (err < 0) - return err; - path =3D ext4_find_extent(inode, map->m_lblk, *ppath, 0); + path =3D ext4_split_convert_extents(handle, inode, map, path, + EXT4_GET_BLOCKS_CONVERT, NULL); + if (IS_ERR(path)) { + *ppath =3D NULL; + return PTR_ERR(path); + } + + path =3D ext4_find_extent(inode, map->m_lblk, path, 0); if (IS_ERR(path)) { *ppath =3D NULL; return PTR_ERR(path); @@ -3845,11 +3842,14 @@ convert_initialized_extent(handle_t *handle, struct= inode *inode, (unsigned long long)ee_block, ee_len); =20 if (ee_block !=3D map->m_lblk || ee_len > map->m_len) { - err =3D ext4_split_convert_extents(handle, inode, map, ppath, - EXT4_GET_BLOCKS_CONVERT_UNWRITTEN); - if (err < 0) - return err; - path =3D ext4_find_extent(inode, map->m_lblk, *ppath, 0); + path =3D ext4_split_convert_extents(handle, inode, map, path, + EXT4_GET_BLOCKS_CONVERT_UNWRITTEN, NULL); + if (IS_ERR(path)) { + *ppath =3D NULL; + return PTR_ERR(path); + } + + path =3D ext4_find_extent(inode, map->m_lblk, path, 0); if (IS_ERR(path)) { *ppath =3D NULL; return PTR_ERR(path); @@ -3915,19 +3915,20 @@ ext4_ext_handle_unwritten_extents(handle_t *handle,= struct inode *inode, =20 /* get_block() before submitting IO, split the extent */ if (flags & EXT4_GET_BLOCKS_PRE_IO) { - ret =3D ext4_split_convert_extents(handle, inode, map, ppath, - flags | EXT4_GET_BLOCKS_CONVERT); - if (ret < 0) { - err =3D ret; + *ppath =3D ext4_split_convert_extents(handle, inode, map, *ppath, + flags | EXT4_GET_BLOCKS_CONVERT, &allocated); + if (IS_ERR(*ppath)) { + err =3D PTR_ERR(*ppath); + *ppath =3D NULL; goto out2; } /* - * shouldn't get a 0 return when splitting an extent unless + * shouldn't get a 0 allocated when splitting an extent unless * m_len is 0 (bug) or extent has been corrupted */ - if (unlikely(ret =3D=3D 0)) { + if (unlikely(allocated =3D=3D 0)) { EXT4_ERROR_INODE(inode, - "unexpected ret =3D=3D 0, m_len =3D %u", + "unexpected allocated =3D=3D 0, m_len =3D %u", map->m_len); err =3D -EFSCORRUPTED; goto out2; @@ -3988,9 +3989,9 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, s= truct inode *inode, err =3D -EFSCORRUPTED; goto out2; } + allocated =3D ret; =20 out: - allocated =3D ret; map->m_flags |=3D EXT4_MAP_NEW; map_out: map->m_flags |=3D EXT4_MAP_MAPPED; --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 59E943D556; Wed, 10 Jul 2024 04:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; cv=none; b=Pdl4N78sX8jXL5fyZtHUGhfq2Vs1s6JJL82Bga+Plvv+oE04W3kvWeQIrnvau+N6nOS2P9R/fKYI4r90G9d49vTDi6LNVNdbuUBlC1T6vEF6IOjwqVza0e1FiWfoKAPX0K59UzDM1HDRK7eW9l/x31PGig7HyfslkNVDZ4OXlrY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; c=relaxed/simple; bh=8i0Pt30pMpVduXWpEQ+RoTimzhs0vW9GkolTc81cIfo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=b6w2SQKbLQHsxbomqS3gsuvjiiHNJi6IXX+3ommu6SAo624c4FFHeON4C1odnCdu0sbfFIGrOqefmzCd4yd31EXo10bVvG94PDjquh2AnngJDTRWP62l/qSBpBBOgRqi1rHKnhKIDOXZlL7+0kQkKWNExm6fNo/HQdqCmYsPTJ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrB36cBz4f3m7R; Wed, 10 Jul 2024 12:08:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 47E271A016E; Wed, 10 Jul 2024 12:09:11 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S20; Wed, 10 Jul 2024 12:09:11 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 16/20] ext4: get rid of ppath in ext4_convert_unwritten_extents_endio() Date: Wed, 10 Jul 2024 12:06:50 +0800 Message-Id: <20240710040654.1714672-17-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S20 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4kZFWfKFW7XrW8Gry7Awb_yoW5AF4rpF 9Ikr1Fkr1UKwsF9FWxAa1UXr1ak3W8GayUArZxG3sY93ZFvrn5XFy8t3WFvFWrJayxWa4a vrW0yryUuasrCaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7ILAAAsz Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_convert_unwritten_extents_endio(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index a41cbb8c4475..b7f443f98e9d 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3745,12 +3745,11 @@ static struct ext4_ext_path *ext4_split_convert_ext= ents(handle_t *handle, allocated); } =20 -static int ext4_convert_unwritten_extents_endio(handle_t *handle, - struct inode *inode, - struct ext4_map_blocks *map, - struct ext4_ext_path **ppath) +static struct ext4_ext_path * +ext4_convert_unwritten_extents_endio(handle_t *handle, struct inode *inode, + struct ext4_map_blocks *map, + struct ext4_ext_path *path) { - struct ext4_ext_path *path =3D *ppath; struct ext4_extent *ex; ext4_lblk_t ee_block; unsigned int ee_len; @@ -3780,24 +3779,19 @@ static int ext4_convert_unwritten_extents_endio(han= dle_t *handle, #endif path =3D ext4_split_convert_extents(handle, inode, map, path, EXT4_GET_BLOCKS_CONVERT, NULL); - if (IS_ERR(path)) { - *ppath =3D NULL; - return PTR_ERR(path); - } + if (IS_ERR(path)) + return path; =20 path =3D ext4_find_extent(inode, map->m_lblk, path, 0); - if (IS_ERR(path)) { - *ppath =3D NULL; - return PTR_ERR(path); - } - *ppath =3D path; + if (IS_ERR(path)) + return path; depth =3D ext_depth(inode); ex =3D path[depth].p_ext; } =20 err =3D ext4_ext_get_access(handle, inode, path + depth); if (err) - goto out; + goto errout; /* first mark the extent as initialized */ ext4_ext_mark_initialized(ex); =20 @@ -3808,9 +3802,15 @@ static int ext4_convert_unwritten_extents_endio(hand= le_t *handle, =20 /* Mark modified extent as dirty */ err =3D ext4_ext_dirty(handle, inode, path + path->p_depth); -out: + if (err) + goto errout; + ext4_ext_show_leaf(inode, path); - return err; + return path; + +errout: + ext4_free_ext_path(path); + return ERR_PTR(err); } =20 static int @@ -3938,10 +3938,13 @@ ext4_ext_handle_unwritten_extents(handle_t *handle,= struct inode *inode, } /* IO end_io complete, convert the filled extent to written */ if (flags & EXT4_GET_BLOCKS_CONVERT) { - err =3D ext4_convert_unwritten_extents_endio(handle, inode, map, - ppath); - if (err < 0) + *ppath =3D ext4_convert_unwritten_extents_endio(handle, inode, + map, *ppath); + if (IS_ERR(*ppath)) { + err =3D PTR_ERR(*ppath); + *ppath =3D NULL; goto out2; + } ext4_update_inode_fsync_trans(handle, inode, 1); goto map_out; } --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE40C3FB30; Wed, 10 Jul 2024 04:09:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; cv=none; b=am2ULmB+BAeERVYmbdNbKRR23OkIga749ENhP+fpddy+EQYnUkFW9c5s+zaoD9q4GyLVVNJiLbDLgBZ8WjUR8nDxgWj7tlaS9wAvvNfk88PtT290FuwIJfEidKDszF2Dx6lLGdSJmzoBYpTCR27o7cAO9tA0W8wC3nAd7b3xl/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584556; c=relaxed/simple; bh=Qe4R0rUsyD3DqkTGK/TO2/kfo4Y0VPL+rim4hueril4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fdqAm9cZcJ+JF7KxuecDexpkoF9dmHIY2oEziKP2UmJKv9uIhQiw67je+vYLhdNvAX4ClndPNp6V2kplkxwzXtTK8Yx9wIZ/xrJ3QVifFXKaddTsYcrsgHyMItOur2JAM9EXAajZMGQmURC7u3HUtKMU+xLeqplxsesJOEWKbLY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrB5yxxz4f3mHW; Wed, 10 Jul 2024 12:08:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id AB12B1A0189; Wed, 10 Jul 2024 12:09:11 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S21; Wed, 10 Jul 2024 12:09:11 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 17/20] ext4: get rid of ppath in ext4_ext_convert_to_initialized() Date: Wed, 10 Jul 2024 12:06:51 +0800 Message-Id: <20240710040654.1714672-18-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S21 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar47uF43try8ZFWxurykKrg_yoWxZrW8pF yYvrn8Grn0g3sFgFZ7ta1UZr1293W5CFyUCrW3KryrZas2qr1fWa4rta4FqFWrtFW8Z3Wr tFW8Ar18GwnxAaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHoQAEsL Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_ext_convert_to_initialized(), the following is done here: * Free the extents path when an error is encountered. * Its caller needs to update ppath if it uses ppath. * The 'allocated' is changed from passing a value to passing an address. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 73 +++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index b7f443f98e9d..59e80926fe3a 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3437,13 +3437,11 @@ static struct ext4_ext_path *ext4_split_extent(hand= le_t *handle, * that are allocated and initialized. * It is guaranteed to be >=3D map->m_len. */ -static int ext4_ext_convert_to_initialized(handle_t *handle, - struct inode *inode, - struct ext4_map_blocks *map, - struct ext4_ext_path **ppath, - int flags) +static struct ext4_ext_path * +ext4_ext_convert_to_initialized(handle_t *handle, struct inode *inode, + struct ext4_map_blocks *map, struct ext4_ext_path *path, + int flags, unsigned int *allocated) { - struct ext4_ext_path *path =3D *ppath; struct ext4_sb_info *sbi; struct ext4_extent_header *eh; struct ext4_map_blocks split_map; @@ -3453,7 +3451,6 @@ static int ext4_ext_convert_to_initialized(handle_t *= handle, unsigned int ee_len, depth, map_len =3D map->m_len; int err =3D 0; int split_flag =3D EXT4_EXT_DATA_VALID2; - int allocated =3D 0; unsigned int max_zeroout =3D 0; =20 ext_debug(inode, "logical block %llu, max_blocks %u\n", @@ -3494,6 +3491,7 @@ static int ext4_ext_convert_to_initialized(handle_t *= handle, * - L2: we only attempt to merge with an extent stored in the * same extent tree node. */ + *allocated =3D 0; if ((map->m_lblk =3D=3D ee_block) && /* See if we can merge left */ (map_len < ee_len) && /*L1*/ @@ -3523,7 +3521,7 @@ static int ext4_ext_convert_to_initialized(handle_t *= handle, (prev_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ err =3D ext4_ext_get_access(handle, inode, path + depth); if (err) - goto out; + goto errout; =20 trace_ext4_ext_convert_to_initialized_fastpath(inode, map, ex, abut_ex); @@ -3538,7 +3536,7 @@ static int ext4_ext_convert_to_initialized(handle_t *= handle, abut_ex->ee_len =3D cpu_to_le16(prev_len + map_len); =20 /* Result: number of initialized blocks past m_lblk */ - allocated =3D map_len; + *allocated =3D map_len; } } else if (((map->m_lblk + map_len) =3D=3D (ee_block + ee_len)) && (map_len < ee_len) && /*L1*/ @@ -3569,7 +3567,7 @@ static int ext4_ext_convert_to_initialized(handle_t *= handle, (next_len < (EXT_INIT_MAX_LEN - map_len))) { /*C4*/ err =3D ext4_ext_get_access(handle, inode, path + depth); if (err) - goto out; + goto errout; =20 trace_ext4_ext_convert_to_initialized_fastpath(inode, map, ex, abut_ex); @@ -3584,18 +3582,20 @@ static int ext4_ext_convert_to_initialized(handle_t= *handle, abut_ex->ee_len =3D cpu_to_le16(next_len + map_len); =20 /* Result: number of initialized blocks past m_lblk */ - allocated =3D map_len; + *allocated =3D map_len; } } - if (allocated) { + if (*allocated) { /* Mark the block containing both extents as dirty */ err =3D ext4_ext_dirty(handle, inode, path + depth); =20 /* Update path to point to the right extent */ path[depth].p_ext =3D abut_ex; + if (err) + goto errout; goto out; } else - allocated =3D ee_len - (map->m_lblk - ee_block); + *allocated =3D ee_len - (map->m_lblk - ee_block); =20 WARN_ON(map->m_lblk < ee_block); /* @@ -3622,21 +3622,21 @@ static int ext4_ext_convert_to_initialized(handle_t= *handle, split_map.m_lblk =3D map->m_lblk; split_map.m_len =3D map->m_len; =20 - if (max_zeroout && (allocated > split_map.m_len)) { - if (allocated <=3D max_zeroout) { + if (max_zeroout && (*allocated > split_map.m_len)) { + if (*allocated <=3D max_zeroout) { /* case 3 or 5 */ zero_ex1.ee_block =3D cpu_to_le32(split_map.m_lblk + split_map.m_len); zero_ex1.ee_len =3D - cpu_to_le16(allocated - split_map.m_len); + cpu_to_le16(*allocated - split_map.m_len); ext4_ext_store_pblock(&zero_ex1, ext4_ext_pblock(ex) + split_map.m_lblk + split_map.m_len - ee_block); err =3D ext4_ext_zeroout(inode, &zero_ex1); if (err) goto fallback; - split_map.m_len =3D allocated; + split_map.m_len =3D *allocated; } if (split_map.m_lblk - ee_block + split_map.m_len < max_zeroout) { @@ -3654,27 +3654,24 @@ static int ext4_ext_convert_to_initialized(handle_t= *handle, =20 split_map.m_len +=3D split_map.m_lblk - ee_block; split_map.m_lblk =3D ee_block; - allocated =3D map->m_len; + *allocated =3D map->m_len; } } =20 fallback: path =3D ext4_split_extent(handle, inode, path, &split_map, split_flag, flags, NULL); - if (IS_ERR(path)) { - err =3D PTR_ERR(path); - *ppath =3D NULL; - goto out; - } - err =3D 0; - *ppath =3D path; + if (IS_ERR(path)) + return path; out: /* If we have gotten a failure, don't zero out status tree */ - if (!err) { - ext4_zeroout_es(inode, &zero_ex1); - ext4_zeroout_es(inode, &zero_ex2); - } - return err ? err : allocated; + ext4_zeroout_es(inode, &zero_ex1); + ext4_zeroout_es(inode, &zero_ex2); + return path; + +errout: + ext4_free_ext_path(path); + return ERR_PTR(err); } =20 /* @@ -3896,7 +3893,6 @@ ext4_ext_handle_unwritten_extents(handle_t *handle, s= truct inode *inode, struct ext4_ext_path **ppath, int flags, unsigned int allocated, ext4_fsblk_t newblock) { - int ret =3D 0; int err =3D 0; =20 ext_debug(inode, "logical block %llu, max_blocks %u, flags 0x%x, allocate= d %u\n", @@ -3976,23 +3972,24 @@ ext4_ext_handle_unwritten_extents(handle_t *handle,= struct inode *inode, * For buffered writes, at writepage time, etc. Convert a * discovered unwritten extent to written. */ - ret =3D ext4_ext_convert_to_initialized(handle, inode, map, ppath, flags); - if (ret < 0) { - err =3D ret; + *ppath =3D ext4_ext_convert_to_initialized(handle, inode, map, *ppath, + flags, &allocated); + if (IS_ERR(*ppath)) { + err =3D PTR_ERR(*ppath); + *ppath =3D NULL; goto out2; } ext4_update_inode_fsync_trans(handle, inode, 1); /* - * shouldn't get a 0 return when converting an unwritten extent + * shouldn't get a 0 allocated when converting an unwritten extent * unless m_len is 0 (bug) or extent has been corrupted */ - if (unlikely(ret =3D=3D 0)) { - EXT4_ERROR_INODE(inode, "unexpected ret =3D=3D 0, m_len =3D %u", + if (unlikely(allocated =3D=3D 0)) { + EXT4_ERROR_INODE(inode, "unexpected allocated =3D=3D 0, m_len =3D %u", map->m_len); err =3D -EFSCORRUPTED; goto out2; } - allocated =3D ret; =20 out: map->m_flags |=3D EXT4_MAP_NEW; --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 051C47D08D; Wed, 10 Jul 2024 04:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584562; cv=none; b=sG6BY/+bmBzIdf1FE2/gF44JH88TcstNtwpVytDdBFI4nETW+GISwKlRRTDD66FHdrL/AJVhe1fCqZV24R2MPcN1TU+7GO0GFe5MHPcI4PdhXWbsK5hFNimqNT2kQq3Sjp+jJyVOMQxUJVwT9dO3FDE4ZROgwYitZkVsdPTPBfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584562; c=relaxed/simple; bh=qSwK7dWLEQrYcSdC7h9xdsXay8n3c++nf45cu77g5rE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eh/D3QGIf4yM5xaNSPAdQDV7Kd94vaS/zLnnH8+5sAAR2khWw8EcysGOQJk7SvggUzEjoIL/X0c7XY9a1ycjUVwWpCTsMJQLpIDn9hKQ5PtxfnszG8JupAWyZvnKTeh1cj+JZyrRquzDNKmtYQMvQU+BbhfTQBXXNWxZOwxBjY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrJ3LpTz4f3kp4; Wed, 10 Jul 2024 12:09:04 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 1CAEC1A016E; Wed, 10 Jul 2024 12:09:12 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S22; Wed, 10 Jul 2024 12:09:11 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 18/20] ext4: get rid of ppath in ext4_ext_handle_unwritten_extents() Date: Wed, 10 Jul 2024 12:06:52 +0800 Message-Id: <20240710040654.1714672-19-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S22 X-Coremail-Antispam: 1UD129KBjvJXoW3Ar45Xw4UAF1UJrW5Gw47CFg_yoW7AF1rpF WayF15Kr4Yg3y2grWv9a1Uur1aka1rGay7CrWIgry5ua42qF1Sga4rt3WFqFWrJFWxua43 XFW0yFyUAa43CaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHoQAGsJ Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in ext4_ext_handle_unwritten_extents(), the following is done here: * Free the extents path when an error is encountered. * The 'allocated' is changed from passing a value to passing an address. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 82 +++++++++++++++++++++-------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 59e80926fe3a..badadcd64e66 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3887,18 +3887,18 @@ convert_initialized_extent(handle_t *handle, struct= inode *inode, return 0; } =20 -static int +static struct ext4_ext_path * ext4_ext_handle_unwritten_extents(handle_t *handle, struct inode *inode, struct ext4_map_blocks *map, - struct ext4_ext_path **ppath, int flags, - unsigned int allocated, ext4_fsblk_t newblock) + struct ext4_ext_path *path, int flags, + unsigned int *allocated, ext4_fsblk_t newblock) { int err =3D 0; =20 ext_debug(inode, "logical block %llu, max_blocks %u, flags 0x%x, allocate= d %u\n", (unsigned long long)map->m_lblk, map->m_len, flags, - allocated); - ext4_ext_show_leaf(inode, *ppath); + *allocated); + ext4_ext_show_leaf(inode, path); =20 /* * When writing into unwritten space, we should not fail to @@ -3907,40 +3907,34 @@ ext4_ext_handle_unwritten_extents(handle_t *handle,= struct inode *inode, flags |=3D EXT4_GET_BLOCKS_METADATA_NOFAIL; =20 trace_ext4_ext_handle_unwritten_extents(inode, map, flags, - allocated, newblock); + *allocated, newblock); =20 /* get_block() before submitting IO, split the extent */ if (flags & EXT4_GET_BLOCKS_PRE_IO) { - *ppath =3D ext4_split_convert_extents(handle, inode, map, *ppath, - flags | EXT4_GET_BLOCKS_CONVERT, &allocated); - if (IS_ERR(*ppath)) { - err =3D PTR_ERR(*ppath); - *ppath =3D NULL; - goto out2; - } + path =3D ext4_split_convert_extents(handle, inode, map, path, + flags | EXT4_GET_BLOCKS_CONVERT, allocated); + if (IS_ERR(path)) + return path; /* * shouldn't get a 0 allocated when splitting an extent unless * m_len is 0 (bug) or extent has been corrupted */ - if (unlikely(allocated =3D=3D 0)) { + if (unlikely(*allocated =3D=3D 0)) { EXT4_ERROR_INODE(inode, "unexpected allocated =3D=3D 0, m_len =3D %u", map->m_len); err =3D -EFSCORRUPTED; - goto out2; + goto errout; } map->m_flags |=3D EXT4_MAP_UNWRITTEN; goto out; } /* IO end_io complete, convert the filled extent to written */ if (flags & EXT4_GET_BLOCKS_CONVERT) { - *ppath =3D ext4_convert_unwritten_extents_endio(handle, inode, - map, *ppath); - if (IS_ERR(*ppath)) { - err =3D PTR_ERR(*ppath); - *ppath =3D NULL; - goto out2; - } + path =3D ext4_convert_unwritten_extents_endio(handle, inode, + map, path); + if (IS_ERR(path)) + return path; ext4_update_inode_fsync_trans(handle, inode, 1); goto map_out; } @@ -3972,23 +3966,20 @@ ext4_ext_handle_unwritten_extents(handle_t *handle,= struct inode *inode, * For buffered writes, at writepage time, etc. Convert a * discovered unwritten extent to written. */ - *ppath =3D ext4_ext_convert_to_initialized(handle, inode, map, *ppath, - flags, &allocated); - if (IS_ERR(*ppath)) { - err =3D PTR_ERR(*ppath); - *ppath =3D NULL; - goto out2; - } + path =3D ext4_ext_convert_to_initialized(handle, inode, map, path, + flags, allocated); + if (IS_ERR(path)) + return path; ext4_update_inode_fsync_trans(handle, inode, 1); /* * shouldn't get a 0 allocated when converting an unwritten extent * unless m_len is 0 (bug) or extent has been corrupted */ - if (unlikely(allocated =3D=3D 0)) { + if (unlikely(*allocated =3D=3D 0)) { EXT4_ERROR_INODE(inode, "unexpected allocated =3D=3D 0, m_len =3D %u", map->m_len); err =3D -EFSCORRUPTED; - goto out2; + goto errout; } =20 out: @@ -3997,12 +3988,15 @@ ext4_ext_handle_unwritten_extents(handle_t *handle,= struct inode *inode, map->m_flags |=3D EXT4_MAP_MAPPED; out1: map->m_pblk =3D newblock; - if (allocated > map->m_len) - allocated =3D map->m_len; - map->m_len =3D allocated; - ext4_ext_show_leaf(inode, *ppath); -out2: - return err ? err : allocated; + if (*allocated > map->m_len) + *allocated =3D map->m_len; + map->m_len =3D *allocated; + ext4_ext_show_leaf(inode, path); + return path; + +errout: + ext4_free_ext_path(path); + return ERR_PTR(err); } =20 /* @@ -4199,7 +4193,7 @@ int ext4_ext_map_blocks(handle_t *handle, struct inod= e *inode, struct ext4_extent newex, *ex, ex2; struct ext4_sb_info *sbi =3D EXT4_SB(inode->i_sb); ext4_fsblk_t newblock =3D 0, pblk; - int err =3D 0, depth, ret; + int err =3D 0, depth; unsigned int allocated =3D 0, offset =3D 0; unsigned int allocated_clusters =3D 0; struct ext4_allocation_request ar; @@ -4273,13 +4267,11 @@ int ext4_ext_map_blocks(handle_t *handle, struct in= ode *inode, goto out; } =20 - ret =3D ext4_ext_handle_unwritten_extents( - handle, inode, map, &path, flags, - allocated, newblock); - if (ret < 0) - err =3D ret; - else - allocated =3D ret; + path =3D ext4_ext_handle_unwritten_extents( + handle, inode, map, path, flags, + &allocated, newblock); + if (IS_ERR(path)) + err =3D PTR_ERR(path); goto out; } } --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C4F3E84A57; Wed, 10 Jul 2024 04:09:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584562; cv=none; b=O78r2ztTTjzsFstkARxtQhZFJLz9/58ry2THaQZKoI45R1yOMi9MaHfv/nGv3kk2LtA6ek0M1XXNxAWNAZOZ4krD6TV5uZyIwXTnyuNdH3k6bQJn1UK2GSlsL3MfbE5uczHSd8y6yKF8h9Dlg8ajoLU6itFtEaf4c4w8DSp8Xig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584562; c=relaxed/simple; bh=8ZfGKLzMFIrhZZIh3wI01lMUhrgGrAIn2dIQ1DvX3mE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wdbv6L5Tn8k3GF/OZyiuLWGdgTAQN1xP3LUtV2nAJm1ZqrnUuAFy+PBzD30mYNV065nmU3kdJB6jiBUb+jWXVyyjUoTv7kATdzOBsYGq11DplzCQk5gtxXJhMbPBr+sTTpWk1k0hiTA1nnCvZg6vIObfEN3iVkaILgCYqCwmQSU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4WJkrD6Khvz4f3mJf; Wed, 10 Jul 2024 12:09:00 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 7D7091A0D24; Wed, 10 Jul 2024 12:09:12 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S23; Wed, 10 Jul 2024 12:09:12 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 19/20] ext4: get rid of ppath in convert_initialized_extent() Date: Wed, 10 Jul 2024 12:06:53 +0800 Message-Id: <20240710040654.1714672-20-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S23 X-Coremail-Antispam: 1UD129KBjvJXoWxAw4DKF45Wr43tF4fXryrZwb_yoW5ZFyUpF ySyr1rCr1Yg39FgrZ7Ja1UZryak3W5Gw4UCrWfG34Fk3WIvr1FgFy8t3WSyFWrtay8Wa4a vFW0yr1UC3W7CaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Gr0_Xr1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAQAABV1jkIPHoQAIsH Content-Type: text/plain; charset="utf-8" From: Baokun Li The use of path and ppath is now very confusing, so to make the code more readable, pass path between functions uniformly, and get rid of ppath. To get rid of the ppath in convert_initialized_extent(), the following is done here: * Free the extents path when an error is encountered. No functional changes. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index badadcd64e66..737432bb316e 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -3810,13 +3810,12 @@ ext4_convert_unwritten_extents_endio(handle_t *hand= le, struct inode *inode, return ERR_PTR(err); } =20 -static int +static struct ext4_ext_path * convert_initialized_extent(handle_t *handle, struct inode *inode, struct ext4_map_blocks *map, - struct ext4_ext_path **ppath, + struct ext4_ext_path *path, unsigned int *allocated) { - struct ext4_ext_path *path =3D *ppath; struct ext4_extent *ex; ext4_lblk_t ee_block; unsigned int ee_len; @@ -3841,29 +3840,25 @@ convert_initialized_extent(handle_t *handle, struct= inode *inode, if (ee_block !=3D map->m_lblk || ee_len > map->m_len) { path =3D ext4_split_convert_extents(handle, inode, map, path, EXT4_GET_BLOCKS_CONVERT_UNWRITTEN, NULL); - if (IS_ERR(path)) { - *ppath =3D NULL; - return PTR_ERR(path); - } + if (IS_ERR(path)) + return path; =20 path =3D ext4_find_extent(inode, map->m_lblk, path, 0); - if (IS_ERR(path)) { - *ppath =3D NULL; - return PTR_ERR(path); - } - *ppath =3D path; + if (IS_ERR(path)) + return path; depth =3D ext_depth(inode); ex =3D path[depth].p_ext; if (!ex) { EXT4_ERROR_INODE(inode, "unexpected hole at %lu", (unsigned long) map->m_lblk); - return -EFSCORRUPTED; + err =3D -EFSCORRUPTED; + goto errout; } } =20 err =3D ext4_ext_get_access(handle, inode, path + depth); if (err) - return err; + goto errout; /* first mark the extent as unwritten */ ext4_ext_mark_unwritten(ex); =20 @@ -3875,7 +3870,7 @@ convert_initialized_extent(handle_t *handle, struct i= node *inode, /* Mark modified extent as dirty */ err =3D ext4_ext_dirty(handle, inode, path + path->p_depth); if (err) - return err; + goto errout; ext4_ext_show_leaf(inode, path); =20 ext4_update_inode_fsync_trans(handle, inode, 1); @@ -3884,7 +3879,11 @@ convert_initialized_extent(handle_t *handle, struct = inode *inode, if (*allocated > map->m_len) *allocated =3D map->m_len; map->m_len =3D *allocated; - return 0; + return path; + +errout: + ext4_free_ext_path(path); + return ERR_PTR(err); } =20 static struct ext4_ext_path * @@ -4254,8 +4253,10 @@ int ext4_ext_map_blocks(handle_t *handle, struct ino= de *inode, */ if ((!ext4_ext_is_unwritten(ex)) && (flags & EXT4_GET_BLOCKS_CONVERT_UNWRITTEN)) { - err =3D convert_initialized_extent(handle, - inode, map, &path, &allocated); + path =3D convert_initialized_extent(handle, + inode, map, path, &allocated); + if (IS_ERR(path)) + err =3D PTR_ERR(path); goto out; } else if (!ext4_ext_is_unwritten(ex)) { map->m_flags |=3D EXT4_MAP_MAPPED; --=20 2.39.2 From nobody Wed Dec 17 13:51:49 2025 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E23997C6D5; Wed, 10 Jul 2024 04:09:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584561; cv=none; b=jB9m67xW8jLR8wZf5Dhsxq5ktTv+LWcgLfDNJZLfQCuLB1qE3KEvDvrH84AdF6ULwWh/reCQbwD/0Vlx1qcXNlYEVt+VwvxFAGcOIFRBtkGkbhIyfQLSK9FvppNMAMPZVlUi7hLMWWIw9Hp9mvfOW7azKEwYMOildDxsipJfA3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720584561; c=relaxed/simple; bh=ZCMKuBfPy9Wvd/tQ4dHG74hcjUltOrCTLBgAhdxf5v4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q7fdiACKuOmmCMTrFqztORJunucVEzu/9KDuW9gaFK1u9S1o0VMizzwolfk/jpUxocoDq0wMZ5pBXc4u14w+WkZcAUn/Y8I0VzUxSX+xG1hqbBYpQyS/9mTwbVMhKrw9T2aEBmPyweM73rG6VyfSSfK0NkLq9FlIQ8iVDUDyp6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4WJkrK2Ncyz4f3kpG; Wed, 10 Jul 2024 12:09:05 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id EDF301A01B9; Wed, 10 Jul 2024 12:09:12 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP2 (Coremail) with SMTP id Syh0CgCXAIZdCY5mkoy3Bg--.14986S24; Wed, 10 Jul 2024 12:09:12 +0800 (CST) From: libaokun@huaweicloud.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, linux-kernel@vger.kernel.org, yi.zhang@huawei.com, yangerkun@huawei.com, libaokun@huaweicloud.com, Baokun Li Subject: [PATCH 20/20] ext4: avoid unnecessary extent path frees and allocations Date: Wed, 10 Jul 2024 12:06:54 +0800 Message-Id: <20240710040654.1714672-21-libaokun@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240710040654.1714672-1-libaokun@huaweicloud.com> References: <20240710040654.1714672-1-libaokun@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: Syh0CgCXAIZdCY5mkoy3Bg--.14986S24 X-Coremail-Antispam: 1UD129KBjvJXoW3Xry7Jw15Xw1Dtr4fGw4UArb_yoW7AF48pF WayF1Ygr15XFsrCrWxKa17Zr13K3W8Gw48GryfW34v9asxXr1SgF17ta1ftFyrKFZ7WFWa qF18Kry8Gry7KFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUmY14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0x vEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIev Ja73UjIFyTuYvjfUYGYpUUUUU X-CM-SenderInfo: 5olet0hnxqqx5xdzvxpfor3voofrz/1tbiAgAABV1jkH7ILQABsz Content-Type: text/plain; charset="utf-8" From: Baokun Li The ext4_find_extent() can update the extent path so that it does not have to allocate and free the path repeatedly, thus reducing the consumption of memory allocation and freeing in the following functions: ext4_ext_clear_bb ext4_ext_replay_set_iblocks ext4_fc_replay_add_range ext4_fc_set_bitmaps_and_counters No functional changes. Note that ext4_find_extent() does not support error pointers, so in this case set path to NULL first. Signed-off-by: Baokun Li Reviewed-by: Jan Kara Reviewed-by: Ojaswin Mujoo Tested-by: Ojaswin Mujoo --- fs/ext4/extents.c | 51 +++++++++++++++++++------------------------ fs/ext4/fast_commit.c | 11 ++++++---- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 737432bb316e..5ff92cd50dc8 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -6068,12 +6068,9 @@ int ext4_ext_replay_set_iblocks(struct inode *inode) if (IS_ERR(path)) return PTR_ERR(path); ex =3D path[path->p_depth].p_ext; - if (!ex) { - ext4_free_ext_path(path); + if (!ex) goto out; - } end =3D le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex); - ext4_free_ext_path(path); =20 /* Count the number of data blocks */ cur =3D 0; @@ -6099,32 +6096,28 @@ int ext4_ext_replay_set_iblocks(struct inode *inode) ret =3D skip_hole(inode, &cur); if (ret < 0) goto out; - path =3D ext4_find_extent(inode, cur, NULL, 0); + path =3D ext4_find_extent(inode, cur, path, 0); if (IS_ERR(path)) goto out; numblks +=3D path->p_depth; - ext4_free_ext_path(path); while (cur < end) { - path =3D ext4_find_extent(inode, cur, NULL, 0); + path =3D ext4_find_extent(inode, cur, path, 0); if (IS_ERR(path)) break; ex =3D path[path->p_depth].p_ext; - if (!ex) { - ext4_free_ext_path(path); - return 0; - } + if (!ex) + goto cleanup; + cur =3D max(cur + 1, le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex)); ret =3D skip_hole(inode, &cur); - if (ret < 0) { - ext4_free_ext_path(path); + if (ret < 0) break; - } - path2 =3D ext4_find_extent(inode, cur, NULL, 0); - if (IS_ERR(path2)) { - ext4_free_ext_path(path); + + path2 =3D ext4_find_extent(inode, cur, path2, 0); + if (IS_ERR(path2)) break; - } + for (i =3D 0; i <=3D max(path->p_depth, path2->p_depth); i++) { cmp1 =3D cmp2 =3D 0; if (i <=3D path->p_depth) @@ -6136,13 +6129,14 @@ int ext4_ext_replay_set_iblocks(struct inode *inode) if (cmp1 !=3D cmp2 && cmp2 !=3D 0) numblks++; } - ext4_free_ext_path(path); - ext4_free_ext_path(path2); } =20 out: inode->i_blocks =3D numblks << (inode->i_sb->s_blocksize_bits - 9); ext4_mark_inode_dirty(NULL, inode); +cleanup: + ext4_free_ext_path(path); + ext4_free_ext_path(path2); return 0; } =20 @@ -6163,12 +6157,9 @@ int ext4_ext_clear_bb(struct inode *inode) if (IS_ERR(path)) return PTR_ERR(path); ex =3D path[path->p_depth].p_ext; - if (!ex) { - ext4_free_ext_path(path); - return 0; - } + if (!ex) + goto out; end =3D le32_to_cpu(ex->ee_block) + ext4_ext_get_actual_len(ex); - ext4_free_ext_path(path); =20 cur =3D 0; while (cur < end) { @@ -6178,16 +6169,16 @@ int ext4_ext_clear_bb(struct inode *inode) if (ret < 0) break; if (ret > 0) { - path =3D ext4_find_extent(inode, map.m_lblk, NULL, 0); - if (!IS_ERR_OR_NULL(path)) { + path =3D ext4_find_extent(inode, map.m_lblk, path, 0); + if (!IS_ERR(path)) { for (j =3D 0; j < path->p_depth; j++) { - ext4_mb_mark_bb(inode->i_sb, path[j].p_block, 1, false); ext4_fc_record_regions(inode->i_sb, inode->i_ino, 0, path[j].p_block, 1, 1); } - ext4_free_ext_path(path); + } else { + path =3D NULL; } ext4_mb_mark_bb(inode->i_sb, map.m_pblk, map.m_len, false); ext4_fc_record_regions(inode->i_sb, inode->i_ino, @@ -6196,5 +6187,7 @@ int ext4_ext_clear_bb(struct inode *inode) cur =3D cur + map.m_len; } =20 +out: + ext4_free_ext_path(path); return 0; } diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c index 1dee40477727..1426d595fab7 100644 --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1766,7 +1766,7 @@ static int ext4_fc_replay_add_range(struct super_bloc= k *sb, =20 if (ret =3D=3D 0) { /* Range is not mapped */ - path =3D ext4_find_extent(inode, cur, NULL, 0); + path =3D ext4_find_extent(inode, cur, path, 0); if (IS_ERR(path)) goto out; memset(&newex, 0, sizeof(newex)); @@ -1782,7 +1782,6 @@ static int ext4_fc_replay_add_range(struct super_bloc= k *sb, up_write((&EXT4_I(inode)->i_data_sem)); if (IS_ERR(path)) goto out; - ext4_free_ext_path(path); goto next; } =20 @@ -1830,6 +1829,7 @@ static int ext4_fc_replay_add_range(struct super_bloc= k *sb, ext4_ext_replay_shrink_inode(inode, i_size_read(inode) >> sb->s_blocksize_bits); out: + ext4_free_ext_path(path); iput(inode); return 0; } @@ -1930,12 +1930,13 @@ static void ext4_fc_set_bitmaps_and_counters(struct= super_block *sb) break; =20 if (ret > 0) { - path =3D ext4_find_extent(inode, map.m_lblk, NULL, 0); + path =3D ext4_find_extent(inode, map.m_lblk, path, 0); if (!IS_ERR(path)) { for (j =3D 0; j < path->p_depth; j++) ext4_mb_mark_bb(inode->i_sb, path[j].p_block, 1, true); - ext4_free_ext_path(path); + } else { + path =3D NULL; } cur +=3D ret; ext4_mb_mark_bb(inode->i_sb, map.m_pblk, @@ -1946,6 +1947,8 @@ static void ext4_fc_set_bitmaps_and_counters(struct s= uper_block *sb) } iput(inode); } + + ext4_free_ext_path(path); } =20 /* --=20 2.39.2