This patch add support for logical partitions. 1) OpResize newsize: an additional parameter for resizing logical partitions: - gap_start For logical partitions, we had to reserce at least 1 gap between each other. Also, we may had an extra aligment between 1st logical partition and extended partition. We need to remove gap_start from 'OpResize newsize'
2) OpIgnore | OpCopy: If in logical partition, add an extra alignment of 1 sector. Signed-off-by: Chen Hanxiao <chenhanx...@cn.fujitsu.com> --- resize/resize.ml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 22e3559..5deaa74 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1131,13 +1131,17 @@ read the man page virt-resize(1). * the final list just contains partitions that need to be created * on the target. *) - let rec calculate_target_partitions partnum start ~create_surplus = function + let rec calculate_target_partitions partnum start ~create_surplus ?(gap_start=0L) = function | p :: ps -> (match p.p_operation with | OpDelete -> calculate_target_partitions partnum start ~create_surplus ps (* skip p *) | OpIgnore | OpCopy -> (* same size *) + (* add an extra gap for logical partitions *) + let alg = if p.p_mbr_p_type = LogicalPartition then 1L else 0L in + let start = roundup64 (start +^ alg) 2L in + (* Size in sectors. *) let size = div_roundup64 p.p_part.G.part_size sectsize in (* Start of next partition + alignment. *) @@ -1150,13 +1154,24 @@ read the man page virt-resize(1). { p with p_target_start = start; p_target_end = end_ -^ 1L; p_target_partnum = partnum } :: - calculate_target_partitions (partnum+1) next ~create_surplus ps + calculate_target_partitions (partnum+1) next ~create_surplus ~gap_start ps | OpResize newsize -> (* resized partition *) + (* add an extra gap for logical partitions *) + let alg = if p.p_mbr_p_type = LogicalPartition then 1L else 0L in + + let start = roundup64 start 2L in (* New size in sectors. *) let size = div_roundup64 newsize sectsize in + (* remove gap_start from size *) + let size = size -^ gap_start in + (* remove max alignment between logical partitions *) + let size = size -^ logical_align in (* Start of next partition + alignment. *) let next = start +^ size in + (* We will reserve a 1-sector gap between logical partitions + * by decreasing current partition by 1 sector, see below. *) + let next = next -^ alg in let next = roundup64 next alignment in if verbose () then -- 2.1.0 _______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs