1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef RBD_MIRROR_IMAGE_SYNC_IMAGE_COPY_REQUEST_H
5 #define RBD_MIRROR_IMAGE_SYNC_IMAGE_COPY_REQUEST_H
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "common/Mutex.h"
10 #include "librbd/journal/Types.h"
11 #include "librbd/journal/TypeTraits.h"
12 #include "tools/rbd_mirror/BaseRequest.h"
18 namespace journal
{ class Journaler
; }
19 namespace librbd
{ struct ImageCtx
; }
24 class ProgressContext
;
26 namespace image_sync
{
28 template <typename ImageCtxT
= librbd::ImageCtx
>
29 class ImageCopyRequest
: public BaseRequest
{
31 typedef std::vector
<librados::snap_t
> SnapIds
;
32 typedef std::map
<librados::snap_t
, SnapIds
> SnapMap
;
33 typedef librbd::journal::TypeTraits
<ImageCtxT
> TypeTraits
;
34 typedef typename
TypeTraits::Journaler Journaler
;
35 typedef librbd::journal::MirrorPeerSyncPoint MirrorPeerSyncPoint
;
36 typedef librbd::journal::MirrorPeerClientMeta MirrorPeerClientMeta
;
37 typedef rbd::mirror::ProgressContext ProgressContext
;
39 static ImageCopyRequest
* create(ImageCtxT
*local_image_ctx
,
40 ImageCtxT
*remote_image_ctx
,
41 SafeTimer
*timer
, Mutex
*timer_lock
,
43 MirrorPeerClientMeta
*client_meta
,
44 MirrorPeerSyncPoint
*sync_point
,
46 ProgressContext
*progress_ctx
= nullptr) {
47 return new ImageCopyRequest(local_image_ctx
, remote_image_ctx
, timer
,
48 timer_lock
, journaler
, client_meta
, sync_point
,
49 on_finish
, progress_ctx
);
52 ImageCopyRequest(ImageCtxT
*local_image_ctx
, ImageCtxT
*remote_image_ctx
,
53 SafeTimer
*timer
, Mutex
*timer_lock
, Journaler
*journaler
,
54 MirrorPeerClientMeta
*client_meta
,
55 MirrorPeerSyncPoint
*sync_point
, Context
*on_finish
,
56 ProgressContext
*progress_ctx
= nullptr);
59 void cancel() override
;
68 * UPDATE_MAX_OBJECT_COUNT
71 * | . . (parallel execution of
72 * v v . multiple objects at once)
84 ImageCtxT
*m_local_image_ctx
;
85 ImageCtxT
*m_remote_image_ctx
;
88 Journaler
*m_journaler
;
89 MirrorPeerClientMeta
*m_client_meta
;
90 MirrorPeerSyncPoint
*m_sync_point
;
91 ProgressContext
*m_progress_ctx
;
96 bool m_canceled
= false;
98 uint64_t m_object_no
= 0;
99 uint64_t m_end_object_no
;
100 uint64_t m_current_ops
= 0;
103 bool m_updating_sync_point
;
104 Context
*m_update_sync_ctx
;
105 double m_update_sync_point_interval
;
107 MirrorPeerClientMeta m_client_meta_copy
;
109 void send_update_max_object_count();
110 void handle_update_max_object_count(int r
);
112 void send_object_copies();
113 void send_next_object_copy();
114 void handle_object_copy(int r
);
116 void send_update_sync_point();
117 void handle_update_sync_point(int r
);
119 void send_flush_sync_point();
120 void handle_flush_sync_point(int r
);
122 int compute_snap_map();
124 void update_progress(const std::string
&description
, bool flush
= true);
127 } // namespace image_sync
128 } // namespace mirror
131 extern template class rbd::mirror::image_sync::ImageCopyRequest
<librbd::ImageCtx
>;
133 #endif // RBD_MIRROR_IMAGE_SYNC_IMAGE_COPY_REQUEST_H