]>
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_IMAGE_DEEP_COPY_REQUEST_H | |
5 | #define CEPH_LIBRBD_DEEP_COPY_IMAGE_DEEP_COPY_REQUEST_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include "include/rados/librados.hpp" | |
9f95a23c TL |
9 | #include "common/bit_vector.hpp" |
10 | #include "common/ceph_mutex.h" | |
11fdf7f2 TL |
11 | #include "common/RefCountedObj.h" |
12 | #include "librbd/Types.h" | |
13 | #include "librbd/deep_copy/Types.h" | |
14 | #include <functional> | |
15 | #include <map> | |
16 | #include <queue> | |
17 | #include <vector> | |
18 | #include <boost/optional.hpp> | |
19 | ||
20 | class Context; | |
21 | ||
22 | namespace librbd { | |
23 | ||
24 | class ImageCtx; | |
11fdf7f2 TL |
25 | |
26 | namespace deep_copy { | |
27 | ||
1911f103 TL |
28 | class Handler; |
29 | ||
11fdf7f2 TL |
30 | template <typename ImageCtxT = ImageCtx> |
31 | class ImageCopyRequest : public RefCountedObject { | |
32 | public: | |
33 | static ImageCopyRequest* create(ImageCtxT *src_image_ctx, | |
34 | ImageCtxT *dst_image_ctx, | |
9f95a23c TL |
35 | librados::snap_t src_snap_id_start, |
36 | librados::snap_t src_snap_id_end, | |
37 | librados::snap_t dst_snap_id_start, | |
38 | bool flatten, | |
11fdf7f2 TL |
39 | const ObjectNumber &object_number, |
40 | const SnapSeqs &snap_seqs, | |
1911f103 | 41 | Handler *handler, |
11fdf7f2 | 42 | Context *on_finish) { |
9f95a23c TL |
43 | return new ImageCopyRequest(src_image_ctx, dst_image_ctx, src_snap_id_start, |
44 | src_snap_id_end, dst_snap_id_start, flatten, | |
1911f103 | 45 | object_number, snap_seqs, handler, on_finish); |
11fdf7f2 TL |
46 | } |
47 | ||
48 | ImageCopyRequest(ImageCtxT *src_image_ctx, ImageCtxT *dst_image_ctx, | |
9f95a23c TL |
49 | librados::snap_t src_snap_id_start, |
50 | librados::snap_t src_snap_id_end, | |
51 | librados::snap_t dst_snap_id_start, | |
11fdf7f2 | 52 | bool flatten, const ObjectNumber &object_number, |
1911f103 | 53 | const SnapSeqs &snap_seqs, Handler *handler, |
11fdf7f2 TL |
54 | Context *on_finish); |
55 | ||
56 | void send(); | |
57 | void cancel(); | |
58 | ||
59 | private: | |
60 | /** | |
61 | * @verbatim | |
62 | * | |
63 | * <start> | |
9f95a23c TL |
64 | * | |
65 | * v | |
66 | * COMPUTE_DIFF | |
67 | * | | |
11fdf7f2 TL |
68 | * | . . . . . |
69 | * | . . (parallel execution of | |
70 | * v v . multiple objects at once) | |
71 | * COPY_OBJECT . . . . | |
72 | * | | |
73 | * v | |
74 | * <finish> | |
75 | * | |
76 | * @endverbatim | |
77 | */ | |
78 | ||
79 | ImageCtxT *m_src_image_ctx; | |
80 | ImageCtxT *m_dst_image_ctx; | |
9f95a23c TL |
81 | librados::snap_t m_src_snap_id_start; |
82 | librados::snap_t m_src_snap_id_end; | |
83 | librados::snap_t m_dst_snap_id_start; | |
11fdf7f2 TL |
84 | bool m_flatten; |
85 | ObjectNumber m_object_number; | |
86 | SnapSeqs m_snap_seqs; | |
1911f103 | 87 | Handler *m_handler; |
11fdf7f2 TL |
88 | Context *m_on_finish; |
89 | ||
90 | CephContext *m_cct; | |
9f95a23c | 91 | ceph::mutex m_lock; |
11fdf7f2 TL |
92 | bool m_canceled = false; |
93 | ||
94 | uint64_t m_object_no = 0; | |
95 | uint64_t m_end_object_no = 0; | |
96 | uint64_t m_current_ops = 0; | |
97 | std::priority_queue< | |
98 | uint64_t, std::vector<uint64_t>, std::greater<uint64_t>> m_copied_objects; | |
99 | bool m_updating_progress = false; | |
100 | SnapMap m_snap_map; | |
101 | int m_ret_val = 0; | |
102 | ||
9f95a23c TL |
103 | BitVector<2> m_object_diff_state; |
104 | ||
105 | void compute_diff(); | |
106 | void handle_compute_diff(int r); | |
107 | ||
11fdf7f2 | 108 | void send_object_copies(); |
9f95a23c | 109 | int send_next_object_copy(); |
11fdf7f2 TL |
110 | void handle_object_copy(uint64_t object_no, int r); |
111 | ||
112 | void finish(int r); | |
113 | }; | |
114 | ||
115 | } // namespace deep_copy | |
116 | } // namespace librbd | |
117 | ||
118 | extern template class librbd::deep_copy::ImageCopyRequest<librbd::ImageCtx>; | |
119 | ||
120 | #endif // CEPH_LIBRBD_DEEP_COPY_IMAGE_DEEP_COPY_REQUEST_H |