Skip to content

Commit 7670247

Browse files
authored
maintenance: add interface files for vhd-tool (#6052)
This detects some unused bindings and a mutable field. Chunked got also documented and changed the interface to make it more understandable to use.
2 parents f7c3e7f + 4284169 commit 7670247

File tree

12 files changed

+211
-48
lines changed

12 files changed

+211
-48
lines changed

ocaml/vhd-tool/cli/dune

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
(names main sparse_dd get_vhd_vsize)
44
(libraries
55
astring
6-
6+
77
local_lib
88
cmdliner
99
cstruct
@@ -19,6 +19,7 @@
1919
xapi-idl
2020
xapi-log
2121
xenstore_transport.unix
22+
ezxenstore
2223
)
2324
)
2425

ocaml/vhd-tool/cli/sparse_dd.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,15 @@ module Progress = struct
175175
let s = Printf.sprintf "Progress: %.0f" (fraction *. 100.) in
176176
let data = Cstruct.create (String.length s) in
177177
Cstruct.blit_from_string s 0 data 0 (String.length s) ;
178-
Chunked.marshal header {Chunked.offset= 0L; data} ;
178+
Chunked.(marshal header (make ~sector:0L data)) ;
179179
Printf.printf "%s%s%!" (Cstruct.to_string header) s
180180
)
181181

182182
(** Emit the end-of-stream message *)
183183
let close () =
184184
if !machine_readable_progress then (
185185
let header = Cstruct.create Chunked.sizeof in
186-
Chunked.marshal header {Chunked.offset= 0L; data= Cstruct.create 0} ;
186+
Chunked.(marshal header end_of_stream) ;
187187
Printf.printf "%s%!" (Cstruct.to_string header)
188188
)
189189
end
@@ -198,7 +198,7 @@ let after f g =
198198
the driver domain corresponding to the frontend device [path] in this domain. *)
199199
let find_backend_device path =
200200
try
201-
let open Xenstore in
201+
let open Ezxenstore_core.Xenstore in
202202
(* If we're looking at a xen frontend device, see if the backend
203203
is in the same domain. If so check if it looks like a .vhd *)
204204
let rdev = (Unix.LargeFile.stat path).Unix.LargeFile.st_rdev in

ocaml/vhd-tool/src/channels.mli

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(* Copyright (C) Cloud Software Group Inc.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU Lesser General Public License as published
4+
by the Free Software Foundation; version 2.1 only. with the special
5+
exception on linking described in file LICENSE.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU Lesser General Public License for more details.
11+
*)
12+
13+
type t = {
14+
really_read: Cstruct.t -> unit Lwt.t
15+
; really_write: Cstruct.t -> unit Lwt.t
16+
; offset: int64 ref
17+
; skip: int64 -> unit Lwt.t
18+
; copy_from: Lwt_unix.file_descr -> int64 -> int64 Lwt.t
19+
; close: unit -> unit Lwt.t
20+
}
21+
22+
exception Impossible_to_seek
23+
24+
val of_raw_fd : Lwt_unix.file_descr -> t Lwt.t
25+
26+
val of_seekable_fd : Lwt_unix.file_descr -> t Lwt.t
27+
28+
type verification_config = {
29+
sni: string option
30+
; verify: Ssl.verify_mode
31+
; cert_bundle_path: string
32+
}
33+
34+
val of_ssl_fd :
35+
Lwt_unix.file_descr -> string option -> verification_config option -> t Lwt.t

ocaml/vhd-tool/src/chunked.ml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ let sizeof = sizeof_t
1818

1919
type t = {
2020
offset: int64 (** offset on the physical disk *)
21-
; data: Cstruct.t (** data to write *)
21+
; len: int32 (** how much data to write *)
2222
}
2323

24-
let marshal (buf : Cstruct.t) t =
25-
set_t_offset buf t.offset ;
26-
set_t_len buf (Int32.of_int (Cstruct.length t.data))
24+
let end_of_stream = {offset= 0L; len= 0l}
2725

28-
let is_last_chunk (buf : Cstruct.t) =
29-
get_t_offset buf = 0L && get_t_len buf = 0l
26+
let make ~sector ?(size = 512L) data =
27+
{offset= Int64.mul sector size; len= Int32.of_int (Cstruct.length data)}
28+
29+
let marshal buf t = set_t_offset buf t.offset ; set_t_len buf t.len
30+
31+
let is_last_chunk buf = get_t_offset buf = 0L && get_t_len buf = 0l
3032

3133
let get_offset = get_t_offset
3234

ocaml/vhd-tool/src/chunked.mli

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(* Copyright (C) Cloud Software Group Inc.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU Lesser General Public License as published
4+
by the Free Software Foundation; version 2.1 only. with the special
5+
exception on linking described in file LICENSE.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU Lesser General Public License for more details.
11+
*)
12+
13+
val sizeof : int
14+
15+
(** [t] is the metadata of a chunk of disk that's meant to be streamed. These
16+
are used in a protocol that interleaves the metadata and the data until an
17+
empty metadata block is sent, which signals the end of the stream. *)
18+
type t
19+
20+
val end_of_stream : t
21+
(** [end_of_stream] is the value that signals the end of the stream of chunks
22+
being transferred. *)
23+
24+
val make : sector:int64 -> ?size:int64 -> Cstruct.t -> t
25+
(** [make ~sector ?size data] creates a chunk of disk that needs to be
26+
transferred, starting at the sector [sector]. [size] is the sector size, in
27+
bytes. The default is 512. *)
28+
29+
val marshal : Cstruct.t -> t -> unit
30+
(** [marshall buffer chunk] writes the metadata of [chunk] to [buffer]. When
31+
transferring a whole disk, this is called a header and is written before
32+
the data. *)
33+
34+
val is_last_chunk : Cstruct.t -> bool
35+
(** [is_last_chunk buffer] returns whether the current [buffer] is
36+
{end_of_stream} *)
37+
38+
val get_offset : Cstruct.t -> int64
39+
40+
val get_len : Cstruct.t -> int32

ocaml/vhd-tool/src/dune

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
cohttp
1313
cohttp-lwt
1414
cstruct
15-
(re_export ezxenstore)
1615
io-page
1716
lwt
1817
lwt.unix
@@ -27,17 +26,13 @@
2726
ssl
2827
tar
2928
uri
29+
uuidm
3030
vhd-format
3131
vhd-format-lwt
3232
tapctl
3333
xapi-stdext-std
3434
xapi-stdext-unix
3535
xen-api-client-lwt
36-
xenstore
37-
xenstore.client
38-
xenstore.unix
39-
xenstore_transport
40-
xenstore_transport.unix
4136
)
4237
(preprocess
4338
(per_module

ocaml/vhd-tool/src/impl.ml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ end)
4242

4343
open F
4444

45-
(*
46-
open Vhd
47-
open Vhd_format_lwt
48-
*)
49-
let vhd_search_path = "/dev/mapper"
50-
5145
let require name arg =
5246
match arg with
5347
| None ->
@@ -304,7 +298,7 @@ let stream_chunked _common c s prezeroed _ ?(progress = no_progress_bar) () =
304298
(fun (sector, work_done) x ->
305299
( match x with
306300
| `Sectors data ->
307-
let t = {Chunked.offset= Int64.(mul sector 512L); data} in
301+
let t = Chunked.make ~sector ~size:512L data in
308302
Chunked.marshal header t ;
309303
c.Channels.really_write header >>= fun () ->
310304
c.Channels.really_write data >>= fun () ->
@@ -332,7 +326,7 @@ let stream_chunked _common c s prezeroed _ ?(progress = no_progress_bar) () =
332326
p total_work ;
333327

334328
(* Send the end-of-stream marker *)
335-
Chunked.marshal header {Chunked.offset= 0L; data= Cstruct.create 0} ;
329+
Chunked.(marshal header end_of_stream) ;
336330
c.Channels.really_write header >>= fun () -> return (Some total_work)
337331

338332
let stream_raw _common c s prezeroed _ ?(progress = no_progress_bar) () =
@@ -398,16 +392,9 @@ module TarStream = struct
398392
; nr_bytes_remaining: int
399393
; (* start at 0 *)
400394
next_counter: int
401-
; mutable header: Tar.Header.t option
395+
; header: Tar.Header.t option
402396
}
403397

404-
let to_string t =
405-
Printf.sprintf
406-
"work_done = %Ld; nr_bytes_remaining = %d; next_counter = %d; filename = \
407-
%s"
408-
t.work_done t.nr_bytes_remaining t.next_counter
409-
(match t.header with None -> "None" | Some h -> h.Tar.Header.file_name)
410-
411398
let initial total_size =
412399
{
413400
work_done= 0L

ocaml/vhd-tool/src/impl.mli

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
(* Copyright (C) Cloud Software Group Inc.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU Lesser General Public License as published
4+
by the Free Software Foundation; version 2.1 only. with the special
5+
exception on linking described in file LICENSE.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU Lesser General Public License for more details.
11+
*)
12+
13+
module F : module type of Vhd_format.F.From_file (Vhd_format_lwt.IO)
14+
15+
val get :
16+
'a
17+
-> string option
18+
-> string option
19+
-> [> `Error of bool * string | `Ok of unit]
20+
21+
val info : 'a -> string option -> [> `Error of bool * string | `Ok of unit]
22+
23+
val contents : 'a -> string option -> [> `Error of bool * string | `Ok of unit]
24+
25+
val create :
26+
Common.t
27+
-> string option
28+
-> string option
29+
-> string option
30+
-> [> `Error of bool * string | `Ok of unit]
31+
32+
val check :
33+
Common.t -> string option -> [> `Error of bool * string | `Ok of unit]
34+
35+
val stream :
36+
Common.t -> StreamCommon.t -> [> `Error of bool * string | `Ok of unit]
37+
38+
val serve :
39+
Common.t
40+
-> string
41+
-> int option
42+
-> string
43+
-> string option
44+
-> string
45+
-> int option
46+
-> string
47+
-> int64 option
48+
-> bool
49+
-> bool
50+
-> bool
51+
-> string option
52+
-> bool
53+
-> [> `Error of bool * string | `Ok of unit]
54+
55+
(** Functions used by sparse_dd *)
56+
57+
val make_stream :
58+
Common.t
59+
-> string
60+
-> string option
61+
-> string
62+
-> string
63+
-> Vhd_format_lwt.IO.fd Nbd_input.F.stream Lwt.t
64+
65+
val write_stream :
66+
Common.t
67+
-> Vhd_format_lwt.IO.fd F.stream
68+
-> string
69+
-> StreamCommon.protocol option
70+
-> bool
71+
-> (int64 -> int64 -> unit)
72+
-> string option
73+
-> string option
74+
-> Channels.verification_config option
75+
-> unit Lwt.t

ocaml/vhd-tool/src/input.mli

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(* Copyright (C) Cloud Software Group Inc.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU Lesser General Public License as published
4+
by the Free Software Foundation; version 2.1 only. with the special
5+
exception on linking described in file LICENSE.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU Lesser General Public License for more details.
11+
*)
12+
13+
type 'a t = 'a Lwt.t
14+
15+
type fd = {fd: Lwt_unix.file_descr; mutable offset: int64}
16+
17+
include Vhd_format.S.INPUT with type 'a t := 'a t with type fd := fd
18+
19+
val of_fd : Lwt_unix.file_descr -> fd

ocaml/vhd-tool/src/nbd_input.mli

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(* Copyright (C) Cloud Software Group Inc.
2+
This program is free software; you can redistribute it and/or modify
3+
it under the terms of the GNU Lesser General Public License as published
4+
by the Free Software Foundation; version 2.1 only. with the special
5+
exception on linking described in file LICENSE.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU Lesser General Public License for more details.
11+
*)
12+
13+
module F : module type of Vhd_format.F.From_file (Vhd_format_lwt.IO)
14+
15+
val raw :
16+
?extent_reader:string -> 'a -> string -> string -> int64 -> 'a F.stream Lwt.t
17+
18+
val vhd :
19+
?extent_reader:string
20+
-> Vhd_format_lwt.IO.fd Vhd_format.F.Raw.t
21+
-> string
22+
-> string
23+
-> int64
24+
-> Vhd_format_lwt.IO.fd F.stream Lwt.t

ocaml/vhd-tool/src/xenstore.ml

Lines changed: 0 additions & 15 deletions
This file was deleted.

quality-gate.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ verify-cert () {
2525
}
2626

2727
mli-files () {
28-
N=505
28+
N=499
2929
# do not count ml files from the tests in ocaml/{tests/perftest/quicktest}
3030
MLIS=$(git ls-files -- '**/*.mli' | grep -vE "ocaml/tests|ocaml/perftest|ocaml/quicktest|ocaml/message-switch/core_test" | xargs -I {} sh -c "echo {} | cut -f 1 -d '.'" \;)
3131
MLS=$(git ls-files -- '**/*.ml' | grep -vE "ocaml/tests|ocaml/perftest|ocaml/quicktest|ocaml/message-switch/core_test" | xargs -I {} sh -c "echo {} | cut -f 1 -d '.'" \;)

0 commit comments

Comments
 (0)