Patchwork [14/25] e2fsck: only release clusters when shortening a directory during a rehash

login
register
mail settings
Submitter Darrick J. Wong
Date Oct. 18, 2013, 4:50 a.m.
Message ID <20131018045027.7339.9686.stgit@birch.djwong.org>
Download mbox | patch
Permalink /patch/284421/
State Superseded
Headers show

Comments

Darrick J. Wong - Oct. 18, 2013, 4:50 a.m.
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.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 e2fsck/rehash.c |   14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Zheng Liu - Nov. 25, 2013, 11:09 a.m.
On Thu, Oct 17, 2013 at 09:50:27PM -0700, Darrick J. Wong wrote:
> 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.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>

                                                - Zheng

> ---
>  e2fsck/rehash.c |   14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> 
> diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
> index 6ef3568..29da9a1 100644
> --- a/e2fsck/rehash.c
> +++ b/e2fsck/rehash.c
> @@ -719,10 +719,18 @@ static int write_dir_block(ext2_filsys fs,
>  		/* We don't need this block, so release it */
>  		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;
>  	}
>  
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c
index 6ef3568..29da9a1 100644
--- a/e2fsck/rehash.c
+++ b/e2fsck/rehash.c
@@ -719,10 +719,18 @@  static int write_dir_block(ext2_filsys fs,
 		/* We don't need this block, so release it */
 		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;
 	}