]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: separate read vs write migration parent overlaps
authorJason Dillaman <dillaman@redhat.com>
Wed, 18 Apr 2018 15:08:24 +0000 (11:08 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 14 Aug 2018 22:29:45 +0000 (18:29 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
Signed-off-by: Mykola Golub <mgolub@suse.com>
src/librbd/image/RefreshRequest.cc
src/librbd/io/CopyupRequest.cc
src/librbd/io/ObjectRequest.cc
src/librbd/io/ObjectRequest.h

index a53a3528bfc57d1e361cb050829f2c80dc2c352a..9b3947c2751a9d8073577af9976c76bbdea79b6c 100644 (file)
@@ -1404,11 +1404,7 @@ bool RefreshRequest<I>::get_migration_info(ParentInfo *parent_md,
   parent_md->spec.pool_id = m_migration_spec.pool_id;
   parent_md->spec.image_id = m_migration_spec.image_id;
   parent_md->spec.snap_id = CEPH_NOSNAP;
-  parent_md->overlap = m_migration_spec.overlap;
-
-  *migration_info = {m_migration_spec.pool_id, m_migration_spec.image_name,
-                     m_migration_spec.image_id, {}, m_migration_spec.overlap,
-                     m_migration_spec.flatten};
+  parent_md->overlap = std::min(m_size, m_migration_spec.overlap);
 
   auto snap_seqs = m_migration_spec.snap_seqs;
   // If new snapshots have been created on destination image after
@@ -1423,6 +1419,22 @@ bool RefreshRequest<I>::get_migration_info(ParentInfo *parent_md,
     snap_seqs[CEPH_NOSNAP] = CEPH_NOSNAP;
   }
 
+  std::set<uint64_t> snap_ids;
+  for (auto& it : snap_seqs) {
+    snap_ids.insert(it.second);
+  }
+  uint64_t overlap = snap_ids.find(CEPH_NOSNAP) != snap_ids.end() ?
+    parent_md->overlap : 0;
+  for (size_t i = 0; i < m_snapc.snaps.size(); ++i) {
+    if (snap_ids.find(m_snapc.snaps[i].val) != snap_ids.end()) {
+      overlap = std::max(overlap, m_snap_infos[i].image_size);
+    }
+  }
+
+  *migration_info = {m_migration_spec.pool_id, m_migration_spec.image_name,
+                     m_migration_spec.image_id, {}, overlap,
+                     m_migration_spec.flatten};
+
   deep_copy::util::compute_snap_map(0, CEPH_NOSNAP, snap_seqs,
                                     &migration_info->snap_map);
   return true;
index f33830b153053b0a1690f455539236d38e57e614..a09f36a4d09916468f7faf59726176e421eabe74 100644 (file)
@@ -223,8 +223,7 @@ bool CopyupRequest<I>::is_update_object_map_required() {
 
 template <typename I>
 bool CopyupRequest<I>::is_deep_copy() const {
-  return !m_ictx->migration_info.empty() &&
-    m_ictx->migration_info.snap_map.size() > 1;
+  return !m_ictx->migration_info.empty();
 }
 
 template <typename I>
index 5fd37482dee88c6aed2dd3c8e3a7e208337cffd9..647282853b1ad606c08d20bcabe1bb38434a1948 100644 (file)
@@ -131,7 +131,8 @@ void ObjectRequest<I>::add_write_hint(I& image_ctx,
 }
 
 template <typename I>
-bool ObjectRequest<I>::compute_parent_extents(Extents *parent_extents) {
+bool ObjectRequest<I>::compute_parent_extents(Extents *parent_extents,
+                                              bool read_request) {
   assert(m_ictx->snap_lock.is_locked());
   assert(m_ictx->parent_lock.is_locked());
 
@@ -146,7 +147,13 @@ bool ObjectRequest<I>::compute_parent_extents(Extents *parent_extents) {
     lderr(m_ictx->cct) << "failed to retrieve parent overlap: "
                        << cpp_strerror(r) << dendl;
     return false;
-  } else if (parent_overlap == 0) {
+  }
+
+  if (!read_request && !m_ictx->migration_info.empty()) {
+    parent_overlap = m_ictx->migration_info.overlap;
+  }
+
+  if (parent_overlap == 0) {
     return false;
   }
 
@@ -323,7 +330,7 @@ void ObjectReadRequest<I>::copyup() {
   image_ctx->snap_lock.get_read();
   image_ctx->parent_lock.get_read();
   Extents parent_extents;
-  if (!this->compute_parent_extents(&parent_extents) ||
+  if (!this->compute_parent_extents(&parent_extents, true) ||
       (image_ctx->exclusive_lock != nullptr &&
        !image_ctx->exclusive_lock->is_lock_owner())) {
     image_ctx->parent_lock.put_read();
@@ -372,7 +379,7 @@ AbstractObjectWriteRequest<I>::AbstractObjectWriteRequest(
   {
     RWLock::RLocker snap_locker(ictx->snap_lock);
     RWLock::RLocker parent_locker(ictx->parent_lock);
-    this->compute_parent_extents(&m_parent_extents);
+    this->compute_parent_extents(&m_parent_extents, false);
   }
 
   if (this->m_object_off == 0 &&
index e5b94b2d8e157b5aba8a6c46b58337614b93f331..689a5e0edc1a16faf9e3899fe7d0d4be4dea14af 100644 (file)
@@ -74,7 +74,7 @@ public:
   virtual const char *get_op_type() const = 0;
 
 protected:
-  bool compute_parent_extents(Extents *parent_extents);
+  bool compute_parent_extents(Extents *parent_extents, bool read_request);
 
   ImageCtxT *m_ictx;
   std::string m_oid;