]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: integrate image cache hooks into IO path 9121/head
authorJason Dillaman <dillaman@redhat.com>
Fri, 26 Aug 2016 17:48:23 +0000 (13:48 -0400)
committerJason Dillaman <dillaman@redhat.com>
Sat, 27 Aug 2016 23:37:37 +0000 (19:37 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/AioImageRequest.cc
src/librbd/ImageCtx.h
src/test/librbd/mock/MockImageCtx.h
src/test/librbd/mock/cache/MockImageCache.h [new file with mode: 0644]
src/test/librbd/test_mock_AioImageRequest.cc

index 984e6c69c7e2bd5a657999f9d7347b864f4daf30..72abba52a83d9f68c146327a4f412f1b9c674523 100644 (file)
@@ -8,6 +8,7 @@
 #include "librbd/internal.h"
 #include "librbd/Journal.h"
 #include "librbd/Utils.h"
+#include "librbd/cache/ImageCache.h"
 #include "librbd/journal/Types.h"
 #include "include/rados/librados.hpp"
 #include "common/WorkQueue.h"
@@ -241,7 +242,7 @@ void AioImageRequest<I>::send() {
     return;
   }
 
-  if (m_bypass_image_cache || true) { // TODO
+  if (m_bypass_image_cache || m_image_ctx.image_cache == nullptr) {
     send_request();
   } else {
     send_image_cache_request();
@@ -349,7 +350,16 @@ void AioImageRead<I>::send_request() {
 
 template <typename I>
 void AioImageRead<I>::send_image_cache_request() {
-  // TODO
+  I &image_ctx = this->m_image_ctx;
+  assert(image_ctx.image_cache != nullptr);
+
+  AioCompletion *aio_comp = this->m_aio_comp;
+  aio_comp->set_request_count(1);
+  C_ImageCacheRead<I> *req_comp = new C_ImageCacheRead<I>(
+    aio_comp, this->m_image_extents);
+  image_ctx.image_cache->aio_read(std::move(this->m_image_extents),
+                                  &req_comp->get_data(), m_op_flags,
+                                  req_comp);
 }
 
 template <typename I>
@@ -483,7 +493,14 @@ uint64_t AioImageWrite<I>::append_journal_event(
 
 template <typename I>
 void AioImageWrite<I>::send_image_cache_request() {
-  // TODO
+  I &image_ctx = this->m_image_ctx;
+  assert(image_ctx.image_cache != nullptr);
+
+  AioCompletion *aio_comp = this->m_aio_comp;
+  aio_comp->set_request_count(1);
+  C_AioRequest *req_comp = new C_AioRequest(aio_comp);
+  image_ctx.image_cache->aio_write(std::move(this->m_image_extents),
+                                   std::move(m_bl), m_op_flags, req_comp);
 }
 
 template <typename I>
@@ -588,7 +605,15 @@ uint32_t AioImageDiscard<I>::get_object_cache_request_count(bool journaling) con
 
 template <typename I>
 void AioImageDiscard<I>::send_image_cache_request() {
-  // TODO
+  I &image_ctx = this->m_image_ctx;
+  assert(image_ctx.image_cache != nullptr);
+
+  AioCompletion *aio_comp = this->m_aio_comp;
+  aio_comp->set_request_count(this->m_image_extents.size());
+  for (auto &extent : this->m_image_extents) {
+    C_AioRequest *req_comp = new C_AioRequest(aio_comp);
+    image_ctx.image_cache->aio_discard(extent.first, extent.second, req_comp);
+  }
 }
 
 template <typename I>
@@ -684,7 +709,13 @@ void AioImageFlush<I>::send_request() {
 
 template <typename I>
 void AioImageFlush<I>::send_image_cache_request() {
-  // TODO
+  I &image_ctx = this->m_image_ctx;
+  assert(image_ctx.image_cache != nullptr);
+
+  AioCompletion *aio_comp = this->m_aio_comp;
+  aio_comp->set_request_count(1);
+  C_AioRequest *req_comp = new C_AioRequest(aio_comp);
+  image_ctx.image_cache->aio_flush(req_comp);
 }
 
 } // namespace librbd
index 6c79f80ea74babe262868ffdf4a56ca607eb79f9..b7a7eeae027421179dbbd1ecf7ddf8ae25e73235 100644 (file)
@@ -51,6 +51,7 @@ namespace librbd {
   template <typename> class Operations;
   class LibrbdWriteback;
 
+  namespace cache { struct ImageCache; }
   namespace exclusive_lock { struct Policy; }
   namespace journal { struct Policy; }
 
@@ -127,6 +128,7 @@ namespace librbd {
 
     file_layout_t layout;
 
+    cache::ImageCache *image_cache = nullptr;
     ObjectCacher *object_cacher;
     LibrbdWriteback *writeback_handler;
     ObjectCacher::ObjectSet *object_set;
index bf1ee539e097204440bf26de447eaff8aa60f402..e762fe6fba93cc6a6a4b3a2a45532376d11e553b 100644 (file)
@@ -22,6 +22,7 @@
 
 namespace librbd {
 
+namespace cache { class MockImageCache; }
 namespace operation {
 template <typename> class ResizeRequest;
 }
@@ -231,10 +232,11 @@ struct MockImageCtx {
   xlist<AsyncRequest<MockImageCtx>*> async_requests;
   std::list<Context*> async_requests_waiters;
 
-
   MockAioImageRequestWQ *aio_work_queue;
   MockContextWQ *op_work_queue;
 
+  cache::MockImageCache *image_cache = nullptr;
+
   MockReadahead readahead;
   uint64_t readahead_max_bytes;
 
diff --git a/src/test/librbd/mock/cache/MockImageCache.h b/src/test/librbd/mock/cache/MockImageCache.h
new file mode 100644 (file)
index 0000000..4969c03
--- /dev/null
@@ -0,0 +1,38 @@
+// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_TEST_LIBRBD_CACHE_MOCK_IMAGE_CACHE_H
+#define CEPH_TEST_LIBRBD_CACHE_MOCK_IMAGE_CACHE_H
+
+#include "gmock/gmock.h"
+#include <vector>
+
+namespace librbd {
+namespace cache {
+
+struct MockImageCache {
+  typedef std::vector<std::pair<uint64_t,uint64_t> > Extents;
+
+  MOCK_METHOD4(aio_read_mock, void(const Extents &, ceph::bufferlist*, int,
+                                   Context *));
+  void aio_read(Extents&& image_extents, ceph::bufferlist* bl,
+                int fadvise_flags, Context *on_finish) {
+    aio_read_mock(image_extents, bl, fadvise_flags, on_finish);
+  }
+
+
+  MOCK_METHOD4(aio_write_mock, void(const Extents &, const ceph::bufferlist &,
+                                    int, Context *));
+  void aio_write(Extents&& image_extents, ceph::bufferlist&& bl,
+                 int fadvise_flags, Context *on_finish) {
+    aio_write_mock(image_extents, bl, fadvise_flags, on_finish);
+  }
+
+  MOCK_METHOD3(aio_discard, void(uint64_t, uint64_t, Context *));
+  MOCK_METHOD1(aio_flush, void(Context *));
+};
+
+} // namespace cache
+} // namespace librbd
+
+#endif // CEPH_TEST_LIBRBD_CACHE_MOCK_IMAGE_CACHE_H
index dd64b5f28a886547ee3ce008bd92ce16523d42bc..8e91b72a15d2d1a4c34d18b220c954eed72c9232 100644 (file)
@@ -5,6 +5,7 @@
 #include "test/librbd/test_support.h"
 #include "test/librbd/mock/MockImageCtx.h"
 #include "test/librbd/mock/MockJournal.h"
+#include "test/librbd/mock/cache/MockImageCache.h"
 #include "librbd/AioImageRequest.h"
 #include "librbd/AioObjectRequest.h"