]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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_MIRROR_DISABLE_REQUEST_H | |
5 | #define CEPH_LIBRBD_MIRROR_DISABLE_REQUEST_H | |
6 | ||
7 | #include "include/buffer.h" | |
9f95a23c | 8 | #include "common/ceph_mutex.h" |
7c673cae FG |
9 | #include "cls/journal/cls_journal_types.h" |
10 | #include "cls/rbd/cls_rbd_types.h" | |
9f95a23c TL |
11 | #include "librbd/mirror/Types.h" |
12 | ||
7c673cae FG |
13 | #include <map> |
14 | #include <string> | |
15 | ||
16 | class Context; | |
17 | ||
18 | namespace librbd { | |
19 | ||
20 | class ImageCtx; | |
21 | ||
22 | namespace mirror { | |
23 | ||
24 | template <typename ImageCtxT = ImageCtx> | |
25 | class DisableRequest { | |
26 | public: | |
27 | static DisableRequest *create(ImageCtxT *image_ctx, bool force, | |
28 | bool remove, Context *on_finish) { | |
29 | return new DisableRequest(image_ctx, force, remove, on_finish); | |
30 | } | |
31 | ||
32 | DisableRequest(ImageCtxT *image_ctx, bool force, bool remove, | |
33 | Context *on_finish); | |
34 | ||
35 | void send(); | |
36 | ||
37 | private: | |
38 | /** | |
39 | * @verbatim | |
40 | * | |
41 | * <start> | |
42 | * | | |
43 | * v | |
9f95a23c | 44 | * GET_MIRROR_INFO * * * * * * * * * * * * * * * * * * * * * * * |
7c673cae FG |
45 | * | * |
46 | * v * | |
9f95a23c | 47 | * IMAGE_STATE_UPDATE * * * * * * * * * * * * * * * * * * * * * * |
7c673cae FG |
48 | * | * |
49 | * v * | |
9f95a23c | 50 | * PROMOTE_IMAGE (skip if primary) * |
7c673cae FG |
51 | * | * |
52 | * v * | |
9f95a23c | 53 | * REFRESH_IMAGE (skip if necessary) * |
7c673cae FG |
54 | * | * |
55 | * v * | |
56 | * GET_CLIENTS <----------------------------------------\ * * * * | |
57 | * | | (unregister clients) | * (on error) | |
58 | * | |/----------------------------\ | * | |
59 | * | | | | * | |
60 | * | | /-----------\ (repeat | (repeat | (repeat | |
61 | * | | | | as needed) | as needed) | as needed) | |
62 | * | v v | | | * | |
63 | * | REMOVE_SYNC_SNAP --/ * * * * * * | * * * * * * | * * * * | |
64 | * | | | | * | |
65 | * | v | | * | |
66 | * | UNREGISTER_CLIENT ---------------/-------------/ * * * * | |
67 | * | * | |
68 | * | (no more clients * | |
69 | * | to unregister) * | |
70 | * v * | |
71 | * REMOVE_MIRROR_IMAGE * * * * * * * * * * * * * * * * * * * * * | |
72 | * | (skip if no remove) * | |
73 | * v * | |
7c673cae FG |
74 | * <finish> < * * * * * * * * * * * * * * * * * * * * * * * * * * |
75 | * | |
76 | * @endverbatim | |
77 | */ | |
78 | ||
79 | ImageCtxT *m_image_ctx; | |
80 | bool m_force; | |
81 | bool m_remove; | |
82 | Context *m_on_finish; | |
83 | ||
84 | bool m_is_primary = false; | |
7c673cae | 85 | cls::rbd::MirrorImage m_mirror_image; |
9f95a23c TL |
86 | PromotionState m_promotion_state = PROMOTION_STATE_NON_PRIMARY; |
87 | std::string m_primary_mirror_uuid; | |
7c673cae FG |
88 | std::set<cls::journal::Client> m_clients; |
89 | std::map<std::string, int> m_ret; | |
90 | std::map<std::string, int> m_current_ops; | |
91 | int m_error_result = 0; | |
9f95a23c TL |
92 | mutable ceph::mutex m_lock = |
93 | ceph::make_mutex("mirror::DisableRequest::m_lock"); | |
7c673cae | 94 | |
9f95a23c TL |
95 | void send_get_mirror_info(); |
96 | Context *handle_get_mirror_info(int *result); | |
7c673cae | 97 | |
9f95a23c TL |
98 | void send_image_state_update(); |
99 | Context *handle_image_state_update(int *result); | |
7c673cae FG |
100 | |
101 | void send_notify_mirroring_watcher(); | |
102 | Context *handle_notify_mirroring_watcher(int *result); | |
103 | ||
104 | void send_promote_image(); | |
105 | Context *handle_promote_image(int *result); | |
106 | ||
9f95a23c TL |
107 | void send_refresh_image(); |
108 | Context* handle_refresh_image(int* result); | |
109 | ||
110 | void clean_mirror_state(); | |
111 | ||
7c673cae FG |
112 | void send_get_clients(); |
113 | Context *handle_get_clients(int *result); | |
114 | ||
9f95a23c TL |
115 | void remove_mirror_snapshots(); |
116 | ||
7c673cae FG |
117 | void send_remove_snap(const std::string &client_id, |
118 | const cls::rbd::SnapshotNamespace &snap_namespace, | |
119 | const std::string &snap_name); | |
120 | Context *handle_remove_snap(int *result, const std::string &client_id); | |
121 | ||
122 | void send_unregister_client(const std::string &client_id); | |
123 | Context *handle_unregister_client(int *result, const std::string &client_id); | |
124 | ||
125 | void send_remove_mirror_image(); | |
126 | Context *handle_remove_mirror_image(int *result); | |
127 | ||
128 | void send_notify_mirroring_watcher_removed(); | |
129 | Context *handle_notify_mirroring_watcher_removed(int *result); | |
130 | ||
131 | Context *create_context_callback( | |
132 | Context*(DisableRequest<ImageCtxT>::*handle)( | |
133 | int*, const std::string &client_id), | |
134 | const std::string &client_id); | |
135 | ||
136 | }; | |
137 | ||
138 | } // namespace mirror | |
139 | } // namespace librbd | |
140 | ||
141 | extern template class librbd::mirror::DisableRequest<librbd::ImageCtx>; | |
142 | ||
143 | #endif // CEPH_LIBRBD_MIRROR_DISABLE_REQUEST_H |