From patchwork Tue Sep 6 02:36:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Br=C3=BCns?= X-Patchwork-Id: 666141 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3sSrlj4DCcz9s4n for ; Tue, 6 Sep 2016 12:54:09 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 23B1EB382C; Tue, 6 Sep 2016 04:54:07 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0T7v0lF0jS66; Tue, 6 Sep 2016 04:54:07 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 338EAA7533; Tue, 6 Sep 2016 04:53:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B447E4B698 for ; Tue, 6 Sep 2016 04:40:15 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zl7FeNHj853S for ; Tue, 6 Sep 2016 04:40:15 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mx-out-1.rwth-aachen.de (mx-out-1.rwth-aachen.de [134.130.5.186]) by theia.denx.de (Postfix) with ESMTPS id 5E91E4BB1A for ; Tue, 6 Sep 2016 04:38:01 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.30,289,1470693600"; d="scan'208";a="546063855" Received: from rwthex-w2-b.rwth-ad.de ([134.130.26.159]) by mx-1.rz.rwth-aachen.de with ESMTP; 06 Sep 2016 04:37:23 +0200 Received: from pebbles.fritz.box (78.48.8.184) by rwthex-w2-b.rwth-ad.de (2002:8682:1a9f::8682:1a9f) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Tue, 6 Sep 2016 04:37:51 +0200 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= To: Date: Tue, 6 Sep 2016 04:36:49 +0200 X-Mailer: git-send-email 2.9.3 In-Reply-To: <20160906023656.13421-1-stefan.bruens@rwth-aachen.de> References: <20160906023656.13421-1-stefan.bruens@rwth-aachen.de> MIME-Version: 1.0 X-Originating-IP: [78.48.8.184] X-ClientProxiedBy: rwthex-s1-b.rwth-ad.de (2002:8682:1a99::8682:1a99) To rwthex-w2-b.rwth-ad.de (2002:8682:1a9f::8682:1a9f) Message-ID: Cc: Stephen Warren , Stefan Roese Subject: [U-Boot] [PATCH v5 09/16] ext4: After completely filled group, scan next group from the beginning X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The last free block of a block group may be in its middle. After it has been allocated, the next block group should be scanned from its beginning. The following command triggers the bad behaviour (on a blocksize 1024 fs): ./sandbox/u-boot -c 'i=0; host bind 0 ./disk.raw ; while test $i -lt 260 ; do echo $i; setexpr i $i + 1; ext4write host 0:2 0 /X${i} 0x1450; done ; ext4write host 0:2 0 /X240 0x2000 ; ' When 'X240' is extended from 5200 byte to 8192 byte, the new blocks should start from the first free block (8811), but it uses the blocks 8098-8103 and 16296-16297 -- 8103 + 1 + 8192 = 16296. This can be shown with debugfs, commands 'ffb' and 'stat X240'. Signed-off-by: Stefan BrĂ¼ns Reviewed-by: Lukasz Majewski --- fs/ext4/ext4_common.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/fs/ext4/ext4_common.c b/fs/ext4/ext4_common.c index 539d622..8fc7559 100644 --- a/fs/ext4/ext4_common.c +++ b/fs/ext4/ext4_common.c @@ -903,8 +903,8 @@ uint32_t ext4fs_get_new_blk_no(void) goto fail; } else { -restart: fs->curr_blkno++; +restart: /* get the blockbitmap index respective to blockno */ bg_idx = fs->curr_blkno / blk_per_grp; if (fs->blksz == 1024) { @@ -922,8 +922,9 @@ restart: if (bgd[bg_idx].free_blocks == 0) { debug("block group %u is full. Skipping\n", bg_idx); - fs->curr_blkno = fs->curr_blkno + blk_per_grp; - fs->curr_blkno--; + fs->curr_blkno = (bg_idx + 1) * blk_per_grp; + if (fs->blksz == 1024) + fs->curr_blkno += 1; goto restart; } @@ -940,6 +941,7 @@ restart: bg_idx) != 0) { debug("going for restart for the block no %ld %u\n", fs->curr_blkno, bg_idx); + fs->curr_blkno++; goto restart; }