@@ -122,9 +122,10 @@ let get_nbd_device path =
122122 let nbd_device_prefix = " /dev/nbd" in
123123 if Astring.String. is_prefix ~affix: nbd_device_prefix path && is_nbd_device path then begin
124124 let nbd_number =
125- String. sub path (String. length nbd_device_prefix) ( String. length path - String. length nbd_device_prefix)
125+ Astring. String.with_range ~first: (String. length nbd_device_prefix) path
126126 in
127127 let { path; exportname } =
128+ (* persistent_nbd_info_dir is written from nbd_client_manager.py as part of VBD plug*)
128129 let persistent_nbd_info_dir = " /var/run/nonpersistent/nbd" in
129130 let filename = persistent_nbd_info_dir ^ " /" ^ nbd_number in
130131 Xapi_stdext_unix.Unixext. string_of_file filename
@@ -171,23 +172,23 @@ let get_chunk_numbers_in_increasing_order descriptor_list offset =
171172 | false ->
172173 let start_chunk = Int64. div offset increment in
173174 (* If the chunk ends at the boundary don't include the next chunk *)
174- let end_chunk = let open Int64 in div (add (add descriptor.length offset) minus_one) increment in
175+ let end_chunk = Int64. ( div (add (add descriptor.length offset) minus_one) increment) in
175176 let chunks = range [] start_chunk end_chunk in
176177 chunks, descriptor.length
177178 | true -> [] , descriptor.length
178179 in
179180
180181 (* Only compare to most recent chunk added *)
181- let add_new a b =
182- match b with
183- | hd :: _ when Int64. equal a hd -> b
184- | _ -> a::b
182+ let add_new acc b =
183+ match acc with
184+ | hd :: _ when Int64. equal b hd -> acc
185+ | _ -> b::acc
185186 in
186187
187188 (* Output decreasing chunk numbers, x should be increasing and acc should be decreasing *)
188189 let rec add_unique_chunks acc = function
189190 | [] -> acc
190- | x ::xs -> add_unique_chunks (add_new x acc) xs
191+ | x ::xs -> add_unique_chunks (add_new acc x ) xs
191192 in
192193
193194 (* This works in reverse order *)
@@ -209,9 +210,6 @@ let send_all refresh_session ofd ~__context rpc session_id (prefix_vdis: vdi lis
209210
210211 let progress = new_progress_record __context prefix_vdis in
211212
212- (* Remember when we last wrote something so that we can work around firewalls which close 'idle' connections *)
213- let last_transmission_time = ref 0. in
214-
215213 let send_one ofd (__context :Context.t ) (prefix , vdi_ref , size ) =
216214 let size = Db.VDI. get_virtual_size ~__context ~self: vdi_ref in
217215 let reusable_buffer = Bytes. make (Int64. to_int chunk_size) '\000' in
@@ -220,6 +218,8 @@ let send_all refresh_session ofd ~__context rpc session_id (prefix_vdis: vdi lis
220218 (fun ifd dom0_path ->
221219 (match get_nbd_device dom0_path with
222220 | None ->
221+ (* Remember when we last wrote something so that we can work around firewalls which close 'idle' connections *)
222+ let last_transmission_time = ref 0. in
223223 (* NB. It used to be that chunks could be larger than a native int *)
224224 (* could handle, but this is no longer the case! Ensure all chunks *)
225225 (* are strictly less than 2^30 bytes *)
@@ -262,6 +262,7 @@ let send_all refresh_session ofd ~__context rpc session_id (prefix_vdis: vdi lis
262262 in
263263 stream_from 0 0L
264264 | Some (path , exportname ) ->
265+ let last_transmission_time = ref 0L in
265266 let actually_write_chunk (this_chunk_no : int ) (this_chunk_size : int ) =
266267 let buffer = if this_chunk_size = Int64. to_int chunk_size
267268 then reusable_buffer
@@ -270,7 +271,7 @@ let send_all refresh_session ofd ~__context rpc session_id (prefix_vdis: vdi lis
270271 let filename = Printf. sprintf " %s/%08d" prefix this_chunk_no in
271272 Unix.LargeFile. lseek ifd (Int64. mul (Int64. of_int this_chunk_no) chunk_size) Unix. SEEK_SET |> ignore;
272273 Unixext. really_read ifd buffer 0 this_chunk_size;
273- last_transmission_time := Unix. gettimeofday () ;
274+ last_transmission_time := Mtime_clock. now_ns () ;
274275 write_block ~__context filename buffer ofd this_chunk_size;
275276 made_progress __context progress (Int64. of_int this_chunk_size);
276277 in
@@ -279,23 +280,21 @@ let send_all refresh_session ofd ~__context rpc session_id (prefix_vdis: vdi lis
279280 if remaining > 0L then begin
280281 let this_chunk_size = min (Int64. to_int chunk_size) (Int64. to_int remaining) in
281282 let this_chunk_no = Int64. div offset chunk_size in
282- let now = Unix. gettimeofday () in
283- let time_since_transmission = now -. ! last_transmission_time in
284- if offset = 0L || remaining < = chunk_size || time_since_transmission > 5. then begin
283+ let now = Mtime_clock. now_ns () in
284+ let time_since_transmission = Int64. sub now ! last_transmission_time in
285+ if offset = 0L || remaining < = chunk_size || time_since_transmission > 5000000000L then begin
285286 actually_write_chunk (Int64. to_int this_chunk_no) this_chunk_size;
286287 stream_from_offset (Int64. add offset (Int64. of_int this_chunk_size))
287288 end else begin
288289 let remaining = Int64. mul (Int64. div (Int64. sub remaining 1L ) chunk_size) chunk_size in
289290 (* Get sparseness for next 10GB or until the end rounded by last chunk, whichever is smaller *)
290291 let sparseness_size = min max_sparseness_size remaining in
291- let output, _ = Forkhelpers. execute_command_get_output " /opt/xensource/libexec/get_nbd_extents.py " [" --path" ; path; " --exportname" ; exportname; " --offset" ; Int64. to_string offset; " --length" ; Int64. to_string sparseness_size] in
292+ let output, _ = Forkhelpers. execute_command_get_output Xapi_globs. get_nbd_extents [" --path" ; path; " --exportname" ; exportname; " --offset" ; Int64. to_string offset; " --length" ; Int64. to_string sparseness_size] in
292293 let extents = extent_list_of_rpc (Jsonrpc. of_string output) in
293294 let chunks = get_chunk_numbers_in_increasing_order extents offset in
294295 List. iter (
295296 fun chunk ->
296- begin
297297 actually_write_chunk (Int64. to_int chunk) (Int64. to_int chunk_size);
298- end
299298 ) chunks;
300299 stream_from_offset (Int64. add offset sparseness_size)
301300 end
0 commit comments