votequorum.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393
  1. /*
  2. * Copyright (c) 2009-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Authors: Christine Caulfield (ccaulfie@redhat.com)
  7. * Fabio M. Di Nitto (fdinitto@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <config.h>
  36. #include <sys/types.h>
  37. #include <stdint.h>
  38. #include <qb/qbipc_common.h>
  39. #include "quorum.h"
  40. #include <corosync/corodefs.h>
  41. #include <corosync/list.h>
  42. #include <corosync/logsys.h>
  43. #include <corosync/coroapi.h>
  44. #include <corosync/icmap.h>
  45. #include <corosync/ipc_votequorum.h>
  46. #include "service.h"
  47. LOGSYS_DECLARE_SUBSYS ("VOTEQ");
  48. /*
  49. * interface with corosync
  50. */
  51. static struct corosync_api_v1 *corosync_api;
  52. /*
  53. * votequorum global config vars
  54. */
  55. #define DEFAULT_QDEVICE_TIMEOUT 10000
  56. static char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  57. static struct cluster_node *qdevice = NULL;
  58. static unsigned int qdevice_timeout = DEFAULT_QDEVICE_TIMEOUT;
  59. static uint8_t qdevice_can_operate = 1;
  60. static void *qdevice_reg_conn = NULL;
  61. static uint8_t qdevice_master_wins = 0;
  62. static uint8_t two_node = 0;
  63. static uint8_t wait_for_all = 0;
  64. static uint8_t wait_for_all_status = 0;
  65. static uint8_t auto_tie_breaker = 0;
  66. static int lowest_node_id = -1;
  67. #define DEFAULT_LMS_WIN 10000
  68. static uint8_t last_man_standing = 0;
  69. static uint32_t last_man_standing_window = DEFAULT_LMS_WIN;
  70. static uint8_t allow_downscale = 0;
  71. static uint32_t ev_barrier = 0;
  72. /*
  73. * votequorum_exec defines/structs/forward definitions
  74. */
  75. struct req_exec_quorum_nodeinfo {
  76. struct qb_ipc_request_header header __attribute__((aligned(8)));
  77. uint32_t nodeid;
  78. uint32_t votes;
  79. uint32_t expected_votes;
  80. uint32_t flags;
  81. } __attribute__((packed));
  82. struct req_exec_quorum_reconfigure {
  83. struct qb_ipc_request_header header __attribute__((aligned(8)));
  84. uint32_t nodeid;
  85. uint32_t value;
  86. uint8_t param;
  87. uint8_t _pad0;
  88. uint8_t _pad1;
  89. uint8_t _pad2;
  90. } __attribute__((packed));
  91. struct req_exec_quorum_qdevice_reg {
  92. struct qb_ipc_request_header header __attribute__((aligned(8)));
  93. uint32_t operation;
  94. char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  95. } __attribute__((packed));
  96. struct req_exec_quorum_qdevice_reconfigure {
  97. struct qb_ipc_request_header header __attribute__((aligned(8)));
  98. char oldname[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  99. char newname[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  100. } __attribute__((packed));
  101. /*
  102. * votequorum_exec onwire version (via totem)
  103. */
  104. #include "votequorum.h"
  105. /*
  106. * votequorum_exec onwire messages (via totem)
  107. */
  108. #define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO 0
  109. #define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE 1
  110. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG 2
  111. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE 3
  112. static void votequorum_exec_send_expectedvotes_notification(void);
  113. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context);
  114. #define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES 1
  115. #define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES 2
  116. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value);
  117. /*
  118. * used by req_exec_quorum_qdevice_reg
  119. */
  120. #define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER 0
  121. #define VOTEQUORUM_QDEVICE_OPERATION_REGISTER 1
  122. /*
  123. * votequorum internal node status/view
  124. */
  125. #define NODE_FLAGS_QUORATE 1
  126. #define NODE_FLAGS_LEAVING 2
  127. #define NODE_FLAGS_WFASTATUS 4
  128. #define NODE_FLAGS_FIRST 8
  129. #define NODE_FLAGS_QDEVICE_REGISTERED 16
  130. #define NODE_FLAGS_QDEVICE_ALIVE 32
  131. #define NODE_FLAGS_QDEVICE_CAST_VOTE 64
  132. #define NODEID_QDEVICE 0
  133. typedef enum {
  134. NODESTATE_MEMBER=1,
  135. NODESTATE_DEAD,
  136. NODESTATE_LEAVING
  137. } nodestate_t;
  138. struct cluster_node {
  139. int node_id;
  140. nodestate_t state;
  141. uint32_t votes;
  142. uint32_t expected_votes;
  143. uint32_t flags;
  144. struct list_head list;
  145. };
  146. /*
  147. * votequorum internal quorum status
  148. */
  149. static uint8_t quorum;
  150. static uint8_t cluster_is_quorate;
  151. /*
  152. * votequorum membership data
  153. */
  154. static struct cluster_node *us;
  155. static struct list_head cluster_members_list;
  156. static unsigned int quorum_members[PROCESSOR_COUNT_MAX];
  157. static int quorum_members_entries = 0;
  158. static struct memb_ring_id quorum_ringid;
  159. /*
  160. * pre allocate all cluster_nodes + one for qdevice
  161. */
  162. static struct cluster_node cluster_nodes[PROCESSOR_COUNT_MAX+2];
  163. static int cluster_nodes_entries = 0;
  164. /*
  165. * votequorum tracking
  166. */
  167. struct quorum_pd {
  168. unsigned char track_flags;
  169. int tracking_enabled;
  170. uint64_t tracking_context;
  171. struct list_head list;
  172. void *conn;
  173. };
  174. static struct list_head trackers_list;
  175. /*
  176. * votequorum timers
  177. */
  178. static corosync_timer_handle_t qdevice_timer;
  179. static int qdevice_timer_set = 0;
  180. static corosync_timer_handle_t last_man_standing_timer;
  181. static int last_man_standing_timer_set = 0;
  182. /*
  183. * Service Interfaces required by service_message_handler struct
  184. */
  185. static void votequorum_confchg_fn (
  186. enum totem_configuration_type configuration_type,
  187. const unsigned int *member_list, size_t member_list_entries,
  188. const unsigned int *left_list, size_t left_list_entries,
  189. const unsigned int *joined_list, size_t joined_list_entries,
  190. const struct memb_ring_id *ring_id);
  191. static quorum_set_quorate_fn_t quorum_callback;
  192. /*
  193. * votequorum_exec handler and definitions
  194. */
  195. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api);
  196. static int votequorum_exec_exit_fn (void);
  197. static int votequorum_exec_send_nodeinfo(uint32_t nodeid);
  198. static void message_handler_req_exec_votequorum_nodeinfo (
  199. const void *message,
  200. unsigned int nodeid);
  201. static void exec_votequorum_nodeinfo_endian_convert (void *message);
  202. static void message_handler_req_exec_votequorum_reconfigure (
  203. const void *message,
  204. unsigned int nodeid);
  205. static void exec_votequorum_reconfigure_endian_convert (void *message);
  206. static void message_handler_req_exec_votequorum_qdevice_reg (
  207. const void *message,
  208. unsigned int nodeid);
  209. static void exec_votequorum_qdevice_reg_endian_convert (void *message);
  210. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  211. const void *message,
  212. unsigned int nodeid);
  213. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message);
  214. static struct corosync_exec_handler votequorum_exec_engine[] =
  215. {
  216. { /* 0 */
  217. .exec_handler_fn = message_handler_req_exec_votequorum_nodeinfo,
  218. .exec_endian_convert_fn = exec_votequorum_nodeinfo_endian_convert
  219. },
  220. { /* 1 */
  221. .exec_handler_fn = message_handler_req_exec_votequorum_reconfigure,
  222. .exec_endian_convert_fn = exec_votequorum_reconfigure_endian_convert
  223. },
  224. { /* 2 */
  225. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reg,
  226. .exec_endian_convert_fn = exec_votequorum_qdevice_reg_endian_convert
  227. },
  228. { /* 3 */
  229. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reconfigure,
  230. .exec_endian_convert_fn = exec_votequorum_qdevice_reconfigure_endian_convert
  231. },
  232. };
  233. /*
  234. * Library Handler and Functions Definitions
  235. */
  236. static int quorum_lib_init_fn (void *conn);
  237. static int quorum_lib_exit_fn (void *conn);
  238. static void message_handler_req_lib_votequorum_getinfo (void *conn,
  239. const void *message);
  240. static void message_handler_req_lib_votequorum_setexpected (void *conn,
  241. const void *message);
  242. static void message_handler_req_lib_votequorum_setvotes (void *conn,
  243. const void *message);
  244. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  245. const void *message);
  246. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  247. const void *message);
  248. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  249. const void *message);
  250. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  251. const void *message);
  252. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  253. const void *message);
  254. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  255. const void *message);
  256. static struct corosync_lib_handler quorum_lib_service[] =
  257. {
  258. { /* 0 */
  259. .lib_handler_fn = message_handler_req_lib_votequorum_getinfo,
  260. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  261. },
  262. { /* 1 */
  263. .lib_handler_fn = message_handler_req_lib_votequorum_setexpected,
  264. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  265. },
  266. { /* 2 */
  267. .lib_handler_fn = message_handler_req_lib_votequorum_setvotes,
  268. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  269. },
  270. { /* 3 */
  271. .lib_handler_fn = message_handler_req_lib_votequorum_trackstart,
  272. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  273. },
  274. { /* 4 */
  275. .lib_handler_fn = message_handler_req_lib_votequorum_trackstop,
  276. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  277. },
  278. { /* 5 */
  279. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_register,
  280. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  281. },
  282. { /* 6 */
  283. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_unregister,
  284. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  285. },
  286. { /* 7 */
  287. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_update,
  288. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  289. },
  290. { /* 8 */
  291. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_poll,
  292. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  293. }
  294. };
  295. static struct corosync_service_engine votequorum_service_engine = {
  296. .name = "corosync vote quorum service v1.0",
  297. .id = VOTEQUORUM_SERVICE,
  298. .priority = 2,
  299. .private_data_size = sizeof (struct quorum_pd),
  300. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  301. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED,
  302. .lib_init_fn = quorum_lib_init_fn,
  303. .lib_exit_fn = quorum_lib_exit_fn,
  304. .lib_engine = quorum_lib_service,
  305. .lib_engine_count = sizeof (quorum_lib_service) / sizeof (struct corosync_lib_handler),
  306. .exec_init_fn = votequorum_exec_init_fn,
  307. .exec_exit_fn = votequorum_exec_exit_fn,
  308. .exec_engine = votequorum_exec_engine,
  309. .exec_engine_count = sizeof (votequorum_exec_engine) / sizeof (struct corosync_exec_handler),
  310. .confchg_fn = votequorum_confchg_fn
  311. };
  312. struct corosync_service_engine *votequorum_get_service_engine_ver0 (void)
  313. {
  314. return (&votequorum_service_engine);
  315. }
  316. static struct default_service votequorum_service[] = {
  317. {
  318. .name = "corosync_votequorum",
  319. .ver = 0,
  320. .loader = votequorum_get_service_engine_ver0
  321. },
  322. };
  323. /*
  324. * common/utility macros/functions
  325. */
  326. #define max(a,b) (((a) > (b)) ? (a) : (b))
  327. #define list_iterate(v, head) \
  328. for (v = (head)->next; v != head; v = v->next)
  329. static void node_add_ordered(struct cluster_node *newnode)
  330. {
  331. struct cluster_node *node = NULL;
  332. struct list_head *tmp;
  333. struct list_head *newlist = &newnode->list;
  334. ENTER();
  335. list_iterate(tmp, &cluster_members_list) {
  336. node = list_entry(tmp, struct cluster_node, list);
  337. if (newnode->node_id < node->node_id) {
  338. break;
  339. }
  340. }
  341. if (!node) {
  342. list_add(&newnode->list, &cluster_members_list);
  343. } else {
  344. newlist->prev = tmp->prev;
  345. newlist->next = tmp;
  346. tmp->prev->next = newlist;
  347. tmp->prev = newlist;
  348. }
  349. LEAVE();
  350. }
  351. static struct cluster_node *allocate_node(unsigned int nodeid)
  352. {
  353. struct cluster_node *cl = NULL;
  354. struct list_head *tmp;
  355. ENTER();
  356. if (cluster_nodes_entries <= PROCESSOR_COUNT_MAX + 1) {
  357. cl = (struct cluster_node *)&cluster_nodes[cluster_nodes_entries];
  358. cluster_nodes_entries++;
  359. } else {
  360. list_iterate(tmp, &cluster_members_list) {
  361. cl = list_entry(tmp, struct cluster_node, list);
  362. if (cl->state == NODESTATE_DEAD) {
  363. break;
  364. }
  365. }
  366. /*
  367. * this should never happen
  368. */
  369. if (!cl) {
  370. log_printf(LOGSYS_LEVEL_CRIT, "Unable to find memory for node %u data!!", nodeid);
  371. goto out;
  372. }
  373. list_del(tmp);
  374. }
  375. memset(cl, 0, sizeof(struct cluster_node));
  376. cl->node_id = nodeid;
  377. if (nodeid != NODEID_QDEVICE) {
  378. node_add_ordered(cl);
  379. }
  380. out:
  381. LEAVE();
  382. return cl;
  383. }
  384. static struct cluster_node *find_node_by_nodeid(unsigned int nodeid)
  385. {
  386. struct cluster_node *node;
  387. struct list_head *tmp;
  388. ENTER();
  389. if (nodeid == us->node_id) {
  390. LEAVE();
  391. return us;
  392. }
  393. if (nodeid == NODEID_QDEVICE) {
  394. LEAVE();
  395. return qdevice;
  396. }
  397. list_iterate(tmp, &cluster_members_list) {
  398. node = list_entry(tmp, struct cluster_node, list);
  399. if (node->node_id == nodeid) {
  400. LEAVE();
  401. return node;
  402. }
  403. }
  404. LEAVE();
  405. return NULL;
  406. }
  407. static void get_lowest_node_id(void)
  408. {
  409. struct cluster_node *node = NULL;
  410. struct list_head *tmp;
  411. ENTER();
  412. lowest_node_id = us->node_id;
  413. list_iterate(tmp, &cluster_members_list) {
  414. node = list_entry(tmp, struct cluster_node, list);
  415. if ((node->state == NODESTATE_MEMBER) &&
  416. (node->node_id < lowest_node_id)) {
  417. lowest_node_id = node->node_id;
  418. }
  419. }
  420. log_printf(LOGSYS_LEVEL_DEBUG, "lowest node id: %d us: %d", lowest_node_id, us->node_id);
  421. icmap_set_uint32("runtime.votequorum.lowest_node_id", lowest_node_id);
  422. LEAVE();
  423. }
  424. static int check_low_node_id_partition(void)
  425. {
  426. struct cluster_node *node = NULL;
  427. struct list_head *tmp;
  428. int found = 0;
  429. ENTER();
  430. list_iterate(tmp, &cluster_members_list) {
  431. node = list_entry(tmp, struct cluster_node, list);
  432. if ((node->state == NODESTATE_MEMBER) &&
  433. (node->node_id == lowest_node_id)) {
  434. found = 1;
  435. }
  436. }
  437. LEAVE();
  438. return found;
  439. }
  440. static int check_qdevice_master(void)
  441. {
  442. struct cluster_node *node = NULL;
  443. struct list_head *tmp;
  444. int found = 0;
  445. ENTER();
  446. list_iterate(tmp, &cluster_members_list) {
  447. node = list_entry(tmp, struct cluster_node, list);
  448. if ((node->state == NODESTATE_MEMBER) &&
  449. (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE)) {
  450. found = 1;
  451. }
  452. }
  453. LEAVE();
  454. return found;
  455. }
  456. static void decode_flags(uint32_t flags)
  457. {
  458. log_printf(LOGSYS_LEVEL_DEBUG,
  459. "flags: quorate: %s Leaving: %s WFA Status: %s First: %s Qdevice: %s QdeviceAlive: %s QdeviceCastVote: %s",
  460. (flags & NODE_FLAGS_QUORATE)?"Yes":"No",
  461. (flags & NODE_FLAGS_LEAVING)?"Yes":"No",
  462. (flags & NODE_FLAGS_WFASTATUS)?"Yes":"No",
  463. (flags & NODE_FLAGS_FIRST)?"Yes":"No",
  464. (flags & NODE_FLAGS_QDEVICE_REGISTERED)?"Yes":"No",
  465. (flags & NODE_FLAGS_QDEVICE_ALIVE)?"Yes":"No",
  466. (flags & NODE_FLAGS_QDEVICE_CAST_VOTE)?"Yes":"No");
  467. }
  468. static void update_wait_for_all_status(uint8_t wfa_status)
  469. {
  470. wait_for_all_status = wfa_status;
  471. if (wait_for_all_status) {
  472. us->flags |= NODE_FLAGS_WFASTATUS;
  473. } else {
  474. us->flags &= ~NODE_FLAGS_WFASTATUS;
  475. }
  476. icmap_set_uint8("runtime.votequorum.wait_for_all_status",
  477. wait_for_all_status);
  478. }
  479. static void update_two_node(void)
  480. {
  481. icmap_set_uint8("runtime.votequorum.two_node", two_node);
  482. }
  483. static void update_ev_barrier(uint32_t expected_votes)
  484. {
  485. ev_barrier = expected_votes;
  486. icmap_set_uint32("runtime.votequorum.ev_barrier", ev_barrier);
  487. }
  488. static void update_qdevice_can_operate(uint8_t status)
  489. {
  490. qdevice_can_operate = status;
  491. icmap_set_uint8("runtime.votequorum.qdevice_can_operate", qdevice_can_operate);
  492. }
  493. /*
  494. * quorum calculation core bits
  495. */
  496. static int calculate_quorum(int allow_decrease, unsigned int max_expected, unsigned int *ret_total_votes)
  497. {
  498. struct list_head *nodelist;
  499. struct cluster_node *node;
  500. unsigned int total_votes = 0;
  501. unsigned int highest_expected = 0;
  502. unsigned int newquorum, q1, q2;
  503. unsigned int total_nodes = 0;
  504. ENTER();
  505. if ((allow_downscale) && (allow_decrease) && (max_expected)) {
  506. max_expected = max(ev_barrier, max_expected);
  507. }
  508. list_iterate(nodelist, &cluster_members_list) {
  509. node = list_entry(nodelist, struct cluster_node, list);
  510. log_printf(LOGSYS_LEVEL_DEBUG, "node %u state=%d, votes=%u, expected=%u",
  511. node->node_id, node->state, node->votes, node->expected_votes);
  512. if (node->state == NODESTATE_MEMBER) {
  513. if (max_expected) {
  514. node->expected_votes = max_expected;
  515. } else {
  516. highest_expected = max(highest_expected, node->expected_votes);
  517. }
  518. total_votes += node->votes;
  519. total_nodes++;
  520. }
  521. }
  522. if (us->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  523. log_printf(LOGSYS_LEVEL_DEBUG, "node 0 state=1, votes=%u", qdevice->votes);
  524. total_votes += qdevice->votes;
  525. total_nodes++;
  526. }
  527. if (max_expected > 0) {
  528. highest_expected = max_expected;
  529. }
  530. /*
  531. * This quorum calculation is taken from the OpenVMS Cluster Systems
  532. * manual, but, then, you guessed that didn't you
  533. */
  534. q1 = (highest_expected + 2) / 2;
  535. q2 = (total_votes + 2) / 2;
  536. newquorum = max(q1, q2);
  537. /*
  538. * Normally quorum never decreases but the system administrator can
  539. * force it down by setting expected votes to a maximum value
  540. */
  541. if (!allow_decrease) {
  542. newquorum = max(quorum, newquorum);
  543. }
  544. /*
  545. * The special two_node mode allows each of the two nodes to retain
  546. * quorum if the other fails. Only one of the two should live past
  547. * fencing (as both nodes try to fence each other in split-brain.)
  548. * Also: if there are more than two nodes, force us inquorate to avoid
  549. * any damage or confusion.
  550. */
  551. if (two_node && total_nodes <= 2) {
  552. newquorum = 1;
  553. }
  554. if (ret_total_votes) {
  555. *ret_total_votes = total_votes;
  556. }
  557. LEAVE();
  558. return newquorum;
  559. }
  560. static void are_we_quorate(unsigned int total_votes)
  561. {
  562. int quorate;
  563. int quorum_change = 0;
  564. ENTER();
  565. /*
  566. * wait for all nodes to show up before granting quorum
  567. */
  568. if ((wait_for_all) && (wait_for_all_status)) {
  569. if (total_votes != us->expected_votes) {
  570. log_printf(LOGSYS_LEVEL_NOTICE,
  571. "Waiting for all cluster members. "
  572. "Current votes: %d expected_votes: %d",
  573. total_votes, us->expected_votes);
  574. cluster_is_quorate = 0;
  575. return;
  576. }
  577. update_wait_for_all_status(0);
  578. }
  579. if (quorum > total_votes) {
  580. quorate = 0;
  581. } else {
  582. quorate = 1;
  583. get_lowest_node_id();
  584. }
  585. if ((auto_tie_breaker) &&
  586. (total_votes == (us->expected_votes / 2)) &&
  587. (check_low_node_id_partition() == 1)) {
  588. quorate = 1;
  589. }
  590. if ((qdevice_master_wins) &&
  591. (!quorate) &&
  592. (check_qdevice_master() == 1)) {
  593. log_printf(LOGSYS_LEVEL_DEBUG, "node is quorate as part of master_wins partition");
  594. quorate = 1;
  595. }
  596. if (cluster_is_quorate && !quorate) {
  597. quorum_change = 1;
  598. log_printf(LOGSYS_LEVEL_DEBUG, "quorum lost, blocking activity");
  599. }
  600. if (!cluster_is_quorate && quorate) {
  601. quorum_change = 1;
  602. log_printf(LOGSYS_LEVEL_DEBUG, "quorum regained, resuming activity");
  603. }
  604. cluster_is_quorate = quorate;
  605. if (cluster_is_quorate) {
  606. us->flags |= NODE_FLAGS_QUORATE;
  607. } else {
  608. us->flags &= ~NODE_FLAGS_QUORATE;
  609. }
  610. if (wait_for_all) {
  611. if (quorate) {
  612. update_wait_for_all_status(0);
  613. } else {
  614. update_wait_for_all_status(1);
  615. }
  616. }
  617. if (quorum_change) {
  618. quorum_callback(quorum_members, quorum_members_entries,
  619. cluster_is_quorate, &quorum_ringid);
  620. }
  621. LEAVE();
  622. }
  623. static void get_total_votes(unsigned int *totalvotes, unsigned int *current_members)
  624. {
  625. unsigned int total_votes = 0;
  626. unsigned int cluster_members = 0;
  627. struct list_head *nodelist;
  628. struct cluster_node *node;
  629. ENTER();
  630. list_iterate(nodelist, &cluster_members_list) {
  631. node = list_entry(nodelist, struct cluster_node, list);
  632. if (node->state == NODESTATE_MEMBER) {
  633. cluster_members++;
  634. total_votes += node->votes;
  635. }
  636. }
  637. if (qdevice->votes) {
  638. total_votes += qdevice->votes;
  639. cluster_members++;
  640. }
  641. *totalvotes = total_votes;
  642. *current_members = cluster_members;
  643. LEAVE();
  644. }
  645. /*
  646. * Recalculate cluster quorum, set quorate and notify changes
  647. */
  648. static void recalculate_quorum(int allow_decrease, int by_current_nodes)
  649. {
  650. unsigned int total_votes = 0;
  651. unsigned int cluster_members = 0;
  652. ENTER();
  653. get_total_votes(&total_votes, &cluster_members);
  654. if (!by_current_nodes) {
  655. cluster_members = 0;
  656. }
  657. /*
  658. * Keep expected_votes at the highest number of votes in the cluster
  659. */
  660. log_printf(LOGSYS_LEVEL_DEBUG, "total_votes=%d, expected_votes=%d", total_votes, us->expected_votes);
  661. if (total_votes > us->expected_votes) {
  662. us->expected_votes = total_votes;
  663. votequorum_exec_send_expectedvotes_notification();
  664. }
  665. quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
  666. are_we_quorate(total_votes);
  667. votequorum_exec_send_quorum_notification(NULL, 0L);
  668. LEAVE();
  669. }
  670. /*
  671. * configuration bits and pieces
  672. */
  673. static int votequorum_read_nodelist_configuration(uint32_t *votes,
  674. uint32_t *nodes,
  675. uint32_t *expected_votes)
  676. {
  677. icmap_iter_t iter;
  678. const char *iter_key;
  679. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  680. uint32_t our_pos, node_pos;
  681. uint32_t nodecount = 0;
  682. uint32_t nodelist_expected_votes = 0;
  683. uint32_t node_votes = 0;
  684. int res = 0;
  685. ENTER();
  686. if (icmap_get_uint32("nodelist.local_node_pos", &our_pos) != CS_OK) {
  687. log_printf(LOGSYS_LEVEL_DEBUG,
  688. "No nodelist defined or our node is not in the nodelist");
  689. return 0;
  690. }
  691. iter = icmap_iter_init("nodelist.node.");
  692. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  693. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  694. if (res != 2) {
  695. continue;
  696. }
  697. if (strcmp(tmp_key, "ring0_addr") != 0) {
  698. continue;
  699. }
  700. nodecount++;
  701. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.quorum_votes", node_pos);
  702. if (icmap_get_uint32(tmp_key, &node_votes) != CS_OK) {
  703. node_votes = 1;
  704. }
  705. nodelist_expected_votes = nodelist_expected_votes + node_votes;
  706. if (node_pos == our_pos) {
  707. *votes = node_votes;
  708. }
  709. }
  710. *expected_votes = nodelist_expected_votes;
  711. *nodes = nodecount;
  712. icmap_iter_finalize(iter);
  713. LEAVE();
  714. return 1;
  715. }
  716. static int votequorum_qdevice_is_configured(uint32_t *qdevice_votes)
  717. {
  718. char *qdevice_model = NULL;
  719. ENTER();
  720. if ((icmap_get_string("quorum.device.model", &qdevice_model) == CS_OK) &&
  721. (strlen(qdevice_model))) {
  722. free(qdevice_model);
  723. if (icmap_get_uint32("quorum.device.votes", qdevice_votes) != CS_OK) {
  724. *qdevice_votes = -1;
  725. }
  726. if (icmap_get_uint32("quorum.device.timeout", &qdevice_timeout) != CS_OK) {
  727. qdevice_timeout = DEFAULT_QDEVICE_TIMEOUT;
  728. }
  729. if (icmap_get_uint8("quorum.device.master_wins", &qdevice_master_wins) != CS_OK) {
  730. qdevice_master_wins = 0;
  731. }
  732. update_qdevice_can_operate(1);
  733. return 1;
  734. }
  735. LEAVE();
  736. return 0;
  737. }
  738. #define VOTEQUORUM_READCONFIG_STARTUP 0
  739. #define VOTEQUORUM_READCONFIG_RUNTIME 1
  740. static char *votequorum_readconfig(int runtime)
  741. {
  742. uint32_t node_votes = 0, qdevice_votes = 0;
  743. uint32_t node_expected_votes = 0, expected_votes = 0;
  744. uint32_t node_count = 0;
  745. int have_nodelist, have_qdevice;
  746. char *error = NULL;
  747. ENTER();
  748. log_printf(LOGSYS_LEVEL_DEBUG, "Reading configuration (runtime: %d)", runtime);
  749. /*
  750. * gather basic data here
  751. */
  752. icmap_get_uint32("quorum.expected_votes", &expected_votes);
  753. have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
  754. have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
  755. icmap_get_uint8("quorum.two_node", &two_node);
  756. /*
  757. * do config verification and enablement
  758. */
  759. if ((!have_nodelist) && (!expected_votes)) {
  760. if (!runtime) {
  761. error = (char *)"configuration error: nodelist or quorum.expected_votes must be configured!";
  762. } else {
  763. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: nodelist or quorum.expected_votes must be configured!");
  764. log_printf(LOGSYS_LEVEL_CRIT, "will continue with current runtime data");
  765. }
  766. goto out;
  767. }
  768. /*
  769. * two_node and qdevice are not compatible in the same config.
  770. * try to make an educated guess of what to do
  771. */
  772. if ((two_node) && (have_qdevice)) {
  773. if (!runtime) {
  774. error = (char *)"configuration error: two_node and quorum device cannot be configured at the same time!";
  775. goto out;
  776. } else {
  777. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: two_node and quorum device cannot be configured at the same time!");
  778. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  779. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is registered, disabling two_node");
  780. two_node = 0;
  781. } else {
  782. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is not registered, allowing two_node");
  783. update_qdevice_can_operate(0);
  784. }
  785. }
  786. }
  787. /*
  788. * Enable special features
  789. */
  790. if (!runtime) {
  791. if (two_node) {
  792. wait_for_all = 1;
  793. }
  794. icmap_get_uint8("quorum.allow_downscale", &allow_downscale);
  795. icmap_get_uint8("quorum.wait_for_all", &wait_for_all);
  796. icmap_get_uint8("quorum.auto_tie_breaker", &auto_tie_breaker);
  797. icmap_get_uint8("quorum.last_man_standing", &last_man_standing);
  798. icmap_get_uint32("quorum.last_man_standing_window", &last_man_standing_window);
  799. }
  800. /*
  801. * quorum device is not compatible with last_man_standing and auto_tie_breaker
  802. * neither lms or atb can be set at runtime, so there is no need to check for
  803. * runtime incompatibilities, but qdevice can be configured _after_ LMS and ATB have
  804. * been enabled at startup.
  805. */
  806. if ((have_qdevice) && (last_man_standing)) {
  807. if (!runtime) {
  808. error = (char *)"configuration error: quorum.device is not compatible with last_man_standing";
  809. goto out;
  810. } else {
  811. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with last_man_standing");
  812. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  813. update_qdevice_can_operate(0);
  814. }
  815. }
  816. if ((have_qdevice) && (auto_tie_breaker)) {
  817. if (!runtime) {
  818. error = (char *)"configuration error: quorum.device is not compatible with auto_tie_breaker";
  819. goto out;
  820. } else {
  821. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with auto_tie_breaker");
  822. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  823. update_qdevice_can_operate(0);
  824. }
  825. }
  826. if ((have_qdevice) && (wait_for_all)) {
  827. if (!runtime) {
  828. error = (char *)"configuration error: quorum.device is not compatible with wait_for_all";
  829. goto out;
  830. } else {
  831. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with wait_for_all");
  832. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  833. update_qdevice_can_operate(0);
  834. }
  835. }
  836. if ((have_qdevice) && (allow_downscale)) {
  837. if (!runtime) {
  838. error = (char *)"configuration error: quorum.device is not compatible with allow_downscale";
  839. goto out;
  840. } else {
  841. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with allow_downscale");
  842. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  843. update_qdevice_can_operate(0);
  844. }
  845. }
  846. /*
  847. * if user specifies quorum.expected_votes + quorum.device but NOT the device.votes
  848. * we don't know what the quorum device should vote.
  849. */
  850. if ((expected_votes) && (have_qdevice) && (qdevice_votes == -1)) {
  851. if (!runtime) {
  852. error = (char *)"configuration error: quorum.device.votes must be specified when quorum.expected_votes is set";
  853. goto out;
  854. } else {
  855. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when quorum.expected_votes is set");
  856. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  857. update_qdevice_can_operate(0);
  858. }
  859. }
  860. /*
  861. * if user specifies a node list with uneven votes and no device.votes
  862. * we cannot autocalculate the votes
  863. */
  864. if ((have_qdevice) &&
  865. (qdevice_votes == -1) &&
  866. (have_nodelist) &&
  867. (node_count != node_expected_votes)) {
  868. if (!runtime) {
  869. error = (char *)"configuration error: quorum.device.votes must be specified when not all nodes votes 1";
  870. goto out;
  871. } else {
  872. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when not all nodes votes 1");
  873. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  874. update_qdevice_can_operate(0);
  875. }
  876. }
  877. /*
  878. * validate quorum device votes vs expected_votes
  879. */
  880. if ((qdevice_votes > 0) && (expected_votes)) {
  881. int delta = expected_votes - qdevice_votes;
  882. if (delta < 2) {
  883. if (!runtime) {
  884. error = (char *)"configuration error: quorum.device.votes is too high or expected_votes is too low";
  885. goto out;
  886. } else {
  887. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes is too high or expected_votes is too low");
  888. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  889. update_qdevice_can_operate(0);
  890. }
  891. }
  892. }
  893. /*
  894. * automatically calculate device votes and adjust expected_votes from nodelist
  895. */
  896. if ((have_qdevice) &&
  897. (qdevice_votes == -1) &&
  898. (!expected_votes) &&
  899. (have_nodelist) &&
  900. (node_count == node_expected_votes)) {
  901. qdevice_votes = node_expected_votes - 1;
  902. node_expected_votes = node_expected_votes + qdevice_votes;
  903. }
  904. /*
  905. * set this node votes and expected_votes
  906. */
  907. if (have_nodelist) {
  908. us->votes = node_votes;
  909. us->expected_votes = node_expected_votes;
  910. } else {
  911. us->votes = 1;
  912. icmap_get_uint32("quorum.votes", &us->votes);
  913. }
  914. if (expected_votes) {
  915. us->expected_votes = expected_votes;
  916. }
  917. /*
  918. * set qdevice votes
  919. */
  920. if (!have_qdevice) {
  921. qdevice->votes = 0;
  922. }
  923. if (qdevice_votes != -1) {
  924. qdevice->votes = qdevice_votes;
  925. }
  926. update_ev_barrier(us->expected_votes);
  927. update_two_node();
  928. if (wait_for_all) {
  929. update_wait_for_all_status(1);
  930. }
  931. out:
  932. LEAVE();
  933. return error;
  934. }
  935. static void votequorum_refresh_config(
  936. int32_t event,
  937. const char *key_name,
  938. struct icmap_notify_value new_val,
  939. struct icmap_notify_value old_val,
  940. void *user_data)
  941. {
  942. ENTER();
  943. /*
  944. * Reload the configuration
  945. */
  946. votequorum_readconfig(VOTEQUORUM_READCONFIG_RUNTIME);
  947. /*
  948. * activate new config
  949. */
  950. votequorum_exec_send_nodeinfo(us->node_id);
  951. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  952. LEAVE();
  953. }
  954. static void votequorum_exec_add_config_notification(void)
  955. {
  956. icmap_track_t icmap_track_nodelist = NULL;
  957. icmap_track_t icmap_track_quorum = NULL;
  958. ENTER();
  959. icmap_track_add("nodelist.",
  960. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  961. votequorum_refresh_config,
  962. NULL,
  963. &icmap_track_nodelist);
  964. icmap_track_add("quorum.",
  965. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  966. votequorum_refresh_config,
  967. NULL,
  968. &icmap_track_quorum);
  969. LEAVE();
  970. }
  971. /*
  972. * votequorum_exec core
  973. */
  974. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value)
  975. {
  976. struct req_exec_quorum_reconfigure req_exec_quorum_reconfigure;
  977. struct iovec iov[1];
  978. int ret;
  979. ENTER();
  980. req_exec_quorum_reconfigure.nodeid = nodeid;
  981. req_exec_quorum_reconfigure.value = value;
  982. req_exec_quorum_reconfigure.param = param;
  983. req_exec_quorum_reconfigure._pad0 = 0;
  984. req_exec_quorum_reconfigure._pad1 = 0;
  985. req_exec_quorum_reconfigure._pad2 = 0;
  986. req_exec_quorum_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE);
  987. req_exec_quorum_reconfigure.header.size = sizeof(req_exec_quorum_reconfigure);
  988. iov[0].iov_base = (void *)&req_exec_quorum_reconfigure;
  989. iov[0].iov_len = sizeof(req_exec_quorum_reconfigure);
  990. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  991. LEAVE();
  992. return ret;
  993. }
  994. static int votequorum_exec_send_nodeinfo(uint32_t nodeid)
  995. {
  996. struct req_exec_quorum_nodeinfo req_exec_quorum_nodeinfo;
  997. struct iovec iov[1];
  998. struct cluster_node *node;
  999. int ret;
  1000. ENTER();
  1001. node = find_node_by_nodeid(nodeid);
  1002. if (!node) {
  1003. return -1;
  1004. }
  1005. req_exec_quorum_nodeinfo.nodeid = nodeid;
  1006. req_exec_quorum_nodeinfo.votes = node->votes;
  1007. req_exec_quorum_nodeinfo.expected_votes = node->expected_votes;
  1008. req_exec_quorum_nodeinfo.flags = node->flags;
  1009. if (nodeid != NODEID_QDEVICE) {
  1010. decode_flags(node->flags);
  1011. }
  1012. req_exec_quorum_nodeinfo.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO);
  1013. req_exec_quorum_nodeinfo.header.size = sizeof(req_exec_quorum_nodeinfo);
  1014. iov[0].iov_base = (void *)&req_exec_quorum_nodeinfo;
  1015. iov[0].iov_len = sizeof(req_exec_quorum_nodeinfo);
  1016. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1017. LEAVE();
  1018. return ret;
  1019. }
  1020. static int votequorum_exec_send_qdevice_reconfigure(const char *oldname, const char *newname)
  1021. {
  1022. struct req_exec_quorum_qdevice_reconfigure req_exec_quorum_qdevice_reconfigure;
  1023. struct iovec iov[1];
  1024. int ret;
  1025. ENTER();
  1026. req_exec_quorum_qdevice_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE);
  1027. req_exec_quorum_qdevice_reconfigure.header.size = sizeof(req_exec_quorum_qdevice_reconfigure);
  1028. strcpy(req_exec_quorum_qdevice_reconfigure.oldname, oldname);
  1029. strcpy(req_exec_quorum_qdevice_reconfigure.newname, newname);
  1030. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reconfigure;
  1031. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reconfigure);
  1032. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1033. LEAVE();
  1034. return ret;
  1035. }
  1036. static int votequorum_exec_send_qdevice_reg(uint32_t operation, const char *qdevice_name_req)
  1037. {
  1038. struct req_exec_quorum_qdevice_reg req_exec_quorum_qdevice_reg;
  1039. struct iovec iov[1];
  1040. int ret;
  1041. ENTER();
  1042. req_exec_quorum_qdevice_reg.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG);
  1043. req_exec_quorum_qdevice_reg.header.size = sizeof(req_exec_quorum_qdevice_reg);
  1044. req_exec_quorum_qdevice_reg.operation = operation;
  1045. strcpy(req_exec_quorum_qdevice_reg.qdevice_name, qdevice_name_req);
  1046. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reg;
  1047. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reg);
  1048. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1049. LEAVE();
  1050. return ret;
  1051. }
  1052. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context)
  1053. {
  1054. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  1055. struct list_head *tmp;
  1056. struct cluster_node *node;
  1057. int cluster_members = 0;
  1058. int i = 0;
  1059. int size;
  1060. char buf[sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * (PROCESSOR_COUNT_MAX + 2)];
  1061. ENTER();
  1062. list_iterate(tmp, &cluster_members_list) {
  1063. node = list_entry(tmp, struct cluster_node, list);
  1064. cluster_members++;
  1065. }
  1066. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1067. cluster_members++;
  1068. }
  1069. size = sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  1070. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)&buf;
  1071. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  1072. res_lib_votequorum_notification->node_list_entries = cluster_members;
  1073. res_lib_votequorum_notification->context = context;
  1074. list_iterate(tmp, &cluster_members_list) {
  1075. node = list_entry(tmp, struct cluster_node, list);
  1076. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  1077. res_lib_votequorum_notification->node_list[i++].state = node->state;
  1078. }
  1079. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1080. res_lib_votequorum_notification->node_list[i].nodeid = NODEID_QDEVICE;
  1081. res_lib_votequorum_notification->node_list[i++].state = qdevice->state;
  1082. }
  1083. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NOTIFICATION;
  1084. res_lib_votequorum_notification->header.size = size;
  1085. res_lib_votequorum_notification->header.error = CS_OK;
  1086. /* Send it to all interested parties */
  1087. if (conn) {
  1088. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1089. LEAVE();
  1090. return ret;
  1091. } else {
  1092. struct quorum_pd *qpd;
  1093. list_iterate(tmp, &trackers_list) {
  1094. qpd = list_entry(tmp, struct quorum_pd, list);
  1095. res_lib_votequorum_notification->context = qpd->tracking_context;
  1096. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1097. }
  1098. }
  1099. LEAVE();
  1100. return 0;
  1101. }
  1102. static void votequorum_exec_send_expectedvotes_notification(void)
  1103. {
  1104. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  1105. struct quorum_pd *qpd;
  1106. struct list_head *tmp;
  1107. ENTER();
  1108. log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback");
  1109. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  1110. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  1111. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  1112. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  1113. list_iterate(tmp, &trackers_list) {
  1114. qpd = list_entry(tmp, struct quorum_pd, list);
  1115. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  1116. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  1117. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  1118. }
  1119. LEAVE();
  1120. }
  1121. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message)
  1122. {
  1123. ENTER();
  1124. LEAVE();
  1125. }
  1126. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  1127. const void *message,
  1128. unsigned int nodeid)
  1129. {
  1130. const struct req_exec_quorum_qdevice_reconfigure *req_exec_quorum_qdevice_reconfigure = message;
  1131. ENTER();
  1132. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice name change req from node %u [from: %s to: %s]",
  1133. nodeid,
  1134. req_exec_quorum_qdevice_reconfigure->oldname,
  1135. req_exec_quorum_qdevice_reconfigure->newname);
  1136. if (!strcmp(req_exec_quorum_qdevice_reconfigure->oldname, qdevice_name)) {
  1137. log_printf(LOGSYS_LEVEL_DEBUG, "Allowing qdevice rename");
  1138. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1139. strcpy(qdevice_name, req_exec_quorum_qdevice_reconfigure->newname);
  1140. /*
  1141. * TODO: notify qdevices about name change?
  1142. * this is not relevant for now and can wait later on since
  1143. * qdevices are local only and libvotequorum is not final
  1144. */
  1145. }
  1146. LEAVE();
  1147. }
  1148. static void exec_votequorum_qdevice_reg_endian_convert (void *message)
  1149. {
  1150. struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1151. ENTER();
  1152. req_exec_quorum_qdevice_reg->operation = swab32(req_exec_quorum_qdevice_reg->operation);
  1153. LEAVE();
  1154. }
  1155. static void message_handler_req_exec_votequorum_qdevice_reg (
  1156. const void *message,
  1157. unsigned int nodeid)
  1158. {
  1159. const struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1160. struct res_lib_votequorum_status res_lib_votequorum_status;
  1161. int wipe_qdevice_name = 1;
  1162. struct cluster_node *node = NULL;
  1163. struct list_head *tmp;
  1164. cs_error_t error = CS_OK;
  1165. ENTER();
  1166. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice op %u req from node %u [%s]",
  1167. req_exec_quorum_qdevice_reg->operation,
  1168. nodeid, req_exec_quorum_qdevice_reg->qdevice_name);
  1169. switch(req_exec_quorum_qdevice_reg->operation)
  1170. {
  1171. case VOTEQUORUM_QDEVICE_OPERATION_REGISTER:
  1172. if (nodeid != us->node_id) {
  1173. if (!strlen(qdevice_name)) {
  1174. log_printf(LOGSYS_LEVEL_DEBUG, "Remote qdevice name recorded");
  1175. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1176. }
  1177. LEAVE();
  1178. return;
  1179. }
  1180. /*
  1181. * protect against the case where we broadcast qdevice registration
  1182. * to new memebers, we receive the message back, but there is no registration
  1183. * connection in progress
  1184. */
  1185. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1186. LEAVE();
  1187. }
  1188. /*
  1189. * this should NEVER happen
  1190. */
  1191. if (!qdevice_reg_conn) {
  1192. log_printf(LOGSYS_LEVEL_WARNING, "Unable to determine origin of the qdevice register call!");
  1193. LEAVE();
  1194. return;
  1195. }
  1196. /*
  1197. * registering our own device in this case
  1198. */
  1199. if (!strlen(qdevice_name)) {
  1200. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1201. }
  1202. /*
  1203. * check if it is our device or something else
  1204. */
  1205. if ((!strncmp(req_exec_quorum_qdevice_reg->qdevice_name,
  1206. qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN))) {
  1207. us->flags |= NODE_FLAGS_QDEVICE_REGISTERED;
  1208. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  1209. votequorum_exec_send_nodeinfo(us->node_id);
  1210. } else {
  1211. log_printf(LOGSYS_LEVEL_WARNING,
  1212. "A new qdevice with different name (new: %s old: %s) is trying to register!",
  1213. req_exec_quorum_qdevice_reg->qdevice_name, qdevice_name);
  1214. error = CS_ERR_EXIST;
  1215. }
  1216. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1217. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1218. res_lib_votequorum_status.header.error = error;
  1219. corosync_api->ipc_response_send(qdevice_reg_conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1220. qdevice_reg_conn = NULL;
  1221. break;
  1222. case VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER:
  1223. list_iterate(tmp, &cluster_members_list) {
  1224. node = list_entry(tmp, struct cluster_node, list);
  1225. if ((node->state == NODESTATE_MEMBER) &&
  1226. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1227. wipe_qdevice_name = 0;
  1228. }
  1229. }
  1230. if (wipe_qdevice_name) {
  1231. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1232. }
  1233. break;
  1234. }
  1235. LEAVE();
  1236. }
  1237. static void exec_votequorum_nodeinfo_endian_convert (void *message)
  1238. {
  1239. struct req_exec_quorum_nodeinfo *nodeinfo = message;
  1240. ENTER();
  1241. nodeinfo->nodeid = swab32(nodeinfo->nodeid);
  1242. nodeinfo->votes = swab32(nodeinfo->votes);
  1243. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  1244. nodeinfo->flags = swab32(nodeinfo->flags);
  1245. LEAVE();
  1246. }
  1247. static void message_handler_req_exec_votequorum_nodeinfo (
  1248. const void *message,
  1249. unsigned int sender_nodeid)
  1250. {
  1251. const struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = message;
  1252. struct cluster_node *node = NULL;
  1253. int old_votes;
  1254. int old_expected;
  1255. uint32_t old_flags;
  1256. nodestate_t old_state;
  1257. int new_node = 0;
  1258. int allow_downgrade = 0;
  1259. int by_node = 0;
  1260. unsigned int nodeid = req_exec_quorum_nodeinfo->nodeid;
  1261. ENTER();
  1262. log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %u", sender_nodeid);
  1263. log_printf(LOGSYS_LEVEL_DEBUG, "nodeinfo message[%u]: votes: %d, expected: %d flags: %d",
  1264. nodeid,
  1265. req_exec_quorum_nodeinfo->votes,
  1266. req_exec_quorum_nodeinfo->expected_votes,
  1267. req_exec_quorum_nodeinfo->flags);
  1268. if (nodeid != NODEID_QDEVICE) {
  1269. decode_flags(req_exec_quorum_nodeinfo->flags);
  1270. }
  1271. node = find_node_by_nodeid(nodeid);
  1272. if (!node) {
  1273. node = allocate_node(nodeid);
  1274. new_node = 1;
  1275. }
  1276. if (!node) {
  1277. corosync_api->error_memory_failure();
  1278. LEAVE();
  1279. return;
  1280. }
  1281. if (new_node) {
  1282. old_votes = 0;
  1283. old_expected = 0;
  1284. old_state = NODESTATE_DEAD;
  1285. old_flags = 0;
  1286. } else {
  1287. old_votes = node->votes;
  1288. old_expected = node->expected_votes;
  1289. old_state = node->state;
  1290. old_flags = node->flags;
  1291. }
  1292. if (nodeid == NODEID_QDEVICE) {
  1293. struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
  1294. if ((!cluster_is_quorate) &&
  1295. (sender_node->flags & NODE_FLAGS_QUORATE)) {
  1296. node->votes = req_exec_quorum_nodeinfo->votes;
  1297. } else {
  1298. node->votes = max(node->votes, req_exec_quorum_nodeinfo->votes);
  1299. }
  1300. goto recalculate;
  1301. }
  1302. /* Update node state */
  1303. node->flags = req_exec_quorum_nodeinfo->flags;
  1304. node->votes = req_exec_quorum_nodeinfo->votes;
  1305. node->state = NODESTATE_MEMBER;
  1306. if (node->flags & NODE_FLAGS_LEAVING) {
  1307. node->state = NODESTATE_LEAVING;
  1308. allow_downgrade = 1;
  1309. by_node = 1;
  1310. }
  1311. if ((!cluster_is_quorate) &&
  1312. (node->flags & NODE_FLAGS_QUORATE)) {
  1313. allow_downgrade = 1;
  1314. us->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1315. }
  1316. if (node->flags & NODE_FLAGS_QUORATE) {
  1317. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1318. } else {
  1319. node->expected_votes = us->expected_votes;
  1320. }
  1321. if ((last_man_standing) && (node->votes > 1)) {
  1322. log_printf(LOGSYS_LEVEL_WARNING, "Last Man Standing feature is supported only when all"
  1323. "cluster nodes votes are set to 1. Disabling LMS.");
  1324. last_man_standing = 0;
  1325. if (last_man_standing_timer_set) {
  1326. corosync_api->timer_delete(last_man_standing_timer);
  1327. last_man_standing_timer_set = 0;
  1328. }
  1329. }
  1330. recalculate:
  1331. if ((new_node) ||
  1332. (nodeid == us->node_id) ||
  1333. (node->flags & NODE_FLAGS_FIRST) ||
  1334. (old_votes != node->votes) ||
  1335. (old_expected != node->expected_votes) ||
  1336. (old_flags != node->flags) ||
  1337. (old_state != node->state)) {
  1338. recalculate_quorum(allow_downgrade, by_node);
  1339. }
  1340. if ((wait_for_all) &&
  1341. (!(node->flags & NODE_FLAGS_WFASTATUS)) &&
  1342. (node->flags & NODE_FLAGS_QUORATE)) {
  1343. update_wait_for_all_status(0);
  1344. }
  1345. LEAVE();
  1346. }
  1347. static void exec_votequorum_reconfigure_endian_convert (void *message)
  1348. {
  1349. struct req_exec_quorum_reconfigure *reconfigure = message;
  1350. ENTER();
  1351. reconfigure->nodeid = swab32(reconfigure->nodeid);
  1352. reconfigure->value = swab32(reconfigure->value);
  1353. LEAVE();
  1354. }
  1355. static void message_handler_req_exec_votequorum_reconfigure (
  1356. const void *message,
  1357. unsigned int nodeid)
  1358. {
  1359. const struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = message;
  1360. struct cluster_node *node;
  1361. struct list_head *nodelist;
  1362. ENTER();
  1363. log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %u for %u",
  1364. nodeid, req_exec_quorum_reconfigure->nodeid);
  1365. switch(req_exec_quorum_reconfigure->param)
  1366. {
  1367. case VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES:
  1368. list_iterate(nodelist, &cluster_members_list) {
  1369. node = list_entry(nodelist, struct cluster_node, list);
  1370. if (node->state == NODESTATE_MEMBER) {
  1371. node->expected_votes = req_exec_quorum_reconfigure->value;
  1372. }
  1373. }
  1374. votequorum_exec_send_expectedvotes_notification();
  1375. update_ev_barrier(req_exec_quorum_reconfigure->value);
  1376. recalculate_quorum(1, 0); /* Allow decrease */
  1377. break;
  1378. case VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES:
  1379. node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
  1380. if (!node) {
  1381. LEAVE();
  1382. return;
  1383. }
  1384. node->votes = req_exec_quorum_reconfigure->value;
  1385. recalculate_quorum(1, 0); /* Allow decrease */
  1386. break;
  1387. }
  1388. LEAVE();
  1389. }
  1390. static int votequorum_exec_exit_fn (void)
  1391. {
  1392. int ret = 0;
  1393. ENTER();
  1394. /*
  1395. * tell the other nodes we are leaving
  1396. */
  1397. if (allow_downscale) {
  1398. us->flags |= NODE_FLAGS_LEAVING;
  1399. ret = votequorum_exec_send_nodeinfo(us->node_id);
  1400. }
  1401. /*
  1402. * clean up our internals
  1403. */
  1404. /*
  1405. * free the node list and qdevice
  1406. */
  1407. list_init(&cluster_members_list);
  1408. qdevice = NULL;
  1409. us = NULL;
  1410. memset(cluster_nodes, 0, sizeof(cluster_nodes));
  1411. /*
  1412. * clean the tracking list
  1413. */
  1414. list_init(&trackers_list);
  1415. LEAVE();
  1416. return ret;
  1417. }
  1418. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api)
  1419. {
  1420. char *error = NULL;
  1421. #ifdef COROSYNC_SOLARIS
  1422. logsys_subsys_init();
  1423. #endif
  1424. ENTER();
  1425. list_init(&cluster_members_list);
  1426. list_init(&trackers_list);
  1427. /*
  1428. * Allocate a cluster_node for qdevice
  1429. */
  1430. qdevice = allocate_node(NODEID_QDEVICE);
  1431. if (!qdevice) {
  1432. LEAVE();
  1433. return ((char *)"Could not allocate node.");
  1434. }
  1435. qdevice->votes = 0;
  1436. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1437. /*
  1438. * Allocate a cluster_node for us
  1439. */
  1440. us = allocate_node(corosync_api->totem_nodeid_get());
  1441. if (!us) {
  1442. LEAVE();
  1443. return ((char *)"Could not allocate node.");
  1444. }
  1445. icmap_set_uint32("runtime.votequorum.this_node_id", us->node_id);
  1446. us->state = NODESTATE_MEMBER;
  1447. us->votes = 1;
  1448. us->flags |= NODE_FLAGS_FIRST;
  1449. error = votequorum_readconfig(VOTEQUORUM_READCONFIG_STARTUP);
  1450. if (error) {
  1451. return error;
  1452. }
  1453. recalculate_quorum(0, 0);
  1454. /*
  1455. * Listen for changes
  1456. */
  1457. votequorum_exec_add_config_notification();
  1458. /*
  1459. * Start us off with one node
  1460. */
  1461. votequorum_exec_send_nodeinfo(us->node_id);
  1462. LEAVE();
  1463. return (NULL);
  1464. }
  1465. /*
  1466. * votequorum service core
  1467. */
  1468. static void votequorum_last_man_standing_timer_fn(void *arg)
  1469. {
  1470. ENTER();
  1471. last_man_standing_timer_set = 0;
  1472. if (cluster_is_quorate) {
  1473. recalculate_quorum(1,1);
  1474. }
  1475. LEAVE();
  1476. }
  1477. static void votequorum_confchg_fn (
  1478. enum totem_configuration_type configuration_type,
  1479. const unsigned int *member_list, size_t member_list_entries,
  1480. const unsigned int *left_list, size_t left_list_entries,
  1481. const unsigned int *joined_list, size_t joined_list_entries,
  1482. const struct memb_ring_id *ring_id)
  1483. {
  1484. int i;
  1485. struct cluster_node *node;
  1486. ENTER();
  1487. if (member_list_entries > 1) {
  1488. us->flags &= ~NODE_FLAGS_FIRST;
  1489. }
  1490. if (left_list_entries) {
  1491. for (i = 0; i< left_list_entries; i++) {
  1492. node = find_node_by_nodeid(left_list[i]);
  1493. if (node) {
  1494. node->state = NODESTATE_DEAD;
  1495. }
  1496. }
  1497. }
  1498. if (last_man_standing) {
  1499. if (((member_list_entries >= quorum) && (left_list_entries)) ||
  1500. ((member_list_entries <= quorum) && (auto_tie_breaker) && (check_low_node_id_partition() == 1))) {
  1501. if (last_man_standing_timer_set) {
  1502. corosync_api->timer_delete(last_man_standing_timer);
  1503. last_man_standing_timer_set = 0;
  1504. }
  1505. corosync_api->timer_add_duration((unsigned long long)last_man_standing_window*1000000,
  1506. NULL, votequorum_last_man_standing_timer_fn,
  1507. &last_man_standing_timer);
  1508. last_man_standing_timer_set = 1;
  1509. }
  1510. }
  1511. if (member_list_entries) {
  1512. memcpy(quorum_members, member_list, sizeof(unsigned int) * member_list_entries);
  1513. quorum_members_entries = member_list_entries;
  1514. votequorum_exec_send_nodeinfo(us->node_id);
  1515. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  1516. if (strlen(qdevice_name)) {
  1517. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1518. qdevice_name);
  1519. }
  1520. }
  1521. memcpy(&quorum_ringid, ring_id, sizeof(*ring_id));
  1522. if (left_list_entries) {
  1523. recalculate_quorum(0, 0);
  1524. }
  1525. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  1526. quorum_callback(quorum_members, quorum_members_entries,
  1527. cluster_is_quorate, &quorum_ringid);
  1528. }
  1529. LEAVE();
  1530. }
  1531. char *votequorum_init(struct corosync_api_v1 *api,
  1532. quorum_set_quorate_fn_t q_set_quorate_fn)
  1533. {
  1534. char *error;
  1535. ENTER();
  1536. if (q_set_quorate_fn == NULL) {
  1537. return ((char *)"Quorate function not set");
  1538. }
  1539. corosync_api = api;
  1540. quorum_callback = q_set_quorate_fn;
  1541. error = corosync_service_link_and_init(corosync_api,
  1542. &votequorum_service[0]);
  1543. if (error) {
  1544. return (error);
  1545. }
  1546. LEAVE();
  1547. return (NULL);
  1548. }
  1549. /*
  1550. * Library Handler init/fini
  1551. */
  1552. static int quorum_lib_init_fn (void *conn)
  1553. {
  1554. struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1555. ENTER();
  1556. list_init (&pd->list);
  1557. pd->conn = conn;
  1558. LEAVE();
  1559. return (0);
  1560. }
  1561. static int quorum_lib_exit_fn (void *conn)
  1562. {
  1563. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1564. ENTER();
  1565. if (quorum_pd->tracking_enabled) {
  1566. list_del (&quorum_pd->list);
  1567. list_init (&quorum_pd->list);
  1568. }
  1569. LEAVE();
  1570. return (0);
  1571. }
  1572. /*
  1573. * library internal functions
  1574. */
  1575. static void qdevice_timer_fn(void *arg)
  1576. {
  1577. ENTER();
  1578. if ((!(us->flags & NODE_FLAGS_QDEVICE_ALIVE)) ||
  1579. (!qdevice_timer_set)) {
  1580. LEAVE();
  1581. return;
  1582. }
  1583. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1584. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1585. log_printf(LOGSYS_LEVEL_INFO, "lost contact with quorum device %s", qdevice_name);
  1586. votequorum_exec_send_nodeinfo(us->node_id);
  1587. qdevice_timer_set = 0;
  1588. LEAVE();
  1589. }
  1590. /*
  1591. * Library Handler Functions
  1592. */
  1593. static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *message)
  1594. {
  1595. const struct req_lib_votequorum_getinfo *req_lib_votequorum_getinfo = message;
  1596. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  1597. struct cluster_node *node;
  1598. unsigned int highest_expected = 0;
  1599. unsigned int total_votes = 0;
  1600. cs_error_t error = CS_OK;
  1601. uint32_t nodeid = req_lib_votequorum_getinfo->nodeid;
  1602. ENTER();
  1603. log_printf(LOGSYS_LEVEL_DEBUG, "got getinfo request on %p for node %u", conn, req_lib_votequorum_getinfo->nodeid);
  1604. if (nodeid == NODEID_QDEVICE) {
  1605. nodeid = us->node_id;
  1606. }
  1607. node = find_node_by_nodeid(nodeid);
  1608. if (node) {
  1609. struct cluster_node *iternode;
  1610. struct list_head *nodelist;
  1611. list_iterate(nodelist, &cluster_members_list) {
  1612. iternode = list_entry(nodelist, struct cluster_node, list);
  1613. if (iternode->state == NODESTATE_MEMBER) {
  1614. highest_expected =
  1615. max(highest_expected, iternode->expected_votes);
  1616. total_votes += iternode->votes;
  1617. }
  1618. }
  1619. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1620. total_votes += qdevice->votes;
  1621. }
  1622. switch(node->state) {
  1623. case NODESTATE_MEMBER:
  1624. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_MEMBER;
  1625. break;
  1626. case NODESTATE_DEAD:
  1627. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_DEAD;
  1628. break;
  1629. case NODESTATE_LEAVING:
  1630. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_LEAVING;
  1631. break;
  1632. default:
  1633. res_lib_votequorum_getinfo.state = node->state;
  1634. break;
  1635. }
  1636. res_lib_votequorum_getinfo.state = node->state;
  1637. res_lib_votequorum_getinfo.votes = node->votes;
  1638. res_lib_votequorum_getinfo.expected_votes = node->expected_votes;
  1639. res_lib_votequorum_getinfo.highest_expected = highest_expected;
  1640. res_lib_votequorum_getinfo.quorum = quorum;
  1641. res_lib_votequorum_getinfo.total_votes = total_votes;
  1642. res_lib_votequorum_getinfo.flags = 0;
  1643. res_lib_votequorum_getinfo.nodeid = node->node_id;
  1644. if (two_node) {
  1645. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_TWONODE;
  1646. }
  1647. if (cluster_is_quorate) {
  1648. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QUORATE;
  1649. }
  1650. if (wait_for_all) {
  1651. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_WAIT_FOR_ALL;
  1652. }
  1653. if (last_man_standing) {
  1654. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_LAST_MAN_STANDING;
  1655. }
  1656. if (auto_tie_breaker) {
  1657. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_AUTO_TIE_BREAKER;
  1658. }
  1659. if (allow_downscale) {
  1660. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_ALLOW_DOWNSCALE;
  1661. }
  1662. memset(res_lib_votequorum_getinfo.qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1663. res_lib_votequorum_getinfo.qdevice_votes = 0;
  1664. if (node->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1665. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_REGISTERED;
  1666. res_lib_votequorum_getinfo.qdevice_votes = qdevice->votes;
  1667. strcpy(res_lib_votequorum_getinfo.qdevice_name, qdevice_name);
  1668. }
  1669. if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  1670. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_ALIVE;
  1671. }
  1672. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1673. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_CAST_VOTE;
  1674. }
  1675. } else {
  1676. error = CS_ERR_NOT_EXIST;
  1677. }
  1678. res_lib_votequorum_getinfo.header.size = sizeof(res_lib_votequorum_getinfo);
  1679. res_lib_votequorum_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  1680. res_lib_votequorum_getinfo.header.error = error;
  1681. corosync_api->ipc_response_send(conn, &res_lib_votequorum_getinfo, sizeof(res_lib_votequorum_getinfo));
  1682. log_printf(LOGSYS_LEVEL_DEBUG, "getinfo response error: %d", error);
  1683. LEAVE();
  1684. }
  1685. static void message_handler_req_lib_votequorum_setexpected (void *conn, const void *message)
  1686. {
  1687. const struct req_lib_votequorum_setexpected *req_lib_votequorum_setexpected = message;
  1688. struct res_lib_votequorum_status res_lib_votequorum_status;
  1689. cs_error_t error = CS_OK;
  1690. unsigned int newquorum;
  1691. unsigned int total_votes;
  1692. uint8_t allow_downscale_status = 0;
  1693. ENTER();
  1694. allow_downscale_status = allow_downscale;
  1695. allow_downscale = 0;
  1696. /*
  1697. * Validate new expected votes
  1698. */
  1699. newquorum = calculate_quorum(1, req_lib_votequorum_setexpected->expected_votes, &total_votes);
  1700. allow_downscale = allow_downscale_status;
  1701. if (newquorum < total_votes / 2 ||
  1702. newquorum > total_votes) {
  1703. error = CS_ERR_INVALID_PARAM;
  1704. goto error_exit;
  1705. }
  1706. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES, us->node_id,
  1707. req_lib_votequorum_setexpected->expected_votes);
  1708. error_exit:
  1709. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1710. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1711. res_lib_votequorum_status.header.error = error;
  1712. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1713. LEAVE();
  1714. }
  1715. static void message_handler_req_lib_votequorum_setvotes (void *conn, const void *message)
  1716. {
  1717. const struct req_lib_votequorum_setvotes *req_lib_votequorum_setvotes = message;
  1718. struct res_lib_votequorum_status res_lib_votequorum_status;
  1719. struct cluster_node *node;
  1720. unsigned int newquorum;
  1721. unsigned int total_votes;
  1722. unsigned int saved_votes;
  1723. cs_error_t error = CS_OK;
  1724. unsigned int nodeid;
  1725. ENTER();
  1726. nodeid = req_lib_votequorum_setvotes->nodeid;
  1727. node = find_node_by_nodeid(nodeid);
  1728. if (!node) {
  1729. error = CS_ERR_NAME_NOT_FOUND;
  1730. goto error_exit;
  1731. }
  1732. /*
  1733. * Check votes is valid
  1734. */
  1735. saved_votes = node->votes;
  1736. node->votes = req_lib_votequorum_setvotes->votes;
  1737. newquorum = calculate_quorum(1, 0, &total_votes);
  1738. if (newquorum < total_votes / 2 ||
  1739. newquorum > total_votes) {
  1740. node->votes = saved_votes;
  1741. error = CS_ERR_INVALID_PARAM;
  1742. goto error_exit;
  1743. }
  1744. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES, nodeid,
  1745. req_lib_votequorum_setvotes->votes);
  1746. error_exit:
  1747. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1748. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1749. res_lib_votequorum_status.header.error = error;
  1750. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1751. LEAVE();
  1752. }
  1753. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  1754. const void *message)
  1755. {
  1756. const struct req_lib_votequorum_trackstart *req_lib_votequorum_trackstart = message;
  1757. struct res_lib_votequorum_status res_lib_votequorum_status;
  1758. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1759. ENTER();
  1760. /*
  1761. * If an immediate listing of the current cluster membership
  1762. * is requested, generate membership list
  1763. */
  1764. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
  1765. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
  1766. log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p", conn);
  1767. votequorum_exec_send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
  1768. }
  1769. /*
  1770. * Record requests for tracking
  1771. */
  1772. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES ||
  1773. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
  1774. quorum_pd->track_flags = req_lib_votequorum_trackstart->track_flags;
  1775. quorum_pd->tracking_enabled = 1;
  1776. quorum_pd->tracking_context = req_lib_votequorum_trackstart->context;
  1777. list_add (&quorum_pd->list, &trackers_list);
  1778. }
  1779. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1780. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1781. res_lib_votequorum_status.header.error = CS_OK;
  1782. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1783. LEAVE();
  1784. }
  1785. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  1786. const void *message)
  1787. {
  1788. struct res_lib_votequorum_status res_lib_votequorum_status;
  1789. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1790. int error = CS_OK;
  1791. ENTER();
  1792. if (quorum_pd->tracking_enabled) {
  1793. error = CS_OK;
  1794. quorum_pd->tracking_enabled = 0;
  1795. list_del (&quorum_pd->list);
  1796. list_init (&quorum_pd->list);
  1797. } else {
  1798. error = CS_ERR_NOT_EXIST;
  1799. }
  1800. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1801. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1802. res_lib_votequorum_status.header.error = error;
  1803. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1804. LEAVE();
  1805. }
  1806. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  1807. const void *message)
  1808. {
  1809. const struct req_lib_votequorum_qdevice_register *req_lib_votequorum_qdevice_register = message;
  1810. struct res_lib_votequorum_status res_lib_votequorum_status;
  1811. cs_error_t error = CS_OK;
  1812. ENTER();
  1813. if (!qdevice_can_operate) {
  1814. log_printf(LOGSYS_LEVEL_INFO, "Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
  1815. error = CS_ERR_ACCESS;
  1816. goto out;
  1817. }
  1818. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1819. if ((!strncmp(req_lib_votequorum_qdevice_register->name,
  1820. qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN))) {
  1821. goto out;
  1822. } else {
  1823. log_printf(LOGSYS_LEVEL_WARNING,
  1824. "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
  1825. req_lib_votequorum_qdevice_register->name, qdevice_name);
  1826. error = CS_ERR_EXIST;
  1827. goto out;
  1828. }
  1829. } else {
  1830. if (qdevice_reg_conn != NULL) {
  1831. log_printf(LOGSYS_LEVEL_WARNING,
  1832. "Registration request already in progress");
  1833. error = CS_ERR_TRY_AGAIN;
  1834. goto out;
  1835. }
  1836. qdevice_reg_conn = conn;
  1837. if (votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1838. req_lib_votequorum_qdevice_register->name) != 0) {
  1839. log_printf(LOGSYS_LEVEL_WARNING,
  1840. "Unable to send qdevice registration request to cluster");
  1841. error = CS_ERR_TRY_AGAIN;
  1842. qdevice_reg_conn = NULL;
  1843. } else {
  1844. LEAVE();
  1845. return;
  1846. }
  1847. }
  1848. out:
  1849. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1850. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1851. res_lib_votequorum_status.header.error = error;
  1852. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1853. LEAVE();
  1854. }
  1855. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  1856. const void *message)
  1857. {
  1858. const struct req_lib_votequorum_qdevice_unregister *req_lib_votequorum_qdevice_unregister = message;
  1859. struct res_lib_votequorum_status res_lib_votequorum_status;
  1860. cs_error_t error = CS_OK;
  1861. ENTER();
  1862. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1863. if (strncmp(req_lib_votequorum_qdevice_unregister->name, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1864. error = CS_ERR_INVALID_PARAM;
  1865. goto out;
  1866. }
  1867. if (qdevice_timer_set) {
  1868. corosync_api->timer_delete(qdevice_timer);
  1869. qdevice_timer_set = 0;
  1870. }
  1871. us->flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
  1872. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1873. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1874. votequorum_exec_send_nodeinfo(us->node_id);
  1875. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER,
  1876. req_lib_votequorum_qdevice_unregister->name);
  1877. } else {
  1878. error = CS_ERR_NOT_EXIST;
  1879. }
  1880. out:
  1881. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1882. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1883. res_lib_votequorum_status.header.error = error;
  1884. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1885. LEAVE();
  1886. }
  1887. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  1888. const void *message)
  1889. {
  1890. const struct req_lib_votequorum_qdevice_update *req_lib_votequorum_qdevice_update = message;
  1891. struct res_lib_votequorum_status res_lib_votequorum_status;
  1892. cs_error_t error = CS_OK;
  1893. ENTER();
  1894. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1895. if (strncmp(req_lib_votequorum_qdevice_update->oldname, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1896. error = CS_ERR_INVALID_PARAM;
  1897. goto out;
  1898. }
  1899. votequorum_exec_send_qdevice_reconfigure(req_lib_votequorum_qdevice_update->oldname,
  1900. req_lib_votequorum_qdevice_update->newname);
  1901. } else {
  1902. error = CS_ERR_NOT_EXIST;
  1903. }
  1904. out:
  1905. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1906. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1907. res_lib_votequorum_status.header.error = error;
  1908. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1909. LEAVE();
  1910. }
  1911. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  1912. const void *message)
  1913. {
  1914. const struct req_lib_votequorum_qdevice_poll *req_lib_votequorum_qdevice_poll = message;
  1915. struct res_lib_votequorum_status res_lib_votequorum_status;
  1916. cs_error_t error = CS_OK;
  1917. uint32_t oldflags;
  1918. ENTER();
  1919. if (!qdevice_can_operate) {
  1920. error = CS_ERR_ACCESS;
  1921. goto out;
  1922. }
  1923. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1924. if (strncmp(req_lib_votequorum_qdevice_poll->name, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1925. error = CS_ERR_INVALID_PARAM;
  1926. goto out;
  1927. }
  1928. if (qdevice_timer_set) {
  1929. corosync_api->timer_delete(qdevice_timer);
  1930. qdevice_timer_set = 0;
  1931. }
  1932. oldflags = us->flags;
  1933. us->flags |= NODE_FLAGS_QDEVICE_ALIVE;
  1934. if (req_lib_votequorum_qdevice_poll->cast_vote) {
  1935. us->flags |= NODE_FLAGS_QDEVICE_CAST_VOTE;
  1936. } else {
  1937. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1938. }
  1939. if (us->flags != oldflags) {
  1940. votequorum_exec_send_nodeinfo(us->node_id);
  1941. }
  1942. corosync_api->timer_add_duration((unsigned long long)qdevice_timeout*1000000, qdevice,
  1943. qdevice_timer_fn, &qdevice_timer);
  1944. qdevice_timer_set = 1;
  1945. } else {
  1946. error = CS_ERR_NOT_EXIST;
  1947. }
  1948. out:
  1949. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1950. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1951. res_lib_votequorum_status.header.error = error;
  1952. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1953. LEAVE();
  1954. }