]>
Commit | Line | Data |
---|---|---|
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef RBD_MIRROR_IMAGE_SYNC_SNAPSHOT_COPY_REQUEST_H | |
5 | #define RBD_MIRROR_IMAGE_SYNC_SNAPSHOT_COPY_REQUEST_H | |
6 | ||
7 | #include "include/int_types.h" | |
8 | #include "include/rados/librados.hpp" | |
9 | #include "common/snap_types.h" | |
10 | #include "librbd/ImageCtx.h" | |
11 | #include "librbd/Types.h" | |
12 | #include "librbd/journal/TypeTraits.h" | |
13 | #include "tools/rbd_mirror/BaseRequest.h" | |
14 | #include <map> | |
15 | #include <set> | |
16 | #include <string> | |
17 | #include <tuple> | |
18 | ||
19 | class Context; | |
20 | class ContextWQ; | |
21 | namespace journal { class Journaler; } | |
22 | namespace librbd { namespace journal { struct MirrorPeerClientMeta; } } | |
23 | ||
24 | namespace rbd { | |
25 | namespace mirror { | |
26 | namespace image_sync { | |
27 | ||
28 | template <typename ImageCtxT = librbd::ImageCtx> | |
29 | class SnapshotCopyRequest : public BaseRequest { | |
30 | public: | |
31 | typedef librbd::journal::TypeTraits<ImageCtxT> TypeTraits; | |
32 | typedef typename TypeTraits::Journaler Journaler; | |
33 | ||
34 | typedef std::vector<librados::snap_t> SnapIds; | |
35 | typedef std::map<librados::snap_t, SnapIds> SnapMap; | |
36 | ||
37 | static SnapshotCopyRequest* create(ImageCtxT *local_image_ctx, | |
38 | ImageCtxT *remote_image_ctx, | |
39 | SnapMap *snap_map, Journaler *journaler, | |
40 | librbd::journal::MirrorPeerClientMeta *client_meta, | |
41 | ContextWQ *work_queue, | |
42 | Context *on_finish) { | |
43 | return new SnapshotCopyRequest(local_image_ctx, remote_image_ctx, | |
44 | snap_map, journaler, client_meta, work_queue, | |
45 | on_finish); | |
46 | } | |
47 | ||
48 | SnapshotCopyRequest(ImageCtxT *local_image_ctx, ImageCtxT *remote_image_ctx, | |
49 | SnapMap *snap_map, Journaler *journaler, | |
50 | librbd::journal::MirrorPeerClientMeta *client_meta, | |
51 | ContextWQ *work_queue, Context *on_finish); | |
52 | ||
53 | void send() override; | |
54 | void cancel() override; | |
55 | ||
56 | private: | |
57 | /** | |
58 | * @verbatim | |
59 | * | |
60 | * <start> | |
61 | * | | |
62 | * | /-----------\ | |
63 | * | | | | |
64 | * v v | (repeat as needed) | |
65 | * UNPROTECT_SNAP ----/ | |
66 | * | | |
67 | * | /-----------\ | |
68 | * | | | | |
69 | * v v | (repeat as needed) | |
70 | * REMOVE_SNAP -------/ | |
71 | * | | |
72 | * | /-----------\ | |
73 | * | | | | |
74 | * v v | (repeat as needed) | |
75 | * CREATE_SNAP -------/ | |
76 | * | | |
77 | * | /-----------\ | |
78 | * | | | | |
79 | * v v | (repeat as needed) | |
80 | * PROTECT_SNAP ------/ | |
81 | * | | |
82 | * v | |
83 | * UPDATE_CLIENT | |
84 | * | | |
85 | * v | |
86 | * <finish> | |
87 | * | |
88 | * @endverbatim | |
89 | */ | |
90 | ||
91 | typedef std::set<librados::snap_t> SnapIdSet; | |
92 | typedef std::map<librados::snap_t, librados::snap_t> SnapSeqs; | |
93 | ||
94 | ImageCtxT *m_local_image_ctx; | |
95 | ImageCtxT *m_remote_image_ctx; | |
96 | SnapMap *m_snap_map; | |
97 | Journaler *m_journaler; | |
98 | librbd::journal::MirrorPeerClientMeta *m_client_meta; | |
99 | ContextWQ *m_work_queue; | |
100 | ||
101 | SnapIdSet m_local_snap_ids; | |
102 | SnapIdSet m_remote_snap_ids; | |
103 | SnapSeqs m_snap_seqs; | |
104 | librados::snap_t m_prev_snap_id = CEPH_NOSNAP; | |
105 | ||
106 | std::string m_snap_name; | |
107 | cls::rbd::SnapshotNamespace m_snap_namespace; | |
108 | ||
109 | librbd::ParentSpec m_local_parent_spec; | |
110 | ||
111 | Mutex m_lock; | |
112 | bool m_canceled = false; | |
113 | ||
114 | void send_snap_unprotect(); | |
115 | void handle_snap_unprotect(int r); | |
116 | ||
117 | void send_snap_remove(); | |
118 | void handle_snap_remove(int r); | |
119 | ||
120 | void send_snap_create(); | |
121 | void handle_snap_create(int r); | |
122 | ||
123 | void send_snap_protect(); | |
124 | void handle_snap_protect(int r); | |
125 | ||
126 | void send_update_client(); | |
127 | void handle_update_client(int r); | |
128 | ||
129 | bool handle_cancellation(); | |
130 | ||
131 | void error(int r); | |
132 | ||
133 | void compute_snap_map(); | |
134 | ||
135 | int validate_parent(ImageCtxT *image_ctx, librbd::ParentSpec *spec); | |
136 | ||
137 | Context *start_local_op(); | |
138 | ||
139 | }; | |
140 | ||
141 | } // namespace image_sync | |
142 | } // namespace mirror | |
143 | } // namespace rbd | |
144 | ||
145 | extern template class rbd::mirror::image_sync::SnapshotCopyRequest<librbd::ImageCtx>; | |
146 | ||
147 | #endif // RBD_MIRROR_IMAGE_SYNC_SNAPSHOT_COPY_REQUEST_H |