From 5e950803bbcb63acc10e1e4dbcca44b022be738e Mon Sep 17 00:00:00 2001 From: lixiaoy1 Date: Fri, 9 Oct 2020 06:30:04 -0400 Subject: [PATCH] rbd/cache: remove unnecessary WriteLogCache Remove the class librbd::cache::WriteLogCache. Signed-off-by: Li, Xiaoyan --- src/librbd/CMakeLists.txt | 3 +- src/librbd/cache/WriteLogCache.cc | 102 ------------------ src/librbd/cache/WriteLogCache.h | 63 ----------- ...geDispatch.cc => WriteLogImageDispatch.cc} | 56 +++++----- ...mageDispatch.h => WriteLogImageDispatch.h} | 22 ++-- src/librbd/cache/pwl/AbstractWriteLog.h | 2 - src/librbd/cache/pwl/InitRequest.cc | 10 +- src/librbd/cache/pwl/InitRequest.h | 8 +- src/librbd/cache/pwl/ShutdownRequest.cc | 15 ++- src/librbd/cache/pwl/ShutdownRequest.h | 12 +-- .../exclusive_lock/PreReleaseRequest.cc | 1 - .../cache/test_mock_ReplicatedWriteLog.cc | 81 +++++++------- 12 files changed, 105 insertions(+), 270 deletions(-) delete mode 100644 src/librbd/cache/WriteLogCache.cc delete mode 100644 src/librbd/cache/WriteLogCache.h rename src/librbd/cache/{pwl/ImageDispatch.cc => WriteLogImageDispatch.cc} (82%) rename src/librbd/cache/{pwl/ImageDispatch.h => WriteLogImageDispatch.h} (86%) diff --git a/src/librbd/CMakeLists.txt b/src/librbd/CMakeLists.txt index c25ca46f69f0..62137fb52aa6 100644 --- a/src/librbd/CMakeLists.txt +++ b/src/librbd/CMakeLists.txt @@ -195,8 +195,7 @@ if(WITH_RBD_RWL) cache/pwl/Types.cc cache/pwl/ReplicatedWriteLog.cc cache/pwl/AbstractWriteLog.cc - cache/pwl/ImageDispatch.cc - cache/WriteLogCache.cc) + cache/WriteLogImageDispatch.cc) endif() add_library(rbd_api STATIC librbd.cc) diff --git a/src/librbd/cache/WriteLogCache.cc b/src/librbd/cache/WriteLogCache.cc deleted file mode 100644 index ecbd5aa3cb8a..000000000000 --- a/src/librbd/cache/WriteLogCache.cc +++ /dev/null @@ -1,102 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#include "WriteLogCache.h" -#include "librbd/cache/pwl/ReplicatedWriteLog.h" -#include "librbd/cache/pwl/ImageCacheState.h" - -#undef dout_subsys -#define dout_subsys ceph_subsys_rbd_pwl -#undef dout_prefix -#define dout_prefix *_dout << "librbd::cache::WriteLogCache: " << this << " " \ - << __func__ << ": " - -namespace librbd { -namespace cache { - -using namespace librbd::cache::pwl; - -template -WriteLogCache::WriteLogCache(I &image_ctx, librbd::cache::pwl::ImageCacheState* cache_state) { - m_write_log = new librbd::cache::pwl::ReplicatedWriteLog(image_ctx, cache_state); -} - -template -WriteLogCache::~WriteLogCache() { - delete m_write_log; -} - -template -void WriteLogCache::aio_read(Extents&& image_extents, - ceph::bufferlist* bl, - int fadvise_flags, - Context *on_finish) { - m_write_log->read(std::move(image_extents), std::move(bl), fadvise_flags, - on_finish); -} - -template -void WriteLogCache::aio_write(Extents &&image_extents, - bufferlist&& bl, - int fadvise_flags, - Context *on_finish) { - m_write_log->write(std::move(image_extents), std::move(bl), - fadvise_flags, on_finish); -} - -template -void WriteLogCache::aio_discard(uint64_t offset, uint64_t length, - uint32_t discard_granularity_bytes, - Context *on_finish) { - m_write_log->discard(offset, length, discard_granularity_bytes, on_finish); -} - -template -void WriteLogCache::aio_flush(io::FlushSource flush_source, Context *on_finish) { - m_write_log->flush(flush_source, on_finish); -} - -template -void WriteLogCache::aio_writesame(uint64_t offset, uint64_t length, - bufferlist&& bl, int fadvise_flags, - Context *on_finish) { - m_write_log->writesame(offset, length, std::move(bl), fadvise_flags, - on_finish); -} - -template -void WriteLogCache::aio_compare_and_write(Extents &&image_extents, - bufferlist&& cmp_bl, - bufferlist&& bl, - uint64_t *mismatch_offset, - int fadvise_flags, - Context *on_finish) { - m_write_log->compare_and_write(std::move(image_extents), std::move(cmp_bl), - std::move(bl), mismatch_offset, fadvise_flags, - on_finish); -} - -template -void WriteLogCache::init(Context *on_finish) { - m_write_log->init(on_finish); -} - -template -void WriteLogCache::shut_down(Context *on_finish) { - m_write_log->shut_down(on_finish); -} - -template -void WriteLogCache::invalidate(Context *on_finish) { - m_write_log->invalidate(on_finish); -} - -template -void WriteLogCache::flush(Context *on_finish) { - m_write_log->flush(on_finish); -} - -} // namespace cache -} // namespace librbd - -template class librbd::cache::WriteLogCache; diff --git a/src/librbd/cache/WriteLogCache.h b/src/librbd/cache/WriteLogCache.h deleted file mode 100644 index 5a6bbdf4b41c..000000000000 --- a/src/librbd/cache/WriteLogCache.h +++ /dev/null @@ -1,63 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#ifndef CEPH_LIBRBD_CACHE_WRITE_LOG_CACHE -#define CEPH_LIBRBD_CACHE_WRITE_LOG_CACHE - -#include "librbd/cache/ImageCache.h" -#include "librbd/io/Types.h" - -namespace librbd { - -struct ImageCtx; - -namespace cache { - -namespace pwl { -template class AbstractWriteLog; -template class ImageCacheState; -} - -template -class WriteLogCache { -public: - typedef io::Extent Extent; - typedef io::Extents Extents; - - WriteLogCache(ImageCtxT &image_ctx, librbd::cache::pwl::ImageCacheState* cache_state); - ~WriteLogCache(); - WriteLogCache(const WriteLogCache&) = delete; - WriteLogCache &operator=(const WriteLogCache&) = delete; - - /// client AIO methods - void aio_read(Extents&& image_extents, ceph::bufferlist *bl, - int fadvise_flags, Context *on_finish) ; - void aio_write(Extents&& image_extents, ceph::bufferlist&& bl, - int fadvise_flags, Context *on_finish) ; - void aio_discard(uint64_t offset, uint64_t length, - uint32_t discard_granularity_bytes, - Context *on_finish) ; - void aio_flush(io::FlushSource flush_source, Context *on_finish) ; - void aio_writesame(uint64_t offset, uint64_t length, - ceph::bufferlist&& bl, - int fadvise_flags, Context *on_finish) ; - void aio_compare_and_write(Extents&& image_extents, - ceph::bufferlist&& cmp_bl, ceph::bufferlist&& bl, - uint64_t *mismatch_offset,int fadvise_flags, - Context *on_finish) ; - - /// internal state methods - void init(Context *on_finish) ; - void shut_down(Context *on_finish) ; - void invalidate(Context *on_finish) ; - void flush(Context *on_finish) ; - - librbd::cache::pwl::AbstractWriteLog *m_write_log; -}; - -} // namespace cache -} // namespace librbd - -extern template class librbd::cache::WriteLogCache; - -#endif // CEPH_LIBRBD_CACHE_WRITE_LOG_CACHE diff --git a/src/librbd/cache/pwl/ImageDispatch.cc b/src/librbd/cache/WriteLogImageDispatch.cc similarity index 82% rename from src/librbd/cache/pwl/ImageDispatch.cc rename to src/librbd/cache/WriteLogImageDispatch.cc index 14735411429d..254eb431f518 100644 --- a/src/librbd/cache/pwl/ImageDispatch.cc +++ b/src/librbd/cache/WriteLogImageDispatch.cc @@ -2,21 +2,20 @@ // vim: ts=8 sw=2 smarttab #include "common/dout.h" -#include "librbd/cache/pwl/ImageDispatch.h" +#include "librbd/cache/pwl/AbstractWriteLog.h" #include "librbd/cache/pwl/ShutdownRequest.h" -#include "librbd/cache/WriteLogCache.h" +#include "librbd/cache/WriteLogImageDispatch.h" #include "librbd/ImageCtx.h" #include "librbd/io/AioCompletion.h" #include "librbd/io/Utils.h" #define dout_subsys ceph_subsys_rbd_pwl #undef dout_prefix -#define dout_prefix *_dout << "librbd::cache::pwl::ImageDispatch: " << this << " " \ +#define dout_prefix *_dout << "librbd::cache::WriteLogImageDispatch: " << this << " " \ << __func__ << ": " namespace librbd { namespace cache { -namespace pwl{ namespace { @@ -29,7 +28,7 @@ void start_in_flight_io(io::AioCompletion* aio_comp) { } // anonymous namespace template -void ImageDispatch::shut_down(Context* on_finish) { +void WriteLogImageDispatch::shut_down(Context* on_finish) { ceph_assert(m_image_cache != nullptr); Context* ctx = new LambdaContext( @@ -44,7 +43,7 @@ void ImageDispatch::shut_down(Context* on_finish) { } template -bool ImageDispatch::read( +bool WriteLogImageDispatch::read( io::AioCompletion* aio_comp, io::Extents &&image_extents, io::ReadResult &&read_result, IOContext io_context, int op_flags, int read_flags, @@ -70,14 +69,14 @@ bool ImageDispatch::read( auto *req_comp = new io::ReadResult::C_ImageReadRequest( aio_comp, image_extents); - m_image_cache->aio_read(std::move(image_extents), - &req_comp->bl, op_flags, - req_comp); + m_image_cache->read(std::move(image_extents), + &req_comp->bl, op_flags, + req_comp); return true; } template -bool ImageDispatch::write( +bool WriteLogImageDispatch::write( io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl, IOContext io_context, int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid, std::atomic* image_dispatch_flags, @@ -95,13 +94,13 @@ bool ImageDispatch::write( aio_comp->set_request_count(1); io::C_AioRequest *req_comp = new io::C_AioRequest(aio_comp); - m_image_cache->aio_write(std::move(image_extents), - std::move(bl), op_flags, req_comp); + m_image_cache->write(std::move(image_extents), + std::move(bl), op_flags, req_comp); return true; } template -bool ImageDispatch::discard( +bool WriteLogImageDispatch::discard( io::AioCompletion* aio_comp, io::Extents &&image_extents, uint32_t discard_granularity_bytes, IOContext io_context, const ZTracer::Trace &parent_trace, @@ -121,15 +120,15 @@ bool ImageDispatch::discard( aio_comp->set_request_count(image_extents.size()); for (auto &extent : image_extents) { io::C_AioRequest *req_comp = new io::C_AioRequest(aio_comp); - m_image_cache->aio_discard(extent.first, extent.second, - discard_granularity_bytes, - req_comp); + m_image_cache->discard(extent.first, extent.second, + discard_granularity_bytes, + req_comp); } return true; } template -bool ImageDispatch::write_same( +bool WriteLogImageDispatch::write_same( io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl, IOContext io_context, int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid, @@ -149,15 +148,15 @@ bool ImageDispatch::write_same( aio_comp->set_request_count(image_extents.size()); for (auto &extent : image_extents) { io::C_AioRequest *req_comp = new io::C_AioRequest(aio_comp); - m_image_cache->aio_writesame(extent.first, extent.second, - std::move(bl), op_flags, - req_comp); + m_image_cache->writesame(extent.first, extent.second, + std::move(bl), op_flags, + req_comp); } return true; } template -bool ImageDispatch::compare_and_write( +bool WriteLogImageDispatch::compare_and_write( io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset, IOContext io_context, int op_flags, const ZTracer::Trace &parent_trace, uint64_t tid, @@ -176,14 +175,14 @@ bool ImageDispatch::compare_and_write( aio_comp->set_request_count(1); io::C_AioRequest *req_comp = new io::C_AioRequest(aio_comp); - m_image_cache->aio_compare_and_write( + m_image_cache->compare_and_write( std::move(image_extents), std::move(cmp_bl), std::move(bl), mismatch_offset, op_flags, req_comp); return true; } template -bool ImageDispatch::flush( +bool WriteLogImageDispatch::flush( io::AioCompletion* aio_comp, io::FlushSource flush_source, const ZTracer::Trace &parent_trace, uint64_t tid, std::atomic* image_dispatch_flags, @@ -198,13 +197,13 @@ bool ImageDispatch::flush( aio_comp->set_request_count(1); io::C_AioRequest *req_comp = new io::C_AioRequest(aio_comp); - m_image_cache->aio_flush(flush_source, req_comp); + m_image_cache->flush(flush_source, req_comp); return true; } template -bool ImageDispatch::list_snaps( +bool WriteLogImageDispatch::list_snaps( io::AioCompletion* aio_comp, io::Extents&& image_extents, io::SnapIds&& snap_ids, int list_snaps_flags, io::SnapshotDelta* snapshot_delta, @@ -212,12 +211,12 @@ bool ImageDispatch::list_snaps( std::atomic* image_dispatch_flags, io::DispatchResult* dispatch_result, Context** on_finish, Context* on_dispatched) { - ceph_abort(); + return false; } template -bool ImageDispatch::preprocess_length( +bool WriteLogImageDispatch::preprocess_length( io::AioCompletion* aio_comp, io::Extents &image_extents) const { auto total_bytes = io::util::extents_length(image_extents); if (total_bytes == 0) { @@ -227,8 +226,7 @@ bool ImageDispatch::preprocess_length( return false; } -} // namespace pwl } // namespace io } // namespace librbd -template class librbd::cache::pwl::ImageDispatch; +template class librbd::cache::WriteLogImageDispatch; diff --git a/src/librbd/cache/pwl/ImageDispatch.h b/src/librbd/cache/WriteLogImageDispatch.h similarity index 86% rename from src/librbd/cache/pwl/ImageDispatch.h rename to src/librbd/cache/WriteLogImageDispatch.h index 322aba4c1ac3..86d3f70afcd8 100644 --- a/src/librbd/cache/pwl/ImageDispatch.h +++ b/src/librbd/cache/WriteLogImageDispatch.h @@ -1,8 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#ifndef CEPH_LIBRBD_PWL_IMAGE_DISPATCH_H -#define CEPH_LIBRBD_PWL_IMAGE_DISPATCH_H +#ifndef CEPH_LIBRBD_WRITELOG_IMAGE_DISPATCH_H +#define CEPH_LIBRBD_WRITELOG_IMAGE_DISPATCH_H #include "librbd/io/ImageDispatchInterface.h" #include "include/int_types.h" @@ -19,16 +19,13 @@ struct ImageCtx; namespace cache { -template -class WriteLogCache; - -namespace pwl { +namespace pwl { template class AbstractWriteLog; } template -class ImageDispatch : public io::ImageDispatchInterface { +class WriteLogImageDispatch : public io::ImageDispatchInterface { public: - ImageDispatch(ImageCtxT* image_ctx, - WriteLogCache *image_cache) : + WriteLogImageDispatch(ImageCtxT* image_ctx, + pwl::AbstractWriteLog *image_cache) : m_image_ctx(image_ctx), m_image_cache(image_cache) { } @@ -91,16 +88,15 @@ public: private: ImageCtxT* m_image_ctx; - cache::WriteLogCache *m_image_cache; + pwl::AbstractWriteLog *m_image_cache; bool preprocess_length( io::AioCompletion* aio_comp, io::Extents &image_extents) const; }; -} // namespace pwl } // namespace cache } // namespace librbd -extern template class librbd::cache::pwl::ImageDispatch; +extern template class librbd::cache::WriteLogImageDispatch; -#endif // CEPH_LIBRBD_PWL_IMAGE_DISPATCH_H +#endif // CEPH_LIBRBD_WRITELOG_IMAGE_DISPATCH_H diff --git a/src/librbd/cache/pwl/AbstractWriteLog.h b/src/librbd/cache/pwl/AbstractWriteLog.h index 5796e1b9df38..c67870270513 100644 --- a/src/librbd/cache/pwl/AbstractWriteLog.h +++ b/src/librbd/cache/pwl/AbstractWriteLog.h @@ -7,7 +7,6 @@ #include "common/RWLock.h" #include "common/WorkQueue.h" #include "common/AsyncOpTracker.h" -#include "librbd/cache/ImageCache.h" #include "librbd/cache/ImageWriteback.h" #include "librbd/Utils.h" #include "librbd/BlockGuard.h" @@ -15,7 +14,6 @@ #include "librbd/cache/pwl/LogOperation.h" #include "librbd/cache/pwl/Request.h" #include "librbd/cache/pwl/LogMap.h" -#include "librbd/cache/pwl/Types.h" #include #include diff --git a/src/librbd/cache/pwl/InitRequest.cc b/src/librbd/cache/pwl/InitRequest.cc index 1df48cdf50c6..1f696d518bd3 100644 --- a/src/librbd/cache/pwl/InitRequest.cc +++ b/src/librbd/cache/pwl/InitRequest.cc @@ -10,8 +10,8 @@ #if defined(WITH_RBD_RWL) #include "librbd/cache/pwl/ImageCacheState.h" -#include "librbd/cache/pwl/ImageDispatch.h" -#include "librbd/cache/WriteLogCache.h" +#include "librbd/cache/pwl/ReplicatedWriteLog.h" +#include "librbd/cache/WriteLogImageDispatch.h" #endif // WITH_RBD_RWL #include "librbd/cache/Utils.h" @@ -78,8 +78,8 @@ void InitRequest::get_image_cache_state() { switch(cache_type) { case cache::IMAGE_CACHE_TYPE_RWL: m_image_cache = - new librbd::cache::WriteLogCache(m_image_ctx, - cache_state); + new librbd::cache::pwl::ReplicatedWriteLog(m_image_ctx, + cache_state); break; default: delete cache_state; @@ -161,7 +161,7 @@ void InitRequest::handle_set_feature_bit(int r) { } // Register RWL dispatch - auto image_dispatch = new cache::pwl::ImageDispatch(&m_image_ctx, m_image_cache); + auto image_dispatch = new cache::WriteLogImageDispatch(&m_image_ctx, m_image_cache); m_image_ctx.io_image_dispatcher->register_dispatch(image_dispatch); diff --git a/src/librbd/cache/pwl/InitRequest.h b/src/librbd/cache/pwl/InitRequest.h index 8030e17104c8..b1bda3eda1ca 100644 --- a/src/librbd/cache/pwl/InitRequest.h +++ b/src/librbd/cache/pwl/InitRequest.h @@ -14,11 +14,11 @@ namespace io { class ImageDispatchInterface; } namespace cache { -template -class WriteLogCache; - namespace pwl { +template +class AbstractWriteLog; + template class ImageCacheState; @@ -56,7 +56,7 @@ private: InitRequest(ImageCtxT &image_ctx, Context *on_finish); ImageCtxT &m_image_ctx; - cache::WriteLogCache *m_image_cache; + AbstractWriteLog *m_image_cache; Context *m_on_finish; int m_error_result; diff --git a/src/librbd/cache/pwl/ShutdownRequest.cc b/src/librbd/cache/pwl/ShutdownRequest.cc index 8af1cc2707d1..bb3c9520984e 100644 --- a/src/librbd/cache/pwl/ShutdownRequest.cc +++ b/src/librbd/cache/pwl/ShutdownRequest.cc @@ -2,7 +2,6 @@ // vim: ts=8 sw=2 smarttab #include "librbd/cache/pwl/ShutdownRequest.h" -#include "librbd/cache/WriteLogCache.h" #include "librbd/ImageCtx.h" #include "librbd/Utils.h" #include "common/dout.h" @@ -11,6 +10,9 @@ #include "librbd/asio/ContextWQ.h" #include "librbd/cache/Types.h" +#if defined(WITH_RBD_RWL) +#include "librbd/cache/pwl/AbstractWriteLog.h" +#endif // WITH_RBD_RWL #define dout_subsys ceph_subsys_rbd_pwl #undef dout_prefix @@ -27,7 +29,7 @@ using librbd::util::create_context_callback; template ShutdownRequest* ShutdownRequest::create( I &image_ctx, - cache::WriteLogCache *image_cache, + AbstractWriteLog *image_cache, Context *on_finish) { return new ShutdownRequest(image_ctx, image_cache, on_finish); } @@ -35,7 +37,7 @@ ShutdownRequest* ShutdownRequest::create( template ShutdownRequest::ShutdownRequest( I &image_ctx, - cache::WriteLogCache *image_cache, + AbstractWriteLog *image_cache, Context *on_finish) : m_image_ctx(image_ctx), m_image_cache(image_cache), @@ -45,9 +47,14 @@ ShutdownRequest::ShutdownRequest( template void ShutdownRequest::send() { +#if defined(WITH_RBD_RWL) send_shutdown_image_cache(); +#else + finish(); +#endif // WITH_RBD_RWL } +#if defined(WITH_RBD_RWL) template void ShutdownRequest::send_shutdown_image_cache() { CephContext *cct = m_image_ctx.cct; @@ -144,6 +151,8 @@ void ShutdownRequest::handle_remove_image_cache_state(int r) { finish(); } +#endif // WITH_RBD_RWL + template void ShutdownRequest::finish() { m_on_finish->complete(m_error_result); diff --git a/src/librbd/cache/pwl/ShutdownRequest.h b/src/librbd/cache/pwl/ShutdownRequest.h index ec8da976b0b0..2ed22f72782c 100644 --- a/src/librbd/cache/pwl/ShutdownRequest.h +++ b/src/librbd/cache/pwl/ShutdownRequest.h @@ -12,11 +12,11 @@ class ImageCtx; namespace cache { -template -class WriteLogCache; - namespace pwl { +template +class AbstractWriteLog; + template class ImageCacheState; @@ -25,7 +25,7 @@ class ShutdownRequest { public: static ShutdownRequest* create( ImageCtxT &image_ctx, - cache::WriteLogCache *image_cache, + AbstractWriteLog *image_cache, Context *on_finish); void send(); @@ -55,11 +55,11 @@ private: */ ShutdownRequest(ImageCtxT &image_ctx, - cache::WriteLogCache *image_cache, + AbstractWriteLog *image_cache, Context *on_finish); ImageCtxT &m_image_ctx; - cache::WriteLogCache *m_image_cache; + AbstractWriteLog *m_image_cache; Context *m_on_finish; int m_error_result; diff --git a/src/librbd/exclusive_lock/PreReleaseRequest.cc b/src/librbd/exclusive_lock/PreReleaseRequest.cc index 83799eb5a245..d6b2990237f8 100644 --- a/src/librbd/exclusive_lock/PreReleaseRequest.cc +++ b/src/librbd/exclusive_lock/PreReleaseRequest.cc @@ -5,7 +5,6 @@ #include "common/AsyncOpTracker.h" #include "common/dout.h" #include "common/errno.h" -#include "librbd/cache/pwl/ShutdownRequest.h" #include "librbd/ExclusiveLock.h" #include "librbd/ImageState.h" #include "librbd/ImageWatcher.h" diff --git a/src/test/librbd/cache/test_mock_ReplicatedWriteLog.cc b/src/test/librbd/cache/test_mock_ReplicatedWriteLog.cc index 6027b28a2074..5c650021e290 100644 --- a/src/test/librbd/cache/test_mock_ReplicatedWriteLog.cc +++ b/src/test/librbd/cache/test_mock_ReplicatedWriteLog.cc @@ -7,10 +7,10 @@ #include "test/librbd/test_support.h" #include "test/librbd/mock/MockImageCtx.h" #include "include/rbd/librbd.hpp" +#include "librbd/cache/pwl/AbstractWriteLog.h" #include "librbd/cache/pwl/ImageCacheState.h" #include "librbd/cache/pwl/Types.h" #include "librbd/cache/ImageWriteback.h" -#include "librbd/cache/WriteLogCache.h" namespace librbd { @@ -36,7 +36,6 @@ inline ImageCtx *get_image_ctx(MockImageCtx *image_ctx) { } // namespace util } // namespace librbd -#include "librbd/cache/WriteLogCache.cc" #include "librbd/cache/pwl/AbstractWriteLog.cc" #include "librbd/cache/pwl/ReplicatedWriteLog.cc" @@ -47,6 +46,7 @@ inline ImageCtx *get_image_ctx(MockImageCtx *image_ctx) { namespace librbd { namespace cache { +namespace pwl { using ::testing::_; using ::testing::DoDefault; @@ -54,7 +54,7 @@ using ::testing::InSequence; using ::testing::Invoke; struct TestMockCacheReplicatedWriteLog : public TestMockFixture { - typedef WriteLogCache MockReplicatedWriteLog; + typedef librbd::cache::pwl::ReplicatedWriteLog MockReplicatedWriteLog; typedef librbd::cache::pwl::ImageCacheState MockImageCacheStateRWL; MockImageCacheStateRWL *get_cache_state(MockImageCtx& mock_image_ctx) { @@ -192,7 +192,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, init_shutdown) { ASSERT_EQ(0, finish_ctx2.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_write) { +TEST_F(TestMockCacheReplicatedWriteLog, write) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -212,7 +212,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_write) { bufferlist bl; bl.append(std::string(4096, '1')); int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx3; @@ -242,7 +242,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, flush) { bl.append(std::string(4096, '1')); bufferlist bl_copy = bl; int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_flush; @@ -257,7 +257,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, flush) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_shutdown) { +TEST_F(TestMockCacheReplicatedWriteLog, flush_source_shutdown) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -277,12 +277,12 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_shutdown) { bufferlist bl; bl.append(std::string(4096, '1')); int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_flush; expect_context_complete(finish_ctx_flush, 0); - rwl.aio_flush(io::FLUSH_SOURCE_SHUTDOWN, &finish_ctx_flush); + rwl.flush(io::FLUSH_SOURCE_SHUTDOWN, &finish_ctx_flush); ASSERT_EQ(0, finish_ctx_flush.wait()); MockContextRWL finish_ctx3; @@ -291,7 +291,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_shutdown) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_internal) { +TEST_F(TestMockCacheReplicatedWriteLog, flush_source_internal) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -311,12 +311,12 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_internal) { bufferlist bl; bl.append(std::string(4096, '1')); int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_flush; expect_context_complete(finish_ctx_flush, 0); - rwl.aio_flush(io::FLUSH_SOURCE_INTERNAL, &finish_ctx_flush); + rwl.flush(io::FLUSH_SOURCE_INTERNAL, &finish_ctx_flush); ASSERT_EQ(0, finish_ctx_flush.wait()); MockContextRWL finish_ctx3; @@ -325,7 +325,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_internal) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_user) { +TEST_F(TestMockCacheReplicatedWriteLog, flush_source_user) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -345,13 +345,13 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_user) { bufferlist bl; bl.append(std::string(4096, '1')); int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); usleep(10000); MockContextRWL finish_ctx_flush; expect_context_complete(finish_ctx_flush, 0); - rwl.aio_flush(io::FLUSH_SOURCE_USER, &finish_ctx_flush); + rwl.flush(io::FLUSH_SOURCE_USER, &finish_ctx_flush); ASSERT_EQ(0, finish_ctx_flush.wait()); MockContextRWL finish_ctx3; @@ -360,7 +360,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_flush_source_user) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_read_hit_rwl_cache) { +TEST_F(TestMockCacheReplicatedWriteLog, read_hit_rwl_cache) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -381,14 +381,14 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_hit_rwl_cache) { bl.append(std::string(4096, '1')); bufferlist bl_copy = bl; int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_read; expect_context_complete(finish_ctx_read, 0); Extents image_extents_read{{0, 4096}}; bufferlist read_bl; - rwl.aio_read(std::move(image_extents_read), &read_bl, fadvise_flags, &finish_ctx_read); + rwl.read(std::move(image_extents_read), &read_bl, fadvise_flags, &finish_ctx_read); ASSERT_EQ(0, finish_ctx_read.wait()); ASSERT_EQ(4096, read_bl.length()); ASSERT_TRUE(bl_copy.contents_equal(read_bl)); @@ -399,7 +399,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_hit_rwl_cache) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_read_hit_part_rwl_cache) { +TEST_F(TestMockCacheReplicatedWriteLog, read_hit_part_rwl_cache) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -420,7 +420,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_hit_part_rwl_cache) { bl.append(std::string(4096, '1')); bufferlist bl_copy = bl; int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_read; @@ -429,7 +429,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_hit_part_rwl_cache) { bl_copy.begin(511).copy(4096-512, hit_bl); expect_context_complete(finish_ctx_read, 512); bufferlist read_bl; - rwl.aio_read(std::move(image_extents_read), &read_bl, fadvise_flags, &finish_ctx_read); + rwl.read(std::move(image_extents_read), &read_bl, fadvise_flags, &finish_ctx_read); ASSERT_EQ(512, finish_ctx_read.wait()); ASSERT_EQ(4096, read_bl.length()); bufferlist read_bl_hit; @@ -442,7 +442,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_hit_part_rwl_cache) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_read_miss_rwl_cache) { +TEST_F(TestMockCacheReplicatedWriteLog, read_miss_rwl_cache) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -462,7 +462,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_miss_rwl_cache) { bufferlist bl; bl.append(std::string(4096, '1')); int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_read; @@ -470,7 +470,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_miss_rwl_cache) { expect_context_complete(finish_ctx_read, 4096); bufferlist read_bl; ASSERT_EQ(0, read_bl.length()); - rwl.aio_read(std::move(image_extents_read), &read_bl, fadvise_flags, &finish_ctx_read); + rwl.read(std::move(image_extents_read), &read_bl, fadvise_flags, &finish_ctx_read); ASSERT_EQ(4096, finish_ctx_read.wait()); ASSERT_EQ(4096, read_bl.length()); @@ -480,7 +480,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_read_miss_rwl_cache) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_discard) { +TEST_F(TestMockCacheReplicatedWriteLog, discard) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -501,18 +501,18 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_discard) { bl.append(std::string(4096, '1')); bufferlist bl_copy = bl; int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_discard; expect_context_complete(finish_ctx_discard, 0); - rwl.aio_discard(0, 4096, 1, &finish_ctx_discard); + rwl.discard(0, 4096, 1, &finish_ctx_discard); ASSERT_EQ(0, finish_ctx_discard.wait()); MockContextRWL finish_ctx_read; bufferlist read_bl; expect_context_complete(finish_ctx_read, 0); - rwl.aio_read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); + rwl.read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); ASSERT_EQ(0, finish_ctx_read.wait()); ASSERT_EQ(4096, read_bl.length()); ASSERT_TRUE(read_bl.is_zero()); @@ -524,7 +524,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_discard) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_writesame) { +TEST_F(TestMockCacheReplicatedWriteLog, writesame) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -544,13 +544,13 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_writesame) { bl.append(std::string(512, '1')); test_bl.append(std::string(4096, '1')); int fadvise_flags = 0; - rwl.aio_writesame(0, 4096, std::move(bl), fadvise_flags, &finish_ctx2); + rwl.writesame(0, 4096, std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_read; bufferlist read_bl; expect_context_complete(finish_ctx_read, 0); - rwl.aio_read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); + rwl.read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); ASSERT_EQ(0, finish_ctx_read.wait()); ASSERT_EQ(4096, read_bl.length()); ASSERT_TRUE(test_bl.contents_equal(read_bl)); @@ -583,7 +583,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, invalidate) { bl.append(std::string(4096, '1')); bufferlist bl_copy = bl; int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_invalidate; @@ -598,7 +598,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, invalidate) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_matched) { +TEST_F(TestMockCacheReplicatedWriteLog, compare_and_write_compare_matched) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -619,7 +619,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_matched) { bl1.append(std::string(4096, '1')); bufferlist com_bl = bl1; int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl1), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl1), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_cw; @@ -628,7 +628,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_matched) { bufferlist bl2_copy = bl2; uint64_t mismatch_offset = -1; expect_context_complete(finish_ctx_cw, 0); - rwl.aio_compare_and_write({{0, 4096}}, std::move(com_bl), std::move(bl2), + rwl.compare_and_write({{0, 4096}}, std::move(com_bl), std::move(bl2), &mismatch_offset, fadvise_flags, &finish_ctx_cw); ASSERT_EQ(0, finish_ctx_cw.wait()); ASSERT_EQ(0, mismatch_offset); @@ -636,7 +636,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_matched) { MockContextRWL finish_ctx_read; bufferlist read_bl; expect_context_complete(finish_ctx_read, 0); - rwl.aio_read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); + rwl.read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); ASSERT_EQ(0, finish_ctx_read.wait()); ASSERT_EQ(4096, read_bl.length()); ASSERT_TRUE(bl2_copy.contents_equal(read_bl)); @@ -648,7 +648,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_matched) { ASSERT_EQ(0, finish_ctx3.wait()); } -TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_failed) { +TEST_F(TestMockCacheReplicatedWriteLog, compare_and_write_compare_failed) { librbd::ImageCtx *ictx; ASSERT_EQ(0, open_image(m_image_name, &ictx)); @@ -669,7 +669,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_failed) { bl1.append(std::string(4096, '1')); bufferlist bl1_copy = bl1; int fadvise_flags = 0; - rwl.aio_write(std::move(image_extents), std::move(bl1), fadvise_flags, &finish_ctx2); + rwl.write(std::move(image_extents), std::move(bl1), fadvise_flags, &finish_ctx2); ASSERT_EQ(0, finish_ctx2.wait()); MockContextRWL finish_ctx_cw; @@ -678,7 +678,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_failed) { bufferlist com_bl = bl2; uint64_t mismatch_offset = -1; expect_context_complete(finish_ctx_cw, -EILSEQ); - rwl.aio_compare_and_write({{0, 4096}}, std::move(com_bl), std::move(bl2), + rwl.compare_and_write({{0, 4096}}, std::move(com_bl), std::move(bl2), &mismatch_offset, fadvise_flags, &finish_ctx_cw); ASSERT_EQ(-EILSEQ, finish_ctx_cw.wait()); ASSERT_EQ(0, mismatch_offset); @@ -686,7 +686,7 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_failed) { MockContextRWL finish_ctx_read; bufferlist read_bl; expect_context_complete(finish_ctx_read, 0); - rwl.aio_read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); + rwl.read({{0, 4096}}, &read_bl, fadvise_flags, &finish_ctx_read); ASSERT_EQ(0, finish_ctx_read.wait()); ASSERT_EQ(4096, read_bl.length()); ASSERT_TRUE(bl1_copy.contents_equal(read_bl)); @@ -697,5 +697,6 @@ TEST_F(TestMockCacheReplicatedWriteLog, aio_compare_and_write_compare_failed) { ASSERT_EQ(0, finish_ctx3.wait()); } +} // namespace pwl } // namespace cache } // namespace librbd -- 2.47.3