]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/operation/DisableFeaturesRequest.h
623eb1f87dca6614eff6222ab73ad68ea5aa924e
[ceph.git] / ceph / src / librbd / operation / DisableFeaturesRequest.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_DISABLE_FEATURES_REQUEST_H
5 #define CEPH_LIBRBD_OPERATION_DISABLE_FEATURES_REQUEST_H
6
7 #include "librbd/operation/Request.h"
8 #include "cls/rbd/cls_rbd_client.h"
9
10 class Context;
11
12 namespace librbd {
13
14 class ImageCtx;
15
16 namespace operation {
17
18 template <typename ImageCtxT = ImageCtx>
19 class DisableFeaturesRequest : public Request<ImageCtxT> {
20 public:
21 static DisableFeaturesRequest *create(ImageCtxT &image_ctx, Context *on_finish,
22 uint64_t journal_op_tid,
23 uint64_t features, bool force) {
24 return new DisableFeaturesRequest(image_ctx, on_finish, journal_op_tid,
25 features, force);
26 }
27
28 DisableFeaturesRequest(ImageCtxT &image_ctx, Context *on_finish,
29 uint64_t journal_op_tid, uint64_t features, bool force);
30
31 protected:
32 void send_op() override;
33 bool should_complete(int r) override;
34 bool can_affect_io() const override {
35 return true;
36 }
37 journal::Event create_event(uint64_t op_tid) const override {
38 return journal::UpdateFeaturesEvent(op_tid, m_features, false);
39 }
40
41 private:
42 /**
43 * DisableFeatures goes through the following state machine:
44 *
45 * @verbatim
46 *
47 * <start>
48 * |
49 * v
50 * STATE_PREPARE_LOCK
51 * |
52 * v
53 * STATE_BLOCK_WRITES
54 * |
55 * v
56 * STATE_ACQUIRE_EXCLUSIVE_LOCK (skip if not
57 * | required)
58 * | (disbling journaling)
59 * \-------------------\
60 * | |
61 * | V
62 * | STATE_GET_MIRROR_MODE
63 * |(not |
64 * | disabling v
65 * | journaling) STATE_GET_MIRROR_IMAGE
66 * | |
67 * | v
68 * | STATE_DISABLE_MIRROR_IMAGE (skip if not
69 * | | required)
70 * | v
71 * | STATE_CLOSE_JOURNAL
72 * | |
73 * | v
74 * | STATE_REMOVE_JOURNAL
75 * | |
76 * |/-------------------/
77 * |
78 * v
79 * STATE_APPEND_OP_EVENT (skip if journaling
80 * | disabled)
81 * v
82 * STATE_REMOVE_OBJECT_MAP (skip if not
83 * | disabling object map)
84 * v
85 * STATE_SET_FEATURES
86 * |
87 * v
88 * STATE_UPDATE_FLAGS
89 * |
90 * v
91 * STATE_NOTIFY_UPDATE
92 * |
93 * v
94 * STATE_REALEASE_EXCLUSIVE_LOCK (skip if not
95 * | required)
96 * | (unblock writes)
97 * v
98 * <finish>
99 *
100 * @endverbatim
101 *
102 */
103
104 uint64_t m_features;
105 bool m_force;
106
107 bool m_acquired_lock = false;
108 bool m_writes_blocked = false;
109 bool m_snap_lock_acquired = false;
110 bool m_requests_blocked = false;
111
112 uint64_t m_new_features = 0;
113 uint64_t m_disable_flags = 0;
114 uint64_t m_features_mask = 0;
115
116 cls::rbd::MirrorMode m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED;
117 bufferlist m_out_bl;
118
119 void send_prepare_lock();
120 Context *handle_prepare_lock(int *result);
121
122 void send_block_writes();
123 Context *handle_block_writes(int *result);
124
125 void send_acquire_exclusive_lock();
126 Context *handle_acquire_exclusive_lock(int *result);
127
128 void send_get_mirror_mode();
129 Context *handle_get_mirror_mode(int *result);
130
131 void send_get_mirror_image();
132 Context *handle_get_mirror_image(int *result);
133
134 void send_disable_mirror_image();
135 Context *handle_disable_mirror_image(int *result);
136
137 void send_close_journal();
138 Context *handle_close_journal(int *result);
139
140 void send_remove_journal();
141 Context *handle_remove_journal(int *result);
142
143 void send_append_op_event();
144 Context *handle_append_op_event(int *result);
145
146 void send_remove_object_map();
147 Context *handle_remove_object_map(int *result);
148
149 void send_set_features();
150 Context *handle_set_features(int *result);
151
152 void send_update_flags();
153 Context *handle_update_flags(int *result);
154
155 void send_notify_update();
156 Context *handle_notify_update(int *result);
157
158 void send_release_exclusive_lock();
159 Context *handle_release_exclusive_lock(int *result);
160
161 Context *handle_finish(int r);
162 };
163
164 } // namespace operation
165 } // namespace librbd
166
167 extern template class librbd::operation::DisableFeaturesRequest<librbd::ImageCtx>;
168
169 #endif // CEPH_LIBRBD_OPERATION_DISABLE_FEATURES_REQUEST_H