]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd : fix enable objectmap feature issue 6477/head
authorxinxin shu <xinxin.shu@intel.com>
Wed, 21 Oct 2015 11:01:21 +0000 (19:01 +0800)
committerNathan Cutler <ncutler@suse.com>
Thu, 5 Nov 2015 15:58:59 +0000 (16:58 +0100)
Fixes: #13558
Signed-off-by: xinxin shu <xinxin.shu@intel.com>
(cherry picked from commit b0536ebab4e1f34e1ed87fe5efbb00d0f7b48abb)

src/librbd/internal.cc

index 3c6f7409d086e7304a89471a9f2389368c92f69d..1eaa50f81f3be1e19eca20bcd51f544f5ccfe9d2 100644 (file)
@@ -79,6 +79,36 @@ int remove_object_map(ImageCtx *ictx) {
   }
   return 0;
 }
+int create_object_map(ImageCtx *ictx) {
+  assert(ictx->snap_lock.is_locked());
+  CephContext *cct = ictx->cct;
+
+  int r;
+  std::vector<uint64_t> snap_ids;
+  snap_ids.push_back(CEPH_NOSNAP);
+  for (std::map<snap_t, SnapInfo>::iterator it = ictx->snap_info.begin();
+       it != ictx->snap_info.end(); ++it) {
+    snap_ids.push_back(it->first);
+  }
+
+  for (std::vector<uint64_t>::iterator it = snap_ids.begin();
+    it != snap_ids.end(); ++it) {
+    librados::ObjectWriteOperation op;
+    std::string oid(ObjectMap::object_map_name(ictx->id, *it));
+    uint64_t snap_size = ictx->get_image_size(*it);
+    cls_client::object_map_resize(&op, Striper::get_num_objects(ictx->layout, snap_size),
+                                  OBJECT_NONEXISTENT);
+    r = ictx->md_ctx.operate(oid, &op);
+    if (r < 0) {
+      lderr(cct) << "failed to create object map " << oid << ": "
+                 << cpp_strerror(r) << dendl;
+      return r;
+    }
+  }
+
+  return 0;
+}
+
 
 int update_all_flags(ImageCtx *ictx, uint64_t flags, uint64_t mask) {
   assert(ictx->snap_lock.is_locked());
@@ -1616,6 +1646,14 @@ reprotect_and_return_err:
       lderr(cct) << "failed to update features: " << cpp_strerror(r)
                  << dendl;
     }
+    if (((ictx->features & RBD_FEATURE_OBJECT_MAP) == 0) &&
+      ((features & RBD_FEATURE_OBJECT_MAP) != 0)) {
+      r = create_object_map(ictx);
+      if (r < 0) {
+        lderr(cct) << "failed to create object map" << dendl;
+        return r;
+      }
+    }
 
     if (disable_flags != 0) {
       r = update_all_flags(ictx, 0, disable_flags);