Skip to content

Commit

Permalink
make format
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Reis <[email protected]>
  • Loading branch information
benjamreis committed Apr 2, 2024
1 parent 08d14d8 commit a7a170e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 29 deletions.
14 changes: 8 additions & 6 deletions ocaml/idl/datamodel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6782,10 +6782,11 @@ module PGPU = struct

let enable_dom0_access =
call ~name:"enable_dom0_access"
~lifecycle:[
~lifecycle:
[
(Published, rel_cream, "")
; (Deprecated, rel_next, "Use PCI.enable_dom0_access instead.")
]
]
~versioned_params:
[
{
Expand All @@ -6801,10 +6802,11 @@ module PGPU = struct

let disable_dom0_access =
call ~name:"disable_dom0_access"
~lifecycle:[
~lifecycle:
[
(Published, rel_cream, "")
; (Deprecated, rel_next, "Use PCI.disable_dom0_access instead.")
]
]
~versioned_params:
[
{
Expand Down Expand Up @@ -6879,8 +6881,8 @@ module PGPU = struct
; field ~qualifier:DynamicRO ~ty:pci_dom0_access
~lifecycle:
[
(Published, rel_cream, "")
; (Deprecated, rel_next, "Use PCI.get_dom0_access_status instead.")
(Published, rel_cream, "")
; (Deprecated, rel_next, "Use PCI.get_dom0_access_status instead.")
]
~default_value:(Some (VEnum "enabled")) "dom0_access"
"The accessibility of this device from dom0"
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi-cli-server/cli_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ let gen_cmds rpc session_id =
)
; Client.PGPU.(
mk get_all_records_where get_by_uuid pgpu_record "pgpu" []
["uuid"; "pci-uuid" ; "vendor-name"; "device-name"; "gpu-group-uuid"]
["uuid"; "pci-uuid"; "vendor-name"; "device-name"; "gpu-group-uuid"]
rpc session_id
)
; Client.GPU_group.(
Expand Down
15 changes: 12 additions & 3 deletions ocaml/xapi/xapi_pci.mli
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,20 @@ val disable_system_display_device : unit -> unit
val dequarantine : __context:Context.t -> Xenops_interface.Pci.address -> unit
(** dequarantine a PCI device. This is idempotent. *)

val disable_dom0_access : __context:Context.t -> self:API.ref_PCI -> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
val disable_dom0_access :
__context:Context.t
-> self:API.ref_PCI
-> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
(** Hide a PCI device from the dom0 kernel. (Takes affect after next boot.) *)

val enable_dom0_access : __context:Context.t -> self:API.ref_PCI -> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
val enable_dom0_access :
__context:Context.t
-> self:API.ref_PCI
-> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
(** Unhide a PCI device from the dom0 kernel. (Takes affect after next boot.) *)

val get_dom0_access_status : __context:Context.t -> self:API.ref_PCI -> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
val get_dom0_access_status :
__context:Context.t
-> self:API.ref_PCI
-> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
(** Return a PCI device dom0 access status. *)
39 changes: 22 additions & 17 deletions ocaml/xapi/xapi_pci_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -180,37 +180,42 @@ let is_pci_hidden_cmdline ~__context ~self =
| [x] ->
x
| _ ->
failwith "Unable to read cmdline" ;
failwith "Unable to read cmdline"
in
let device = Db.PCI.get_pci_id ~__context ~self in
let elems = String.split_on_char ' ' cmdline in

let pciback = List.find_opt
(fun s -> String.starts_with ~prefix:"xen-pciback.hide=" s)
elems
let pciback =
List.find_opt
(fun s -> String.starts_with ~prefix:"xen-pciback.hide=" s)
elems
in

let contains s1 s2 =
let re = Re.Str.regexp_string s2 in
try ignore (Re.Str.search_forward re s1 0); true
try
ignore (Re.Str.search_forward re s1 0) ;
true
with Not_found -> false
in

match pciback with
| None -> false
| Some value -> contains value device
match pciback with None -> false | Some value -> contains value device

let determine_dom0_access_status ~__context ~self =
(* Current hidden status *)
let is_hidden_cmdline = is_pci_hidden_cmdline ~__context ~self in
(* Hidden status after reboot *)
let is_hidden = Pciops.is_pci_hidden ~__context self in
let new_access =
match is_hidden_cmdline, is_hidden with
| true, true -> `disabled
| false, true -> `disable_on_reboot
| false, false -> `enabled
| true, false -> `enable_on_reboot
match (is_hidden_cmdline, is_hidden) with
| true, true ->
`disabled
| false, true ->
`disable_on_reboot
| false, false ->
`enabled
| true, false ->
`enable_on_reboot
in

(* Keep up to date deprecated PGPU DB field, to eb removed eventually. *)
Expand All @@ -226,10 +231,10 @@ let determine_dom0_access_status ~__context ~self =

let update_dom0_access ~__context ~self ~action =
( match action with
| `enable ->
Pciops.unhide_pci ~__context self
| `disable ->
Pciops.hide_pci ~__context self
| `enable ->
Pciops.unhide_pci ~__context self
| `disable ->
Pciops.hide_pci ~__context self
) ;

determine_dom0_access_status ~__context ~self
8 changes: 6 additions & 2 deletions ocaml/xapi/xapi_pgpu.mli
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ val get_remaining_capacity :
-> int64

val assert_can_run_VGPU :
__context:Context.t -> self:API.ref_PGPU -> vgpu:API.ref_VGPU -> unit
__context:Context.t
-> self:API.ref_PGPU
-> vgpu:API.ref_VGPU -> unit
(** Check whether a VGPU can run on a particular PGPU. *)

val enable_dom0_access :
__context:Context.t -> self:API.ref_PGPU -> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
__context:Context.t
-> self:API.ref_PGPU
-> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]

val disable_dom0_access :
__context:Context.t -> self:API.ref_PGPU -> [`disable_on_reboot | `disabled | `enable_on_reboot | `enabled]
Expand Down

0 comments on commit a7a170e

Please sign in to comment.