]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: discard from cache after committed to disk 20682/head
authorJason Dillaman <dillaman@redhat.com>
Mon, 5 Mar 2018 16:16:00 +0000 (11:16 -0500)
committerJason Dillaman <dillaman@redhat.com>
Wed, 7 Mar 2018 17:45:42 +0000 (12:45 -0500)
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 <dillaman@redhat.com>
src/librbd/cache/ObjectCacherObjectDispatch.cc

index 32a1d8952773fadebd060af287c9acf355199c57..8531a190ba1399279d014fdbd0ff16dcbee6e3ee 100644 (file)
@@ -215,12 +215,19 @@ bool ObjectCacherObjectDispatch<I>::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.