votequorum.c 66 KB

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