[Libguestfs] [RFC PATCH v4 7/7] resize: support resize extended partition

Hu Tao hutao at cn.fujitsu.com
Fri Sep 26 03:04:11 UTC 2014


Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---

This patch doesn't pass `make -C resize check`. The error message is:

  virt-resize: error: There is a deficit of 512 bytes (512).  You need to 
  make the target disk larger by at least this amount or adjust your resizing 
  requests.

I spent hours but can't found the reason. please help! I'll send the
complete log later.

 resize/resize.ml | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/resize/resize.ml b/resize/resize.ml
index a5cc7e5..c45d058 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -749,6 +749,24 @@ 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 -> p.p_part.G.part_size
+        | _ -> 0L in
+        total +^ newsize
+    ) 0L partitions in
+
     let required = List.fold_left (
       fun total p ->
         let newsize =
@@ -762,16 +780,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
 
     if verbose then
-- 
1.9.3




More information about the Libguestfs mailing list