@@ -216,6 +216,23 @@ let assert_sr_support_operations ~__context ~vdi_map ~remote ~local_ops
216216 op_supported_on_dest_sr sr remote_ops sm_record remote
217217 )
218218
219+ (* * [check_supported_image_format] checks that the [image_format] string
220+ corresponds to valid image format type listed in [sm_formats].
221+ If [sm_formats] is an empty list or [image_format] is an empty string
222+ there function does nothing. Otherwise, if [image_format] is not found
223+ in [sm_formats], an exception is raised. *)
224+ let check_supported_image_format ~image_format ~sm_formats ~sr_uuid =
225+ if image_format = " " || sm_formats = [] then
226+ ()
227+ else
228+ let ty = Record_util. image_format_type_of_string image_format in
229+ if not (List. mem ty sm_formats) then
230+ let msg =
231+ Printf. sprintf " Image format %s is not supported by %s" image_format
232+ sr_uuid
233+ in
234+ raise Api_errors. (Server_error (vdi_incompatible_type, [msg]))
235+
219236(* * [assert_vdi_format_is_supported] checks that all VDIs in [vdi_map] are included in the list of
220237 supported image format of their corresponding SM. The type of the VDI is found in [vdi_format_map].
221238 - If no VDI type is specified we just returned so no error is raised.
@@ -229,9 +246,9 @@ let assert_vdi_format_is_supported ~__context ~vdi_map ~vdi_format_map =
229246 let sr_uuid = Db.SR. get_uuid ~__context ~self: sr_ref in
230247 match List. assoc_opt vdi_ref vdi_format_map with
231248 | None ->
232- debug " GTNDEBUG: read vdi %s, sr %s. No type specified for the VDI"
233- vdi_uuid sr_uuid
234- | Some ty -> (
249+ debug " read vdi %s, sr %s. No type specified for the VDI" vdi_uuid
250+ sr_uuid
251+ | Some image_format -> (
235252 (* To get the supported image format from SM we need the SR type because both have
236253 the same type. *)
237254 let sr_type = Db.SR. get_type ~__context ~self: sr_ref in
@@ -242,36 +259,20 @@ let assert_vdi_format_is_supported ~__context ~vdi_map ~vdi_format_map =
242259 (* We expect that one sr_type matches one sm_ref *)
243260 match sm_refs with
244261 | [sm_ref] ->
245- debug " GTNDEBUG: read vdi %s, sr %s. Type is %s" vdi_uuid sr_uuid
246- ty ;
262+ debug " read vdi %s, sr %s. Type is %s" vdi_uuid sr_uuid
263+ image_format ;
247264 let sm_formats =
248265 Db.SM. get_supported_image_formats ~__context ~self: sm_ref
249266 in
250- if ty <> " " && sm_formats <> [] && not (List. mem ty sm_formats)
251- then
252- raise
253- Api_errors. (
254- Server_error
255- ( vdi_incompatible_type
256- , [
257- Printf. sprintf
258- " Image format %s is not supported by %s" ty sr_uuid
259- ]
260- )
261- )
267+ check_supported_image_format ~image_format ~sm_formats ~sr_uuid
262268 | _ ->
263- raise
264- Api_errors. (
265- Server_error
266- ( vdi_incompatible_type
267- , [
268- Printf. sprintf
269- " Found more than one SM ref (%d) when checking type \
270- (%s) of VDI."
271- (List. length sm_refs) ty
272- ]
273- )
274- )
269+ let msg =
270+ Printf. sprintf
271+ " Found more than one SM ref (%d) when checking type (%s) of \
272+ VDI."
273+ (List. length sm_refs) image_format
274+ in
275+ raise Api_errors. (Server_error (vdi_incompatible_type, [msg]))
275276 )
276277 )
277278 vdi_map
@@ -792,27 +793,22 @@ let update_snapshot_info ~__context ~dbg ~url ~vdi_map ~snapshots_map
792793 debug " Remote SMAPI doesn't implement update_snapshot_info_src - ignoring"
793794
794795type vdi_mirror = {
795- vdi : [`VDI ] API.Ref .t
796- ; (* The API reference of the local VDI *)
797- format : string
798- ; (* The image format of the VDI the must be used during its creation *)
799- dp : string
800- ; (* The datapath the VDI will be using if the VM is running *)
801- location : Storage_interface.Vdi .t
802- ; (* The location of the VDI in the current SR *)
803- sr : Storage_interface.Sr .t
804- ; (* The VDI's current SR uuid *)
805- xenops_locator : string
806- ; (* The 'locator' xenops uses to refer to the VDI on the current host *)
807- size : Int64 .t
808- ; (* Size of the VDI *)
809- snapshot_of : [`VDI ] API.Ref .t
810- ; (* API's snapshot_of reference *)
811- do_mirror : bool (* Whether we should mirror or just copy the VDI *)
796+ vdi : [`VDI ] API.Ref .t (* * The API reference of the local VDI *)
797+ ; format : string
798+ (* * The image format of the VDI that must be used during its creation *)
799+ ; dp : string (* * The datapath the VDI will be using if the VM is running *)
800+ ; location : Storage_interface.Vdi .t
801+ (* * The location of the VDI in the current SR *)
802+ ; sr : Storage_interface.Sr .t (* * The VDI's current SR uuid *)
803+ ; xenops_locator : string
804+ (* * The 'locator' xenops uses to refer to the VDI on the current host *)
805+ ; size : Int64 .t (* * Size of the VDI *)
806+ ; snapshot_of : [`VDI ] API.Ref .t (* * API's snapshot_of reference *)
807+ ; do_mirror : bool (* * Whether we should mirror or just copy the VDI *)
812808 ; mirror_vm : Vm .t
813- (* The domain slice to which SMAPI calls should be made when mirroring this vdi *)
809+ (* * The domain slice to which SMAPI calls should be made when mirroring this vdi *)
814810 ; copy_vm : Vm .t
815- (* The domain slice to which SMAPI calls should be made when copying this vdi *)
811+ (* * The domain slice to which SMAPI calls should be made when copying this vdi *)
816812}
817813
818814(* For VMs (not snapshots) xenopsd does not allow remapping, so we
@@ -1468,7 +1464,7 @@ let migrate_send' ~__context ~vm ~dest ~live:_ ~vdi_map ~vdi_format_map ~vif_map
14681464 let all_vdis =
14691465 List. map
14701466 (fun vm ->
1471- match get_vdi_type vm.vdi vdi_format_map with
1467+ match get_vdi_type ~vdi_ref: vm.vdi ~ vdi_format_map with
14721468 | None ->
14731469 vm
14741470 | Some vdi_ty ->
0 commit comments