From 0158308828dd9847e9333819de76ee218118a1d3 Mon Sep 17 00:00:00 2001 From: Bob Ball Date: Tue, 9 Apr 2013 12:38:03 +0100 Subject: [PATCH] CP-4498: Added relaxed check mode to allow iSCSI SRs during XSM Signed-off-by: Bob Ball bob.ball@citrix.com --- ocaml/xapi/xapi_config.ml | 1 + ocaml/xapi/xapi_globs.ml | 3 +++ ocaml/xapi/xapi_vm_migrate.ml | 39 +++++++++++++++++++++++++++++++++-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ocaml/xapi/xapi_config.ml b/ocaml/xapi/xapi_config.ml index 7ddadaedd0..87f071a4d4 100644 --- a/ocaml/xapi/xapi_config.ml +++ b/ocaml/xapi/xapi_config.ml @@ -25,6 +25,7 @@ let read_config filename = let configargs = [ "use-xenopsd", Config.Set_bool Xapi_globs.use_xenopsd; Config_shared.disable_logging_for; + "relax-xsm-sr-check", Config.Set_bool Xapi_globs.relax_xsm_sr_check; ] in try Config.read filename configargs (fun _ _ -> ()) diff --git a/ocaml/xapi/xapi_globs.ml b/ocaml/xapi/xapi_globs.ml index ebb5fc97c7..40e3e7b263 100644 --- a/ocaml/xapi/xapi_globs.ml +++ b/ocaml/xapi/xapi_globs.ml @@ -22,6 +22,9 @@ module D = Debug.Debugger(struct let name="xapi_globs" end) (* set this to true to use the experimental codepath *) let use_xenopsd = ref false +(* set this to true to enable XSM to out-of-pool SRs with matching UUID *) +let relax_xsm_sr_check = ref false + (* xapi process returns this code on exit when it wants to be restarted *) let restart_return_code = 123 diff --git a/ocaml/xapi/xapi_vm_migrate.ml b/ocaml/xapi/xapi_vm_migrate.ml index dffddde49a..7771833b87 100644 --- a/ocaml/xapi/xapi_vm_migrate.ml +++ b/ocaml/xapi/xapi_vm_migrate.ml @@ -274,11 +274,46 @@ let migrate_send' ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options = let vdi_uuid = Db.VDI.get_uuid ~__context ~self:vdi in failwith ("No SR specified in VDI map for VDI " ^ vdi_uuid) in - let mirror = (not is_intra_pool) || (dest_sr <> sr) in + + + let rec dest_vdi_exists_on_sr vdi_uuid sr_ref retry = + try + let dest_vdi_ref = XenAPI.VDI.get_by_uuid remote_rpc session_id vdi_uuid in + let dest_vdi_sr_ref = XenAPI.VDI.get_SR remote_rpc session_id dest_vdi_ref in + if dest_vdi_sr_ref = sr_ref then + true + else + false + with _ -> + if retry then + begin + XenAPI.SR.scan remote_rpc session_id sr_ref; + dest_vdi_exists_on_sr vdi_uuid sr_ref false + end + else + false + in + + let vdi_uuid = Db.VDI.get_uuid ~__context ~self:vdi in + let mirror = if !Xapi_globs.relax_xsm_sr_check then + if (dest_sr = sr) then + begin + (* Check if the VDI uuid already exists in the target SR *) + if (dest_vdi_exists_on_sr vdi_uuid dest_sr_ref true) then + false + else + failwith ("SR UUID matches on destination but VDI does not exist") + end + else + true + else + (not is_intra_pool) || (dest_sr <> sr) + in let remote_vdi,remote_vdi_reference,newdp = if not mirror then - location,vdi,"none" + let dest_vdi_ref = XenAPI.VDI.get_by_uuid remote_rpc session_id vdi_uuid in + location,dest_vdi_ref,"none" else begin let newdp = Printf.sprintf "mirror_%s" dp in ignore(SMAPI.VDI.attach ~dbg ~dp:newdp ~sr ~vdi:location ~read_write:false);