[Pkg-libvirt-commits] [libguestfs] 16/40: resize: add function find_partitions

Hilko Bengen bengen at moszumanska.debian.org
Fri Oct 3 14:49:12 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to annotated tag debian/1%1.27.57-1
in repository libguestfs.

commit 5aa7e99cb9bba7eb7ab0d826fe76b29d9b1c9b2e
Author: Hu Tao <hutao at cn.fujitsu.com>
Date:   Fri Sep 26 11:04:05 2014 +0800

    resize: add function find_partitions
    
    find_partitions can find partitions of given type.
    
    Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 resize/resize.ml | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/resize/resize.ml b/resize/resize.ml
index 81bb270..cfd02fc 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -73,6 +73,9 @@ and partition_id =
   | MBR_ID of int                (* MBR ID. *)
   | GPT_Type of string           (* GPT UUID. *)
 
+type partition_type =
+  | PrimaryPartition
+
 let rec debug_partition p =
   eprintf "%s:\n" p.p_name;
   eprintf "\tpartition data: %ld %Ld-%Ld (%Ld bytes)\n"
@@ -443,14 +446,15 @@ 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 parts =
+      match part_type with
+      (* for GPT, all partitions are regarded as Primary Partition,
+       * e.g. there is no Extended Partition or Logical Partition. *)
+      | PrimaryPartition ->
         List.filter (fun p -> parttype <> MBR || p.G.part_num <= 4_l)
         parts in
 
@@ -482,11 +486,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.
@@ -518,6 +517,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

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list