votequorum.c 51 KB

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