Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
---
resize/resize.ml | 45 +++++++++++++++++++++++++++++++--------------
1 file changed, 31 insertions(+), 14 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index fc622ba..80a37e2 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -749,12 +749,33 @@ 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_logical = required_logical +^ alignment *^ sectsize 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 =
- (* don't count extended partition but logical partitions below,
- * because we may extend and resize logical partitions at
- * the same time. *)
+ (* 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
@@ -762,23 +783,17 @@ 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
if verbose then
eprintf "calculate surplus: outsize=%Ld required=%Ld overhead=%Ld
surplus=%Ld\n%!"
outsize required overhead surplus;
- surplus
+ (* XXX: fix of expanding a logical partition. without the sectsize,
+ * we'll get a deficit of 512 bytes. *)
+ surplus +^ sectsize
in
(* Handle --expand and --shrink options. *)
@@ -822,6 +837,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
--
1.9.3