Skip to content

Commit

Permalink
fixup: librbd: deep_copy: src_to_dst_object_offset
Browse files Browse the repository at this point in the history
Signed-off-by: Mykola Golub <to.my.trociny@gmail.com>
  • Loading branch information
trociny committed Nov 3, 2017
1 parent 640b6ce commit 9024db9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
44 changes: 38 additions & 6 deletions src/librbd/deep_copy/ObjectCopyRequest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,27 @@ Context *ObjectCopyRequest<I>::start_lock_op(RWLock &owner_lock) {
return m_dst_image_ctx->exclusive_lock->start_op();
}

template <typename I>
uint64_t ObjectCopyRequest<I>::src_to_dst_object_offset(uint64_t objectno,
uint64_t offset) {
std::vector<std::pair<uint64_t, uint64_t>> image_extents;
Striper::extent_to_file(m_cct, &m_src_image_ctx->layout, objectno, offset, 1,
image_extents);
assert(image_extents.size() == 1);
auto dst_object_offset = image_extents.begin()->first;

std::map<object_t, std::vector<ObjectExtent>> dst_object_extents;
Striper::file_to_extents(m_cct, m_dst_image_ctx->format_string,
&m_dst_image_ctx->layout, dst_object_offset, 1, 0,
dst_object_extents);
assert(dst_object_extents.size() == 1);
assert(dst_object_extents.begin()->second.size() == 1);
auto &e = *dst_object_extents.begin()->second.begin();
assert(e.objectno == m_dst_object_number);

return e.offset;
}

template <typename I>
void ObjectCopyRequest<I>::compute_src_object_extents() {
std::vector<std::pair<uint64_t, uint64_t>> image_extents;
Expand All @@ -412,11 +433,20 @@ void ObjectCopyRequest<I>::compute_src_object_extents() {
Striper::file_to_extents(m_cct, m_src_image_ctx->format_string,
&m_src_image_ctx->layout, e.first, e.second, 0,
src_object_extents);
auto stripe_unit = std::min(m_src_image_ctx->layout.stripe_unit,
m_dst_image_ctx->layout.stripe_unit);
for (auto &p : src_object_extents) {
for (auto &s : p.second) {
m_src_objects.insert(s.objectno);
m_src_object_extents.push_back({s.objectno, s.offset, s.length});
total += s.length;
while (s.length > 0) {
assert(s.length >= stripe_unit);
auto dst_object_offset = src_to_dst_object_offset(s.objectno, s.offset);
m_src_object_extents[dst_object_offset] = {s.objectno, s.offset,
stripe_unit};
s.offset += stripe_unit;
s.length -= stripe_unit;
}
}
}
}
Expand Down Expand Up @@ -484,10 +514,11 @@ void ObjectCopyRequest<I>::compute_read_ops() {
}
}

uint64_t dst_object_offset = 0;
for (auto &e : m_src_object_extents) {
for (auto &it : m_src_object_extents) {
auto dst_object_offset = it.first;
auto &e = it.second;

if (e.object_no != m_src_ono) {
dst_object_offset += e.length;
continue;
}

Expand All @@ -514,7 +545,9 @@ void ObjectCopyRequest<I>::compute_read_ops() {
// limit read interval to diff
read_interval.intersection_of(diff);

ldout(m_cct, 20) << "read: " << read_interval << dendl;
ldout(m_cct, 20) << "src_object_extent: " << e.offset << "~" << e.length
<< ", dst_object_offset=" << dst_object_offset
<< ", read: " << read_interval << dendl;

assert(exists || read_interval.empty());

Expand All @@ -529,7 +562,6 @@ void ObjectCopyRequest<I>::compute_read_ops() {
.emplace_back(COPY_OP_TYPE_WRITE, it.get_start(),
dst_object_offset + offset, it.get_len());
}
dst_object_offset += e.length;
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/librbd/deep_copy/ObjectCopyRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <list>
#include <map>
#include <string>
#include <vector>

class Context;
class RWLock;
Expand Down Expand Up @@ -80,16 +79,18 @@ class ObjectCopyRequest {
*/

struct SrcObjectExtent {
uint64_t object_no;
uint64_t offset;
uint64_t length;
uint64_t object_no = 0;
uint64_t offset = 0;
uint64_t length = 0;

SrcObjectExtent() {
}
SrcObjectExtent(uint64_t object_no, uint64_t offset, uint64_t length)
: object_no(object_no), offset(offset), length(length) {
}
};

typedef std::vector<SrcObjectExtent> SrcObjectExtents;
typedef std::map<uint64_t, SrcObjectExtent> SrcObjectExtents;

enum CopyOpType {
COPY_OP_TYPE_WRITE,
Expand Down Expand Up @@ -163,6 +164,8 @@ class ObjectCopyRequest {

Context *start_lock_op(RWLock &owner_lock);

uint64_t src_to_dst_object_offset(uint64_t objectno, uint64_t offset);

void compute_src_object_extents();
void compute_read_ops();
void merge_write_ops();
Expand Down

0 comments on commit 9024db9

Please sign in to comment.