Skip to content

Change receive_start2 to multiplex on the local SR type #6434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions ocaml/tests/test_storage_migrate_state.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ let sample_send_state =
)
; failed= false
; watchdog= None
; live_vm= Storage_interface.Vm.of_string "0"
; mirror_key= None
; vdi= Storage_interface.Vdi.of_string ""
}

let sample_receive_state =
Expand All @@ -54,6 +57,8 @@ let sample_receive_state =
; parent_vdi= Vdi.of_string "parent_vdi"
; remote_vdi= Vdi.of_string "remote_vdi"
; mirror_vm= Vm.of_string "mirror_vm"
; url= ""
; verify_dest= false
}

let sample_copy_state =
Expand Down
91 changes: 81 additions & 10 deletions ocaml/xapi-idl/storage/storage_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,42 @@ module Mirror = struct
}
[@@deriving rpcty]

type mirror_receive_result = Vhd_mirror of mirror_receive_result_vhd_t
type mirror_receive_result_smapiv3_t = {
mirror_vdi: vdi_info
; mirror_datapath: dp
; nbd_export: string
}
[@@deriving rpcty]

(* The variant of the mirror receive result depends on the SMAPI version being used,
rather than the VDI image type. We call the new variant SMAPIv3_mirror to reflect
this, but keep the old one Vhd_mirror for backwards compatability reasons. *)
type mirror_receive_result =
| Vhd_mirror of mirror_receive_result_vhd_t
| SMAPIv3_mirror of mirror_receive_result_smapiv3_t
[@@deriving rpcty]

type similars = content_id list [@@deriving rpcty]

type copy_operation_v1 = string [@@deriving rpcty, show {with_path= false}]

type mirror_operation_v1 = string [@@deriving rpcty, show {with_path= false}]

(* SMAPIv3 mirror operation *)
type operation =
| CopyV1 of copy_operation_v1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the v's are getting confusing... But this seems to be defined in xapi-storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

| MirrorV1 of mirror_operation_v1
[@@deriving rpcty, show {with_path= false}]

(* status of SMAPIv3 mirror *)
type status = {failed: bool; complete: bool; progress: float option}
[@@deriving rpcty]
end

type operation = Mirror.operation

type status = Mirror.status

type async_result_t = Vdi_info of vdi_info | Mirror_id of Mirror.id
[@@deriving rpcty]

Expand Down Expand Up @@ -373,7 +403,7 @@ module Errors = struct
(* mirror_copy_failure: raised when copying of the base image fails (SMAPIv1 only) *)
| Migration_mirror_copy_failure of string
(* mirror_failure: raised when there is any issues that causes the mirror to crash
during SXM (SMAPIv3 only, v1 uses more specific errors as above) *)
during SXM (SMAPIv1 and SMAPIv3 *)
| Migration_mirror_failure of string
| Internal_error of string
| Unknown_error
Expand Down Expand Up @@ -1106,6 +1136,8 @@ module StorageAPI (R : RPC) = struct
@-> id_p
@-> similar_p
@-> vm_p
@-> url_p
@-> verify_dest_p
@-> returning result err
)

Expand All @@ -1124,13 +1156,29 @@ module StorageAPI (R : RPC) = struct
should be used in conjunction with [receive_start2] *)
let receive_finalize2 =
declare "DATA.MIRROR.receive_finalize2" []
(dbg_p @-> id_p @-> returning unit_p err)
(dbg_p
@-> id_p
@-> sr_p
@-> url_p
@-> verify_dest_p
@-> returning unit_p err
)

(** [receive_cancel dbg id] is called in the case of migration failure to
do the clean up.*)
do the clean up.
@deprecated This function is deprecated, and is only here to keep backward
compatibility with old xapis that call Remote.DATA.MIRROR.receive_cancel
during SXM. Use the receive_cancel2 function instead.
*)
let receive_cancel =
declare "DATA.MIRROR.receive_cancel" []
(dbg_p @-> id_p @-> returning unit_p err)

(** [receive_cancel2 dbg mirror_id url verify_dest] cleans up the side effects
done by [receive_start2] on the destination host when the migration fails. *)
let receive_cancel2 =
declare "DATA.MIRROR.receive_cancel2" []
(dbg_p @-> id_p @-> url_p @-> verify_dest_p @-> returning unit_p err)
end
end

Expand Down Expand Up @@ -1210,16 +1258,33 @@ module type MIRROR = sig
-> dbg:debug_info
-> sr:sr
-> vdi_info:vdi_info
-> id:Mirror.id
-> mirror_id:Mirror.id
-> similar:Mirror.similars
-> vm:vm
-> url:string
-> verify_dest:bool
-> Mirror.mirror_receive_result

val receive_finalize : context -> dbg:debug_info -> id:Mirror.id -> unit

val receive_finalize2 : context -> dbg:debug_info -> id:Mirror.id -> unit
val receive_finalize2 :
context
-> dbg:debug_info
-> mirror_id:Mirror.id
-> sr:sr
-> url:string
-> verify_dest:bool
-> unit

val receive_cancel : context -> dbg:debug_info -> id:Mirror.id -> unit

val receive_cancel2 :
context
-> dbg:debug_info
-> mirror_id:Mirror.id
-> url:string
-> verify_dest:bool
-> unit
end

module type Server_impl = sig
Expand Down Expand Up @@ -1676,17 +1741,23 @@ module Server (Impl : Server_impl) () = struct
S.DATA.MIRROR.receive_start (fun dbg sr vdi_info id similar ->
Impl.DATA.MIRROR.receive_start () ~dbg ~sr ~vdi_info ~id ~similar
) ;
S.DATA.MIRROR.receive_start2 (fun dbg sr vdi_info id similar vm ->
Impl.DATA.MIRROR.receive_start2 () ~dbg ~sr ~vdi_info ~id ~similar ~vm
S.DATA.MIRROR.receive_start2
(fun dbg sr vdi_info mirror_id similar vm url verify_dest ->
Impl.DATA.MIRROR.receive_start2 () ~dbg ~sr ~vdi_info ~mirror_id
~similar ~vm ~url ~verify_dest
) ;
S.DATA.MIRROR.receive_cancel (fun dbg id ->
Impl.DATA.MIRROR.receive_cancel () ~dbg ~id
) ;
S.DATA.MIRROR.receive_cancel2 (fun dbg mirror_id url verify_dest ->
Impl.DATA.MIRROR.receive_cancel2 () ~dbg ~mirror_id ~url ~verify_dest
) ;
S.DATA.MIRROR.receive_finalize (fun dbg id ->
Impl.DATA.MIRROR.receive_finalize () ~dbg ~id
) ;
S.DATA.MIRROR.receive_finalize2 (fun dbg id ->
Impl.DATA.MIRROR.receive_finalize2 () ~dbg ~id
S.DATA.MIRROR.receive_finalize2 (fun dbg mirror_id sr url verify_dest ->
Impl.DATA.MIRROR.receive_finalize2 () ~dbg ~mirror_id ~sr ~url
~verify_dest
) ;
S.DATA.import_activate (fun dbg dp sr vdi vm ->
Impl.DATA.import_activate () ~dbg ~dp ~sr ~vdi ~vm
Expand Down
9 changes: 7 additions & 2 deletions ocaml/xapi-idl/storage/storage_skeleton.ml
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,19 @@ module DATA = struct
let receive_start ctx ~dbg ~sr ~vdi_info ~id ~similar =
u "DATA.MIRROR.receive_start"

let receive_start2 ctx ~dbg ~sr ~vdi_info ~id ~similar ~vm =
let receive_start2 ctx ~dbg ~sr ~vdi_info ~mirror_id ~similar ~vm ~url
~verify_dest =
u "DATA.MIRROR.receive_start2"

let receive_finalize ctx ~dbg ~id = u "DATA.MIRROR.receive_finalize"

let receive_finalize2 ctx ~dbg ~id = u "DATA.MIRROR.receive_finalize2"
let receive_finalize2 ctx ~dbg ~mirror_id ~sr ~url ~verify_dest =
u "DATA.MIRROR.receive_finalize2"

let receive_cancel ctx ~dbg ~id = u "DATA.MIRROR.receive_cancel"

let receive_cancel2 ctx ~dbg ~mirror_id ~url ~verify_dest =
u "DATA.MIRROR.receive_cancel2"
end
end

Expand Down
5 changes: 4 additions & 1 deletion ocaml/xapi-storage-cli/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ let mirror_vm = Vm.of_string "SXM_mirror"

let copy_vm = Vm.of_string "SXM_copy"

let live_vm = Vm.of_string "live_vm"

let mirror_start common_opts sr vdi dp url dest verify_dest =
on_vdi'
(fun sr vdi ->
Expand All @@ -323,7 +325,8 @@ let mirror_start common_opts sr vdi dp url dest verify_dest =
let url = get_opt url "Need a URL" in
let dest = get_opt dest "Need a destination SR" in
let task =
Storage_migrate.start ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url
Storage_migrate.start ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~live_vm
~url
~dest:(Storage_interface.Sr.of_string dest)
~verify_dest
in
Expand Down
1 change: 1 addition & 0 deletions ocaml/xapi-storage-script/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1926,6 +1926,7 @@ let bind ~volume_script_dir =
S.DATA.MIRROR.receive_finalize (u "DATA.MIRROR.receive_finalize") ;
S.DATA.MIRROR.receive_finalize2 (u "DATA.MIRROR.receive_finalize2") ;
S.DATA.MIRROR.receive_cancel (u "DATA.MIRROR.receive_cancel") ;
S.DATA.MIRROR.receive_cancel2 (u "DATA.MIRROR.receive_cancel2") ;
S.DP.create (u "DP.create") ;
S.TASK.cancel (u "TASK.cancel") ;
S.TASK.list (u "TASK.list") ;
Expand Down
Loading
Loading