From: Ilya Dryomov Date: Sun, 10 Apr 2022 14:57:24 +0000 (+0200) Subject: librbd/cache/pwl: don't crash if cache file removal fails X-Git-Tag: v16.2.8~19^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1ed031fec5ca5eb275a9601e390f8cb4201d42f9;p=ceph.git librbd/cache/pwl: don't crash if cache file removal fails The non-ec overload will throw fs::filesystem_error on any error (e.g. EPERM due to unprivileged "rbd persistent-cache invalidate" being brought up against a privileged workload). Signed-off-by: Ilya Dryomov (cherry picked from commit 63197ff7003fa9e595527a7431f9f3f6790f7d57) --- diff --git a/src/librbd/cache/pwl/DiscardRequest.cc b/src/librbd/cache/pwl/DiscardRequest.cc index 9f66e077b1f..69f48d243e8 100644 --- a/src/librbd/cache/pwl/DiscardRequest.cc +++ b/src/librbd/cache/pwl/DiscardRequest.cc @@ -72,7 +72,13 @@ void DiscardRequest::delete_image_cache_file() { if (m_cache_state->present && !m_cache_state->host.compare(ceph_get_short_hostname()) && fs::exists(m_cache_state->path)) { - fs::remove(m_cache_state->path); + std::error_code ec; + fs::remove(m_cache_state->path, ec); + if (ec) { + lderr(cct) << "failed to remove persistent cache file: " << ec.message() + << dendl; + // not fatal + } } remove_image_cache_state();