Skip to content

Commit

Permalink
Add PCI to xe CLI
Browse files Browse the repository at this point in the history
New CLI methods:
- pci-enable-dom0-access
- pci-disable-dom0-access

Signed-off-by: Benjamin Reis <[email protected]>
  • Loading branch information
benjamreis committed Mar 13, 2024
1 parent d54aa96 commit 78aaa22
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ocaml/xapi-cli-server/cli_frontend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3680,6 +3680,24 @@ let rec cmdtable_data : (string * cmd_spec) list =
; flags= []
}
)
; ( "pci-enable-dom0-access"
, {
reqd= ["uuid"]
; optn= []
; help= "Enable PCI access to dom0."
; implementation= No_fd Cli_operations.pci_enable_dom0_access
; flags= []
}
)
; ( "pci-disable-dom0-access"
, {
reqd= ["uuid"]
; optn= []
; help= "Disable PCI access to dom0."
; implementation= No_fd Cli_operations.pci_disable_dom0_access
; flags= []
}
)
]

let cmdtable : (string, cmd_spec) Hashtbl.t = Hashtbl.create 50
Expand Down
17 changes: 17 additions & 0 deletions ocaml/xapi-cli-server/cli_operations.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,11 @@ let gen_cmds rpc session_id =
]
rpc session_id
)
; Client.PCI.(
mk get_all_records_where get_by_uuid pci_record "pci" []
["uuid"; "vendor-name"; "device-name"; "pci-id"]
rpc session_id
)
]

let message_create (_ : printer) rpc session_id params =
Expand Down Expand Up @@ -7473,6 +7478,18 @@ let lvhd_enable_thin_provisioning _printer rpc session_id params =
["sr-uuid"; "initial-allocation"; "allocation-quantum"]
)

let pci_enable_dom0_access printer rpc session_id params =
let uuid = List.assoc "uuid" params in
let ref = Client.PCI.get_by_uuid ~rpc ~session_id ~uuid in
let result = Client.PCI.enable_dom0_access ~rpc ~session_id ~self:ref in
printer (Cli_printer.PMsg (Record_util.pci_dom0_access_to_string result))

let pci_disable_dom0_access printer rpc session_id params =
let uuid = List.assoc "uuid" params in
let ref = Client.PCI.get_by_uuid ~rpc ~session_id ~uuid in
let result = Client.PCI.disable_dom0_access ~rpc ~session_id ~self:ref in
printer (Cli_printer.PMsg (Record_util.pci_dom0_access_to_string result))

module PVS_site = struct
let introduce printer rpc session_id params =
let name_label = List.assoc "name-label" params in
Expand Down
77 changes: 77 additions & 0 deletions ocaml/xapi-cli-server/records.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5500,3 +5500,80 @@ let observer_record rpc session_id observer =
()
]
}

let pci_record rpc session_id pci =
let _ref = ref pci in
let empty_record =
ToGet (fun () -> Client.PCI.get_record ~rpc ~session_id ~self:!_ref)
in
let record = ref empty_record in
let x () = lzy_get record in
let pci_record p =
ref (ToGet (fun () -> Client.PCI.get_record ~rpc ~session_id ~self:p))
in
let xp0 p = lzy_get (pci_record p) in
{
setref=
(fun r ->
_ref := r ;
record := empty_record
)
; setrefrec=
(fun (a, b) ->
_ref := a ;
record := Got b
)
; record= x
; getref= (fun () -> !_ref)
; fields=
[
make_field ~name:"uuid" ~get:(fun () -> (x ()).API.pCI_uuid) ()
; make_field ~name:"vendor-name"
~get:(fun () -> try (x ()).API.pCI_vendor_name with _ -> nid)
()
; make_field ~name:"device-name"
~get:(fun () -> try (x ()).API.pCI_device_name with _ -> nid)
()
; make_field ~name:"driver-name"
~get:(fun () -> try (x ()).API.pCI_driver_name with _ -> nid)
()
; make_field ~name:"host-uuid"
~get:(fun () ->
try get_uuid_from_ref (x ()).API.pCI_host with _ -> nid
)
()
; make_field ~name:"host-name-label"
~get:(fun () ->
try get_name_from_ref (x ()).API.pCI_host with _ -> nid
)
()
; make_field ~name:"pci-id"
~get:(fun () -> try (x ()).API.pCI_pci_id with _ -> nid)
()
; make_field ~name:"dependencies"
~get:(fun () ->
map_and_concat
(fun pci -> (xp0 pci).API.pCI_pci_id)
(x ()).API.pCI_dependencies
)
~get_set:(fun () ->
List.map
(fun pci -> (xp0 pci).API.pCI_pci_id)
(x ()).API.pCI_dependencies
)
()
; make_field ~name:"other-config"
~get:(fun () ->
Record_util.s2sm_to_string "; " (x ()).API.pCI_other_config
)
~add_to_map:(fun key value ->
Client.PCI.add_to_other_config ~rpc ~session_id ~self:pci ~key
~value
)
~remove_from_map:(fun key ->
Client.PCI.remove_from_other_config ~rpc ~session_id ~self:pci ~key
)
~get_map:(fun () -> (x ()).API.pCI_other_config)
()
]
}

0 comments on commit 78aaa22

Please sign in to comment.