Skip to content

Commit a0f895e

Browse files
authored
Merge 26.1-lcm into feature/26.1-lcm/trusted-certs (#7027)
2 parents e6e6dd5 + 18019bc commit a0f895e

18 files changed

Lines changed: 466 additions & 180 deletions

dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@
506506
cohttp
507507
cohttp-lwt
508508
conf-libssl
509+
(conf-qemu-img :with-test)
509510
(cstruct
510511
(>= "3.0.0"))
511512
(ezxenstore

ocaml/libs/vhd/vhd_format/f.ml

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,24 +2903,10 @@ functor
29032903

29042904
let raw ?from (vhd : fd Vhd.t) = raw_common ?from vhd
29052905

2906-
let vhd_blocks_to_json (t : fd Vhd.t) =
2906+
let vhd_blocks_to_json_aux (t : fd Vhd.t) blocks =
29072907
let block_size_sectors_shift =
29082908
t.Vhd.header.Header.block_size_sectors_shift
29092909
in
2910-
let max_table_entries = Vhd.used_max_table_entries t in
2911-
2912-
let include_block = include_block None t in
2913-
2914-
let blocks =
2915-
Seq.init max_table_entries Fun.id
2916-
|> Seq.filter_map (fun i ->
2917-
if include_block i then
2918-
Some (`Int i)
2919-
else
2920-
None
2921-
)
2922-
|> List.of_seq
2923-
in
29242910
let json =
29252911
`Assoc
29262912
[
@@ -2934,6 +2920,52 @@ functor
29342920
let json_string = Yojson.to_string json in
29352921
print_string json_string ; return ()
29362922

2923+
let vhd_blocks_to_json (t : fd Vhd.t) =
2924+
let max_table_entries = Vhd.used_max_table_entries t in
2925+
let blocks =
2926+
Seq.init max_table_entries Fun.id
2927+
|> Seq.filter_map (fun i ->
2928+
if include_block None t i then
2929+
Some (`Int i)
2930+
else
2931+
None
2932+
)
2933+
|> List.of_seq
2934+
in
2935+
vhd_blocks_to_json_aux t blocks
2936+
2937+
let vhd_blocks_to_json_interval (t : fd Vhd.t) =
2938+
let max_table_entries = Vhd.used_max_table_entries t in
2939+
let blocks, last_block =
2940+
Seq.init max_table_entries Fun.id
2941+
|> Seq.fold_left
2942+
(fun (acc, left_block) i ->
2943+
if include_block None t i then
2944+
match left_block with
2945+
| Some _ ->
2946+
(acc, left_block)
2947+
| None ->
2948+
(acc, Some i)
2949+
else
2950+
match left_block with
2951+
| Some x ->
2952+
(`List [`Int x; `Int (i - 1)] :: acc, None)
2953+
| None ->
2954+
(acc, None)
2955+
)
2956+
([], None)
2957+
in
2958+
(* Close off the interval we were tracking we ran off the end of the seq *)
2959+
let blocks =
2960+
match last_block with
2961+
| Some x ->
2962+
`List [`Int x; `Int (max_table_entries - 1)] :: blocks
2963+
| None ->
2964+
blocks
2965+
in
2966+
let blocks = List.rev blocks in
2967+
vhd_blocks_to_json_aux t blocks
2968+
29372969
let vhd_common ?from ?raw ?(emit_batmap = false) (t : fd Vhd.t) =
29382970
let block_size_sectors_shift =
29392971
t.Vhd.header.Header.block_size_sectors_shift
@@ -3173,6 +3205,8 @@ functor
31733205
Vhd_input.vhd_common ?from ~raw vhd
31743206

31753207
let blocks_json = Vhd_input.vhd_blocks_to_json
3208+
3209+
let blocks_json_interval = Vhd_input.vhd_blocks_to_json_interval
31763210
end
31773211

31783212
(* Create a VHD stream from data on t, using `include_block` guide us which blocks have data *)

ocaml/libs/vhd/vhd_format/f.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ module From_file : functor (F : S.FILE) -> sig
470470
[from] into [t] *)
471471

472472
val blocks_json : fd Vhd.t -> unit t
473+
474+
val blocks_json_interval : fd Vhd.t -> unit t
473475
end
474476

475477
module Raw_input : sig

ocaml/qcow-stream-tool/qcow_stream_tool.ml

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,13 @@ module Impl = struct
44
let stream_decode output =
55
Qcow_stream.stream_decode Unix.stdin output ;
66
`Ok ()
7-
8-
let read_headers qcow_path =
9-
let open Lwt.Syntax in
10-
let t =
11-
let* fd = Lwt_unix.openfile qcow_path [Unix.O_RDONLY] 0 in
12-
let* virtual_size, cluster_bits, _, data_cluster_map =
13-
Qcow_stream.start_stream_decode fd
14-
in
15-
(* TODO: List.map becomes tail-recursive in OCaml 5.1, and could be used here instead *)
16-
let clusters =
17-
data_cluster_map
18-
|> Qcow_types.Cluster.Map.to_seq
19-
|> Seq.map (fun (_, virt_address) ->
20-
let ( >> ) = Int64.shift_right_logical in
21-
let address =
22-
Int64.to_int (virt_address >> Int32.to_int cluster_bits)
23-
in
24-
`Int address
25-
)
26-
|> List.of_seq
27-
in
28-
let json =
29-
`Assoc
30-
[
31-
("virtual_size", `Int (Int64.to_int virtual_size))
32-
; ("cluster_bits", `Int (Int32.to_int cluster_bits))
33-
; ("data_clusters", `List clusters)
34-
]
35-
in
36-
let json_string = Yojson.to_string json in
37-
let* () = Lwt_io.print json_string in
38-
let* () = Lwt_io.flush Lwt_io.stdout in
39-
Lwt.return_unit
40-
in
41-
Lwt_main.run t ; `Ok ()
427
end
438

449
module Cli = struct
4510
let output default =
4611
let doc = Printf.sprintf "Path to the output file." in
4712
Arg.(value & pos 0 string default & info [] ~doc)
4813

49-
let input =
50-
let doc = Printf.sprintf "Path to the input file." in
51-
Arg.(required & pos 0 (some string) None & info [] ~doc)
52-
5314
let stream_decode_cmd =
5415
let doc = "decode qcow2 formatted data from stdin and write a raw image" in
5516
let man =
@@ -62,18 +23,7 @@ module Cli = struct
6223
(Cmd.info "stream_decode" ~doc ~man)
6324
Term.(ret (const Impl.stream_decode $ output "test.raw"))
6425

65-
let read_headers_cmd =
66-
let doc =
67-
"Determine allocated clusters by parsing qcow2 file at the provided \
68-
path. Returns JSON like the following: {'virtual_size': X, \
69-
'cluster_bits': Y, 'data_clusters': [1,2,3]}"
70-
in
71-
let man = [`S "DESCRIPTION"; `P doc] in
72-
Cmd.v
73-
(Cmd.info "read_headers" ~doc ~man)
74-
Term.(ret (const Impl.read_headers $ input))
75-
76-
let cmds = [stream_decode_cmd; read_headers_cmd]
26+
let cmds = [stream_decode_cmd]
7727
end
7828

7929
let info =

ocaml/vhd-tool/cli/main.ml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,19 +385,34 @@ let stream_cmd =
385385
, Cmd.info "stream" ~sdocs:_common_options ~doc ~man
386386
)
387387

388+
let vhd_source =
389+
let doc = Printf.sprintf "Path to the VHD file" in
390+
Arg.(required & pos 0 (some file) None & info [] ~doc)
391+
388392
let read_headers_cmd =
389393
let doc =
390394
{|Parse VHD headers and output allocated blocks information in JSON format \
391395
like: {"virtual_size": X, "cluster_bits": X, "data_clusters": [1,2,3]}|}
392396
in
393-
let source =
394-
let doc = Printf.sprintf "Path to the VHD file" in
395-
Arg.(required & pos 0 (some file) None & info [] ~doc)
396-
in
397-
( Term.(ret (const Impl.read_headers $ common_options_t $ source))
397+
( Term.(
398+
ret
399+
(const (Impl.read_headers ~legacy:true) $ common_options_t $ vhd_source)
400+
)
398401
, Cmd.info "read_headers" ~sdocs:_common_options ~doc
399402
)
400403

404+
let read_headers_interval_cmd =
405+
let doc =
406+
{|Parse VHD headers and output allocated blocks intervals information in JSON format \
407+
like: {"virtual_size": X, "cluster_bits": X, "data_clusters": [[1,13],[17,17],[19,272]]|}
408+
in
409+
( Term.(
410+
ret
411+
(const (Impl.read_headers ~legacy:false) $ common_options_t $ vhd_source)
412+
)
413+
, Cmd.info "read_headers_interval" ~sdocs:_common_options ~doc
414+
)
415+
401416
let cmds =
402417
[
403418
info_cmd
@@ -408,6 +423,7 @@ let cmds =
408423
; serve_cmd
409424
; stream_cmd
410425
; read_headers_cmd
426+
; read_headers_interval_cmd
411427
]
412428
|> List.map (fun (t, i) -> Cmd.v i t)
413429

ocaml/vhd-tool/src/impl.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,11 +1168,15 @@ let stream_t common args ?(progress = no_progress_bar) () =
11681168
args.StreamCommon.tar_filename_prefix args.StreamCommon.good_ciphersuites
11691169
args.StreamCommon.verify_cert
11701170

1171-
let read_headers common source =
1171+
let read_headers common source ~legacy =
11721172
let path = [Filename.dirname source] in
11731173
let thread =
11741174
retry common 3 (fun () -> Vhd_IO.openchain ~path source false) >>= fun t ->
1175-
Vhd_IO.close t >>= fun () -> Hybrid_input.blocks_json t
1175+
Vhd_IO.close t >>= fun () ->
1176+
if legacy then
1177+
Hybrid_input.blocks_json t
1178+
else
1179+
Hybrid_input.blocks_json_interval t
11761180
in
11771181
Lwt_main.run thread ; `Ok ()
11781182

ocaml/vhd-tool/src/impl.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ val stream :
3636
Common.t -> StreamCommon.t -> [> `Error of bool * string | `Ok of unit]
3737

3838
val read_headers :
39-
Common.t -> string -> [> `Error of bool * string | `Ok of unit]
39+
Common.t -> string -> legacy:bool -> [> `Error of bool * string | `Ok of unit]
4040

4141
val serve :
4242
Common.t

ocaml/xapi/message_forwarding.ml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ let iter_with_drop ?(doc = "performing unknown operation") f xs =
199199
let log_exn ?(doc = "performing unknown operation") f x =
200200
try f x
201201
with e ->
202+
Backtrace.is_important e ;
202203
debug "Caught exception while %s in message forwarder: %s" doc
203204
(ExnHelper.string_of_exn e) ;
204205
raise e
@@ -323,9 +324,10 @@ functor
323324
let tolerate_connection_loss fn success timeout =
324325
try fn ()
325326
with
326-
| Api_errors.Server_error (ercode, params)
327+
| Api_errors.Server_error (ercode, _) as e
327328
when ercode = Api_errors.cannot_contact_host
328329
->
330+
Backtrace.is_important e ;
329331
debug
330332
"Lost connection with slave during call (expected). Waiting for \
331333
slave to come up again." ;
@@ -337,8 +339,7 @@ functor
337339
let rec poll i =
338340
match i with
339341
| 0 ->
340-
raise (Api_errors.Server_error (ercode, params))
341-
(* give up and re-raise exn *)
342+
raise e (* give up and re-raise exn *)
342343
| i -> (
343344
match success () with
344345
| Some result ->
@@ -1367,6 +1368,7 @@ functor
13671368
vbds ;
13681369
vbds
13691370
with e ->
1371+
Backtrace.is_important e ;
13701372
debug "Caught exception marking VBD for %s on VM %s: %s" doc
13711373
(Ref.string_of vm)
13721374
(ExnHelper.string_of_exn e) ;
@@ -1548,6 +1550,7 @@ functor
15481550
(Helpers.will_have_qemu ~__context ~self:vm) ;
15491551
Xapi_network_sriov_helpers.reserve_sriov_vfs ~__context ~host ~vm
15501552
with e ->
1553+
Backtrace.is_important e ;
15511554
clear_vif_reservations ~__context ~vm ;
15521555
clear_reservations ~__context ~vm ;
15531556
raise e
@@ -1692,6 +1695,7 @@ functor
16921695
) ;
16931696
try f ()
16941697
with exn ->
1698+
Backtrace.is_important exn ;
16951699
if !restore_old_values_on_error then (
16961700
Db.VM.set_memory_dynamic_min ~__context ~self:vm
16971701
~value:old_dynamic_min ;
@@ -5271,6 +5275,7 @@ functor
52715275
(fun (vdi, op) -> mark_vdi ~__context ~vdi ~doc ~op)
52725276
vdi
52735277
with e ->
5278+
Backtrace.is_important e ;
52745279
Option.iter
52755280
(fun (sr, op) -> SR.unmark_sr ~__context ~sr ~doc ~op)
52765281
sr ;
@@ -6620,6 +6625,7 @@ functor
66206625
-> (
66216626
match rest with
66226627
| [] ->
6628+
Backtrace.is_important e ;
66236629
debug
66246630
"Ran out of hosts to try (and no cluster host on \
66256631
ourselves), reporting error" ;

0 commit comments

Comments
 (0)