Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
resize/resize.ml | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 000a4f8..9dfa21e 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -768,18 +768,6 @@ read the man page virt-resize(1).
start_overhead_sects +^ alignment_sects +^ gpt_end_sects in
sectsize *^ overhead_sects in
- let required = List.fold_left (
- fun total p ->
- let newsize =
- (* size of extended partition is calculated seperately *)
- if p.p_type = ContentExtendedPartition then 0L else
- match p.p_operation with
- | OpCopy | OpIgnore -> p.p_part.G.part_size
- | OpDelete -> 0L
- | OpResize newsize -> newsize in
- total +^ newsize
- ) 0L partitions in
-
let required_logical = List.fold_left (
fun total p ->
let newsize =
@@ -793,7 +781,34 @@ read the man page virt-resize(1).
let required_logical =
(* an extra alignment for the gap between extended and 1st logical *)
required_logical +^ (max_logi_align +^ alignment) *^sectsize in
- let required = required +^ required_logical 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 =
+ (* size of extended partition is calculated seperately *)
+ if p.p_type = ContentExtendedPartition then 0L else
+ match p.p_operation with
+ | OpCopy | OpIgnore -> p.p_part.G.part_size
+ | OpDelete -> 0L
+ | OpResize newsize -> newsize in
+ total +^ newsize
+ ) 0L partitions in
+
+ let required = required +^ if required_extended > required_logical
+ then required_extended else required_logical in
let surplus = outsize -^ (required +^ overhead) in
--
2.1.0