]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/deep_copy/SnapshotCopyRequest.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / deep_copy / SnapshotCopyRequest.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_SNAPSHOT_COPY_REQUEST_H
5 #define CEPH_LIBRBD_DEEP_COPY_SNAPSHOT_COPY_REQUEST_H
6
7 #include "include/int_types.h"
8 #include "include/rados/librados.hpp"
9 #include "common/RefCountedObj.h"
10 #include "common/snap_types.h"
11 #include "librbd/ImageCtx.h"
12 #include "librbd/Types.h"
13 #include <map>
14 #include <set>
15 #include <string>
16 #include <tuple>
17
18 class Context;
19
20 namespace librbd {
21
22 namespace asio { struct ContextWQ; }
23
24 namespace deep_copy {
25
26 template <typename ImageCtxT = librbd::ImageCtx>
27 class SnapshotCopyRequest : public RefCountedObject {
28 public:
29 static SnapshotCopyRequest* create(ImageCtxT *src_image_ctx,
30 ImageCtxT *dst_image_ctx,
31 librados::snap_t src_snap_id_start,
32 librados::snap_t src_snap_id_end,
33 librados::snap_t dst_snap_id_start,
34 bool flatten, asio::ContextWQ *work_queue,
35 SnapSeqs *snap_seqs, Context *on_finish) {
36 return new SnapshotCopyRequest(src_image_ctx, dst_image_ctx,
37 src_snap_id_start, src_snap_id_end,
38 dst_snap_id_start, flatten, work_queue,
39 snap_seqs, on_finish);
40 }
41
42 SnapshotCopyRequest(ImageCtxT *src_image_ctx, ImageCtxT *dst_image_ctx,
43 librados::snap_t src_snap_id_start,
44 librados::snap_t src_snap_id_end,
45 librados::snap_t dst_snap_id_start,
46 bool flatten, asio::ContextWQ *work_queue,
47 SnapSeqs *snap_seqs, Context *on_finish);
48
49 void send();
50 void cancel();
51
52 private:
53 /**
54 * @verbatim
55 *
56 * <start>
57 * |
58 * | /-----------\
59 * | | |
60 * v v | (repeat as needed)
61 * UNPROTECT_SNAP ----/
62 * |
63 * | /-----------\
64 * | | |
65 * v v | (repeat as needed)
66 * REMOVE_SNAP -------/
67 * |
68 * | /-----------\
69 * | | |
70 * v v | (repeat as needed)
71 * CREATE_SNAP -------/
72 * |
73 * | /-----------\
74 * | | |
75 * v v | (repeat as needed)
76 * PROTECT_SNAP ------/
77 * |
78 * v
79 * SET_HEAD (skip if not needed)
80 * |
81 * v
82 * RESIZE_OBJECT_MAP (skip if not needed)
83 * |
84 * v
85 * <finish>
86 *
87 * @endverbatim
88 */
89
90 typedef std::set<librados::snap_t> SnapIdSet;
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 asio::ContextWQ *m_work_queue;
99 SnapSeqs *m_snap_seqs_result;
100 SnapSeqs m_snap_seqs;
101 Context *m_on_finish;
102
103 CephContext *m_cct;
104 SnapIdSet m_src_snap_ids;
105 SnapIdSet m_dst_snap_ids;
106 librados::snap_t m_prev_snap_id = CEPH_NOSNAP;
107
108 std::string m_snap_name;
109 cls::rbd::SnapshotNamespace m_snap_namespace;
110
111 cls::rbd::ParentImageSpec m_dst_parent_spec;
112
113 ceph::mutex m_lock;
114 bool m_canceled = false;
115
116 void send_snap_unprotect();
117 void handle_snap_unprotect(int r);
118
119 void send_snap_remove();
120 void handle_snap_remove(int r);
121
122 void send_snap_create();
123 void handle_snap_create(int r);
124
125 void send_snap_protect();
126 void handle_snap_protect(int r);
127
128 void send_set_head();
129 void handle_set_head(int r);
130
131 void send_resize_object_map();
132 void handle_resize_object_map(int r);
133
134 bool handle_cancellation();
135
136 void error(int r);
137
138 int validate_parent(ImageCtxT *image_ctx, cls::rbd::ParentImageSpec *spec);
139
140 Context *start_lock_op(int* r);
141 Context *start_lock_op(ceph::shared_mutex &owner_locki, int* r);
142
143 void finish(int r);
144 };
145
146 } // namespace deep_copy
147 } // namespace librbd
148
149 extern template class librbd::deep_copy::SnapshotCopyRequest<librbd::ImageCtx>;
150
151 #endif // CEPH_LIBRBD_DEEP_COPY_SNAPSHOT_COPY_REQUEST_H