Skip to content

Commit d1be351

Browse files
simonjbeaumontjohnelse
authored andcommitted
Disallow moving of PGPUs with resident VGPUs
The precondition was checking for PCI.attached_VMs on the PGPU's PCI. This isn't used for VGPU and so the check was not robust. Now we check using the resident_VGPUs field of the PGPU from the new API. Signed-off-by: Si Beaumont <[email protected]>
1 parent 676e588 commit d1be351

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ocaml/xapi/xapi_pgpu.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,21 @@ let set_GPU_group ~__context ~self ~value =
102102
debug "Move PGPU %s -> GPU group %s" (Db.PGPU.get_uuid ~__context ~self)
103103
(Db.GPU_group.get_uuid ~__context ~self:value);
104104
Mutex.execute gpu_group_m (fun () ->
105-
let pci = Db.PGPU.get_PCI ~__context ~self in
106-
107-
(* Precondition: PGPU not currently in use by a VM *)
108-
let attached_vms = Db.PCI.get_attached_VMs ~__context ~self:pci in
109-
if attached_vms <> [] then
105+
(* Precondition: PGPU has no resident VGPUs *)
106+
let resident_vgpus = Db.PGPU.get_resident_VGPUs ~__context ~self in
107+
if resident_vgpus <> [] then begin
108+
let resident_vms = List.map
109+
(fun self -> Db.VGPU.get_VM ~__context ~self) resident_vgpus in
110110
raise (Api_errors.Server_error (Api_errors.pgpu_in_use_by_vm,
111-
List.map Ref.string_of attached_vms));
111+
List.map Ref.string_of resident_vms))
112+
end;
112113

113114
let check_compatibility gpu_type group_types =
114115
match group_types with
115116
| [] -> true, [gpu_type]
116117
| _ -> List.mem gpu_type group_types, group_types in
117118

119+
let pci = Db.PGPU.get_PCI ~__context ~self in
118120
let gpu_type = Xapi_pci.string_of_pci ~__context ~self:pci
119121
and group_types = Db.GPU_group.get_GPU_types ~__context ~self:value in
120122
match check_compatibility gpu_type group_types with

0 commit comments

Comments
 (0)