Skip to content

Commit

Permalink
IH-728: Refactor SXM code, Pt1 (#6084)
Browse files Browse the repository at this point in the history
The Storage migration code is too messy to be maintainable, making the
developing experience quite bad. This is the first attempt to make it
less spaghetti.

I am intending to do this in several stages. This PR is just for those
that are mostly "safe" operations that can probably be checked
statically by the compiler. More risky changes on the way...

Best reviewed by commit.
  • Loading branch information
psafont authored Nov 18, 2024
2 parents 1da872b + 20fb265 commit 77dd474
Show file tree
Hide file tree
Showing 8 changed files with 787 additions and 801 deletions.
35 changes: 2 additions & 33 deletions ocaml/xapi-idl/storage/storage_interface.ml
Original file line number Diff line number Diff line change
Expand Up @@ -976,28 +976,12 @@ module StorageAPI (R : RPC) = struct
~description:["when true, verify remote server certificate"]
Types.bool

(** [copy_into task sr vdi url sr2] copies the data from [vdi] into a remote
system [url]'s [sr2] *)
let copy_into =
let dest_vdi_p = Param.mk ~name:"dest_vdi" Vdi.t in
declare "DATA.copy_into" []
(dbg_p
@-> sr_p
@-> vdi_p
@-> url_p
@-> dest_p
@-> dest_vdi_p
@-> verify_dest_p
@-> returning task_id_p err
)

let copy =
let result_p = Param.mk ~name:"task_id" Task.id in
declare "DATA.copy" []
(dbg_p
@-> sr_p
@-> vdi_p
@-> dp_p
@-> url_p
@-> dest_p
@-> verify_dest_p
Expand Down Expand Up @@ -1344,23 +1328,11 @@ module type Server_impl = sig
val get_by_name : context -> dbg:debug_info -> name:string -> sr * vdi_info

module DATA : sig
val copy_into :
context
-> dbg:debug_info
-> sr:sr
-> vdi:vdi
-> url:string
-> dest:sr
-> dest_vdi:vdi
-> verify_dest:bool
-> Task.id

val copy :
context
-> dbg:debug_info
-> sr:sr
-> vdi:vdi
-> dp:dp
-> url:string
-> dest:sr
-> verify_dest:bool
Expand Down Expand Up @@ -1549,11 +1521,8 @@ module Server (Impl : Server_impl) () = struct
Impl.VDI.list_changed_blocks () ~dbg ~sr ~vdi_from ~vdi_to
) ;
S.get_by_name (fun dbg name -> Impl.get_by_name () ~dbg ~name) ;
S.DATA.copy_into (fun dbg sr vdi url dest dest_vdi verify_dest ->
Impl.DATA.copy_into () ~dbg ~sr ~vdi ~url ~dest ~dest_vdi ~verify_dest
) ;
S.DATA.copy (fun dbg sr vdi dp url dest verify_dest ->
Impl.DATA.copy () ~dbg ~sr ~vdi ~dp ~url ~dest ~verify_dest
S.DATA.copy (fun dbg sr vdi url dest verify_dest ->
Impl.DATA.copy () ~dbg ~sr ~vdi ~url ~dest ~verify_dest
) ;
S.DATA.MIRROR.start (fun dbg sr vdi dp url dest verify_dest ->
Impl.DATA.MIRROR.start () ~dbg ~sr ~vdi ~dp ~url ~dest ~verify_dest
Expand Down
4 changes: 1 addition & 3 deletions ocaml/xapi-idl/storage/storage_skeleton.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,7 @@ end
let get_by_name ctx ~dbg ~name = u "get_by_name"

module DATA = struct
let copy_into ctx ~dbg ~sr ~vdi ~url ~dest ~dest_vdi = u "DATA.copy_into"

let copy ctx ~dbg ~sr ~vdi ~dp ~url ~dest = u "DATA.copy"
let copy ctx ~dbg ~sr ~vdi ~url ~dest = u "DATA.copy"

module MIRROR = struct
(** [start task sr vdi url sr2] creates a VDI in remote [url]'s [sr2] and
Expand Down
1 change: 0 additions & 1 deletion ocaml/xapi-storage-script/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,6 @@ let bind ~volume_script_dir =
S.VDI.get_url (u "VDI.get_url") ;
S.DATA.MIRROR.start (u "DATA.MIRROR.start") ;
S.Policy.get_backend_vm (u "Policy.get_backend_vm") ;
S.DATA.copy_into (u "DATA.copy_into") ;
S.DATA.MIRROR.receive_cancel (u "DATA.MIRROR.receive_cancel") ;
S.SR.update_snapshot_info_src (u "SR.update_snapshot_info_src") ;
S.DATA.MIRROR.stop (u "DATA.MIRROR.stop") ;
Expand Down
Loading

0 comments on commit 77dd474

Please sign in to comment.