Skip to content

Commit

Permalink
TBD: remove code duplication
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Reis <[email protected]>
  • Loading branch information
benjamreis committed Mar 25, 2024
1 parent eb576f8 commit 23238fa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 29 deletions.
31 changes: 2 additions & 29 deletions ocaml/xapi/xapi_pci.ml
Original file line number Diff line number Diff line change
Expand Up @@ -320,38 +320,11 @@ let get_system_display_device () =
None items
with _ -> None

let update_dom0_access ~__context ~self ~action =
let expr = Printf.sprintf "field \"PCI\"=\"%s\"" (Ref.string_of self) in
let pgpus = Db.PGPU.get_all_records_where ~__context ~expr in
List.iter (
fun (pgpu_ref, _) -> (
let db_current = Db.PGPU.get_dom0_access ~__context ~self in
let db_new =
match (db_current, action) with
| `enabled, `enable | `disable_on_reboot, `enable ->
`enabled
| `disabled, `enable | `enable_on_reboot, `enable ->
`enable_on_reboot
| `enabled, `disable | `disable_on_reboot, `disable ->
`disable_on_reboot
| `disabled, `disable | `enable_on_reboot, `disable ->
`disabled
in
Db.PGPU.set_dom0_access ~__context ~self:pgpu_ref ~value:db_new
)
) pgpus ;
( match action with
| `enable ->
Pciops.unhide_pci ~__context self
| `disable ->
Pciops.hide_pci ~__context self
)

let disable_dom0_access ~__context ~self =
update_dom0_access ~__context ~self ~action:`disable
Xapi_pci_helpers.update_dom0_access ~__context ~pci:self ~action:`disable ;

let enable_dom0_access ~__context ~self =
update_dom0_access ~__context ~self ~action:`enable
Xapi_pci_helpers.update_dom0_access ~__context ~pci:self ~action:`enable ;

let is_dom0_access_enabled ~__context ~self =
not (Pciops.is_pci_hidden ~__context self)
32 changes: 32 additions & 0 deletions ocaml/xapi/xapi_pci_helpers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,35 @@ let get_host_pcis () =
let igd_is_whitelisted ~__context pci =
let vendor_id = Db.PCI.get_vendor_id ~__context ~self:pci in
List.mem vendor_id !Xapi_globs.igd_passthru_vendor_whitelist

let update_dom0_access ~__context ~pci ~action =
let db_new = ref (
match action with
| `enable ->
Pciops.unhide_pci ~__context pci ;
`enabled
| `disable ->
Pciops.hide_pci ~__context pci ;
`disabled
)
in
let expr = Printf.sprintf "field \"PCI\"=\"%s\"" (Ref.string_of pci) in
let pgpus = Db.PGPU.get_all_records_where ~__context ~expr in
List.iter (
fun (pgpu_ref, _) -> (
let db_current = Db.PGPU.get_dom0_access ~__context ~self:pgpu_ref in
db_new :=
( match (db_current, action) with
| `enabled, `enable | `disable_on_reboot, `enable ->
`enabled
| `disabled, `enable | `enable_on_reboot, `enable ->
`enable_on_reboot
| `enabled, `disable | `disable_on_reboot, `disable ->
`disable_on_reboot
| `disabled, `disable | `enable_on_reboot, `disable ->
`disabled
) ;
Db.PGPU.set_dom0_access ~__context ~self:pgpu_ref ~value:!db_new
)
) pgpus ;
!db_new

0 comments on commit 23238fa

Please sign in to comment.