Skip to content

Commit beab0b0

Browse files
mg12ctxlindig
authored andcommitted
CP-22500: support clean suspend,shutdown etc for HVM Linux using upstream qemu
The original qemu-trad patch added as part of CP-9364 was split into two: - a small upstream qemu patch that implements the xen platform io-port 0x10 and collects the product-num and build-num for the PV driver, and exposes them via the new query-xen-platform-pv-driver-info QMP command, see qemu.pg PR 34: . CP-23471: Expose product number and build number of XEN PV driver - this xenopsd patch, which collects product-num and build-num for the PV driver using the QMP command above, and using the original algorithm in qemu-trad, decides if the PV driver belongs to a HVM Linux guest. In this case, it writes to xenstore as qemu-trad would have done, see qemu-trad.pg patches: . CP-9364: write feature-flags to xenstore when HVM guest stops using emulated devices . CP-9364: xapi expects data/updated to exist This patch keeps the same behaviour present in the original qemu-trad patch, in order to maintain the the support for clean suspend, shutdown etc for the same set of HVM Linux guests. Signed-off-by: Marcus Granado <[email protected]>
1 parent 5a2b8db commit beab0b0

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

xc/device.ml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,6 +1912,29 @@ let stop ~xs ~qemu_domid domid =
19121912
stop_vgpu ();
19131913
stop_qemu ()
19141914

1915+
let is_hvm_linux domid =
1916+
let _XEN_IOPORT_LINUX_PRODNUM = 3 in (* from Linux include/xen/platform_pci.h *)
1917+
let error x = error "%s" x; Result.Error x in
1918+
try
1919+
let open Qmp in
1920+
match qmp_write_and_read domid (Command (None, Query_xen_platform_pv_driver_info)) with
1921+
| Some (Success (None, Xen_platform_pv_driver_info { product_num; build_num })) ->
1922+
Result.Ok ((product_num = _XEN_IOPORT_LINUX_PRODNUM) && (build_num <= 0xff))
1923+
| Some x ->
1924+
error (Printf.sprintf "Unexpected QMP response: %s" (Qmp.string_of_message x))
1925+
| None -> error "No QMP response for Query_xen_platform_pv_driver_info"
1926+
with e ->
1927+
error (Printf.sprintf "Exception attempting to obtain Linux product_id and build_number: %s" (Printexc.to_string e))
1928+
1929+
let maybe_write_pv_feature_flags ~xs domid =
1930+
if is_upstream_qemu domid then
1931+
match is_hvm_linux domid with
1932+
| Result.Ok true ->
1933+
let write_local_domain prefix x = xs.Xs.write (Printf.sprintf "/local/domain/%d/%s%s" domid prefix x) "1" in
1934+
List.iter (write_local_domain "control/feature-") ["suspend"; "shutdown"; "vcpu-hotplug"];
1935+
List.iter (write_local_domain "data/") ["updated"]
1936+
| _ -> ()
1937+
19151938
end (* End of module Dm *)
19161939

19171940
let get_vnc_port ~xs domid =

xc/device.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ sig
233233
val suspend : Xenops_task.task_handle -> xs:Xenstore.Xs.xsh -> qemu_domid:int -> Xenctrl.domid -> unit
234234
val resume : Xenops_task.task_handle -> xs:Xenstore.Xs.xsh -> qemu_domid:int -> Xenctrl.domid -> unit
235235
val stop : xs:Xenstore.Xs.xsh -> qemu_domid:int -> Xenctrl.domid -> unit
236+
237+
val maybe_write_pv_feature_flags : xs:Xenstore.Xs.xsh -> Xenctrl.domid -> unit
236238
end
237239

238240
val get_vnc_port : xs:Xenstore.Xs.xsh -> Xenctrl.domid -> int option

xc/xenops_server_xen.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,6 +2763,7 @@ module Actions = struct
27632763
let non_persistent = { non_persistent with VmExtra.pv_drivers_detected = true } in
27642764
debug "VM = %s; found PV driver evidence on %s (value = %s)" vm path value;
27652765
DB.write vm { VmExtra.persistent; non_persistent };
2766+
Device.Dm.maybe_write_pv_feature_flags ~xs domid;
27662767
Updates.add (Dynamic.Vm vm) internal_updates
27672768
end
27682769
with Xs_protocol.Enoent _ ->

0 commit comments

Comments
 (0)