Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 00/11] virt-resize: add support for resizing MBR logical partitions
In current virt-resize, only primary partitions(including extended partition) are supported. They are collected in an array for resize operations. Logical partitions are not supported. This series add support for resizing logical partitions. v4: rebase on upstream. v3: 1) rewrite partitions/logical_partitions/extended_partition section by the comments from Rich and Pino. 2) in 03/11 introduce logical_align for reserve enough space when resizing logical/extended partitions. v2: 1) Add 3 variables to describe relationship of logical and extended partitions: - partitions flat list of primary partitions (as now, the global 'partitions'). extended partitions is essentially primary partition - logical_partitions flat list of logical partitions - extended_partition one MBR extended partition 2) reserve enough size when resizing logical partitions Original patches by Hu Tao at: https://www.redhat.com/archives/libguestfs/2014-October/msg00238.html Chen Hanxiao (11): resize: move loop check from find_partitions resize: add logical_partitions and extended_partition resize: calculate max alignment of logical partitions resize: add support for logical partitions for calculate_surplus resize: handle resize of logical partitions resize: add support for logical partitions of calculate_target_partitions resize: calculate_target_partitions for logical partitions resize: parted and copy logical partitions resize: more misc ops on logical partition resize: add support resize extended partition resize: test: add support for resizing extended and logical partitions resize/resize.ml | 220 +++++++++++++++++++++++++++++++++++---------- resize/test-virt-resize.pl | 32 ++----- 2 files changed, 179 insertions(+), 73 deletions(-) -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 01/11] resize: move loop check from find_partitions
As logical partitions laid inside extended partition, overlap check will not work. make loop as a individual function, which could do a seperate check on logical/extended partitions. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 101b303..65464eb 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -521,20 +521,20 @@ read the man page virt-resize(1). | _ -> () ) partitions; - (* Check partitions don't overlap. *) - let rec loop end_of_prev = function - | [] -> () - | { p_name = name; p_part = { G.part_start = part_start } } :: _ - when end_of_prev > part_start -> - error (f_"%s: this partition overlaps the previous one") name - | { p_part = { G.part_end = part_end } } :: parts -> loop part_end parts - in - loop 0L partitions; - partitions in let partitions = find_partitions () in + (* Check partitions don't overlap. *) + let rec loop end_of_prev = function + | [] -> () + | { p_name = name; p_part = { G.part_start = part_start } } :: _ + when end_of_prev > part_start -> + error (f_"%s: this partition overlaps the previous one") name + | { p_part = { G.part_end = part_end } } :: parts -> loop part_end parts + in + loop 0L partitions; + if verbose () then ( printf "%d partitions found\n" (List.length partitions); List.iter (debug_partition ~sectsize) partitions -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 02/11] resize: add logical_partitions and extended_partition
For MBR, logical partitions laid inside extended partition. Add 3 variables to describe this: - partitions flat list of primary partitions (as now, the global 'partitions'). extended partitions is essentially primary partition - logical_partitions flat list of logical partitions - extended_partition one MBR extended partition Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- v3: rewrite partitions/logical_partitions/extended_partition according to Rich and Pino's commnets resize/resize.ml | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 65464eb..f4cc588 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -32,13 +32,7 @@ type align_first_t = [ `Never | `Always | `Auto ] (* Source partition type. *) type parttype = MBR | GPT -(* Data structure describing the source disk's partition layout. - * - * NOTE: For MBR, only primary/extended partitions are tracked here. - * Logical partitions are contained within an extended partition, and - * we don't track them (they are just copied within the extended - * partition). For the same reason we cannot resize logical partitions. - *) +(* Data structure describing the source disk's partition layout. *) type partition = { p_name : string; (* Device name, like /dev/sda1. *) p_part : G.partition; (* SOURCE partition data from libguestfs. *) @@ -496,12 +490,6 @@ read the man page virt-resize(1). p_target_start = 0L; p_target_end = 0L } ) parts in - (* Filter out logical partitions. See note above. *) - let partitions - (* for GPT, all partitions are regarded as Primary Partition, - * e.g. there is no Extended Partition or Logical Partition. *) - List.filter (fun p -> parttype <> MBR || p.p_mbr_p_type <> LogicalPartition) partitions in - (* 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. @@ -533,11 +521,35 @@ read the man page virt-resize(1). error (f_"%s: this partition overlaps the previous one") name | { p_part = { G.part_end = part_end } } :: parts -> loop part_end parts in + + let extended_partition_list + List.filter (fun p -> parttype = MBR && p.p_mbr_p_type = ExtendedPartition) partitions in + let extended_partition + match extended_partition_list with + | h :: _ -> Some h + | [] -> None in + + let is_logical_partition p + parttype = MBR && p.p_mbr_p_type = LogicalPartition + in + + let logical_partitions, partitions + List.partition is_logical_partition partitions in + + let nr_logical = List.length logical_partitions in + loop 0L partitions; + loop 0L logical_partitions; if verbose () then ( - printf "%d partitions found\n" (List.length partitions); - List.iter (debug_partition ~sectsize) partitions + printf "%d partitions found\n" + (List.length partitions + List.length logical_partitions); + List.iter (debug_partition ~sectsize) partitions; + List.iter (debug_partition ~sectsize) logical_partitions; + match extended_partition with + | Some v -> printf "%s is extended partition\n" + (List.hd extended_partition_list).p_name + | None -> () ); (* Build a data structure describing LVs on the source disk. *) @@ -603,6 +615,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 -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 03/11] resize: calculate max alignment of logical partitions
If a logical/extended partition is resized, we had to re-calculate all the position of logical partitions. For logical partitions can't be placed just next to each other, we had to think about the loss of the size because of the alignment of recalculation. This patch will calculate a max number to ensure a successfull parted. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index f4cc588..7aa1c96 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -820,6 +820,23 @@ read the man page virt-resize(1). ) ); + (* filter out logical partitions for OpResize *) + let logical_resize = List.filter ( + fun p -> + match p.p_operation with + | OpResize _ -> true + | OpCopy | OpIgnore | OpDelete -> false + ) logical_partitions in + + (* calculate the max logical partition alignment *) + let logical_align + if (List.length logical_resize) > 0 then + ((Int64.of_int nr_logical) -^ 1L) *^ alignment + else + 0L in + if verbose () then + printf "Max alignment loss of logical partition is %Ld\n" logical_align; + (* Calculate the final surplus. * At this point, this number must be >= 0. *) -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 04/11] resize: add support for logical partitions for calculate_surplus
Add support for logical partitions. - add max_logi_align for calculate_surplus If we resize logical partition, we will lose size becasue of alignment. max_logi_align shows the max loss for alignment, which can ensure a successfully resize - don't count size of extended partition For it'll duplicate with logical partition, we'll count it later - we need at leat 1 gap between logical partitions. so --aligment=1 will be increased by 1 Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- v3: introduce max_logi_align for calculate_surplus resize/resize.ml | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 7aa1c96..6974869 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -736,10 +736,12 @@ read the man page virt-resize(1). * the size of the target disk. If the return value >= 0 then it's * a surplus, if it is < 0 then it's a deficit. *) - let calculate_surplus () + let calculate_surplus max_logi_align (* We need some overhead for partitioning. *) let overhead let maxl64 = List.fold_left max 0L in + (* We need at least 1 sector gap between logical partitions *) + let alignment = if alignment = 1L then 2L else alignment in let nr_partitions = List.length partitions in @@ -769,12 +771,29 @@ read the man page virt-resize(1). let required = List.fold_left ( fun total p -> let newsize + (* size of extended partition is calculated seperately *) + 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_logical = 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 required_logical + (* an extra alignment for the gap between extended and 1st logical *) + required_logical +^ (max_logi_align +^ alignment) *^sectsize in + let required = required +^ required_logical in let surplus = outsize -^ (required +^ overhead) in @@ -790,7 +809,7 @@ read the man page virt-resize(1). error (f_"you cannot use options --expand and --shrink together"); if expand <> None || shrink <> None then ( - let surplus = calculate_surplus () in + let surplus = calculate_surplus 0L in if verbose () then printf "surplus before --expand or --shrink: %Ld\n" surplus; @@ -841,7 +860,7 @@ read the man page virt-resize(1). * At this point, this number must be >= 0. *) let surplus - let surplus = calculate_surplus () in + let surplus = calculate_surplus logical_align in if surplus < 0L then ( let deficit = Int64.neg surplus in -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 05/11] resize: handle resize of logical partitions
This will re-calculate the size of logical partitions. and take logical partitions' aligment into account. If needed, update extended partition's OpResize. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index 6974869..22e3559 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -856,6 +856,36 @@ read the man page virt-resize(1). if verbose () then printf "Max alignment loss of logical partition is %Ld\n" logical_align; + (* handle resizing of logical partitions + * If we resized logical partitions, + * we may need to resize extended partition too. + * *) + 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 + (* the start of logical partitions is aligned *) + | OpCopy | OpIgnore -> total +^ p.p_part.G.part_size + | OpResize newsize -> total +^ newsize + ) 0L logical_partitions in + + (* the first logical partition is aligned *) + let logical_sizes = logical_sizes +^ alignment *^ sectsize in + let logical_sizes + roundup64 (logical_sizes +^ logical_align *^ sectsize) (alignment *^ sectsize) in + if logical_sizes > size then + p.p_operation <- OpResize logical_sizes + (* no need to touch the extended partition + * if new logical sizes less than the original size + * *) + ) + ) partitions; + (* Calculate the final surplus. * At this point, this number must be >= 0. *) @@ -924,6 +954,7 @@ read the man page virt-resize(1). wrap (text ^ "\n\n") in List.iter print_summary partitions; + List.iter print_summary logical_partitions; List.iter ( fun ({ lv_name = name } as lv) -> -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 06/11] resize: add support for logical partitions of calculate_target_partitions
This patch add support for logical partitions. 1) OpResize newsize: an additional parameter for resizing logical partitions: - gap_start For logical partitions, we had to reserce at least 1 gap between each other. Also, we may had an extra aligment between 1st logical partition and extended partition. We need to remove gap_start from 'OpResize newsize' 2) OpIgnore | OpCopy: If in logical partition, add an extra alignment of 1 sector. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 22e3559..5deaa74 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1131,13 +1131,17 @@ read the man page virt-resize(1). * the final list just contains partitions that need to be created * on the target. *) - let rec calculate_target_partitions partnum start ~create_surplus = function + let rec calculate_target_partitions partnum start ~create_surplus ?(gap_start=0L) = function | p :: ps -> (match p.p_operation with | OpDelete -> calculate_target_partitions partnum start ~create_surplus ps (* skip p *) | OpIgnore | OpCopy -> (* same size *) + (* add an extra gap for logical partitions *) + let alg = if p.p_mbr_p_type = LogicalPartition then 1L else 0L in + let start = roundup64 (start +^ alg) 2L in + (* Size in sectors. *) let size = div_roundup64 p.p_part.G.part_size sectsize in (* Start of next partition + alignment. *) @@ -1150,13 +1154,24 @@ read the man page virt-resize(1). { p with p_target_start = start; p_target_end = end_ -^ 1L; p_target_partnum = partnum } :: - calculate_target_partitions (partnum+1) next ~create_surplus ps + calculate_target_partitions (partnum+1) next ~create_surplus ~gap_start ps | OpResize newsize -> (* resized partition *) + (* add an extra gap for logical partitions *) + let alg = if p.p_mbr_p_type = LogicalPartition then 1L else 0L in + + let start = roundup64 start 2L in (* New size in sectors. *) let size = div_roundup64 newsize sectsize in + (* remove gap_start from size *) + let size = size -^ gap_start in + (* remove max alignment between logical partitions *) + let size = size -^ logical_align in (* Start of next partition + alignment. *) let next = start +^ size in + (* We will reserve a 1-sector gap between logical partitions + * by decreasing current partition by 1 sector, see below. *) + let next = next -^ alg in let next = roundup64 next alignment in if verbose () then -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 07/11] resize: calculate_target_partitions for logical partitions
Pass gap_start to calculate_target_partitions when calculating logical partitions. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/resize/resize.ml b/resize/resize.ml index 5deaa74..7d99b38 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1223,9 +1223,24 @@ 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 + | _ -> total +^ 0L + ) 0L partitions in + + let gap_start = (roundup64 (start +^ 1L) alignment) -^ start in + (* align logical partitions, too *) + let start = roundup64 (start +^ 1L) alignment in + + calculate_target_partitions 5 start ~create_surplus:false ~gap_start logical_partitions in + if verbose () then ( printf "After calculate target partitions:\n"; - List.iter (debug_partition ~sectsize) partitions + List.iter (debug_partition ~sectsize) partitions; + List.iter (debug_partition ~sectsize) logical_partitions ); let mbr_part_type x -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 08/11] resize: parted and copy logical partitions
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 7d99b38..b4236ab 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1258,6 +1258,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 @@ -1282,24 +1287,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). - * - * You can't write directly to the extended partition, - * because the size of it reported by Linux is always 1024 - * bytes. Instead, write to the offset of the extended - * partition in the destination disk (/dev/sdb). - *) - let srcoffset = p.p_part.G.part_start in - let destoffset = p.p_target_start *^ 512L in - g#copy_device_to_device ~srcoffset ~destoffset ~size:copysize "/dev/sda" "/dev/sdb" + | 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 -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 09/11] resize: more misc ops on logical partition
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index b4236ab..000a4f8 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1322,6 +1322,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 ( @@ -1373,6 +1374,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) -> @@ -1434,6 +1442,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 ( -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 10/11] resize: add support resize extended partition
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 000a4f8..9dfa21e 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -768,18 +768,6 @@ read the man page virt-resize(1). start_overhead_sects +^ alignment_sects +^ gpt_end_sects in sectsize *^ overhead_sects in - let required = List.fold_left ( - fun total p -> - let newsize - (* size of extended partition is calculated seperately *) - 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_logical = List.fold_left ( fun total p -> let newsize @@ -793,7 +781,34 @@ read the man page virt-resize(1). let required_logical (* an extra alignment for the gap between extended and 1st logical *) required_logical +^ (max_logi_align +^ alignment) *^sectsize in - let required = required +^ required_logical in + + let required_extended = List.fold_left ( + fun total p -> + let newsize + match p.p_type with + | ContentExtendedPartition -> + (* resizing extended partition by --resize or --expand is supported *) + (match p.p_operation with + | OpResize newsize -> newsize + | _ -> p.p_part.G.part_size) + | _ -> 0L in + total +^ newsize + ) 0L partitions in + + let required = List.fold_left ( + fun total p -> + let newsize + (* size of extended partition is calculated seperately *) + 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 +^ if required_extended > required_logical + then required_extended else required_logical in let surplus = outsize -^ (required +^ overhead) in -- 2.1.0
Chen Hanxiao
2015-Jul-06 10:14 UTC
[Libguestfs] [PATCH rebase v4 11/11] resize: test: add support for resizing extended and logical partitions
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/test-virt-resize.pl | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/resize/test-virt-resize.pl b/resize/test-virt-resize.pl index be9c9b4..85ed1b2 100755 --- a/resize/test-virt-resize.pl +++ b/resize/test-virt-resize.pl @@ -75,13 +75,6 @@ if (rand () <= 0.5) { # an extended partition (#4) and zero or more logical partitions. my $nr_parts = 1 + int (rand (7)); -# XXX Temporarily restriction XXX -# Currently virt-resize is broken when dealing with any extended -# partition, so don't test this for the moment. -if ($part_type eq "mbr" && $nr_parts >= 4) { - $nr_parts = 3; -} - # expand (1) or shrink (0) my $expand = 0; if (rand () >= 0.2) { @@ -120,31 +113,16 @@ my $i; for ($i = 1; $i <= $nr_parts; ++$i) { $parts[$i] = { name => "sda".$i, resize => 0 }; - if ($part_type eq "mbr") { - if ($i < 4) { - if (rand () < 0.5) { - $parts[$i]->{resize} = 1; - } - } elsif ($i == 4) { + if ($part_type eq "mbr" && $i == 4) { $parts[$i]->{content} = "extended"; - } - } else { - if (rand () < 0.5) { - $parts[$i]->{resize} = 1; - } + } + if (rand () < 0.5) { + $parts[$i]->{resize} = 1; } } # Pick a partition at random to expand or shrink. -if ($part_type eq "mbr") { - # virt-resize cannot shrink extended or logical partitions, so we - # set $max so that these cannot be chosen: - my $max = 3; - $max = $nr_parts if $max > $nr_parts; - $i = 1 + int (rand ($max)); -} else { - $i = 1 + int (rand ($nr_parts)); -} +$i = 1 + int (rand ($nr_parts)); $parts[$i]->{resize} = 0; $parts[$i]->{expand_shrink} = 1; -- 2.1.0
Chen, Hanxiao
2015-Jul-08 10:56 UTC
Re: [Libguestfs] [PATCH rebase v4 00/11] virt-resize: add support for resizing MBR logical partitions
> -----Original Message----- > From: libguestfs-bounces@redhat.com [mailto:libguestfs-bounces@redhat.com] On > Behalf Of Chen Hanxiao > Sent: Monday, July 06, 2015 6:14 PM > To: libguestfs@redhat.com > Subject: [Libguestfs] [PATCH rebase v4 00/11] virt-resize: add support for resizing > MBR logical partitions > > In current virt-resize, only primary partitions(including > extended partition) are supported. They are collected in an > array for resize operations. Logical partitions are not > supported. > > This series add support for resizing logical partitions. > > v4: > rebase on upstream. > > v3: > 1) rewrite partitions/logical_partitions/extended_partition section > by the comments from Rich and Pino. > 2) in 03/11 introduce logical_align for reserve enough space > when resizing logical/extended partitions. > > v2: > 1) Add 3 variables to describe relationship of logical and extended partitions: > - partitions > flat list of primary partitions (as now, the global 'partitions'). > extended partitions is essentially primary partition > - logical_partitions > flat list of logical partitions > - extended_partition > one MBR extended partition > > 2) reserve enough size when resizing logical partitions > > Original patches by Hu Tao at: > https://www.redhat.com/archives/libguestfs/2014-October/msg00238.html > > Chen Hanxiao (11): > resize: move loop check from find_partitions > resize: add logical_partitions and extended_partition > resize: calculate max alignment of logical partitions > resize: add support for logical partitions for calculate_surplus > resize: handle resize of logical partitions > resize: add support for logical partitions of > calculate_target_partitions > resize: calculate_target_partitions for logical partitions > resize: parted and copy logical partitions > resize: more misc ops on logical partition > resize: add support resize extended partition > resize: test: add support for resizing extended and logical partitions > > resize/resize.ml | 220 +++++++++++++++++++++++++++++++++++---------- > resize/test-virt-resize.pl | 32 ++----- > 2 files changed, 179 insertions(+), 73 deletions(-) > > -- > 2.1.0 >ping Regards, - Chen
Chen, Hanxiao
2015-Jul-10 06:01 UTC
Re: [Libguestfs] [PATCH rebase v4 00/11] virt-resize: add support for resizing MBR logical partitions
> -----Original Message----- > From: Chen, Hanxiao > Sent: Wednesday, July 08, 2015 6:57 PM > To: Chen, Hanxiao; libguestfs@redhat.com > Subject: RE: [Libguestfs] [PATCH rebase v4 00/11] virt-resize: add support for > resizing MBR logical partitions > > > > > -----Original Message----- > > From: libguestfs-bounces@redhat.com [mailto:libguestfs-bounces@redhat.com] On > > Behalf Of Chen Hanxiao > > Sent: Monday, July 06, 2015 6:14 PM > > To: libguestfs@redhat.com > > Subject: [Libguestfs] [PATCH rebase v4 00/11] virt-resize: add support for resizing > > MBR logical partitions > >[snip]> > -- > > 2.1.0 > > > > ping > > Regards, > - ChenHi, Rich Do we have a plan for reviewing this series? Regards, - Chen
Possibly Parallel Threads
- [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
- [PATCH v2 00/11] virt-resize: add support for resizing MBR logical partitions
- [PATCH V5 0/4] virt-resize: add support for resizing logical
- [PATCH v5 REBASE 0/4] virt-resize: add support for resizing logical