Skip to content

Commit 7991e12

Browse files
authored
CP-54020: Refactor sxm and storage_mux code (#6378)
There are various refactors in this PR, details in each commit message. This is mainly for clean up purposes and also to prepare for the real refactoring of sxm for SMAPIv1 and SMAPIv3. No functional change. More to come...
2 parents 29015dd + 112ef69 commit 7991e12

20 files changed

Lines changed: 896 additions & 539 deletions

ocaml/tests/test_sm_features.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ module CreateSMObject = Generic.MakeStateful (struct
249249
; features
250250
; configuration= []
251251
; required_cluster_stack= []
252+
; smapi_version= SMAPIv2
252253
}
253254

254255
let extract_output __context _ =

ocaml/tests/test_storage_migrate_state.ml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ open Test_highlevel
1717
module StorageMigrateState = struct
1818
type state_t = unit
1919

20-
let create_default_state () = Storage_migrate.State.clear ()
20+
let create_default_state () = Storage_migrate_helper.State.clear ()
2121
end
2222

2323
let sample_send_state =
24-
Storage_migrate.State.Send_state.
24+
Storage_migrate_helper.State.Send_state.
2525
{
2626
url= "url"
2727
; dest_sr= Storage_interface.Sr.of_string "dest_sr"
@@ -45,7 +45,7 @@ let sample_send_state =
4545

4646
let sample_receive_state =
4747
let open Storage_interface in
48-
Storage_migrate.State.Receive_state.
48+
Storage_migrate_helper.State.Receive_state.
4949
{
5050
sr= Sr.of_string "my_sr"
5151
; dummy_vdi= Vdi.of_string "dummy_vdi"
@@ -57,7 +57,7 @@ let sample_receive_state =
5757
}
5858

5959
let sample_copy_state =
60-
Storage_migrate.State.Copy_state.
60+
Storage_migrate_helper.State.Copy_state.
6161
{
6262
base_dp= "base_dp"
6363
; leaf_dp= "leaf_dp"
@@ -70,7 +70,7 @@ let sample_copy_state =
7070

7171
module MapOf = Generic.MakeStateful (struct
7272
module Io = struct
73-
open Storage_migrate.State
73+
open Storage_migrate_helper.State
7474

7575
type input_t =
7676
(string * osend operation) option
@@ -88,7 +88,7 @@ module MapOf = Generic.MakeStateful (struct
8888
end
8989

9090
module State = StorageMigrateState
91-
open Storage_migrate.State
91+
open Storage_migrate_helper.State
9292

9393
let load_input () (send, recv, copy) =
9494
Option.iter (fun (id, send) -> add id send) send ;
@@ -116,7 +116,7 @@ module MapOf = Generic.MakeStateful (struct
116116
end)
117117

118118
let test_clear () =
119-
let open Storage_migrate.State in
119+
let open Storage_migrate_helper.State in
120120
clear () ;
121121
add "foo" (Send_op sample_send_state) ;
122122
add "bar" (Recv_op sample_receive_state) ;
@@ -130,5 +130,5 @@ let test_clear () =
130130
let test = [("clear", `Quick, test_clear)]
131131

132132
let tests =
133-
Storage_migrate.State.persist_root := Test_common.working_area ;
133+
Storage_migrate_helper.State.persist_root := Test_common.working_area ;
134134
[("storage_migrate_state_map_of", MapOf.tests)]

ocaml/tests/test_vdi_cbt.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ let register_smapiv2_server (module S : Storage_interface.Server_impl) sr_ref =
3030
; features= []
3131
; configuration= []
3232
; required_cluster_stack= []
33+
; smapi_version= SMAPIv2
3334
}
3435
in
3536

36-
Storage_mux.register sr_ref rpc "" dummy_query_result
37+
Storage_mux_reg.register sr_ref rpc "" dummy_query_result
3738

3839
let make_smapiv2_storage_server ?vdi_enable_cbt ?vdi_disable_cbt
3940
?vdi_list_changed_blocks ?vdi_data_destroy ?vdi_snapshot ?vdi_clone:_ () =

ocaml/xapi-idl/storage/storage_interface.ml

Lines changed: 59 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ let err =
404404
)
405405
}
406406

407+
type smapi_version = SMAPIv1 | SMAPIv2 | SMAPIv3
408+
[@@deriving rpcty, show {with_path= false}]
409+
407410
type query_result = {
408411
driver: string
409412
; name: string
@@ -415,6 +418,7 @@ type query_result = {
415418
; features: string list
416419
; configuration: (string * string) list
417420
; required_cluster_stack: string list
421+
; smapi_version: smapi_version
418422
}
419423
[@@deriving rpcty]
420424

@@ -1157,6 +1161,60 @@ module StorageAPI (R : RPC) = struct
11571161
end
11581162
end
11591163

1164+
module type MIRROR = sig
1165+
type context = unit
1166+
1167+
val start :
1168+
context
1169+
-> dbg:debug_info
1170+
-> sr:sr
1171+
-> vdi:vdi
1172+
-> dp:dp
1173+
-> mirror_vm:vm
1174+
-> copy_vm:vm
1175+
-> url:string
1176+
-> dest:sr
1177+
-> verify_dest:bool
1178+
-> Task.id
1179+
1180+
val stop : context -> dbg:debug_info -> id:Mirror.id -> unit
1181+
1182+
val stat : context -> dbg:debug_info -> id:Mirror.id -> Mirror.t
1183+
1184+
val receive_start :
1185+
context
1186+
-> dbg:debug_info
1187+
-> sr:sr
1188+
-> vdi_info:vdi_info
1189+
-> id:Mirror.id
1190+
-> similar:Mirror.similars
1191+
-> Mirror.mirror_receive_result
1192+
1193+
val receive_start2 :
1194+
context
1195+
-> dbg:debug_info
1196+
-> sr:sr
1197+
-> vdi_info:vdi_info
1198+
-> id:Mirror.id
1199+
-> similar:Mirror.similars
1200+
-> vm:vm
1201+
-> Mirror.mirror_receive_result
1202+
1203+
val receive_finalize : context -> dbg:debug_info -> id:Mirror.id -> unit
1204+
1205+
val receive_finalize2 : context -> dbg:debug_info -> id:Mirror.id -> unit
1206+
1207+
val receive_cancel : context -> dbg:debug_info -> id:Mirror.id -> unit
1208+
1209+
val list : context -> dbg:debug_info -> (Mirror.id * Mirror.t) list
1210+
1211+
val import_activate :
1212+
context -> dbg:debug_info -> dp:dp -> sr:sr -> vdi:vdi -> vm:vm -> sock_path
1213+
1214+
val get_nbd_server :
1215+
context -> dbg:debug_info -> dp:dp -> sr:sr -> vdi:vdi -> vm:vm -> sock_path
1216+
end
1217+
11601218
module type Server_impl = sig
11611219
type context = unit
11621220

@@ -1413,69 +1471,7 @@ module type Server_impl = sig
14131471
-> verify_dest:bool
14141472
-> Task.id
14151473

1416-
module MIRROR : sig
1417-
val start :
1418-
context
1419-
-> dbg:debug_info
1420-
-> sr:sr
1421-
-> vdi:vdi
1422-
-> dp:dp
1423-
-> mirror_vm:vm
1424-
-> copy_vm:vm
1425-
-> url:string
1426-
-> dest:sr
1427-
-> verify_dest:bool
1428-
-> Task.id
1429-
1430-
val stop : context -> dbg:debug_info -> id:Mirror.id -> unit
1431-
1432-
val stat : context -> dbg:debug_info -> id:Mirror.id -> Mirror.t
1433-
1434-
val receive_start :
1435-
context
1436-
-> dbg:debug_info
1437-
-> sr:sr
1438-
-> vdi_info:vdi_info
1439-
-> id:Mirror.id
1440-
-> similar:Mirror.similars
1441-
-> Mirror.mirror_receive_result
1442-
1443-
val receive_start2 :
1444-
context
1445-
-> dbg:debug_info
1446-
-> sr:sr
1447-
-> vdi_info:vdi_info
1448-
-> id:Mirror.id
1449-
-> similar:Mirror.similars
1450-
-> vm:vm
1451-
-> Mirror.mirror_receive_result
1452-
1453-
val receive_finalize : context -> dbg:debug_info -> id:Mirror.id -> unit
1454-
1455-
val receive_finalize2 : context -> dbg:debug_info -> id:Mirror.id -> unit
1456-
1457-
val receive_cancel : context -> dbg:debug_info -> id:Mirror.id -> unit
1458-
1459-
val list : context -> dbg:debug_info -> (Mirror.id * Mirror.t) list
1460-
1461-
val import_activate :
1462-
context
1463-
-> dbg:debug_info
1464-
-> dp:dp
1465-
-> sr:sr
1466-
-> vdi:vdi
1467-
-> vm:vm
1468-
-> sock_path
1469-
1470-
val get_nbd_server :
1471-
context
1472-
-> dbg:debug_info
1473-
-> dp:dp
1474-
-> sr:sr
1475-
-> vdi:vdi
1476-
-> vm:vm
1477-
-> sock_path
1478-
end
1474+
module MIRROR : MIRROR
14791475
end
14801476

14811477
module Policy : sig

ocaml/xapi-idl/storage/storage_skeleton.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ module DATA = struct
155155
let copy ctx ~dbg ~sr ~vdi ~vm ~url ~dest = u "DATA.copy"
156156

157157
module MIRROR = struct
158+
type context = unit
159+
158160
(** [start task sr vdi url sr2] creates a VDI in remote [url]'s [sr2] and
159161
writes data synchronously. It returns the id of the VDI.*)
160162
let start ctx ~dbg ~sr ~vdi ~dp ~mirror_vm ~copy_vm ~url ~dest =

ocaml/xapi-storage-script/main.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,7 @@ module QueryImpl (M : META) = struct
948948
; configuration= response.Xapi_storage.Plugin.configuration
949949
; required_cluster_stack=
950950
response.Xapi_storage.Plugin.required_cluster_stack
951+
; smapi_version= SMAPIv3
951952
}
952953
in
953954
wrap th

ocaml/xapi/dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@
217217
((pps ppx_deriving.ord) Xapi_observer_components)
218218
((pps ppx_deriving_rpc)
219219
Config_file_sync Extauth_plugin_ADwinbind Importexport Sparse_dd_wrapper
220-
Storage_migrate Storage_mux Storage_smapiv1_wrapper Stream_vdi
221-
System_domains Xapi_psr Xapi_services Xapi_udhcpd)))
220+
Storage_migrate Storage_migrate_helper Storage_mux Storage_smapiv1_wrapper
221+
Stream_vdi System_domains Xapi_psr Xapi_services Xapi_udhcpd)))
222222
)
223223

224224
(library

ocaml/xapi/sm_exec.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ let parse_sr_get_driver_info driver (xml : Xml.xml) =
582582
; sr_driver_configuration= configuration
583583
; sr_driver_text_features= text_features
584584
; sr_driver_required_cluster_stack= []
585+
; sr_smapi_version= SMAPIv1
585586
}
586587

587588
let sr_get_driver_info ~dbg driver =

ocaml/xapi/smint.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ type sr_driver_info = {
192192
; sr_driver_text_features: string list
193193
; sr_driver_configuration: (string * string) list
194194
; sr_driver_required_cluster_stack: string list
195+
; sr_smapi_version: Storage_interface.smapi_version
195196
}
196197

197198
let query_result_of_sr_driver_info x =
@@ -206,6 +207,7 @@ let query_result_of_sr_driver_info x =
206207
; features= x.sr_driver_text_features
207208
; configuration= x.sr_driver_configuration
208209
; required_cluster_stack= x.sr_driver_required_cluster_stack
210+
; smapi_version= x.sr_smapi_version
209211
}
210212

211213
type attach_info = {

ocaml/xapi/storage_access.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ let bind ~__context ~pbd =
264264
let service = make_service uuid ty in
265265
System_domains.register_service service queue_name ;
266266
let info = Client.Query.query dbg in
267-
Storage_mux.register (Storage_interface.Sr.of_string sr_uuid) rpc uuid info ;
267+
Storage_mux_reg.register
268+
(Storage_interface.Sr.of_string sr_uuid)
269+
rpc uuid info ;
268270
info
269271
with e ->
270272
error
@@ -281,7 +283,7 @@ let unbind ~__context ~pbd =
281283
let ty = Db.SR.get_type ~__context ~self:sr in
282284
let sr = Db.SR.get_uuid ~__context ~self:sr in
283285
info "SR %s will nolonger be implemented by VM %s" sr (Ref.string_of driver) ;
284-
Storage_mux.unregister (Storage_interface.Sr.of_string sr) ;
286+
Storage_mux_reg.unregister (Storage_interface.Sr.of_string sr) ;
285287
let service = make_service uuid ty in
286288
System_domains.unregister_service service
287289

0 commit comments

Comments
 (0)