@@ -450,46 +450,60 @@ let process root_dir name x =
450
450
(* Active servers, one per sub-directory of the root_dir *)
451
451
let servers = String.Table. create () ~size: 4
452
452
453
- let create switch_port root_dir name =
453
+ (* XXX: need a better error-handling strategy *)
454
+ let get_ok = function
455
+ | `Ok x -> x
456
+ | `Error e ->
457
+ let b = Buffer. create 16 in
458
+ let fmt = Format. formatter_of_buffer b in
459
+ Protocol_unix.Server. pp_error fmt e;
460
+ Format. pp_print_flush fmt () ;
461
+ failwith (Buffer. contents b)
462
+
463
+ let create switch_path root_dir name =
454
464
if Hashtbl. mem servers name
455
465
then return ()
456
466
else begin
457
467
info " Adding %s" name
458
468
>> = fun () ->
459
- Protocol_async.M. connect switch_port >> = fun c ->
460
- let server = Protocol_async.Server. listen (process root_dir name) c (Filename. basename name) in
469
+ Protocol_async.Server. listen ~process: (process root_dir name) ~switch: switch_path ~queue: (Filename. basename name) ()
470
+ >> = fun result ->
471
+ let server = get_ok result in
461
472
Hashtbl. add_exn servers name server;
462
473
return ()
463
474
end
464
475
465
- let destroy switch_port name =
476
+ let destroy switch_path name =
466
477
info " Removing %s" name
467
478
>> = fun () ->
468
- Protocol_async.M. connect switch_port >> = fun c ->
469
- Hashtbl. remove servers name;
470
- return ()
479
+ if Hashtbl. mem servers name then begin
480
+ let t = Hashtbl. find_exn servers name in
481
+ Protocol_async.Server. shutdown ~t () >> = fun () ->
482
+ Hashtbl. remove servers name;
483
+ return ()
484
+ end else return ()
471
485
472
486
let rec diff a b = match a with
473
487
| [] -> []
474
488
| a :: aa ->
475
489
if List. mem b a then diff aa b else a :: (diff aa b)
476
490
477
491
(* Ensure the right servers are started *)
478
- let sync ~root_dir ~switch_port =
492
+ let sync ~root_dir ~switch_path =
479
493
Sys. readdir root_dir
480
494
>> = fun names ->
481
495
let needed : string list = Array. to_list names in
482
496
let got_already : string list = Hashtbl. keys servers in
483
- Deferred. all_ignore (List. map ~f: (create switch_port root_dir) (diff needed got_already))
497
+ Deferred. all_ignore (List. map ~f: (create switch_path root_dir) (diff needed got_already))
484
498
>> = fun () ->
485
- Deferred. all_ignore (List. map ~f: (destroy switch_port ) (diff got_already needed))
499
+ Deferred. all_ignore (List. map ~f: (destroy switch_path ) (diff got_already needed))
486
500
487
- let main ~root_dir ~switch_port =
501
+ let main ~root_dir ~switch_path =
488
502
(* We watch and create queues for the Volume plugins only *)
489
503
let root_dir = Filename. concat root_dir " volume" in
490
504
Async_inotify. create ~recursive: false ~watch_new_dirs: false root_dir
491
505
>> = fun (watch , _ ) ->
492
- sync ~root_dir ~switch_port
506
+ sync ~root_dir ~switch_path
493
507
>> = fun () ->
494
508
let pipe = Async_inotify. pipe watch in
495
509
let open Async_inotify.Event in
@@ -501,24 +515,24 @@ let main ~root_dir ~switch_port =
501
515
Shutdown. exit 1
502
516
| `Ok (Created path)
503
517
| `Ok (Moved (Into path )) ->
504
- create switch_port root_dir (Filename. basename path)
518
+ create switch_path root_dir (Filename. basename path)
505
519
| `Ok (Unlinked path)
506
520
| `Ok (Moved (Away path )) ->
507
- destroy switch_port (Filename. basename path)
521
+ destroy switch_path (Filename. basename path)
508
522
| `Ok (Modified _ ) ->
509
523
return ()
510
524
| `Ok (Moved (Move (path_a , path_b ))) ->
511
- destroy switch_port (Filename. basename path_a)
525
+ destroy switch_path (Filename. basename path_a)
512
526
>> = fun () ->
513
- create switch_port root_dir (Filename. basename path_b)
527
+ create switch_path root_dir (Filename. basename path_b)
514
528
| `Ok Queue_overflow ->
515
- sync ~root_dir ~switch_port
529
+ sync ~root_dir ~switch_path
516
530
) >> = fun () ->
517
531
loop () in
518
532
loop ()
519
533
520
- let main ~root_dir ~switch_port =
521
- let (_: unit Deferred.t ) = main ~root_dir ~switch_port in
534
+ let main ~root_dir ~switch_path =
535
+ let (_: unit Deferred.t ) = main ~root_dir ~switch_path in
522
536
never_returns (Scheduler. go () )
523
537
524
538
open Xcp_service
@@ -558,5 +572,5 @@ let _ =
558
572
use_syslog := true ;
559
573
Core.Syslog. openlog ~id: " xapi-storage-script" ~facility: Core.Syslog.Facility. DAEMON () ;
560
574
end ;
561
- main ~root_dir: ! root_dir ~switch_port : ! Xcp_client. switch_port
575
+ main ~root_dir: ! root_dir ~switch_path : ! Xcp_client. switch_path
562
576
0 commit comments