From 4c86bccf07b8cce6180b378220c3a28dc576f627 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 7 Sep 2018 14:20:00 +0300 Subject: [PATCH] librbd: add object_may_not_exist helper Signed-off-by: Mykola Golub --- src/librbd/ObjectMap.cc | 26 ++++++++++++++++++++++++++ src/librbd/ObjectMap.h | 1 + 2 files changed, 27 insertions(+) diff --git a/src/librbd/ObjectMap.cc b/src/librbd/ObjectMap.cc index 66f96768c94f0..d4d70420007aa 100644 --- a/src/librbd/ObjectMap.cc +++ b/src/librbd/ObjectMap.cc @@ -110,6 +110,32 @@ bool ObjectMap::object_may_exist(uint64_t object_no) const return exists; } +template +bool ObjectMap::object_may_not_exist(uint64_t object_no) const +{ + ceph_assert(m_image_ctx.snap_lock.is_locked()); + + // Fall back to default logic if object map is disabled or invalid + if (!m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP, + m_image_ctx.snap_lock)) { + return true; + } + + bool flags_set; + int r = m_image_ctx.test_flags(RBD_FLAG_OBJECT_MAP_INVALID, + m_image_ctx.snap_lock, &flags_set); + if (r < 0 || flags_set) { + return true; + } + + RWLock::RLocker l(m_image_ctx.object_map_lock); + uint8_t state = (*this)[object_no]; + bool nonexistent = (state != OBJECT_EXISTS && state != OBJECT_EXISTS_CLEAN); + ldout(m_image_ctx.cct, 20) << "object_no=" << object_no << " r=" + << nonexistent << dendl; + return nonexistent; +} + template bool ObjectMap::update_required(const ceph::BitVector<2>::Iterator& it, uint8_t new_state) { diff --git a/src/librbd/ObjectMap.h b/src/librbd/ObjectMap.h index f00311bbb05cf..ad393ef15d9e7 100644 --- a/src/librbd/ObjectMap.h +++ b/src/librbd/ObjectMap.h @@ -48,6 +48,7 @@ public: void close(Context *on_finish); bool set_object_map(ceph::BitVector<2> &target_object_map); bool object_may_exist(uint64_t object_no) const; + bool object_may_not_exist(uint64_t object_no) const; void aio_save(Context *on_finish); void aio_resize(uint64_t new_size, uint8_t default_object_state, -- 2.39.5