2 * Copyright (c) 2015-2016 Red Hat, Inc.
6 * Author: Jan Friesse (jfriesse@redhat.com)
8 * This software licensed under BSD license, the text of which follows:
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
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.
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.
35 #include "qnetd-log.h"
36 #include "qnetd-client-algo-timer.h"
37 #include "qnetd-client-send.h"
38 #include "qnetd-algorithm.h"
39 #include "timer-list.h"
42 qnetd_client_algo_timer_callback(void *data1
, void *data2
)
44 struct qnetd_client
*client
;
45 enum tlv_vote result_vote
;
48 enum tlv_reply_error_code reply_error_code
;
50 client
= (struct qnetd_client
*)data1
;
52 result_vote
= TLV_VOTE_WAIT_FOR_REPLY
;
56 reply_error_code
= qnetd_algorithm_timer_callback(client
, &reschedule_timer
,
57 &send_vote
, &result_vote
);
59 if (reply_error_code
!= TLV_REPLY_ERROR_CODE_NO_ERROR
) {
60 qnetd_log(LOG_ERR
, "Algorithm for client %s returned error code. "
61 "Sending error reply.", client
->addr_str
);
63 if (qnetd_client_send_err(client
, 0, 0, reply_error_code
) != 0) {
64 client
->schedule_disconnect
= 1;
70 qnetd_log(LOG_DEBUG
, "Algorithm for client %s decided to %s timer and %s vote "
71 "with value %s", client
->addr_str
,
72 (reschedule_timer
? "reschedule" : "not reschedule"),
73 (send_vote
? "send" : "not send"),
74 tlv_vote_to_str(result_vote
));
78 client
->algo_timer_vote_info_msq_seq_number
++;
80 if (qnetd_client_send_vote_info(client
,
81 client
->algo_timer_vote_info_msq_seq_number
, &client
->last_ring_id
,
83 client
->schedule_disconnect
= 1;
88 if (reschedule_timer
) {
90 * Timer list makes sure to schedule callback again
95 client
->algo_timer
= NULL
;
100 qnetd_client_algo_timer_is_scheduled(struct qnetd_client
*client
)
103 return (client
->algo_timer
!= NULL
);
107 qnetd_client_algo_timer_schedule_timeout(struct qnetd_client
*client
, uint32_t timeout
)
110 if (qnetd_client_algo_timer_is_scheduled(client
)) {
111 if (qnetd_client_algo_timer_abort(client
) != 0) {
112 qnetd_log(LOG_ERR
, "Can't abort algo timer");
118 client
->algo_timer
= timer_list_add(client
->main_timer_list
, timeout
,
119 qnetd_client_algo_timer_callback
, (void *)client
, NULL
);
120 if (client
->algo_timer
== NULL
) {
121 qnetd_log(LOG_ERR
, "Can't schedule algo timer");
130 qnetd_client_algo_timer_schedule(struct qnetd_client
*client
)
133 return (qnetd_client_algo_timer_schedule_timeout(client
, client
->heartbeat_interval
/ 4));
137 qnetd_client_algo_timer_abort(struct qnetd_client
*client
)
140 if (qnetd_client_algo_timer_is_scheduled(client
)) {
141 timer_list_delete(client
->main_timer_list
, client
->algo_timer
);
142 client
->algo_timer
= NULL
;