@@ -766,8 +766,7 @@ let rec diff a b = match a with
766
766
| a :: aa ->
767
767
if List. mem b a then diff aa b else a :: (diff aa b)
768
768
769
- let watch_volume_plugins ~root_dir ~switch_path =
770
- let root_dir = Filename. concat root_dir " volume" in
769
+ let watch_volume_plugins ~root_dir ~switch_path ~pipe =
771
770
let create switch_path root_dir name =
772
771
if Hashtbl. mem servers name
773
772
then return ()
@@ -795,11 +794,8 @@ let watch_volume_plugins ~root_dir ~switch_path =
795
794
Deferred. all_ignore (List. map ~f: (create switch_path root_dir) (diff needed got_already))
796
795
>> = fun () ->
797
796
Deferred. all_ignore (List. map ~f: (destroy switch_path) (diff got_already needed)) in
798
- Async_inotify. create ~recursive: false ~watch_new_dirs: false root_dir
799
- >> = fun (watch , _ ) ->
800
797
sync ~root_dir ~switch_path
801
798
>> = fun () ->
802
- let pipe = Async_inotify. pipe watch in
803
799
let open Async_inotify.Event in
804
800
let rec loop () =
805
801
( Pipe. read pipe >> = function
@@ -824,8 +820,7 @@ let watch_volume_plugins ~root_dir ~switch_path =
824
820
loop () in
825
821
loop ()
826
822
827
- let watch_datapath_plugins ~root_dir =
828
- let root_dir = Filename. concat root_dir " datapath" in
823
+ let watch_datapath_plugins ~root_dir ~pipe =
829
824
let sync ~root_dir =
830
825
Sys. readdir root_dir
831
826
>> = fun names ->
@@ -834,11 +829,8 @@ let watch_datapath_plugins ~root_dir =
834
829
Deferred. all_ignore (List. map ~f: (Datapath_plugins. register root_dir) (diff needed got_already))
835
830
>> = fun () ->
836
831
Deferred. all_ignore (List. map ~f: (Datapath_plugins. unregister root_dir) (diff got_already needed)) in
837
- Async_inotify. create ~recursive: false ~watch_new_dirs: false root_dir
838
- >> = fun (watch , _ ) ->
839
832
sync ~root_dir
840
833
>> = fun () ->
841
- let pipe = Async_inotify. pipe watch in
842
834
let open Async_inotify.Event in
843
835
let rec loop () =
844
836
( Pipe. read pipe >> = function
@@ -866,14 +858,32 @@ let watch_datapath_plugins ~root_dir =
866
858
let main ~root_dir ~state_path ~switch_path =
867
859
Attached_SRs. reload state_path
868
860
>> = fun () ->
869
- Deferred. all_unit [
870
- watch_volume_plugins ~root_dir ~switch_path ;
871
- watch_datapath_plugins ~root_dir
872
- ]
861
+ let datapath_root = Filename. concat root_dir " datapath" in
862
+ Async_inotify. create ~recursive: false ~watch_new_dirs: false datapath_root
863
+ >> = fun (watch , _ ) ->
864
+ let datapath = Async_inotify. pipe watch in
865
+ let volume_root = Filename. concat root_dir " volume" in
866
+ Async_inotify. create ~recursive: false ~watch_new_dirs: false volume_root
867
+ >> = fun (watch , _ ) ->
868
+ let volume = Async_inotify. pipe watch in
873
869
874
- let main ~root_dir ~state_path ~switch_path =
875
- let (_: unit Deferred.t ) = main ~root_dir ~state_path ~switch_path in
876
- never_returns (Scheduler. go () )
870
+ let rec loop () =
871
+ Monitor. try_with
872
+ (fun () ->
873
+ Deferred. all_unit [
874
+ watch_volume_plugins ~root_dir: volume_root ~switch_path ~pipe: volume;
875
+ watch_datapath_plugins ~root_dir: datapath_root ~pipe: datapath
876
+ ]
877
+ )
878
+ >> = function
879
+ | Ok () ->
880
+ info " main thread shutdown cleanly" ;
881
+ return ()
882
+ | Error x ->
883
+ error " main thread failed with %s" (Exn. to_string x);
884
+ Clock. after (Time.Span. of_sec 5. ) >> = fun () ->
885
+ loop () in
886
+ loop ()
877
887
878
888
open Xcp_service
879
889
@@ -918,5 +928,20 @@ let _ =
918
928
use_syslog := true ;
919
929
info " Daemonisation successful." ;
920
930
end ;
921
- main ~root_dir: ! root_dir ~state_path: ! state_path ~switch_path: ! Xcp_client. switch_path
931
+ let (_: unit Deferred.t ) =
932
+ let rec loop () =
933
+ Monitor. try_with
934
+ (fun () ->
935
+ main ~root_dir: ! root_dir ~state_path: ! state_path ~switch_path: ! Xcp_client. switch_path
936
+ )
937
+ >> = function
938
+ | Ok () ->
939
+ info " main thread shutdown cleanly" ;
940
+ return ()
941
+ | Error x ->
942
+ error " main thread failed with %s" (Exn. to_string x);
943
+ Clock. after (Time.Span. of_sec 5. ) >> = fun () ->
944
+ loop () in
945
+ loop () in
946
+ never_returns (Scheduler. go () )
922
947
0 commit comments