votequorum.c 66 KB

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