This patch add support for logical partitions.
1) OpResize newsize:
two 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'
- nr_logical
number of logical partitions.
We had to remove all size of gap between each logical partitions.
each gap is in (1, alignment).
So size = (nr_logical - 1) * alignment
removed from size will be enough.
2) OpIgnore | OpCopy:
If in logical partition, add an extra aligment of 1 sector.
Signed-off-by: Chen Hanxiao <chenhanxiao(a)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 c54ed2e..6a3d286 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -1083,13 +1083,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 ?(nr_logical=0)
?(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. *)
@@ -1102,13 +1106,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 ~nr_logical
~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 aligment between logical partitions *)
+ let size = size -^ ((Int64.of_int nr_logical) -^ 1L) *^ alignment 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