Skip to content

Commit 1fe6389

Browse files
committed
Add more states for SXM
Adding a few more states that will be tracked by the send_state and receive_state. These will be used later on for SMAPIv3 outbound migration. We do need to give them a default value in case the deserialisation of the on-disk copy does not have these values. These are not used yet, so no functional change. Signed-off-by: Vincent Liu <shuntian.liu2@cloud.com>
1 parent 82c509f commit 1fe6389

File tree

8 files changed

+60
-14
lines changed

8 files changed

+60
-14
lines changed

ocaml/tests/test_storage_migrate_state.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ let sample_send_state =
4141
)
4242
; failed= false
4343
; watchdog= None
44+
; live_vm= Storage_interface.Vm.of_string "0"
45+
; mirror_key= None
46+
; vdi= Storage_interface.Vdi.of_string ""
4447
}
4548

4649
let sample_receive_state =
@@ -54,6 +57,8 @@ let sample_receive_state =
5457
; parent_vdi= Vdi.of_string "parent_vdi"
5558
; remote_vdi= Vdi.of_string "remote_vdi"
5659
; mirror_vm= Vm.of_string "mirror_vm"
60+
; url= ""
61+
; verify_dest= false
5762
}
5863

5964
let sample_copy_state =

ocaml/xapi-storage-cli/main.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ let mirror_vm = Vm.of_string "SXM_mirror"
315315

316316
let copy_vm = Vm.of_string "SXM_copy"
317317

318+
let live_vm = Vm.of_string "live_vm"
319+
318320
let mirror_start common_opts sr vdi dp url dest verify_dest =
319321
on_vdi'
320322
(fun sr vdi ->
@@ -323,7 +325,8 @@ let mirror_start common_opts sr vdi dp url dest verify_dest =
323325
let url = get_opt url "Need a URL" in
324326
let dest = get_opt dest "Need a destination SR" in
325327
let task =
326-
Storage_migrate.start ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url
328+
Storage_migrate.start ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~live_vm
329+
~url
327330
~dest:(Storage_interface.Sr.of_string dest)
328331
~verify_dest
329332
in

ocaml/xapi/storage_migrate.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ module MigrateLocal = struct
261261
raise
262262
(Storage_error (Migration_preparation_failure (Printexc.to_string e)))
263263

264-
let start ~task_id ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url ~dest
264+
let start ~task_id ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~live_vm ~url ~dest
265265
~verify_dest =
266266
SXM.info
267267
"%s sr:%s vdi:%s dp: %s mirror_vm: %s copy_vm: %s url:%s dest:%s \
@@ -292,6 +292,9 @@ module MigrateLocal = struct
292292
; tapdev= None
293293
; failed= false
294294
; watchdog= None
295+
; live_vm
296+
; vdi
297+
; mirror_key= None
295298
}
296299
in
297300

@@ -608,13 +611,14 @@ let copy ~dbg ~sr ~vdi ~vm ~url ~dest ~verify_dest =
608611
~sr ~vdi ~vm ~url ~dest ~verify_dest
609612
)
610613

611-
let start ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url ~dest ~verify_dest =
614+
let start ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~live_vm ~url ~dest ~verify_dest
615+
=
612616
with_dbg ~name:__FUNCTION__ ~dbg @@ fun dbg ->
613617
with_task_and_thread ~dbg (fun task ->
614618
MigrateLocal.start
615619
~task_id:(Storage_task.id_of_handle task)
616-
~dbg:dbg.Debug_info.log ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url ~dest
617-
~verify_dest
620+
~dbg:dbg.Debug_info.log ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~live_vm ~url
621+
~dest ~verify_dest
618622
)
619623

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

ocaml/xapi/storage_migrate_helper.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ module State = struct
3636
; parent_vdi: Vdi.t
3737
; remote_vdi: Vdi.t
3838
; mirror_vm: Vm.t
39+
; url: string [@default ""]
40+
; verify_dest: bool [@default false]
3941
}
4042
[@@deriving rpcty]
4143

@@ -92,6 +94,11 @@ module State = struct
9294
; tapdev: tapdev option
9395
; mutable failed: bool
9496
; mutable watchdog: handle option
97+
; vdi: Vdi.t [@default Vdi.of_string ""] (* source vdi *)
98+
; live_vm: Vm.t
99+
[@default Vm.of_string "0"]
100+
(* vm to which the source vdi is attached *)
101+
; mirror_key: Mirror.operation option [@default None]
95102
}
96103
[@@deriving rpcty]
97104

ocaml/xapi/storage_migrate_helper.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module State : sig
2828
; parent_vdi: Storage_interface.vdi
2929
; remote_vdi: Storage_interface.vdi
3030
; mirror_vm: Storage_interface.vm
31+
; url: string
32+
; verify_dest: bool
3133
}
3234

3335
val t_sr : (Storage_interface.sr, t) Rpc.Types.field
@@ -89,6 +91,9 @@ module State : sig
8991
; tapdev: tapdev option
9092
; mutable failed: bool
9193
; mutable watchdog: handle option
94+
; vdi: Vdi.t [@default Vdi.of_string ""]
95+
; live_vm: Vm.t [@default Vm.of_string "0"]
96+
; mirror_key: Mirror.operation option [@default None]
9297
}
9398

9499
val t_url : (string, t) Rpc.Types.field

ocaml/xapi/storage_smapiv1_migrate.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,9 @@ module Copy = struct
386386
raise (Storage_error (Internal_error (Printexc.to_string e)))
387387
end
388388

389-
let mirror_pass_fds ~dbg ~dp ~sr ~vdi ~mirror_vm ~mirror_id ~url ~dest_sr
390-
~verify_dest ~(remote_mirror : Mirror.mirror_receive_result_vhd_t) =
389+
let mirror_pass_fds ~dbg ~dp ~sr ~vdi ~mirror_vm ~live_vm ~mirror_id ~url
390+
~dest_sr ~verify_dest ~(remote_mirror : Mirror.mirror_receive_result_vhd_t)
391+
=
391392
let remote_vdi = remote_mirror.mirror_vdi.vdi in
392393
let mirror_dp = remote_mirror.mirror_datapath in
393394

@@ -470,6 +471,9 @@ let mirror_pass_fds ~dbg ~dp ~sr ~vdi ~mirror_vm ~mirror_id ~url ~dest_sr
470471
; tapdev= Some tapdev
471472
; failed= false
472473
; watchdog= None
474+
; vdi
475+
; live_vm
476+
; mirror_key= None
473477
}
474478
in
475479
State.add mirror_id (State.Send_op alm) ;
@@ -549,7 +553,7 @@ module MIRROR : SMAPIv2_MIRROR = struct
549553
type context = unit
550554

551555
let send_start _ctx ~dbg ~task_id ~dp ~sr ~vdi ~mirror_vm ~mirror_id
552-
~local_vdi ~copy_vm ~live_vm:_ ~url ~remote_mirror ~dest_sr ~verify_dest =
556+
~local_vdi ~copy_vm ~live_vm ~url ~remote_mirror ~dest_sr ~verify_dest =
553557
let (module Remote) =
554558
Storage_migrate_helper.get_remote_backend url verify_dest
555559
in
@@ -564,8 +568,8 @@ module MIRROR : SMAPIv2_MIRROR = struct
564568
)
565569
| Mirror.Vhd_mirror mirror_res ->
566570
let tapdev =
567-
mirror_pass_fds ~dbg ~dp ~sr ~vdi ~mirror_vm ~mirror_id ~url ~dest_sr
568-
~verify_dest ~remote_mirror:mirror_res
571+
mirror_pass_fds ~dbg ~dp ~sr ~vdi ~mirror_vm ~live_vm ~mirror_id ~url
572+
~dest_sr ~verify_dest ~remote_mirror:mirror_res
569573
in
570574

571575
let snapshot = mirror_snapshot ~dbg ~sr ~dp ~mirror_id ~local_vdi in
@@ -663,6 +667,8 @@ module MIRROR : SMAPIv2_MIRROR = struct
663667
; parent_vdi= parent.vdi
664668
; remote_vdi= vdi_info.vdi
665669
; mirror_vm= vm
670+
; url= ""
671+
; verify_dest= false
666672
}
667673
) ;
668674
let nearest_content_id = Option.map (fun x -> x.content_id) nearest in

ocaml/xapi/storage_smapiv1_migrate.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ val mirror_pass_fds :
5656
-> sr:Storage_interface.sr
5757
-> vdi:Storage_interface.vdi
5858
-> mirror_vm:Storage_interface.vm
59+
-> live_vm:Storage_interface.vm
5960
-> mirror_id:string
6061
-> url:string
6162
-> dest_sr:Storage_interface.sr

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,14 +1030,29 @@ let vdi_copy_fun __context dbg vdi_map remote is_intra_pool remote_vdis so_far
10301030
let id =
10311031
Storage_migrate_helper.State.mirror_id_of (vconf.sr, vconf.location)
10321032
in
1033-
debug "%s mirror_vm is %s copy_vm is %s" __FUNCTION__
1033+
let live_vm =
1034+
match Db.VDI.get_VBDs ~__context ~self:vconf.vdi with
1035+
| [] ->
1036+
Storage_migrate_helper.failwith_fmt
1037+
"VDI %s does not have a corresponding VBD"
1038+
(Ref.string_of vconf.vdi)
1039+
| vbd_ref :: _ ->
1040+
(* XX Is it possible that this VDI might be used as multiple VBDs attached to different VMs? *)
1041+
let vm_ref = Db.VBD.get_VM ~__context ~self:vbd_ref in
1042+
let domid =
1043+
Db.VM.get_domid ~__context ~self:vm_ref |> Int64.to_string
1044+
in
1045+
Vm.of_string domid
1046+
in
1047+
debug "%s mirror_vm is %s copy_vm is %s live_vm is %s" __FUNCTION__
10341048
(Vm.string_of vconf.mirror_vm)
1035-
(Vm.string_of vconf.copy_vm) ;
1049+
(Vm.string_of vconf.copy_vm)
1050+
(Vm.string_of live_vm) ;
10361051
(* Layering violation!! *)
10371052
ignore (Storage_access.register_mirror __context id) ;
10381053
Storage_migrate.start ~dbg ~sr:vconf.sr ~vdi:vconf.location ~dp:new_dp
1039-
~mirror_vm:vconf.mirror_vm ~copy_vm:vconf.copy_vm ~url:remote.sm_url
1040-
~dest:dest_sr ~verify_dest:is_intra_pool
1054+
~mirror_vm:vconf.mirror_vm ~copy_vm:vconf.copy_vm ~live_vm
1055+
~url:remote.sm_url ~dest:dest_sr ~verify_dest:is_intra_pool
10411056
in
10421057
let mapfn x =
10431058
let total = Int64.to_float total_size in

0 commit comments

Comments
 (0)