From a94ceb608857c48f2237704bf60bd3e384feedb8 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 23 Feb 2015 18:46:26 -0800 Subject: [PATCH] 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 --- src/librbd/ImageCtx.cc | 8 ++++++++ src/librbd/ObjectMap.cc | 10 +++++----- src/librbd/internal.cc | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index df75f97d273..e27149bd354 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 f30c14b4251..c90a8b34200 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 eca70c27cb5..c51ae75bce2 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); -- 2.47.3