Hu Tao
2014-Sep-22 07:47 UTC
[Libguestfs] [PATCH v3 0/7] add support to resize MBR logical partitions
Hi Rich, This is v3 series to add support for resizing MBR logical partitions. changes to v2: 1. remove p_part_num 2. remove filter_parts 3. name the function calculate_target_partitions 4. remove the code to restart guest introduced in v2 changes to v1: 1. spit the patches so it's easier to review 2. fix the parted error caused by unaligned logical partitions 3. extend the content of logical partitions 4. refactor to make logical partitions a seperate list Hu Tao (7): resize: introduce partition_type resize: simplify the code to filter parts resize: add function find_partitions resize: add function calculate_target_partitions resize: add function mbr_part_type resize: add partition type LogicalPartition resize: add support to resize logical partitions resize/resize.ml | 145 +++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 110 insertions(+), 35 deletions(-) -- 1.9.3
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- resize/resize.ml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index 356303c..72c4da2 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" -- 1.9.3
Hu Tao
2014-Sep-22 07:47 UTC
[Libguestfs] [PATCH v3 2/7] resize: simplify the code to filter parts
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- resize/resize.ml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 72c4da2..8f2105c 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -454,13 +454,8 @@ read the man page virt-resize(1). (* Filter out logical partitions. See note above. *) let parts - match parttype with - | GPT -> parts - | MBR -> - List.filter (function - | { G.part_num = part_num } when part_num >= 5_l -> false - | _ -> true - ) parts in + List.filter (fun p -> parttype <> MBR || p.G.part_num <= 4_l) + parts in let partitions List.map ( -- 1.9.3
Hu Tao
2014-Sep-22 07:47 UTC
[Libguestfs] [PATCH v3 3/7] resize: add function find_partitions
find_partitions can find partitions of given type. Signed-off-by: Hu Tao <hutao@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 -- 1.9.3
Hu Tao
2014-Sep-22 07:47 UTC
[Libguestfs] [PATCH v3 4/7] resize: add function calculate_target_partitions
And introduce parameter create_surplus to indicate whether to create surplus partition or not. Later this parameter will be used by when calculating positions for target logical partitions. Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- resize/resize.ml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index cfd02fc..8b43306 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1019,11 +1019,10 @@ read the man page virt-resize(1). * the final list just contains partitions that need to be created * on the target. *) - let partitions - let rec loop partnum start = function + let rec calculate_target_partitions partnum start ~create_surplus = function | p :: ps -> (match p.p_operation with - | OpDelete -> loop partnum start ps (* skip p *) + | OpDelete -> calculate_target_partitions partnum start ~create_surplus ps (* skip p *) | OpIgnore | OpCopy -> (* same size *) (* Size in sectors. *) @@ -1037,7 +1036,7 @@ read the man page virt-resize(1). partnum start (end_ -^ 1L); { p with p_target_start = start; p_target_end = end_ -^ 1L; - p_target_partnum = partnum } :: loop (partnum+1) next ps + p_target_partnum = partnum } :: calculate_target_partitions (partnum+1) next ~create_surplus ps | OpResize newsize -> (* resized partition *) (* New size in sectors. *) @@ -1051,12 +1050,12 @@ read the man page virt-resize(1). partnum newsize start (next -^ 1L); { p with p_target_start = start; p_target_end = next -^ 1L; - p_target_partnum = partnum } :: loop (partnum+1) next ps + p_target_partnum = partnum } :: calculate_target_partitions (partnum+1) next ~create_surplus ps ) | [] -> (* Create the surplus partition if there is room for it. *) - if extra_partition && surplus >= min_extra_partition then ( + if create_surplus && extra_partition && surplus >= min_extra_partition then ( [ { (* Since this partition has no source, this data is * meaningless and not used since the operation is @@ -1077,6 +1076,7 @@ read the man page virt-resize(1). else [] in + let partitions (* Choose the alignment of the first partition based on the * '--align-first' option. Old virt-resize used to always align this * to 64 sectors, but this causes boot failures unless we are able to @@ -1089,7 +1089,7 @@ read the man page virt-resize(1). (* Preserve the existing start, but convert to sectors. *) (List.hd partitions).p_part.G.part_start /^ sectsize in - loop 1 start partitions in + calculate_target_partitions 1 start ~create_surplus:true partitions in (* Now partition the target disk. *) List.iter ( -- 1.9.3
Hu Tao
2014-Sep-22 07:47 UTC
[Libguestfs] [PATCH v3 5/7] resize: add function mbr_part_type
Function mbr_part_type returns one of "primary", "extended" and "logical". The type is used by parted when adding partitions. Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- resize/resize.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/resize/resize.ml b/resize/resize.ml index 8b43306..c56a91a 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1091,10 +1091,17 @@ read the man page virt-resize(1). calculate_target_partitions 1 start ~create_surplus:true partitions in + (* For GPT, the part type simply becomes partition name, so we don't + * handle the case specifically. *) + let mbr_part_type x + if x.p_part.G.part_num <= 4l && x.p_type <> ContentExtendedPartition then "primary" + else if x.p_part.G.part_num <= 4l && x.p_type = ContentExtendedPartition then "extended" + else "logical" in + (* Now partition the target disk. *) List.iter ( fun p -> - g#part_add "/dev/sdb" "primary" p.p_target_start p.p_target_end + g#part_add "/dev/sdb" (mbr_part_type p) p.p_target_start p.p_target_end ) partitions; (* Copy over the data. *) -- 1.9.3
Hu Tao
2014-Sep-22 07:47 UTC
[Libguestfs] [PATCH v3 6/7] resize: add partition type LogicalPartition
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- resize/resize.ml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index c56a91a..3f804a0 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -75,6 +75,7 @@ and partition_id type partition_type | PrimaryPartition + | LogicalPartition let rec debug_partition p eprintf "%s:\n" p.p_name; @@ -449,13 +450,15 @@ read the man page virt-resize(1). let find_partitions part_type let parts = Array.to_list (g#part_list "/dev/sda") in - (* 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 + | LogicalPartition -> + List.filter (fun p -> parttype = MBR && p.G.part_num >= 5_l) parts in let partitions @@ -518,10 +521,12 @@ read the man page virt-resize(1). partitions in let partitions = find_partitions PrimaryPartition in + let logical_partitions = find_partitions LogicalPartition in if verbose then ( - eprintf "%d partitions found\n" (List.length partitions); - List.iter debug_partition partitions + eprintf "%d partitions found\n" (List.length partitions + List.length logical_partitions); + List.iter debug_partition partitions; + List.iter debug_partition logical_partitions ); (* Build a data structure describing LVs on the source disk. *) -- 1.9.3
Hu Tao
2014-Sep-22 07:47 UTC
[Libguestfs] [PATCH v3 7/7] resize: add support to resize logical partitions
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- resize/resize.ml | 82 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 10 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 3f804a0..ea0be9e 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -596,6 +596,8 @@ read the man page virt-resize(1). let hash = Hashtbl.create 13 in List.iter (fun ({ p_name = name } as p) -> Hashtbl.add hash name p) partitions; + List.iter (fun ({ p_name = name } as p) -> Hashtbl.add hash name p) + logical_partitions; fun ~option name -> let name if String.length name < 5 || String.sub name 0 5 <> "/dev/" then @@ -719,8 +721,10 @@ read the man page virt-resize(1). (* We need some overhead for partitioning. *) let overhead let maxl64 = List.fold_left max 0L in + let alignment = if alignment = 1L then 2L else alignment in let nr_partitions = List.length partitions in + let nr_partitions = nr_partitions + List.length logical_partitions in let gpt_start_sects = 64L in let gpt_end_sects = gpt_start_sects in @@ -748,12 +752,25 @@ read the man page virt-resize(1). let required = List.fold_left ( fun total p -> let newsize + (* don't count extended partition but logical partitions below, + * because we may extend and resize logical partitions at + * the same time. *) + if p.p_type = ContentExtendedPartition then 0L else + match p.p_operation with + | OpCopy | OpIgnore -> p.p_part.G.part_size + | OpDelete -> 0L + | 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 partitions in + ) 0L logical_partitions in let surplus = outsize -^ (required +^ overhead) in @@ -799,6 +816,28 @@ 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 + | 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 + * then the original size *) + ) + ) partitions; + (* Calculate the final surplus. * At this point, this number must be >= 0. *) @@ -857,6 +896,7 @@ read the man page virt-resize(1). wrap ~indent:4 (text ^ "\n\n") in List.iter print_summary partitions; + List.iter print_summary logical_partitions; List.iter ( fun ({ lv_name = name } as lv) -> @@ -1030,6 +1070,7 @@ read the man page virt-resize(1). | OpDelete -> calculate_target_partitions partnum start ~create_surplus ps (* skip p *) | OpIgnore | OpCopy -> (* same size *) + let start = roundup64 start 2L in (* Size in sectors. *) let size = div_roundup64 p.p_part.G.part_size sectsize in (* Start of next partition + alignment. *) @@ -1044,6 +1085,7 @@ read the man page virt-resize(1). p_target_partnum = partnum } :: calculate_target_partitions (partnum+1) next ~create_surplus ps | OpResize newsize -> (* resized partition *) + let start = roundup64 start 2L in (* New size in sectors. *) let size = div_roundup64 newsize sectsize in (* Start of next partition + alignment. *) @@ -1054,7 +1096,9 @@ read the man page virt-resize(1). eprintf "target partition %d: resize: newsize=%Ld start=%Ld end=%Ld\n%!" partnum newsize start (next -^ 1L); - { p with p_target_start = start; p_target_end = next -^ 1L; + (* there must be a at least 1-sector gap between logical + * partitions otherwise parted refused to add logical partition *) + { p with p_target_start = start; p_target_end = next -^ 2L; p_target_partnum = partnum } :: calculate_target_partitions (partnum+1) next ~create_surplus ps ) @@ -1096,6 +1140,16 @@ read the man page virt-resize(1). calculate_target_partitions 1 start ~create_surplus:true partitions in + let logical_partitions + let start = List.fold_left ( + fun total p -> + match p.p_type with + | ContentExtendedPartition -> total +^ p.p_target_start | _ -> 0L ) 0L partitions + in + (* align logical partitions, too *) + let start = roundup64 (start +^ 1L) alignment in + calculate_target_partitions 5 start ~create_surplus:false logical_partitions in + (* For GPT, the part type simply becomes partition name, so we don't * handle the case specifically. *) let mbr_part_type x @@ -1109,6 +1163,11 @@ read the man page virt-resize(1). g#part_add "/dev/sdb" (mbr_part_type p) p.p_target_start p.p_target_end ) partitions; + List.iter ( + fun p -> + g#part_add "/dev/sdb" "logical" p.p_target_start p.p_target_end + ) logical_partitions; + (* Copy over the data. *) let copy_partition p match p.p_operation with @@ -1134,18 +1193,12 @@ read the man page virt-resize(1). | ContentUnknown | ContentPV _ | ContentFS _ -> g#copy_device_to_device ~size:copysize ~sparse source target - | ContentExtendedPartition -> - (* You can't just copy an extended partition by name, eg. - * source = "/dev/sda2", because the device name only covers - * the first 1K of the partition. Instead, copy the - * source bytes from the parent disk (/dev/sda). - *) - let srcoffset = p.p_part.G.part_start in - g#copy_device_to_device ~srcoffset ~size:copysize "/dev/sda" target + | ContentExtendedPartition -> () ) | OpIgnore | OpDelete -> () in List.iter copy_partition partitions; + List.iter copy_partition logical_partitions; (* Set bootable and MBR IDs. Do this *after* copying over the data, * so that we can magically change the primary partition to an extended @@ -1169,6 +1222,7 @@ read the man page virt-resize(1). | GPT, (No_ID|MBR_ID _) | MBR, (No_ID|GPT_Type _) -> () in List.iter set_partition_bootable_and_id partitions; + List.iter set_partition_bootable_and_id logical_partitions; (* Fix the bootloader if we aligned the first partition. *) if align_first_partition_and_fix_bootloader then ( @@ -1221,6 +1275,13 @@ read the man page virt-resize(1). can_expand_content p.p_type | { p_operation = (OpCopy | OpIgnore | OpDelete) } -> false ) partitions + || + List.exists ( + function + | ({ p_operation = OpResize _ } as p) -> + can_expand_content p.p_type + | { p_operation = (OpCopy | OpIgnore | OpDelete) } -> false + ) logical_partitions || List.exists ( function | ({ lv_operation = LVOpExpand } as lv) -> @@ -1283,6 +1344,7 @@ read the man page virt-resize(1). -> () in List.iter expand_partition_content partitions; + List.iter expand_partition_content logical_partitions; (* Expand logical volume content as required. *) List.iter ( -- 1.9.3
Richard W.M. Jones
2014-Sep-22 15:48 UTC
Re: [Libguestfs] [PATCH v3 2/7] resize: simplify the code to filter parts
On Mon, Sep 22, 2014 at 03:47:35PM +0800, Hu Tao wrote:> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> > --- > resize/resize.ml | 9 ++------- > 1 file changed, 2 insertions(+), 7 deletions(-) > > diff --git a/resize/resize.ml b/resize/resize.ml > index 72c4da2..8f2105c 100644 > --- a/resize/resize.ml > +++ b/resize/resize.ml > @@ -454,13 +454,8 @@ read the man page virt-resize(1). > > (* Filter out logical partitions. See note above. *) > let parts > - match parttype with > - | GPT -> parts > - | MBR -> > - List.filter (function > - | { G.part_num = part_num } when part_num >= 5_l -> false > - | _ -> true > - ) parts in > + List.filter (fun p -> parttype <> MBR || p.G.part_num <= 4_l) > + parts in > > let partitions > List.map (ACK. I'll push this later today. Thanks, Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 100 libraries supported. http://fedoraproject.org/wiki/MinGW
Richard W.M. Jones
2014-Sep-22 15:51 UTC
Re: [Libguestfs] [PATCH v3 3/7] resize: add function find_partitions
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@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 ()) inLet'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
Richard W.M. Jones
2014-Sep-22 15:52 UTC
Re: [Libguestfs] [PATCH v3 4/7] resize: add function calculate_target_partitions
On Mon, Sep 22, 2014 at 03:47:37PM +0800, Hu Tao wrote:> And introduce parameter create_surplus to indicate whether to > create surplus partition or not. Later this parameter will be > used by when calculating positions for target logical partitions. > > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> > --- > resize/resize.ml | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/resize/resize.ml b/resize/resize.ml > index cfd02fc..8b43306 100644 > --- a/resize/resize.ml > +++ b/resize/resize.ml > @@ -1019,11 +1019,10 @@ read the man page virt-resize(1). > * the final list just contains partitions that need to be created > * on the target. > *) > - let partitions > - let rec loop partnum start = function > + let rec calculate_target_partitions partnum start ~create_surplus = function > | p :: ps -> > (match p.p_operation with > - | OpDelete -> loop partnum start ps (* skip p *) > + | OpDelete -> calculate_target_partitions partnum start ~create_surplus ps (* skip p *) > > | OpIgnore | OpCopy -> (* same size *) > (* Size in sectors. *) > @@ -1037,7 +1036,7 @@ read the man page virt-resize(1). > partnum start (end_ -^ 1L); > > { p with p_target_start = start; p_target_end = end_ -^ 1L; > - p_target_partnum = partnum } :: loop (partnum+1) next ps > + p_target_partnum = partnum } :: calculate_target_partitions (partnum+1) next ~create_surplus ps > > | OpResize newsize -> (* resized partition *) > (* New size in sectors. *) > @@ -1051,12 +1050,12 @@ read the man page virt-resize(1). > partnum newsize start (next -^ 1L); > > { p with p_target_start = start; p_target_end = next -^ 1L; > - p_target_partnum = partnum } :: loop (partnum+1) next ps > + p_target_partnum = partnum } :: calculate_target_partitions (partnum+1) next ~create_surplus ps > ) > > | [] -> > (* Create the surplus partition if there is room for it. *) > - if extra_partition && surplus >= min_extra_partition then ( > + if create_surplus && extra_partition && surplus >= min_extra_partition then ( > [ { > (* Since this partition has no source, this data is > * meaningless and not used since the operation is > @@ -1077,6 +1076,7 @@ read the man page virt-resize(1). > else > [] in > > + let partitions > (* Choose the alignment of the first partition based on the > * '--align-first' option. Old virt-resize used to always align this > * to 64 sectors, but this causes boot failures unless we are able to > @@ -1089,7 +1089,7 @@ read the man page virt-resize(1). > (* Preserve the existing start, but convert to sectors. *) > (List.hd partitions).p_part.G.part_start /^ sectsize in > > - loop 1 start partitions in > + calculate_target_partitions 1 start ~create_surplus:true partitions in > > (* Now partition the target disk. *) > List.iter ( > -- > 1.9.3Yes, this looks fine now, although the indentation is wrong for the final patch (but easier to review!) 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
Richard W.M. Jones
2014-Sep-22 15:55 UTC
Re: [Libguestfs] [PATCH v3 5/7] resize: add function mbr_part_type
On Mon, Sep 22, 2014 at 03:47:38PM +0800, Hu Tao wrote:> Function mbr_part_type returns one of "primary", "extended" and > "logical". The type is used by parted when adding partitions. > > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> > --- > resize/resize.ml | 9 ++++++++- > 1 file changed, 8 insertions(+), 1 deletion(-) > > diff --git a/resize/resize.ml b/resize/resize.ml > index 8b43306..c56a91a 100644 > --- a/resize/resize.ml > +++ b/resize/resize.ml > @@ -1091,10 +1091,17 @@ read the man page virt-resize(1). > > calculate_target_partitions 1 start ~create_surplus:true partitions in > > + (* For GPT, the part type simply becomes partition name, so we don't > + * handle the case specifically. *) > + let mbr_part_type x > + if x.p_part.G.part_num <= 4l && x.p_type <> ContentExtendedPartition then "primary" > + else if x.p_part.G.part_num <= 4l && x.p_type = ContentExtendedPartition then "extended" > + else "logical" in > + > (* Now partition the target disk. *) > List.iter ( > fun p -> > - g#part_add "/dev/sdb" "primary" p.p_target_start p.p_target_end > + g#part_add "/dev/sdb" (mbr_part_type p) p.p_target_start p.p_target_end > ) partitions; > > (* Copy over the data. *)I don't think the comment is true: $ guestfish -N disk -- \ part-init /dev/sda gpt : part-add /dev/sda "foo" 100 -100 libguestfs: error: part_add: unknown partition type: foo: this should be "primary", "logical" or "extended" The mbr_part_type function just has to be changed so it always returns "primary" is the part_type = GPT. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Richard W.M. Jones
2014-Sep-22 15:56 UTC
Re: [Libguestfs] [PATCH v3 6/7] resize: add partition type LogicalPartition
On Mon, Sep 22, 2014 at 03:47:39PM +0800, Hu Tao wrote:> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> > --- > resize/resize.ml | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/resize/resize.ml b/resize/resize.ml > index c56a91a..3f804a0 100644 > --- a/resize/resize.ml > +++ b/resize/resize.ml > @@ -75,6 +75,7 @@ and partition_id > > type partition_type > | PrimaryPartition > + | LogicalPartition > > let rec debug_partition p > eprintf "%s:\n" p.p_name; > @@ -449,13 +450,15 @@ read the man page virt-resize(1). > let find_partitions part_type > let parts = Array.to_list (g#part_list "/dev/sda") in > > - (* 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 > + | LogicalPartition -> > + List.filter (fun p -> parttype = MBR && p.G.part_num >= 5_l) > parts in > > let partitions > @@ -518,10 +521,12 @@ read the man page virt-resize(1). > partitions in > > let partitions = find_partitions PrimaryPartition in > + let logical_partitions = find_partitions LogicalPartition in > > if verbose then ( > - eprintf "%d partitions found\n" (List.length partitions); > - List.iter debug_partition partitions > + eprintf "%d partitions found\n" (List.length partitions + List.length logical_partitions); > + List.iter debug_partition partitions; > + List.iter debug_partition logical_partitions > ); > > (* Build a data structure describing LVs on the source disk. *) > -- > 1.9.3This looks fine now. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Richard W.M. Jones
2014-Sep-22 15:58 UTC
Re: [Libguestfs] [PATCH v3 7/7] resize: add support to resize logical partitions
I'm going to have to test the heck out of patch 07 to really understand what it is doing and whether it works. Our current virt-resize test suite isn't really up to the job. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Possibly Parallel Threads
- [PATCH V5 0/4] virt-resize: add support for resizing logical
- [PATCH v5 REBASE 0/4] virt-resize: add support for resizing logical
- [PATCH v2 00/13] virt-resize: add support for resizing MBR logical partitions
- [PATCH v3 00/11] virt-resize: add support for resizing MBR logical partitions
- [PATCH v4 00/11] virt-resize: add support for resizing MBR logical partitions