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