Skip to content

Commit 6e61256

Browse files
committed
Merge pull request #138 from simonjbeaumont/ca-177298
CA-177298: local allocator: Add retry around DM operation
2 parents 14ceda4 + 0410b8e commit 6e61256

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

idl/log.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type traced_operation_list = traced_operation list with sexp
88

99
let debug fmt = Printf.ksprintf (fun s -> print_endline s) fmt
1010
let info fmt = Printf.ksprintf (fun s -> print_endline s) fmt
11+
let warn fmt = Printf.ksprintf (fun s -> print_endline s) fmt
1112
let error fmt = Printf.ksprintf (fun s -> print_endline s) fmt
1213

1314
let trace ts =

xenvm-local-allocator/local_allocator.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ let dm = ref (module Devmapper.Linux : Devmapper.S.DEVMAPPER)
2323

2424
let 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+
2640
let 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

Comments
 (0)