resize2fs: Make minimum size estimates more reliable for mounted fs
diff mbox series

Message ID 20191018125059.2446-1-jack@suse.cz
State Accepted
Headers show
Series
  • resize2fs: Make minimum size estimates more reliable for mounted fs
Related show

Commit Message

Jan Kara Oct. 18, 2019, 12:50 p.m. UTC
Currently, the estimate of minimum filesystem size is using free blocks
counter in the superblock. The counter generally doesn't get updated
while the filesystem is mounted and thus the estimate is very unreliable
for a mounted filesystem. For some usecases such as automated
partitioning proposal to the user it is desirable that the estimate of
minimum filesystem size is reasonably accurate even for a mounted
filesystem. So use group descriptor counters of free blocks for the
estimate of minimum filesystem size. These get updated together with
block being allocated and so the resulting estimate is more accurate.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 resize/resize2fs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Theodore Y. Ts'o Nov. 10, 2019, 1:14 p.m. UTC | #1
On Fri, Oct 18, 2019 at 02:50:59PM +0200, Jan Kara wrote:
> Currently, the estimate of minimum filesystem size is using free blocks
> counter in the superblock. The counter generally doesn't get updated
> while the filesystem is mounted and thus the estimate is very unreliable
> for a mounted filesystem. For some usecases such as automated
> partitioning proposal to the user it is desirable that the estimate of
> minimum filesystem size is reasonably accurate even for a mounted
> filesystem. So use group descriptor counters of free blocks for the
> estimate of minimum filesystem size. These get updated together with
> block being allocated and so the resulting estimate is more accurate.
> 
> Signed-off-by: Jan Kara <jack@suse.cz>

Thanks, applied.

						- Ted

Patch
diff mbox series

diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index c2e10471bfd1..8a3d08db19f3 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -2926,11 +2926,11 @@  blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags)
 			fs->super->s_reserved_gdt_blocks;
 
 	/* calculate how many blocks are needed for data */
-	data_needed = ext2fs_blocks_count(fs->super) -
-		ext2fs_free_blocks_count(fs->super);
-
-	for (grp = 0; grp < fs->group_desc_count; grp++)
+	data_needed = ext2fs_blocks_count(fs->super);
+	for (grp = 0; grp < fs->group_desc_count; grp++) {
 		data_needed -= calc_group_overhead(fs, grp, old_desc_blocks);
+		data_needed -= ext2fs_bg_free_blocks_count(fs, grp);
+	}
 #ifdef RESIZE2FS_DEBUG
 	if (flags & RESIZE_DEBUG_MIN_CALC)
 		printf("fs requires %llu data blocks.\n", data_needed);