Skip to content

Commit 516d754

Browse files
committed
ocp-indent auto indent
Signed-off-by: Lin Liu <[email protected]>
1 parent 1b6d33a commit 516d754

File tree

4 files changed

+110
-110
lines changed

4 files changed

+110
-110
lines changed

ocaml/xapi/vgpuops.ml

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,29 +61,29 @@ let allocate_vgpu_to_gpu ?dry_run ?pre_allocate_list ~__context vm host vgpu =
6161
let pgpus = List.intersect compatible_pgpus available_pgpus in
6262

6363
let pgpu_can_hold_vgpu pgpu vgpu =
64-
try Xapi_pgpu.assert_can_run_VGPU ~__context ~self:pgpu ~vgpu;
65-
true
66-
with e -> false in
64+
try Xapi_pgpu.assert_can_run_VGPU ~__context ~self:pgpu ~vgpu;
65+
true
66+
with e -> false in
6767

6868
let active_pgpus = List.filter ( fun pgpu -> pgpu_can_hold_vgpu pgpu vgpu.vgpu_ref ) pgpus in
6969

7070
let remaining_capacity_for_vgpu_from_pgpu vgpu pgpu =
7171
let db_remaining = Helpers.call_api_functions ~__context
7272
(fun rpc session_id ->
73-
Client.Client.PGPU.get_remaining_capacity ~rpc ~session_id
74-
~self:pgpu ~vgpu_type:vgpu.type_ref) in
73+
Client.Client.PGPU.get_remaining_capacity ~rpc ~session_id
74+
~self:pgpu ~vgpu_type:vgpu.type_ref) in
7575
(* Check if any pre-allocation existed, the pre-allocation is not reflected
7676
* in the database, usually in the dry run mode, with following format
7777
* [(v1,p1);(v2,p2);(v3,p1)...]*)
7878
match pre_allocate_list with
7979
| Some pre_allocate_list ->
80-
let virtul_allocation = List.fold_left (fun num ele ->
81-
match ele with
82-
|(_,cpgpu) when cpgpu = pgpu -> Int64.add num 1L
83-
|(_,_) -> num )
84-
0L pre_allocate_list in
85-
Int64.sub db_remaining virtul_allocation
86-
(* Probablly need check here, assert >0*)
80+
let virtul_allocation = List.fold_left (fun num ele ->
81+
match ele with
82+
|(_,cpgpu) when cpgpu = pgpu -> Int64.add num 1L
83+
|(_,_) -> num )
84+
0L pre_allocate_list in
85+
Int64.sub db_remaining virtul_allocation
86+
(* Probablly need check here, assert >0*)
8787
| _ -> db_remaining
8888
in
8989

@@ -110,16 +110,16 @@ let allocate_vgpu_to_gpu ?dry_run ?pre_allocate_list ~__context vm host vgpu =
110110
match choose_pgpu sorted_pgpus with
111111
| None -> fail_creation vm vgpu
112112
| Some pgpu ->
113-
let bneed_db_operation = match dry_run with
114-
| Some true -> false
115-
| _ -> true in
116-
if bneed_db_operation then
117-
Db.VGPU.set_scheduled_to_be_resident_on ~__context ~self:vgpu.vgpu_ref ~value:pgpu;
113+
let bneed_db_operation = match dry_run with
114+
| Some true -> false
115+
| _ -> true in
116+
if bneed_db_operation then
117+
Db.VGPU.set_scheduled_to_be_resident_on ~__context ~self:vgpu.vgpu_ref ~value:pgpu;
118118

119-
let pre_list = match pre_allocate_list with
120-
| Some pre_allocate_list -> pre_allocate_list
121-
| _ -> [] in
122-
(vgpu.vgpu_ref,pgpu)::pre_list
119+
let pre_list = match pre_allocate_list with
120+
| Some pre_allocate_list -> pre_allocate_list
121+
| _ -> [] in
122+
(vgpu.vgpu_ref,pgpu)::pre_list
123123

124124
(* Take a PCI device and assign it, and any dependent devices, to the VM *)
125125
let add_pcis_to_vm ~__context host vm pci =
@@ -149,8 +149,8 @@ let reserve_free_virtual_function ~__context vm pf =
149149
(* We may still need to load the driver... do that and try again *)
150150
let pf_host = Db.PCI.get_host ~__context ~self:pf in
151151
Helpers.call_api_functions ~__context (fun rpc session_id ->
152-
Client.Client.Host.mxgpu_vf_setup rpc session_id pf_host
153-
);
152+
Client.Client.Host.mxgpu_vf_setup rpc session_id pf_host
153+
);
154154
get false
155155
end else
156156
(* This probably means that our capacity checking went wrong! *)
@@ -198,7 +198,7 @@ let vgpu_manual_setup_of_vm vm_r =
198198
let create_vgpus ~__context host (vm, vm_r) hvm =
199199
let vgpus = vgpus_of_vm ~__context vm_r in
200200
if vgpus <> [] && not hvm then
201-
raise (Api_errors.Server_error (Api_errors.feature_requires_hvm, ["vGPU- and GPU-passthrough needs HVM"]));
201+
raise (Api_errors.Server_error (Api_errors.feature_requires_hvm, ["vGPU- and GPU-passthrough needs HVM"]));
202202
add_vgpus_to_vm ~__context host vm vgpus (vgpu_manual_setup_of_vm vm_r)
203203

204204
(* This function is called from Xapi_xenops, after forwarding, so possibly on a slave. *)

ocaml/xapi/xapi_pgpu.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ let assert_can_run_VGPU ~__context ~self ~vgpu =
317317
(** Check whether Nvidia NVML allow the vGPU by gpumon *)
318318
let nvidia_compatible = Xapi_gpumon.Nvidia.vgpu_pgpu_are_compatible ~__context ~vgpu ~pgpu:self in
319319
if not nvidia_compatible then raise (Api_errors.Server_error
320-
(** This should be a new exception **)
321-
(Api_errors.pgpu_insufficient_capacity_for_vgpu, [Ref.string_of self;Ref.string_of vgpu_type]))
320+
(** This should be a new exception **)
321+
(Api_errors.pgpu_insufficient_capacity_for_vgpu, [Ref.string_of self;Ref.string_of vgpu_type]))
322322

323323

324324
let update_dom0_access ~__context ~self ~action =

ocaml/xapi/xapi_pgpu_helpers.ml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,25 +55,25 @@ let assert_VGPU_type_allowed ~__context ~self ~vgpu_type =
5555
match allocated_vgpu_list with
5656
| [] -> () (* Not allocated on this pgpu, does not need to check compatibility*)
5757
| hd::tail ->
58-
let grant_vgpu_type_list = List.fold_left
59-
(fun grant_list current_list -> Listext.List.intersect grant_list current_list)
60-
(Db.VGPU_type.get_compatible_types_on_pgpu ~__context ~self:(Db.VGPU.get_type ~__context ~self:hd))
61-
(
62-
List.map (fun self -> Db.VGPU.get_type ~__context ~self) tail
63-
|> List.sort_uniq Pervasives.compare (* Remove the duplicated elements*)
64-
|> List.map (fun self -> Db.VGPU_type.get_compatible_types_on_pgpu ~__context ~self)
65-
) in
66-
if not (List.mem vgpu_type (List.map Ref.of_string (*Remove this when String-> Ref *) grant_vgpu_type_list)) then
67-
let sep = ";" in
68-
raise (Api_errors.Server_error (
69-
Api_errors.vgpu_type_not_compatible_with_running_type, [
70-
Ref.string_of self;
71-
Ref.string_of vgpu_type;
72-
List.map (fun self-> Db.VGPU.get_type ~__context ~self) allocated_vgpu_list
73-
|> List.sort_uniq Pervasives.compare
74-
|> List.map (fun vgpu_ref -> Ref.string_of vgpu_ref)
75-
|> String.concat sep
76-
]))
58+
let grant_vgpu_type_list = List.fold_left
59+
(fun grant_list current_list -> Listext.List.intersect grant_list current_list)
60+
(Db.VGPU_type.get_compatible_types_on_pgpu ~__context ~self:(Db.VGPU.get_type ~__context ~self:hd))
61+
(
62+
List.map (fun self -> Db.VGPU.get_type ~__context ~self) tail
63+
|> List.sort_uniq Pervasives.compare (* Remove the duplicated elements*)
64+
|> List.map (fun self -> Db.VGPU_type.get_compatible_types_on_pgpu ~__context ~self)
65+
) in
66+
if not (List.mem vgpu_type (List.map Ref.of_string (*Remove this when String-> Ref *) grant_vgpu_type_list)) then
67+
let sep = ";" in
68+
raise (Api_errors.Server_error (
69+
Api_errors.vgpu_type_not_compatible_with_running_type, [
70+
Ref.string_of self;
71+
Ref.string_of vgpu_type;
72+
List.map (fun self-> Db.VGPU.get_type ~__context ~self) allocated_vgpu_list
73+
|> List.sort_uniq Pervasives.compare
74+
|> List.map (fun vgpu_ref -> Ref.string_of vgpu_ref)
75+
|> String.concat sep
76+
]))
7777

7878
let assert_no_resident_VGPUs_of_type ~__context ~self ~vgpu_type =
7979
let open Db_filter_types in
@@ -222,9 +222,9 @@ let assert_destination_has_pgpu_compatible_with_vm ~__context ~vm ~vgpu_map ~hos
222222
| `nvidia ->
223223
Db.VGPU.get_GPU_group ~__context ~self:vgpu
224224
|> fun self -> Db.GPU_group.get_GPU_types ~__context ~self
225-
|> fun pgpu_types -> get_first_suitable_pgpu pgpu_types vgpu pgpus
226-
|> fun pgpu ->
227-
assert_destination_pgpu_is_compatible_with_vm ~__context ~vm ~vgpu ~pgpu ~host ?remote ()
225+
|> fun pgpu_types -> get_first_suitable_pgpu pgpu_types vgpu pgpus
226+
|> fun pgpu ->
227+
assert_destination_pgpu_is_compatible_with_vm ~__context ~vm ~vgpu ~pgpu ~host ?remote ()
228228
in
229229
let vgpus = Db.VM.get_VGPUs ~__context ~self:vm in
230230
let _mapped, unmapped = List.partition (fun vgpu -> List.mem_assoc vgpu vgpu_map) vgpus in

ocaml/xapi/xapi_vm_helpers.ml

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ let ensure_domain_type_is_specified ~__context ~self =
4949
if Db.VM.get_domain_type ~__context ~self = `unspecified then
5050
Db.VM.get_HVM_boot_policy ~__context ~self
5151
|> fun hbp -> derive_domain_type ~hVM_boot_policy:hbp
52-
|> fun value -> Db.VM.set_domain_type ~__context ~self ~value
52+
|> fun value -> Db.VM.set_domain_type ~__context ~self ~value
5353

5454
let derive_hvm_boot_policy ~domain_type =
5555
if domain_type = `hvm then
@@ -239,17 +239,17 @@ let validate_basic_parameters ~__context ~self ~snapshot:x =
239239
let assert_vm_supports_quiesce_snapshot ~__context ~self =
240240
let vmr = Db.VM.get_record_internal ~__context ~self in
241241
if List.exists ( fun vbd ->
242-
try
243-
let vdi = Db.VBD.get_VDI ~__context ~self:vbd in
244-
let sm_config = Db.VDI.get_sm_config ~__context ~self:vdi in
245-
Xapi_vm_lifecycle.assoc_opt "on_boot" sm_config = Some "reset"
246-
with _ -> false
247-
) vmr.Db_actions.vM_VBDs then
242+
try
243+
let vdi = Db.VBD.get_VDI ~__context ~self:vbd in
244+
let sm_config = Db.VDI.get_sm_config ~__context ~self:vdi in
245+
Xapi_vm_lifecycle.assoc_opt "on_boot" sm_config = Some "reset"
246+
with _ -> false
247+
) vmr.Db_actions.vM_VBDs then
248248
raise (Api_errors.Server_error(Api_errors.vdi_on_boot_mode_incompatible_with_operation, [ ]));
249249

250250
let vmgmr = Xapi_vm_lifecycle.maybe_get_guest_metrics ~__context ~ref:(vmr.Db_actions.vM_guest_metrics) in
251251
if not ((Xapi_vm_lifecycle.has_feature ~vmgmr ~feature:"feature-snapshot") ||
252-
(Xapi_vm_lifecycle.has_feature ~vmgmr ~feature:"feature-quiesce")) then
252+
(Xapi_vm_lifecycle.has_feature ~vmgmr ~feature:"feature-quiesce")) then
253253
raise (Api_errors.Server_error(Api_errors.vm_snapshot_with_quiesce_not_supported, [ Ref.string_of self ]))
254254

255255
let assert_hardware_platform_support ~__context ~vm ~host =
@@ -361,27 +361,27 @@ let assert_gpus_available ~__context ~self ~host =
361361
let vgpus = Db.VM.get_VGPUs ~__context ~self in
362362
let open Vgpuops in
363363
let vgpurs = List.map (Vgpuops.vgpu_of_ref ~__context) vgpus in
364-
try
365-
ignore (List.fold_left (fun pre_allocate_list vgpu -> Vgpuops.allocate_vgpu_to_gpu ~dry_run:true ~pre_allocate_list ~__context self host vgpu) [] vgpurs)
366-
with _ -> raise (Api_errors.Server_error (Api_errors.vm_requires_gpu, [
367-
Ref.string_of self;
368-
String.concat ";" (List.map Ref.string_of vgpus)
369-
]))
364+
try
365+
ignore (List.fold_left (fun pre_allocate_list vgpu -> Vgpuops.allocate_vgpu_to_gpu ~dry_run:true ~pre_allocate_list ~__context self host vgpu) [] vgpurs)
366+
with _ -> raise (Api_errors.Server_error (Api_errors.vm_requires_gpu, [
367+
Ref.string_of self;
368+
String.concat ";" (List.map Ref.string_of vgpus)
369+
]))
370370

371371

372372
let assert_usbs_available ~__context ~self ~host =
373373
Db.VM.get_VUSBs ~__context ~self
374374
|> List.iter (fun vusb ->
375-
try
376-
let usb_group = Db.VUSB.get_USB_group ~__context ~self:vusb in
377-
let pusb = List.hd (Db.USB_group.get_PUSBs ~__context ~self:usb_group) in
378-
let usb_host = Db.PUSB.get_host ~__context ~self:pusb in
379-
assert (usb_host = host)
380-
with _ -> raise (Api_errors.Server_error (Api_errors.operation_not_allowed,
381-
[Printf.sprintf "VUSB %s is not available on Host %s"
382-
(Ref.string_of vusb)
383-
(Ref.string_of host)
384-
]))
375+
try
376+
let usb_group = Db.VUSB.get_USB_group ~__context ~self:vusb in
377+
let pusb = List.hd (Db.USB_group.get_PUSBs ~__context ~self:usb_group) in
378+
let usb_host = Db.PUSB.get_host ~__context ~self:pusb in
379+
assert (usb_host = host)
380+
with _ -> raise (Api_errors.Server_error (Api_errors.operation_not_allowed,
381+
[Printf.sprintf "VUSB %s is not available on Host %s"
382+
(Ref.string_of vusb)
383+
(Ref.string_of host)
384+
]))
385385
)
386386

387387
(* 1.To avoid redundant checks,for each VF if it was reserved, then it's no need to check remaining capacity again.
@@ -398,9 +398,9 @@ let assert_netsriov_available ~__context ~self ~host =
398398
let required, pif = List.assoc network acc in
399399
(network,(required + 1,pif)) :: (List.remove_assoc network acc)
400400
with Not_found ->
401-
match Xapi_network_sriov_helpers.get_local_underlying_pif ~__context ~network ~host with
402-
| Some pif -> (network,(1,pif)) :: acc
403-
| None -> acc
401+
match Xapi_network_sriov_helpers.get_local_underlying_pif ~__context ~network ~host with
402+
| Some pif -> (network,(1,pif)) :: acc
403+
| None -> acc
404404
end
405405
) [] (Db.VM.get_VIFs ~__context ~self)
406406
in
@@ -442,9 +442,9 @@ let assert_enough_memory_available ~__context ~self ~host ~snapshot =
442442
let assert_matches_control_domain_affinity ~__context ~self ~host =
443443
if Db.VM.get_is_control_domain ~__context ~self then
444444
match Db.VM.get_affinity ~__context ~self with
445-
| x when x = Ref.null || x = host -> ()
446-
| _ -> raise (Api_errors.Server_error (Api_errors.operation_not_allowed,
447-
["Cannot boot a control domain on a host different from its affinity"]))
445+
| x when x = Ref.null || x = host -> ()
446+
| _ -> raise (Api_errors.Server_error (Api_errors.operation_not_allowed,
447+
["Cannot boot a control domain on a host different from its affinity"]))
448448

449449
let assert_enough_pcpus ~__context ~self ~host ?remote () =
450450
let vcpus = Db.VM.get_VCPUs_max ~__context ~self in
@@ -457,13 +457,13 @@ let assert_enough_pcpus ~__context ~self ~host ?remote () =
457457
let platformdata = Db.VM.get_platform ~__context ~self in
458458
if Vm_platform.(is_true ~key:vcpu_unrestricted ~platformdata ~default:false) then
459459
warn "Allowing VM %s to run on host %s, even though #vCPUs > #pCPUs (%Ld > %Ld), \
460-
because platform:vcpu-unrestricted is set"
460+
because platform:vcpu-unrestricted is set"
461461
(Ref.string_of self) (Ref.string_of host) vcpus pcpus
462462
else
463463
raise Api_errors.(Server_error (
464-
host_not_enough_pcpus,
465-
List.map Int64.to_string [vcpus; pcpus]
466-
))
464+
host_not_enough_pcpus,
465+
List.map Int64.to_string [vcpus; pcpus]
466+
))
467467

468468
(** Checks to see if a VM can boot on a particular host, throws an error if not.
469469
* Criteria:
@@ -508,9 +508,9 @@ let assert_can_boot_here ~__context ~self ~host ~snapshot ?(do_sr_check=true) ?(
508508
assert_usbs_available ~__context ~self ~host;
509509
assert_netsriov_available ~__context ~self ~host;
510510
begin match Helpers.domain_type ~__context ~self with
511-
| `hvm | `pv_in_pvh ->
512-
assert_host_supports_hvm ~__context ~self ~host
513-
| `pv -> ()
511+
| `hvm | `pv_in_pvh ->
512+
assert_host_supports_hvm ~__context ~self ~host
513+
| `pv -> ()
514514
end;
515515
if do_memory_check then
516516
assert_enough_memory_available ~__context ~self ~host ~snapshot;
@@ -633,8 +633,8 @@ let vm_can_run_on_host ~__context ~vm ~snapshot ~do_memory_check host =
633633
try let _ = List.find (fun s -> snd s = `evacuate) (Db.Host.get_current_operations ~__context ~self:host) in false with _ -> true
634634
in
635635
try host_has_proper_version ()
636-
&& (is_control_domain || host_enabled ()) (*CA-233580: allow control domains to start on a disabled host*)
637-
&& host_live () && host_can_run_vm () && host_evacuate_in_progress
636+
&& (is_control_domain || host_enabled ()) (*CA-233580: allow control domains to start on a disabled host*)
637+
&& host_live () && host_can_run_vm () && host_evacuate_in_progress
638638
with _ -> false
639639

640640

@@ -716,7 +716,7 @@ let choose_host_for_vm_no_wlb ~__context ~vm ~snapshot =
716716
| `VGPU vgpu -> group_hosts_by_best_pgpu ~__context vgpu
717717
| `Netsriov network ->
718718
let host_group = Xapi_network_sriov_helpers.group_hosts_by_best_sriov ~__context ~network
719-
|> List.map (fun g -> List.map (fun (h,_)-> h) g)
719+
|> List.map (fun g -> List.map (fun (h,_)-> h) g)
720720
in
721721
if host_group <> [] then host_group
722722
else raise (Api_errors.Server_error(Api_errors.network_sriov_insufficient_capacity, [Ref.string_of network]))
@@ -771,9 +771,9 @@ let choose_host_for_vm ~__context ~vm ~snapshot =
771771
| ["WLB"; "0.0"; rec_id; zero_reason] ->
772772
filter_and_convert tl
773773
| ["WLB"; stars; rec_id] ->
774-
let st = try float_of_string stars with Failure _ -> raise Float_of_string_failure
775-
in
776-
(h, st, rec_id) :: filter_and_convert tl
774+
let st = try float_of_string stars with Failure _ -> raise Float_of_string_failure
775+
in
776+
(h, st, rec_id) :: filter_and_convert tl
777777
| _ -> filter_and_convert tl
778778
end
779779
| [] -> []
@@ -1075,20 +1075,20 @@ let assert_valid_bios_strings ~__context ~value =
10751075
(* Validate size of value provided is within bios_string_limit_size and not empty *)
10761076
(* Validate value chars are printable ASCII characters *)
10771077
value |> List.iter (fun (k, v) ->
1078-
if not (List.mem k Xapi_globs.settable_vm_bios_string_keys) then
1079-
raise (Api_errors.Server_error(Api_errors.invalid_value, [k; "Unknown key"]));
1080-
match String.length v with
1081-
| 0 -> raise (Api_errors.Server_error(Api_errors.invalid_value, [k; "Value provided is empty"]))
1082-
| len when len > Xapi_globs.bios_string_limit_size ->
1083-
let err = Printf.sprintf "%s has length more than %d characters" v Xapi_globs.bios_string_limit_size in
1084-
raise (Api_errors.Server_error(Api_errors.invalid_value, [k; err]))
1085-
| _ ->
1086-
String.iter
1087-
(fun c ->
1088-
if c < (Char.chr 32) || c >= (Char.chr 127) then
1089-
raise (Api_errors.Server_error(Api_errors.invalid_value, [k; v ^ " has non-printable ASCII characters"]))
1090-
) v
1091-
)
1078+
if not (List.mem k Xapi_globs.settable_vm_bios_string_keys) then
1079+
raise (Api_errors.Server_error(Api_errors.invalid_value, [k; "Unknown key"]));
1080+
match String.length v with
1081+
| 0 -> raise (Api_errors.Server_error(Api_errors.invalid_value, [k; "Value provided is empty"]))
1082+
| len when len > Xapi_globs.bios_string_limit_size ->
1083+
let err = Printf.sprintf "%s has length more than %d characters" v Xapi_globs.bios_string_limit_size in
1084+
raise (Api_errors.Server_error(Api_errors.invalid_value, [k; err]))
1085+
| _ ->
1086+
String.iter
1087+
(fun c ->
1088+
if c < (Char.chr 32) || c >= (Char.chr 127) then
1089+
raise (Api_errors.Server_error(Api_errors.invalid_value, [k; v ^ " has non-printable ASCII characters"]))
1090+
) v
1091+
)
10921092

10931093
let copy_bios_strings ~__context ~vm ~host =
10941094
(* only allow to fill in BIOS strings if they are not yet set *)
@@ -1153,9 +1153,9 @@ let ensure_device_model_profile_present ~__context ~domain_type ~is_a_template ?
11531153
let trad = Vm_platform.(device_model, fallback_device_model_stage_1) in
11541154
if is_a_template then platform
11551155
else
1156-
if not needs_qemu || List.mem_assoc Vm_platform.device_model platform then
1157-
(* upgrade existing Device Model entry *)
1158-
platform |> List.map (fun entry -> if entry = trad then default else entry)
1159-
else (* only add device-model to an HVM VM platform if it is not already there *)
1160-
default :: platform
1156+
if not needs_qemu || List.mem_assoc Vm_platform.device_model platform then
1157+
(* upgrade existing Device Model entry *)
1158+
platform |> List.map (fun entry -> if entry = trad then default else entry)
1159+
else (* only add device-model to an HVM VM platform if it is not already there *)
1160+
default :: platform
11611161

0 commit comments

Comments
 (0)