Skip to content

Commit 33ebbb9

Browse files
committed
Adding review changes
Signed-off-by: Sharad Yadav <[email protected]>
1 parent 33328ae commit 33ebbb9

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

ocaml/idl/api_errors.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ let vm_has_checkpoint = "VM_HAS_CHECKPOINT"
505505

506506
let mirror_failed = "MIRROR_FAILED"
507507
let too_many_storage_migrates = "TOO_MANY_STORAGE_MIGRATES"
508-
let vdi_on_rawhba_sr = "VDI_ON_RAWHBA_SR"
508+
let sr_does_not_support_migration = "SR_DOES_NOT_SUPPORT_MIGRATION"
509509
let unimplemented_in_sm_backend = "UNIMPLEMENTED_IN_SM_BACKEND"
510510

511511
let vm_call_plugin_rate_limit = "VM_CALL_PLUGIN_RATE_LIMIT"

ocaml/idl/datamodel.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,8 @@ let _ =
917917
~doc:"The VDI mirroring cannot be performed" ();
918918
error Api_errors.too_many_storage_migrates [ "number" ]
919919
~doc:"You reached the maximal number of concurrently migrating VMs." ();
920-
error Api_errors.vdi_on_rawhba_sr [ "vdi" ]
921-
~doc:"You attempted to migrate a VDI which is on rawHBA SR." ();
920+
error Api_errors.sr_does_not_support_migration [ "sr" ]
921+
~doc:"You attempted to migrate a VDI on SR which doesn't have snapshot capability" ();
922922
error Api_errors.vm_failed_shutdown_ack []
923923
~doc:"VM didn't acknowledge the need to shutdown." ();
924924
error Api_errors.vm_shutdown_timeout [ "vm"; "timeout" ]

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,25 @@ open Storage_interface
5757
open Listext
5858
open Fun
5959

60-
let assert_vdi_on_rawhba ~__context ~vdi_map ~remote_rpc ~session_id =
60+
let assert_sr_support_migration ~__context ~vdi_map ~remote_rpc ~session_id =
61+
(* Get destination host SM record *)
62+
let sm_record = XenAPI.SM.get_all_records remote_rpc session_id in
6163
List.iter (fun (vdi, sr) ->
64+
(* Check VDIs must not be present on SR which doesn't have snapshot capability *)
6265
let source_sr = Db.VDI.get_SR ~__context ~self:vdi in
63-
(* Check VDIs must not be present on rawHBA source SR
64-
* OR VDIs must not be mirrored to rawHBA destination SR
65-
* *)
66-
if (Db.SR.get_type ~__context ~self:source_sr = "rawhba") ||
67-
(XenAPI.SR.get_type remote_rpc session_id sr = "rawhba") then
68-
raise (Api_errors.Server_error(Api_errors.vdi_on_rawhba_sr, [Ref.string_of vdi]))
66+
let sr_record = Db.SR.get_record_internal ~__context ~self:source_sr in
67+
let sr_features = Xapi_sr_operations.features_of_sr ~__context sr_record in
68+
if not Smint.(has_capability Vdi_snapshot sr_features) then
69+
raise (Api_errors.Server_error(Api_errors.sr_does_not_support_migration, [Ref.string_of source_sr]));
70+
(* Check VDIs must not be mirrored to SR which doesn't have snapshot capability *)
71+
let sr_type = XenAPI.SR.get_type remote_rpc session_id sr in
72+
let sm_capabilities =
73+
match List.filter (fun (_, r) -> r.API.sM_type = sr_type) sm_record with
74+
| [ _, plugin ] -> plugin.API.sM_capabilities
75+
| _ -> []
76+
in
77+
if not (List.exists (fun cp -> cp = "Vdi_snapshot") sm_capabilities) then
78+
raise (Api_errors.Server_error(Api_errors.sr_does_not_support_migration, [Ref.string_of sr]))
6979
) vdi_map
7080

7181
let assert_licensed_storage_motion ~__context =
@@ -837,8 +847,8 @@ let assert_can_migrate ~__context ~vm ~dest ~live ~vdi_map ~vif_map ~options =
837847
~host_to;
838848
(* Check the host can support the VM's required version of virtual hardware platform *)
839849
Xapi_vm_helpers.assert_hardware_platform_support ~__context ~vm ~host:host_to;
840-
(* Check VDIs are not on rawHBA SR *)
841-
assert_vdi_on_rawhba ~__context ~vdi_map ~remote_rpc ~session_id;
850+
(* Check VDIs are not on SR which doesn't have snapshot capability *)
851+
assert_sr_support_migration ~__context ~vdi_map ~remote_rpc ~session_id;
842852

843853
(*Check that the remote host is enabled and not in maintenance mode*)
844854
let check_host_enabled = XenAPI.Host.get_enabled remote_rpc session_id (dest_host_ref) in

0 commit comments

Comments
 (0)