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