]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
tools: create local utils for object cache daemon
authorYuan Zhou <yuan.zhou@intel.com>
Thu, 20 Dec 2018 10:30:19 +0000 (18:30 +0800)
committerYuan Zhou <yuan.zhou@intel.com>
Thu, 21 Mar 2019 16:16:25 +0000 (00:16 +0800)
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
src/tools/immutable_object_cache/CMakeLists.txt
src/tools/immutable_object_cache/ObjectCacheFile.cc
src/tools/immutable_object_cache/ObjectCacheStore.cc
src/tools/immutable_object_cache/Utils.cc [new file with mode: 0644]
src/tools/immutable_object_cache/Utils.h [new file with mode: 0644]

index cf0decf6962c52a28f643cfe53e49f5eb397b725..4358b90216a9bcc433b7afaaab5760fa984ae078 100644 (file)
@@ -5,7 +5,9 @@ set(ceph_immutable_object_cache_files
   CacheServer.cc
   CacheClient.cc
   CacheSession.cc
-  SimplePolicy.cc)
+  SimplePolicy.cc
+  Utils.cc
+  )
 add_library(ceph_immutable_object_cache_lib STATIC ${ceph_immutable_object_cache_files})
 
 add_executable(ceph-immutable-object-cache
@@ -15,6 +17,7 @@ add_executable(ceph-immutable-object-cache
   CacheServer.cc
   CacheSession.cc
   SimplePolicy.cc
+  Utils.cc
   main.cc)
 target_link_libraries(ceph-immutable-object-cache
   librados-cxx
index 538a59edc537a12087a3ab508b5b1b91d88e7d46..750a2249e0c6ba8bc28a3efb5d395ae6313dfea0 100644 (file)
@@ -5,7 +5,6 @@
 #include "include/Context.h"
 #include "common/dout.h"
 #include "common/WorkQueue.h"
-#include "librbd/ImageCtx.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <aio.h>
index 83ad6ad53b039da05db1a2b40629979a77d40772..7894266bdfdc18e184f903248826a174ceb28827 100644 (file)
@@ -1,9 +1,9 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
+#include "include/Context.h"
 #include "ObjectCacheStore.h"
-#include "librbd/Utils.h"
-
+#include "Utils.h"
 #include <experimental/filesystem>
 
 #define dout_context g_ceph_context
@@ -217,10 +217,10 @@ int ObjectCacheStore::promote_object(librados::IoCtx* ioctx, std::string object_
     on_finish->complete(ret);
   });
 
-  librados::AioCompletion* read_completion = librbd::util::create_rados_callback(ctx);
+  librados::AioCompletion* read_completion = create_rados_callback(ctx);
   int ret = ioctx->aio_read(object_name, read_completion, read_buf, read_len, 0);
   if(ret < 0) {
-    lderr(m_cct) << "fail to read from rados" << dendl;
+    lderr(m_cct) << "failed to read from rados" << dendl;
   }
   read_completion->release();
 
diff --git a/src/tools/immutable_object_cache/Utils.cc b/src/tools/immutable_object_cache/Utils.cc
new file mode 100644 (file)
index 0000000..28b9b0b
--- /dev/null
@@ -0,0 +1,18 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "Utils.h"
+
+#define dout_subsys ceph_subsys_immutable_obj_cache
+#undef dout_prefix
+#define dout_prefix *_dout << "ceph::cache::Utils: " << __func__ << ": "
+
+namespace ceph {
+namespace immutable_obj_cache {
+
+librados::AioCompletion *create_rados_callback(Context *on_finish) {
+  return create_rados_callback<Context, &Context::complete>(on_finish);
+}
+
+} // namespace immutable_obj_cache
+} // namespace ceph
diff --git a/src/tools/immutable_object_cache/Utils.h b/src/tools/immutable_object_cache/Utils.h
new file mode 100644 (file)
index 0000000..d3fb8d9
--- /dev/null
@@ -0,0 +1,113 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef CEPH_CACHE_UTILS_H
+#define CEPH_CACHE_UTILS_H
+
+#include "include/rados/librados.hpp"
+#include "include/Context.h"
+
+
+namespace ceph {
+namespace immutable_obj_cache {
+namespace detail {
+
+template <typename T>
+void rados_callback(rados_completion_t c, void *arg) {
+  reinterpret_cast<T*>(arg)->complete(rados_aio_get_return_value(c));
+}
+
+template <typename T, void(T::*MF)(int)>
+void rados_callback(rados_completion_t c, void *arg) {
+  T *obj = reinterpret_cast<T*>(arg);
+  int r = rados_aio_get_return_value(c);
+  (obj->*MF)(r);
+}
+
+template <typename T, Context*(T::*MF)(int*), bool destroy>
+void rados_state_callback(rados_completion_t c, void *arg) {
+  T *obj = reinterpret_cast<T*>(arg);
+  int r = rados_aio_get_return_value(c);
+  Context *on_finish = (obj->*MF)(&r);
+  if (on_finish != nullptr) {
+    on_finish->complete(r);
+    if (destroy) {
+      delete obj;
+    }
+  }
+}
+
+template <typename T, void (T::*MF)(int)>
+class C_CallbackAdapter : public Context {
+  T *obj;
+public:
+  C_CallbackAdapter(T *obj) : obj(obj) {
+  }
+
+protected:
+  void finish(int r) override {
+    (obj->*MF)(r);
+  }
+};
+
+template <typename T, Context*(T::*MF)(int*), bool destroy>
+class C_StateCallbackAdapter : public Context {
+  T *obj;
+public:
+  C_StateCallbackAdapter(T *obj) : obj(obj){
+  }
+
+protected:
+  void complete(int r) override {
+    Context *on_finish = (obj->*MF)(&r);
+    if (on_finish != nullptr) {
+      on_finish->complete(r);
+      if (destroy) {
+        delete obj;
+      }
+    }
+    Context::complete(r);
+  }
+  void finish(int r) override {
+  }
+};
+
+template <typename WQ>
+struct C_AsyncCallback : public Context {
+  WQ *op_work_queue;
+  Context *on_finish;
+
+  C_AsyncCallback(WQ *op_work_queue, Context *on_finish)
+    : op_work_queue(op_work_queue), on_finish(on_finish) {
+  }
+  void finish(int r) override {
+    op_work_queue->queue(on_finish, r);
+  }
+};
+
+} // namespace detail
+
+
+librados::AioCompletion *create_rados_callback(Context *on_finish);
+
+template <typename T>
+librados::AioCompletion *create_rados_callback(T *obj) {
+  return librados::Rados::aio_create_completion(
+    obj, &detail::rados_callback<T>, nullptr);
+}
+
+template <typename T, void(T::*MF)(int)>
+librados::AioCompletion *create_rados_callback(T *obj) {
+  return librados::Rados::aio_create_completion(
+    obj, &detail::rados_callback<T, MF>, nullptr);
+}
+
+template <typename T, Context*(T::*MF)(int*), bool destroy=true>
+librados::AioCompletion *create_rados_callback(T *obj) {
+  return librados::Rados::aio_create_completion(
+    obj, &detail::rados_state_callback<T, MF, destroy>, nullptr);
+}
+
+} // namespace immutable_obj_cache
+} // namespace ceph
+#endif