diff --git a/src/xenstore_watch.ml b/src/xenstore_watch.ml index 8b401d86d..0a97489d6 100644 --- a/src/xenstore_watch.ml +++ b/src/xenstore_watch.ml @@ -26,6 +26,7 @@ module IntMap = Map.Make(struct type t = int let compare = compare end) module IntSet = Set.Make(struct type t = int let compare = compare end) module type WATCH_ACTIONS = sig + val watch_token : int -> string val interesting_paths_for_domain : int -> string -> string list val watch_fired : Xenctrl.handle -> string -> Xenctrl.domaininfo IntMap.t -> IntSet.t -> unit val unmanaged_domain : int -> string -> bool @@ -34,14 +35,14 @@ module type WATCH_ACTIONS = sig val domain_disappeared : Xenctrl.handle -> int -> unit end -let watch xs path = - debug "xenstore watch %s" path; - Xs.watch xs path path +let watch xs token path = + debug "xenstore watch path=%s token=%s" path token; + Xs.watch xs path token -let unwatch xs path = +let unwatch xs token path = try - debug "xenstore unwatch %s" path; - Xs.unwatch xs path path + debug "xenstore unwatch path=%s token=%s" path token; + Xs.unwatch xs path token with Xs_protocol.Enoent _ -> debug "xenstore unwatch %s threw Xs_protocol.Enoent" path @@ -75,16 +76,18 @@ module WatchXenstore = functor(Actions: WATCH_ACTIONS) -> struct let add_watches_for_domain xs domid uuid = debug "Adding watches for: domid %d" domid; Actions.domain_appeared xc domid; - List.iter (watch xs) (Actions.interesting_paths_for_domain domid uuid); + let token = Actions.watch_token domid in + List.iter (watch xs token) (Actions.interesting_paths_for_domain domid uuid); uuids := IntMap.add domid uuid !uuids; watches := IntSet.add domid !watches in let remove_watches_for_domain xs domid = debug "Removing watches for: domid %d" domid; Actions.domain_disappeared xc domid; + let token = Actions.watch_token domid in if IntMap.mem domid !uuids then begin let uuid = IntMap.find domid !uuids in - List.iter (unwatch xs) (Actions.interesting_paths_for_domain domid uuid); + List.iter (unwatch xs token) (Actions.interesting_paths_for_domain domid uuid); watches := IntSet.remove domid !watches; uuids := IntMap.remove domid !uuids; end in