From: Jason Dillaman Date: Mon, 5 Mar 2018 16:16:00 +0000 (-0500) Subject: librbd: discard from cache after committed to disk X-Git-Tag: v13.0.2~31^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F20682%2Fhead;p=ceph.git librbd: discard from cache after committed to disk This prevents a possible race condition with readahead racing with a discard and re-populating the cache with non-zeroed data. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/cache/ObjectCacherObjectDispatch.cc b/src/librbd/cache/ObjectCacherObjectDispatch.cc index 32a1d8952773f..8531a190ba139 100644 --- a/src/librbd/cache/ObjectCacherObjectDispatch.cc +++ b/src/librbd/cache/ObjectCacherObjectDispatch.cc @@ -215,12 +215,19 @@ bool ObjectCacherObjectDispatch::discard( ldout(cct, 20) << "object_no=" << object_no << " " << object_off << "~" << object_len << dendl; - ObjectExtents object_extents; - object_extents.emplace_back(oid, object_no, object_off, object_len, 0); - - m_cache_lock.Lock(); - m_object_cacher->discard_set(m_object_set, object_extents); - m_cache_lock.Unlock(); + // discard the cache state after changes are committed to disk + auto ctx = *on_finish; + *on_finish = new FunctionContext( + [this, oid, object_no, object_off, object_len, ctx](int r) { + ObjectExtents object_extents; + object_extents.emplace_back(oid, object_no, object_off, object_len, 0); + + m_cache_lock.Lock(); + m_object_cacher->discard_set(m_object_set, object_extents); + m_cache_lock.Unlock(); + + ctx->complete(r); + }); // pass-through the discard request since ObjectCacher won't // writeback discards.