Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ocaml/test/OMakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OCAMLPACKS = oUnit sexpr xcp xmlm stunnel xml-light2 http-svr uuid \
netdev tapctl xenctrl xenctrlext xenstore-compat \
pciutil oclock gzip sha1 xcp.network xcp.rrd xcp.storage \
pciutil oclock gzip sha1 sha.sha1 xcp.network xcp.rrd xcp.storage \
xcp.xen xcp.memory tar tar.unix oPasswd xcp-inventory \
rrdd-plugin pci xapi-test-utils

Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi/OMakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
OCAMLPACKS = oclock xml-light2 cdrom pciutil sexpr xcp stunnel \
http-svr netdev tapctl rpclib xenstore-compat \
uuid gzip sha1 xcp.network xcp.rrd xcp.storage \
uuid gzip sha1 sha.sha1 xcp.network xcp.rrd xcp.storage \
xcp.xen xcp.memory tar tar.unix oPasswd xcp-inventory \
rrdd-plugin pci

Expand Down
27 changes: 17 additions & 10 deletions ocaml/xapi/stream_vdi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,8 @@ let write_block ~__context filename buffer ofd len =
let hdr = Tar_unix.Header.make filename (Int64.of_int len) in

try
let csum = Sha1sum.sha1sum
(fun checksumfd ->
Tar_unix.write_block hdr (fun ofd -> Tar_unix.Archive.multicast_n_string buffer
[ ofd; checksumfd ] len) ofd
) in
let csum = Sha1.to_hex (Sha1.string buffer) in
Tar_unix.write_block hdr (fun ofd -> Tar_unix.Archive.multicast_n_string buffer [ ofd ] len ) ofd;
(* Write the checksum as a separate file *)
let hdr' = Tar_unix.Header.make (filename ^ checksum_extension) (Int64.of_int (String.length csum)) in
Tar_unix.write_block hdr' (fun ofd -> ignore(Unix.write ofd csum 0 (String.length csum))) ofd
Expand Down Expand Up @@ -126,6 +123,7 @@ let send_all refresh_session ofd ~__context rpc session_id (prefix_vdis: vdi lis
with_open_vdi __context rpc session_id vdi_ref `RO [Unix.O_RDONLY] 0o644
(fun ifd ->

let reusable_buffer = String.make (Int64.to_int chunk_size) '\000' in

(* NB. It used to be that chunks could be larger than a native int *)
(* could handle, but this is no longer the case! Ensure all chunks *)
Expand Down Expand Up @@ -153,7 +151,10 @@ let send_all refresh_session ofd ~__context rpc session_id (prefix_vdis: vdi lis
(* no progress has been made *)
stream_from (chunk_no + 1) offset
end else begin
let buffer = String.make this_chunk '\000' in
let buffer = if (Int64.of_int this_chunk) = chunk_size
then reusable_buffer
else String.make this_chunk '\000'
in
Unixext.really_read ifd buffer 0 this_chunk;
if not (Zerocheck.is_all_zeros buffer this_chunk) || first_or_last then begin
last_transmission_time := now;
Expand Down Expand Up @@ -214,6 +215,8 @@ let recv_all refresh_session ifd (__context:Context.t) rpc session_id vsn force

with_open_vdi __context rpc session_id vdi_ref `RW [Unix.O_WRONLY] 0o644
(fun ofd ->
let reusable_buffer = String.make (Int64.to_int chunk_size) '\000' in

let rec stream_from (last_suffix: string) (offset: int64) =
refresh_session ();

Expand Down Expand Up @@ -261,10 +264,14 @@ let recv_all refresh_session ifd (__context:Context.t) rpc session_id vsn force
done
end;

let csum = Sha1sum.sha1sum
(fun checksumfd ->
Tar_unix.Archive.multicast_n ifd [ ofd; checksumfd ] length) in

let buffer = if length = chunk_size
then reusable_buffer
else String.make (Int64.to_int length) '\000'
in
Unixext.really_read ifd buffer 0 (Int64.to_int length);
Tar_unix.Archive.multicast_n_string buffer [ ofd ] (Int64.to_int length);
let csum = Sha1.to_hex (Sha1.string buffer) in

checksum_table := (file_name, csum) :: !checksum_table;

Tar_unix.Archive.skip ifd (Tar_unix.Header.compute_zero_padding_length hdr);
Expand Down
1 change: 1 addition & 0 deletions opam
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ depends: [
"opasswd" {>= "0.9.3"}
"xapi-rrdd-plugin"
"pci" {>= "0.2.0"}
"sha"
]
depexts: [
[["centos"] ["pam-devel"]]
Expand Down