Skip to content

Commit 338912c

Browse files
committed
CP-34942: compatibility with Core 0.13
When using core polymorphic comparison is not available anymore, so operator from a particular module are used. Signed-off-by: Pau Ruiz Safont <[email protected]>
1 parent b200a06 commit 338912c

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

main.ml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let error fmt = log Syslog.Err fmt
109109

110110
let pvs_version = "3.0"
111111
let supported_api_versions = [pvs_version; "5.0"]
112-
let api_max = List.fold_left ~f:max supported_api_versions ~init:""
112+
let api_max = List.fold_left ~f:String.max supported_api_versions ~init:""
113113

114114
let id = fun x -> x
115115

@@ -153,11 +153,16 @@ end = struct
153153

154154
let remove field rpc =
155155
match !V.version, rpc with
156-
| Some v, R.Dict d when v = pvs_version ->
157-
R.Dict (List.filter ~f:(fun (k,_) -> k <> field) d)
156+
| Some v, R.Dict d when String.( v = pvs_version) ->
157+
R.Dict (List.filter ~f:(fun (k,_) -> String.( k <> field)) d)
158158
| _ -> rpc
159159

160-
let with_pvs_version f rpc = if !V.version = Some pvs_version then f rpc else rpc
160+
let with_pvs_version f rpc =
161+
match !V.version with
162+
| Some v when String.( v = pvs_version) ->
163+
f rpc
164+
| _ ->
165+
rpc
161166

162167
let add_param_to_input params =
163168
with_pvs_version (function
@@ -188,26 +193,29 @@ end = struct
188193
(** Adds the uri parameter to the call from device_config when talking to the
189194
old PVS scripts *)
190195
let compat_uri device_config =
191-
if !V.version = Some pvs_version then
196+
match !V.version with
197+
| Some version when String.(version = pvs_version) -> (
192198
match List.Assoc.find ~equal:String.equal device_config "uri" with
193199
| None ->
194200
return (Error (missing_uri ()))
195201
| Some uri ->
196202
return (Ok (add_param_to_input ["uri", R.String uri]))
197-
else
203+
)
204+
| _ ->
198205
return (Ok id)
199206

200207
let sr_create device_config =
201208
compat_uri device_config >>>= fun compat_in ->
202209
let compat_out =
203-
if !V.version = Some pvs_version then begin
204-
fun rpc ->
205-
(* The PVS version will return nothing *)
206-
if rpc = R.Null then
207-
Rpcmarshal.marshal Xapi_storage.Control.typ_of_configuration device_config
208-
else rpc
209-
end
210-
else id
210+
match !V.version with
211+
| Some v when String.(v = pvs_version) -> (
212+
function
213+
(* The PVS version will return nothing *)
214+
| R.Null ->
215+
Rpcmarshal.marshal Xapi_storage.Control.typ_of_configuration device_config
216+
| rpc -> rpc
217+
)
218+
| _ -> id
211219
in
212220
return (Ok (device_config, compat_in, compat_out))
213221

@@ -216,7 +224,7 @@ end
216224

217225
let check_plugin_version_compatible query_result =
218226
let Xapi_storage.Plugin.{ name; required_api_version; _ } = query_result in
219-
if required_api_version <> api_max then
227+
if String.(required_api_version <> api_max) then
220228
warn "Using deprecated SMAPIv3 API version %s, latest is %s. Update your %s plugin!" required_api_version api_max name;
221229
if List.mem ~equal:String.equal supported_api_versions required_api_version then
222230
Deferred.Result.return ()
@@ -279,7 +287,7 @@ module Script = struct
279287
just take the first one, instead of failing *)
280288
let mapping =
281289
List.zip_exn files files
282-
|> Core.String.Caseless.Map.of_alist_reduce ~f:min
290+
|> String.Caseless.Map.of_alist_reduce ~f:String.min
283291
in
284292
Hashtbl.set name_mapping ~key:script_dir ~data:mapping
285293

@@ -587,11 +595,15 @@ let bind ~volume_script_dir =
587595
(* this is wrong, we loose the VDI type, but old pvsproxy didn't have
588596
* Volume.set and Volume.unset *)
589597
(* TODO handle this properly? *)
590-
let missing = if !version = Some pvs_version then Some (R.rpc_of_unit ()) else None in
598+
let missing = Option.bind !version (fun v ->
599+
if String.(v = pvs_version) then Some (R.rpc_of_unit ()) else None)
600+
in
591601
return_volume_rpc (fun () -> Volume_client.set (volume_rpc ?missing) dbg sr vdi key value)
592602
in
593603
let unset ~dbg ~sr ~vdi ~key =
594-
let missing = if !version = Some pvs_version then Some (R.rpc_of_unit ()) else None in
604+
let missing = Option.bind !version (fun v ->
605+
if String.(v = pvs_version) then Some (R.rpc_of_unit ()) else None)
606+
in
595607
return_volume_rpc (fun () -> Volume_client.unset (volume_rpc ?missing) dbg sr vdi key)
596608
in
597609
let update_keys ~dbg ~sr ~key ~value response =
@@ -1196,7 +1208,7 @@ let get_ok = function
11961208
let rec diff a b = match a with
11971209
| [] -> []
11981210
| a :: aa ->
1199-
if List.mem b a ~equal:(=) then diff aa b else a :: (diff aa b)
1211+
if List.mem b a ~equal:String.(=) then diff aa b else a :: (diff aa b)
12001212

12011213
let watch_volume_plugins ~volume_root ~switch_path ~pipe =
12021214
let create volume_plugin_name =

0 commit comments

Comments
 (0)