diff --git a/ocaml/xapi/pvs_cache_vdi.ml b/ocaml/xapi/pvs_cache_vdi.ml index 5fe404be61..f98dd0ac56 100644 --- a/ocaml/xapi/pvs_cache_vdi.ml +++ b/ocaml/xapi/pvs_cache_vdi.ml @@ -79,11 +79,22 @@ 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 _ = 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 ) diff --git a/ocaml/xapi/xapi_globs.ml b/ocaml/xapi/xapi_globs.ml index c07c3d9b73..f49a060678 100644 --- a/ocaml/xapi/xapi_globs.ml +++ b/ocaml/xapi/xapi_globs.ml @@ -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" @@ -1805,6 +1807,10 @@ module Resources = struct ; ("depmod", depmod, "Path to depmod command") ; ("dracut", dracut, "Path to dracut command") ; ("udevadm", udevadm, "Path to udevadm command") + ; ( "pvsproxy_close_cache_vdi" + , pvsproxy_close_cache_vdi + , "Path to close-cache-vdi.sh" + ) ] let nonessential_executables =