struct Handler {
virtual ~Handler() {}
+ virtual void handle_read(uint64_t bytes_read) = 0;
+
virtual int update_progress(uint64_t object_number,
uint64_t object_count) = 0;
};
struct NoOpHandler : public Handler {
+ void handle_read(uint64_t bytes_read) override {
+ }
+
int update_progress(uint64_t object_number,
uint64_t object_count) override {
return 0;
[this, ono](int r) {
handle_object_copy(ono, r);
});
- ObjectCopyRequest<I> *req = ObjectCopyRequest<I>::create(
+ auto req = ObjectCopyRequest<I>::create(
m_src_image_ctx, m_dst_image_ctx, m_src_snap_id_start, m_dst_snap_id_start,
- m_snap_map, ono, m_flatten, ctx);
+ m_snap_map, ono, m_flatten, m_handler, ctx);
req->send();
return 0;
}
#include "librbd/ExclusiveLock.h"
#include "librbd/ObjectMap.h"
#include "librbd/Utils.h"
+#include "librbd/deep_copy/Handler.h"
#include "librbd/io/AioCompletion.h"
#include "librbd/io/AsyncOperation.h"
#include "librbd/io/ImageRequest.h"
librados::snap_t dst_snap_id_start,
const SnapMap &snap_map,
uint64_t dst_object_number,
- bool flatten, Context *on_finish)
+ bool flatten, Handler* handler,
+ Context *on_finish)
: m_src_image_ctx(src_image_ctx),
m_dst_image_ctx(dst_image_ctx), m_cct(dst_image_ctx->cct),
m_src_snap_id_start(src_snap_id_start),
m_dst_snap_id_start(dst_snap_id_start), m_snap_map(snap_map),
m_dst_object_number(dst_object_number), m_flatten(flatten),
- m_on_finish(on_finish) {
+ m_handler(handler), m_on_finish(on_finish) {
ceph_assert(src_image_ctx->data_ctx.is_valid());
ceph_assert(dst_image_ctx->data_ctx.is_valid());
ceph_assert(!m_snap_map.empty());
return;
}
+ if (m_handler != nullptr) {
+ uint64_t bytes_read = 0;
+
+ auto index = *m_read_snaps.begin();
+ for (auto ©_op : m_read_ops[index]) {
+ bytes_read += copy_op.out_bl.length();
+ }
+ m_handler->handle_read(bytes_read);
+ }
+
ceph_assert(!m_read_snaps.empty());
m_read_snaps.erase(m_read_snaps.begin());
namespace deep_copy {
+struct Handler;
+
template <typename ImageCtxT = librbd::ImageCtx>
class ObjectCopyRequest {
public:
librados::snap_t dst_snap_id_start,
const SnapMap &snap_map,
uint64_t object_number, bool flatten,
- Context *on_finish) {
+ Handler* handler, Context *on_finish) {
return new ObjectCopyRequest(src_image_ctx, dst_image_ctx,
src_snap_id_start, dst_snap_id_start, snap_map,
- object_number, flatten, on_finish);
+ object_number, flatten, handler, on_finish);
}
ObjectCopyRequest(ImageCtxT *src_image_ctx, ImageCtxT *dst_image_ctx,
librados::snap_t src_snap_id_start,
librados::snap_t dst_snap_id_start, const SnapMap &snap_map,
- uint64_t object_number, bool flatten, Context *on_finish);
+ uint64_t object_number, bool flatten, Handler* handler,
+ Context *on_finish);
void send();
SnapMap m_snap_map;
uint64_t m_dst_object_number;
bool m_flatten;
+ Handler* m_handler;
Context *m_on_finish;
decltype(m_src_image_ctx->data_ctx) m_src_io_ctx;
CopyupRequest<I>, &CopyupRequest<I>::handle_deep_copy>(this);
auto req = deep_copy::ObjectCopyRequest<I>::create(
m_image_ctx->parent, m_image_ctx, 0, 0,
- m_image_ctx->migration_info.snap_map, m_object_no, m_flatten, ctx);
+ m_image_ctx->migration_info.snap_map, m_object_no, m_flatten, nullptr, ctx);
req->send();
}
auto req = deep_copy::ObjectCopyRequest<I>::create(
image_ctx.parent, &image_ctx, 0, 0, image_ctx.migration_info.snap_map,
- m_object_no, image_ctx.migration_info.flatten, ctx);
+ m_object_no, image_ctx.migration_info.flatten, nullptr, ctx);
ldout(cct, 20) << "deep copy object req " << req << ", object_no "
<< m_object_no << dendl;
librados::snap_t src_snap_id_start,
librados::snap_t dst_snap_id_start,
const SnapMap &snap_map,
- uint64_t object_number, bool flatten, Context *on_finish) {
+ uint64_t object_number, bool flatten, Handler* handler,
+ Context *on_finish) {
ceph_assert(s_instance != nullptr);
std::lock_guard locker{s_instance->lock};
s_instance->snap_map = &snap_map;
expect_get_object_name(mock_dst_image_ctx);
return new MockObjectCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx,
src_snap_id_start, dst_snap_id_start,
- m_snap_map, 0, false, on_finish);
+ m_snap_map, 0, false, nullptr, on_finish);
}
void expect_set_snap_read(librados::MockTestMemIoCtxImpl &mock_io_ctx,
librados::snap_t dst_snap_id_start,
const SnapMap &snap_map,
uint64_t object_number, bool flatten,
- Context *on_finish) {
+ Handler*, Context *on_finish) {
ceph_assert(s_instance != nullptr);
s_instance->object_number = object_number;
s_instance->flatten = flatten;
DeepCopyHandler(Replayer* replayer) : replayer(replayer) {
}
+ void handle_read(uint64_t bytes_read) override {
+ }
+
int update_progress(uint64_t object_number, uint64_t object_count) override {
replayer->handle_copy_image_progress(object_number, object_count);
return 0;