Permalink
Browse files

CA-92156: Reapply the c/s that caused the problem with a fix.

The is_tools_sr cache is incorrect when the tools SR is introduced.
This is an attempt at a fix by simply clearing the cache after
dbsync_master might have introduced the tools SR.

Signed-off-by: Jon Ludlam <jonathan.ludlam@eu.citrix.com>
  • Loading branch information...
1 parent 8c7cee0 commit 6c5513745024e47acd9a5db948b610f0b39d3789 @jonludlam jonludlam committed Oct 13, 2012
Showing with 33 additions and 5 deletions.
  1. +9 −0 ocaml/xapi/dbsync_master.ml
  2. +24 −5 ocaml/xapi/helpers.ml
@@ -211,4 +211,13 @@ let update_env __context =
create_tools_sr_noexn __context;
+ (* If we did actually create a tools sr in the previous call,
+ the cache will be incorrect. This is because the SR is
+ introduced before the magic flag marking it as a tools SR
+ is set. A side effect of the introduction is to calculate
+ its allowed operations, which calls 'is_tools_sr', which
+ returns false, and that result is cached. The simplest fix
+ is to just clear the cache, which we do here. *)
+ Helpers.clear_tools_sr_cache ();
+
ensure_vm_metrics_records_exist_noexn __context
View
@@ -668,13 +668,32 @@ let cancel_tasks ~__context ~ops ~all_tasks_in_db (* all tasks in database *) ~t
Currently this just means "CD" but might change in future? *)
let is_removable ~__context ~vbd = Db.VBD.get_type ~__context ~self:vbd = `CD
+let is_tools_sr_cache = ref []
+let is_tools_sr_cache_m = Mutex.create ()
+
+let clear_tools_sr_cache () =
+ Mutex.execute is_tools_sr_cache_m
+ (fun () -> is_tools_sr_cache := [])
+
(** Returns true if this SR is the XenSource Tools SR *)
let is_tools_sr ~__context ~sr =
- let other_config = Db.SR.get_other_config ~__context ~self:sr in
- (* Miami GA *)
- List.mem_assoc Xapi_globs.tools_sr_tag other_config
- (* Miami beta2 and earlier: *)
- || (List.mem_assoc Xapi_globs.xensource_internal other_config)
+ try
+ Mutex.execute is_tools_sr_cache_m
+ (fun () -> List.assoc sr !is_tools_sr_cache)
+ with Not_found _ ->
+ let other_config = Db.SR.get_other_config ~__context ~self:sr in
+ (* Miami GA *)
+ let result =
+ List.mem_assoc Xapi_globs.tools_sr_tag other_config
+ (* Miami beta2 and earlier: *)
+ || (List.mem_assoc Xapi_globs.xensource_internal other_config)
+ in
+ Mutex.execute is_tools_sr_cache_m
+ (fun () ->
+ let cache = !is_tools_sr_cache in
+ if not (List.mem_assoc sr cache) then
+ is_tools_sr_cache := (sr, result) :: !is_tools_sr_cache);
+ result
(** Return true if the MAC is in the right format XX:XX:XX:XX:XX:XX *)
let is_valid_MAC mac =

0 comments on commit 6c55137

Please sign in to comment.