Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3186792rwd; Sat, 3 Jun 2023 00:03:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4303LNECW97ZDeMBUMRXBqJk3IrnhOJ7bFq1T8TDMKzqsoSxx9lnUAZV4ejDgPd7jiEIxY X-Received: by 2002:a05:6a00:1821:b0:655:ebb0:196a with SMTP id y33-20020a056a00182100b00655ebb0196amr156373pfa.25.1685775798218; Sat, 03 Jun 2023 00:03:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685775798; cv=none; d=google.com; s=arc-20160816; b=BP/SM/QRvz4tty4Y+IdVQqSKMyMASPD4fjSsDz72n1Dkx/JLgioln+3pxrv7yeVgsm b49JU2Vyi2TgjKbTZkfblUHH6Hilqj516kIWzpHqdtPjDLYCzvwN4x3YG0Huw5wx5Izh nlRONgr8IzxICfE9Mo9pQ9r/6emvaZcXatpCLgpLB1yhNbjjR/WCp4auK1iD5zDgJfPk LB4nVltBxzhpFnIJqUU796VKMFBKio0Q+gtfZnDZjJgZvBs615GHeRj6xyRIyLoePAsP 3m1RoNXXDaf7IQDL1/Yp4jTUnbE29HndHUOs0Jm1tOW2JDypisssSUTWxWqmcBt+QUAd ryHQ== 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=i0oposOAjaSYO+egG4+xY53Q9erMj6uLIFS+mdlb+Zg=; b=iLC1kYI123FEXSvVvAu97Rg42bLuGywsW87FD5y4D4OK1g4pdjm8ZrUJ3kTz8mpq5X MCj5JLJGyf5LrpPgdoYzcL/GC0YdRQCpQoSJsPFW0p42Dr3jmg5oAHlr0HulZgnkonEE zJ0MX9aB5mdgC9F0v2MEQ9GV4NFwa1oVcAlNfdz9O2zJzSZxmoyMP0UWLs73hls6njen F7HEjK13mU0aKNiz2PsW9I2dczQat69rLUmryEEn10HzOs2ed11LLdAJy9VYLB4VcH/W +JfS/0x8nbliL6u87wfsbr9svC80DWrHgo76PW3ddUXw3xzvxrmD/jnPbmlwk3pOPgvo sVkA== 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 f13-20020a65550d000000b0053ef3c50929si2305286pgr.508.2023.06.03.00.03.05; Sat, 03 Jun 2023 00:03:18 -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 S234343AbjFCHCe (ORCPT + 99 others); Sat, 3 Jun 2023 03:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232738AbjFCHCO (ORCPT ); Sat, 3 Jun 2023 03:02:14 -0400 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC283E5D; Sat, 3 Jun 2023 00:02:12 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.153]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4QY9lv0mZSz4f3nqP; Sat, 3 Jun 2023 15:02:03 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgCHOKxk5Xpk+MxPKw--.30174S15; Sat, 03 Jun 2023 15:02:04 +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 13/19] ext4: call ext4_mb_mark_group_bb in ext4_free_blocks_simple Date: Sat, 3 Jun 2023 23:03:21 +0800 Message-Id: <20230603150327.3596033-14-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--.30174S15 X-Coremail-Antispam: 1UD129KBjvJXoWxXrykJF4fGF1DJFWxZFyUtrb_yoW5JFWDpr ZIyr17Gr1fGr1Dur4xJ34jq3W8Kw18u3WUGryfC3s5CFW3Ar9YgFWxKF1Fvas0yFZrZ3Zx ZF1Y93yUur1fW37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPF14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2jI8I6cxK62vIxIIY0VWUZVW8XwA2048vs2IY02 0E87I2jVAFwI0_JF0E3s1l82xGYIkIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0 rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6x IIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xv wVC2z280aVCY1x0267AKxVW0oVCq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFc xC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_ Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2 IErcIFxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Cr0_Gr1UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8JV WxJwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjTRKfOw 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 call ext4_mb_mark_group_bb in ext4_free_blocks_simple to: 1. remove repeat code 2. pair update of free_clusters in ext4_mb_new_blocks_simple. 3. add missing ext4_lock_group/ext4_unlock_group protection. Signed-off-by: Kemeng Shi Reviewed-by: Ojaswin Mujoo --- fs/ext4/mballoc.c | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 685dcc17bf7c..dae4533411f7 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -3798,6 +3798,8 @@ ext4_mb_mark_group_bb(struct ext4_mark_context *mc, ext4_group_t group, ext4_lock_group(sb, group); if (ext4_has_group_desc_csum(sb) && (gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT))) { + WARN_ON(mc->state == 0); + gdp->bg_flags &= cpu_to_le16(~EXT4_BG_BLOCK_UNINIT); ext4_free_group_clusters_set(sb, gdp, ext4_free_clusters_after_init(sb, group, gdp)); @@ -6120,43 +6122,16 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b, static void ext4_free_blocks_simple(struct inode *inode, ext4_fsblk_t block, unsigned long count) { - struct buffer_head *bitmap_bh; + struct ext4_mark_context mc = { + .sb = inode->i_sb, + .state = 0, + }; struct super_block *sb = inode->i_sb; - struct ext4_group_desc *gdp; - struct buffer_head *gdp_bh; ext4_group_t group; ext4_grpblk_t blkoff; - int already_freed = 0, err, i; ext4_get_group_no_and_offset(sb, block, &group, &blkoff); - bitmap_bh = ext4_read_block_bitmap(sb, group); - if (IS_ERR(bitmap_bh)) { - pr_warn("Failed to read block bitmap\n"); - return; - } - gdp = ext4_get_group_desc(sb, group, &gdp_bh); - if (!gdp) - goto err_out; - - for (i = 0; i < count; i++) { - if (!mb_test_bit(blkoff + i, bitmap_bh->b_data)) - already_freed++; - } - mb_clear_bits(bitmap_bh->b_data, blkoff, count); - err = ext4_handle_dirty_metadata(NULL, NULL, bitmap_bh); - if (err) - goto err_out; - ext4_free_group_clusters_set( - sb, gdp, ext4_free_group_clusters(sb, gdp) + - count - already_freed); - ext4_block_bitmap_csum_set(sb, gdp, bitmap_bh); - ext4_group_desc_csum_set(sb, group, gdp); - ext4_handle_dirty_metadata(NULL, NULL, gdp_bh); - sync_dirty_buffer(bitmap_bh); - sync_dirty_buffer(gdp_bh); - -err_out: - brelse(bitmap_bh); + ext4_mb_mark_group_bb(&mc, group, blkoff, count); } /** -- 2.30.0