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