Skip to content

Commit 1fd6db6

Browse files
authored
xapi_vm_migrate: add capabilities to migration not supported by sr error (xapi-project#6829)
The error does not make it clear at all what are the capabilities that are stopping it from supporting migration, which makes debugging issues difficult, add a string that contains them. This can be easily ignored by default in clients, but the information is easily available if needed. We have come up with an issue where the migration is blocked, but the SM seems to report the correct capabilities, so more information is needed to understand the error.
2 parents a6aa363 + 5bf2fb7 commit 1fd6db6

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

ocaml/idl/datamodel_errors.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1059,7 +1059,7 @@ let _ =
10591059
~doc:"The VDI mirroring cannot be performed" () ;
10601060
error Api_errors.too_many_storage_migrates ["number"]
10611061
~doc:"You reached the maximal number of concurrently migrating VMs." () ;
1062-
error Api_errors.sr_does_not_support_migration ["sr"]
1062+
error Api_errors.sr_does_not_support_migration ["sr"; "capabilities"]
10631063
~doc:"Cannot migrate a VDI to or from an SR that doesn't support migration."
10641064
() ;
10651065
error Api_errors.vm_failed_shutdown_ack ["vm"]

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,19 +160,25 @@ end))
160160

161161
open Storage_interface
162162

163+
let supported_on ~ops sr sr_features =
164+
let open Smint.Feature in
165+
let missing =
166+
List.filter (fun op -> not (has_capability op sr_features)) ops
167+
in
168+
if missing <> [] then
169+
let missing = List.map capability_to_string missing |> String.concat ";" in
170+
let msg = [Ref.string_of sr; missing] in
171+
raise Api_errors.(Server_error (sr_does_not_support_migration, msg))
172+
163173
let assert_sr_support_operations ~__context ~vdi_map ~remote ~local_ops
164174
~remote_ops =
165175
let op_supported_on_source_sr vdi ops =
166-
let open Smint.Feature in
167-
(* Check VDIs must not be present on SR which doesn't have required capability *)
176+
(* Check VDIs must not be present on SR which doesn't have required
177+
capability *)
168178
let source_sr = Db.VDI.get_SR ~__context ~self:vdi in
169179
let sr_record = Db.SR.get_record_internal ~__context ~self:source_sr in
170180
let sr_features = Xapi_sr_operations.features_of_sr ~__context sr_record in
171-
if not (List.for_all (fun op -> has_capability op sr_features) ops) then
172-
raise
173-
(Api_errors.Server_error
174-
(Api_errors.sr_does_not_support_migration, [Ref.string_of source_sr])
175-
)
181+
supported_on ~ops source_sr sr_features
176182
in
177183
let op_supported_on_dest_sr sr ops sm_record remote =
178184
let open Smint.Feature in
@@ -187,11 +193,7 @@ let assert_sr_support_operations ~__context ~vdi_map ~remote ~local_ops
187193
| _ ->
188194
[]
189195
in
190-
if not (List.for_all (fun op -> has_capability op sm_features) ops) then
191-
raise
192-
(Api_errors.Server_error
193-
(Api_errors.sr_does_not_support_migration, [Ref.string_of sr])
194-
)
196+
supported_on ~ops sr sm_features
195197
in
196198
let is_sr_matching local_vdi_ref remote_sr_ref =
197199
let source_sr_ref = Db.VDI.get_SR ~__context ~self:local_vdi_ref in

0 commit comments

Comments
 (0)