Skip to content

Commit b9bb282

Browse files
authored
Merge pull request #74 from gaborigloi/CA-293335
CA-293335: compat code cleanups, remove layering violation
2 parents 00b6d1f + 88aa9a7 commit b9bb282

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

main.ml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ module Compat(V : sig val version : string option ref end) : sig
135135
volumes in the output match the new volume record type and are
136136
successfully parsed by rpclib. *)
137137

138-
val compat_uri : device_config -> (compat_in, Storage_interface.Exception.exnty) Deferred.Result.t
139-
(** For the old PVS version, adds the uri parameter to the call from
140-
device_config, for newer versions, removes the uri key from device_config *)
141-
142138
val sr_create : device_config -> (device_config * compat_in * compat_out, Storage_interface.Exception.exnty) Deferred.Result.t
143139
(** Compatiblity for the old PVS version of SR.create, which had signature
144140
[uri -> name -> desc -> config -> unit] *)
141+
142+
val sr_attach : device_config -> (compat_in, Storage_interface.Exception.exnty) Deferred.Result.t
143+
(** Compatiblity for the old PVS version of SR.attach, which had signature
144+
[uri -> sr (=string)] *)
145145
end = struct
146146

147147
type device_config = (Core.String.t, string) Core.List.Assoc.t
@@ -182,6 +182,8 @@ end = struct
182182
let compat_out_volumes =
183183
add_fields_to_record_list_output ["sharable", R.Bool false]
184184

185+
(** Adds the uri parameter to the call from device_config when talking to the
186+
old PVS scripts *)
185187
let compat_uri device_config =
186188
if !V.version = Some pvs_version then
187189
match List.Assoc.find ~equal:String.equal device_config "uri" with
@@ -194,13 +196,19 @@ end = struct
194196

195197
let sr_create device_config =
196198
compat_uri device_config >>>= fun compat_in ->
197-
let compat_out rpc =
198-
(* The PVS version will return nothing *)
199-
if rpc = R.Null then
200-
Rpcmarshal.marshal Xapi_storage.Control.typ_of_configuration device_config
201-
else rpc
199+
let compat_out =
200+
if !V.version = Some pvs_version then begin
201+
fun rpc ->
202+
(* The PVS version will return nothing *)
203+
if rpc = R.Null then
204+
Rpcmarshal.marshal Xapi_storage.Control.typ_of_configuration device_config
205+
else rpc
206+
end
207+
else id
202208
in
203209
return (Ok (device_config, compat_in, compat_out))
210+
211+
let sr_attach = compat_uri
204212
end
205213

206214
let check_plugin_version_compatible query_result =
@@ -685,11 +693,7 @@ let process_smapiv2_requests ~volume_script_dir =
685693
| { R.name = "SR.attach"; R.params = [ args ] } ->
686694
let args = Args.SR.Attach.request_of_rpc args in
687695
let device_config = args.Args.SR.Attach.device_config in
688-
Compat.compat_uri device_config >>>= fun compat_in ->
689-
let device_config =
690-
let uuid = args.Args.SR.Attach.sr in
691-
("sr_uuid", uuid) :: device_config
692-
in
696+
Compat.sr_attach device_config >>>= fun compat_in ->
693697
return_volume_rpc (fun () -> Sr_client.attach (volume_rpc ~compat_in) args.Args.SR.Attach.dbg device_config)
694698
>>>= fun attach_response ->
695699
let sr = args.Args.SR.Attach.sr in

0 commit comments

Comments
 (0)