[Libguestfs] [PATCH 04/10] resize: update calculate_target_partitions for logical partitions

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Thu Apr 23 06:14:16 UTC 2015


Signed-off-by: Chen Hanxiao <chenhanxiao at 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




More information about the Libguestfs mailing list