From: Josh Durgin Date: Tue, 24 Feb 2015 02:46:26 +0000 (-0800) Subject: librbd: add and use a test_features() helper X-Git-Tag: v0.93~6^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a94ceb608857c48f2237704bf60bd3e384feedb8;p=ceph.git librbd: add and use a test_features() helper 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 --- diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index df75f97d2732..e27149bd3546 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -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) { diff --git a/src/librbd/ObjectMap.cc b/src/librbd/ObjectMap.cc index f30c14b4251b..c90a8b342008 100644 --- a/src/librbd/ObjectMap.cc +++ b/src/librbd/ObjectMap.cc @@ -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 ¤t_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()); diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index eca70c27cb54..c51ae75bce2b 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -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);