Skip to content

Commit e24abc8

Browse files
committed
Merge pull request #13 from djs55/message-switch.0.11.0
Update to the new message-switch API
2 parents 6d87ef5 + 22b4034 commit e24abc8

File tree

5 files changed

+47
-28
lines changed

5 files changed

+47
-28
lines changed

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
0.3.0 (24-Apr-2015)
2+
- Update to message-switch.0.11.0
3+
14
0.2.0 (4-Apr-2015)
25
- Update to SMAPIv2 with o_direct, o_direct_reason
36
- Update to using json marshalling for exception backtraces

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.3.0

_oasis

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OASISFormat: 0.2
22
Name: xapi-script-storage
3-
Version: 0.1
3+
Version: 0.3
44
Synopsis: Adapter which allows xapi to call storage scripts
55
Authors: David Scott
66
License: LGPL-2.1 with OCaml linking exception
@@ -13,4 +13,4 @@ Executable xapi_script_storage
1313
MainIs: main.ml
1414
Custom: true
1515
Install: false
16-
BuildDepends: xcp, xcp.storage, async_inotify, threads, message_switch.async, rpclib, xapi-storage, sexplib, sexplib.syntax, rpclib, rpclib.syntax
16+
BuildDepends: xcp, xcp.storage, async_inotify, threads, message_switch.async (>= 0.11.0), rpclib, xapi-storage, sexplib, sexplib.syntax, rpclib, rpclib.syntax

main.ml

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -450,46 +450,60 @@ let process root_dir name x =
450450
(* Active servers, one per sub-directory of the root_dir *)
451451
let servers = String.Table.create () ~size:4
452452

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 =
454464
if Hashtbl.mem servers name
455465
then return ()
456466
else begin
457467
info "Adding %s" name
458468
>>= 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
461472
Hashtbl.add_exn servers name server;
462473
return ()
463474
end
464475

465-
let destroy switch_port name =
476+
let destroy switch_path name =
466477
info "Removing %s" name
467478
>>= 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 ()
471485

472486
let rec diff a b = match a with
473487
| [] -> []
474488
| a :: aa ->
475489
if List.mem b a then diff aa b else a :: (diff aa b)
476490

477491
(* Ensure the right servers are started *)
478-
let sync ~root_dir ~switch_port =
492+
let sync ~root_dir ~switch_path =
479493
Sys.readdir root_dir
480494
>>= fun names ->
481495
let needed : string list = Array.to_list names in
482496
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))
484498
>>= 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))
486500

487-
let main ~root_dir ~switch_port =
501+
let main ~root_dir ~switch_path =
488502
(* We watch and create queues for the Volume plugins only *)
489503
let root_dir = Filename.concat root_dir "volume" in
490504
Async_inotify.create ~recursive:false ~watch_new_dirs:false root_dir
491505
>>= fun (watch, _) ->
492-
sync ~root_dir ~switch_port
506+
sync ~root_dir ~switch_path
493507
>>= fun () ->
494508
let pipe = Async_inotify.pipe watch in
495509
let open Async_inotify.Event in
@@ -501,24 +515,24 @@ let main ~root_dir ~switch_port =
501515
Shutdown.exit 1
502516
| `Ok (Created path)
503517
| `Ok (Moved (Into path)) ->
504-
create switch_port root_dir (Filename.basename path)
518+
create switch_path root_dir (Filename.basename path)
505519
| `Ok (Unlinked path)
506520
| `Ok (Moved (Away path)) ->
507-
destroy switch_port (Filename.basename path)
521+
destroy switch_path (Filename.basename path)
508522
| `Ok (Modified _) ->
509523
return ()
510524
| `Ok (Moved (Move (path_a, path_b))) ->
511-
destroy switch_port (Filename.basename path_a)
525+
destroy switch_path (Filename.basename path_a)
512526
>>= fun () ->
513-
create switch_port root_dir (Filename.basename path_b)
527+
create switch_path root_dir (Filename.basename path_b)
514528
| `Ok Queue_overflow ->
515-
sync ~root_dir ~switch_port
529+
sync ~root_dir ~switch_path
516530
) >>= fun () ->
517531
loop () in
518532
loop ()
519533

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
522536
never_returns (Scheduler.go ())
523537

524538
open Xcp_service
@@ -558,5 +572,5 @@ let _ =
558572
use_syslog := true;
559573
Core.Syslog.openlog ~id:"xapi-storage-script" ~facility:Core.Syslog.Facility.DAEMON ();
560574
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
562576

setup.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(* setup.ml generated for the first time by OASIS v0.4.4 *)
22

33
(* OASIS_START *)
4-
(* DO NOT EDIT (digest: 357e519346d191c046f831856e592460) *)
4+
(* DO NOT EDIT (digest: 2cebb0f2ebccebc1740714c72972c587) *)
55
(*
66
Regenerated by OASIS v0.4.5
77
Visit http://oasis.forge.ocamlcore.org for more information and
@@ -6673,7 +6673,7 @@ let setup_t =
66736673
alpha_features = [];
66746674
beta_features = [];
66756675
name = "xapi-script-storage";
6676-
version = "0.1";
6676+
version = "0.3";
66776677
license =
66786678
OASISLicense.DEP5License
66796679
(OASISLicense.DEP5Unit
@@ -6743,7 +6743,9 @@ let setup_t =
67436743
FindlibPackage ("xcp.storage", None);
67446744
FindlibPackage ("async_inotify", None);
67456745
FindlibPackage ("threads", None);
6746-
FindlibPackage ("message_switch.async", None);
6746+
FindlibPackage
6747+
("message_switch.async",
6748+
Some (OASISVersion.VGreaterEqual "0.11.0"));
67476749
FindlibPackage ("rpclib", None);
67486750
FindlibPackage ("xapi-storage", None);
67496751
FindlibPackage ("sexplib", None);
@@ -6770,14 +6772,14 @@ let setup_t =
67706772
};
67716773
oasis_fn = Some "_oasis";
67726774
oasis_version = "0.4.5";
6773-
oasis_digest = Some "#8c\151\238J\181\240\231Z\r\141PQ\248h";
6775+
oasis_digest = Some "\223w\129*\2508n\224(\131\015\249\232\225\232\031";
67746776
oasis_exec = None;
67756777
oasis_setup_args = [];
67766778
setup_update = false
67776779
};;
67786780

67796781
let setup () = BaseSetup.setup setup_t;;
67806782

6781-
# 6782 "setup.ml"
6783+
# 6784 "setup.ml"
67826784
(* OASIS_STOP *)
67836785
let () = setup ();;

0 commit comments

Comments
 (0)