]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add object_may_not_exist helper
authorMykola Golub <mgolub@suse.com>
Fri, 7 Sep 2018 11:20:00 +0000 (14:20 +0300)
committerMykola Golub <mgolub@suse.com>
Mon, 10 Sep 2018 13:14:03 +0000 (16:14 +0300)
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/librbd/ObjectMap.cc
src/librbd/ObjectMap.h

index 66f96768c94f0965a05ddb6d74b048aa2ef26a1b..d4d70420007aa17b7f95a1b058f706ea995c2ca1 100644 (file)
@@ -110,6 +110,32 @@ bool ObjectMap<I>::object_may_exist(uint64_t object_no) const
   return exists;
 }
 
+template <typename I>
+bool ObjectMap<I>::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 <typename I>
 bool ObjectMap<I>::update_required(const ceph::BitVector<2>::Iterator& it,
                                    uint8_t new_state) {
index f00311bbb05cf9e09d1eee3c9fbedecf38ebc01d..ad393ef15d9e7dc6e0aae347ccfbbaff7bc9a9f4 100644 (file)
@@ -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,