Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
resize/resize.ml | 36 +++++++++++++++++++++++++++---------
1 file changed, 27 insertions(+), 9 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 37b946e..8cdc5b1 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -769,6 +769,29 @@ read the man page virt-resize(1).
start_overhead_sects +^ alignment_sects +^ gpt_end_sects in
sectsize *^ overhead_sects in
+ let required_logical = List.fold_left (
+ fun total p ->
+ let newsize =
+ match p.p_operation with
+ | OpCopy | OpIgnore -> roundup64 p.p_part.G.part_size (alignment *^
sectsize)
+ | OpDelete -> 0L
+ | OpResize newsize -> roundup64 newsize (alignment *^ sectsize) in
+ total +^ newsize
+ ) 0L logical_partitions in
+
+ let required_extended = List.fold_left (
+ fun total p ->
+ let newsize =
+ match p.p_type with
+ | ContentExtendedPartition ->
+ (* resizing extended partition by --resize or --expand is supported *)
+ (match p.p_operation with
+ | OpResize newsize -> newsize
+ | _ -> p.p_part.G.part_size)
+ | _ -> 0L in
+ total +^ newsize
+ ) 0L partitions in
+
let required = List.fold_left (
fun total p ->
let newsize =
@@ -780,15 +803,8 @@ read the man page virt-resize(1).
| OpResize newsize -> newsize in
total +^ newsize
) 0L partitions in
- let required = required +^ List.fold_left (
- fun total p ->
- let newsize =
- match p.p_operation with
- | OpCopy | OpIgnore -> p.p_part.G.part_size
- | OpDelete -> 0L
- | OpResize newsize -> newsize in
- total +^ newsize
- ) 0L logical_partitions in
+ let required = required +^ if required_extended > required_logical
+ then required_extended else required_logical in
let surplus = outsize -^ (required +^ overhead) in
@@ -840,6 +856,8 @@ read the man page virt-resize(1).
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
+ (* resizing extended partition by --resize or --expand is supported *)
+ let size = match p.p_operation with OpResize s -> s | _ -> size in
let logical_sizes = List.fold_left (
fun total p ->
match p.p_operation with
--
2.1.0