Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / operation / EnableFeaturesRequest.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_OPERATION_ENABLE_FEATURES_REQUEST_H
5 #define CEPH_LIBRBD_OPERATION_ENABLE_FEATURES_REQUEST_H
6
7 #include "librbd/operation/Request.h"
8
9 class Context;
10
11 namespace librbd {
12
13 class ImageCtx;
14
15 namespace operation {
16
17 template <typename ImageCtxT = ImageCtx>
18 class EnableFeaturesRequest : public Request<ImageCtxT> {
19 public:
20   static EnableFeaturesRequest *create(ImageCtxT &image_ctx, Context *on_finish,
21                                        uint64_t journal_op_tid,
22                                        uint64_t features) {
23     return new EnableFeaturesRequest(image_ctx, on_finish, journal_op_tid,
24                                      features);
25   }
26
27   EnableFeaturesRequest(ImageCtxT &image_ctx, Context *on_finish,
28                         uint64_t journal_op_tid, uint64_t features);
29
30 protected:
31   void send_op() override;
32   bool should_complete(int r) override;
33   bool can_affect_io() const override {
34     return true;
35   }
36   journal::Event create_event(uint64_t op_tid) const override {
37     return journal::UpdateFeaturesEvent(op_tid, m_features, true);
38   }
39
40 private:
41   /**
42    * EnableFeatures goes through the following state machine:
43    *
44    * @verbatim
45    *
46    * <start>
47    *    |
48    *    v
49    * STATE_PREPARE_LOCK
50    *    |
51    *    v
52    * STATE_BLOCK_WRITES
53    *    |
54    *    v
55    * STATE_GET_MIRROR_MODE
56    *    |
57    *    v
58    * STATE_CREATE_JOURNAL (skip if not
59    *    |                  required)
60    *    v
61    * STATE_APPEND_OP_EVENT (skip if journaling
62    *    |                   disabled)
63    *    v
64    * STATE_UPDATE_FLAGS
65    *    |
66    *    v
67    * STATE_SET_FEATURES
68    *    |
69    *    v
70    * STATE_CREATE_OBJECT_MAP (skip if not
71    *    |                     required)
72    *    v
73    * STATE_ENABLE_MIRROR_IMAGE
74    *    |
75    *    V
76    * STATE_NOTIFY_UPDATE
77    *    |
78    *    | (unblock writes)
79    *    v
80    * <finish>
81    * @endverbatim
82    *
83    */
84
85   uint64_t m_features;
86
87   bool m_enable_mirroring = false;
88   bool m_requests_blocked = false;
89   bool m_writes_blocked = false;
90
91   uint64_t m_new_features = 0;
92   uint64_t m_enable_flags = 0;
93   uint64_t m_features_mask = 0;
94
95   bufferlist m_out_bl;
96
97   void send_prepare_lock();
98   Context *handle_prepare_lock(int *result);
99
100   void send_block_writes();
101   Context *handle_block_writes(int *result);
102
103   void send_get_mirror_mode();
104   Context *handle_get_mirror_mode(int *result);
105
106   void send_create_journal();
107   Context *handle_create_journal(int *result);
108
109   void send_append_op_event();
110   Context *handle_append_op_event(int *result);
111
112   void send_update_flags();
113   Context *handle_update_flags(int *result);
114
115   void send_set_features();
116   Context *handle_set_features(int *result);
117
118   void send_create_object_map();
119   Context *handle_create_object_map(int *result);
120
121   void send_enable_mirror_image();
122   Context *handle_enable_mirror_image(int *result);
123
124   void send_notify_update();
125   Context *handle_notify_update(int *result);
126
127   Context *handle_finish(int r);
128 };
129
130 } // namespace operation
131 } // namespace librbd
132
133 extern template class librbd::operation::EnableFeaturesRequest<librbd::ImageCtx>;
134
135 #endif // CEPH_LIBRBD_OPERATION_ENABLE_FEATURES_REQUEST_H