From: Jason Dillaman Date: Tue, 24 Mar 2015 14:19:32 +0000 (-0400) Subject: librbd: remove object maps when disabling X-Git-Tag: v9.0.0~37^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F3980%2Fhead;p=ceph.git librbd: remove object maps when disabling If the object map feature is disabled, remove any object maps prior to disabling the feature. Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index ce70350480a..64879a034fb 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -55,6 +55,34 @@ using librados::IoCtx; using librados::Rados; namespace librbd { + +namespace { + +int remove_object_map(ImageCtx *ictx) { + assert(ictx->snap_lock.is_locked()); + CephContext *cct = ictx->cct; + + int r; + for (std::map::iterator it = ictx->snap_info.begin(); + it != ictx->snap_info.end(); ++it) { + std::string oid(ObjectMap::object_map_name(ictx->id, it->first)); + r = ictx->md_ctx.remove(oid); + if (r < 0 && r != -ENOENT) { + lderr(cct) << "failed to remove object map " << oid << ": " + << cpp_strerror(r) << dendl; + return r; + } + } + + r = ictx->md_ctx.remove(ObjectMap::object_map_name(ictx->id, CEPH_NOSNAP)); + if (r < 0 && r != -ENOENT) { + lderr(cct) << "failed to remove object map: " << cpp_strerror(r) << dendl; + } + return 0; +} + +} // anonymous namespace + const string id_obj_name(const string &name) { return RBD_ID_PREFIX + name; @@ -1381,18 +1409,28 @@ reprotect_and_return_err: } uint64_t mask = features; - if ((features & RBD_FEATURE_EXCLUSIVE_LOCK) != 0 && !enabled) { - if ((new_features & RBD_FEATURE_OBJECT_MAP) != 0) { - lderr(cct) << "cannot disable exclusive lock" << dendl; - return -EINVAL; - } - mask |= RBD_FEATURE_OBJECT_MAP; - } else if ((features & RBD_FEATURE_OBJECT_MAP) != 0 && enabled) { - if ((new_features & RBD_FEATURE_EXCLUSIVE_LOCK) == 0) { - lderr(cct) << "cannot enable object map" << dendl; - return -EINVAL; - } - mask |= RBD_FEATURE_EXCLUSIVE_LOCK; + if (enabled) { + if ((features & RBD_FEATURE_OBJECT_MAP) != 0) { + if ((new_features & RBD_FEATURE_EXCLUSIVE_LOCK) == 0) { + lderr(cct) << "cannot enable object map" << dendl; + return -EINVAL; + } + mask |= RBD_FEATURE_EXCLUSIVE_LOCK; + } + } else { + if ((features & RBD_FEATURE_EXCLUSIVE_LOCK) != 0) { + if ((new_features & RBD_FEATURE_OBJECT_MAP) != 0) { + lderr(cct) << "cannot disable exclusive lock" << dendl; + return -EINVAL; + } + mask |= RBD_FEATURE_OBJECT_MAP; + } else if ((features & RBD_FEATURE_OBJECT_MAP) != 0) { + r = remove_object_map(ictx); + if (r < 0) { + lderr(cct) << "failed to remove object map" << dendl; + return r; + } + } } ldout(cct, 10) << "update_features: features=" << new_features << ", mask="