@@ -23,6 +23,20 @@ let dm = ref (module Devmapper.Linux : Devmapper.S.DEVMAPPER)
2323
2424let journal_size = Int64. (mul 4L (mul 1024L 1024L ))
2525
26+ let retry ~dbg ~retries ~interval f =
27+ debug " Attempting to '%s': will try at most %d times with a %ds interval."
28+ dbg retries interval;
29+ let rec aux n =
30+ if n < = 0 then f ()
31+ else
32+ try f ()
33+ with exn ->
34+ warn " warning: '%s' failed with '%s'; will retry %d more time%s..."
35+ dbg (Printexc. to_string exn ) retries (if retries = 1 then " " else " s" );
36+ Unix. sleep interval;
37+ aux (retries - 1 ) in
38+ aux retries
39+
2640let rec try_forever msg f =
2741 f ()
2842 >> = function
@@ -357,13 +371,14 @@ let main use_mock config daemon socket journal fromLVM toLVM =
357371 >> = fun to_device_targets ->
358372 (* Append the physical blocks to toLV *)
359373 let to_targets = to_device_targets @ t.device.ExpandDevice. targets in
360- D. suspend t.device.ExpandDevice. device;
361- print_endline " Suspend local dm device" ;
362- D. reload t.device.ExpandDevice. device to_targets;
374+ retry ~dbg: " Suspend local dm device" ~retries: 3 ~interval: 1 (fun () ->
375+ D. suspend t.device.ExpandDevice. device);
376+ retry ~dbg: " Reload local dm device" ~retries: 3 ~interval: 1 (fun () ->
377+ D. reload t.device.ExpandDevice. device to_targets);
363378 ToLVM. advance tolvm position
364379 >> = fun () ->
365- D. resume t. device. ExpandDevice. device;
366- print_endline " Resume local dm device" ;
380+ retry ~dbg: " Resume local dm device" ~retries: 3 ~interval: 1 ( fun () ->
381+ D. resume t. device. ExpandDevice. device) ;
367382 return ()
368383 ) ops
369384 >> = fun () ->
0 commit comments