Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3425051rwe; Sun, 16 Apr 2023 20:05:27 -0700 (PDT) X-Google-Smtp-Source: AKy350Y7eSDoSCFqP90rplRI71c5NG9zmIo7ILQBkqZDe1mOyjvENJ7QzJZKFVe13if1H4VE/uXG X-Received: by 2002:a05:6a00:a84:b0:63b:6933:a328 with SMTP id b4-20020a056a000a8400b0063b6933a328mr16999791pfl.28.1681700727273; Sun, 16 Apr 2023 20:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681700727; cv=none; d=google.com; s=arc-20160816; b=r3SWER1OBymTXK1Xj0NSQbhSfkm/cvqCXXwLu8sC55Wua/VMRb81HNLNeny4q+lJ1t FIM4Rq3lYtmKDcGsrkzysvBYY3vqEeGZZbvsNwKAhYBUfLO/AT+vHkmUT2yADZbsnUQj o3Pcset063jT3h81kKUR468FBAqOWgKJ00g5cnEgZxasVVupcfMqXDTLsUbIiQdl9X7q nSQ1VEd/VElaWs+ecxXHQkjAEC7g4wePHm5ikgf7UEmQ9K+Iuqtt++YfMKKCg+9v2+h1 QSM9mMIy5K2RvmF1Tzs3L7uLuk26T8Ir/Td1nv9Ej8+xppmWGhzGWjQh9ZWiel4ZqW/L sb5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Yx+L8uyFqV/zBzJjTjdKJr6DJqToRyOIqi/PgcRBsao=; b=Qo3hO9EwESCAM/FBPQKUVXJLGdDn6f1xA/dpuFbSVnf1XLtcUJprevhUOSeo3K1UfZ uHt5ltS2vp3b0oeXrzUiWRqjK0ZsYI2tSdCMBsWW8Sps0AZi+wEUd0H2ab6PIqpwhujA +q+pkGah7JIUCsCUInU87MjOakJ+eJ7ucQHvA8c/r13UtGMUVihXvhU405jNqZpJ0OpG 7dIIrmld7meZ9Ogd3LhwChp1BMZ/CExsxl9xfAyVzaz2wM+nGRANtx02is1Rs9Kpl/5D M16hxrjqA/fyWzX2/OyrObYlMbDruxoHZoZJYBe1Xp3U9docpE3TOHfam5SkmZ/p0DLr fceQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020aa79514000000b0063b8935bcbasi3357542pfp.310.2023.04.16.20.05.15; Sun, 16 Apr 2023 20:05:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230177AbjDQDE3 (ORCPT + 99 others); Sun, 16 Apr 2023 23:04:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229604AbjDQDEC (ORCPT ); Sun, 16 Apr 2023 23:04:02 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69964270C; Sun, 16 Apr 2023 20:04:01 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Q0Bhq3xLDz4f47kR; Mon, 17 Apr 2023 11:03:55 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP1 (Coremail) with SMTP id cCh0CgAXODIXtzxkfzJgHA--.17426S10; Mon, 17 Apr 2023 11:03:56 +0800 (CST) From: Kemeng Shi To: tytso@mit.edu, adilger.kernel@dilger.ca, ojaswin@linux.ibm.com Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, shikemeng@huaweicloud.com Subject: [PATCH v3 08/19] ext4: get block from bh before pass it to ext4_free_blocks_simple in ext4_free_blocks Date: Mon, 17 Apr 2023 19:06:06 +0800 Message-Id: <20230417110617.2664129-9-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230417110617.2664129-1-shikemeng@huaweicloud.com> References: <20230417110617.2664129-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: cCh0CgAXODIXtzxkfzJgHA--.17426S10 X-Coremail-Antispam: 1UD129KBjvJXoW7JF48Cr4UZw1DJw1xJFy8Grg_yoW8Jr17pr srCFyrGr1kWwn2gF4fJr15Jwsa9w48G3WUWFWfuw18Xry7Z34Sy3WqyF15WF1UtrZav3ZF qFn0grW5Cw4UuaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_tr0E3s1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJV W8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjTRKfOw UUUUU X-CM-SenderInfo: 5vklyvpphqwq5kxd4v5lfo033gof0z/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=2.5 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, KHOP_HELO_FCRDNS,MAY_BE_FORGED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org ext4_free_blocks will retrieve block from bh if block parameter is zero. Retrieve block before ext4_free_blocks_simple to avoid potentially passing wrong block to ext4_free_blocks_simple. Signed-off-by: Kemeng Shi --- fs/ext4/mballoc.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index e980513c7a14..f37e921c11e5 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -6310,12 +6310,6 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, sbi = EXT4_SB(sb); - if (sbi->s_mount_state & EXT4_FC_REPLAY) { - ext4_free_blocks_simple(inode, block, count); - return; - } - - might_sleep(); if (bh) { if (block) BUG_ON(block != bh->b_blocknr); @@ -6323,6 +6317,13 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, block = bh->b_blocknr; } + if (sbi->s_mount_state & EXT4_FC_REPLAY) { + ext4_free_blocks_simple(inode, block, count); + return; + } + + might_sleep(); + if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) && !ext4_inode_block_valid(inode, block, count)) { ext4_error(sb, "Freeing blocks not in datazone - " -- 2.30.0