]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: skeleton implementation of client-side image cache
authorJason Dillaman <dillaman@redhat.com>
Thu, 12 May 2016 18:25:26 +0000 (14:25 -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/CMakeLists.txt
src/librbd/Makefile.am
src/librbd/cache/ImageCache.h [new file with mode: 0644]
src/librbd/cache/ImageWriteback.cc [new file with mode: 0644]
src/librbd/cache/ImageWriteback.h [new file with mode: 0644]
src/librbd/cache/PassthroughImageCache.cc [new file with mode: 0644]
src/librbd/cache/PassthroughImageCache.h [new file with mode: 0644]

index 1eaa652c974daf5c95d3d72b18fa7061a4982c8f..aa80fc58c670133e3d2520ddfe8dab4fc21bb8f3 100644 (file)
@@ -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
index 271d1236bbc466b4062f2c8dc62c39b4f39240d0..0067acf2596a8ce719e317e4973a4e3e6d0da110 100644 (file)
@@ -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 (file)
index 0000000..859993b
--- /dev/null
@@ -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 <vector>
+
+class Context;
+
+namespace librbd {
+namespace cache {
+
+/**
+ * client-side, image extent cache interface
+ */
+struct ImageCache {
+  typedef std::vector<std::pair<uint64_t,uint64_t> > 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 (file)
index 0000000..2bef714
--- /dev/null
@@ -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 <typename I>
+ImageWriteback<I>::ImageWriteback(I &image_ctx) : m_image_ctx(image_ctx) {
+}
+
+template <typename I>
+void ImageWriteback<I>::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 <typename I>
+void ImageWriteback<I>::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 <typename I>
+void ImageWriteback<I>::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 <typename I>
+void ImageWriteback<I>::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<librbd::ImageCtx>;
+
diff --git a/src/librbd/cache/ImageWriteback.h b/src/librbd/cache/ImageWriteback.h
new file mode 100644 (file)
index 0000000..c373780
--- /dev/null
@@ -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 <vector>
+
+class Context;
+
+namespace librbd {
+
+struct ImageCtx;
+
+namespace cache {
+
+/**
+ * client-side, image extent cache writeback handler
+ */
+template <typename ImageCtxT = librbd::ImageCtx>
+class ImageWriteback {
+public:
+  typedef std::vector<std::pair<uint64_t,uint64_t> > 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<librbd::ImageCtx>;
+
+#endif // CEPH_LIBRBD_CACHE_IMAGE_WRITEBACK
diff --git a/src/librbd/cache/PassthroughImageCache.cc b/src/librbd/cache/PassthroughImageCache.cc
new file mode 100644 (file)
index 0000000..0ad2f4e
--- /dev/null
@@ -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 <typename I>
+PassthroughImageCache<I>::PassthroughImageCache(ImageCtx &image_ctx)
+  : m_image_ctx(image_ctx), m_image_writeback(image_ctx) {
+}
+
+template <typename I>
+void PassthroughImageCache<I>::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 <typename I>
+void PassthroughImageCache<I>::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 <typename I>
+void PassthroughImageCache<I>::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 <typename I>
+void PassthroughImageCache<I>::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 <typename I>
+void PassthroughImageCache<I>::init(Context *on_finish) {
+  CephContext *cct = m_image_ctx.cct;
+  ldout(cct, 20) << dendl;
+
+  on_finish->complete(0);
+}
+
+template <typename I>
+void PassthroughImageCache<I>::shut_down(Context *on_finish) {
+  CephContext *cct = m_image_ctx.cct;
+  ldout(cct, 20) << dendl;
+
+  on_finish->complete(0);
+}
+
+template <typename I>
+void PassthroughImageCache<I>::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 <typename I>
+void PassthroughImageCache<I>::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<librbd::ImageCtx>;
diff --git a/src/librbd/cache/PassthroughImageCache.h b/src/librbd/cache/PassthroughImageCache.h
new file mode 100644 (file)
index 0000000..aa4ceba
--- /dev/null
@@ -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 <typename ImageCtxT = librbd::ImageCtx>
+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<ImageCtxT> m_image_writeback;
+
+};
+
+} // namespace cache
+} // namespace librbd
+
+extern template class librbd::cache::PassthroughImageCache<librbd::ImageCtx>;
+
+#endif // CEPH_LIBRBD_CACHE_PASSTHROUGH_IMAGE_CACHE