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_OBJECT_COPY_REQUEST_H
5 #define RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "common/snap_types.h"
10 #include "librbd/ImageCtx.h"
21 namespace image_sync
{
23 template <typename ImageCtxT
= librbd::ImageCtx
>
24 class ObjectCopyRequest
{
26 typedef std::vector
<librados::snap_t
> SnapIds
;
27 typedef std::map
<librados::snap_t
, SnapIds
> SnapMap
;
29 static ObjectCopyRequest
* create(ImageCtxT
*local_image_ctx
,
30 ImageCtxT
*remote_image_ctx
,
31 const SnapMap
*snap_map
,
32 uint64_t object_number
, Context
*on_finish
) {
33 return new ObjectCopyRequest(local_image_ctx
, remote_image_ctx
, snap_map
,
34 object_number
, on_finish
);
37 ObjectCopyRequest(ImageCtxT
*local_image_ctx
, ImageCtxT
*remote_image_ctx
,
38 const SnapMap
*snap_map
, uint64_t object_number
,
44 inline librados::IoCtx
&get_local_io_ctx() {
45 return m_local_io_ctx
;
47 inline librados::IoCtx
&get_remote_io_ctx() {
48 return m_remote_io_ctx
;
59 * | * (-ENOENT and snap set stale)
63 * READ_OBJECT <--------\
64 * | | (repeat for each snapshot)
66 * WRITE_OBJECT --------/
69 * | | | (repeat for each snapshot)
71 * UPDATE_OBJECT_MAP ---/ (skip if object
86 typedef std::map
<uint64_t, uint64_t> ExtentMap
;
89 SyncOp(SyncOpType type
, uint64_t offset
, uint64_t length
)
90 : type(type
), offset(offset
), length(length
) {
101 typedef std::list
<SyncOp
> SyncOps
;
102 typedef std::pair
<librados::snap_t
, librados::snap_t
> WriteReadSnapIds
;
103 typedef std::map
<WriteReadSnapIds
, SyncOps
> SnapSyncOps
;
104 typedef std::map
<librados::snap_t
, uint8_t> SnapObjectStates
;
105 typedef std::map
<librados::snap_t
, uint64_t> SnapObjectSizes
;
107 ImageCtxT
*m_local_image_ctx
;
108 ImageCtxT
*m_remote_image_ctx
;
109 const SnapMap
*m_snap_map
;
110 uint64_t m_object_number
;
111 Context
*m_on_finish
;
113 decltype(m_local_image_ctx
->data_ctx
) m_local_io_ctx
;
114 decltype(m_remote_image_ctx
->data_ctx
) m_remote_io_ctx
;
115 std::string m_local_oid
;
116 std::string m_remote_oid
;
118 librados::snap_set_t m_snap_set
;
121 bool m_retry_missing_read
= false;
122 librados::snap_set_t m_retry_snap_set
;
123 std::map
<librados::snap_t
, bool> m_read_whole_object
;
125 SnapSyncOps m_snap_sync_ops
;
126 SnapObjectStates m_snap_object_states
;
127 SnapObjectSizes m_snap_object_sizes
;
129 void send_list_snaps();
130 void handle_list_snaps(int r
);
132 void send_read_object();
133 void handle_read_object(int r
);
135 void send_write_object();
136 void handle_write_object(int r
);
138 void send_update_object_map();
139 void handle_update_object_map(int r
);
141 Context
*start_local_op(RWLock
&owner_lock
);
143 void compute_diffs();
148 } // namespace image_sync
149 } // namespace mirror
152 extern template class rbd::mirror::image_sync::ObjectCopyRequest
<librbd::ImageCtx
>;
154 #endif // RBD_MIRROR_IMAGE_SYNC_OBJECT_COPY_REQUEST_H