]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add and use a test_features() helper
authorJosh Durgin <jdurgin@redhat.com>
Tue, 24 Feb 2015 02:46:26 +0000 (18:46 -0800)
committerJosh Durgin <jdurgin@redhat.com>
Wed, 25 Feb 2015 23:41:54 +0000 (15:41 -0800)
This gets the appropriate locks, and checks the currently open
snapshot instead of head.  Looking up features by snap_id prepares us
for future addition or removal of e.g. an object map throughout the
life of an image.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
src/librbd/ImageCtx.cc
src/librbd/ObjectMap.cc
src/librbd/internal.cc

index df75f97d2732442e34252d832f39e4646d0b125d..e27149bd35467d266bcc0a80ac58bf44339ed27d 100644 (file)
@@ -452,6 +452,14 @@ namespace librbd {
     return -ENOENT;
   }
 
+  bool ImageCtx::test_features(uint64_t test_features) const
+  {
+    RWLock::RLocker l(snap_lock);
+    uint64_t snap_features = 0;
+    get_features(snap_id, &snap_features);
+    return ((snap_features & test_features) == test_features);
+  }
+
   int ImageCtx::get_flags(librados::snap_t _snap_id, uint64_t *_flags) const
   {
     if (_snap_id == CEPH_NOSNAP) {
index f30c14b4251b9273b9de90d7b80b69ae9a1d4f91..c90a8b342008054d72fa817d5e5969710d25da9b 100644 (file)
@@ -35,7 +35,7 @@ std::string ObjectMap::object_map_name(const std::string &image_id,
 
 int ObjectMap::lock()
 {
-  if ((m_image_ctx.features & RBD_FEATURE_OBJECT_MAP) == 0) {
+  if (!m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP)) {
     return 0;
   }
 
@@ -94,7 +94,7 @@ int ObjectMap::lock()
 
 int ObjectMap::unlock()
 {
-  if ((m_image_ctx.features & RBD_FEATURE_OBJECT_MAP) == 0) {
+  if (!m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP)) {
     return 0;
   }
 
@@ -113,7 +113,7 @@ int ObjectMap::unlock()
 bool ObjectMap::object_may_exist(uint64_t object_no) const
 {
   // Fall back to default logic if object map is disabled or invalid
-  if ((m_image_ctx.features & RBD_FEATURE_OBJECT_MAP) == 0 ||
+  if (!m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP) ||
       ((m_image_ctx.flags & RBD_FLAG_OBJECT_MAP_INVALID) != 0)) {
     return true;
   }
@@ -237,7 +237,7 @@ void ObjectMap::snapshot(uint64_t snap_id) {
 
 void ObjectMap::aio_resize(uint64_t new_size, uint8_t default_object_state,
                           Context *on_finish) {
-  assert((m_image_ctx.features & RBD_FEATURE_OBJECT_MAP) != 0);
+  assert(m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP));
   assert(m_image_ctx.owner_lock.is_locked());
   assert(m_image_ctx.image_watcher->is_lock_owner());
 
@@ -259,7 +259,7 @@ bool ObjectMap::aio_update(uint64_t start_object_no, uint64_t end_object_no,
                            const boost::optional<uint8_t> &current_state,
                            Context *on_finish)
 {
-  assert((m_image_ctx.features & RBD_FEATURE_OBJECT_MAP) != 0);
+  assert(m_image_ctx.test_features(RBD_FEATURE_OBJECT_MAP));
   assert(m_image_ctx.owner_lock.is_locked());
   assert(m_image_ctx.image_watcher->is_lock_owner());
 
index eca70c27cb54a44969e9318a1e1a8450e19826ff..c51ae75bce2bfce38d18d21d9e3c6e636a1145f7 100644 (file)
@@ -379,7 +379,7 @@ namespace librbd {
       return r;
 
     // no children for non-layered or old format image
-    if ((ictx->features & RBD_FEATURE_LAYERING) == 0)
+    if (!ictx->test_features(RBD_FEATURE_LAYERING))
       return 0;
 
     parent_spec parent_spec(ictx->md_ctx.get_id(), ictx->id, ictx->snap_id);