From: Darrick J. Wong Date: Wed, 11 Dec 2013 01:23:12 +0000 (-0800) Subject: e2fsck: only release clusters when shortening a directory during a rehash X-Git-Tag: android-x86-6.0-r1~26^2~54 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=5797cb017cb8accbab8c69aaf83269c5d2d72e4e;p=android-x86%2Fexternal-e2fsprogs.git e2fsck: only release clusters when shortening a directory during a rehash When the rehash process is running on a bigalloc filesystem, it compresses all the directory entries and hash structures into the beginning of the directory file and then uses block_iterate3() to free the blocks off the end of the file. It seems to call ext2fs_block_alloc_stats2() for every block in a cluster, which is unfortunate because this function allocates and frees entire clusters (and updates the summary counts accordingly). In this case e2fsck writes out incorrect summary counts. Reviewed-by: Zheng Liu Signed-off-by: Darrick J. Wong Signed-off-by: "Theodore Ts'o" --- diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c index ac0ff31f..3aafbb12 100644 --- a/e2fsck/rehash.c +++ b/e2fsck/rehash.c @@ -648,10 +648,18 @@ static int write_dir_block(ext2_filsys fs, if (blockcnt >= wd->outdir->num) { e2fsck_read_bitmaps(wd->ctx); blk = *block_nr; - ext2fs_unmark_block_bitmap2(wd->ctx->block_found_map, blk); - ext2fs_block_alloc_stats2(fs, blk, -1); + /* + * In theory, we only release blocks from the end of the + * directory file, so it's fine to clobber a whole cluster at + * once. + */ + if (blk % EXT2FS_CLUSTER_RATIO(fs) == 0) { + ext2fs_unmark_block_bitmap2(wd->ctx->block_found_map, + blk); + ext2fs_block_alloc_stats2(fs, blk, -1); + wd->cleared++; + } *block_nr = 0; - wd->cleared++; return BLOCK_CHANGED; } if (blockcnt < 0)