This will re-calculate the size of logical partitions. and take logical partitions' aligment into account. If needed, update extended partition's OpResize.
Signed-off-by: Chen Hanxiao <[email protected]> --- resize/resize.ml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index d2c1724..6c90a0d 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -860,6 +860,36 @@ read the man page virt-resize(1). if verbose () then printf "Max alignment loss of logical partition is %Ld\n" logical_align; + (* handle resizing of logical partitions + * If we resized logical partitions, + * we may need to resize extended partition too. + * *) + List.iter ( + fun p -> + if p.p_type = ContentExtendedPartition then ( + let alignment = if alignment = 1L then 2L else alignment in + let size = roundup64 p.p_part.G.part_size sectsize in + let logical_sizes = List.fold_left ( + fun total p -> + match p.p_operation with + | OpDelete -> total +^ 0L + (* the start of logical partitions is aligned *) + | OpCopy | OpIgnore -> total +^ p.p_part.G.part_size + | OpResize newsize -> total +^ newsize + ) 0L logical_partitions in + + (* the first logical partition is aligned *) + let logical_sizes = logical_sizes +^ alignment *^ sectsize in + let logical_sizes = + roundup64 (logical_sizes +^ logical_align *^ sectsize) (alignment *^ sectsize) in + if logical_sizes > size then + p.p_operation <- OpResize logical_sizes + (* no need to touch the extended partition + * if new logical sizes less than the original size + * *) + ) + ) partitions; + (* Calculate the final surplus. * At this point, this number must be >= 0. *) @@ -918,6 +948,7 @@ read the man page virt-resize(1). wrap (text ^ "\n\n") in List.iter print_summary partitions; + List.iter print_summary logical_partitions; List.iter ( fun ({ lv_name = name } as lv) -> -- 2.1.0 _______________________________________________ Libguestfs mailing list [email protected] https://www.redhat.com/mailman/listinfo/libguestfs
