From ca18a524f6d875bfcbb1565d320e45a3861c3989 Mon Sep 17 00:00:00 2001 From: Rob Hoes Date: Fri, 31 Jan 2025 17:12:25 +0000 Subject: [PATCH] CA-405628: unmount/detach PVS cache VDI before destroying 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. Signed-off-by: Rob Hoes --- ocaml/xapi/pvs_cache_vdi.ml | 13 +++++++++++++ ocaml/xapi/xapi_globs.ml | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/ocaml/xapi/pvs_cache_vdi.ml b/ocaml/xapi/pvs_cache_vdi.ml index 5fe404be616..e0bfea098e9 100644 --- a/ocaml/xapi/pvs_cache_vdi.ml +++ b/ocaml/xapi/pvs_cache_vdi.ml @@ -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 ) diff --git a/ocaml/xapi/xapi_globs.ml b/ocaml/xapi/xapi_globs.ml index c07c3d9b739..c7a440523c0 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" @@ -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 =