diff mbox

resize2fs: move bitmaps if shrinking would orphan them

Message ID 20130621024707.GC10730@thunk.org
State New, archived
Headers show

Commit Message

Theodore Ts'o June 21, 2013, 2:47 a.m. UTC
On Tue, Jun 18, 2013 at 08:37:05PM -0500, Eric Sandeen wrote:
> It is possible to have a flex_bg filesystem with block groups
> which have inode & block bitmaps at some point well past the
> start of the group.
> 
> If an offline shrink puts the new size somewhere between
> the start of the block group and the (old) location of
> the bitmaps, they can be left beyond the end of the filesystem,
> i.e. result in fs corruption.
> 
> Check each remaining block group for whether its bitmaps
> are beyond the end of the new filesystem, and reallocate
> them in a new location if needed.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Looks good, thanks for the patch.  I made a few minor changes to fix
up some extra whitespace and a minor optimization.

   	      		       	     - Ted

--
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

Comments

Eric Sandeen June 21, 2013, 2:13 p.m. UTC | #1
On 6/20/13 9:47 PM, Theodore Ts'o wrote:
> On Tue, Jun 18, 2013 at 08:37:05PM -0500, Eric Sandeen wrote:
>> It is possible to have a flex_bg filesystem with block groups
>> which have inode & block bitmaps at some point well past the
>> start of the group.
>>
>> If an offline shrink puts the new size somewhere between
>> the start of the block group and the (old) location of
>> the bitmaps, they can be left beyond the end of the filesystem,
>> i.e. result in fs corruption.
>>
>> Check each remaining block group for whether its bitmaps
>> are beyond the end of the new filesystem, and reallocate
>> them in a new location if needed.
>>
>> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> 
> Looks good, thanks for the patch.  I made a few minor changes to fix
> up some extra whitespace and a minor optimization.

Great, thanks for the review.

>    	      		       	     - Ted
> 
> diff --git a/resize/resize2fs.c b/resize/resize2fs.c
> index 28131c2..204b10a 100644
> --- a/resize/resize2fs.c
> +++ b/resize/resize2fs.c
> @@ -889,7 +889,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
>  	 * bitmaps which are beyond the end of the new filesystem.
>  	 */
>  	new_size = ext2fs_blocks_count(fs->super);
> -	if (ext2fs_blocks_count(fs->super) < ext2fs_blocks_count(old_fs->super)) {
> +	if (new_size < ext2fs_blocks_count(old_fs->super)) {

thanks, I think I *meant* to do that

>  		for (g = 0; g < fs->group_desc_count; g++) {
>  			/*
>  			 * ext2fs_allocate_group_table re-allocates bitmaps
> @@ -900,13 +900,13 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
>  				retval = ext2fs_allocate_group_table(fs, g, 0);
>  				if (retval)
>  					return retval;
> -			} 
                         ^ whoops sorry
> +			}
>  			if (ext2fs_inode_bitmap_loc(fs, g) >= new_size) {
>  				ext2fs_inode_bitmap_loc_set(fs, g, 0);
>  				retval = ext2fs_allocate_group_table(fs, g, 0);
>  				if (retval)
>  					return retval;
> -			}
                         ^ whoops sorry^2!
 
> +			}
>  		}
>  	}
>  
> 

--
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
diff mbox

Patch

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 28131c2..204b10a 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -889,7 +889,7 @@  static errcode_t blocks_to_move(ext2_resize_t rfs)
 	 * bitmaps which are beyond the end of the new filesystem.
 	 */
 	new_size = ext2fs_blocks_count(fs->super);
-	if (ext2fs_blocks_count(fs->super) < ext2fs_blocks_count(old_fs->super)) {
+	if (new_size < ext2fs_blocks_count(old_fs->super)) {
 		for (g = 0; g < fs->group_desc_count; g++) {
 			/*
 			 * ext2fs_allocate_group_table re-allocates bitmaps
@@ -900,13 +900,13 @@  static errcode_t blocks_to_move(ext2_resize_t rfs)
 				retval = ext2fs_allocate_group_table(fs, g, 0);
 				if (retval)
 					return retval;
-			} 
+			}
 			if (ext2fs_inode_bitmap_loc(fs, g) >= new_size) {
 				ext2fs_inode_bitmap_loc_set(fs, g, 0);
 				retval = ext2fs_allocate_group_table(fs, g, 0);
 				if (retval)
 					return retval;
-			} 
+			}
 		}
 	}