]>
Commit | Line | Data |
---|---|---|
9a1955a7 JF |
1 | /* |
2 | * Copyright (c) 2015-2017 Red Hat, Inc. | |
3 | * | |
4 | * All rights reserved. | |
5 | * | |
6 | * Author: Jan Friesse (jfriesse@redhat.com) | |
7 | * | |
8 | * This software licensed under BSD license, the text of which follows: | |
9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions are met: | |
12 | * | |
13 | * - Redistributions of source code must retain the above copyright notice, | |
14 | * this list of conditions and the following disclaimer. | |
15 | * - Redistributions in binary form must reproduce the above copyright notice, | |
16 | * this list of conditions and the following disclaimer in the documentation | |
17 | * and/or other materials provided with the distribution. | |
18 | * - Neither the name of the Red Hat, Inc. nor the names of its | |
19 | * contributors may be used to endorse or promote products derived from this | |
20 | * software without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
23 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
28 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
29 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
30 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
31 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
32 | * THE POSSIBILITY OF SUCH DAMAGE. | |
33 | */ | |
34 | ||
35 | #include <sys/types.h> | |
36 | ||
37 | #include <string.h> | |
38 | ||
39 | #include "qdevice-net-algo-lms.h" | |
40 | #include "qdevice-log.h" | |
41 | #include "qdevice-net-send.h" | |
42 | #include "qdevice-net-cast-vote-timer.h" | |
43 | ||
44 | struct algo_lms_instance_data { | |
45 | uint32_t quorate; | |
46 | uint8_t have_wfa; | |
47 | enum tlv_vote vote; | |
48 | }; | |
49 | ||
50 | int | |
51 | qdevice_net_algo_lms_init(struct qdevice_net_instance *instance) | |
52 | { | |
53 | struct algo_lms_instance_data *data; | |
54 | int res; | |
55 | ||
56 | data = malloc(sizeof(struct algo_lms_instance_data)); | |
57 | if (!data) { | |
58 | return (-1); | |
59 | } | |
60 | instance->algorithm_data = data; | |
61 | ||
62 | data->quorate = 0; | |
63 | data->vote = TLV_VOTE_ASK_LATER; | |
64 | res = cmap_get_uint8(instance->qdevice_instance_ptr->cmap_handle, "quorum.wait_for_all", &data->have_wfa); | |
65 | if (res != CS_OK) { | |
66 | qdevice_log(LOG_DEBUG, "algo-lms: Can't get WFA res = %d", res); | |
67 | data->have_wfa = 0; | |
68 | } | |
69 | ||
70 | qdevice_log(LOG_DEBUG, "algo-lms: initialised. WFA = %d", data->have_wfa); | |
71 | return (0); | |
72 | } | |
73 | ||
74 | ||
75 | int | |
76 | qdevice_net_algo_lms_connected(struct qdevice_net_instance *instance, | |
77 | enum tlv_heuristics *heuristics, int *send_config_node_list, int *send_membership_node_list, | |
78 | int *send_quorum_node_list, enum tlv_vote *vote) | |
79 | { | |
80 | ||
81 | return (0); | |
82 | } | |
83 | ||
84 | int | |
85 | qdevice_net_algo_lms_config_node_list_changed(struct qdevice_net_instance *instance, | |
86 | const struct node_list *nlist, int config_version_set, uint64_t config_version, | |
87 | int *send_node_list, enum tlv_vote *vote) | |
88 | { | |
89 | ||
90 | return (0); | |
91 | } | |
92 | ||
93 | int | |
94 | qdevice_net_algo_lms_votequorum_node_list_notify(struct qdevice_net_instance *instance, | |
95 | const struct tlv_ring_id *ring_id, uint32_t node_list_entries, uint32_t node_list[], | |
96 | int *pause_cast_vote_timer, enum tlv_vote *vote) | |
97 | { | |
98 | ||
99 | return (0); | |
100 | } | |
101 | ||
102 | int | |
103 | qdevice_net_algo_lms_votequorum_node_list_heuristics_notify(struct qdevice_net_instance *instance, | |
104 | const struct tlv_ring_id *ring_id, uint32_t node_list_entries, uint32_t node_list[], | |
105 | int *send_node_list, enum tlv_vote *vote, enum tlv_heuristics *heuristics) | |
106 | { | |
107 | ||
108 | return (0); | |
109 | } | |
110 | ||
111 | int | |
112 | qdevice_net_algo_lms_votequorum_quorum_notify(struct qdevice_net_instance *instance, | |
113 | uint32_t quorate, uint32_t node_list_entries, votequorum_node_t node_list[], int *send_node_list, | |
114 | enum tlv_vote *vote) | |
115 | { | |
116 | struct algo_lms_instance_data *data = instance->algorithm_data; | |
117 | ||
118 | data->quorate = quorate; | |
119 | qdevice_log(LOG_DEBUG, "algo-lms: quorum_notify. quorate = %d", data->quorate); | |
120 | ||
121 | return (0); | |
122 | } | |
123 | ||
124 | int | |
125 | qdevice_net_algo_lms_config_node_list_reply_received(struct qdevice_net_instance *instance, | |
126 | uint32_t seq_number, int initial, const struct tlv_ring_id *ring_id, int ring_id_is_valid, | |
127 | enum tlv_vote *vote) | |
128 | { | |
129 | ||
130 | if (!ring_id_is_valid) { | |
131 | *vote = TLV_VOTE_NO_CHANGE; | |
132 | } | |
133 | ||
134 | return (0); | |
135 | } | |
136 | ||
137 | int | |
138 | qdevice_net_algo_lms_membership_node_list_reply_received(struct qdevice_net_instance *instance, | |
139 | uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, | |
140 | enum tlv_vote *vote) | |
141 | { | |
142 | ||
143 | if (!ring_id_is_valid) { | |
144 | *vote = TLV_VOTE_NO_CHANGE; | |
145 | } | |
146 | ||
147 | return (0); | |
148 | } | |
149 | ||
150 | int | |
151 | qdevice_net_algo_lms_quorum_node_list_reply_received(struct qdevice_net_instance *instance, | |
152 | uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, | |
153 | enum tlv_vote *vote) | |
154 | { | |
155 | ||
156 | if (!ring_id_is_valid) { | |
157 | *vote = TLV_VOTE_NO_CHANGE; | |
158 | } | |
159 | ||
160 | return (0); | |
161 | } | |
162 | ||
163 | int | |
164 | qdevice_net_algo_lms_votequorum_expected_votes_notify(struct qdevice_net_instance *instance, | |
165 | uint32_t expected_votes, enum tlv_vote *vote) | |
166 | { | |
167 | ||
168 | return (0); | |
169 | } | |
170 | ||
171 | int | |
172 | qdevice_net_algo_lms_ask_for_vote_reply_received(struct qdevice_net_instance *instance, | |
173 | uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, | |
174 | enum tlv_vote *vote) | |
175 | { | |
176 | ||
177 | if (!ring_id_is_valid) { | |
178 | *vote = TLV_VOTE_NO_CHANGE; | |
179 | } | |
180 | ||
181 | return (0); | |
182 | } | |
183 | ||
184 | int | |
185 | qdevice_net_algo_lms_vote_info_received(struct qdevice_net_instance *instance, | |
186 | uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, | |
187 | enum tlv_vote *vote) | |
188 | { | |
189 | ||
190 | if (!ring_id_is_valid) { | |
191 | *vote = TLV_VOTE_NO_CHANGE; | |
192 | } | |
193 | ||
194 | return (0); | |
195 | } | |
196 | ||
197 | int | |
198 | qdevice_net_algo_lms_echo_reply_received(struct qdevice_net_instance *instance, | |
199 | uint32_t seq_number, int is_expected_seq_number) | |
200 | { | |
201 | ||
202 | return (is_expected_seq_number ? 0 : -1); | |
203 | } | |
204 | ||
205 | int | |
206 | qdevice_net_algo_lms_echo_reply_not_received(struct qdevice_net_instance *instance) | |
207 | { | |
208 | struct algo_lms_instance_data *data = instance->algorithm_data; | |
209 | ||
210 | qdevice_log(LOG_DEBUG, "algo-lms: echo_not_recvd. quorate = %d, WFA = %d", data->quorate, data->have_wfa); | |
211 | ||
212 | /* qnetd server is disconnected, if we were already quorate AND WFA is enabled | |
213 | then we can continue to provide our vote. | |
214 | Otherwise ... no | |
215 | */ | |
216 | if (data->quorate && data->have_wfa) { | |
217 | return (0); | |
218 | } | |
219 | ||
220 | return (-1); | |
221 | } | |
222 | ||
223 | int | |
224 | qdevice_net_algo_lms_heuristics_change(struct qdevice_net_instance *instance, | |
225 | enum tlv_heuristics *heuristics, int *send_msg, enum tlv_vote *vote) | |
226 | { | |
227 | ||
228 | return (0); | |
229 | } | |
230 | ||
231 | int | |
232 | qdevice_net_algo_lms_heuristics_change_reply_received(struct qdevice_net_instance *instance, | |
233 | uint32_t seq_number, const struct tlv_ring_id *ring_id, int ring_id_is_valid, | |
234 | enum tlv_heuristics heuristics, enum tlv_vote *vote) | |
235 | { | |
236 | ||
237 | if (!ring_id_is_valid) { | |
238 | *vote = TLV_VOTE_NO_CHANGE; | |
239 | } | |
240 | ||
241 | return (0); | |
242 | } | |
243 | ||
244 | int | |
245 | qdevice_net_algo_lms_disconnected(struct qdevice_net_instance *instance, | |
246 | enum qdevice_net_disconnect_reason disconnect_reason, int *try_reconnect, enum tlv_vote *vote) | |
247 | { | |
248 | struct algo_lms_instance_data *data = instance->algorithm_data; | |
249 | ||
250 | qdevice_log(LOG_DEBUG, "algo-lms: disconnected. quorate = %d, WFA = %d", data->quorate, data->have_wfa); | |
251 | qdevice_log(LOG_DEBUG, "algo-lms: disconnected. reason = %d, WFA = %d", disconnect_reason, data->have_wfa); | |
252 | ||
253 | if (!data->quorate || !data->have_wfa) { | |
254 | *vote = TLV_VOTE_NACK; | |
255 | } | |
256 | *try_reconnect = 1; | |
257 | return (0); | |
258 | } | |
259 | ||
260 | void | |
261 | qdevice_net_algo_lms_destroy(struct qdevice_net_instance *instance) | |
262 | { | |
263 | free(instance->algorithm_data); | |
264 | } | |
265 | ||
266 | static struct qdevice_net_algorithm qdevice_net_algo_lms = { | |
267 | .init = qdevice_net_algo_lms_init, | |
268 | .connected = qdevice_net_algo_lms_connected, | |
269 | .config_node_list_changed = qdevice_net_algo_lms_config_node_list_changed, | |
270 | .votequorum_node_list_notify = qdevice_net_algo_lms_votequorum_node_list_notify, | |
271 | .votequorum_node_list_heuristics_notify = qdevice_net_algo_lms_votequorum_node_list_heuristics_notify, | |
272 | .votequorum_quorum_notify = qdevice_net_algo_lms_votequorum_quorum_notify, | |
273 | .votequorum_expected_votes_notify = qdevice_net_algo_lms_votequorum_expected_votes_notify, | |
274 | .config_node_list_reply_received = qdevice_net_algo_lms_config_node_list_reply_received, | |
275 | .membership_node_list_reply_received = qdevice_net_algo_lms_membership_node_list_reply_received, | |
276 | .quorum_node_list_reply_received = qdevice_net_algo_lms_quorum_node_list_reply_received, | |
277 | .ask_for_vote_reply_received = qdevice_net_algo_lms_ask_for_vote_reply_received, | |
278 | .vote_info_received = qdevice_net_algo_lms_vote_info_received, | |
279 | .echo_reply_received = qdevice_net_algo_lms_echo_reply_received, | |
280 | .echo_reply_not_received = qdevice_net_algo_lms_echo_reply_not_received, | |
281 | .heuristics_change = qdevice_net_algo_lms_heuristics_change, | |
282 | .heuristics_change_reply_received = qdevice_net_algo_lms_heuristics_change_reply_received, | |
283 | .disconnected = qdevice_net_algo_lms_disconnected, | |
284 | .destroy = qdevice_net_algo_lms_destroy, | |
285 | }; | |
286 | ||
287 | int | |
288 | qdevice_net_algo_lms_register(void) | |
289 | { | |
290 | return (qdevice_net_algorithm_register(TLV_DECISION_ALGORITHM_TYPE_LMS, &qdevice_net_algo_lms)); | |
291 | } |