Skip to content

Commit da263f9

Browse files
authored
xapi: Wrap {vhd,qcow}-tool read_header invocation in a thread (#6902)
This allows it to proceed in parallel with the parse side, not deadlocking on the filled pipe. Backport of #6901
2 parents 86e1780 + 7a9f929 commit da263f9

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

ocaml/xapi/qcow_tool_wrapper.ml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ let read_header qcow_path =
2727
let pipe_reader, pipe_writer = Unix.pipe ~cloexec:true () in
2828

2929
let progress_cb _ = () in
30-
Xapi_stdext_pervasives.Pervasiveext.finally
31-
(fun () ->
32-
Vhd_qcow_parsing.run_tool qcow_tool progress_cb args
33-
~output_fd:pipe_writer
34-
)
35-
(fun () -> Unix.close pipe_writer) ;
30+
let (_ : Thread.t) =
31+
Thread.create
32+
(fun () ->
33+
Xapi_stdext_pervasives.Pervasiveext.finally
34+
(fun () ->
35+
Vhd_qcow_parsing.run_tool qcow_tool progress_cb args
36+
~output_fd:pipe_writer
37+
)
38+
(fun () -> Unix.close pipe_writer)
39+
)
40+
()
41+
in
3642
pipe_reader
3743

3844
let parse_header qcow_path =

ocaml/xapi/vhd_tool_wrapper.ml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,18 @@ let read_vhd_header path =
122122
let pipe_reader, pipe_writer = Unix.pipe ~cloexec:true () in
123123

124124
let progress_cb _ = () in
125-
Xapi_stdext_pervasives.Pervasiveext.finally
126-
(fun () ->
127-
Vhd_qcow_parsing.run_tool vhd_tool progress_cb args ~output_fd:pipe_writer
128-
)
129-
(fun () -> Unix.close pipe_writer) ;
125+
let (_ : Thread.t) =
126+
Thread.create
127+
(fun () ->
128+
Xapi_stdext_pervasives.Pervasiveext.finally
129+
(fun () ->
130+
Vhd_qcow_parsing.run_tool vhd_tool progress_cb args
131+
~output_fd:pipe_writer
132+
)
133+
(fun () -> Unix.close pipe_writer)
134+
)
135+
()
136+
in
130137
pipe_reader
131138

132139
let parse_header vhd_path =

0 commit comments

Comments
 (0)