#undef dout_prefix
#define dout_prefix *_dout << "librbd::cache::SharedReadOnlyObjectDispatch: " \
<< this << " " << __func__ << ": "
-using namespace ceph::immutable_obj_cache;
namespace librbd {
namespace cache {
-template <typename I>
-SharedReadOnlyObjectDispatch<I>::SharedReadOnlyObjectDispatch(
- I* image_ctx) : m_image_ctx(image_ctx) {
+template <typename I, typename C>
+SharedReadOnlyObjectDispatch<I, C>::SharedReadOnlyObjectDispatch(
+ I* image_ctx) : m_image_ctx(image_ctx), m_cache_client(nullptr),
+ m_initialzed(false) {
}
-template <typename I>
-SharedReadOnlyObjectDispatch<I>::~SharedReadOnlyObjectDispatch() {
+template <typename I, typename C>
+SharedReadOnlyObjectDispatch<I, C>::~SharedReadOnlyObjectDispatch() {
delete m_object_store;
delete m_cache_client;
}
// TODO if connect fails, init will return error to high layer.
-template <typename I>
-void SharedReadOnlyObjectDispatch<I>::init() {
+template <typename I, typename C>
+void SharedReadOnlyObjectDispatch<I, C>::init() {
auto cct = m_image_ctx->cct;
ldout(cct, 5) << dendl;
ldout(cct, 5) << "parent image: setup SRO cache client" << dendl;
std::string controller_path = ((CephContext*)cct)->_conf.get_val<std::string>("immutable_object_cache_sock");
- m_cache_client = new ceph::immutable_obj_cache::CacheClient(controller_path.c_str(), m_image_ctx->cct);
+ if(m_cache_client == nullptr) {
+ m_cache_client = new C(controller_path.c_str(), m_image_ctx->cct);
+ }
m_cache_client->run();
int ret = m_cache_client->connect();
auto ctx = new FunctionContext([this](bool reg) {
handle_register_client(reg);
});
+
ret = m_cache_client->register_client(ctx);
if (ret >= 0) {
// add ourself to the IO object dispatcher chain
m_image_ctx->io_object_dispatcher->register_object_dispatch(this);
+ m_initialzed = true;
}
}
}
-template <typename I>
-bool SharedReadOnlyObjectDispatch<I>::read(
+template <typename I, typename C>
+bool SharedReadOnlyObjectDispatch<I, C>::read(
const std::string &oid, uint64_t object_no, uint64_t object_off,
uint64_t object_len, librados::snap_t snap_id, int op_flags,
const ZTracer::Trace &parent_trace, ceph::bufferlist* read_data,
return true;
}
-template <typename I>
-int SharedReadOnlyObjectDispatch<I>::handle_read_cache(
+template <typename I, typename C>
+int SharedReadOnlyObjectDispatch<I, C>::handle_read_cache(
const std::string file_path, uint64_t read_off,
uint64_t read_len, ceph::bufferlist* read_data,
io::DispatchResult* dispatch_result, Context* on_dispatched) {
return false;
}
-template <typename I>
-int SharedReadOnlyObjectDispatch<I>::handle_register_client(bool reg) {
+template <typename I, typename C>
+int SharedReadOnlyObjectDispatch<I, C>::handle_register_client(bool reg) {
auto cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
return 0;
}
-template <typename I>
-void SharedReadOnlyObjectDispatch<I>::client_handle_request(std::string msg) {
+template <typename I, typename C>
+void SharedReadOnlyObjectDispatch<I, C>::client_handle_request(std::string msg) {
auto cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
} // namespace cache
} // namespace librbd
-template class librbd::cache::SharedReadOnlyObjectDispatch<librbd::ImageCtx>;
+template class librbd::cache::SharedReadOnlyObjectDispatch<librbd::ImageCtx, ceph::immutable_obj_cache::CacheClient>;
#include "tools/immutable_object_cache/CacheClient.h"
#include "tools/immutable_object_cache/Types.h"
+using namespace ceph::immutable_obj_cache;
namespace librbd {
namespace cache {
-template <typename ImageCtxT = ImageCtx>
+template <typename ImageCtxT = ImageCtx, typename CacheClientT = CacheClient>
class SharedReadOnlyObjectDispatch : public io::ObjectDispatchInterface {
public:
static SharedReadOnlyObjectDispatch* create(ImageCtxT* image_ctx) {
uint64_t journal_tid, uint64_t new_journal_tid) {
}
+ bool get_state() {
+ return m_initialzed;
+ }
+
+ CacheClientT *m_cache_client = nullptr;
+ ImageCtxT* m_image_ctx;
+
private:
int handle_read_cache(
int handle_register_client(bool reg);
void client_handle_request(std::string msg);
- ImageCtxT* m_image_ctx;
-
- ceph::immutable_obj_cache::CacheClient *m_cache_client = nullptr;
SharedPersistentObjectCacher<ImageCtxT> *m_object_store = nullptr;
+ bool m_initialzed;
};
} // namespace cache
} // namespace librbd
-extern template class librbd::cache::SharedReadOnlyObjectDispatch<librbd::ImageCtx>;
+extern template class librbd::cache::SharedReadOnlyObjectDispatch<librbd::ImageCtx, ceph::immutable_obj_cache::CacheClient>;
#endif // CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H