Skip to content

Commit 173e37b

Browse files
committed
fixup! Allow selection of image format during migration
1 parent 4800128 commit 173e37b

File tree

5 files changed

+50
-53
lines changed

5 files changed

+50
-53
lines changed

ocaml/idl/datamodel.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5456,7 +5456,7 @@ module VDI = struct
54565456
; (Ref _sr, "sr", "The destination SR")
54575457
; ( String
54585458
, "dest_img_format"
5459-
, "The image format to use on destination SR"
5459+
, "The image format to use on destination SR: raw, vhd, qcow2"
54605460
)
54615461
; (Map (String, String), "options", "Other parameters")
54625462
]

ocaml/idl/datamodel_vm.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,7 +1718,7 @@ let migrate_send =
17181718
param_type= Map (Ref _vdi, String)
17191719
; param_name= "vdi_format_map"
17201720
; param_doc= "Map of source VDI to it's expected type on destination"
1721-
; param_release= numbered_release "25.24.0-next"
1721+
; param_release= numbered_release "25.33.0-next"
17221722
; param_default= Some (VMap [])
17231723
}
17241724
]
@@ -1792,7 +1792,7 @@ let assert_can_migrate =
17921792
param_type= Map (Ref _vdi, String)
17931793
; param_name= "vdi_format_map"
17941794
; param_doc= "Map of source VDI to it's expected type on destination"
1795-
; param_release= numbered_release "25.24.0-next"
1795+
; param_release= numbered_release "25.33.0-next"
17961796
; param_default= Some (VMap [])
17971797
}
17981798
]

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4907,7 +4907,6 @@ let vm_migrate printer rpc session_id params =
49074907
let vdi =
49084908
Client.VDI.get_by_uuid ~rpc ~session_id ~uuid:vdi_uuid
49094909
in
4910-
debug "GTNDEBUG: add image format %s,%s" vdi_uuid vdi_fmt ;
49114910
(vdi, vdi_fmt)
49124911
)
49134912
(read_map_params "image-format" params)

ocaml/xapi-storage-script/main.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,6 +1818,8 @@ module DATAImpl (M : META) = struct
18181818
let stat_impl dbg sr vdi vm key = wrap @@ stat dbg sr vdi vm key
18191819

18201820
let mirror dbg sr vdi' image_format vm' remote =
1821+
let _ = image_format in
1822+
(* TODO: really use image format *)
18211823
let vdi = Storage_interface.Vdi.string_of vdi' in
18221824
let domain = Storage_interface.Vm.string_of vm' in
18231825
Attached_SRs.find sr >>>= fun sr ->

ocaml/xapi/xapi_vm_migrate.ml

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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

794795
type 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

Comments
 (0)