Skip to content

Commit 33f0e84

Browse files
committed
CA-218221: make sure SXM destination VDI has the same size as the source
When SXM copies a VDI across, it first tries to find a pair of VDIs with identical contents on both sender and receiver sides as base copies. And the content of the pair should also be close enough to the content of source VDI. This way, we can simply make a clone (VHD child) of the base copy on the reciver side, which will then become the destination VDI. We then only need to copy into it the small differences between the source VDI and the base copy on the sender side. In some cases, despite the similarity, base copies might have a size different from the source VDI's. This is usually true when there was a resize operation in the history of VHD chain. In these cases, the destination VDI (as the result of direct cloning the base copy on the reciever side) will have a size initially different from the source VDI, therefore a resize operation is necessary to make sure the destination VDIs having the same side as the source. Signed-off-by: Zheng Li <zheng.li3@citrix.com>
1 parent 76a9459 commit 33f0e84

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ocaml/xapi/storage_migrate.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,12 @@ let receive_start ~dbg ~sr ~vdi_info ~id ~similar =
670670
| Some vdi ->
671671
debug "Cloning VDI %s" vdi.vdi;
672672
let vdi = add_to_sm_config vdi "base_mirror" id in
673-
Local.VDI.clone ~dbg ~sr ~vdi_info:vdi
673+
let vdi_clone = Local.VDI.clone ~dbg ~sr ~vdi_info:vdi in
674+
if vdi_clone.virtual_size <> vdi_info.virtual_size then begin
675+
let new_size = Local.VDI.resize ~dbg ~sr ~vdi:vdi_clone.vdi ~new_size:vdi_info.virtual_size in
676+
debug "Resize local VDI %s to %Ld: result %Ld" vdi_clone.vdi vdi_info.virtual_size new_size;
677+
end;
678+
vdi_clone
674679
| None ->
675680
debug "Creating a blank remote VDI";
676681
Local.VDI.create ~dbg ~sr ~vdi_info
@@ -826,7 +831,12 @@ let copy ~task ~dbg ~sr ~vdi ~dp ~url ~dest =
826831
let remote_base = match nearest with
827832
| Some vdi ->
828833
debug "Cloning VDI %s" vdi.vdi;
829-
Remote.VDI.clone ~dbg ~sr:dest ~vdi_info:vdi
834+
let vdi_clone = Remote.VDI.clone ~dbg ~sr:dest ~vdi_info:vdi in
835+
if vdi_clone.virtual_size <> local_vdi.virtual_size then begin
836+
let new_size = Remote.VDI.resize ~dbg ~sr:dest ~vdi:vdi_clone.vdi ~new_size:local_vdi.virtual_size in
837+
debug "Resize remote VDI %s to %Ld: result %Ld" vdi_clone.vdi local_vdi.virtual_size new_size;
838+
end;
839+
vdi_clone
830840
| None ->
831841
debug "Creating a blank remote VDI";
832842
Remote.VDI.create ~dbg ~sr:dest ~vdi_info:{ local_vdi with sm_config = [] } in

0 commit comments

Comments
 (0)