[Libguestfs] [PATCH v2 04/11] resize: add support for logical partitions for calculate_surplus

Richard W.M. Jones rjones at redhat.com
Thu May 28 11:11:17 UTC 2015


On Wed, May 20, 2015 at 06:51:30AM -0400, Chen Hanxiao wrote:
> Add support for logical partitions.
>  - count number of logical_partition (we've split partitions list)
>  - 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 at cn.fujitsu.com>
> ---
>  resize/resize.ml | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/resize/resize.ml b/resize/resize.ml
> index 92f7304..a0ed713 100644
> --- a/resize/resize.ml
> +++ b/resize/resize.ml
> @@ -741,8 +741,10 @@ read the man page virt-resize(1).
>      (* 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
> +      let nr_partitions = List.length partitions + List.length logical_partitions in

I don't understand this at all.  Why do logical partitions count
towards the surplus?  I don't think they do.

Rich.

>        let gpt_start_sects = 64L in
>        let gpt_end_sects = gpt_start_sects in
> @@ -770,12 +772,23 @@ 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 = 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
>  
> -- 
> 2.1.0
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
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




More information about the Libguestfs mailing list