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: v17.2.1~87^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=05c167f8cd767974d268862eb421fdf8399da391;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 decefafb5277..9d4bff26b2ce 100644 --- a/src/librbd/cache/pwl/DiscardRequest.cc +++ b/src/librbd/cache/pwl/DiscardRequest.cc @@ -68,7 +68,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();