Skip to content

Commit

Permalink
librbd: integrate image cache hooks into IO path
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
  • Loading branch information
Jason Dillaman committed Aug 26, 2016
1 parent 1b44a03 commit 0c1e8f3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 6 deletions.
41 changes: 36 additions & 5 deletions src/librbd/AioImageRequest.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/librbd/ImageCtx.h
Expand Up @@ -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; }

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion src/test/librbd/mock/MockImageCtx.h
Expand Up @@ -22,6 +22,7 @@

namespace librbd {

namespace cache { class MockImageCache; }
namespace operation {
template <typename> class ResizeRequest;
}
Expand Down Expand Up @@ -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;

Expand Down
38 changes: 38 additions & 0 deletions src/test/librbd/mock/cache/MockImageCache.h
@@ -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
1 change: 1 addition & 0 deletions src/test/librbd/test_mock_AioImageRequest.cc
Expand Up @@ -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"

Expand Down

0 comments on commit 0c1e8f3

Please sign in to comment.