Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp740406ybx; Wed, 6 Nov 2019 07:44:40 -0800 (PST) X-Google-Smtp-Source: APXvYqxjmEwetGdQ6up2YFfdnweYT/Bi1RrdHEaTwfuy/fIDjoGgeWO50lFMA1Fwn76c8H4efyfA X-Received: by 2002:a17:906:198c:: with SMTP id g12mr24079682ejd.247.1573055079998; Wed, 06 Nov 2019 07:44:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573055079; cv=none; d=google.com; s=arc-20160816; b=E4iTXrwOIDtyCg5NvqbyxPcTUNcMQue5p7PBusopqam/6gxMkcKW6Z6xAeXcg377eK 6HzrFYgHv9jUCiEUXP+07tkA89tBAYLUXNrD1+k6EgYXzb2O/WPNBFmFD2mjG6a26ASQ 7SsG4MZCWaaatN4EPatje7V2vvA51Aml2lEzxOHVT6dfTVaS6M78p1zsRkTrmEg7GJXR 1KkSNXDWDdPcpxBEhcXWb5ZuUyQPqIXYBX3NXHRnYzVvUmlzKUBII8J39dgdLh07nKVw u1KHXgaKUueLJbZHwhsiy+66sEF1VvWvxGejVcO4h+qqSMjBum+eDLk1yWf4PwPthAW3 knQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=+SUqeQYotcgyfJvnyVaxMWIDhGTXtwgzeNesp8l42ww=; b=xWXnMUTM/M7G4lzK3VoJHyIeklNxyG3jA1/2rBC7mLEQOvoYXPGDADl/C1V/kC/tWf SFvgH2VLYafEDexWfDueaLN0lJbhu+uJTw7uhAvJxEsDpFhr+m15KESWeqdvWhjjj1yV OJBVbG5D6nNzK14R4A7v10QqkR0YjnRwuGi7hd4niHH/Z4DKjLS1B4foBV3P6R62Niw1 chgYvUCV1p1SKlyPVe4/jngYz7/BEhWjZ1I5aMDLj04zQha5t01Z5ZX5iUxlzTVQdS9Q /w+AeOhxldHq3CeZF5tNvC7O3KBqIobtE7xXYRPwB3kezPd/WIRhlj8P+lmtW9qMm7rR oQ0A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z65si16205500ede.388.2019.11.06.07.43.45; Wed, 06 Nov 2019 07:44:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728530AbfKFPmj (ORCPT + 99 others); Wed, 6 Nov 2019 10:42:39 -0500 Received: from mx2.suse.de ([195.135.220.15]:57660 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728289AbfKFPmj (ORCPT ); Wed, 6 Nov 2019 10:42:39 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 008E6B1B2; Wed, 6 Nov 2019 15:42:36 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 6CF471E4353; Wed, 6 Nov 2019 16:42:36 +0100 (CET) Date: Wed, 6 Nov 2019 16:42:36 +0100 From: Jan Kara To: Chengguang Xu Cc: jack@suse.com, linux-ext4@vger.kernel.org Subject: Re: [PATCH 2/5] ext2: code cleanup by calling ext2_group_last_block_no() Message-ID: <20191106154236.GB12685@quack2.suse.cz> References: <20191104114036.9893-1-cgxu519@mykernel.net> <20191104114036.9893-2-cgxu519@mykernel.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" Content-Disposition: inline In-Reply-To: <20191104114036.9893-2-cgxu519@mykernel.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon 04-11-19 19:40:33, Chengguang Xu wrote: > Call common helper ext2_group_last_block_no() to > calculate group last block number. > > Signed-off-by: Chengguang Xu Thanks for the patch! I've applied it (as well as 1/5) and added attached simplification on top. Honza > --- > fs/ext2/balloc.c | 16 ++++++++-------- > fs/ext2/super.c | 8 +------- > 2 files changed, 9 insertions(+), 15 deletions(-) > > diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c > index 19bce75d207b..994a1fd18e93 100644 > --- a/fs/ext2/balloc.c > +++ b/fs/ext2/balloc.c > @@ -269,7 +269,7 @@ goal_in_my_reservation(struct ext2_reserve_window *rsv, ext2_grpblk_t grp_goal, > ext2_fsblk_t group_first_block, group_last_block; > > group_first_block = ext2_group_first_block_no(sb, group); > - group_last_block = group_first_block + EXT2_BLOCKS_PER_GROUP(sb) - 1; > + group_last_block = ext2_group_last_block_no(sb, group); > > if ((rsv->_rsv_start > group_last_block) || > (rsv->_rsv_end < group_first_block)) > @@ -666,22 +666,22 @@ ext2_try_to_allocate(struct super_block *sb, int group, > unsigned long *count, > struct ext2_reserve_window *my_rsv) > { > - ext2_fsblk_t group_first_block; > + ext2_fsblk_t group_first_block = ext2_group_first_block_no(sb, group); > + ext2_fsblk_t group_last_block = ext2_group_last_block_no(sb, group); > ext2_grpblk_t start, end; > unsigned long num = 0; > > /* we do allocation within the reservation window if we have a window */ > if (my_rsv) { > - group_first_block = ext2_group_first_block_no(sb, group); > if (my_rsv->_rsv_start >= group_first_block) > start = my_rsv->_rsv_start - group_first_block; > else > /* reservation window cross group boundary */ > start = 0; > end = my_rsv->_rsv_end - group_first_block + 1; > - if (end > EXT2_BLOCKS_PER_GROUP(sb)) > + if (end > group_last_block - group_first_block + 1) > /* reservation window crosses group boundary */ > - end = EXT2_BLOCKS_PER_GROUP(sb); > + end = group_last_block - group_first_block + 1; > if ((start <= grp_goal) && (grp_goal < end)) > start = grp_goal; > else > @@ -691,7 +691,7 @@ ext2_try_to_allocate(struct super_block *sb, int group, > start = grp_goal; > else > start = 0; > - end = EXT2_BLOCKS_PER_GROUP(sb); > + end = group_last_block - group_first_block + 1; > } > > BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb)); > @@ -907,7 +907,7 @@ static int alloc_new_reservation(struct ext2_reserve_window_node *my_rsv, > spinlock_t *rsv_lock = &EXT2_SB(sb)->s_rsv_window_lock; > > group_first_block = ext2_group_first_block_no(sb, group); > - group_end_block = group_first_block + (EXT2_BLOCKS_PER_GROUP(sb) - 1); > + group_end_block = ext2_group_last_block_no(sb, group); > > if (grp_goal < 0) > start_block = group_first_block; > @@ -1114,7 +1114,7 @@ ext2_try_to_allocate_with_rsv(struct super_block *sb, unsigned int group, > * first block is the block number of the first block in this group > */ > group_first_block = ext2_group_first_block_no(sb, group); > - group_last_block = group_first_block + (EXT2_BLOCKS_PER_GROUP(sb) - 1); > + group_last_block = ext2_group_last_block_no(sb, group); > > /* > * Basically we will allocate a new block from inode's reservation > diff --git a/fs/ext2/super.c b/fs/ext2/super.c > index 30c630d73f0f..4cd401a2f207 100644 > --- a/fs/ext2/super.c > +++ b/fs/ext2/super.c > @@ -702,13 +702,7 @@ static int ext2_check_descriptors(struct super_block *sb) > for (i = 0; i < sbi->s_groups_count; i++) { > struct ext2_group_desc *gdp = ext2_get_group_desc(sb, i, NULL); > ext2_fsblk_t first_block = ext2_group_first_block_no(sb, i); > - ext2_fsblk_t last_block; > - > - if (i == sbi->s_groups_count - 1) > - last_block = le32_to_cpu(sbi->s_es->s_blocks_count) - 1; > - else > - last_block = first_block + > - (EXT2_BLOCKS_PER_GROUP(sb) - 1); > + ext2_fsblk_t last_block = ext2_group_last_block_no(sb, i); > > if (le32_to_cpu(gdp->bg_block_bitmap) < first_block || > le32_to_cpu(gdp->bg_block_bitmap) > last_block) > -- > 2.20.1 > > > -- Jan Kara SUSE Labs, CR --Nq2Wo0NMKNjxTN9z Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-ext2-Simplify-initialization-in-ext2_try_to_allocate.patch" From 33229f6f844afe29a76584922a1c705ba5e88717 Mon Sep 17 00:00:00 2001 From: Jan Kara Date: Wed, 6 Nov 2019 16:39:26 +0100 Subject: [PATCH] ext2: Simplify initialization in ext2_try_to_allocate() Somewhat simplify the logic initializing search start and end in ext2_try_to_allocate(). No functional change. Signed-off-by: Jan Kara --- fs/ext2/balloc.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c index 994a1fd18e93..65df001f4cc2 100644 --- a/fs/ext2/balloc.c +++ b/fs/ext2/balloc.c @@ -671,29 +671,17 @@ ext2_try_to_allocate(struct super_block *sb, int group, ext2_grpblk_t start, end; unsigned long num = 0; + start = 0; + end = group_last_block - group_first_block + 1; /* we do allocation within the reservation window if we have a window */ if (my_rsv) { if (my_rsv->_rsv_start >= group_first_block) start = my_rsv->_rsv_start - group_first_block; - else - /* reservation window cross group boundary */ - start = 0; - end = my_rsv->_rsv_end - group_first_block + 1; - if (end > group_last_block - group_first_block + 1) - /* reservation window crosses group boundary */ - end = group_last_block - group_first_block + 1; - if ((start <= grp_goal) && (grp_goal < end)) - start = grp_goal; - else + if (my_rsv->_rsv_end < group_last_block) + end = my_rsv->_rsv_end - group_first_block + 1; + if (grp_goal < start || grp_goal > end) grp_goal = -1; - } else { - if (grp_goal > 0) - start = grp_goal; - else - start = 0; - end = group_last_block - group_first_block + 1; } - BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb)); repeat: -- 2.16.4 --Nq2Wo0NMKNjxTN9z--