Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp3848656ybx; Mon, 4 Nov 2019 03:56:46 -0800 (PST) X-Google-Smtp-Source: APXvYqyzMtfF3WgH/HQFQrhpQlFONcvdNaqHtjsXsqU3UzA1oBC/hBjc0YEMuWtyLo4B1SgyMmZW X-Received: by 2002:a17:906:4884:: with SMTP id v4mr1391129ejq.235.1572868606363; Mon, 04 Nov 2019 03:56:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1572868606; cv=pass; d=google.com; s=arc-20160816; b=ywxaomzHya9dUf9kPGQrOsAlofwedMuD575w/CnvtMbO8P5g1nIVJuhVIU+2aMOtom 9nrwMz1r8XzicR748sxIlPj5LDO1WWZYMbb8GgblhRcC2RqIGPcAV5e7krjNUU77aimh 8lePUDsjiyhIHwicX6TeV/A0SYhWBsaWHhe9dFmfvCybmG9UvGCgJZ8CL578dJJQBLTD NVcM8G9jF9+rjEYYw0xVbwrh5MYdor9PKKUbJkBKkg+yyqjFvgVyELQ26Az1c8fefbbI z71D5PCsgKqI5oMZyt7pTV73ZPA/T3naRr+C+9dgg7BDspOi33zZfk+xQKaTo0OvzfpO Z/fA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:message-id:cc:to:from :dkim-signature; bh=CMQuzlno95XbIzQ1wuAOAASx9zQo5tfKqr71pMmWDvU=; b=WT5cfZPqW+HAgCpFXQNzGTyR4rzRs0+8/ApkkT/t4vKz/Yb2/5dTP+j/U6EpKyUUiV qbPQ8egUPZsr7HTfSgAsNRxa4lfBVxV9PrTyo8JB+abZaia2l2ANugaqb9ZwNtwClrop H8IKhiIJKBZHlScWzhJoKSwjqCHhHJySEBV1IrpAPWHv48y70Wu4I0XnsYgr3IzgfbDF m5dQb2yd6+BWtD1VzYCkMfJjcUQco9oDG+t/vpFtrjveQOf2FiiLv3becE5DmipDQcRr doN8XGZ4VJeIyPxOUbPByQxv4iFwpGqh+4GxnxkKJIhpEDwI7kY6/ueds83JKbCDRMk5 bi2A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mykernel.net header.s=zohomail header.b=e+DcnTCM; arc=pass (i=1 spf=pass spfdomain=mykernel.net dkim=pass dkdomain=mykernel.net dmarc=pass fromdomain=mykernel.net>); 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 t17si11441272ejg.44.2019.11.04.03.56.20; Mon, 04 Nov 2019 03:56:46 -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; dkim=pass header.i=@mykernel.net header.s=zohomail header.b=e+DcnTCM; arc=pass (i=1 spf=pass spfdomain=mykernel.net dkim=pass dkdomain=mykernel.net dmarc=pass fromdomain=mykernel.net>); 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 S1728873AbfKDL4T (ORCPT + 99 others); Mon, 4 Nov 2019 06:56:19 -0500 Received: from sender3-of-o52.zoho.com.cn ([124.251.121.247]:21931 "EHLO sender2.zoho.com.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728346AbfKDL4S (ORCPT ); Mon, 4 Nov 2019 06:56:18 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1572867660; cv=none; d=zoho.com.cn; s=zohoarc; b=q9LnFowmEN9JUzdmDLuiwIKCyMLD9ZOsmu9uoms84WLi7MhgLYhCAMuSIgiLvIQyXUtS/rBmH0wL3u36EK6XM/4CdwWgz+GJU+y3EQXmJjWeOl/jSXGA7CFrcxuPh5f4ppOvbAZRAkJnN62NqxBtC1wjJcpmnhw8Ct1U7zue24w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com.cn; s=zohoarc; t=1572867660; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=CMQuzlno95XbIzQ1wuAOAASx9zQo5tfKqr71pMmWDvU=; b=L6aZvMXH75RhqFFBQ/Bi0oPbKgy3vqszOd6J9n7bImXlySQ0uYYGrZVJp+dnaTUAy8Pk3Wn26v4eseKVG8D2BGnwxhun6SAwhIn2vO+z4u1HzBZwqZzkq9qsWAjF+2WgzZUbDGSDbWUxHf/trXMEOFP2TTKeROIPWsd6YZRst3A= ARC-Authentication-Results: i=1; mx.zoho.com.cn; dkim=pass header.i=mykernel.net; spf=pass smtp.mailfrom=cgxu519@mykernel.net; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1572867660; s=zohomail; d=mykernel.net; i=cgxu519@mykernel.net; h=From:To:Cc:Message-ID:Subject:Date:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Content-Type; l=4212; bh=CMQuzlno95XbIzQ1wuAOAASx9zQo5tfKqr71pMmWDvU=; b=e+DcnTCMLMiccl3Vf9f5FH/oc7FibsSfSt0WehQzSya6nA8xiyVLr7uoTjTkqa4r KNuwMtzVbNpPZIZ6wMHcS/GnmY6e8t23b2hHb9d+H/JOxSqByvT5nxiLP6PXTCeJN77 n1+V7MA43OMPJ1dDV5gORl0YR6eMYgHN30WHxxrM= Received: from localhost.localdomain (218.18.229.179 [218.18.229.179]) by mx.zoho.com.cn with SMTPS id 15728676596340.035362748932016075; Mon, 4 Nov 2019 19:40:59 +0800 (CST) From: Chengguang Xu To: jack@suse.com Cc: linux-ext4@vger.kernel.org, Chengguang Xu Message-ID: <20191104114036.9893-2-cgxu519@mykernel.net> Subject: [PATCH 2/5] ext2: code cleanup by calling ext2_group_last_block_no() Date: Mon, 4 Nov 2019 19:40:33 +0800 X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191104114036.9893-1-cgxu519@mykernel.net> References: <20191104114036.9893-1-cgxu519@mykernel.net> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoCNMailClient: External Content-Type: text/plain; charset=utf8 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Call common helper ext2_group_last_block_no() to calculate group last block number. Signed-off-by: Chengguang Xu --- 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, =09ext2_fsblk_t group_first_block, group_last_block; =20 =09group_first_block =3D ext2_group_first_block_no(sb, group); -=09group_last_block =3D group_first_block + EXT2_BLOCKS_PER_GROUP(sb) - 1; +=09group_last_block =3D ext2_group_last_block_no(sb, group); =20 =09if ((rsv->_rsv_start > group_last_block) || =09 (rsv->_rsv_end < group_first_block)) @@ -666,22 +666,22 @@ ext2_try_to_allocate(struct super_block *sb, int grou= p, =09=09=09unsigned long *count, =09=09=09struct ext2_reserve_window *my_rsv) { -=09ext2_fsblk_t group_first_block; +=09ext2_fsblk_t group_first_block =3D ext2_group_first_block_no(sb, group)= ; +=09ext2_fsblk_t group_last_block =3D ext2_group_last_block_no(sb, group); =09ext2_grpblk_t start, end; =09unsigned long num =3D 0; =20 =09/* we do allocation within the reservation window if we have a window *= / =09if (my_rsv) { -=09=09group_first_block =3D ext2_group_first_block_no(sb, group); =09=09if (my_rsv->_rsv_start >=3D group_first_block) =09=09=09start =3D my_rsv->_rsv_start - group_first_block; =09=09else =09=09=09/* reservation window cross group boundary */ =09=09=09start =3D 0; =09=09end =3D my_rsv->_rsv_end - group_first_block + 1; -=09=09if (end > EXT2_BLOCKS_PER_GROUP(sb)) +=09=09if (end > group_last_block - group_first_block + 1) =09=09=09/* reservation window crosses group boundary */ -=09=09=09end =3D EXT2_BLOCKS_PER_GROUP(sb); +=09=09=09end =3D group_last_block - group_first_block + 1; =09=09if ((start <=3D grp_goal) && (grp_goal < end)) =09=09=09start =3D grp_goal; =09=09else @@ -691,7 +691,7 @@ ext2_try_to_allocate(struct super_block *sb, int group, =09=09=09start =3D grp_goal; =09=09else =09=09=09start =3D 0; -=09=09end =3D EXT2_BLOCKS_PER_GROUP(sb); +=09=09end =3D group_last_block - group_first_block + 1; =09} =20 =09BUG_ON(start > EXT2_BLOCKS_PER_GROUP(sb)); @@ -907,7 +907,7 @@ static int alloc_new_reservation(struct ext2_reserve_wi= ndow_node *my_rsv, =09spinlock_t *rsv_lock =3D &EXT2_SB(sb)->s_rsv_window_lock; =20 =09group_first_block =3D ext2_group_first_block_no(sb, group); -=09group_end_block =3D group_first_block + (EXT2_BLOCKS_PER_GROUP(sb) - 1)= ; +=09group_end_block =3D ext2_group_last_block_no(sb, group); =20 =09if (grp_goal < 0) =09=09start_block =3D group_first_block; @@ -1114,7 +1114,7 @@ ext2_try_to_allocate_with_rsv(struct super_block *sb,= unsigned int group, =09 * first block is the block number of the first block in this group =09 */ =09group_first_block =3D ext2_group_first_block_no(sb, group); -=09group_last_block =3D group_first_block + (EXT2_BLOCKS_PER_GROUP(sb) - 1= ); +=09group_last_block =3D ext2_group_last_block_no(sb, group); =20 =09/* =09 * 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) =09for (i =3D 0; i < sbi->s_groups_count; i++) { =09=09struct ext2_group_desc *gdp =3D ext2_get_group_desc(sb, i, NULL); =09=09ext2_fsblk_t first_block =3D ext2_group_first_block_no(sb, i); -=09=09ext2_fsblk_t last_block; - -=09=09if (i =3D=3D sbi->s_groups_count - 1) -=09=09=09last_block =3D le32_to_cpu(sbi->s_es->s_blocks_count) - 1; -=09=09else -=09=09=09last_block =3D first_block + -=09=09=09=09(EXT2_BLOCKS_PER_GROUP(sb) - 1); +=09=09ext2_fsblk_t last_block =3D ext2_group_last_block_no(sb, i); =20 =09=09if (le32_to_cpu(gdp->bg_block_bitmap) < first_block || =09=09 le32_to_cpu(gdp->bg_block_bitmap) > last_block) --=20 2.20.1