Skip to content

Commit

Permalink
Merge pull request #821 from johnelse/ca-88388
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-git committed Aug 14, 2012
2 parents f003243 + 3efde3e commit e1f6087
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ocaml/xapi/cli_frontend.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ let rec cmdtable_data : (string*cmd_spec) list =
"vm-migrate", "vm-migrate",
{ {
reqd=[]; reqd=[];
optn=["live"; "host"; "host-uuid"; "remote-address"; "remote-username"; "remote-password"; "remote-network"; "destination-sr-uuid"; "encrypt"; "force"; "vif"; "vdi"]; optn=["live"; "host"; "host-uuid"; "remote-address"; "remote-username"; "remote-password"; "remote-network"; "destination-sr-uuid"; "encrypt"; "force"; "vif:"; "vdi:"];
help="Migrate the selected VM(s). The parameter '--live' will migrate the VM without shutting it down. The 'host' parameter matches can be either the name or the uuid of the host. The parameter '--encrypt' will encrypt the memory image transfer."; help="Migrate the selected VM(s). The parameter '--live' will migrate the VM without shutting it down. The 'host' parameter matches can be either the name or the uuid of the host. The parameter '--encrypt' will encrypt the memory image transfer.";
implementation=No_fd Cli_operations.vm_migrate; implementation=No_fd Cli_operations.vm_migrate;
flags=[Standard; Vm_selectors]; flags=[Standard; Vm_selectors];
Expand Down
17 changes: 16 additions & 1 deletion ocaml/xapi/import.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -841,25 +841,40 @@ module VIF : HandlerTools = struct
let vif_exists () = try ignore (get_vif ()); true with _ -> false in let vif_exists () = try ignore (get_vif ()); true with _ -> false in


if config.full_restore && vif_exists () then begin if config.full_restore && vif_exists () then begin
(* If there's already a VIF with the same UUID and we're preserving UUIDs, use that one. *)
let vif = get_vif () in let vif = get_vif () in
Found_VIF vif Found_VIF vif
end else end else
(* If not restoring a full backup then blank the MAC so it is regenerated *) (* If not restoring a full backup then blank the MAC so it is regenerated *)
let vif_record = { vif_record with API.vIF_MAC = let vif_record = { vif_record with API.vIF_MAC =
if config.full_restore then vif_record.API.vIF_MAC else "" } in if config.full_restore then vif_record.API.vIF_MAC else "" } in
(* Determine the VM to which we're going to attach this VIF. *)
let vm = log_reraise let vm = log_reraise
("Failed to find VIF's VM: " ^ (Ref.string_of vif_record.API.vIF_VM)) ("Failed to find VIF's VM: " ^ (Ref.string_of vif_record.API.vIF_VM))
(lookup vif_record.API.vIF_VM) state.table in (lookup vif_record.API.vIF_VM) state.table in
(* Determine the network to which we're going to attach this VIF. *)
let net = let net =
(* If we find the cross-pool migration key, attach the VIF to that network... *)
if List.mem_assoc Constants.storage_migrate_vif_map_key vif_record.API.vIF_other_config if List.mem_assoc Constants.storage_migrate_vif_map_key vif_record.API.vIF_other_config
then Ref.of_string (List.assoc Constants.storage_migrate_vif_map_key vif_record.API.vIF_other_config) then Ref.of_string (List.assoc Constants.storage_migrate_vif_map_key vif_record.API.vIF_other_config)
else else
(* ...otherwise fall back to looking up the network from the state table. *)
log_reraise log_reraise
("Failed to find VIF's Network: " ^ (Ref.string_of vif_record.API.vIF_network)) ("Failed to find VIF's Network: " ^ (Ref.string_of vif_record.API.vIF_network))
(lookup vif_record.API.vIF_network) state.table in (lookup vif_record.API.vIF_network) state.table in
(* Make sure we remove the cross-pool migration VIF mapping key from the other_config
* before creating a VIF - otherwise we'll risk sending this key on to another pool
* during a future cross-pool migration and it won't make sense. *)
let other_config =
List.filter
(fun (k, _) -> k <> Constants.storage_migrate_vif_map_key)
vif_record.API.vIF_other_config
in
(* Construct the VIF record we're going to try to create locally. *)
let vif_record = { vif_record with let vif_record = { vif_record with
API.vIF_VM = vm; API.vIF_VM = vm;
API.vIF_network = net } in API.vIF_network = net;
API.vIF_other_config = other_config } in
Create vif_record Create vif_record


let handle_dry_run __context config rpc session_id state x precheck_result = let handle_dry_run __context config rpc session_id state x precheck_result =
Expand Down
31 changes: 16 additions & 15 deletions ocaml/xapi/xapi_vm_migrate.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -164,7 +164,15 @@ let intra_pool_vdi_remap ~__context vm vdi_map =
Db.VBD.set_VDI ~__context ~self:vbd ~value:mirror_record.mr_remote_vdi_reference) vbds Db.VBD.set_VDI ~__context ~self:vbd ~value:mirror_record.mr_remote_vdi_reference) vbds




let inter_pool_metadata_transfer ~__context ~remote_rpc ~session_id ~remote_address ~vm ~vdi_map ~dry_run ~live = let inter_pool_metadata_transfer ~__context ~remote_rpc ~session_id ~remote_address ~vm ~vdi_map ~vif_map ~dry_run ~live =
List.iter (fun (vdi,mirror_record) ->
Db.VDI.remove_from_other_config ~__context ~self:vdi ~key:Constants.storage_migrate_vdi_map_key;
Db.VDI.add_to_other_config ~__context ~self:vdi ~key:Constants.storage_migrate_vdi_map_key ~value:(Ref.string_of mirror_record.mr_remote_vdi_reference)) vdi_map;

List.iter (fun (vif,network) ->
Db.VIF.remove_from_other_config ~__context ~self:vif ~key:Constants.storage_migrate_vif_map_key;
Db.VIF.add_to_other_config ~__context ~self:vif ~key:Constants.storage_migrate_vif_map_key ~value:(Ref.string_of network)) vif_map;

let vm_export_import = { let vm_export_import = {
Importexport.vm = vm; dry_run = dry_run; live = live; send_snapshots=true; Importexport.vm = vm; dry_run = dry_run; live = live; send_snapshots=true;
} in } in
Expand All @@ -173,10 +181,13 @@ let inter_pool_metadata_transfer ~__context ~remote_rpc ~session_id ~remote_addr
Importexport.remote_metadata_export_import ~__context Importexport.remote_metadata_export_import ~__context
~rpc:remote_rpc ~session_id ~remote_address (`Only vm_export_import)) ~rpc:remote_rpc ~session_id ~remote_address (`Only vm_export_import))
(fun () -> (fun () ->
(* Make sure we clean up the remote VDI mapping keys. *) (* Make sure we clean up the remote VDI and VIF mapping keys. *)
List.iter List.iter
(fun (vdi, _) -> Db.VDI.remove_from_other_config ~__context ~self:vdi ~key:Constants.storage_migrate_vdi_map_key) (fun (vdi, _) -> Db.VDI.remove_from_other_config ~__context ~self:vdi ~key:Constants.storage_migrate_vdi_map_key)
vdi_map) vdi_map;
List.iter
(fun (vif, _) -> Db.VIF.remove_from_other_config ~__context ~self:vif ~key:Constants.storage_migrate_vif_map_key)
vif_map)


let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options = let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =
SMPERF.debug "vm.migrate_send called vm:%s" (Db.VM.get_uuid ~__context ~self:vm); SMPERF.debug "vm.migrate_send called vm:%s" (Db.VM.get_uuid ~__context ~self:vm);
Expand Down Expand Up @@ -343,16 +354,6 @@ let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =


let xenops_vdi_map = List.map (fun (_, mirror_record) -> (mirror_record.mr_local_xenops_locator, mirror_record.mr_remote_xenops_locator)) (snapshots_map @ vdi_map) in let xenops_vdi_map = List.map (fun (_, mirror_record) -> (mirror_record.mr_local_xenops_locator, mirror_record.mr_remote_xenops_locator)) (snapshots_map @ vdi_map) in


List.iter (fun (vdi,mirror_record) ->
let other_config = Db.VDI.get_other_config ~__context ~self:vdi in
if List.mem_assoc Constants.storage_migrate_vdi_map_key other_config then
Db.VDI.remove_from_other_config ~__context ~self:vdi ~key:Constants.storage_migrate_vdi_map_key;
Db.VDI.add_to_other_config ~__context ~self:vdi ~key:Constants.storage_migrate_vdi_map_key ~value:(Ref.string_of mirror_record.mr_remote_vdi_reference)) (snapshots_map @ vdi_map);

List.iter (fun (vif,network) ->
Db.VIF.remove_from_other_config ~__context ~self:vif ~key:Constants.storage_migrate_vif_map_key;
Db.VIF.add_to_other_config ~__context ~self:vif ~key:Constants.storage_migrate_vif_map_key ~value:(Ref.string_of network)) vif_map;

(* Wait for delay fist to disappear *) (* Wait for delay fist to disappear *)
if Xapi_fist.pause_storage_migrate () then begin if Xapi_fist.pause_storage_migrate () then begin
TaskHelper.add_to_other_config ~__context "fist" "pause_storage_migrate"; TaskHelper.add_to_other_config ~__context "fist" "pause_storage_migrate";
Expand All @@ -374,7 +375,7 @@ let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =
intra_pool_vdi_remap ~__context vm (snapshots_map @ vdi_map) ; intra_pool_vdi_remap ~__context vm (snapshots_map @ vdi_map) ;
intra_pool_fix_suspend_sr ~__context (Ref.of_string dest_host) vm intra_pool_fix_suspend_sr ~__context (Ref.of_string dest_host) vm
end end
else inter_pool_metadata_transfer ~__context ~remote_rpc ~session_id ~remote_address:remote_master_address ~vm ~vdi_map:(snapshots_map @ vdi_map) ~dry_run:false ~live:true; else inter_pool_metadata_transfer ~__context ~remote_rpc ~session_id ~remote_address:remote_master_address ~vm ~vdi_map:(snapshots_map @ vdi_map) ~vif_map ~dry_run:false ~live:true;


if Xapi_fist.pause_storage_migrate2 () then begin if Xapi_fist.pause_storage_migrate2 () then begin
TaskHelper.add_to_other_config ~__context "fist" "pause_storage_migrate2"; TaskHelper.add_to_other_config ~__context "fist" "pause_storage_migrate2";
Expand Down Expand Up @@ -576,7 +577,7 @@ let assert_can_migrate ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =
~remote:(remote_rpc, session_id) (); ~remote:(remote_rpc, session_id) ();


(* Ignore vdi_map for now since we won't be doing any mirroring. *) (* Ignore vdi_map for now since we won't be doing any mirroring. *)
try inter_pool_metadata_transfer ~__context ~remote_rpc ~session_id ~remote_address ~vm ~vdi_map:[] ~dry_run:true ~live:true try inter_pool_metadata_transfer ~__context ~remote_rpc ~session_id ~remote_address ~vm ~vdi_map:[] ~vif_map ~dry_run:true ~live:true
with Xmlrpc_client.Connection_reset -> with Xmlrpc_client.Connection_reset ->
raise (Api_errors.Server_error(Api_errors.cannot_contact_host, [remote_address])) raise (Api_errors.Server_error(Api_errors.cannot_contact_host, [remote_address]))


Expand Down

0 comments on commit e1f6087

Please sign in to comment.