Skip to content

Commit 874f648

Browse files
sharadyrobhoes
authored andcommitted
CA-192449: Don't special-case HVM-without-drivers when setting allowed_{VBD,VIF}_devices
HVM guests without PV drivers only support 4 VBD or VIF devices, where VMs with drivers follow wider limits. We used to make this distinction when setting allowed_{VBD,VIF}_devices. However, detecting PV drivers at the right time is tricky, so we simplify this to always allow the PV range. Signed-off-by: Sharad Yadav <[email protected]> Signed-off-by: Rob Hoes <[email protected]>
1 parent 358aa80 commit 874f648

File tree

1 file changed

+13
-27
lines changed

1 file changed

+13
-27
lines changed

ocaml/xapi/xapi_vm_helpers.ml

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -783,14 +783,16 @@ let vif_inclusive_range a b =
783783
(* These are high-watermark limits as documented in CA-6525. Individual guest types
784784
may be further restricted. *)
785785

786-
let allowed_VBD_devices_HVM = vbd_inclusive_range true 0 3
787-
let allowed_VBD_devices_HVM_PP = vbd_inclusive_range true 0 254
786+
(* HVM guests without PV drivers only support 4 VBD or VIF devices, where VMs with drivers follow
787+
* the wider limits below. We used to make this distinction here when setting allowed_{VBD,VIF}_devices.
788+
* However, detecting PV drivers at the right time is tricky, so we have simplified this to always
789+
* allow the PV range. *)
790+
let allowed_VBD_devices_HVM = vbd_inclusive_range true 0 254
788791
let allowed_VBD_devices_PV = vbd_inclusive_range false 0 254
789792
let allowed_VBD_devices_control_domain = vbd_inclusive_range false 0 255
790793
let allowed_VBD_devices_HVM_floppy = List.map (fun x -> Device_number.make (Device_number.Floppy, x, 0)) (inclusive_range 0 1)
791794

792-
let allowed_VIF_devices_HVM = vif_inclusive_range 0 3
793-
let allowed_VIF_devices_HVM_PP = vif_inclusive_range 0 6
795+
let allowed_VIF_devices_HVM = vif_inclusive_range 0 6
794796
let allowed_VIF_devices_PV = vif_inclusive_range 0 6
795797

796798
(** [possible_VBD_devices_of_string s] returns a list of Device_number.t which
@@ -815,36 +817,20 @@ let all_used_VBD_devices ~__context ~self =
815817
let allowed_VBD_devices ~__context ~vm ~_type =
816818
let is_hvm = Helpers.will_boot_hvm ~__context ~self:vm in
817819
let is_control_domain = Db.VM.get_is_control_domain ~__context ~self:vm in
818-
let is_pp =
819-
try
820-
let guest_metrics = Db.VM.get_guest_metrics ~__context ~self:vm in
821-
(Db.VM_guest_metrics.get_PV_drivers_version ~__context ~self:guest_metrics) <> []
822-
with _ -> false in
823-
let all_devices = match is_hvm,is_pp,is_control_domain,_type with
824-
| true, _, _, `Floppy -> allowed_VBD_devices_HVM_floppy
825-
| false, _, _, `Floppy -> [] (* floppy is not supported on PV *)
826-
| false, _, true, _ -> allowed_VBD_devices_control_domain
827-
| false, _, false, _ -> allowed_VBD_devices_PV
828-
| true, false, _, _ -> allowed_VBD_devices_HVM
829-
| true, true, _, _ -> allowed_VBD_devices_HVM_PP
820+
let all_devices = match is_hvm,is_control_domain,_type with
821+
| true, _, `Floppy -> allowed_VBD_devices_HVM_floppy
822+
| false, _, `Floppy -> [] (* floppy is not supported on PV *)
823+
| false, true, _ -> allowed_VBD_devices_control_domain
824+
| false, false, _ -> allowed_VBD_devices_PV
825+
| true, _, _ -> allowed_VBD_devices_HVM
830826
in
831827
(* Filter out those we've already got VBDs for *)
832828
let used_devices = all_used_VBD_devices ~__context ~self:vm in
833829
List.filter (fun dev -> not (List.mem dev used_devices)) all_devices
834830

835831
let allowed_VIF_devices ~__context ~vm =
836832
let is_hvm = Helpers.will_boot_hvm ~__context ~self:vm in
837-
let guest_metrics = Db.VM.get_guest_metrics ~__context ~self:vm in
838-
let is_pp =
839-
try (Db.VM_guest_metrics.get_PV_drivers_version ~__context ~self:guest_metrics) <> []
840-
with _ -> false
841-
in
842-
let all_devices =
843-
match is_hvm,is_pp with
844-
| false,_ -> allowed_VIF_devices_PV
845-
| true,false -> allowed_VIF_devices_HVM
846-
| true,true -> allowed_VIF_devices_HVM_PP
847-
in
833+
let all_devices = if is_hvm then allowed_VIF_devices_HVM else allowed_VIF_devices_PV in
848834
(* Filter out those we've already got VIFs for *)
849835
let all_vifs = Db.VM.get_VIFs ~__context ~self:vm in
850836
let used_devices = List.map (fun vif -> Db.VIF.get_device ~__context ~self:vif) all_vifs in

0 commit comments

Comments
 (0)