diff --git a/ocaml/test/OMakefile b/ocaml/test/OMakefile index 777c996755d..53623d3afa2 100644 --- a/ocaml/test/OMakefile +++ b/ocaml/test/OMakefile @@ -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 diff --git a/ocaml/xapi/OMakefile b/ocaml/xapi/OMakefile index 9e4101b0c2d..46951a3ea4c 100644 --- a/ocaml/xapi/OMakefile +++ b/ocaml/xapi/OMakefile @@ -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 diff --git a/ocaml/xapi/stream_vdi.ml b/ocaml/xapi/stream_vdi.ml index 151110e56ee..f5bd95d7706 100644 --- a/ocaml/xapi/stream_vdi.ml +++ b/ocaml/xapi/stream_vdi.ml @@ -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 @@ -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 *) @@ -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; @@ -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 (); @@ -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); diff --git a/opam b/opam index ecb5a63ace8..cda68ac8169 100644 --- a/opam +++ b/opam @@ -32,6 +32,7 @@ depends: [ "opasswd" {>= "0.9.3"} "xapi-rrdd-plugin" "pci" {>= "0.2.0"} + "sha" ] depexts: [ [["centos"] ["pam-devel"]]