[Libguestfs] [PATCH v2 05/13] resize: add function find_partition

Hu Tao hutao at cn.fujitsu.com
Fri Sep 19 07:39:07 UTC 2014


Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 resize/resize.ml | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/resize/resize.ml b/resize/resize.ml
index 660ac86..8f0fbea 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -446,12 +446,9 @@ read the man page virt-resize(1).
     | MBR_ID _ | GPT_Type _ | No_ID -> false
   in
 
-  let partitions : partition list =
+  let find_partitions part_type =
     let parts = Array.to_list (g#part_list "/dev/sda") in
 
-    if List.length parts = 0 then
-      error (f_"the source disk has no partitions");
-
     (* Filter out logical partitions.  See note above. *)
     let filter_part part_type parts =
       match parttype with
@@ -465,7 +462,7 @@ read the man page virt-resize(1).
           ) parts
     in
 
-    let parts = filter_part PrimaryPartition parts in
+    let parts = filter_part part_type parts in
 
     let partitions =
       List.map (
@@ -495,11 +492,6 @@ read the man page virt-resize(1).
             p_target_start = 0L; p_target_end = 0L }
       ) parts in
 
-    if verbose then (
-      eprintf "%d partitions found\n" (List.length partitions);
-      List.iter debug_partition partitions
-    );
-
     (* Check content isn't larger than partitions.  If it is then
      * something has gone wrong and we shouldn't continue.  Old
      * virt-resize didn't do these checks.
@@ -531,6 +523,13 @@ read the man page virt-resize(1).
 
     partitions in
 
+  let partitions = find_partitions PrimaryPartition in
+
+  if verbose then (
+    eprintf "%d partitions found\n" (List.length partitions);
+    List.iter debug_partition partitions
+    );
+
   (* Build a data structure describing LVs on the source disk. *)
   let lvs =
     let lvs = Array.to_list (g#lvs ()) in
-- 
1.9.3




More information about the Libguestfs mailing list