]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/internal: update invalidate_cache
authorlixiaoy1 <xiaoyan.li@intel.com>
Fri, 11 Sep 2020 14:26:39 +0000 (10:26 -0400)
committerlixiaoy1 <xiaoyan.li@intel.com>
Thu, 29 Oct 2020 15:33:10 +0000 (23:33 +0800)
Except invalidating object cache, invalidate image writeback cache.

Signed-off-by: Li, Xiaoyan <xiaoyan.li@intel.com>
src/librbd/cache/pwl/DiscardRequest.cc
src/librbd/internal.cc
src/test/librbd/test_librbd.cc

index 32a0077d4e7833c7f7cbb10ea6ffed7cc48a80c0..80ccd5abca072e0bb05dd456eabe47ff5cd0f857 100644 (file)
@@ -62,6 +62,7 @@ void DiscardRequest<I>::send() {
 #endif
 }
 
+#if defined(WITH_RBD_RWL)
 template <typename I>
 void DiscardRequest<I>::delete_image_cache_file() {
   CephContext *cct = m_image_ctx.cct;
@@ -147,6 +148,8 @@ void DiscardRequest<I>::handle_remove_feature_bit(int r) {
   finish();
 }
 
+#endif // WITH_RBD_RWL
+
 template <typename I>
 void DiscardRequest<I>::finish() {
 #if defined(WITH_RBD_RWL)
index d895d1f35e6d66c571d606da9b6be9c911d3788c..50a3a0f38d31688ffdf42e43e5f55c13718f4eb8 100644 (file)
@@ -36,6 +36,7 @@
 #include "librbd/api/Config.h"
 #include "librbd/api/Image.h"
 #include "librbd/api/Io.h"
+#include "librbd/cache/Utils.h"
 #include "librbd/exclusive_lock/AutomaticPolicy.h"
 #include "librbd/exclusive_lock/StandardPolicy.h"
 #include "librbd/deep_copy/MetadataCopyRequest.h"
@@ -45,6 +46,7 @@
 #include "librbd/image/Types.h"
 #include "librbd/io/AioCompletion.h"
 #include "librbd/io/ImageRequest.h"
+#include "librbd/io/ImageDispatcherInterface.h"
 #include "librbd/io/ObjectDispatcherInterface.h"
 #include "librbd/io/ObjectRequest.h"
 #include "librbd/io/ReadResult.h"
@@ -1610,11 +1612,25 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
 
     C_SaferCond ctx;
     {
-      std::shared_lock owner_locker{ictx->owner_lock};
-      ictx->io_object_dispatcher->invalidate_cache(&ctx);
+      ictx->io_image_dispatcher->invalidate_cache(&ctx);
     }
     r = ctx.wait();
+
+    if (r < 0) {
+      ldout(cct, 20) << "failed to invalidate image cache" << dendl;
+      return r;
+    }
+
     ictx->perfcounter->inc(l_librbd_invalidate_cache);
+
+    // Delete writeback cache if it is not initialized
+    if ((!ictx->exclusive_lock ||
+         !ictx->exclusive_lock->is_lock_owner()) &&
+        ictx->test_features(RBD_FEATURE_DIRTY_CACHE)) {
+      C_SaferCond ctx3;
+      librbd::cache::util::discard_cache<>(*ictx, &ctx3);
+      r = ctx3.wait();
+    }
     return r;
   }
 
index 93164f616733914149125d7adc5df839e1ce1791..fa556fc6a6f3323ed4b25537b5c3cad8dace2bc6 100644 (file)
@@ -4538,6 +4538,8 @@ TEST_F(TestLibRBD, TestPendingAio)
                                 false, features));
   ASSERT_EQ(0, rbd_open(ioctx, name.c_str(), &image, NULL));
 
+  ASSERT_EQ(0, rbd_invalidate_cache(image));
+
   char test_data[TEST_IO_SIZE];
   for (size_t i = 0; i < TEST_IO_SIZE; ++i) {
     test_data[i] = (char) (rand() % (126 - 33) + 33);