votequorum.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  1. /*
  2. * Copyright (c) 2009 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@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 MontaVista Software, 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 CONTIBUTORS "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. #include <config.h>
  35. #include <sys/types.h>
  36. #ifndef COROSYNC_BSD
  37. #include <alloca.h>
  38. #endif
  39. #include <sys/types.h>
  40. #include <sys/socket.h>
  41. #include <sys/un.h>
  42. #include <sys/time.h>
  43. #include <sys/ioctl.h>
  44. #include <netinet/in.h>
  45. #include <sys/uio.h>
  46. #include <unistd.h>
  47. #include <fcntl.h>
  48. #include <stdlib.h>
  49. #include <stdio.h>
  50. #include <errno.h>
  51. #include <signal.h>
  52. #include <time.h>
  53. #include <unistd.h>
  54. #include <netinet/in.h>
  55. #include <arpa/inet.h>
  56. #include <corosync/corotypes.h>
  57. #include <corosync/cfg.h>
  58. #include <corosync/list.h>
  59. #include <corosync/lcr/lcr_comp.h>
  60. #include <corosync/engine/logsys.h>
  61. #include <corosync/ipc_gen.h>
  62. #include <corosync/engine/coroapi.h>
  63. #include <corosync/engine/quorum.h>
  64. #include <corosync/ipc_votequorum.h>
  65. #include <corosync/list.h>
  66. #define VOTEQUORUM_MAJOR_VERSION 6
  67. #define VOTEQUORUM_MINOR_VERSION 3
  68. #define VOTEQUORUM_PATCH_VERSION 0
  69. /* Silly default to prevent accidents! */
  70. #define DEFAULT_EXPECTED 1024
  71. #define DEFAULT_QDEV_POLL 10000
  72. #define DEFAULT_LEAVE_TMO 10000
  73. LOGSYS_DECLARE_SUBSYS ("VOTEQ", LOG_INFO);
  74. enum quorum_message_req_types {
  75. MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO = 0,
  76. MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE = 1,
  77. MESSAGE_REQ_EXEC_VOTEQUORUM_KILLNODE = 2,
  78. };
  79. #define NODE_FLAGS_BEENDOWN 1
  80. #define NODE_FLAGS_SEESDISALLOWED 8
  81. #define NODE_FLAGS_HASSTATE 16
  82. #define NODE_FLAGS_QDISK 32
  83. #define NODE_FLAGS_REMOVED 64
  84. #define NODE_FLAGS_US 128
  85. typedef enum { NODESTATE_JOINING=1, NODESTATE_MEMBER,
  86. NODESTATE_DEAD, NODESTATE_LEAVING, NODESTATE_DISALLOWED } nodestate_t;
  87. /* This structure is tacked onto the start of a cluster message packet for our
  88. * own nefarious purposes. */
  89. struct q_protheader {
  90. unsigned char tgtport; /* Target port number */
  91. unsigned char srcport; /* Source (originating) port number */
  92. unsigned short pad;
  93. unsigned int flags;
  94. int srcid; /* Node ID of the sender */
  95. int tgtid; /* Node ID of the target */
  96. } __attribute__((packed));
  97. struct cluster_node {
  98. int flags;
  99. int node_id;
  100. unsigned int expected_votes;
  101. unsigned int votes;
  102. time_t join_time;
  103. nodestate_t state;
  104. struct timeval last_hello; /* Only used for quorum devices */
  105. struct list_head list;
  106. };
  107. static int quorum_flags;
  108. #define VOTEQUORUM_FLAG_FEATURE_DISALLOWED 1
  109. #define VOTEQUORUM_FLAG_FEATURE_TWONODE 1
  110. static int quorum;
  111. static int cluster_is_quorate;
  112. static int first_trans = 1;
  113. static unsigned int quorumdev_poll = DEFAULT_QDEV_POLL;
  114. static unsigned int leaving_timeout = DEFAULT_LEAVE_TMO;
  115. static struct cluster_node *us;
  116. static struct cluster_node *quorum_device = NULL;
  117. static char quorum_device_name[VOTEQUORUM_MAX_QDISK_NAME_LEN];
  118. static corosync_timer_handle_t quorum_device_timer;
  119. static corosync_timer_handle_t leaving_timer;
  120. static struct list_head cluster_members_list;
  121. static struct corosync_api_v1 *corosync_api;
  122. static struct list_head trackers_list;
  123. static unsigned int quorum_members[PROCESSOR_COUNT_MAX+1];
  124. static int quorum_members_entries = 0;
  125. static struct memb_ring_id quorum_ringid;
  126. static hdb_handle_t group_handle;
  127. #define max(a,b) (((a) > (b)) ? (a) : (b))
  128. static struct cluster_node *find_node_by_nodeid(int nodeid);
  129. static struct cluster_node *allocate_node(int nodeid);
  130. static char *kill_reason(int reason);
  131. static struct corosync_tpg_group quorum_group[1] = {
  132. { .group = "VOTEQ", .group_len = 5},
  133. };
  134. #define list_iterate(v, head) \
  135. for (v = (head)->next; v != head; v = v->next)
  136. struct quorum_pd {
  137. unsigned char track_flags;
  138. int tracking_enabled;
  139. uint64_t tracking_context;
  140. struct list_head list;
  141. void *conn;
  142. };
  143. /*
  144. * Service Interfaces required by service_message_handler struct
  145. */
  146. static void votequorum_init(struct corosync_api_v1 *api,
  147. quorum_set_quorate_fn_t report);
  148. static void quorum_confchg_fn (
  149. enum totem_configuration_type configuration_type,
  150. unsigned int *member_list, int member_list_entries,
  151. unsigned int *left_list, int left_list_entries,
  152. unsigned int *joined_list, int joined_list_entries,
  153. struct memb_ring_id *ring_id);
  154. static void quorum_deliver_fn(unsigned int nodeid, struct iovec *iovec, int iov_len,
  155. int endian_conversion_required);
  156. static int votequorum_exec_init_fn (struct corosync_api_v1 *corosync_api);
  157. static int quorum_lib_init_fn (void *conn);
  158. static int quorum_lib_exit_fn (void *conn);
  159. static void message_handler_req_exec_quorum_nodeinfo (
  160. void *message,
  161. unsigned int nodeid);
  162. static void message_handler_req_exec_quorum_reconfigure (
  163. void *message,
  164. unsigned int nodeid);
  165. static void message_handler_req_exec_quorum_killnode (
  166. void *message,
  167. unsigned int nodeid);
  168. static void message_handler_req_lib_votequorum_getinfo (void *conn, void *message);
  169. static void message_handler_req_lib_votequorum_setexpected (void *conn, void *message);
  170. static void message_handler_req_lib_votequorum_setvotes (void *conn, void *message);
  171. static void message_handler_req_lib_votequorum_qdisk_register (void *conn, void *message);
  172. static void message_handler_req_lib_votequorum_qdisk_unregister (void *conn, void *message);
  173. static void message_handler_req_lib_votequorum_qdisk_poll (void *conn, void *message);
  174. static void message_handler_req_lib_votequorum_qdisk_getinfo (void *conn, void *message);
  175. static void message_handler_req_lib_votequorum_setstate (void *conn, void *message);
  176. static void message_handler_req_lib_votequorum_leaving (void *conn, void *message);
  177. static void message_handler_req_lib_votequorum_trackstart (void *conn, void *msg);
  178. static void message_handler_req_lib_votequorum_trackstop (void *conn, void *msg);
  179. static int quorum_exec_send_nodeinfo(void);
  180. static int quorum_exec_send_reconfigure(int param, int nodeid, int value);
  181. static int quorum_exec_send_killnode(int nodeid, unsigned int reason);
  182. static void add_votequorum_config_notification(hdb_handle_t quorum_object_handle);
  183. static void recalculate_quorum(int allow_decrease, int by_current_nodes);
  184. /*
  185. * Library Handler Definition
  186. */
  187. static struct corosync_lib_handler quorum_lib_service[] =
  188. {
  189. { /* 0 */
  190. .lib_handler_fn = message_handler_req_lib_votequorum_getinfo,
  191. .response_size = sizeof (struct res_lib_votequorum_getinfo),
  192. .response_id = MESSAGE_RES_VOTEQUORUM_GETINFO,
  193. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  194. },
  195. { /* 1 */
  196. .lib_handler_fn = message_handler_req_lib_votequorum_setexpected,
  197. .response_size = sizeof (struct res_lib_votequorum_status),
  198. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  199. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  200. },
  201. { /* 2 */
  202. .lib_handler_fn = message_handler_req_lib_votequorum_setvotes,
  203. .response_size = sizeof (struct res_lib_votequorum_status),
  204. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  205. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  206. },
  207. { /* 3 */
  208. .lib_handler_fn = message_handler_req_lib_votequorum_qdisk_register,
  209. .response_size = sizeof (struct res_lib_votequorum_status),
  210. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  211. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  212. },
  213. { /* 4 */
  214. .lib_handler_fn = message_handler_req_lib_votequorum_qdisk_unregister,
  215. .response_size = sizeof (struct res_lib_votequorum_status),
  216. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  217. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  218. },
  219. { /* 5 */
  220. .lib_handler_fn = message_handler_req_lib_votequorum_qdisk_poll,
  221. .response_size = sizeof (struct res_lib_votequorum_status),
  222. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  223. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  224. },
  225. { /* 6 */
  226. .lib_handler_fn = message_handler_req_lib_votequorum_qdisk_getinfo,
  227. .response_size = sizeof (struct res_lib_votequorum_qdisk_getinfo),
  228. .response_id = MESSAGE_RES_VOTEQUORUM_QDISK_GETINFO,
  229. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  230. },
  231. { /* 7 */
  232. .lib_handler_fn = message_handler_req_lib_votequorum_setstate,
  233. .response_size = sizeof (struct res_lib_votequorum_status),
  234. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  235. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  236. },
  237. { /* 8 */
  238. .lib_handler_fn = message_handler_req_lib_votequorum_leaving,
  239. .response_size = sizeof (struct res_lib_votequorum_status),
  240. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  241. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  242. },
  243. { /* 9 */
  244. .lib_handler_fn = message_handler_req_lib_votequorum_trackstart,
  245. .response_size = sizeof (struct res_lib_votequorum_status),
  246. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  247. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  248. },
  249. { /* 10 */
  250. .lib_handler_fn = message_handler_req_lib_votequorum_trackstop,
  251. .response_size = sizeof (struct res_lib_votequorum_status),
  252. .response_id = MESSAGE_RES_VOTEQUORUM_STATUS,
  253. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  254. }
  255. };
  256. static quorum_set_quorate_fn_t set_quorum;
  257. /*
  258. * lcrso object definition
  259. */
  260. static struct quorum_services_api_ver1 votequorum_iface_ver0 = {
  261. .init = votequorum_init
  262. };
  263. static struct corosync_service_engine quorum_service_handler = {
  264. .name = "corosync votes quorum service v0.90",
  265. .id = VOTEQUORUM_SERVICE,
  266. .private_data_size = sizeof (struct quorum_pd),
  267. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  268. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED,
  269. .lib_init_fn = quorum_lib_init_fn,
  270. .lib_exit_fn = quorum_lib_exit_fn,
  271. .lib_engine = quorum_lib_service,
  272. .lib_engine_count = sizeof (quorum_lib_service) / sizeof (struct corosync_lib_handler),
  273. .exec_init_fn = votequorum_exec_init_fn,
  274. .exec_engine = NULL,
  275. .exec_engine_count = 0,
  276. .confchg_fn = NULL,
  277. };
  278. /*
  279. * Dynamic loader definition
  280. */
  281. static struct corosync_service_engine *quorum_get_service_handler_ver0 (void);
  282. static struct corosync_service_engine_iface_ver0 quorum_service_handler_iface = {
  283. .corosync_get_service_engine_ver0 = quorum_get_service_handler_ver0
  284. };
  285. static struct lcr_iface corosync_quorum_ver0[2] = {
  286. {
  287. .name = "corosync_votequorum",
  288. .version = 0,
  289. .versions_replace = 0,
  290. .versions_replace_count = 0,
  291. .dependencies = 0,
  292. .dependency_count = 0,
  293. .constructor = NULL,
  294. .destructor = NULL,
  295. .interfaces = (void **)(void *)&votequorum_iface_ver0
  296. },
  297. {
  298. .name = "corosync_votequorum_iface",
  299. .version = 0,
  300. .versions_replace = 0,
  301. .versions_replace_count = 0,
  302. .dependencies = 0,
  303. .dependency_count = 0,
  304. .constructor = NULL,
  305. .destructor = NULL,
  306. .interfaces = NULL
  307. }
  308. };
  309. static struct lcr_comp quorum_comp_ver0 = {
  310. .iface_count = 2,
  311. .ifaces = corosync_quorum_ver0
  312. };
  313. static struct corosync_service_engine *quorum_get_service_handler_ver0 (void)
  314. {
  315. return (&quorum_service_handler);
  316. }
  317. __attribute__ ((constructor)) static void quorum_comp_register (void) {
  318. lcr_interfaces_set (&corosync_quorum_ver0[0], &votequorum_iface_ver0);
  319. lcr_interfaces_set (&corosync_quorum_ver0[1], &quorum_service_handler_iface);
  320. lcr_component_register (&quorum_comp_ver0);
  321. }
  322. static void votequorum_init(struct corosync_api_v1 *api,
  323. quorum_set_quorate_fn_t report)
  324. {
  325. ENTER();
  326. set_quorum = report;
  327. /* Load the library-servicing part of this module */
  328. api->service_link_and_init(api, "corosync_votequorum_iface", 0);
  329. LEAVE();
  330. }
  331. /* Message types */
  332. #define VOTEQUORUM_MSG_NODEINFO 5
  333. #define VOTEQUORUM_MSG_KILLNODE 6
  334. #define VOTEQUORUM_MSG_RECONFIGURE 8
  335. struct req_exec_quorum_nodeinfo {
  336. unsigned char cmd;
  337. unsigned char first_trans;
  338. unsigned int votes;
  339. unsigned int expected_votes;
  340. unsigned int major_version; /* Not backwards compatible */
  341. unsigned int minor_version; /* Backwards compatible */
  342. unsigned int patch_version; /* Backwards/forwards compatible */
  343. unsigned int config_version;
  344. unsigned int flags;
  345. } __attribute__((packed));
  346. /* Parameters for RECONFIG command */
  347. #define RECONFIG_PARAM_EXPECTED_VOTES 1
  348. #define RECONFIG_PARAM_NODE_VOTES 2
  349. #define RECONFIG_PARAM_LEAVING 3
  350. struct req_exec_quorum_reconfigure {
  351. unsigned char cmd;
  352. unsigned char param;
  353. unsigned short pad;
  354. int nodeid;
  355. unsigned int value;
  356. };
  357. struct req_exec_quorum_killnode {
  358. unsigned char cmd;
  359. unsigned char pad1;
  360. uint16_t reason;
  361. int nodeid;
  362. };
  363. /* These just make the access a little neater */
  364. static inline int objdb_get_string(struct corosync_api_v1 *corosync, unsigned int object_service_handle,
  365. char *key, char **value)
  366. {
  367. int res;
  368. *value = NULL;
  369. if ( !(res = corosync_api->object_key_get(object_service_handle,
  370. key,
  371. strlen(key),
  372. (void *)value,
  373. NULL))) {
  374. if (*value)
  375. return 0;
  376. }
  377. return -1;
  378. }
  379. static inline void objdb_get_int(struct corosync_api_v1 *corosync,
  380. unsigned int object_service_handle,
  381. const char *key, unsigned int *intvalue,
  382. unsigned int default_value)
  383. {
  384. char *value = NULL;
  385. *intvalue = default_value;
  386. if (!corosync_api->object_key_get(object_service_handle, key, strlen(key),
  387. (void *)&value, NULL)) {
  388. if (value) {
  389. *intvalue = atoi(value);
  390. }
  391. }
  392. }
  393. static int votequorum_send_message(void *message, int len)
  394. {
  395. struct iovec iov[2];
  396. struct q_protheader header;
  397. header.tgtport = 0;
  398. header.srcport = 0;
  399. header.flags = 0;
  400. header.srcid = us->node_id;
  401. header.tgtid = 0;
  402. iov[0].iov_base = &header;
  403. iov[0].iov_len = sizeof(header);
  404. iov[1].iov_base = message;
  405. iov[1].iov_len = len;
  406. return corosync_api->tpg_joined_mcast(group_handle, iov, 2, TOTEM_AGREED);
  407. }
  408. static void read_quorum_config(unsigned int quorum_handle)
  409. {
  410. unsigned int value = 0;
  411. int cluster_members = 0;
  412. struct list_head *tmp;
  413. struct cluster_node *node;
  414. log_printf(LOG_INFO, "Reading configuration\n");
  415. objdb_get_int(corosync_api, quorum_handle, "expected_votes", &us->expected_votes, DEFAULT_EXPECTED);
  416. objdb_get_int(corosync_api, quorum_handle, "votes", &us->votes, 1);
  417. objdb_get_int(corosync_api, quorum_handle, "quorumdev_poll", &quorumdev_poll, DEFAULT_QDEV_POLL);
  418. objdb_get_int(corosync_api, quorum_handle, "leaving_timeout", &leaving_timeout, DEFAULT_LEAVE_TMO);
  419. objdb_get_int(corosync_api, quorum_handle, "disallowed", &value, 0);
  420. if (value)
  421. quorum_flags |= VOTEQUORUM_FLAG_FEATURE_DISALLOWED;
  422. else
  423. quorum_flags &= ~VOTEQUORUM_FLAG_FEATURE_DISALLOWED;
  424. objdb_get_int(corosync_api, quorum_handle, "two_node", &value, 0);
  425. if (value)
  426. quorum_flags |= VOTEQUORUM_FLAG_FEATURE_TWONODE;
  427. else
  428. quorum_flags &= ~VOTEQUORUM_FLAG_FEATURE_TWONODE;
  429. /*
  430. * two_node mode is invalid if there are more than 2 nodes in the cluster!
  431. */
  432. list_iterate(tmp, &cluster_members_list) {
  433. node = list_entry(tmp, struct cluster_node, list);
  434. cluster_members++;
  435. }
  436. if (quorum_flags & VOTEQUORUM_FLAG_FEATURE_TWONODE && cluster_members > 2) {
  437. log_printf(LOG_WARNING, "quorum.two_node was set but there are more than 2 nodes in the cluster. It will be ignored.");
  438. quorum_flags &= ~VOTEQUORUM_FLAG_FEATURE_TWONODE;
  439. }
  440. }
  441. static int votequorum_exec_init_fn (struct corosync_api_v1 *api)
  442. {
  443. hdb_handle_t object_handle;
  444. hdb_handle_t find_handle;
  445. ENTER();
  446. corosync_api = api;
  447. list_init(&cluster_members_list);
  448. list_init(&trackers_list);
  449. /* Allocate a cluster_node for us */
  450. us = allocate_node(corosync_api->totem_nodeid_get());
  451. if (!us)
  452. return (1);
  453. us->flags |= NODE_FLAGS_US;
  454. us->state = NODESTATE_MEMBER;
  455. us->expected_votes = DEFAULT_EXPECTED;
  456. us->votes = 1;
  457. time(&us->join_time);
  458. /* Get configuration variables */
  459. corosync_api->object_find_create(OBJECT_PARENT_HANDLE, "quorum", strlen("quorum"), &find_handle);
  460. if (corosync_api->object_find_next(find_handle, &object_handle) == 0) {
  461. read_quorum_config(object_handle);
  462. }
  463. recalculate_quorum(0, 0);
  464. /* Listen for changes */
  465. add_votequorum_config_notification(object_handle);
  466. corosync_api->object_find_destroy(find_handle);
  467. api->tpg_init(&group_handle, quorum_deliver_fn, quorum_confchg_fn);
  468. api->tpg_join(group_handle, quorum_group, 1);
  469. LEAVE();
  470. return (0);
  471. }
  472. static int quorum_lib_exit_fn (void *conn)
  473. {
  474. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  475. ENTER();
  476. if (quorum_pd->tracking_enabled) {
  477. list_del (&quorum_pd->list);
  478. list_init (&quorum_pd->list);
  479. }
  480. LEAVE();
  481. return (0);
  482. }
  483. static int send_quorum_notification(void *conn, uint64_t context)
  484. {
  485. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  486. struct list_head *tmp;
  487. struct cluster_node *node;
  488. int cluster_members = 0;
  489. int i = 0;
  490. int size;
  491. char *buf;
  492. ENTER();
  493. list_iterate(tmp, &cluster_members_list) {
  494. node = list_entry(tmp, struct cluster_node, list);
  495. cluster_members++;
  496. }
  497. if (quorum_device)
  498. cluster_members++;
  499. size = sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  500. buf = alloca(size);
  501. if (!buf) {
  502. LEAVE();
  503. return -1;
  504. }
  505. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)buf;
  506. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  507. res_lib_votequorum_notification->node_list_entries = cluster_members;
  508. res_lib_votequorum_notification->context = context;
  509. list_iterate(tmp, &cluster_members_list) {
  510. node = list_entry(tmp, struct cluster_node, list);
  511. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  512. res_lib_votequorum_notification->node_list[i++].state = node->state;
  513. }
  514. if (quorum_device) {
  515. res_lib_votequorum_notification->node_list[i].nodeid = 0;
  516. res_lib_votequorum_notification->node_list[i++].state = quorum_device->state | 0x80;
  517. }
  518. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NOTIFICATION;
  519. res_lib_votequorum_notification->header.size = size;
  520. res_lib_votequorum_notification->header.error = CS_OK;
  521. /* Send it to all interested parties */
  522. if (conn) {
  523. int ret = corosync_api->ipc_dispatch_send(conn, buf, size);
  524. LEAVE();
  525. return ret;
  526. }
  527. else {
  528. struct quorum_pd *qpd;
  529. list_iterate(tmp, &trackers_list) {
  530. qpd = list_entry(tmp, struct quorum_pd, list);
  531. res_lib_votequorum_notification->context = qpd->tracking_context;
  532. corosync_api->ipc_dispatch_send(qpd->conn, buf, size);
  533. }
  534. }
  535. LEAVE();
  536. return 0;
  537. }
  538. static void send_expectedvotes_notification()
  539. {
  540. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  541. struct quorum_pd *qpd;
  542. struct list_head *tmp;
  543. log_printf(LOG_DEBUG, "Sending expected votes callback\n");
  544. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  545. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  546. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  547. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  548. list_iterate(tmp, &trackers_list) {
  549. qpd = list_entry(tmp, struct quorum_pd, list);
  550. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  551. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  552. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  553. }
  554. }
  555. static void set_quorate(int total_votes)
  556. {
  557. int quorate;
  558. ENTER();
  559. if (quorum > total_votes) {
  560. quorate = 0;
  561. }
  562. else {
  563. quorate = 1;
  564. }
  565. if (cluster_is_quorate && !quorate)
  566. log_printf(LOG_INFO, "quorum lost, blocking activity\n");
  567. if (!cluster_is_quorate && quorate)
  568. log_printf(LOG_INFO, "quorum regained, resuming activity\n");
  569. /* If we are newly quorate, then kill any DISALLOWED nodes */
  570. if (!cluster_is_quorate && quorate) {
  571. struct cluster_node *node = NULL;
  572. struct list_head *tmp;
  573. list_iterate(tmp, &cluster_members_list) {
  574. node = list_entry(tmp, struct cluster_node, list);
  575. if (node->state == NODESTATE_DISALLOWED)
  576. quorum_exec_send_killnode(node->node_id, VOTEQUORUM_REASON_KILL_REJOIN);
  577. }
  578. }
  579. cluster_is_quorate = quorate;
  580. set_quorum(quorum_members, quorum_members_entries, quorate, &quorum_ringid);
  581. ENTER();
  582. }
  583. static int calculate_quorum(int allow_decrease, int max_expected, unsigned int *ret_total_votes)
  584. {
  585. struct list_head *nodelist;
  586. struct cluster_node *node;
  587. unsigned int total_votes = 0;
  588. unsigned int highest_expected = 0;
  589. unsigned int newquorum, q1, q2;
  590. unsigned int total_nodes = 0;
  591. ENTER();
  592. list_iterate(nodelist, &cluster_members_list) {
  593. node = list_entry(nodelist, struct cluster_node, list);
  594. log_printf(LOG_DEBUG, "node %x state=%d, votes=%d, expected=%d\n",
  595. node->node_id, node->state, node->votes, node->expected_votes);
  596. if (node->state == NODESTATE_MEMBER) {
  597. if (max_expected)
  598. node->expected_votes = max_expected;
  599. else
  600. highest_expected = max(highest_expected, node->expected_votes);
  601. total_votes += node->votes;
  602. total_nodes++;
  603. }
  604. }
  605. if (quorum_device && quorum_device->state == NODESTATE_MEMBER)
  606. total_votes += quorum_device->votes;
  607. if (max_expected > 0)
  608. highest_expected = max_expected;
  609. /* This quorum calculation is taken from the OpenVMS Cluster Systems
  610. * manual, but, then, you guessed that didn't you */
  611. q1 = (highest_expected + 2) / 2;
  612. q2 = (total_votes + 2) / 2;
  613. newquorum = max(q1, q2);
  614. /* Normally quorum never decreases but the system administrator can
  615. * force it down by setting expected votes to a maximum value */
  616. if (!allow_decrease)
  617. newquorum = max(quorum, newquorum);
  618. /* The special two_node mode allows each of the two nodes to retain
  619. * quorum if the other fails. Only one of the two should live past
  620. * fencing (as both nodes try to fence each other in split-brain.)
  621. * Also: if there are more than two nodes, force us inquorate to avoid
  622. * any damage or confusion.
  623. */
  624. if ((quorum_flags & VOTEQUORUM_FLAG_FEATURE_TWONODE) && total_nodes <= 2)
  625. newquorum = 1;
  626. if (ret_total_votes)
  627. *ret_total_votes = total_votes;
  628. LEAVE();
  629. return newquorum;
  630. }
  631. /* Recalculate cluster quorum, set quorate and notify changes */
  632. static void recalculate_quorum(int allow_decrease, int by_current_nodes)
  633. {
  634. unsigned int total_votes = 0;
  635. int cluster_members = 0;
  636. struct list_head *nodelist;
  637. struct cluster_node *node;
  638. ENTER();
  639. list_iterate(nodelist, &cluster_members_list) {
  640. node = list_entry(nodelist, struct cluster_node, list);
  641. if (node->state == NODESTATE_MEMBER) {
  642. if (by_current_nodes)
  643. cluster_members++;
  644. total_votes += node->votes;
  645. }
  646. }
  647. /* Keep expected_votes at the highest number of votes in the cluster */
  648. log_printf(LOG_DEBUG, "total_votes=%d, expected_votes=%d\n", total_votes, us->expected_votes);
  649. if (total_votes > us->expected_votes) {
  650. us->expected_votes = total_votes;
  651. send_expectedvotes_notification();
  652. }
  653. quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
  654. set_quorate(total_votes);
  655. send_quorum_notification(NULL, 0L);
  656. LEAVE();
  657. }
  658. static int have_disallowed(void)
  659. {
  660. struct cluster_node *node;
  661. struct list_head *tmp;
  662. list_iterate(tmp, &cluster_members_list) {
  663. node = list_entry(tmp, struct cluster_node, list);
  664. if (node->state == NODESTATE_DISALLOWED)
  665. return 1;
  666. }
  667. return 0;
  668. }
  669. static void node_add_ordered(struct cluster_node *newnode)
  670. {
  671. struct cluster_node *node = NULL;
  672. struct list_head *tmp;
  673. struct list_head *newlist = &newnode->list;
  674. list_iterate(tmp, &cluster_members_list) {
  675. node = list_entry(tmp, struct cluster_node, list);
  676. if (newnode->node_id < node->node_id)
  677. break;
  678. }
  679. if (!node)
  680. list_add(&newnode->list, &cluster_members_list);
  681. else {
  682. newlist->prev = tmp->prev;
  683. newlist->next = tmp;
  684. tmp->prev->next = newlist;
  685. tmp->prev = newlist;
  686. }
  687. }
  688. static struct cluster_node *allocate_node(int nodeid)
  689. {
  690. struct cluster_node *cl;
  691. cl = malloc(sizeof(struct cluster_node));
  692. if (cl) {
  693. memset(cl, 0, sizeof(struct cluster_node));
  694. cl->node_id = nodeid;
  695. if (nodeid)
  696. node_add_ordered(cl);
  697. }
  698. return cl;
  699. }
  700. static struct cluster_node *find_node_by_nodeid(int nodeid)
  701. {
  702. struct cluster_node *node;
  703. struct list_head *tmp;
  704. list_iterate(tmp, &cluster_members_list) {
  705. node = list_entry(tmp, struct cluster_node, list);
  706. if (node->node_id == nodeid)
  707. return node;
  708. }
  709. return NULL;
  710. }
  711. static int quorum_exec_send_nodeinfo()
  712. {
  713. struct req_exec_quorum_nodeinfo req_exec_quorum_nodeinfo;
  714. int ret;
  715. ENTER();
  716. req_exec_quorum_nodeinfo.cmd = VOTEQUORUM_MSG_NODEINFO;
  717. req_exec_quorum_nodeinfo.expected_votes = us->expected_votes;
  718. req_exec_quorum_nodeinfo.votes = us->votes;
  719. req_exec_quorum_nodeinfo.major_version = VOTEQUORUM_MAJOR_VERSION;
  720. req_exec_quorum_nodeinfo.minor_version = VOTEQUORUM_MINOR_VERSION;
  721. req_exec_quorum_nodeinfo.patch_version = VOTEQUORUM_PATCH_VERSION;
  722. req_exec_quorum_nodeinfo.flags = us->flags;
  723. req_exec_quorum_nodeinfo.first_trans = first_trans;
  724. if (have_disallowed())
  725. req_exec_quorum_nodeinfo.flags |= NODE_FLAGS_SEESDISALLOWED;
  726. ret = votequorum_send_message(&req_exec_quorum_nodeinfo, sizeof(req_exec_quorum_nodeinfo));
  727. LEAVE();
  728. return ret;
  729. }
  730. static int quorum_exec_send_reconfigure(int param, int nodeid, int value)
  731. {
  732. struct req_exec_quorum_reconfigure req_exec_quorum_reconfigure;
  733. int ret;
  734. ENTER();
  735. req_exec_quorum_reconfigure.cmd = VOTEQUORUM_MSG_RECONFIGURE;
  736. req_exec_quorum_reconfigure.param = param;
  737. req_exec_quorum_reconfigure.nodeid = nodeid;
  738. req_exec_quorum_reconfigure.value = value;
  739. ret = votequorum_send_message(&req_exec_quorum_reconfigure, sizeof(req_exec_quorum_reconfigure));
  740. LEAVE();
  741. return ret;
  742. }
  743. static int quorum_exec_send_killnode(int nodeid, unsigned int reason)
  744. {
  745. struct req_exec_quorum_killnode req_exec_quorum_killnode;
  746. int ret;
  747. ENTER();
  748. req_exec_quorum_killnode.cmd = VOTEQUORUM_MSG_KILLNODE;
  749. req_exec_quorum_killnode.nodeid = nodeid;
  750. req_exec_quorum_killnode.reason = reason;
  751. ret = votequorum_send_message(&req_exec_quorum_killnode, sizeof(req_exec_quorum_killnode));
  752. LEAVE();
  753. return ret;
  754. }
  755. static void quorum_confchg_fn (
  756. enum totem_configuration_type configuration_type,
  757. unsigned int *member_list, int member_list_entries,
  758. unsigned int *left_list, int left_list_entries,
  759. unsigned int *joined_list, int joined_list_entries,
  760. struct memb_ring_id *ring_id)
  761. {
  762. int i;
  763. int leaving = 0;
  764. struct cluster_node *node;
  765. ENTER();
  766. if (member_list_entries > 1)
  767. first_trans = 0;
  768. if (left_list_entries) {
  769. for (i = 0; i< left_list_entries; i++) {
  770. node = find_node_by_nodeid(left_list[i]);
  771. if (node) {
  772. if (node->state == NODESTATE_LEAVING)
  773. leaving = 1;
  774. node->state = NODESTATE_DEAD;
  775. node->flags |= NODE_FLAGS_BEENDOWN;
  776. }
  777. }
  778. recalculate_quorum(leaving, leaving);
  779. }
  780. if (member_list_entries) {
  781. memcpy(quorum_members, member_list, sizeof(unsigned int) * member_list_entries);
  782. quorum_members_entries = member_list_entries;
  783. if (quorum_device) {
  784. quorum_members[quorum_members_entries++] = 0;
  785. }
  786. quorum_exec_send_nodeinfo();
  787. }
  788. memcpy(&quorum_ringid, ring_id, sizeof(*ring_id));
  789. LEAVE();
  790. }
  791. static void exec_quorum_nodeinfo_endian_convert (void *msg)
  792. {
  793. struct req_exec_quorum_nodeinfo *nodeinfo = (struct req_exec_quorum_nodeinfo *)msg;
  794. nodeinfo->votes = swab32(nodeinfo->votes);
  795. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  796. nodeinfo->major_version = swab32(nodeinfo->major_version);
  797. nodeinfo->minor_version = swab32(nodeinfo->minor_version);
  798. nodeinfo->patch_version = swab32(nodeinfo->patch_version);
  799. nodeinfo->config_version = swab32(nodeinfo->config_version);
  800. nodeinfo->flags = swab32(nodeinfo->flags);
  801. }
  802. static void exec_quorum_reconfigure_endian_convert (void *msg)
  803. {
  804. struct req_exec_quorum_reconfigure *reconfigure = (struct req_exec_quorum_reconfigure *)msg;
  805. reconfigure->nodeid = swab32(reconfigure->nodeid);
  806. reconfigure->value = swab32(reconfigure->value);
  807. }
  808. static void exec_quorum_killnode_endian_convert (void *msg)
  809. {
  810. struct req_exec_quorum_killnode *killnode = (struct req_exec_quorum_killnode *)msg;
  811. killnode->reason = swab16(killnode->reason);
  812. killnode->nodeid = swab32(killnode->nodeid);
  813. }
  814. static void quorum_deliver_fn(unsigned int nodeid, struct iovec *iovec, int iov_len,
  815. int endian_conversion_required)
  816. {
  817. struct q_protheader *header = iovec->iov_base;
  818. char *buf;
  819. ENTER();
  820. if (endian_conversion_required) {
  821. header->srcid = swab32(header->srcid);
  822. header->tgtid = swab32(header->tgtid);
  823. header->flags = swab32(header->flags);
  824. }
  825. /* Only pass on messages for us or everyone */
  826. if (header->tgtport == 0 &&
  827. (header->tgtid == us->node_id ||
  828. header->tgtid == 0)) {
  829. buf = (char *)(iovec->iov_base) + sizeof(struct q_protheader);
  830. switch (*buf) {
  831. case VOTEQUORUM_MSG_NODEINFO:
  832. if (endian_conversion_required)
  833. exec_quorum_nodeinfo_endian_convert(buf);
  834. message_handler_req_exec_quorum_nodeinfo (buf, header->srcid);
  835. break;
  836. case VOTEQUORUM_MSG_RECONFIGURE:
  837. if (endian_conversion_required)
  838. exec_quorum_reconfigure_endian_convert(buf);
  839. message_handler_req_exec_quorum_reconfigure (buf, header->srcid);
  840. break;
  841. case VOTEQUORUM_MSG_KILLNODE:
  842. if (endian_conversion_required)
  843. exec_quorum_killnode_endian_convert(buf);
  844. message_handler_req_exec_quorum_killnode (buf, header->srcid);
  845. break;
  846. /* Just ignore other messages */
  847. }
  848. }
  849. LEAVE();
  850. }
  851. static void message_handler_req_exec_quorum_nodeinfo (
  852. void *message,
  853. unsigned int nodeid)
  854. {
  855. struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = (struct req_exec_quorum_nodeinfo *)message;
  856. struct cluster_node *node;
  857. int old_votes;
  858. int old_expected;
  859. nodestate_t old_state;
  860. int new_node = 0;
  861. ENTER();
  862. log_printf(LOG_LEVEL_DEBUG, "got nodeinfo message from cluster node %d\n", nodeid);
  863. node = find_node_by_nodeid(nodeid);
  864. if (!node) {
  865. node = allocate_node(nodeid);
  866. new_node = 1;
  867. }
  868. if (!node) {
  869. corosync_api->error_memory_failure();
  870. return;
  871. }
  872. /*
  873. * If the node sending the message sees disallowed nodes and we don't, then
  874. * we have to leave
  875. */
  876. if (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_SEESDISALLOWED && !have_disallowed()) {
  877. /* Must use syslog directly here or the message will never arrive */
  878. syslog(LOG_CRIT, "[VOTEQ]: Joined a cluster with disallowed nodes. must die");
  879. corosync_api->fatal_error(2, __FILE__, __LINE__);
  880. exit(2);
  881. }
  882. old_votes = node->votes;
  883. old_expected = node->expected_votes;
  884. old_state = node->state;
  885. /* Update node state */
  886. if (req_exec_quorum_nodeinfo->minor_version >= 2)
  887. node->votes = req_exec_quorum_nodeinfo->votes;
  888. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  889. node->state = NODESTATE_MEMBER;
  890. /* Check flags for disallowed (if enabled) */
  891. if (quorum_flags & VOTEQUORUM_FLAG_FEATURE_DISALLOWED) {
  892. if ((req_exec_quorum_nodeinfo->flags & NODE_FLAGS_HASSTATE && node->flags & NODE_FLAGS_BEENDOWN) ||
  893. (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_HASSTATE && req_exec_quorum_nodeinfo->first_trans && !(node->flags & NODE_FLAGS_US) && (us->flags & NODE_FLAGS_HASSTATE))) {
  894. if (node->state != NODESTATE_DISALLOWED) {
  895. if (cluster_is_quorate) {
  896. log_printf(LOG_CRIT, "Killing node %d because it has rejoined the cluster with existing state", node->node_id);
  897. node->state = NODESTATE_DISALLOWED;
  898. quorum_exec_send_killnode(nodeid, VOTEQUORUM_REASON_KILL_REJOIN);
  899. }
  900. else {
  901. log_printf(LOG_CRIT, "Node %d not joined to quorum because it has existing state", node->node_id);
  902. node->state = NODESTATE_DISALLOWED;
  903. }
  904. }
  905. }
  906. }
  907. node->flags &= ~NODE_FLAGS_BEENDOWN;
  908. if (new_node || old_votes != node->votes || old_expected != node->expected_votes || old_state != node->state)
  909. recalculate_quorum(0, 0);
  910. LEAVE();
  911. }
  912. static void message_handler_req_exec_quorum_killnode (
  913. void *message,
  914. unsigned int nodeid)
  915. {
  916. struct req_exec_quorum_killnode *req_exec_quorum_killnode = (struct req_exec_quorum_killnode *)message;
  917. if (req_exec_quorum_killnode->nodeid == corosync_api->totem_nodeid_get()) {
  918. log_printf(LOG_CRIT, "Killed by node %d: %s\n", nodeid, kill_reason(req_exec_quorum_killnode->reason));
  919. corosync_api->fatal_error(1, __FILE__, __LINE__);
  920. exit(1);
  921. }
  922. }
  923. static void message_handler_req_exec_quorum_reconfigure (
  924. void *message,
  925. unsigned int nodeid)
  926. {
  927. struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = (struct req_exec_quorum_reconfigure *)message;
  928. struct cluster_node *node;
  929. struct list_head *nodelist;
  930. log_printf(LOG_LEVEL_DEBUG, "got reconfigure message from cluster node %d\n", nodeid);
  931. node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
  932. if (!node)
  933. return;
  934. switch(req_exec_quorum_reconfigure->param)
  935. {
  936. case RECONFIG_PARAM_EXPECTED_VOTES:
  937. list_iterate(nodelist, &cluster_members_list) {
  938. node = list_entry(nodelist, struct cluster_node, list);
  939. if (node->state == NODESTATE_MEMBER &&
  940. node->expected_votes > req_exec_quorum_reconfigure->value) {
  941. node->expected_votes = req_exec_quorum_reconfigure->value;
  942. }
  943. }
  944. send_expectedvotes_notification();
  945. recalculate_quorum(1, 0); /* Allow decrease */
  946. break;
  947. case RECONFIG_PARAM_NODE_VOTES:
  948. node->votes = req_exec_quorum_reconfigure->value;
  949. recalculate_quorum(1, 0); /* Allow decrease */
  950. break;
  951. case RECONFIG_PARAM_LEAVING:
  952. if (req_exec_quorum_reconfigure->value == 1 && node->state == NODESTATE_MEMBER)
  953. node->state = NODESTATE_LEAVING;
  954. if (req_exec_quorum_reconfigure->value == 0 && node->state == NODESTATE_LEAVING)
  955. node->state = NODESTATE_MEMBER;
  956. break;
  957. }
  958. }
  959. static int quorum_lib_init_fn (void *conn)
  960. {
  961. struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  962. ENTER();
  963. list_init (&pd->list);
  964. pd->conn = conn;
  965. LEAVE();
  966. return (0);
  967. }
  968. /*
  969. * Someone called votequorum_leave AGES ago!
  970. * Assume they forgot to shut down the node.
  971. */
  972. static void leaving_timer_fn(void *arg)
  973. {
  974. ENTER();
  975. if (us->state == NODESTATE_LEAVING)
  976. us->state = NODESTATE_MEMBER;
  977. /* Tell everyone else we made a mistake */
  978. quorum_exec_send_reconfigure(RECONFIG_PARAM_LEAVING, us->node_id, 0);
  979. LEAVE();
  980. }
  981. /* Message from the library */
  982. static void message_handler_req_lib_votequorum_getinfo (void *conn, void *message)
  983. {
  984. struct req_lib_votequorum_getinfo *req_lib_votequorum_getinfo = (struct req_lib_votequorum_getinfo *)message;
  985. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  986. struct cluster_node *node;
  987. unsigned int highest_expected = 0;
  988. unsigned int total_votes = 0;
  989. cs_error_t error = CS_OK;
  990. log_printf(LOG_LEVEL_DEBUG, "got getinfo request on %p for node %d\n", conn, req_lib_votequorum_getinfo->nodeid);
  991. if (req_lib_votequorum_getinfo->nodeid) {
  992. node = find_node_by_nodeid(req_lib_votequorum_getinfo->nodeid);
  993. }
  994. else {
  995. node = us;
  996. }
  997. if (node) {
  998. struct cluster_node *iternode;
  999. struct list_head *nodelist;
  1000. list_iterate(nodelist, &cluster_members_list) {
  1001. iternode = list_entry(nodelist, struct cluster_node, list);
  1002. if (iternode->state == NODESTATE_MEMBER) {
  1003. highest_expected =
  1004. max(highest_expected, iternode->expected_votes);
  1005. total_votes += iternode->votes;
  1006. }
  1007. }
  1008. if (quorum_device && quorum_device->state == NODESTATE_MEMBER) {
  1009. total_votes += quorum_device->votes;
  1010. }
  1011. res_lib_votequorum_getinfo.votes = us->votes;
  1012. res_lib_votequorum_getinfo.expected_votes = us->expected_votes;
  1013. res_lib_votequorum_getinfo.highest_expected = highest_expected;
  1014. res_lib_votequorum_getinfo.quorum = quorum;
  1015. res_lib_votequorum_getinfo.total_votes = total_votes;
  1016. res_lib_votequorum_getinfo.flags = 0;
  1017. res_lib_votequorum_getinfo.nodeid = node->node_id;
  1018. if (us->flags & NODE_FLAGS_HASSTATE)
  1019. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_FLAG_HASSTATE;
  1020. if (quorum_flags & VOTEQUORUM_FLAG_FEATURE_TWONODE)
  1021. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_FLAG_TWONODE;
  1022. if (cluster_is_quorate)
  1023. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_FLAG_QUORATE;
  1024. if (us->flags & NODE_FLAGS_SEESDISALLOWED)
  1025. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_FLAG_DISALLOWED;
  1026. }
  1027. else {
  1028. error = CS_ERR_NOT_EXIST;
  1029. }
  1030. res_lib_votequorum_getinfo.header.size = sizeof(res_lib_votequorum_getinfo);
  1031. res_lib_votequorum_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  1032. res_lib_votequorum_getinfo.header.error = error;
  1033. corosync_api->ipc_response_send(conn, &res_lib_votequorum_getinfo, sizeof(res_lib_votequorum_getinfo));
  1034. log_printf(LOG_LEVEL_DEBUG, "getinfo response error: %d\n", error);
  1035. }
  1036. /* Message from the library */
  1037. static void message_handler_req_lib_votequorum_setexpected (void *conn, void *message)
  1038. {
  1039. struct req_lib_votequorum_setexpected *req_lib_votequorum_setexpected = (struct req_lib_votequorum_setexpected *)message;
  1040. struct res_lib_votequorum_status res_lib_votequorum_status;
  1041. cs_error_t error = CS_OK;
  1042. unsigned int newquorum;
  1043. unsigned int total_votes;
  1044. ENTER();
  1045. /*
  1046. * If there are disallowed nodes, then we can't allow the user
  1047. * to bypass them by fiddling with expected votes.
  1048. */
  1049. if (quorum_flags & VOTEQUORUM_FLAG_FEATURE_DISALLOWED && have_disallowed()) {
  1050. error = CS_ERR_EXIST;
  1051. goto error_exit;
  1052. }
  1053. /* Validate new expected votes */
  1054. newquorum = calculate_quorum(1, req_lib_votequorum_setexpected->expected_votes, &total_votes);
  1055. if (newquorum < total_votes / 2
  1056. || newquorum > total_votes) {
  1057. error = CS_ERR_INVALID_PARAM;
  1058. goto error_exit;
  1059. }
  1060. quorum_exec_send_reconfigure(RECONFIG_PARAM_EXPECTED_VOTES, us->node_id, req_lib_votequorum_setexpected->expected_votes);
  1061. /* send status */
  1062. error_exit:
  1063. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1064. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1065. res_lib_votequorum_status.header.error = error;
  1066. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1067. LEAVE();
  1068. }
  1069. /* Message from the library */
  1070. static void message_handler_req_lib_votequorum_setvotes (void *conn, void *message)
  1071. {
  1072. struct req_lib_votequorum_setvotes *req_lib_votequorum_setvotes = (struct req_lib_votequorum_setvotes *)message;
  1073. struct res_lib_votequorum_status res_lib_votequorum_status;
  1074. struct cluster_node *node;
  1075. unsigned int newquorum;
  1076. unsigned int total_votes;
  1077. unsigned int saved_votes;
  1078. cs_error_t error = CS_OK;
  1079. ENTER();
  1080. node = find_node_by_nodeid(req_lib_votequorum_setvotes->nodeid);
  1081. if (!node) {
  1082. error = CS_ERR_NAME_NOT_FOUND;
  1083. goto error_exit;
  1084. }
  1085. /* Check votes is valid */
  1086. saved_votes = node->votes;
  1087. node->votes = req_lib_votequorum_setvotes->votes;
  1088. newquorum = calculate_quorum(1, 0, &total_votes);
  1089. if (newquorum < total_votes / 2 || newquorum > total_votes) {
  1090. node->votes = saved_votes;
  1091. error = CS_ERR_INVALID_PARAM;
  1092. goto error_exit;
  1093. }
  1094. if (!req_lib_votequorum_setvotes->nodeid)
  1095. req_lib_votequorum_setvotes->nodeid = corosync_api->totem_nodeid_get();
  1096. quorum_exec_send_reconfigure(RECONFIG_PARAM_NODE_VOTES, req_lib_votequorum_setvotes->nodeid, req_lib_votequorum_setvotes->votes);
  1097. error_exit:
  1098. /* send status */
  1099. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1100. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1101. res_lib_votequorum_status.header.error = error;
  1102. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1103. LEAVE();
  1104. }
  1105. static void message_handler_req_lib_votequorum_leaving (void *conn, void *message)
  1106. {
  1107. struct res_lib_votequorum_status res_lib_votequorum_status;
  1108. cs_error_t error = CS_OK;
  1109. ENTER();
  1110. quorum_exec_send_reconfigure(RECONFIG_PARAM_LEAVING, us->node_id, 1);
  1111. /*
  1112. * If we don't shut down in a sensible amount of time then cancel the
  1113. * leave status.
  1114. */
  1115. if (leaving_timeout)
  1116. corosync_api->timer_add_duration((unsigned long long)leaving_timeout*1000000, NULL,
  1117. leaving_timer_fn, &leaving_timer);
  1118. /* send status */
  1119. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1120. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1121. res_lib_votequorum_status.header.error = error;
  1122. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1123. LEAVE();
  1124. }
  1125. static void quorum_device_timer_fn(void *arg)
  1126. {
  1127. struct timeval now;
  1128. ENTER();
  1129. if (!quorum_device || quorum_device->state == NODESTATE_DEAD)
  1130. return;
  1131. gettimeofday(&now, NULL);
  1132. if (quorum_device->last_hello.tv_sec + quorumdev_poll/1000 < now.tv_sec) {
  1133. quorum_device->state = NODESTATE_DEAD;
  1134. log_printf(LOG_INFO, "lost contact with quorum device\n");
  1135. recalculate_quorum(0, 0);
  1136. }
  1137. else {
  1138. corosync_api->timer_add_duration((unsigned long long)quorumdev_poll*1000000, quorum_device,
  1139. quorum_device_timer_fn, &quorum_device_timer);
  1140. }
  1141. LEAVE();
  1142. }
  1143. static void message_handler_req_lib_votequorum_qdisk_register (void *conn, void *message)
  1144. {
  1145. struct req_lib_votequorum_qdisk_register *req_lib_votequorum_qdisk_register = (struct req_lib_votequorum_qdisk_register *)message;
  1146. struct res_lib_votequorum_status res_lib_votequorum_status;
  1147. cs_error_t error = CS_OK;
  1148. ENTER();
  1149. if (quorum_device) {
  1150. error = CS_ERR_EXIST;
  1151. }
  1152. else {
  1153. quorum_device = allocate_node(0);
  1154. quorum_device->state = NODESTATE_DEAD;
  1155. quorum_device->votes = req_lib_votequorum_qdisk_register->votes;
  1156. strcpy(quorum_device_name, req_lib_votequorum_qdisk_register->name);
  1157. list_add(&quorum_device->list, &cluster_members_list);
  1158. }
  1159. /* send status */
  1160. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1161. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1162. res_lib_votequorum_status.header.error = error;
  1163. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1164. LEAVE();
  1165. }
  1166. static void message_handler_req_lib_votequorum_qdisk_unregister (void *conn, void *message)
  1167. {
  1168. struct res_lib_votequorum_status res_lib_votequorum_status;
  1169. cs_error_t error = CS_OK;
  1170. ENTER();
  1171. if (quorum_device) {
  1172. struct cluster_node *node = quorum_device;
  1173. quorum_device = NULL;
  1174. list_del(&node->list);
  1175. free(node);
  1176. recalculate_quorum(0, 0);
  1177. }
  1178. else {
  1179. error = CS_ERR_NOT_EXIST;
  1180. }
  1181. /* send status */
  1182. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1183. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1184. res_lib_votequorum_status.header.error = error;
  1185. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1186. LEAVE();
  1187. }
  1188. static void message_handler_req_lib_votequorum_qdisk_poll (void *conn, void *message)
  1189. {
  1190. struct req_lib_votequorum_qdisk_poll *req_lib_votequorum_qdisk_poll = (struct req_lib_votequorum_qdisk_poll *)message;
  1191. struct res_lib_votequorum_status res_lib_votequorum_status;
  1192. cs_error_t error = CS_OK;
  1193. ENTER();
  1194. if (quorum_device) {
  1195. if (req_lib_votequorum_qdisk_poll->state) {
  1196. gettimeofday(&quorum_device->last_hello, NULL);
  1197. if (quorum_device->state == NODESTATE_DEAD) {
  1198. quorum_device->state = NODESTATE_MEMBER;
  1199. recalculate_quorum(0, 0);
  1200. corosync_api->timer_add_duration((unsigned long long)quorumdev_poll*1000000, quorum_device,
  1201. quorum_device_timer_fn, &quorum_device_timer);
  1202. }
  1203. }
  1204. else {
  1205. if (quorum_device->state == NODESTATE_MEMBER) {
  1206. quorum_device->state = NODESTATE_DEAD;
  1207. recalculate_quorum(0, 0);
  1208. corosync_api->timer_delete(quorum_device_timer);
  1209. }
  1210. }
  1211. }
  1212. else {
  1213. error = CS_ERR_NOT_EXIST;
  1214. }
  1215. /* send status */
  1216. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1217. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1218. res_lib_votequorum_status.header.error = error;
  1219. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1220. LEAVE();
  1221. }
  1222. static void message_handler_req_lib_votequorum_qdisk_getinfo (void *conn, void *message)
  1223. {
  1224. struct res_lib_votequorum_qdisk_getinfo res_lib_votequorum_qdisk_getinfo;
  1225. cs_error_t error = CS_OK;
  1226. ENTER();
  1227. if (quorum_device) {
  1228. log_printf(LOG_LEVEL_DEBUG, "got qdisk_getinfo state %d\n", quorum_device->state);
  1229. res_lib_votequorum_qdisk_getinfo.votes = quorum_device->votes;
  1230. if (quorum_device->state == NODESTATE_MEMBER)
  1231. res_lib_votequorum_qdisk_getinfo.state = 1;
  1232. else
  1233. res_lib_votequorum_qdisk_getinfo.state = 0;
  1234. strcpy(res_lib_votequorum_qdisk_getinfo.name, quorum_device_name);
  1235. }
  1236. else {
  1237. error = CS_ERR_NOT_EXIST;
  1238. }
  1239. /* send status */
  1240. res_lib_votequorum_qdisk_getinfo.header.size = sizeof(res_lib_votequorum_qdisk_getinfo);
  1241. res_lib_votequorum_qdisk_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  1242. res_lib_votequorum_qdisk_getinfo.header.error = error;
  1243. corosync_api->ipc_response_send(conn, &res_lib_votequorum_qdisk_getinfo, sizeof(res_lib_votequorum_qdisk_getinfo));
  1244. LEAVE();
  1245. }
  1246. static void message_handler_req_lib_votequorum_setstate (void *conn, void *message)
  1247. {
  1248. struct res_lib_votequorum_status res_lib_votequorum_status;
  1249. cs_error_t error = CS_OK;
  1250. ENTER();
  1251. us->flags |= NODE_FLAGS_HASSTATE;
  1252. /* send status */
  1253. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1254. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1255. res_lib_votequorum_status.header.error = error;
  1256. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1257. LEAVE();
  1258. }
  1259. static void message_handler_req_lib_votequorum_trackstart (void *conn, void *msg)
  1260. {
  1261. struct req_lib_votequorum_trackstart *req_lib_votequorum_trackstart = (struct req_lib_votequorum_trackstart *)msg;
  1262. struct res_lib_votequorum_status res_lib_votequorum_status;
  1263. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1264. ENTER();
  1265. /*
  1266. * If an immediate listing of the current cluster membership
  1267. * is requested, generate membership list
  1268. */
  1269. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
  1270. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
  1271. log_printf(LOG_LEVEL_DEBUG, "sending initial status to %p\n", conn);
  1272. send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
  1273. }
  1274. /*
  1275. * Record requests for tracking
  1276. */
  1277. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES ||
  1278. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
  1279. quorum_pd->track_flags = req_lib_votequorum_trackstart->track_flags;
  1280. quorum_pd->tracking_enabled = 1;
  1281. quorum_pd->tracking_context = req_lib_votequorum_trackstart->context;
  1282. list_add (&quorum_pd->list, &trackers_list);
  1283. }
  1284. /* Send status */
  1285. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1286. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1287. res_lib_votequorum_status.header.error = CS_OK;
  1288. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1289. LEAVE();
  1290. }
  1291. static void message_handler_req_lib_votequorum_trackstop (void *conn, void *msg)
  1292. {
  1293. struct res_lib_votequorum_status res_lib_votequorum_status;
  1294. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1295. int error = CS_OK;
  1296. ENTER();
  1297. if (quorum_pd->tracking_enabled) {
  1298. error = CS_OK;
  1299. quorum_pd->tracking_enabled = 0;
  1300. list_del (&quorum_pd->list);
  1301. list_init (&quorum_pd->list);
  1302. } else {
  1303. error = CS_ERR_NOT_EXIST;
  1304. }
  1305. /* send status */
  1306. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1307. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1308. res_lib_votequorum_status.header.error = error;
  1309. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1310. LEAVE();
  1311. }
  1312. static char *kill_reason(int reason)
  1313. {
  1314. static char msg[1024];
  1315. switch (reason)
  1316. {
  1317. case VOTEQUORUM_REASON_KILL_REJECTED:
  1318. return "our membership application was rejected";
  1319. case VOTEQUORUM_REASON_KILL_APPLICATION:
  1320. return "we were killed by an application request";
  1321. case VOTEQUORUM_REASON_KILL_REJOIN:
  1322. return "we rejoined the cluster without a full restart";
  1323. default:
  1324. sprintf(msg, "we got kill message number %d", reason);
  1325. return msg;
  1326. }
  1327. }
  1328. static void reread_config(hdb_handle_t object_handle)
  1329. {
  1330. unsigned int old_votes;
  1331. unsigned int old_expected;
  1332. old_votes = us->votes;
  1333. old_expected = us->expected_votes;
  1334. /*
  1335. * Reload the configuration
  1336. */
  1337. read_quorum_config(object_handle);
  1338. /*
  1339. * Check for fundamental changes that we need to propogate
  1340. */
  1341. if (old_votes != us->votes) {
  1342. quorum_exec_send_reconfigure(RECONFIG_PARAM_NODE_VOTES, us->node_id, us->votes);
  1343. }
  1344. if (old_expected != us->expected_votes) {
  1345. quorum_exec_send_reconfigure(RECONFIG_PARAM_EXPECTED_VOTES, us->node_id, us->expected_votes);
  1346. }
  1347. }
  1348. static void quorum_key_change_notify(object_change_type_t change_type,
  1349. hdb_handle_t parent_object_handle,
  1350. hdb_handle_t object_handle,
  1351. void *object_name_pt, int object_name_len,
  1352. void *key_name_pt, int key_len,
  1353. void *key_value_pt, int key_value_len,
  1354. void *priv_data_pt)
  1355. {
  1356. if (memcmp(object_name_pt, "quorum", object_name_len) == 0)
  1357. reread_config(object_handle);
  1358. }
  1359. /* Called when the objdb is reloaded */
  1360. static void votequorum_objdb_reload_notify(
  1361. objdb_reload_notify_type_t type, int flush,
  1362. void *priv_data_pt)
  1363. {
  1364. /*
  1365. * A new quorum {} key might exist, cancel the
  1366. * existing notification at the start of reload,
  1367. * and start a new one on the new object when
  1368. * it's all settled.
  1369. */
  1370. if (type == OBJDB_RELOAD_NOTIFY_START) {
  1371. corosync_api->object_track_stop(
  1372. quorum_key_change_notify,
  1373. NULL,
  1374. NULL,
  1375. NULL,
  1376. NULL);
  1377. }
  1378. if (type == OBJDB_RELOAD_NOTIFY_END ||
  1379. type == OBJDB_RELOAD_NOTIFY_FAILED) {
  1380. hdb_handle_t find_handle;
  1381. hdb_handle_t object_handle;
  1382. corosync_api->object_find_create(OBJECT_PARENT_HANDLE, "quorum", strlen("quorum"), &find_handle);
  1383. if (corosync_api->object_find_next(find_handle, &object_handle) == 0) {
  1384. add_votequorum_config_notification(object_handle);
  1385. reread_config(object_handle);
  1386. }
  1387. else {
  1388. log_printf(LOG_LEVEL_ERROR, "votequorum objdb tracking stopped, cannot find quorum{} handle in objdb\n");
  1389. }
  1390. }
  1391. }
  1392. static void add_votequorum_config_notification(
  1393. hdb_handle_t quorum_object_handle)
  1394. {
  1395. corosync_api->object_track_start(quorum_object_handle,
  1396. 1,
  1397. quorum_key_change_notify,
  1398. NULL,
  1399. NULL,
  1400. NULL,
  1401. NULL);
  1402. /*
  1403. * Reload notify must be on the parent object
  1404. */
  1405. corosync_api->object_track_start(OBJECT_PARENT_HANDLE,
  1406. 1,
  1407. NULL,
  1408. NULL,
  1409. NULL,
  1410. votequorum_objdb_reload_notify,
  1411. NULL);
  1412. }