On Mon, Sep 22, 2014 at 03:47:36PM +0800, Hu Tao wrote:
find_partitions can find partitions of given type.
Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
---
resize/resize.ml | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 8f2105c..cfd02fc 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -446,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
@@ -485,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.
@@ -521,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
Let's combine patches 01 and 03 into a single patch.
Otherwise, this looks fine to me.
Rich.
--
Richard Jones, Virtualization Group, Red Hat
http://people.redhat.com/~rjones
Read my programming and virtualization blog:
http://rwmj.wordpress.com
virt-top is 'top' for virtual machines. Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top