>From 1cb50ef22658798f3934b15f7f4be06a7ef4d5ff Mon Sep 17 00:00:00 2001 From: Jaco Kroon Date: Fri, 18 Aug 2017 15:37:51 +0200 Subject: [PATCH 3/3] e2fsk: Optimize out the use of region.c for logical block overlap detection. Since extents have a guarantee of being monotonically increasing we merely need to check that block n+1 starts after block n. This is a simple enough check and we can perform this by calculating the next expected block --- e2fsck/pass1.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 97dd79c4..b78c4416 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -103,7 +103,7 @@ struct process_block_struct { struct problem_context *pctx; ext2fs_block_bitmap fs_meta_blocks; e2fsck_t ctx; - region_t region; + blk64_t next_logical_block; struct extent_tree_info eti; }; @@ -2819,9 +2819,16 @@ static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx, (1U << (21 - ctx->fs->super->s_log_block_size)))) problem = PR_1_TOOBIG_DIR; - if (is_leaf && problem == 0 && extent.e_len > 0 && - region_allocate(pb->region, extent.e_lblk, extent.e_len)) - problem = PR_1_EXTENT_COLLISION; + if (is_leaf && problem == 0 && extent.e_len > 0) { +#if 0 + printf("extent_region(ino=%u, expect=%llu, lblk=%llu, len=%u)\n", + pb->ino, pb->next_logical_block, extent.e_lblk, extent.e_len); +#endif + if (extent.e_lblk < pb->next_logical_block) + problem = PR_1_EXTENT_COLLISION; + else if (extent.e_lblk + extent.e_len > pb->next_logical_block) + pb->next_logical_block = extent.e_lblk + extent.e_len; + } /* * Uninitialized blocks in a directory? Clear the flag and @@ -3170,13 +3177,7 @@ static void check_blocks_extents(e2fsck_t ctx, struct problem_context *pctx, memset(pb->eti.ext_info, 0, sizeof(pb->eti.ext_info)); pb->eti.ino = pb->ino; - pb->region = region_create(0, info.max_lblk); - if (!pb->region) { - ext2fs_extent_free(ehandle); - fix_problem(ctx, PR_1_EXTENT_ALLOC_REGION_ABORT, pctx); - ctx->flags |= E2F_FLAG_ABORT; - return; - } + pb->next_logical_block = 0; eof_lblk = ((EXT2_I_SIZE(inode) + fs->blocksize - 1) >> EXT2_BLOCK_SIZE_BITS(fs->super)) - 1; @@ -3189,8 +3190,6 @@ static void check_blocks_extents(e2fsck_t ctx, struct problem_context *pctx, "check_blocks_extents"); pctx->errcode = 0; } - region_free(pb->region); - pb->region = NULL; ext2fs_extent_free(ehandle); /* Rebuild unless it's a dir and we're rehashing it */ -- 2.13.3