]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: remove object maps when disabling 3980/head
authorJason Dillaman <dillaman@redhat.com>
Tue, 24 Mar 2015 14:19:32 +0000 (10:19 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 6 Apr 2015 17:14:35 +0000 (13:14 -0400)
If the object map feature is disabled, remove any object maps
prior to disabling the feature.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/internal.cc

index ce70350480a9afec52c737cd8f3bb1a1746b7045..64879a034fb1ea0773a78ccce1aa496dc235e1a7 100644 (file)
@@ -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<snap_t, SnapInfo>::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="