Skip to content

Commit

Permalink
Merge pull request xapi-project#9 from koushikcgit/CA-191570
Browse files Browse the repository at this point in the history
CA-191570: Make use of meaningful token while adding xenstore watch
  • Loading branch information
robhoes committed Jan 5, 2016
2 parents 378502c + d615c55 commit b927dc5
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/xenstore_watch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b927dc5

Please sign in to comment.