From 7248b93c546cf5134afc77bd14cb5d1ad5465454 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 3 Dec 2015 22:14:42 -0500 Subject: [PATCH] librbd: async object map lock/unlock/refresh state machines Creating async versions to support an async image refresh Signed-off-by: Jason Dillaman --- src/CMakeLists.txt | 3 + src/librbd/Makefile.am | 6 + src/librbd/ObjectMap.cc | 39 +++++ src/librbd/ObjectMap.h | 9 +- src/librbd/object_map/LockRequest.cc | 154 ++++++++++++++++ src/librbd/object_map/LockRequest.h | 72 ++++++++ src/librbd/object_map/RefreshRequest.cc | 224 ++++++++++++++++++++++++ src/librbd/object_map/RefreshRequest.h | 76 ++++++++ src/librbd/object_map/UnlockRequest.cc | 66 +++++++ src/librbd/object_map/UnlockRequest.h | 46 +++++ 10 files changed, 692 insertions(+), 3 deletions(-) create mode 100644 src/librbd/object_map/LockRequest.cc create mode 100644 src/librbd/object_map/LockRequest.h create mode 100644 src/librbd/object_map/RefreshRequest.cc create mode 100644 src/librbd/object_map/RefreshRequest.h create mode 100644 src/librbd/object_map/UnlockRequest.cc create mode 100644 src/librbd/object_map/UnlockRequest.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5950d64d24865..bc7b491f82497 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -890,11 +890,14 @@ if(${WITH_RBD}) librbd/ObjectMap.cc librbd/Utils.cc librbd/object_map/InvalidateRequest.cc + librbd/object_map/LockRequest.cc librbd/object_map/Request.cc + librbd/object_map/RefreshRequest.cc librbd/object_map/ResizeRequest.cc librbd/object_map/SnapshotCreateRequest.cc librbd/object_map/SnapshotRemoveRequest.cc librbd/object_map/SnapshotRollbackRequest.cc + librbd/object_map/UnlockRequest.cc librbd/object_map/UpdateRequest.cc librbd/operation/FlattenRequest.cc librbd/operation/RebuildObjectMapRequest.cc diff --git a/src/librbd/Makefile.am b/src/librbd/Makefile.am index a21bb0a4a2fb6..5d7d082631f74 100644 --- a/src/librbd/Makefile.am +++ b/src/librbd/Makefile.am @@ -27,11 +27,14 @@ librbd_internal_la_SOURCES = \ librbd/ObjectMap.cc \ librbd/Utils.cc \ librbd/object_map/InvalidateRequest.cc \ + librbd/object_map/LockRequest.cc \ librbd/object_map/Request.cc \ + librbd/object_map/RefreshRequest.cc \ librbd/object_map/ResizeRequest.cc \ librbd/object_map/SnapshotCreateRequest.cc \ librbd/object_map/SnapshotRemoveRequest.cc \ librbd/object_map/SnapshotRollbackRequest.cc \ + librbd/object_map/UnlockRequest.cc \ librbd/object_map/UpdateRequest.cc \ librbd/operation/FlattenRequest.cc \ librbd/operation/RebuildObjectMapRequest.cc \ @@ -94,11 +97,14 @@ noinst_HEADERS += \ librbd/Utils.h \ librbd/WatchNotifyTypes.h \ librbd/object_map/InvalidateRequest.h \ + librbd/object_map/LockRequest.h \ librbd/object_map/Request.h \ + librbd/object_map/RefreshRequest.h \ librbd/object_map/ResizeRequest.h \ librbd/object_map/SnapshotCreateRequest.h \ librbd/object_map/SnapshotRemoveRequest.h \ librbd/object_map/SnapshotRollbackRequest.h \ + librbd/object_map/UnlockRequest.h \ librbd/object_map/UpdateRequest.h \ librbd/operation/FlattenRequest.h \ librbd/operation/RebuildObjectMapRequest.h \ diff --git a/src/librbd/ObjectMap.cc b/src/librbd/ObjectMap.cc index aaacd9b08052c..d7f4b6fc8a540 100644 --- a/src/librbd/ObjectMap.cc +++ b/src/librbd/ObjectMap.cc @@ -5,10 +5,13 @@ #include "librbd/ImageWatcher.h" #include "librbd/internal.h" #include "librbd/object_map/InvalidateRequest.h" +#include "librbd/object_map/LockRequest.h" +#include "librbd/object_map/RefreshRequest.h" #include "librbd/object_map/ResizeRequest.h" #include "librbd/object_map/SnapshotCreateRequest.h" #include "librbd/object_map/SnapshotRemoveRequest.h" #include "librbd/object_map/SnapshotRollbackRequest.h" +#include "librbd/object_map/UnlockRequest.h" #include "librbd/object_map/UpdateRequest.h" #include "librbd/Utils.h" #include "common/dout.h" @@ -23,6 +26,23 @@ namespace librbd { +namespace { + +struct C_ApplyRefresh : public Context { + object_map::RefreshRequest<> *request; + C_ApplyRefresh(object_map::RefreshRequest<> *request) : request(request) { + } + virtual void finish(int r) { + if (r < 0) { + request->apply(); + } else { + request->discard(); + } + } +}; + +} // anonymous namespace + ObjectMap::ObjectMap(ImageCtx &image_ctx) : m_image_ctx(image_ctx), m_snap_id(CEPH_NOSNAP), m_enabled(false) { @@ -136,6 +156,12 @@ int ObjectMap::lock() return 0; } +void ObjectMap::lock(Context *on_finish) { + object_map::LockRequest<> *req = new object_map::LockRequest<>( + m_image_ctx, on_finish); + req->send(); +} + int ObjectMap::unlock() { if (!m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP)) { @@ -154,6 +180,12 @@ int ObjectMap::unlock() return r; } +void ObjectMap::unlock(Context *on_finish) { + object_map::UnlockRequest<> *req = new object_map::UnlockRequest<>( + m_image_ctx, on_finish); + req->send(); +} + bool ObjectMap::object_may_exist(uint64_t object_no) const { // Fall back to default logic if object map is disabled or invalid @@ -254,6 +286,13 @@ void ObjectMap::refresh(uint64_t snap_id) } } +Context* ObjectMap::refresh(uint64_t snap_id, Context *on_finish) { + object_map::RefreshRequest<> *req = new object_map::RefreshRequest<>( + m_image_ctx, &m_object_map, snap_id, on_finish); + req->send(); + return new C_ApplyRefresh(req); +} + void ObjectMap::rollback(uint64_t snap_id, Context *on_finish) { assert(m_image_ctx.snap_lock.is_locked()); assert(m_image_ctx.object_map_lock.is_wlocked()); diff --git a/src/librbd/ObjectMap.h b/src/librbd/ObjectMap.h index 46c5b64cf50bb..219d352d035ae 100644 --- a/src/librbd/ObjectMap.h +++ b/src/librbd/ObjectMap.h @@ -31,8 +31,10 @@ public: return m_object_map.size(); } - int lock(); - int unlock(); + int lock(); // TODO remove + void lock(Context *on_finish); + int unlock(); // TODO remove + void unlock(Context *on_finish); bool object_may_exist(uint64_t object_no) const; @@ -52,7 +54,8 @@ public: const boost::optional ¤t_state, Context *on_finish); - void refresh(uint64_t snap_id); + void refresh(uint64_t snap_id); // TODO remove + Context *refresh(uint64_t snap_id, Context *on_finish); void rollback(uint64_t snap_id, Context *on_finish); void snapshot_add(uint64_t snap_id, Context *on_finish); void snapshot_remove(uint64_t snap_id, Context *on_finish); diff --git a/src/librbd/object_map/LockRequest.cc b/src/librbd/object_map/LockRequest.cc new file mode 100644 index 0000000000000..3af50735e431b --- /dev/null +++ b/src/librbd/object_map/LockRequest.cc @@ -0,0 +1,154 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "librbd/object_map/LockRequest.h" +#include "cls/lock/cls_lock_client.h" +#include "common/dout.h" +#include "common/errno.h" +#include "librbd/ImageCtx.h" +#include "librbd/ObjectMap.h" +#include "librbd/Utils.h" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::object_map::LockRequest: " + +namespace librbd { +namespace object_map { + +using util::create_rados_ack_callback; +using util::create_rados_safe_callback; + +template +LockRequest::LockRequest(I &image_ctx, Context *on_finish) + : m_image_ctx(image_ctx), m_on_finish(on_finish), m_broke_lock(false) { +} + +template +void LockRequest::send() { + send_lock(); +} + +template +void LockRequest::send_lock() { + CephContext *cct = m_image_ctx.cct; + std::string oid(ObjectMap::object_map_name(m_image_ctx.id, CEPH_NOSNAP)); + ldout(cct, 10) << this << " " << __func__ << ": oid=" << oid << dendl; + + librados::ObjectWriteOperation op; + rados::cls::lock::lock(&op, RBD_LOCK_NAME, LOCK_EXCLUSIVE, "", "", "", + utime_t(), 0); + + using klass = LockRequest; + librados::AioCompletion *rados_completion = + create_rados_safe_callback(this); + int r = m_image_ctx.md_ctx.aio_operate(oid, rados_completion, &op); + assert(r == 0); + rados_completion->release(); +} + +template +Context *LockRequest::handle_lock(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + if (*ret_val == 0) { + return m_on_finish; + } else if (m_broke_lock || *ret_val != -EBUSY) { + lderr(cct) << "failed to lock object map: " << cpp_strerror(*ret_val) + << dendl; + *ret_val = 0; + return m_on_finish; + } + + send_get_lock_info(); + return nullptr; +} + +template +void LockRequest::send_get_lock_info() { + CephContext *cct = m_image_ctx.cct; + std::string oid(ObjectMap::object_map_name(m_image_ctx.id, CEPH_NOSNAP)); + ldout(cct, 10) << this << " " << __func__ << ": oid=" << oid << dendl; + + librados::ObjectReadOperation op; + rados::cls::lock::get_lock_info_start(&op, RBD_LOCK_NAME); + + using klass = LockRequest; + librados::AioCompletion *rados_completion = + create_rados_ack_callback(this); + int r = m_image_ctx.md_ctx.aio_operate(oid, rados_completion, &op, &m_out_bl); + assert(r == 0); + rados_completion->release(); +} + +template +Context *LockRequest::handle_get_lock_info(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + if (*ret_val == -ENOENT) { + send_lock(); + return nullptr; + } + + ClsLockType lock_type; + std::string lock_tag; + if (*ret_val == 0) { + bufferlist::iterator it = m_out_bl.begin(); + *ret_val = rados::cls::lock::get_lock_info_finish(&it, &m_lockers, + &lock_type, &lock_tag); + } + if (*ret_val < 0) { + lderr(cct) << "failed to list object map locks: " << cpp_strerror(*ret_val) + << dendl; + *ret_val = 0; + return m_on_finish; + } + + send_break_locks(); + return nullptr; +} + +template +void LockRequest::send_break_locks() { + CephContext *cct = m_image_ctx.cct; + std::string oid(ObjectMap::object_map_name(m_image_ctx.id, CEPH_NOSNAP)); + ldout(cct, 10) << this << " " << __func__ << ": oid=" << oid << ", " + << "num_lockers=" << m_lockers.size() << dendl; + + librados::ObjectWriteOperation op; + for (auto &locker : m_lockers) { + rados::cls::lock::break_lock(&op, RBD_LOCK_NAME, locker.first.cookie, + locker.first.locker); + } + + using klass = LockRequest; + librados::AioCompletion *rados_completion = + create_rados_safe_callback(this); + int r = m_image_ctx.md_ctx.aio_operate(oid, rados_completion, &op); + assert(r == 0); + rados_completion->release(); +} + +template +Context *LockRequest::handle_break_locks(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + m_broke_lock = true; + if (*ret_val == 0 || *ret_val == -ENOENT) { + send_lock(); + return nullptr; + } + + lderr(cct) << "failed to break object map lock: " << cpp_strerror(*ret_val) + << dendl; + *ret_val = 0; + return m_on_finish; +} + +} // namespace object_map +} // namespace librbd + +template class librbd::object_map::LockRequest; diff --git a/src/librbd/object_map/LockRequest.h b/src/librbd/object_map/LockRequest.h new file mode 100644 index 0000000000000..8f1ee6c526538 --- /dev/null +++ b/src/librbd/object_map/LockRequest.h @@ -0,0 +1,72 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H +#define CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H + +#include "include/int_types.h" +#include "include/buffer.h" +#include "include/Context.h" +#include "cls/lock/cls_lock_types.h" +#include + +namespace librbd { + +class ImageCtx; + +namespace object_map { + +template +class LockRequest { +public: + LockRequest(ImageCtxT &image_ctx, Context *on_finish); + + void send(); + +private: + /** + * @verbatim + * + * /------------------------------------- BREAK_LOCKS * * * + * | | ^ * + * | | | * + * | | | * + * | v (EBUSY && !broke_lock) | * + * \---------> LOCK_OBJECT_MAP * * * * * * * * * * * > GET_LOCK_INFO * * + * | * ^ * * + * | * * * * + * | * * (ENOENT) * * + * | * * * * * * * * * * * * * * * * * * + * | * * + * | * (other errors) * + * | * * + * v v (other errors) * + * < * * * * * * * * * * * * * * * * * * * * * * * * + * + * @endverbatim + */ + + ImageCtxT &m_image_ctx; + Context *m_on_finish; + + bool m_broke_lock; + std::map m_lockers; + bufferlist m_out_bl; + + void send_lock(); + Context *handle_lock(int *ret_val); + + void send_get_lock_info(); + Context *handle_get_lock_info(int *ret_val); + + void send_break_locks(); + Context *handle_break_locks(int *ret_val); +}; + +} // namespace object_map +} // namespace librbd + +extern template class librbd::object_map::LockRequest; + +#endif // CEPH_LIBRBD_OBJECT_MAP_LOCK_REQUEST_H diff --git a/src/librbd/object_map/RefreshRequest.cc b/src/librbd/object_map/RefreshRequest.cc new file mode 100644 index 0000000000000..84acba3cd05ef --- /dev/null +++ b/src/librbd/object_map/RefreshRequest.cc @@ -0,0 +1,224 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "librbd/object_map/RefreshRequest.h" +#include "cls/rbd/cls_rbd_client.h" +#include "cls/lock/cls_lock_client.h" +#include "common/dout.h" +#include "common/errno.h" +#include "librbd/ImageCtx.h" +#include "librbd/ObjectMap.h" +#include "librbd/object_map/InvalidateRequest.h" +#include "librbd/object_map/ResizeRequest.h" +#include "librbd/Utils.h" +#include "osdc/Striper.h" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::object_map::RefreshRequest: " + +namespace librbd { + +using util::create_context_callback; +using util::create_rados_ack_callback; +using util::create_rados_safe_callback; + +namespace object_map { + +template +RefreshRequest::RefreshRequest(I &image_ctx, ceph::BitVector<2> *object_map, + uint64_t snap_id, Context *on_finish) + : m_image_ctx(image_ctx), m_object_map(object_map), m_snap_id(snap_id), + m_on_finish(on_finish), m_object_count(0), + m_truncate_on_disk_object_map(false) { +} + +template +void RefreshRequest::send() { + { + RWLock::RLocker snap_locker(m_image_ctx.snap_lock); + m_object_count = Striper::get_num_objects( + m_image_ctx.layout, m_image_ctx.get_image_size(m_snap_id)); + } + + send_load(); +} + +template +void RefreshRequest::apply() { + uint64_t num_objs; + { + RWLock::RLocker snap_locker(m_image_ctx.snap_lock); + num_objs = Striper::get_num_objects( + m_image_ctx.layout, m_image_ctx.get_image_size(m_snap_id)); + } + assert(m_on_disk_object_map.size() >= num_objs); + + *m_object_map = m_on_disk_object_map; +} + +template +void RefreshRequest::send_load() { + CephContext *cct = m_image_ctx.cct; + std::string oid(ObjectMap::object_map_name(m_image_ctx.id, m_snap_id)); + ldout(cct, 10) << this << " " << __func__ << ": oid=" << oid << dendl; + + librados::ObjectReadOperation op; + cls_client::object_map_load_start(&op); + + using klass = RefreshRequest; + m_out_bl.clear(); + librados::AioCompletion *rados_completion = + create_rados_ack_callback(this); + int r = m_image_ctx.md_ctx.aio_operate(oid, rados_completion, &op, &m_out_bl); + assert(r == 0); + rados_completion->release(); +} + +template +Context *RefreshRequest::handle_load(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + if (*ret_val == 0) { + bufferlist::iterator bl_it = m_out_bl.begin(); + *ret_val = cls_client::object_map_load_finish(&bl_it, + &m_on_disk_object_map); + } + + std::string oid(ObjectMap::object_map_name(m_image_ctx.id, m_snap_id)); + if (*ret_val == -EINVAL) { + // object map is corrupt on-disk -- clear it and properly size it + // so future IO can keep the object map in sync + lderr(cct) << "object map corrupt on-disk: " << oid << dendl; + m_truncate_on_disk_object_map = true; + send_resize_invalidate(); + return nullptr; + } else if (*ret_val < 0) { + lderr(cct) << "failed to load object map: " << oid << dendl; + send_invalidate(); + return nullptr; + } + + if (m_on_disk_object_map.size() < m_object_count) { + lderr(cct) << "object map smaller than current object count: " + << m_on_disk_object_map.size() << " != " + << m_object_count << dendl; + send_resize_invalidate(); + return nullptr; + } + + ldout(cct, 20) << "refreshed object map: num_objs=" + << m_on_disk_object_map.size() << dendl; + if (m_on_disk_object_map.size() > m_object_count) { + // resize op might have been interrupted + ldout(cct, 1) << "object map larger than current object count: " + << m_on_disk_object_map.size() << " != " + << m_object_count << dendl; + } + + apply(); + return m_on_finish; +} + +template +void RefreshRequest::send_invalidate() { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << dendl; + + m_on_disk_object_map.clear(); + object_map::ResizeRequest::resize(&m_on_disk_object_map, m_object_count, + OBJECT_EXISTS); + + using klass = RefreshRequest; + Context *ctx = create_context_callback< + klass, &klass::handle_invalidate>(this); + InvalidateRequest *req = InvalidateRequest::create( + m_image_ctx, m_snap_id, false, ctx); + + RWLock::RLocker owner_locker(m_image_ctx.owner_lock); + RWLock::WLocker snap_locker(m_image_ctx.snap_lock); + req->send(); +} + +template +Context *RefreshRequest::handle_invalidate(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + assert(*ret_val == 0); + apply(); + return m_on_finish; +} + +template +void RefreshRequest::send_resize_invalidate() { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << dendl; + + m_on_disk_object_map.clear(); + object_map::ResizeRequest::resize(&m_on_disk_object_map, m_object_count, + OBJECT_EXISTS); + + using klass = RefreshRequest; + Context *ctx = create_context_callback< + klass, &klass::handle_resize_invalidate>(this); + InvalidateRequest *req = InvalidateRequest::create( + m_image_ctx, m_snap_id, false, ctx); + + RWLock::RLocker owner_locker(m_image_ctx.owner_lock); + RWLock::WLocker snap_locker(m_image_ctx.snap_lock); + req->send(); +} + +template +Context *RefreshRequest::handle_resize_invalidate(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + assert(*ret_val == 0); + send_resize(); + return nullptr; +} + +template +void RefreshRequest::send_resize() { + CephContext *cct = m_image_ctx.cct; + std::string oid(ObjectMap::object_map_name(m_image_ctx.id, m_snap_id)); + ldout(cct, 10) << this << " " << __func__ << ": oid=" << oid << dendl; + + librados::ObjectWriteOperation op; + if (m_snap_id == CEPH_NOSNAP) { + rados::cls::lock::assert_locked(&op, RBD_LOCK_NAME, LOCK_EXCLUSIVE, "", ""); + } + if (m_truncate_on_disk_object_map) { + op.truncate(0); + } + cls_client::object_map_resize(&op, m_object_count, OBJECT_NONEXISTENT); + + using klass = RefreshRequest; + librados::AioCompletion *rados_completion = + create_rados_safe_callback(this); + int r = m_image_ctx.md_ctx.aio_operate(oid, rados_completion, &op); + assert(r == 0); + rados_completion->release(); +} + +template +Context *RefreshRequest::handle_resize(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + if (*ret_val < 0) { + lderr(cct) << "failed to adjust object map size: " << cpp_strerror(*ret_val) + << dendl; + *ret_val = 0; + } + apply(); + return m_on_finish; +} + +} // namespace object_map +} // namespace librbd + +template class librbd::object_map::RefreshRequest; diff --git a/src/librbd/object_map/RefreshRequest.h b/src/librbd/object_map/RefreshRequest.h new file mode 100644 index 0000000000000..17a69a009ec0d --- /dev/null +++ b/src/librbd/object_map/RefreshRequest.h @@ -0,0 +1,76 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H +#define CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H + +#include "include/int_types.h" +#include "include/buffer.h" +#include "include/Context.h" +#include "common/bit_vector.hpp" + +namespace librbd { + +class ImageCtx; + +namespace object_map { + +template +class RefreshRequest { +public: + RefreshRequest(ImageCtxT &image_ctx, ceph::BitVector<2> *object_map, + uint64_t snap_id, Context *on_finish); + + void send(); + +private: + /** + * @verbatim + * (other errors) + * -----> LOAD * * * * * * * > INVALIDATE ------------\ + * | * | + * | * (-EINVAL or too small) | + * | * * * * * * > INVALIDATE_AND_RESIZE | + * | | * | + * | | * | + * | v * | + * | RESIZE * | + * | | * | + * | | * * * * * * * | + * | | * | + * | v v | + * \-----------------> <------------/ + * @endverbatim + */ + + ImageCtxT &m_image_ctx; + ceph::BitVector<2> *m_object_map; + uint64_t m_snap_id; + Context *m_on_finish; + + uint64_t m_object_count; + ceph::BitVector<2> m_on_disk_object_map; + bool m_truncate_on_disk_object_map; + bufferlist m_out_bl; + + void send_load(); + Context *handle_load(int *ret_val); + + void send_invalidate(); + Context *handle_invalidate(int *ret_val); + + void send_resize_invalidate(); + Context *handle_resize_invalidate(int *ret_val); + + void send_resize(); + Context *handle_resize(int *ret_val); + + void apply(); +}; + +} // namespace object_map +} // namespace librbd + +extern template class librbd::object_map::RefreshRequest; + +#endif // CEPH_LIBRBD_OBJECT_MAP_REFRESH_REQUEST_H diff --git a/src/librbd/object_map/UnlockRequest.cc b/src/librbd/object_map/UnlockRequest.cc new file mode 100644 index 0000000000000..c7ae9801d3ce0 --- /dev/null +++ b/src/librbd/object_map/UnlockRequest.cc @@ -0,0 +1,66 @@ +// -*- mode:C; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "librbd/object_map/UnlockRequest.h" +#include "cls/lock/cls_lock_client.h" +#include "common/dout.h" +#include "common/errno.h" +#include "librbd/ImageCtx.h" +#include "librbd/ObjectMap.h" +#include "librbd/Utils.h" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::object_map::UnlockRequest: " + +namespace librbd { +namespace object_map { + +using util::create_rados_safe_callback; + +template +UnlockRequest::UnlockRequest(I &image_ctx, Context *on_finish) + : m_image_ctx(image_ctx), m_on_finish(on_finish) { +} + +template +void UnlockRequest::send() { + send_unlock(); +} + +template +void UnlockRequest::send_unlock() { + CephContext *cct = m_image_ctx.cct; + std::string oid(ObjectMap::object_map_name(m_image_ctx.id, CEPH_NOSNAP)); + ldout(cct, 10) << this << " " << __func__ << ": oid=" << oid << dendl; + + librados::ObjectWriteOperation op; + rados::cls::lock::unlock(&op, RBD_LOCK_NAME, ""); + + using klass = UnlockRequest; + librados::AioCompletion *rados_completion = + create_rados_safe_callback(this); + int r = m_image_ctx.md_ctx.aio_operate(oid, rados_completion, &op); + assert(r == 0); + rados_completion->release(); +} + +template +Context *UnlockRequest::handle_unlock(int *ret_val) { + CephContext *cct = m_image_ctx.cct; + ldout(cct, 10) << this << " " << __func__ << ": r=" << *ret_val << dendl; + + if (*ret_val < 0 && *ret_val != -ENOENT) { + lderr(m_image_ctx.cct) << "failed to release object map lock: " + << cpp_strerror(*ret_val) << dendl; + + } + + *ret_val = 0; + return m_on_finish; +} + +} // namespace object_map +} // namespace librbd + +template class librbd::object_map::UnlockRequest; diff --git a/src/librbd/object_map/UnlockRequest.h b/src/librbd/object_map/UnlockRequest.h new file mode 100644 index 0000000000000..14535403381d0 --- /dev/null +++ b/src/librbd/object_map/UnlockRequest.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_OBJECT_MAP_UNLOCK_REQUEST_H +#define CEPH_LIBRBD_OBJECT_MAP_UNLOCK_REQUEST_H + +#include "include/int_types.h" +#include "include/buffer.h" +#include "include/Context.h" +#include + +namespace librbd { + +class ImageCtx; + +namespace object_map { + +template +class UnlockRequest { +public: + UnlockRequest(ImageCtxT &image_ctx, Context *on_finish); + + void send(); + +private: + /** + * @verbatim + * + * ----> UNLOCK ----> + * + * @endverbatim + */ + + ImageCtxT &m_image_ctx; + Context *m_on_finish; + + void send_unlock(); + Context* handle_unlock(int *ret_val); +}; + +} // namespace object_map +} // namespace librbd + +extern template class librbd::object_map::UnlockRequest; + +#endif // CEPH_LIBRBD_OBJECT_MAP_UNLOCK_REQUEST_H -- 2.39.5