[PATCH 00/10] 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. Original patches by Hu Tao at: https://www.redhat.com/archives/libguestfs/2014-October/msg00238.html Chen Hanxiao (10): resize: don't filter out logical partitions resize: don't count new size of logical and extended partition resize: caculate the size of logical partitions resize: update calculate_target_partitions for logical partitions resize: calculate location of the partitions of logical partition resize: skip overlap check for logical partitions resize: parted logical partitions resize: caculate surplus for resize extended partition resize: support resize extended partition resize: test: add support for resizing extended and logical partitions resize/resize.ml | 144 ++++++++++++++++++++++++++++++++++----------- resize/test-virt-resize.pl | 32 ++-------- 2 files changed, 114 insertions(+), 62 deletions(-) -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 8e69d44..42d39c9 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -36,13 +36,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. *) @@ -504,12 +498,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. -- 2.1.0
It will should be count seperately later. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 42d39c9..9b4b49f 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -755,10 +755,12 @@ read the man page virt-resize(1). let 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 + (* size of extended partition and logical partition is calculated seperately *) + if p.p_type = ContentExtendedPartition || p.p_mbr_p_type = LogicalPartition 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 -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index 9b4b49f..d793e50 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -808,6 +808,34 @@ read the man page virt-resize(1). ) ); + (* caculate the size of logical partitions *) + let logical_sizes = List.fold_left ( + fun total p -> + if p.p_mbr_p_type <> LogicalPartition then 0L else + match p.p_operation with + | OpDelete -> total +^ 0L + (* the start of logical partitions is aligned *) + | OpCopy | OpIgnore -> total +^ (roundup64 p.p_part.G.part_size (alignment *^ sectsize)) + | OpResize newsize -> total +^ (roundup64 newsize (alignment *^ sectsize)) + ) 0L partitions in + + (* 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 + (* resizing extended partition by --resize or --expand is supported *) + let size = match p.p_operation with OpResize s -> s | _ -> size in + (* the first logical partition is aligned *) + let logical_sizes_align = logical_sizes +^ alignment *^ sectsize in + if logical_sizes_align > size then + p.p_operation <- OpResize logical_sizes_align + (* don't touch the extended partition if logical sizes less + * than the original size *) + ) + ) partitions; + (* Calculate the final surplus. * At this point, this number must be >= 0. *) -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/resize/resize.ml b/resize/resize.ml index d793e50..6221254 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1067,6 +1067,7 @@ read the man page virt-resize(1). 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. *) @@ -1082,17 +1083,25 @@ read the man page virt-resize(1). 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. *) let next = start +^ size in let next = roundup64 next alignment in + (* We will reserve a 1-sector gap between logical partitions + * by decreasing current partition by 1 sector, see below. + * But in case of shrink, we must ensure new partition size no + * less than newsize, thus make it one alignment-sectors larger. *) + let next = next +^ alignment in if verbose then printf "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 ) -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index 6221254..218eb44 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1131,6 +1131,13 @@ read the man page virt-resize(1). [] in + (* logical partitions's start have to treat specially. + * So we have to split partitions to two parts *) + let logical_partitions = + List.filter (fun p -> p.p_mbr_p_type = LogicalPartition) partitions in + let partitions = + List.filter (fun p -> parttype <> MBR || p.p_mbr_p_type <> LogicalPartition) partitions in + let partitions = (* Choose the alignment of the first partition based on the * '--align-first' option. Old virt-resize used to always align this @@ -1146,6 +1153,18 @@ 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 + + (* align logical partitions, too *) + let start = roundup64 (start +^ 1L) alignment in + calculate_target_partitions 5 start ~create_surplus:false logical_partitions in + let mbr_part_type x = match parttype, x.p_part.G.part_num <= 4_l, x.p_type with (* for GPT, all partitions are regarded as Primary Partition. *) -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 218eb44..12bc8e9 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -520,8 +520,9 @@ read the man page virt-resize(1). (* 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 -> + (* skip logical partitions overlap check for it's inside extended partition *) + | { p_name = name; p_part = { G.part_start = part_start }; p_mbr_p_type = p_mbr_part_type } :: _ + when p_mbr_part_type <> LogicalPartition && 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 -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resize/resize.ml b/resize/resize.ml index 12bc8e9..d5c457c 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1181,6 +1181,14 @@ 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; + + (* combine logical partitions and others together after parted *) + let partitions = partitions @ logical_partitions in + (* Copy over the data. *) let copy_partition p = match p.p_operation with -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/resize/resize.ml b/resize/resize.ml index d5c457c..67321c2 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -727,6 +727,7 @@ 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 @@ -753,6 +754,31 @@ read the man page virt-resize(1). start_overhead_sects +^ alignment_sects +^ gpt_end_sects in sectsize *^ overhead_sects in + let required_logical = List.fold_left ( + fun total p -> + if p.p_mbr_p_type <> LogicalPartition then 0L else + let newsize = + match p.p_operation with + | OpCopy | OpIgnore -> roundup64 p.p_part.G.part_size (alignment *^ sectsize) + | OpDelete -> 0L + | OpResize newsize -> roundup64 newsize (alignment *^ sectsize) in + total +^ newsize + ) 0L partitions in + + let required_logical = required_logical +^ alignment *^ sectsize 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 = @@ -765,13 +791,19 @@ read the man page virt-resize(1). 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 if verbose then printf "calculate surplus: outsize=%Ld required=%Ld overhead=%Ld surplus=%Ld\n%!" outsize required overhead surplus; - surplus + (* XXX: fix of expanding a logical partition. without the sectsize, + * we'll get a deficit of 512 bytes. *) + surplus +^ sectsize in (* Handle --expand and --shrink options. *) -- 2.1.0
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- resize/resize.ml | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/resize/resize.ml b/resize/resize.ml index 67321c2..146c170 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -1245,20 +1245,7 @@ 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 -- 2.1.0
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
On Thu, Apr 23, 2015 at 02:14:12AM -0400, Chen Hanxiao wrote:
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.
Original patches by Hu Tao at: https://www.redhat.com/archives/libguestfs/2014-October/msg00238.html
Chen Hanxiao (10): resize: don't filter out logical partitions resize: don't count new size of logical and extended partition resize: caculate the size of logical partitions resize: update calculate_target_partitions for logical partitions resize: calculate location of the partitions of logical partition resize: skip overlap check for logical partitions resize: parted logical partitions resize: caculate surplus for resize extended partition resize: support resize extended partition resize: test: add support for resizing extended and logical partitions
resize/resize.ml | 144 ++++++++++++++++++++++++++++++++++----------- resize/test-virt-resize.pl | 32 ++-------- 2 files changed, 114 insertions(+), 62 deletions(-)
No, this patch series cannot be applied. It doesn't model what extended / logical partitions look like. It's very hard to understand what changes are being made. The commits are not grouped in a way that makes them easily understandable 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-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Hi, Rich
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Monday, April 27, 2015 10:01 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 00/10] virt-resize: add support for resizing MBR logical partitions
On Thu, Apr 23, 2015 at 02:14:12AM -0400, Chen Hanxiao wrote:
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.
Original patches by Hu Tao at: https://www.redhat.com/archives/libguestfs/2014-October/msg00238.html
Chen Hanxiao (10): resize: don't filter out logical partitions resize: don't count new size of logical and extended partition resize: caculate the size of logical partitions resize: update calculate_target_partitions for logical partitions resize: calculate location of the partitions of logical partition resize: skip overlap check for logical partitions resize: parted logical partitions resize: caculate surplus for resize extended partition resize: support resize extended partition resize: test: add support for resizing extended and logical partitions
resize/resize.ml | 144 ++++++++++++++++++++++++++++++++++----------- resize/test-virt-resize.pl | 32 ++-------- 2 files changed, 114 insertions(+), 62 deletions(-)
No, this patch series cannot be applied.
It doesn't model what extended / logical partitions look like.
commit 6e989fd709fea37430398cbb7c01c52cd44bd1ac already did this: we had p_mbr_p_type : partition_type in type partition. Like what MBR/EBR did, this patchset use `partition_type`: /dev/sda3: partition data: 3 210763776-420478975 (209715200 bytes) bootable: false partition ID: 0x5 content: extended partition label: (none) GUID: (none) *partition type: extended* /dev/sda5: partition data: 5 211812352-222298111 (10485760 bytes) bootable: false partition ID: 0x83 content: unknown data label: (none) GUID: (none) *partition type: logical* As we could only had one extended partition, all logical partitions belong to that extended partition, so current type partition of virt-resize can reflect logical/extended partition model.
It's very hard to understand what changes are being made. The commits are not grouped in a way that makes them easily understandable to me.
I'll try to regroup them and make the patchset easy to review. Regards, - Chen
On Wed, Apr 29, 2015 at 09:19:24AM +0000, Chen, Hanxiao wrote:
commit 6e989fd709fea37430398cbb7c01c52cd44bd1ac already did this: we had p_mbr_p_type : partition_type in type partition. Like what MBR/EBR did, this patchset use `partition_type`:
/dev/sda3: partition data: 3 210763776-420478975 (209715200 bytes) bootable: false partition ID: 0x5 content: extended partition label: (none) GUID: (none) *partition type: extended* /dev/sda5: partition data: 5 211812352-222298111 (10485760 bytes) bootable: false partition ID: 0x83 content: unknown data label: (none) GUID: (none) *partition type: logical*
As we could only had one extended partition, all logical partitions belong to that extended partition, so current type partition of virt-resize can reflect logical/extended partition model.
The specific problem is that the extended partition (eg /dev/sda3) contains the logical partition (/dev/sda5). Having a flat list doesn't express that at all. I agree it is very hard to express this, because extended partitions just work so differently from how any sensible partition scheme should work (because they are a big hack). But perhaps: - flat list of primary partitions (as now, the global 'partitions') - one MBR extended partition (as a new global variable) - flat list of logical partitions would do it? It still has the problem that the extended partition is a bit like a primary partition, yet isn't in the partitions list.
It's very hard to understand what changes are being made. The commits are not grouped in a way that makes them easily understandable to me.
I'll try to regroup them and make the patchset easy to review.
Thanks, 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
Hi, Rich
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Wednesday, April 29, 2015 7:04 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 00/10] virt-resize: add support for resizing MBR logical partitions
On Wed, Apr 29, 2015 at 09:19:24AM +0000, Chen, Hanxiao wrote:
commit 6e989fd709fea37430398cbb7c01c52cd44bd1ac already did this: we had p_mbr_p_type : partition_type in type partition. Like what MBR/EBR did, this patchset use `partition_type`:
/dev/sda3: partition data: 3 210763776-420478975 (209715200 bytes) bootable: false partition ID: 0x5 content: extended partition label: (none) GUID: (none) *partition type: extended* /dev/sda5: partition data: 5 211812352-222298111 (10485760 bytes) bootable: false partition ID: 0x83 content: unknown data label: (none) GUID: (none) *partition type: logical*
As we could only had one extended partition, all logical partitions belong to that extended partition, so current type partition of virt-resize can reflect logical/extended partition model.
The specific problem is that the extended partition (eg /dev/sda3) contains the logical partition (/dev/sda5). Having a flat list doesn't express that at all.
We had at most 4 PTE in MBR, in PTE, a partition type is on +04h, value 05h or 0fh shows it's an extended partition.
From extended partition's EBR, we got logical partitions.
sda1-- sda2 -- sda3 -- sda4 ^ | sda5 -- sda6 I think we do not need to show this specially, just use the original design: logical partitions existed in extended partition, an implicit relations. So a flat list can do this: We mark each members, then a tree view above could be rebuilt precisely from plat list. In this patchset, logical partitions are not filter out, it did: 1) partitions list: sda1 sda2 sda3 sda5 every member of partitions got a member `partition type` 2) calculate surplus 3) then filter out logical partitions list: logical_partitions: sda5 partitions: sda1 sda2 sda3 do something to it (calculate_target_partitions...) 4) part_add to 'non-logical' partitions and logical partitions, then concrete them together for the original partition list. 5) copy_partition (ignore extended partitions, for we had logical partition in partitions list, we copy data from there)
I agree it is very hard to express this, because extended partitions just work so differently from how any sensible partition scheme should work (because they are a big hack). But perhaps:
- flat list of primary partitions (as now, the global 'partitions')
members of partitions list whose partition type is 'primary'
- one MBR extended partition (as a new global variable)
member of partitions list whose partition type is 'extended'.
- flat list of logical partitions
members of partitions list whose partition type is 'logical'. So I think we do not need 2 list and a global variable, if we want to know something, just do a List.filter.
would do it? It still has the problem that the extended partition is a bit like a primary partition, yet isn't in the partitions list.
For the point of PTE's view, it does. PS: In my patch, it's in partitions list :) Regards - Chen
It's very hard to understand what changes are being made. The commits are not grouped in a way that makes them easily understandable to me.
I'll try to regroup them and make the patchset easy to review.
Thanks,
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
On 04/30/2015 06:51 PM, Chen, Hanxiao wrote:
Hi, Rich
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Wednesday, April 29, 2015 7:04 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 00/10] virt-resize: add support for resizing MBR logical partitions
On Wed, Apr 29, 2015 at 09:19:24AM +0000, Chen, Hanxiao wrote:
commit 6e989fd709fea37430398cbb7c01c52cd44bd1ac already did this: we had p_mbr_p_type : partition_type in type partition. Like what MBR/EBR did, this patchset use `partition_type`:
/dev/sda3: partition data: 3 210763776-420478975 (209715200 bytes) bootable: false partition ID: 0x5 content: extended partition label: (none) GUID: (none) *partition type: extended* /dev/sda5: partition data: 5 211812352-222298111 (10485760 bytes) bootable: false partition ID: 0x83 content: unknown data label: (none) GUID: (none) *partition type: logical*
As we could only had one extended partition, all logical partitions belong to that extended partition, so current type partition of virt-resize can reflect logical/extended partition model.
The specific problem is that the extended partition (eg /dev/sda3) contains the logical partition (/dev/sda5). Having a flat list doesn't express that at all. We had at most 4 PTE in MBR, in PTE, a partition type is on +04h, value 05h or 0fh shows it's an extended partition. From extended partition's EBR, we got logical partitions.
sda1-- sda2 -- sda3 -- sda4 ^ | sda5 -- sda6
I think we do not need to show this specially, just use the original design: logical partitions existed in extended partition, an implicit relations.
So a flat list can do this: We mark each members, then a tree view above could be rebuilt precisely from plat list. Hi, Rich
Any comments on this? Regards, - Chen
In this patchset, logical partitions are not filter out, it did:
1) partitions list: sda1 sda2 sda3 sda5 every member of partitions got a member `partition type`
2) calculate surplus
3) then filter out logical partitions list: logical_partitions: sda5 partitions: sda1 sda2 sda3 do something to it (calculate_target_partitions...)
4) part_add to 'non-logical' partitions and logical partitions, then concrete them together for the original partition list.
5) copy_partition (ignore extended partitions, for we had logical partition in partitions list, we copy data from there)
I agree it is very hard to express this, because extended partitions just work so differently from how any sensible partition scheme should work (because they are a big hack). But perhaps:
- flat list of primary partitions (as now, the global 'partitions') members of partitions list whose partition type is 'primary' - one MBR extended partition (as a new global variable) member of partitions list whose partition type is 'extended'.
- flat list of logical partitions members of partitions list whose partition type is 'logical'.
So I think we do not need 2 list and a global variable, if we want to know something, just do a List.filter.
would do it? It still has the problem that the extended partition is a bit like a primary partition, yet isn't in the partitions list. For the point of PTE's view, it does. PS: In my patch, it's in partitions list :)
Regards - Chen
It's very hard to understand what changes are being made. The commits are not grouped in a way that makes them easily understandable to me. I'll try to regroup them and make the patchset easy to review. Thanks,
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
On Fri, May 08, 2015 at 10:26:22PM +0800, Chen Hanxiao wrote:
On 04/30/2015 06:51 PM, Chen, Hanxiao wrote:
Hi, Rich
-----Original Message----- From: Richard W.M. Jones [mailto:rjones@redhat.com] Sent: Wednesday, April 29, 2015 7:04 PM To: Chen, Hanxiao/陈 晗霄 Cc: libguestfs@redhat.com Subject: Re: [Libguestfs] [PATCH 00/10] virt-resize: add support for resizing MBR logical partitions
On Wed, Apr 29, 2015 at 09:19:24AM +0000, Chen, Hanxiao wrote:
commit 6e989fd709fea37430398cbb7c01c52cd44bd1ac already did this: we had p_mbr_p_type : partition_type in type partition. Like what MBR/EBR did, this patchset use `partition_type`:
/dev/sda3: partition data: 3 210763776-420478975 (209715200 bytes) bootable: false partition ID: 0x5 content: extended partition label: (none) GUID: (none) *partition type: extended* /dev/sda5: partition data: 5 211812352-222298111 (10485760 bytes) bootable: false partition ID: 0x83 content: unknown data label: (none) GUID: (none) *partition type: logical*
As we could only had one extended partition, all logical partitions belong to that extended partition, so current type partition of virt-resize can reflect logical/extended partition model.
The specific problem is that the extended partition (eg /dev/sda3) contains the logical partition (/dev/sda5). Having a flat list doesn't express that at all. We had at most 4 PTE in MBR, in PTE, a partition type is on +04h, value 05h or 0fh shows it's an extended partition. From extended partition's EBR, we got logical partitions.
sda1-- sda2 -- sda3 -- sda4 ^ | sda5 -- sda6
I think we do not need to show this specially, just use the original design: logical partitions existed in extended partition, an implicit relations.
So a flat list can do this: We mark each members, then a tree view above could be rebuilt precisely from plat list. Hi, Rich
Any comments on this?
As I said in my original email, my opinion is still that the code would be clearer if it expressed the peculiar structure of MBR extended/logical partitions directly in the structures. There's really a high hurdle for these changes. They must be: - easy to review - absolutely not break existing uses of virt-resize We're nowhere near there at the moment. There's no good testing, there are no patches for review which look sound. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
participants (4)
-
Chen Hanxiao -
Chen Hanxiao -
Chen, Hanxiao -
Richard W.M. Jones