]> git.proxmox.com Git - pve-cluster.git/blame - data/src/dfsm.h
pmxcfs: update copyright in license header
[pve-cluster.git] / data / src / dfsm.h
CommitLineData
fe000966 1/*
84c98315 2 Copyright (C) 2010 - 2020 Proxmox Server Solutions GmbH
fe000966
DM
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
29typedef struct dfsm dfsm_t;
30
31typedef 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
39typedef 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 */
50typedef 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
61typedef 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 */
71typedef gpointer (*dfsm_get_state_fn_t)(
72 dfsm_t *dfsm,
73 gpointer data,
74 unsigned int *res_len);
75
76typedef gboolean (*dfsm_checksum_fn_t)(
77 dfsm_t *dfsm,
78 gpointer data,
79 unsigned char *csum,
80 size_t csum_len);
81
82typedef int (*dfsm_process_state_update_fn_t)(
83 dfsm_t *dfsm,
84 gpointer data,
85 dfsm_sync_info_t *syncinfo);
86
87typedef void (*dfsm_synced_fn_t)(dfsm_t *dfsm);
88
89/* return values:
90 * res < 0 ... serious error, leave group
91 * res >= 0 ... OK
92 */
93typedef 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
102typedef 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
114typedef struct {
115 uint64_t msgcount;
116 int result; /* we only have integer results for now */
117 int processed;
118} dfsm_result_t;
119
120dfsm_t *
121dfsm_new(
122 gpointer data,
123 const char *group_name,
124 const char *log_domain,
125 guint32 protocol_version,
126 dfsm_callbacks_t *callbacks);
127
128void
129dfsm_destroy(dfsm_t *dfsm);
130
131cs_error_t
132dfsm_initialize(dfsm_t *dfsm, int *fd);
133
134gboolean
135dfsm_finalize(dfsm_t *dfsm);
136
137cs_error_t
138dfsm_join(dfsm_t *dfsm);
139
140cs_error_t
141dfsm_leave(dfsm_t *dfsm);
142
143cs_error_t
144dfsm_dispatch(
145 dfsm_t *dfsm,
146 cs_dispatch_flags_t dispatch_types);
147
148gboolean
149dfsm_restartable(dfsm_t *dfsm);
150
af2e9dd4
DM
151gboolean
152dfsm_is_initialized(dfsm_t *dfsm);
153
fe000966
DM
154void
155dfsm_set_errormode(dfsm_t *dfsm);
156
89fde9ac 157cs_error_t
fe000966
DM
158dfsm_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 */
89fde9ac 165cs_error_t
fe000966
DM
166dfsm_send_message_sync(
167 dfsm_t *dfsm,
168 uint16_t msgtype,
169 struct iovec *iov,
170 int len,
171 dfsm_result_t *rp);
172
89fde9ac 173cs_error_t
fe000966
DM
174dfsm_send_update(
175 dfsm_t *dfsm,
176 struct iovec *iov,
177 unsigned int len);
178
89fde9ac 179cs_error_t
fe000966
DM
180dfsm_send_update_complete(dfsm_t *dfsm);
181
182gboolean
183dfsm_lowest_nodeid(dfsm_t *dfsm);
184
185gboolean
186dfsm_nodeid_is_local(
187 dfsm_t *dfsm,
188 uint32_t nodeid,
189 uint32_t pid);
190
191cs_error_t
192dfsm_verify_request(dfsm_t *dfsm);
193
194cfs_service_t *
195service_dfsm_new(dfsm_t *dfsm);
196
197void
198service_dfsm_destroy(cfs_service_t *service);
199
200
201#endif /* _PVE_DFSM_H_ */