Skip to content

Commit 87a2aec

Browse files
committed
qcow_tool_wrapper: Implement parse_header to determine allocated clusters
Translates JSON from qcow-stream-tool to OCaml types. This is currently unused, but will be used in stream_vdi and vhd_tool_wrapper in the future. Signed-off-by: Andrii Sultanov <[email protected]>
1 parent 2d55b95 commit 87a2aec

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

ocaml/xapi/qcow_tool_wrapper.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ let read_header qcow_path =
6262
(fun () -> Unix.close pipe_writer) ;
6363
pipe_reader
6464

65+
let parse_header qcow_path =
66+
let pipe_reader = read_header qcow_path in
67+
let ic = Unix.in_channel_of_descr pipe_reader in
68+
let buf = Buffer.create 4096 in
69+
let json = Yojson.Basic.from_channel ~buf ~fname:"qcow_header.json" ic in
70+
In_channel.close ic ;
71+
let cluster_size =
72+
1 lsl Yojson.Basic.Util.(member "cluster_bits" json |> to_int)
73+
in
74+
let cluster_list =
75+
Yojson.Basic.Util.(member "data_clusters" json |> to_list |> List.map to_int)
76+
in
77+
(cluster_size, cluster_list)
78+
6579
let send ?relative_to (progress_cb : int -> unit) (unix_fd : Unix.file_descr)
6680
(path : string) (_size : Int64.t) =
6781
let qcow_of_device =

ocaml/xapi/qcow_tool_wrapper.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ val send :
2323
-> string
2424
-> int64
2525
-> unit
26+
27+
val parse_header : string -> int * int list

0 commit comments

Comments
 (0)