Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1749464pxb; Wed, 9 Feb 2022 03:48:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJxdwIfpniA1eFBzgyxtvYfBhk/4cVCObKNSQ24o8rwOnBxpBdzwh/BctxcIXpRAlqHbEP5L X-Received: by 2002:a17:902:bc82:: with SMTP id bb2mr1732969plb.21.1644407293637; Wed, 09 Feb 2022 03:48:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644407293; cv=none; d=google.com; s=arc-20160816; b=CULkWn2fhxvue5WkHQxIwWvovFAoTNPSn8apE5lxlZvzA3ERwGHsxFWIYaHUkJAs1T GYY7gmVs4XiHHItcNuiRQJztgCJlhFgVsJ0dbWDZcq+llZ1tgLH4gMVznBw75w1S+cWP yGmQhO1Mn4/U3diiFNEGOTljM7jk8qO6MM5BSh5b5z5mEzDhoXRZKUPrMUawQjnAUGcY PoRUIkCbuV53ANkbKyhmQFvNPGlLPjUE93obRN5kWXBkBeyOMlFe608gCsZQVChFwzx0 rTVDREocygGHbDOVCrtHq7taZadQuxnQUSEcDJTN0Uull2KF4Wx5ZciN0UNzO/pC80CG wB7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=P3xiAB7Mo6lVoFRC3DJUrL8QW3+mxBSV67aGhGzwkyY=; b=la93XargtmvZ2ZoXlNWCrJh+iZ+4zy3EFXt8oUE13qHbTeJgnhe95ZLeYHTPsktBM0 16Hblse6atrKv2kJFJmRLHvZb0v+mfZOIE0I+A6nvU8KKNlma/68jYm3t1jV4SXf3Cro mdFT9FkEWs7WIEQRptvUcaQxW68NeZz6/WFgpFPY3sdaU4M8e8aeEJ8k+MsVoS6I9+MD Tq8C8Tee0rDHAbwlNjQFj6REPYOrQLnlvmvCLR17lOV2aSETqVwOJM9x+3QR/BB+veqy LnPUQE/dvD1iejkGuwq5sb7OeYUh+ulwSaq9ZDSNKHoaacc1O1NM3kOlkA/LIlvGitu3 zYag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=vQP2O2eT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="/7HjnIJO"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g187si6996793pgc.830.2022.02.09.03.48.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 03:48:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=vQP2O2eT; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b="/7HjnIJO"; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5A9B3E0E08AE; Wed, 9 Feb 2022 01:58:56 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230508AbiBGPjY (ORCPT + 99 others); Mon, 7 Feb 2022 10:39:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242907AbiBGP2Y (ORCPT ); Mon, 7 Feb 2022 10:28:24 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A506C0401C1; Mon, 7 Feb 2022 07:28:23 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id BCB4E1F380; Mon, 7 Feb 2022 15:28:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1644247701; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=P3xiAB7Mo6lVoFRC3DJUrL8QW3+mxBSV67aGhGzwkyY=; b=vQP2O2eTLzu3UbS+z24nWi7MMPHUkMgvOvTZRec7PK817zQ0tAwpSkkzeIH+Qy6phq7ZMb ef+g4TtwijF4R/WQTtueBPf3w1uAPgPmSquPJp3Hf+gttkhQDWTjNUBlWGOYoSp15jGXmQ cBS3918P+0zQJR8VRsZX9Z5MVPQaJAA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1644247701; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=P3xiAB7Mo6lVoFRC3DJUrL8QW3+mxBSV67aGhGzwkyY=; b=/7HjnIJOGGflB/LKU/980wAt0HQ0a+1sRa3HVvqSpJ8xMReuPfAGI1K5CKoZOQo3WzbFUD w3f5lC1kmv/406BQ== Received: from quack3.suse.cz (unknown [10.100.224.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id AD468A3B81; Mon, 7 Feb 2022 15:28:21 +0000 (UTC) Received: by quack3.suse.cz (Postfix, from userid 1000) id EFC58A05BC; Mon, 7 Feb 2022 16:28:18 +0100 (CET) Date: Mon, 7 Feb 2022 16:28:18 +0100 From: Jan Kara To: Ritesh Harjani Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, Theodore Ts'o , Jan Kara , Harshad Shirwadkar Subject: Re: [PATCHv1 1/9] ext4: Correct cluster len and clusters changed accounting in ext4_mb_mark_bb Message-ID: <20220207152818.tsrqwe2hebyvr25e@quack3.lan> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Sat 05-02-22 19:39:50, Ritesh Harjani wrote: > ext4_mb_mark_bb() currently wrongly calculates cluster len (clen) and > flex_group->free_clusters. This patch fixes that. > > Identified based on code review of ext4_mb_mark_bb() function. > > Signed-off-by: Ritesh Harjani Looks good. Feel free to add: Reviewed-by: Jan Kara Honza > --- > fs/ext4/mballoc.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c > index c781974df9d0..2f117ce3bb73 100644 > --- a/fs/ext4/mballoc.c > +++ b/fs/ext4/mballoc.c > @@ -3899,10 +3899,11 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, > struct ext4_sb_info *sbi = EXT4_SB(sb); > ext4_group_t group; > ext4_grpblk_t blkoff; > - int i, clen, err; > + int i, err; > int already; > + unsigned int clen, clen_changed; > > - clen = EXT4_B2C(sbi, len); > + clen = EXT4_NUM_B2C(sbi, len); > > ext4_get_group_no_and_offset(sb, block, &group, &blkoff); > bitmap_bh = ext4_read_block_bitmap(sb, group); > @@ -3923,6 +3924,7 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, > if (!mb_test_bit(blkoff + i, bitmap_bh->b_data) == !state) > already++; > > + clen_changed = clen - already; > if (state) > ext4_set_bits(bitmap_bh->b_data, blkoff, clen); > else > @@ -3935,9 +3937,9 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, > group, gdp)); > } > if (state) > - clen = ext4_free_group_clusters(sb, gdp) - clen + already; > + clen = ext4_free_group_clusters(sb, gdp) - clen_changed; > else > - clen = ext4_free_group_clusters(sb, gdp) + clen - already; > + clen = ext4_free_group_clusters(sb, gdp) + clen_changed; > > ext4_free_group_clusters_set(sb, gdp, clen); > ext4_block_bitmap_csum_set(sb, group, gdp, bitmap_bh); > @@ -3947,10 +3949,13 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block, > > if (sbi->s_log_groups_per_flex) { > ext4_group_t flex_group = ext4_flex_group(sbi, group); > + struct flex_groups *fg = sbi_array_rcu_deref(sbi, > + s_flex_groups, flex_group); > > - atomic64_sub(len, > - &sbi_array_rcu_deref(sbi, s_flex_groups, > - flex_group)->free_clusters); > + if (state) > + atomic64_sub(clen_changed, &fg->free_clusters); > + else > + atomic64_add(clen_changed, &fg->free_clusters); > } > > err = ext4_handle_dirty_metadata(NULL, NULL, bitmap_bh); > -- > 2.31.1 > -- Jan Kara SUSE Labs, CR