Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[PV PCI passthrough]: temporarily switch to "xl pci-{attach,detach}" …

…invocations

Once the Xenlight ocaml bindings are repaired we can switch back to them.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
  • Loading branch information...
commit 50b8be048d3d874d7389f4491ed284de51ffb796 1 parent b258509
@djs55 djs55 authored
Showing with 50 additions and 22 deletions.
  1. +50 −22 ocaml/xenops/device.ml
View
72 ocaml/xenops/device.ml
@@ -1099,49 +1099,70 @@ let add_noexn ~xc ~xs ~hvm ~msitranslate ~pci_power_mgmt ?(flrscript=None) pcide
Generic.add_device ~xs device (others @ xsdevs @ backendlist) frontendlist [];
()
+let pci_info_of ~msitranslate ~pci_power_mgmt = function
+ | domain, bus, dev, func ->
+ {
+ (* XXX: I don't think we can guarantee how the C compiler will
+ lay out bitfields.
+ unsigned int reserved1:2;
+ unsigned int reg:6;
+ unsigned int func:3;
+ unsigned int dev:5;
+ unsigned int bus:8;
+ unsigned int reserved2:7;
+ unsigned int enable:1;
+ *)
+ Xenlight.v = (func lsl 8) lor (dev lsl 11) lor (bus lsl 16);
+ domain = domain;
+ vdevfn = 0;
+ msitranslate = msitranslate = 1;
+ power_mgmt = pci_power_mgmt = 1;
+ }
+
+
(* XXX: this will crash because of the logging policy within the
Xenlight ocaml bindings. *)
let add_libxl ~msitranslate ~pci_power_mgmt pcidevs domid =
List.iter
- (fun (domain, bus, dev, func) ->
+ (fun dev ->
try
- Xenlight.pci_add {
- (* XXX: I don't think we can guarantee how the C compiler will
- lay out bitfields.
- unsigned int reserved1:2;
- unsigned int reg:6;
- unsigned int func:3;
- unsigned int dev:5;
- unsigned int bus:8;
- unsigned int reserved2:7;
- unsigned int enable:1;
- *)
- Xenlight.v = (func lsl 8) lor (dev lsl 11) lor (bus lsl 16);
- domain = domain;
- vdevfn = 0;
- msitranslate = msitranslate = 1;
- power_mgmt = pci_power_mgmt = 1;
- } domid
+ Xenlight.pci_add (pci_info_of ~msitranslate ~pci_power_mgmt dev) domid
with e ->
debug "Xenlight.pci_add: %s" (Printexc.to_string e);
raise e
) pcidevs
+(* XXX: this will crash because of the logging policy within the
+ Xenlight ocaml bindings. *)
+let release_libxl ~msitranslate ~pci_power_mgmt pcidevs domid =
+ List.iter
+ (fun dev ->
+ try
+ Xenlight.pci_remove (pci_info_of ~msitranslate ~pci_power_mgmt dev) domid
+ with e ->
+ debug "Xenlight.pci_remove: %s" (Printexc.to_string e);
+ raise e
+ ) pcidevs
+
(* XXX: we don't want to use the 'xl' command here because the "interface"
isn't considered as stable as the C API *)
-let add_xl ~msitranslate ~pci_power_mgmt pcidevs domid =
+let xl_pci cmd ?(msitranslate=0) ?(pci_power_mgmt=0) pcidevs domid =
List.iter
(fun dev ->
try
let (_, _) = Forkhelpers.execute_command_get_output
"/usr/sbin/xl"
- [ "pci-attach"; string_of_int domid; to_string dev ] in
+ [ cmd; string_of_int domid; to_string dev ] in
()
with e ->
- debug "xl pci-attach: %s" (Printexc.to_string e);
+ debug "xl %s: %s" cmd (Printexc.to_string e);
raise e
) pcidevs
+let add_xl = xl_pci "pci-attach"
+
+let release_xl = xl_pci "pci-detach"
+
let add ~xc ~xs ~hvm ~msitranslate ~pci_power_mgmt ?flrscript pcidevs domid devid =
try
if hvm
@@ -1152,7 +1173,7 @@ let add ~xc ~xs ~hvm ~msitranslate ~pci_power_mgmt ?flrscript pcidevs domid devi
with exn ->
raise (Cannot_add (pcidevs, exn))
-let release ~xc ~xs ~hvm pcidevs domid devid =
+let release_exn ~xc ~xs ~hvm pcidevs domid devid =
let pcidevs = List.map (fun (domain, bus, slot, func) ->
let (irq, resources, driver) = query_pci_device domain bus slot func in
{ domain = domain; bus = bus; slot = slot; func = func;
@@ -1171,6 +1192,13 @@ let release ~xc ~xs ~hvm pcidevs domid devid =
) pcidevs;
()
+let release ~xc ~xs ~hvm pcidevs domid devid =
+ if hvm
+ then release_exn ~xc ~xs ~hvm pcidevs domid devid
+ else
+ (* Switch the PV path over to libxl since the code is better *)
+ release_xl pcidevs domid
+
let write_string_to_file file s =
let fn_write_string fd = Unixext.really_write fd s 0 (String.length s) in
Unixext.with_file file [ Unix.O_WRONLY ] 0o640 fn_write_string

0 comments on commit 50b8be0

Please sign in to comment.
Something went wrong with that request. Please try again.