@@ -625,49 +625,43 @@ let get_ok = function
625
625
Format. pp_print_flush fmt () ;
626
626
failwith (Buffer. contents b)
627
627
628
- let create switch_path root_dir name =
629
- if Hashtbl. mem servers name
630
- then return ()
631
- else begin
632
- info " Adding %s" name
633
- >> = fun () ->
634
- Protocol_async.Server. listen ~process: (process root_dir name) ~switch: switch_path ~queue: (Filename. basename name) ()
635
- >> = fun result ->
636
- let server = get_ok result in
637
- Hashtbl. add_exn servers name server;
638
- return ()
639
- end
640
-
641
- let destroy switch_path name =
642
- info " Removing %s" name
643
- >> = fun () ->
644
- if Hashtbl. mem servers name then begin
645
- let t = Hashtbl. find_exn servers name in
646
- Protocol_async.Server. shutdown ~t () >> = fun () ->
647
- Hashtbl. remove servers name;
648
- return ()
649
- end else return ()
650
628
651
629
let rec diff a b = match a with
652
630
| [] -> []
653
631
| a :: aa ->
654
632
if List. mem b a then diff aa b else a :: (diff aa b)
655
633
656
- (* Ensure the right servers are started *)
657
- let sync ~root_dir ~switch_path =
658
- Sys. readdir root_dir
659
- >> = fun names ->
660
- let needed : string list = Array. to_list names in
661
- let got_already : string list = Hashtbl. keys servers in
662
- Deferred. all_ignore (List. map ~f: (create switch_path root_dir) (diff needed got_already))
663
- >> = fun () ->
664
- Deferred. all_ignore (List. map ~f: (destroy switch_path) (diff got_already needed))
665
-
666
- let main ~root_dir ~state_path ~switch_path =
667
- Attached_SRs. reload state_path
668
- >> = fun () ->
669
- (* We watch and create queues for the Volume plugins only *)
634
+ let watch_volume_plugins ~root_dir ~switch_path =
670
635
let root_dir = Filename. concat root_dir " volume" in
636
+ let create switch_path root_dir name =
637
+ if Hashtbl. mem servers name
638
+ then return ()
639
+ else begin
640
+ info " Adding %s" name
641
+ >> = fun () ->
642
+ Protocol_async.Server. listen ~process: (process root_dir name) ~switch: switch_path ~queue: (Filename. basename name) ()
643
+ >> = fun result ->
644
+ let server = get_ok result in
645
+ Hashtbl. add_exn servers name server;
646
+ return ()
647
+ end in
648
+ let destroy switch_path name =
649
+ info " Removing %s" name
650
+ >> = fun () ->
651
+ if Hashtbl. mem servers name then begin
652
+ let t = Hashtbl. find_exn servers name in
653
+ Protocol_async.Server. shutdown ~t () >> = fun () ->
654
+ Hashtbl. remove servers name;
655
+ return ()
656
+ end else return () in
657
+ let sync ~root_dir ~switch_path =
658
+ Sys. readdir root_dir
659
+ >> = fun names ->
660
+ let needed : string list = Array. to_list names in
661
+ let got_already : string list = Hashtbl. keys servers in
662
+ Deferred. all_ignore (List. map ~f: (create switch_path root_dir) (diff needed got_already))
663
+ >> = fun () ->
664
+ Deferred. all_ignore (List. map ~f: (destroy switch_path) (diff got_already needed)) in
671
665
Async_inotify. create ~recursive: false ~watch_new_dirs: false root_dir
672
666
>> = fun (watch , _ ) ->
673
667
sync ~root_dir ~switch_path
@@ -698,6 +692,11 @@ let main ~root_dir ~state_path ~switch_path =
698
692
loop () in
699
693
loop ()
700
694
695
+ let main ~root_dir ~state_path ~switch_path =
696
+ Attached_SRs. reload state_path
697
+ >> = fun () ->
698
+ watch_volume_plugins ~root_dir ~switch_path
699
+
701
700
let main ~root_dir ~state_path ~switch_path =
702
701
let (_: unit Deferred.t ) = main ~root_dir ~state_path ~switch_path in
703
702
never_returns (Scheduler. go () )
0 commit comments