Skip to content

Commit

Permalink
Merge pull request #3962 from lippirk/CA-314317-backport-to-v8.0
Browse files Browse the repository at this point in the history
CA-314317: Protect PVS-cache get_or_recreate_vdi by mutex
  • Loading branch information
lippirk authored Sep 30, 2019
2 parents f5ae6cc + da5a744 commit 5ba6c01
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions ocaml/xapi/pvs_cache_vdi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,19 @@ let get_vdi ~__context ~self =
end
end

let m = Mutex.create ()

let get_or_recreate_vdi ~__context ~self =
match get_vdi ~__context ~self with
| None ->
let sR = Db.PVS_cache_storage.get_SR ~__context ~self in
let size = Db.PVS_cache_storage.get_size ~__context ~self in
let vdi = create_vdi ~__context ~sR ~size in
Db.PVS_cache_storage.set_VDI ~__context ~self ~value:vdi;
vdi
| Some vdi -> vdi
Stdext.Threadext.Mutex.execute m (fun () ->
match get_vdi ~__context ~self with
| None ->
let sR = Db.PVS_cache_storage.get_SR ~__context ~self in
let size = Db.PVS_cache_storage.get_size ~__context ~self in
let vdi = create_vdi ~__context ~sR ~size in
Db.PVS_cache_storage.set_VDI ~__context ~self ~value:vdi;
vdi
| Some vdi -> vdi
)

let destroy_vdi ~__context ~self =
match get_vdi ~__context ~self with
Expand Down

0 comments on commit 5ba6c01

Please sign in to comment.