Skip to content

Commit 8569f1d

Browse files
CA-187693: Check that all a VM's VIFs are mapped during migrate_send
Signed-off-by: Si Beaumont <[email protected]>
1 parent 00576e1 commit 8569f1d

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

ocaml/idl/api_errors.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ let vdi_not_managed = "VDI_NOT_MANAGED"
224224
let vdi_io_error = "VDI_IO_ERROR"
225225
let vdi_on_boot_mode_incompatible_with_operation = "VDI_ON_BOOT_MODE_INCOMPATIBLE_WITH_OPERATION"
226226
let vdi_not_in_map = "VDI_NOT_IN_MAP"
227+
let vif_not_in_map = "VIF_NOT_IN_MAP"
227228
let cannot_create_state_file = "CANNOT_CREATE_STATE_FILE"
228229

229230
let operation_partially_failed = "OPERATION_PARTIALLY_FAILED"

ocaml/idl/datamodel.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,8 @@ let _ =
998998
~doc:"This operation is not permitted on VMs containing VDIs in the 'on-boot=reset' mode" ();
999999
error Api_errors.cannot_create_state_file []
10001000
~doc:"An HA statefile could not be created, perhaps because no SR with the appropriate capability was found." ();
1001+
error Api_errors.vif_not_in_map [ "vif" ]
1002+
~doc:"This VIF was not mapped to a destination Network in VM.migrate_send operation" () ;
10011003

10021004
error Api_errors.sr_operation_not_supported [ "sr" ]
10031005
~doc:"The SR backend does not support the operation (check the SR's allowed operations)" ();

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =
315315
(* Create mirrors of all the disks on the remote *)
316316
let vm_uuid = Db.VM.get_uuid ~__context ~self:vm in
317317
let vbds = Db.VM.get_VBDs ~__context ~self:vm in
318+
let vifs = Db.VM.get_VIFs ~__context ~self:vm in
318319
let snapshots = Db.VM.get_snapshots ~__context ~self:vm in
319320
let vm_and_snapshots = vm :: snapshots in
320321
let snapshots_vbds = List.flatten (List.map (fun self -> Db.VM.get_VBDs ~__context ~self) snapshots) in
@@ -364,6 +365,15 @@ let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =
364365
error "VDI:SR map not fully specified for VDI %s" vdi_uuid ;
365366
raise (Api_errors.Server_error(Api_errors.vdi_not_in_map, [ Ref.string_of vdi ]))) vdis) ;
366367

368+
(* Assert that every VIF is specified in the VIF map *)
369+
List.iter (fun vif ->
370+
if not (List.mem_assoc vif vif_map)
371+
then
372+
let vif_uuid = Db.VIF.get_uuid ~__context ~self:vif in
373+
error "VIF:Network map not fully specified for VIF %s" vif_uuid;
374+
raise (Api_errors.Server_error(Api_errors.vif_not_in_map, [ Ref.string_of vif ]))
375+
) vifs;
376+
367377
(* Block SXM when VM has a VDI with on_boot=reset *)
368378
List.(iter (fun (vdi,_,_,_,_,_,_,_) ->
369379
if (Db.VDI.get_on_boot ~__context ~self:vdi ==`reset) then

0 commit comments

Comments
 (0)