]>
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_REQUEST_H | |
5 | #define CEPH_LIBRBD_DEEP_COPY_REQUEST_H | |
6 | ||
9f95a23c | 7 | #include "common/ceph_mutex.h" |
11fdf7f2 TL |
8 | #include "common/RefCountedObj.h" |
9 | #include "include/int_types.h" | |
10 | #include "librbd/ImageCtx.h" | |
11 | #include "librbd/Types.h" | |
12 | #include "librbd/deep_copy/Types.h" | |
13 | ||
14 | #include <map> | |
15 | #include <vector> | |
16 | ||
17 | class Context; | |
18 | ||
19 | namespace librbd { | |
20 | ||
21 | class ImageCtx; | |
22 | ||
23 | namespace deep_copy { | |
24 | ||
25 | template <typename> class ImageCopyRequest; | |
26 | template <typename> class SnapshotCopyRequest; | |
1911f103 | 27 | struct Handler; |
11fdf7f2 TL |
28 | |
29 | } | |
30 | ||
31 | template <typename ImageCtxT = ImageCtx> | |
32 | class DeepCopyRequest : public RefCountedObject { | |
33 | public: | |
34 | static DeepCopyRequest* create(ImageCtxT *src_image_ctx, | |
35 | ImageCtxT *dst_image_ctx, | |
9f95a23c TL |
36 | librados::snap_t src_snap_id_start, |
37 | librados::snap_t src_snap_id_end, | |
38 | librados::snap_t dst_snap_id_start, | |
39 | bool flatten, | |
11fdf7f2 TL |
40 | const deep_copy::ObjectNumber &object_number, |
41 | ContextWQ *work_queue, | |
42 | SnapSeqs *snap_seqs, | |
1911f103 | 43 | deep_copy::Handler *handler, |
11fdf7f2 | 44 | Context *on_finish) { |
9f95a23c TL |
45 | return new DeepCopyRequest(src_image_ctx, dst_image_ctx, src_snap_id_start, |
46 | src_snap_id_end, dst_snap_id_start, flatten, | |
1911f103 | 47 | object_number, work_queue, snap_seqs, handler, |
9f95a23c | 48 | on_finish); |
11fdf7f2 TL |
49 | } |
50 | ||
51 | DeepCopyRequest(ImageCtxT *src_image_ctx, ImageCtxT *dst_image_ctx, | |
9f95a23c TL |
52 | librados::snap_t src_snap_id_start, |
53 | librados::snap_t src_snap_id_end, | |
54 | librados::snap_t dst_snap_id_start, | |
11fdf7f2 TL |
55 | bool flatten, const deep_copy::ObjectNumber &object_number, |
56 | ContextWQ *work_queue, SnapSeqs *snap_seqs, | |
1911f103 | 57 | deep_copy::Handler *handler, Context *on_finish); |
11fdf7f2 TL |
58 | ~DeepCopyRequest(); |
59 | ||
60 | void send(); | |
61 | void cancel(); | |
62 | ||
63 | private: | |
64 | /** | |
65 | * @verbatim | |
66 | * | |
67 | * <start> | |
68 | * | | |
69 | * v | |
70 | * COPY_SNAPSHOTS | |
71 | * | | |
72 | * v | |
73 | * COPY_IMAGE . . . . . . . . . . . . . . | |
74 | * | . | |
75 | * v . | |
76 | * COPY_OBJECT_MAP (skip if object . | |
77 | * | map disabled) . | |
78 | * v . | |
79 | * REFRESH_OBJECT_MAP (skip if object . (image copy canceled) | |
80 | * | map disabled) . | |
81 | * v . | |
82 | * COPY_METADATA . | |
83 | * | . | |
84 | * v . | |
85 | * <finish> < . . . . . . . . . . . . . . | |
86 | * | |
87 | * @endverbatim | |
88 | */ | |
89 | ||
90 | typedef std::vector<librados::snap_t> SnapIds; | |
91 | typedef std::map<librados::snap_t, SnapIds> SnapMap; | |
92 | ||
93 | ImageCtxT *m_src_image_ctx; | |
94 | ImageCtxT *m_dst_image_ctx; | |
9f95a23c TL |
95 | librados::snap_t m_src_snap_id_start; |
96 | librados::snap_t m_src_snap_id_end; | |
97 | librados::snap_t m_dst_snap_id_start; | |
11fdf7f2 TL |
98 | bool m_flatten; |
99 | deep_copy::ObjectNumber m_object_number; | |
100 | ContextWQ *m_work_queue; | |
101 | SnapSeqs *m_snap_seqs; | |
1911f103 | 102 | deep_copy::Handler *m_handler; |
11fdf7f2 TL |
103 | Context *m_on_finish; |
104 | ||
105 | CephContext *m_cct; | |
9f95a23c | 106 | ceph::mutex m_lock; |
11fdf7f2 TL |
107 | bool m_canceled = false; |
108 | ||
109 | deep_copy::SnapshotCopyRequest<ImageCtxT> *m_snapshot_copy_request = nullptr; | |
110 | deep_copy::ImageCopyRequest<ImageCtxT> *m_image_copy_request = nullptr; | |
111 | decltype(ImageCtxT::object_map) m_object_map = nullptr; | |
112 | ||
113 | void send_copy_snapshots(); | |
114 | void handle_copy_snapshots(int r); | |
115 | ||
116 | void send_copy_image(); | |
117 | void handle_copy_image(int r); | |
118 | ||
119 | void send_copy_object_map(); | |
120 | void handle_copy_object_map(int r); | |
121 | ||
122 | void send_refresh_object_map(); | |
123 | void handle_refresh_object_map(int r); | |
124 | ||
125 | void send_copy_metadata(); | |
126 | void handle_copy_metadata(int r); | |
127 | ||
128 | int validate_copy_points(); | |
129 | ||
130 | void finish(int r); | |
131 | }; | |
132 | ||
133 | } // namespace librbd | |
134 | ||
135 | extern template class librbd::DeepCopyRequest<librbd::ImageCtx>; | |
136 | ||
137 | #endif // CEPH_LIBRBD_DEEP_COPY_REQUEST_H |