]> git.proxmox.com Git - pve-cluster.git/blob - data/src/dfsm.h
6a4081dd2c97a21924e45e1b1193d5582e8e5d22
[pve-cluster.git] / data / src / dfsm.h
1 /*
2 Copyright (C) 2010 Proxmox Server Solutions GmbH
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Affero General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Affero General Public License for more details.
13
14 You should have received a copy of the GNU Affero General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 Author: Dietmar Maurer <dietmar@proxmox.com>
18
19 */
20
21 #ifndef _PVE_DFSM_H_
22 #define _PVE_DFSM_H_
23
24 #include <corosync/corotypes.h>
25 #include <corosync/cpg.h>
26
27 #include "loop.h"
28
29 typedef struct dfsm dfsm_t;
30
31 typedef struct {
32 uint32_t nodeid;
33 uint32_t pid;
34 gpointer state;
35 unsigned int state_len;
36 gboolean synced;
37 } dfsm_node_info_t;
38
39 typedef struct {
40 int node_count;
41 gpointer data; /* app can use that */
42 dfsm_node_info_t *local;
43 dfsm_node_info_t nodes[];
44 } dfsm_sync_info_t;
45
46 /* return values:
47 * res <= 0 ... serious error, leave group
48 * res > 0 ... OK, continue
49 */
50 typedef int (*dfsm_deliver_fn_t)(
51 dfsm_t *dfsm,
52 gpointer data,
53 int *res_ptr,
54 uint32_t nodeid,
55 uint32_t pid,
56 uint16_t msgtype,
57 uint32_t msg_time,
58 const void *msg,
59 size_t msg_len);
60
61 typedef void (*dfsm_confchg_fn_t)(
62 dfsm_t *dfsm,
63 gpointer data,
64 const struct cpg_address *member_list,
65 size_t member_list_entries);
66
67 /* return values:
68 * res == NULL ... serious error, leave group
69 * res != NULL ... OK, continue
70 */
71 typedef gpointer (*dfsm_get_state_fn_t)(
72 dfsm_t *dfsm,
73 gpointer data,
74 unsigned int *res_len);
75
76 typedef gboolean (*dfsm_checksum_fn_t)(
77 dfsm_t *dfsm,
78 gpointer data,
79 unsigned char *csum,
80 size_t csum_len);
81
82 typedef int (*dfsm_process_state_update_fn_t)(
83 dfsm_t *dfsm,
84 gpointer data,
85 dfsm_sync_info_t *syncinfo);
86
87 typedef void (*dfsm_synced_fn_t)(dfsm_t *dfsm);
88
89 /* return values:
90 * res < 0 ... serious error, leave group
91 * res >= 0 ... OK
92 */
93 typedef int (*dfsm_process_update_fn_t)(
94 dfsm_t *dfsm,
95 gpointer data,
96 dfsm_sync_info_t *syncinfo,
97 uint32_t nodeid,
98 uint32_t pid,
99 const void *msg,
100 size_t msg_len);
101
102 typedef struct {
103 dfsm_deliver_fn_t dfsm_deliver_fn;
104 dfsm_confchg_fn_t dfsm_confchg_fn;
105 dfsm_get_state_fn_t dfsm_get_state_fn;
106 dfsm_process_state_update_fn_t dfsm_process_state_update_fn;
107 dfsm_process_state_update_fn_t dfsm_commit_fn;
108 dfsm_process_state_update_fn_t dfsm_cleanup_fn;
109 dfsm_process_update_fn_t dfsm_process_update_fn;
110 dfsm_checksum_fn_t dfsm_checksum_fn;
111 dfsm_synced_fn_t dfsm_synced_fn;
112 } dfsm_callbacks_t;
113
114 typedef struct {
115 uint64_t msgcount;
116 int result; /* we only have integer results for now */
117 int processed;
118 } dfsm_result_t;
119
120 dfsm_t *
121 dfsm_new(
122 gpointer data,
123 const char *group_name,
124 const char *log_domain,
125 guint32 protocol_version,
126 dfsm_callbacks_t *callbacks);
127
128 void
129 dfsm_destroy(dfsm_t *dfsm);
130
131 cs_error_t
132 dfsm_initialize(dfsm_t *dfsm, int *fd);
133
134 gboolean
135 dfsm_finalize(dfsm_t *dfsm);
136
137 cs_error_t
138 dfsm_join(dfsm_t *dfsm);
139
140 cs_error_t
141 dfsm_leave(dfsm_t *dfsm);
142
143 cs_error_t
144 dfsm_dispatch(
145 dfsm_t *dfsm,
146 cs_dispatch_flags_t dispatch_types);
147
148 gboolean
149 dfsm_restartable(dfsm_t *dfsm);
150
151 gboolean
152 dfsm_is_initialized(dfsm_t *dfsm);
153
154 void
155 dfsm_set_errormode(dfsm_t *dfsm);
156
157 cs_error_t
158 dfsm_send_message(
159 dfsm_t *dfsm,
160 uint16_t msgtype,
161 struct iovec *iov,
162 int len);
163
164 /* only call this from another thread - else you get blocked forever */
165 cs_error_t
166 dfsm_send_message_sync(
167 dfsm_t *dfsm,
168 uint16_t msgtype,
169 struct iovec *iov,
170 int len,
171 dfsm_result_t *rp);
172
173 cs_error_t
174 dfsm_send_update(
175 dfsm_t *dfsm,
176 struct iovec *iov,
177 unsigned int len);
178
179 cs_error_t
180 dfsm_send_update_complete(dfsm_t *dfsm);
181
182 gboolean
183 dfsm_lowest_nodeid(dfsm_t *dfsm);
184
185 gboolean
186 dfsm_nodeid_is_local(
187 dfsm_t *dfsm,
188 uint32_t nodeid,
189 uint32_t pid);
190
191 cs_error_t
192 dfsm_verify_request(dfsm_t *dfsm);
193
194 cfs_service_t *
195 service_dfsm_new(dfsm_t *dfsm);
196
197 void
198 service_dfsm_destroy(cfs_service_t *service);
199
200
201 #endif /* _PVE_DFSM_H_ */