]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPH_LIBRBD_DEEP_COPY_OBJECT_COPY_REQUEST_H | |
5 | #define CEPH_LIBRBD_DEEP_COPY_OBJECT_COPY_REQUEST_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include "include/interval_set.h" | |
9 | #include "include/rados/librados.hpp" | |
10 | #include "common/snap_types.h" | |
11 | #include "librbd/ImageCtx.h" | |
12 | #include "librbd/deep_copy/Types.h" | |
13 | #include "librbd/io/Types.h" | |
14 | #include <list> | |
15 | #include <map> | |
16 | #include <string> | |
17 | ||
18 | class Context; | |
19 | class RWLock; | |
20 | ||
21 | namespace librbd { | |
81eedcae TL |
22 | |
23 | namespace io { class AsyncOperation; } | |
24 | ||
11fdf7f2 TL |
25 | namespace deep_copy { |
26 | ||
1911f103 TL |
27 | struct Handler; |
28 | ||
11fdf7f2 TL |
29 | template <typename ImageCtxT = librbd::ImageCtx> |
30 | class ObjectCopyRequest { | |
31 | public: | |
32 | static ObjectCopyRequest* create(ImageCtxT *src_image_ctx, | |
33 | ImageCtxT *dst_image_ctx, | |
9f95a23c TL |
34 | librados::snap_t src_snap_id_start, |
35 | librados::snap_t dst_snap_id_start, | |
11fdf7f2 | 36 | const SnapMap &snap_map, |
cd265ab1 | 37 | uint64_t object_number, uint32_t flags, |
1911f103 | 38 | Handler* handler, Context *on_finish) { |
9f95a23c TL |
39 | return new ObjectCopyRequest(src_image_ctx, dst_image_ctx, |
40 | src_snap_id_start, dst_snap_id_start, snap_map, | |
cd265ab1 | 41 | object_number, flags, handler, on_finish); |
11fdf7f2 TL |
42 | } |
43 | ||
44 | ObjectCopyRequest(ImageCtxT *src_image_ctx, ImageCtxT *dst_image_ctx, | |
9f95a23c TL |
45 | librados::snap_t src_snap_id_start, |
46 | librados::snap_t dst_snap_id_start, const SnapMap &snap_map, | |
cd265ab1 | 47 | uint64_t object_number, uint32_t flags, Handler* handler, |
1911f103 | 48 | Context *on_finish); |
11fdf7f2 TL |
49 | |
50 | void send(); | |
51 | ||
52 | // testing support | |
53 | inline librados::IoCtx &get_src_io_ctx() { | |
54 | return m_src_io_ctx; | |
55 | } | |
56 | inline librados::IoCtx &get_dst_io_ctx() { | |
57 | return m_dst_io_ctx; | |
58 | } | |
59 | ||
60 | private: | |
61 | /** | |
62 | * @verbatim | |
63 | * | |
64 | * <start> | |
f67539c2 | 65 | * | |
11fdf7f2 | 66 | * v |
f67539c2 TL |
67 | * LIST_SNAPS |
68 | * | | |
69 | * |/---------\ | |
70 | * | | (repeat for each snapshot) | |
71 | * v | | |
72 | * READ ---------/ | |
11fdf7f2 TL |
73 | * | |
74 | * | /-----------\ | |
75 | * | | | (repeat for each snapshot) | |
76 | * v v | | |
cd265ab1 TL |
77 | * UPDATE_OBJECT_MAP ---/ (skip if object |
78 | * | map disabled) | |
11fdf7f2 TL |
79 | * | /-----------\ |
80 | * | | | (repeat for each snapshot) | |
81 | * v v | | |
cd265ab1 TL |
82 | * WRITE_OBJECT --------/ |
83 | * | | |
11fdf7f2 TL |
84 | * v |
85 | * <finish> | |
86 | * | |
87 | * @endverbatim | |
88 | */ | |
89 | ||
f67539c2 TL |
90 | enum WriteOpType { |
91 | WRITE_OP_TYPE_WRITE, | |
92 | WRITE_OP_TYPE_ZERO | |
11fdf7f2 TL |
93 | }; |
94 | ||
f67539c2 TL |
95 | struct ReadOp { |
96 | interval_set<uint64_t> image_interval; | |
97 | io::Extents image_extent_map; | |
11fdf7f2 TL |
98 | bufferlist out_bl; |
99 | }; | |
100 | ||
11fdf7f2 | 101 | typedef std::pair<librados::snap_t, librados::snap_t> WriteReadSnapIds; |
11fdf7f2 TL |
102 | |
103 | ImageCtxT *m_src_image_ctx; | |
104 | ImageCtxT *m_dst_image_ctx; | |
105 | CephContext *m_cct; | |
9f95a23c TL |
106 | librados::snap_t m_src_snap_id_start; |
107 | librados::snap_t m_dst_snap_id_start; | |
11fdf7f2 TL |
108 | SnapMap m_snap_map; |
109 | uint64_t m_dst_object_number; | |
cd265ab1 | 110 | uint32_t m_flags; |
1911f103 | 111 | Handler* m_handler; |
11fdf7f2 TL |
112 | Context *m_on_finish; |
113 | ||
114 | decltype(m_src_image_ctx->data_ctx) m_src_io_ctx; | |
115 | decltype(m_dst_image_ctx->data_ctx) m_dst_io_ctx; | |
116 | std::string m_dst_oid; | |
117 | ||
f67539c2 | 118 | io::Extents m_image_extents; |
1e59de90 | 119 | io::ImageArea m_image_area = io::ImageArea::DATA; |
f67539c2 TL |
120 | |
121 | io::SnapshotDelta m_snapshot_delta; | |
122 | ||
123 | std::map<WriteReadSnapIds, ReadOp> m_read_ops; | |
11fdf7f2 | 124 | std::list<WriteReadSnapIds> m_read_snaps; |
f67539c2 TL |
125 | io::SnapshotSparseBufferlist m_snapshot_sparse_bufferlist; |
126 | ||
127 | std::map<librados::snap_t, interval_set<uint64_t>> m_dst_data_interval; | |
11fdf7f2 TL |
128 | std::map<librados::snap_t, interval_set<uint64_t>> m_dst_zero_interval; |
129 | std::map<librados::snap_t, uint8_t> m_dst_object_state; | |
130 | std::map<librados::snap_t, bool> m_dst_object_may_exist; | |
11fdf7f2 | 131 | |
81eedcae TL |
132 | io::AsyncOperation* m_src_async_op = nullptr; |
133 | ||
11fdf7f2 TL |
134 | void send_list_snaps(); |
135 | void handle_list_snaps(int r); | |
136 | ||
f67539c2 TL |
137 | void send_read(); |
138 | void handle_read(int r); | |
11fdf7f2 | 139 | |
11fdf7f2 TL |
140 | void send_update_object_map(); |
141 | void handle_update_object_map(int r); | |
142 | ||
f67539c2 | 143 | void process_copyup(); |
cd265ab1 TL |
144 | void send_write_object(); |
145 | void handle_write_object(int r); | |
146 | ||
9f95a23c | 147 | Context *start_lock_op(ceph::shared_mutex &owner_lock, int* r); |
11fdf7f2 | 148 | |
11fdf7f2 | 149 | void compute_read_ops(); |
11fdf7f2 TL |
150 | void merge_write_ops(); |
151 | void compute_zero_ops(); | |
152 | ||
153 | void compute_dst_object_may_exist(); | |
154 | ||
155 | void finish(int r); | |
156 | }; | |
157 | ||
158 | } // namespace deep_copy | |
159 | } // namespace librbd | |
160 | ||
161 | extern template class librbd::deep_copy::ObjectCopyRequest<librbd::ImageCtx>; | |
162 | ||
163 | #endif // CEPH_LIBRBD_DEEP_COPY_OBJECT_COPY_REQUEST_H |