From dbc498f210dfe202423a20312fee761bf65b038b Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 12 May 2016 14:25:26 -0400 Subject: [PATCH] librbd: skeleton implementation of client-side image cache Signed-off-by: Jason Dillaman --- src/librbd/CMakeLists.txt | 2 + src/librbd/Makefile.am | 5 ++ src/librbd/cache/ImageCache.h | 46 ++++++++++ src/librbd/cache/ImageWriteback.cc | 65 ++++++++++++++ src/librbd/cache/ImageWriteback.h | 46 ++++++++++ src/librbd/cache/PassthroughImageCache.cc | 103 ++++++++++++++++++++++ src/librbd/cache/PassthroughImageCache.h | 51 +++++++++++ 7 files changed, 318 insertions(+) create mode 100644 src/librbd/cache/ImageCache.h create mode 100644 src/librbd/cache/ImageWriteback.cc create mode 100644 src/librbd/cache/ImageWriteback.h create mode 100644 src/librbd/cache/PassthroughImageCache.cc create mode 100644 src/librbd/cache/PassthroughImageCache.h diff --git a/src/librbd/CMakeLists.txt b/src/librbd/CMakeLists.txt index 1eaa652c974da..aa80fc58c6701 100644 --- a/src/librbd/CMakeLists.txt +++ b/src/librbd/CMakeLists.txt @@ -26,6 +26,8 @@ set(librbd_internal_srcs ObjectWatcher.cc Operations.cc Utils.cc + cache/ImageWriteback.cc + cache/PassthroughImageCache.cc exclusive_lock/AcquireRequest.cc exclusive_lock/ReacquireRequest.cc exclusive_lock/ReleaseRequest.cc diff --git a/src/librbd/Makefile.am b/src/librbd/Makefile.am index 271d1236bbc46..0067acf2596a8 100644 --- a/src/librbd/Makefile.am +++ b/src/librbd/Makefile.am @@ -31,6 +31,8 @@ librbd_internal_la_SOURCES = \ librbd/ObjectWatcher.cc \ librbd/Operations.cc \ librbd/Utils.cc \ + librbd/cache/ImageWriteback.cc \ + librbd/cache/PassthroughImageCache.cc \ librbd/exclusive_lock/AcquireRequest.cc \ librbd/exclusive_lock/ReacquireRequest.cc \ librbd/exclusive_lock/ReleaseRequest.cc \ @@ -123,6 +125,9 @@ noinst_HEADERS += \ librbd/TaskFinisher.h \ librbd/Utils.h \ librbd/WatchNotifyTypes.h \ + librbd/cache/ImageCache.h \ + librbd/cache/ImageWriteback.h \ + librbd/cache/PassthroughImageCache.h \ librbd/exclusive_lock/AcquireRequest.h \ librbd/exclusive_lock/Policy.h \ librbd/exclusive_lock/ReacquireRequest.h \ diff --git a/src/librbd/cache/ImageCache.h b/src/librbd/cache/ImageCache.h new file mode 100644 index 0000000000000..859993b0ff993 --- /dev/null +++ b/src/librbd/cache/ImageCache.h @@ -0,0 +1,46 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_CACHE_IMAGE_CACHE +#define CEPH_LIBRBD_CACHE_IMAGE_CACHE + +#include "include/buffer_fwd.h" +#include "include/int_types.h" +#include + +class Context; + +namespace librbd { +namespace cache { + +/** + * client-side, image extent cache interface + */ +struct ImageCache { + typedef std::vector > Extents; + + virtual ~ImageCache() { + } + + /// client AIO methods + virtual void aio_read(Extents&& image_extents, ceph::bufferlist* bl, + int fadvise_flags, Context *on_finish) = 0; + virtual void aio_write(Extents&& image_extents, ceph::bufferlist&& bl, + int fadvise_flags, Context *on_finish) = 0; + virtual void aio_discard(uint64_t offset, uint64_t length, + Context *on_finish) = 0; + virtual void aio_flush(Context *on_finish) = 0; + + /// internal state methods + virtual void init(Context *on_finish) = 0; + virtual void shut_down(Context *on_finish) = 0; + + virtual void invalidate(Context *on_finish) = 0; + virtual void flush(Context *on_finish) = 0; + +}; + +} // namespace cache +} // namespace librbd + +#endif // CEPH_LIBRBD_CACHE_IMAGE_CACHE diff --git a/src/librbd/cache/ImageWriteback.cc b/src/librbd/cache/ImageWriteback.cc new file mode 100644 index 0000000000000..2bef71418e1dc --- /dev/null +++ b/src/librbd/cache/ImageWriteback.cc @@ -0,0 +1,65 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "ImageWriteback.h" +#include "include/buffer.h" +#include "common/dout.h" +#include "librbd/AioImageRequest.h" +#include "librbd/ImageCtx.h" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::ImageWriteback: " << __func__ << ": " + +namespace librbd { +namespace cache { + +template +ImageWriteback::ImageWriteback(I &image_ctx) : m_image_ctx(image_ctx) { +} + +template +void ImageWriteback::aio_read(Extents &&image_extents, bufferlist *bl, + int fadvise_flags, Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "image_extents=" << image_extents << ", " + << "on_finish=" << on_finish << dendl; + + // TODO +} + +template +void ImageWriteback::aio_write(Extents &&image_extents, + ceph::bufferlist&& bl, + int fadvise_flags, Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "image_extents=" << image_extents << ", " + << "on_finish=" << on_finish << dendl; + + // TODO +} + +template +void ImageWriteback::aio_discard(uint64_t offset, uint64_t length, + Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "offset=" << offset << ", " + << "length=" << length << ", " + << "on_finish=" << on_finish << dendl; + + // TODO +} + +template +void ImageWriteback::aio_flush(Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "on_finish=" << on_finish << dendl; + + // TODO +} + +} // namespace cache +} // namespace librbd + +template class librbd::cache::ImageWriteback; + diff --git a/src/librbd/cache/ImageWriteback.h b/src/librbd/cache/ImageWriteback.h new file mode 100644 index 0000000000000..c3737800ecbf0 --- /dev/null +++ b/src/librbd/cache/ImageWriteback.h @@ -0,0 +1,46 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_CACHE_IMAGE_WRITEBACK +#define CEPH_LIBRBD_CACHE_IMAGE_WRITEBACK + +#include "include/buffer_fwd.h" +#include "include/int_types.h" +#include + +class Context; + +namespace librbd { + +struct ImageCtx; + +namespace cache { + +/** + * client-side, image extent cache writeback handler + */ +template +class ImageWriteback { +public: + typedef std::vector > Extents; + + ImageWriteback(ImageCtxT &image_ctx); + + 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, Context *on_finish); + void aio_flush(Context *on_finish); + +private: + ImageCtxT &m_image_ctx; + +}; + +} // namespace cache +} // namespace librbd + +extern template class librbd::cache::ImageWriteback; + +#endif // CEPH_LIBRBD_CACHE_IMAGE_WRITEBACK diff --git a/src/librbd/cache/PassthroughImageCache.cc b/src/librbd/cache/PassthroughImageCache.cc new file mode 100644 index 0000000000000..0ad2f4ef87790 --- /dev/null +++ b/src/librbd/cache/PassthroughImageCache.cc @@ -0,0 +1,103 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "PassthroughImageCache.h" +#include "include/buffer.h" +#include "common/dout.h" +#include "librbd/ImageCtx.h" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::PassthroughImageCache: " << this << " " \ + << __func__ << ": " + +namespace librbd { +namespace cache { + +template +PassthroughImageCache::PassthroughImageCache(ImageCtx &image_ctx) + : m_image_ctx(image_ctx), m_image_writeback(image_ctx) { +} + +template +void PassthroughImageCache::aio_read(Extents &&image_extents, bufferlist *bl, + int fadvise_flags, Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "image_extents=" << image_extents << ", " + << "on_finish=" << on_finish << dendl; + + m_image_writeback.aio_read(std::move(image_extents), bl, fadvise_flags, + on_finish); +} + +template +void PassthroughImageCache::aio_write(Extents &&image_extents, + bufferlist&& bl, + int fadvise_flags, + Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "image_extents=" << image_extents << ", " + << "on_finish=" << on_finish << dendl; + + m_image_writeback.aio_write(std::move(image_extents), std::move(bl), + fadvise_flags, on_finish); +} + +template +void PassthroughImageCache::aio_discard(uint64_t offset, uint64_t length, + Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "offset=" << offset << ", " + << "length=" << length << ", " + << "on_finish=" << on_finish << dendl; + + m_image_writeback.aio_discard(offset, length, on_finish); +} + +template +void PassthroughImageCache::aio_flush(Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << "on_finish=" << on_finish << dendl; + + m_image_writeback.aio_flush(on_finish); +} + +template +void PassthroughImageCache::init(Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << dendl; + + on_finish->complete(0); +} + +template +void PassthroughImageCache::shut_down(Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << dendl; + + on_finish->complete(0); +} + +template +void PassthroughImageCache::invalidate(Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << dendl; + + // dump cache contents (don't have anything) + on_finish->complete(0); +} + +template +void PassthroughImageCache::flush(Context *on_finish) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 20) << dendl; + + // internal flush -- nothing to writeback but make sure + // in-flight IO is flushed + aio_flush(on_finish); +} + +} // namespace cache +} // namespace librbd + +template class librbd::cache::PassthroughImageCache; diff --git a/src/librbd/cache/PassthroughImageCache.h b/src/librbd/cache/PassthroughImageCache.h new file mode 100644 index 0000000000000..aa4ceba69c473 --- /dev/null +++ b/src/librbd/cache/PassthroughImageCache.h @@ -0,0 +1,51 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_CACHE_PASSTHROUGH_IMAGE_CACHE +#define CEPH_LIBRBD_CACHE_PASSTHROUGH_IMAGE_CACHE + +#include "ImageCache.h" +#include "ImageWriteback.h" + +namespace librbd { + +struct ImageCtx; + +namespace cache { + +/** + * Example passthrough client-side, image extent cache + */ +template +class PassthroughImageCache : public ImageCache { +public: + PassthroughImageCache(ImageCtx &image_ctx); + + /// client AIO methods + virtual void aio_read(Extents&& image_extents, ceph::bufferlist *bl, + int fadvise_flags, Context *on_finish); + virtual void aio_write(Extents&& image_extents, ceph::bufferlist&& bl, + int fadvise_flags, Context *on_finish); + virtual void aio_discard(uint64_t offset, uint64_t length, + Context *on_finish); + virtual void aio_flush(Context *on_finish); + + /// internal state methods + virtual void init(Context *on_finish); + virtual void shut_down(Context *on_finish); + + virtual void invalidate(Context *on_finish); + virtual void flush(Context *on_finish); + +private: + ImageCtxT &m_image_ctx; + ImageWriteback m_image_writeback; + +}; + +} // namespace cache +} // namespace librbd + +extern template class librbd::cache::PassthroughImageCache; + +#endif // CEPH_LIBRBD_CACHE_PASSTHROUGH_IMAGE_CACHE -- 2.39.5