Skip to content

Commit 28670f1

Browse files
committed
vhd_tool_wrapper: Make vhd_of_device generic
Take the expected driver type as a parameter, to allow this helper to be used by qcow code as well. Signed-off-by: Andrii Sultanov <[email protected]>
1 parent de254e2 commit 28670f1

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

ocaml/xapi/vhd_tool_wrapper.ml

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,25 +149,27 @@ let find_backend_device path =
149149
raise Not_found
150150
with _ -> None
151151

152-
(** [vhd_of_device path] returns (Some vhd) where 'vhd' is the vhd leaf backing a particular device [path] or None.
153-
[path] may either be a blktap2 device *or* a blkfront device backed by a blktap2 device. If the latter then
154-
the script must be run in the same domain as blkback. *)
155-
let vhd_of_device path =
152+
(** [backing_file_of_device path] returns (Some backing_file) where 'backing_file'
153+
is the leaf backing a particular device [path] (with a driver of type
154+
[driver] or None. [path] may either be a blktap2 device *or* a blkfront
155+
device backed by a blktap2 device. If the latter then the script must be
156+
run in the same domain as blkback. *)
157+
let backing_file_of_device path ~driver =
156158
let tapdisk_of_path path =
157159
try
158160
match Tapctl.of_device (Tapctl.create ()) path with
159-
| _, _, Some ("vhd", vhd) ->
160-
Some vhd
161+
| _, _, Some (typ, backing_file) when typ = driver ->
162+
Some backing_file
161163
| _, _, _ ->
162164
raise Not_found
163165
with
164166
| Tapctl.Not_blktap -> (
165167
debug "Device %s is not controlled by blktap" path ;
166-
(* Check if it is a VHD behind a NBD deivce *)
168+
(* Check if it is a [driver] behind a NBD device *)
167169
Stream_vdi.(get_nbd_device path |> image_behind_nbd_device) |> function
168-
| Some ("vhd", vhd) ->
169-
debug "%s is a VHD behind NBD device %s" vhd path ;
170-
Some vhd
170+
| Some (typ, backing_file) when typ = driver ->
171+
debug "%s is a %s behind NBD device %s" backing_file driver path ;
172+
Some backing_file
171173
| _ ->
172174
None
173175
)
@@ -182,6 +184,7 @@ let vhd_of_device path =
182184

183185
let send progress_cb ?relative_to (protocol : string) (dest_format : string)
184186
(s : Unix.file_descr) (path : string) (size : Int64.t) (prefix : string) =
187+
let vhd_of_device = backing_file_of_device ~driver:"vhd" in
185188
let s' = Uuidx.(to_string (make ())) in
186189
let source_format, source =
187190
match (Stream_vdi.get_nbd_device path, vhd_of_device path, relative_to) with

0 commit comments

Comments
 (0)