[Libguestfs] [PATCH v2 05/11] resize: handle resize of logical partitions

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed May 20 10:51:31 UTC 2015


This will re-calculate the size of logical partitions.
and take logical partitions' aligment into account.
Then update extended partition's OpResize.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 resize/resize.ml | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/resize/resize.ml b/resize/resize.ml
index a0ed713..c54ed2e 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -834,6 +834,30 @@ read the man page virt-resize(1).
     )
   );
 
+  (* handle resizing of logical partitions *)
+  List.iter (
+    fun p ->
+      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
+        let logical_sizes = List.fold_left (
+          fun total p ->
+            match p.p_operation with
+              | OpDelete -> total +^ 0L
+              (* the start of logical partitions is aligned *)
+              | OpCopy | OpIgnore -> total +^ (roundup64 p.p_part.G.part_size (alignment *^ sectsize))
+              | OpResize newsize -> total +^ roundup64 newsize (alignment *^ sectsize)
+          ) 0L logical_partitions in
+
+        (* the first logical partition is aligned *)
+        let logical_sizes = logical_sizes +^ alignment *^ sectsize in
+        if logical_sizes > size then
+          p.p_operation <- OpResize logical_sizes
+        (* don't touch the extended partition if logical sizes less
+         * than the original size *)
+      )
+  ) partitions;
+
   (* Calculate the final surplus.
    * At this point, this number must be >= 0.
    *)
@@ -892,6 +916,7 @@ read the man page virt-resize(1).
       wrap (text ^ "\n\n") in
 
     List.iter print_summary partitions;
+    List.iter print_summary logical_partitions;
 
     List.iter (
       fun ({ lv_name = name } as lv) ->
-- 
2.1.0




More information about the Libguestfs mailing list