votequorum.c 51 KB

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