Skip to content

Commit 6234d34

Browse files
committed
CA-223505 detach a VM's network (PVS) when migrating away from a host
The detach is part of xapi_vm_migrate:{pool_migrate, migrate_send}. Previously PVS resources would not be freed because the network was not explicitly detached. Signed-off-by: Christian Lindig <[email protected]>
1 parent 79bc6b3 commit 6234d34

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,16 @@ let rec migrate_with_retries ~__context queue_name max try_no dbg vm_uuid xenops
177177
let migrate_with_retry ~__context queue_name dbg vm_uuid xenops_vdi_map xenops_vif_map xenops =
178178
migrate_with_retries ~__context queue_name 3 1 dbg vm_uuid xenops_vdi_map xenops_vif_map xenops
179179

180+
(** detach the network of [vm] if it is migrating away to [destination] *)
181+
let detach_local_network_for_vm ~__context ~vm ~destination =
182+
let src, dst = Helpers.get_localhost ~__context, destination in
183+
let ref = Ref.string_of in
184+
if src <> dst then begin
185+
info "VM %s migrated from %s to %s - detaching VM's network at source"
186+
(ref vm) (ref src) (ref dst);
187+
Xapi_network.detach_for_vm ~__context ~host:src ~vm;
188+
end (* else: localhost migration - nothing to do *)
189+
180190
let pool_migrate ~__context ~vm ~host ~options =
181191
if (not (Pool_features.is_enabled ~__context Features.Xen_motion)) then
182192
raise (Api_errors.Server_error(Api_errors.license_restriction, []));
@@ -198,6 +208,7 @@ let pool_migrate ~__context ~vm ~host ~options =
198208
Xapi_xenops.Xenopsd_metadata.delete ~__context vm_uuid;
199209
);
200210
Rrdd_proxy.migrate_rrd ~__context ~vm_uuid ~host_uuid:(Ref.string_of host) ();
211+
detach_local_network_for_vm ~__context ~vm ~destination:host;
201212
Helpers.call_api_functions ~__context (fun rpc session_id ->
202213
XenAPI.VM.pool_migrate_complete rpc session_id vm host
203214
);
@@ -893,7 +904,7 @@ let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =
893904
| Xenops_interface.Does_not_exist ("extra",_) ->
894905
()
895906
end;
896-
907+
detach_local_network_for_vm ~__context ~vm ~destination:remote.dest_host;
897908
debug "Migration complete";
898909
SMPERF.debug "vm.migrate_send: migration complete vm:%s" vm_uuid;
899910

0 commit comments

Comments
 (0)