From f02a9ab4c56339df9aa097250fbe4a3bb37b27ed Mon Sep 17 00:00:00 2001 From: dma Date: Tue, 14 May 2019 11:07:32 -0400 Subject: [PATCH] fix realmfs resize calculation bug on update + add e2fsck prior to ext4 resize --- libcitadel/src/realmfs/resizer.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libcitadel/src/realmfs/resizer.rs b/libcitadel/src/realmfs/resizer.rs index 67f4a62..64dd671 100644 --- a/libcitadel/src/realmfs/resizer.rs +++ b/libcitadel/src/realmfs/resizer.rs @@ -10,6 +10,7 @@ const BLOCK_SIZE: usize = 4096; const BLOCKS_PER_MEG: usize = (1024 * 1024) / BLOCK_SIZE; const BLOCKS_PER_GIG: usize = 1024 * BLOCKS_PER_MEG; +const E2FSCK: &str = "e2fsck"; const RESIZE2FS: &str = "resize2fs"; // If less than 1gb remaining space @@ -90,10 +91,14 @@ impl <'a> ImageResizer<'a> { ImageResizer::resize_image_file(self.image.path(), new_nblocks)?; if let Some(open_loop) = self.notify_open_loops()? { + info!("Running e2fsck {:?}", open_loop); + cmd!(E2FSCK,"{} {} {}","-f","-p",open_loop.device().display())?; info!("Running resize2fs {:?}", open_loop); cmd!(RESIZE2FS, "{}", open_loop.device().display())?; } else { LoopDevice::with_loop(self.image.path(), Some(4096), false, |loopdev| { + info!("Running e2fsck {:?}", loopdev); + cmd!(E2FSCK,"{} {} {}","-f","-p",loopdev.device().display())?; info!("Running resize2fs {:?}", loopdev); cmd!(RESIZE2FS, "{}", loopdev.device().display())?; Ok(()) @@ -140,8 +145,10 @@ impl <'a> ImageResizer<'a> { sb.free_block_count(); let free_blocks = sb.free_block_count() as usize; if free_blocks < AUTO_RESIZE_MINIMUM_FREE.nblocks() { - let mask = AUTO_RESIZE_INCREASE_SIZE.nblocks() - 1; - let grow_blocks = (free_blocks + mask) & !mask; + let increase_multiple = realmfs.metainfo_nblocks() / AUTO_RESIZE_INCREASE_SIZE.nblocks(); + let grow_size = (increase_multiple + 1) * AUTO_RESIZE_INCREASE_SIZE.nblocks(); + let mask = grow_size - 1; + let grow_blocks = (free_blocks + mask) & !mask; Some(ResizeSize::blocks(grow_blocks)) } else { None