votequorum.c 65 KB

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