Skip to content

Commit bd6cab7

Browse files
committed
Implement send_start for SMAPIv1
Now that the split is done, we can implement the `send_start` function defined earlier for SMAPIv1, by combining all the different stages into one function and invoke it from `Storage_migrate.start`. At this point the refacotring for SMAPIv1 should be finished, and there should still be no functional change. Signed-off-by: Vincent Liu <shuntian.liu2@cloud.com>
1 parent 5d93088 commit bd6cab7

2 files changed

Lines changed: 40 additions & 26 deletions

File tree

ocaml/xapi/storage_migrate.ml

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -298,32 +298,15 @@ module MigrateLocal = struct
298298
State.add mirror_id (State.Send_op alm) ;
299299
debug "%s Added mirror %s to active local mirrors" __FUNCTION__ mirror_id ;
300300
(* A list of cleanup actions to perform if the operation should fail. *)
301+
let (module Migrate_Backend) = choose_backend dbg sr in
301302
try
302-
let (Vhd_mirror remote_mirror) =
303+
let remote_mirror =
303304
prepare ~dbg ~sr ~vdi ~dest ~local_vdi ~mirror_id ~mirror_vm ~url
304305
~verify_dest
305306
in
306-
let tapdev =
307-
Storage_smapiv1_migrate.mirror_pass_fds ~dbg ~dp ~sr ~vdi ~mirror_vm
308-
~mirror_id ~url ~dest_sr:dest ~verify_dest ~remote_mirror
309-
in
310-
let snapshot =
311-
Storage_smapiv1_migrate.mirror_snapshot ~dbg ~sr ~dp ~mirror_id
312-
~local_vdi
313-
in
314-
Storage_smapiv1_migrate.mirror_checker mirror_id tapdev ;
315-
let new_parent =
316-
Storage_smapiv1_migrate.mirror_copy ~task ~dbg ~sr ~snapshot ~copy_vm
317-
~url ~dest_sr:dest ~remote_mirror ~verify_dest
318-
in
319-
debug "Local VDI %s = remote VDI %s"
320-
(Storage_interface.Vdi.string_of snapshot.vdi)
321-
(Storage_interface.Vdi.string_of new_parent.vdi) ;
322-
debug "Local VDI %s now mirrored to remote VDI: %s"
323-
(Storage_interface.Vdi.string_of local_vdi.vdi)
324-
(Storage_interface.Vdi.string_of remote_mirror.Mirror.mirror_vdi.vdi) ;
325-
debug "Destroying snapshot on src" ;
326-
Local.VDI.destroy dbg sr snapshot.vdi ;
307+
Migrate_Backend.send_start () ~dbg ~task_id:task ~dp ~sr ~vdi ~mirror_vm
308+
~mirror_id ~local_vdi ~copy_vm ~live_vm:(Vm.of_string "0") ~url
309+
~remote_mirror ~dest_sr:dest ~verify_dest ;
327310
Some (Mirror_id mirror_id)
328311
with
329312
| Storage_error (Sr_not_attached sr_uuid) ->
@@ -628,8 +611,10 @@ let copy ~dbg ~sr ~vdi ~vm ~url ~dest ~verify_dest =
628611
let start ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url ~dest ~verify_dest =
629612
with_dbg ~name:__FUNCTION__ ~dbg @@ fun dbg ->
630613
with_task_and_thread ~dbg (fun task ->
631-
MigrateLocal.start ~task ~dbg:dbg.Debug_info.log ~sr ~vdi ~dp ~mirror_vm
632-
~copy_vm ~url ~dest ~verify_dest
614+
MigrateLocal.start
615+
~task:(Storage_task.id_of_handle task)
616+
~dbg:dbg.Debug_info.log ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url ~dest
617+
~verify_dest
633618
)
634619

635620
(* XXX: PR-1255: copy the xenopsd 'raise Exception' pattern *)

ocaml/xapi/storage_smapiv1_migrate.ml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,12 +556,41 @@ let mirror_copy ~task ~dbg ~sr ~snapshot ~copy_vm ~url ~dest_sr ~remote_mirror
556556
with e ->
557557
raise (Storage_error (Migration_mirror_copy_failure (Printexc.to_string e)))
558558

559+
let mirror_cleanup ~dbg ~sr ~snapshot =
560+
D.debug "Destroying snapshot on src" ;
561+
Local.VDI.destroy dbg sr snapshot.vdi
562+
559563
module MIRROR : SMAPIv2_MIRROR = struct
560564
type context = unit
561565

562-
let u x = raise Storage_interface.(Storage_error (Errors.Unimplemented x))
566+
let send_start _ctx ~dbg ~task_id ~dp ~sr ~vdi ~mirror_vm ~mirror_id
567+
~local_vdi ~copy_vm ~live_vm:_ ~url ~remote_mirror ~dest_sr ~verify_dest =
568+
let (module Remote) =
569+
Storage_migrate_helper.get_remote_backend url verify_dest
570+
in
571+
match remote_mirror with
572+
| Mirror.Vhd_mirror mirror_res ->
573+
let tapdev =
574+
mirror_pass_fds ~dbg ~dp ~sr ~vdi ~mirror_vm ~mirror_id ~url ~dest_sr
575+
~verify_dest ~remote_mirror:mirror_res
576+
in
577+
578+
let snapshot = mirror_snapshot ~dbg ~sr ~dp ~mirror_id ~local_vdi in
579+
580+
mirror_checker mirror_id tapdev ;
581+
let task = Storage_task.(handle_of_id tasks) task_id in
582+
let new_parent =
583+
mirror_copy ~task ~dbg ~sr ~snapshot ~copy_vm ~url ~dest_sr
584+
~remote_mirror:mirror_res ~verify_dest
585+
in
563586

564-
let send_start _ctx = u __FUNCTION__
587+
D.debug "Local VDI %s = remote VDI %s"
588+
(Storage_interface.Vdi.string_of snapshot.vdi)
589+
(Storage_interface.Vdi.string_of new_parent.vdi) ;
590+
D.debug "Local VDI %s now mirrored to remote VDI: %s"
591+
(Storage_interface.Vdi.string_of local_vdi.vdi)
592+
(Storage_interface.Vdi.string_of mirror_res.Mirror.mirror_vdi.vdi) ;
593+
mirror_cleanup ~dbg ~sr ~snapshot
565594

566595
let receive_start_common ~dbg ~sr ~vdi_info ~id ~similar ~vm =
567596
let on_fail : (unit -> unit) list ref = ref [] in

0 commit comments

Comments
 (0)