Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3186718rwd; Sat, 3 Jun 2023 00:03:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4G1bqiRmumH222FG2Vueb2pPYkLAysnh1z9w5vbMsrcbyDrlOsTA/2kAEaoqkBybpqFVH7 X-Received: by 2002:aca:650c:0:b0:398:dd2d:b114 with SMTP id m12-20020aca650c000000b00398dd2db114mr2348347oim.58.1685775793015; Sat, 03 Jun 2023 00:03:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685775792; cv=none; d=google.com; s=arc-20160816; b=JhPnRIy2ajcXe9snhY4JhNqx9QLeYS+LvEq5Od1x26mUw8UdSG0asQrWYSklCjfiq7 PzJpXgBaanFHtBChclCSfcvDN8CAckAfDaR9HPQkYaRdRNa3jC7bWMvmOC1Kivj/u56l ho6w+EupoQh0Ch0PfTNCNIgW2aZOuC4OP+4Xju7kEo/wW4MM8chTB9xceAHPvq6lDA+t pd4N0JUZk828N9Q6Ar5wdrjmGb69hAAngaWPW42BTQbBvJy3A+AZoe10GRGlzRXNw6pa YnRYrO0p6rbHts4PldkNuRx72QripWfwiwN5533fryjQxUPxDOeUwylgXq5jfTd6Zd6z 6D1g== 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=jMREmVmxk9YNvMjcWocgo4HekvnFGntyrMFCr+gippw=; b=cOvBoxYd02WkoPhS6hiY/WRxa/N8Wn5FKijQX+O57fIUhDik9oyuM4hHeC4ug0Xg33 R8Hons4BhuLUa3tzTmJK1L8lXsziJWcFdOcgDYuFKLU4tjZ8vNaMmrv/TjwmRGA1zvot TdoNNoAcZaFngR1JByTFUNV5MrjMzz+1rmvTxTZ/OtMFWPcGyaGwH8fHw+Zss7xh9yfS Roqqb4xl0Q0/4kBoLR/5G8/y+bCX4V/bANLWzixu9nDgXFxRj5Z5+irtgb/yF/qV/JB2 pcTJw1/wlMTnETRv+SN/aNwqt2v78XF5MIm59D+DNuN+yTt79j8L++FzZGAfHvTTRRG0 JyeA== 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 k14-20020a170902c40e00b001b1cdef2654si1591271plk.645.2023.06.03.00.03.00; Sat, 03 Jun 2023 00:03:12 -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 S233554AbjFCHCZ (ORCPT + 99 others); Sat, 3 Jun 2023 03:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232349AbjFCHCL (ORCPT ); Sat, 3 Jun 2023 03:02:11 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 72886E58; Sat, 3 Jun 2023 00:02:10 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QY9lt1zKNz4f3lXr; Sat, 3 Jun 2023 15:02:02 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgCHOKxk5Xpk+MxPKw--.30174S10; Sat, 03 Jun 2023 15:02:03 +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 v4 08/19] ext4: get block from bh before pass it to ext4_free_blocks_simple in ext4_free_blocks Date: Sat, 3 Jun 2023 23:03:16 +0800 Message-Id: <20230603150327.3596033-9-shikemeng@huaweicloud.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20230603150327.3596033-1-shikemeng@huaweicloud.com> References: <20230603150327.3596033-1-shikemeng@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgCHOKxk5Xpk+MxPKw--.30174S10 X-Coremail-Antispam: 1UD129KBjvJXoW7JF48Cr4UZw1DJw1xJFy8Grg_yoW8JF48pw srCF1rGr1kWr1IgF4ftw15Xwsa9w48G3WUWFyfWw18Xry3Z34Sy3WDtF1rWF1UtrZav3ZF qFn0grW5Cw4UuaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6x 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=0.0 required=5.0 tests=BAYES_00,DATE_IN_FUTURE_06_12, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 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 Reviewed-by: Ojaswin Mujoo --- 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 bcc9622daa4a..dadda9e8cf29 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -6368,12 +6368,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); @@ -6381,6 +6375,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