Skip to content

Commit

Permalink
CA-405628: unmount/detach PVS cache VDI before destroying (#6266)
Browse files Browse the repository at this point in the history
The pvsproxy daemon normally unmounts and removes the locally attached
VBD for the cache VDI when needed. We do it as well in
`PVS_cache_storage.destroy`, just in case pvsproxy did not manage to,
for whatever reason. This should avoid any VDI_IN_USE errors.
  • Loading branch information
robhoes authored Feb 3, 2025
2 parents 3183abf + ca18a52 commit b81ff9d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ocaml/xapi/pvs_cache_vdi.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,24 @@ let get_or_recreate_vdi ~__context ~self =
vdi
)

let ensure_vdi_is_closed ~__context vdi =
(* The pvsproxy daemon normally unmounts and removes the locally attached VBD
for the cache VDI. Here we do it as well, just in case pvsproxy did not
manage to, for whatever reason. *)
try
let uuid = Db.VDI.get_uuid ~__context ~self:vdi in
let _ : string =
Helpers.call_script !Xapi_globs.pvsproxy_close_cache_vdi [uuid]
in
()
with _ -> () (* call_script will log anything interesting already *)

let destroy_vdi ~__context ~self =
match get_vdi ~__context ~self with
| None ->
() (* The VDI doesn't exist anymore; nothing to do. *)
| Some vdi ->
ensure_vdi_is_closed ~__context vdi ;
Helpers.call_api_functions ~__context (fun rpc session_id ->
Client.Client.VDI.destroy ~rpc ~session_id ~self:vdi
)
6 changes: 6 additions & 0 deletions ocaml/xapi/xapi_globs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,8 @@ let dracut = ref "/usr/bin/dracut"

let udevadm = ref "/usr/sbin/udevadm"

let pvsproxy_close_cache_vdi = ref "/opt/citrix/pvsproxy/close-cache-vdi.sh"

let yum_repos_config_dir = ref "/etc/yum.repos.d"

let remote_repository_prefix = ref "remote"
Expand Down Expand Up @@ -1892,6 +1894,10 @@ module Resources = struct
, "Execute during PIF unplug to get the lun devices related with the \
ether interface of the PIF"
)
; ( "pvsproxy_close_cache_vdi"
, pvsproxy_close_cache_vdi
, "Path to close-cache-vdi.sh"
)
]

let essential_files =
Expand Down

0 comments on commit b81ff9d

Please sign in to comment.