Skip to content

Commit e413177

Browse files
committed
xapi_vdi_helpers: Split backing_file_of_device in two
Qcow_tool_wrapper and Vhd_tool_wrapper expect a particular driver to be backing the VDI and fall back to handling the VDI as raw otherwise - they will be using backing_file_of_device_with_driver. Stream_vdi, however, will need to branch on the type of the driver, and it will use backing_info_of_device (which also returns the type of the driver) Signed-off-by: Andrii Sultanov <[email protected]>
1 parent 66431fb commit e413177

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

ocaml/xapi/qcow_tool_wrapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ let parse_header qcow_path =
7979
let send ?relative_to (progress_cb : int -> unit) (unix_fd : Unix.file_descr)
8080
(path : string) (_size : Int64.t) =
8181
let qcow_of_device =
82-
Xapi_vdi_helpers.backing_file_of_device ~driver:"qcow2"
82+
Xapi_vdi_helpers.backing_file_of_device_with_driver ~driver:"qcow2"
8383
in
8484
let qcow_path = qcow_of_device path in
8585

ocaml/xapi/vhd_tool_wrapper.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ let receive progress_cb format protocol (s : Unix.file_descr)
114114

115115
let send progress_cb ?relative_to (protocol : string) (dest_format : string)
116116
(s : Unix.file_descr) (path : string) (size : Int64.t) (prefix : string) =
117-
let vhd_of_device = Xapi_vdi_helpers.backing_file_of_device ~driver:"vhd" in
117+
let vhd_of_device =
118+
Xapi_vdi_helpers.backing_file_of_device_with_driver ~driver:"vhd"
119+
in
118120
let s' = Uuidx.(to_string (make ())) in
119121
let source_format, source =
120122
match

ocaml/xapi/xapi_vdi_helpers.ml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -394,35 +394,40 @@ let find_backend_device path =
394394
raise Not_found
395395
with _ -> None
396396

397-
(** [backing_file_of_device path] returns (Some backing_file) where 'backing_file'
398-
is the leaf backing a particular device [path] (with a driver of type
399-
[driver] or None. [path] may either be a blktap2 device *or* a blkfront
400-
device backed by a blktap2 device. If the latter then the script must be
401-
run in the same domain as blkback. *)
402-
let backing_file_of_device path ~driver =
397+
(** [backing_info_of_device] returns Some (driver_type, backing_file) for the
398+
leaf backing a particular device [path]. *)
399+
let backing_info_of_device path =
403400
let tapdisk_of_path path =
404401
try
405-
match Tapctl.of_device (Tapctl.create ()) path with
406-
| _, _, Some (typ, backing_file) when typ = driver ->
407-
Some backing_file
408-
| _, _, _ ->
409-
raise Not_found
402+
let _, _, backing_info = Tapctl.of_device (Tapctl.create ()) path in
403+
backing_info
410404
with
405+
| Tapctl.Not_a_device ->
406+
debug "%s is not a device" path ;
407+
None
411408
| Tapctl.Not_blktap -> (
412409
debug "Device %s is not controlled by blktap" path ;
413410
(* Check if it is a [driver] behind a NBD device *)
414411
get_nbd_device path |> image_behind_nbd_device |> function
415-
| Some (typ, backing_file) when typ = driver ->
416-
debug "%s is a %s behind NBD device %s" backing_file driver path ;
417-
Some backing_file
412+
| Some (typ, backing_file) as backing_info ->
413+
debug "%s is a %s behind NBD device %s" backing_file typ path ;
414+
backing_info
418415
| _ ->
419416
None
420417
)
421-
| Tapctl.Not_a_device ->
422-
debug "%s is not a device" path ;
423-
None
424-
| _ ->
425-
debug "Device %s has an unknown driver" path ;
426-
None
427418
in
428419
find_backend_device path |> Option.value ~default:path |> tapdisk_of_path
420+
421+
(** [backing_file_of_device_with_driver path driver] returns Some backing_file
422+
where [backing_file] is the leaf backing a particular device [path]
423+
(with a driver of type [driver]) or None.
424+
[path] may either be a blktap2 device *or* a blkfront device backed by a
425+
blktap2 device. If the latter then the script must be
426+
run in the same domain as blkback. *)
427+
let backing_file_of_device_with_driver path ~driver =
428+
match backing_info_of_device path with
429+
| Some (typ, backing_file) when typ = driver ->
430+
Some backing_file
431+
| _ ->
432+
debug "Device %s has an unknown driver" path ;
433+
None

0 commit comments

Comments
 (0)