1 /* 2 * Copyright (c) 2009-2012 Red Hat, Inc. 3 * 4 * All rights reserved. 5 * 6 * Authors: Christine Caulfield (ccaulfie@redhat.com) 7 * Fabio M. Di Nitto (fdinitto@redhat.com) 8 * 9 * This software licensed under BSD license, the text of which follows: 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions are met: 13 * 14 * - Redistributions of source code must retain the above copyright notice, 15 * this list of conditions and the following disclaimer. 16 * - Redistributions in binary form must reproduce the above copyright notice, 17 * this list of conditions and the following disclaimer in the documentation 18 * and/or other materials provided with the distribution. 19 * - Neither the name of the MontaVista Software, Inc. nor the names of its 20 * contributors may be used to endorse or promote products derived from this 21 * software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS" 24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 33 * THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #ifndef COROSYNC_VOTEQUORUM_H_DEFINED 37 #define COROSYNC_VOTEQUORUM_H_DEFINED 38 39 #include <corosync/corotypes.h> 40 41 #ifdef __cplusplus 42 extern "C" { 43 #endif 44 45 /** 46 * @brief votequorum_handle_t 47 */ 48 typedef uint64_t votequorum_handle_t; 49 50 #define VOTEQUORUM_INFO_TWONODE 1 51 #define VOTEQUORUM_INFO_QUORATE 2 52 #define VOTEQUORUM_INFO_WAIT_FOR_ALL 4 53 #define VOTEQUORUM_INFO_LAST_MAN_STANDING 8 54 #define VOTEQUORUM_INFO_AUTO_TIE_BREAKER 16 55 #define VOTEQUORUM_INFO_ALLOW_DOWNSCALE 32 56 #define VOTEQUORUM_INFO_QDEVICE_REGISTERED 64 57 #define VOTEQUORUM_INFO_QDEVICE_ALIVE 128 58 #define VOTEQUORUM_INFO_QDEVICE_CAST_VOTE 256 59 #define VOTEQUORUM_INFO_QDEVICE_MASTER_WINS 512 60 61 #define VOTEQUORUM_QDEVICE_NODEID 0 62 #define VOTEQUORUM_QDEVICE_MAX_NAME_LEN 255 63 #define VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT 10000 64 #define VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT 30000 65 66 #define VOTEQUORUM_NODESTATE_MEMBER 1 67 #define VOTEQUORUM_NODESTATE_DEAD 2 68 #define VOTEQUORUM_NODESTATE_LEAVING 3 69 70 /** @} */ 71 72 /** 73 * @brief The votequorum_info struct 74 */ 75 struct votequorum_info { 76 unsigned int node_id; 77 unsigned int node_state; 78 unsigned int node_votes; 79 unsigned int node_expected_votes; 80 unsigned int highest_expected; 81 unsigned int total_votes; 82 unsigned int quorum; 83 unsigned int flags; 84 unsigned int qdevice_votes; 85 char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN]; 86 }; 87 88 /** 89 * @brief The votequorum_node_t struct 90 */ 91 typedef struct { 92 uint32_t nodeid; 93 uint32_t state; 94 } votequorum_node_t; 95 96 /** 97 * @brief The votequorum_ring_id_t struct 98 */ 99 typedef struct { 100 uint32_t nodeid; 101 uint64_t seq; 102 } votequorum_ring_id_t; 103 104 /** 105 * @brief The votequorum_quorum_notification_fn_t callback 106 */ 107 typedef void (*votequorum_quorum_notification_fn_t) ( 108 votequorum_handle_t handle, 109 uint64_t context, 110 uint32_t quorate, 111 uint32_t node_list_entries, 112 votequorum_node_t node_list[]); 113 114 typedef void (*votequorum_nodelist_notification_fn_t) ( 115 votequorum_handle_t handle, 116 uint64_t context, 117 votequorum_ring_id_t ring_id, 118 uint32_t node_list_entries, 119 uint32_t node_list[]); 120 121 /** 122 * @brief The votequorum_expectedvotes_notification_fn_t callback 123 */ 124 typedef void (*votequorum_expectedvotes_notification_fn_t) ( 125 votequorum_handle_t handle, 126 uint64_t context, 127 uint32_t expected_votes); 128 129 /** 130 * @brief The votequorum_callbacks_t struct 131 */ 132 typedef struct { 133 votequorum_quorum_notification_fn_t votequorum_quorum_notify_fn; 134 votequorum_expectedvotes_notification_fn_t votequorum_expectedvotes_notify_fn; 135 votequorum_nodelist_notification_fn_t votequorum_nodelist_notify_fn; 136 } votequorum_callbacks_t; 137 138 /** 139 * @brief Create a new quorum connection 140 * @param handle 141 * @param callbacks 142 * @return 143 */ 144 cs_error_t votequorum_initialize ( 145 votequorum_handle_t *handle, 146 votequorum_callbacks_t *callbacks); 147 148 /** 149 * @brief Close the quorum handle 150 * @param handle 151 * @return 152 */ 153 cs_error_t votequorum_finalize ( 154 votequorum_handle_t handle); 155 156 /** 157 * @brief Dispatch messages and configuration changes 158 * @param handle 159 * @param dispatch_types 160 * @return 161 */ 162 cs_error_t votequorum_dispatch ( 163 votequorum_handle_t handle, 164 cs_dispatch_flags_t dispatch_types); 165 166 /** 167 * @brief Get a file descriptor on which to poll. 168 * 169 * @note votequorum_handle_t is NOT a file descriptor and may not be used directly. 170 * 171 * @param handle 172 * @param fd 173 * @return 174 */ 175 cs_error_t votequorum_fd_get ( 176 votequorum_handle_t handle, 177 int *fd); 178 179 /** 180 * @brief Get quorum information. 181 * @param handle 182 * @param nodeid 183 * @param info 184 * @return 185 */ 186 cs_error_t votequorum_getinfo ( 187 votequorum_handle_t handle, 188 unsigned int nodeid, 189 struct votequorum_info *info); 190 191 /** 192 * @brief set expected_votes 193 * @param handle 194 * @param expected_votes 195 * @return 196 */ 197 cs_error_t votequorum_setexpected ( 198 votequorum_handle_t handle, 199 unsigned int expected_votes); 200 201 /** 202 * @brief set votes for a node 203 * @param handle 204 * @param nodeid 205 * @param votes 206 * @return 207 */ 208 cs_error_t votequorum_setvotes ( 209 votequorum_handle_t handle, 210 unsigned int nodeid, 211 unsigned int votes); 212 213 /** 214 * @brief Track node and quorum changes 215 * @param handle 216 * @param context 217 * @param flags 218 * @return 219 */ 220 cs_error_t votequorum_trackstart ( 221 votequorum_handle_t handle, 222 uint64_t context, 223 unsigned int flags); 224 225 /** 226 * @brief votequorum_trackstop 227 * @param handle 228 * @return 229 */ 230 cs_error_t votequorum_trackstop ( 231 votequorum_handle_t handle); 232 233 /** 234 * @brief Save and retrieve private data/context 235 * @param handle 236 * @param context 237 * @return 238 */ 239 cs_error_t votequorum_context_get ( 240 votequorum_handle_t handle, 241 void **context); 242 243 /** 244 * @brief votequorum_context_set 245 * @param handle 246 * @param context 247 * @return 248 */ 249 cs_error_t votequorum_context_set ( 250 votequorum_handle_t handle, 251 void *context); 252 253 /** 254 * @brief Register a quorum device 255 * 256 * it will be DEAD until polled 257 * 258 * @param handle 259 * @param name 260 * @return 261 */ 262 cs_error_t votequorum_qdevice_register ( 263 votequorum_handle_t handle, 264 const char *name); 265 266 /** 267 * @brief Unregister a quorum device 268 * @param handle 269 * @param name 270 * @return 271 */ 272 cs_error_t votequorum_qdevice_unregister ( 273 votequorum_handle_t handle, 274 const char *name); 275 276 /** 277 * @brief Update registered name of a quorum device 278 * @param handle 279 * @param oldname 280 * @param newname 281 * @return 282 */ 283 cs_error_t votequorum_qdevice_update ( 284 votequorum_handle_t handle, 285 const char *oldname, 286 const char *newname); 287 288 /** 289 * @brief Poll a quorum device 290 * @param handle 291 * @param name 292 * @param cast_vote 293 * @param ring_id 294 * @return 295 */ 296 cs_error_t votequorum_qdevice_poll ( 297 votequorum_handle_t handle, 298 const char *name, 299 unsigned int cast_vote, 300 votequorum_ring_id_t ring_id); 301 302 /** 303 * @brief Allow qdevice to tell votequorum if master_wins can be enabled or not 304 * @param handle 305 * @param name 306 * @param allow 307 * @return 308 */ 309 cs_error_t votequorum_qdevice_master_wins ( 310 votequorum_handle_t handle, 311 const char *name, 312 unsigned int allow); 313 314 #ifdef __cplusplus 315 } 316 #endif 317 #endif /* COROSYNC_VOTEQUORUM_H_DEFINED */ 318