Skip to content

Commit 64aac22

Browse files
committed
CA-273649: add xapi restriction when attach several host's usbs
This change is to add restriction when attaching usb to vm that the host of the usb is not in possible_hosts that vm can boot on. Signed-off-by: Taoyong Ding <taoyong.ding@citrix.com>
1 parent 091c65b commit 64aac22

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

ocaml/idl/datamodel.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,9 @@ let _ =
15151515
error Api_errors.pusb_vdi_conflict [ "PUSB"; "VDI" ]
15161516
~doc:"The VDI corresponding to this PUSB has existing VBDs." ();
15171517
error Api_errors.vm_has_vusbs ["VM"]
1518-
~doc:"The operation is not allowed when the VM has VUSBs." ()
1518+
~doc:"The operation is not allowed when the VM has VUSBs." ();
1519+
error Api_errors.pusb_not_in_possible_hosts [ "pusb"; "possible_hosts" ]
1520+
~doc:"The VM can't boot on the host that belongs to the pusb; it can boot only on the following hosts." ()
15191521

15201522
let _ =
15211523
message (fst Api_messages.ha_pool_overcommitted) ~doc:"Pool has become overcommitted: it can no longer guarantee to restart protected VMs if the configured number of hosts fail." ();

ocaml/xapi-consts/api_errors.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,3 +580,4 @@ let too_many_vusbs = "TOO_MANY_VUSBS"
580580
let passthrough_not_enabled = "PASSTHROUGH_NOT_ENABLED"
581581
let pusb_vdi_conflict = "PUSB_VDI_CONFLICT"
582582
let vm_has_vusbs = "VM_HAS_VUSBS"
583+
let pusb_not_in_possible_hosts = "PUSB_NOT_IN_POSSIBLE_HOSTS"

ocaml/xapi/xapi_vusb.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ let create ~__context ~vM ~uSB_group ~other_config =
3434
another vusb can not create with the same USB_group. *)
3535
if vusbs <> [] then
3636
raise (Api_errors.Server_error(Api_errors.usb_group_conflict, [Ref.string_of uSB_group]));
37+
38+
(* All USBs that will be attached to the VM must be on the same host, as USB from host A can
39+
not attach to the vm resident on host B. *)
40+
let possible_hosts = Xapi_vm.get_possible_hosts ~__context ~vm:vM in
41+
let pusb = Helpers.get_first_pusb ~__context uSB_group in
42+
let host = Db.PUSB.get_host ~__context ~self:pusb in
43+
if not (List.mem host possible_hosts) then
44+
raise (Api_errors.Server_error (Api_errors.pusb_not_in_possible_hosts, [Ref.string_of pusb; String.concat ";" (List.map Ref.string_of possible_hosts)]));
3745
(* We won't attach VUSB when VM ha_restart_priority is set to 'restart' *)
3846
let ha_restart_priority = Db.VM.get_ha_restart_priority ~__context ~self:vM in
3947
match ha_restart_priority with

0 commit comments

Comments
 (0)