votequorum.c 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978
  1. /*
  2. * Copyright (c) 2009-2015 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 <sys/stat.h>
  38. #include <fcntl.h>
  39. #include <stdint.h>
  40. #include <unistd.h>
  41. #include <qb/qbipc_common.h>
  42. #include "quorum.h"
  43. #include <corosync/corodefs.h>
  44. #include <corosync/list.h>
  45. #include <corosync/logsys.h>
  46. #include <corosync/coroapi.h>
  47. #include <corosync/icmap.h>
  48. #include <corosync/votequorum.h>
  49. #include <corosync/ipc_votequorum.h>
  50. #include "service.h"
  51. #include "util.h"
  52. LOGSYS_DECLARE_SUBSYS ("VOTEQ");
  53. /*
  54. * interface with corosync
  55. */
  56. static struct corosync_api_v1 *corosync_api;
  57. /*
  58. * votequorum global config vars
  59. */
  60. static char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  61. static struct cluster_node *qdevice = NULL;
  62. static unsigned int qdevice_timeout = VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT;
  63. static unsigned int qdevice_sync_timeout = VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT;
  64. static uint8_t qdevice_can_operate = 1;
  65. static void *qdevice_reg_conn = NULL;
  66. static uint8_t qdevice_master_wins = 0;
  67. static uint8_t two_node = 0;
  68. static uint8_t wait_for_all = 0;
  69. static uint8_t wait_for_all_status = 0;
  70. static enum {ATB_NONE, ATB_LOWEST, ATB_HIGHEST, ATB_LIST} auto_tie_breaker = ATB_NONE;
  71. static int lowest_node_id = -1;
  72. static int highest_node_id = -1;
  73. #define DEFAULT_LMS_WIN 10000
  74. static uint8_t last_man_standing = 0;
  75. static uint32_t last_man_standing_window = DEFAULT_LMS_WIN;
  76. static uint8_t allow_downscale = 0;
  77. static uint32_t ev_barrier = 0;
  78. static uint8_t ev_tracking = 0;
  79. static uint32_t ev_tracking_barrier = 0;
  80. static int ev_tracking_fd = -1;
  81. /*
  82. * votequorum_exec defines/structs/forward definitions
  83. */
  84. struct req_exec_quorum_nodeinfo {
  85. struct qb_ipc_request_header header __attribute__((aligned(8)));
  86. uint32_t nodeid;
  87. uint32_t votes;
  88. uint32_t expected_votes;
  89. uint32_t flags;
  90. } __attribute__((packed));
  91. struct req_exec_quorum_reconfigure {
  92. struct qb_ipc_request_header header __attribute__((aligned(8)));
  93. uint32_t nodeid;
  94. uint32_t value;
  95. uint8_t param;
  96. uint8_t _pad0;
  97. uint8_t _pad1;
  98. uint8_t _pad2;
  99. } __attribute__((packed));
  100. struct req_exec_quorum_qdevice_reg {
  101. struct qb_ipc_request_header header __attribute__((aligned(8)));
  102. uint32_t operation;
  103. char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  104. } __attribute__((packed));
  105. struct req_exec_quorum_qdevice_reconfigure {
  106. struct qb_ipc_request_header header __attribute__((aligned(8)));
  107. char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  108. char newname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  109. } __attribute__((packed));
  110. /*
  111. * votequorum_exec onwire version (via totem)
  112. */
  113. #include "votequorum.h"
  114. /*
  115. * votequorum_exec onwire messages (via totem)
  116. */
  117. #define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO 0
  118. #define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE 1
  119. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG 2
  120. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE 3
  121. static void votequorum_exec_send_expectedvotes_notification(void);
  122. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context);
  123. #define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES 1
  124. #define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES 2
  125. #define VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA 3
  126. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value);
  127. /*
  128. * used by req_exec_quorum_qdevice_reg
  129. */
  130. #define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER 0
  131. #define VOTEQUORUM_QDEVICE_OPERATION_REGISTER 1
  132. /*
  133. * votequorum internal node status/view
  134. */
  135. #define NODE_FLAGS_QUORATE 1
  136. #define NODE_FLAGS_LEAVING 2
  137. #define NODE_FLAGS_WFASTATUS 4
  138. #define NODE_FLAGS_FIRST 8
  139. #define NODE_FLAGS_QDEVICE_REGISTERED 16
  140. #define NODE_FLAGS_QDEVICE_ALIVE 32
  141. #define NODE_FLAGS_QDEVICE_CAST_VOTE 64
  142. #define NODE_FLAGS_QDEVICE_MASTER_WINS 128
  143. typedef enum {
  144. NODESTATE_MEMBER=1,
  145. NODESTATE_DEAD,
  146. NODESTATE_LEAVING
  147. } nodestate_t;
  148. struct cluster_node {
  149. int node_id;
  150. nodestate_t state;
  151. uint32_t votes;
  152. uint32_t expected_votes;
  153. uint32_t flags;
  154. struct list_head list;
  155. };
  156. /*
  157. * votequorum internal quorum status
  158. */
  159. static uint8_t quorum;
  160. static uint8_t cluster_is_quorate;
  161. /*
  162. * votequorum membership data
  163. */
  164. static struct cluster_node *us;
  165. static struct list_head cluster_members_list;
  166. static unsigned int quorum_members[PROCESSOR_COUNT_MAX];
  167. static unsigned int previous_quorum_members[PROCESSOR_COUNT_MAX];
  168. static unsigned int atb_nodelist[PROCESSOR_COUNT_MAX];
  169. static int quorum_members_entries = 0;
  170. static int previous_quorum_members_entries = 0;
  171. static int atb_nodelist_entries = 0;
  172. static struct memb_ring_id quorum_ringid;
  173. /*
  174. * pre allocate all cluster_nodes + one for qdevice
  175. */
  176. static struct cluster_node cluster_nodes[PROCESSOR_COUNT_MAX+2];
  177. static int cluster_nodes_entries = 0;
  178. /*
  179. * votequorum tracking
  180. */
  181. struct quorum_pd {
  182. unsigned char track_flags;
  183. int tracking_enabled;
  184. uint64_t tracking_context;
  185. struct list_head list;
  186. void *conn;
  187. };
  188. static struct list_head trackers_list;
  189. /*
  190. * votequorum timers
  191. */
  192. static corosync_timer_handle_t qdevice_timer;
  193. static int qdevice_timer_set = 0;
  194. static corosync_timer_handle_t last_man_standing_timer;
  195. static int last_man_standing_timer_set = 0;
  196. static int sync_nodeinfo_sent = 0;
  197. static int sync_wait_for_poll_or_timeout = 0;
  198. /*
  199. * Service Interfaces required by service_message_handler struct
  200. */
  201. static int sync_in_progress = 0;
  202. static void votequorum_sync_init (
  203. const unsigned int *trans_list,
  204. size_t trans_list_entries,
  205. const unsigned int *member_list,
  206. size_t member_list_entries,
  207. const struct memb_ring_id *ring_id);
  208. static int votequorum_sync_process (void);
  209. static void votequorum_sync_activate (void);
  210. static void votequorum_sync_abort (void);
  211. static quorum_set_quorate_fn_t quorum_callback;
  212. /*
  213. * votequorum_exec handler and definitions
  214. */
  215. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api);
  216. static int votequorum_exec_exit_fn (void);
  217. static int votequorum_exec_send_nodeinfo(uint32_t nodeid);
  218. static void message_handler_req_exec_votequorum_nodeinfo (
  219. const void *message,
  220. unsigned int nodeid);
  221. static void exec_votequorum_nodeinfo_endian_convert (void *message);
  222. static void message_handler_req_exec_votequorum_reconfigure (
  223. const void *message,
  224. unsigned int nodeid);
  225. static void exec_votequorum_reconfigure_endian_convert (void *message);
  226. static void message_handler_req_exec_votequorum_qdevice_reg (
  227. const void *message,
  228. unsigned int nodeid);
  229. static void exec_votequorum_qdevice_reg_endian_convert (void *message);
  230. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  231. const void *message,
  232. unsigned int nodeid);
  233. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message);
  234. static struct corosync_exec_handler votequorum_exec_engine[] =
  235. {
  236. { /* 0 */
  237. .exec_handler_fn = message_handler_req_exec_votequorum_nodeinfo,
  238. .exec_endian_convert_fn = exec_votequorum_nodeinfo_endian_convert
  239. },
  240. { /* 1 */
  241. .exec_handler_fn = message_handler_req_exec_votequorum_reconfigure,
  242. .exec_endian_convert_fn = exec_votequorum_reconfigure_endian_convert
  243. },
  244. { /* 2 */
  245. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reg,
  246. .exec_endian_convert_fn = exec_votequorum_qdevice_reg_endian_convert
  247. },
  248. { /* 3 */
  249. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reconfigure,
  250. .exec_endian_convert_fn = exec_votequorum_qdevice_reconfigure_endian_convert
  251. },
  252. };
  253. /*
  254. * Library Handler and Functions Definitions
  255. */
  256. static int quorum_lib_init_fn (void *conn);
  257. static int quorum_lib_exit_fn (void *conn);
  258. static void qdevice_timer_fn(void *arg);
  259. static void message_handler_req_lib_votequorum_getinfo (void *conn,
  260. const void *message);
  261. static void message_handler_req_lib_votequorum_setexpected (void *conn,
  262. const void *message);
  263. static void message_handler_req_lib_votequorum_setvotes (void *conn,
  264. const void *message);
  265. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  266. const void *message);
  267. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  268. const void *message);
  269. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  270. const void *message);
  271. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  272. const void *message);
  273. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  274. const void *message);
  275. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  276. const void *message);
  277. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  278. const void *message);
  279. static struct corosync_lib_handler quorum_lib_service[] =
  280. {
  281. { /* 0 */
  282. .lib_handler_fn = message_handler_req_lib_votequorum_getinfo,
  283. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  284. },
  285. { /* 1 */
  286. .lib_handler_fn = message_handler_req_lib_votequorum_setexpected,
  287. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  288. },
  289. { /* 2 */
  290. .lib_handler_fn = message_handler_req_lib_votequorum_setvotes,
  291. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  292. },
  293. { /* 3 */
  294. .lib_handler_fn = message_handler_req_lib_votequorum_trackstart,
  295. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  296. },
  297. { /* 4 */
  298. .lib_handler_fn = message_handler_req_lib_votequorum_trackstop,
  299. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  300. },
  301. { /* 5 */
  302. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_register,
  303. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  304. },
  305. { /* 6 */
  306. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_unregister,
  307. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  308. },
  309. { /* 7 */
  310. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_update,
  311. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  312. },
  313. { /* 8 */
  314. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_poll,
  315. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  316. },
  317. { /* 9 */
  318. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_master_wins,
  319. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  320. }
  321. };
  322. static struct corosync_service_engine votequorum_service_engine = {
  323. .name = "corosync vote quorum service v1.0",
  324. .id = VOTEQUORUM_SERVICE,
  325. .priority = 2,
  326. .private_data_size = sizeof (struct quorum_pd),
  327. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  328. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED,
  329. .lib_init_fn = quorum_lib_init_fn,
  330. .lib_exit_fn = quorum_lib_exit_fn,
  331. .lib_engine = quorum_lib_service,
  332. .lib_engine_count = sizeof (quorum_lib_service) / sizeof (struct corosync_lib_handler),
  333. .exec_init_fn = votequorum_exec_init_fn,
  334. .exec_exit_fn = votequorum_exec_exit_fn,
  335. .exec_engine = votequorum_exec_engine,
  336. .exec_engine_count = sizeof (votequorum_exec_engine) / sizeof (struct corosync_exec_handler),
  337. .sync_init = votequorum_sync_init,
  338. .sync_process = votequorum_sync_process,
  339. .sync_activate = votequorum_sync_activate,
  340. .sync_abort = votequorum_sync_abort
  341. };
  342. struct corosync_service_engine *votequorum_get_service_engine_ver0 (void)
  343. {
  344. return (&votequorum_service_engine);
  345. }
  346. static struct default_service votequorum_service[] = {
  347. {
  348. .name = "corosync_votequorum",
  349. .ver = 0,
  350. .loader = votequorum_get_service_engine_ver0
  351. },
  352. };
  353. /*
  354. * common/utility macros/functions
  355. */
  356. #define max(a,b) (((a) > (b)) ? (a) : (b))
  357. #define list_iterate(v, head) \
  358. for (v = (head)->next; v != head; v = v->next)
  359. static void node_add_ordered(struct cluster_node *newnode)
  360. {
  361. struct cluster_node *node = NULL;
  362. struct list_head *tmp;
  363. struct list_head *newlist = &newnode->list;
  364. ENTER();
  365. list_iterate(tmp, &cluster_members_list) {
  366. node = list_entry(tmp, struct cluster_node, list);
  367. if (newnode->node_id < node->node_id) {
  368. break;
  369. }
  370. }
  371. if (!node) {
  372. list_add(&newnode->list, &cluster_members_list);
  373. } else {
  374. newlist->prev = tmp->prev;
  375. newlist->next = tmp;
  376. tmp->prev->next = newlist;
  377. tmp->prev = newlist;
  378. }
  379. LEAVE();
  380. }
  381. static struct cluster_node *allocate_node(unsigned int nodeid)
  382. {
  383. struct cluster_node *cl = NULL;
  384. struct list_head *tmp;
  385. ENTER();
  386. if (cluster_nodes_entries <= PROCESSOR_COUNT_MAX + 1) {
  387. cl = (struct cluster_node *)&cluster_nodes[cluster_nodes_entries];
  388. cluster_nodes_entries++;
  389. } else {
  390. list_iterate(tmp, &cluster_members_list) {
  391. cl = list_entry(tmp, struct cluster_node, list);
  392. if (cl->state == NODESTATE_DEAD) {
  393. break;
  394. }
  395. }
  396. /*
  397. * this should never happen
  398. */
  399. if (!cl) {
  400. log_printf(LOGSYS_LEVEL_CRIT, "Unable to find memory for node %u data!!", nodeid);
  401. goto out;
  402. }
  403. list_del(tmp);
  404. }
  405. memset(cl, 0, sizeof(struct cluster_node));
  406. cl->node_id = nodeid;
  407. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  408. node_add_ordered(cl);
  409. }
  410. out:
  411. LEAVE();
  412. return cl;
  413. }
  414. static struct cluster_node *find_node_by_nodeid(unsigned int nodeid)
  415. {
  416. struct cluster_node *node;
  417. struct list_head *tmp;
  418. ENTER();
  419. if (nodeid == us->node_id) {
  420. LEAVE();
  421. return us;
  422. }
  423. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  424. LEAVE();
  425. return qdevice;
  426. }
  427. list_iterate(tmp, &cluster_members_list) {
  428. node = list_entry(tmp, struct cluster_node, list);
  429. if (node->node_id == nodeid) {
  430. LEAVE();
  431. return node;
  432. }
  433. }
  434. LEAVE();
  435. return NULL;
  436. }
  437. static void get_lowest_node_id(void)
  438. {
  439. struct cluster_node *node = NULL;
  440. struct list_head *tmp;
  441. ENTER();
  442. lowest_node_id = us->node_id;
  443. list_iterate(tmp, &cluster_members_list) {
  444. node = list_entry(tmp, struct cluster_node, list);
  445. if ((node->state == NODESTATE_MEMBER) &&
  446. (node->node_id < lowest_node_id)) {
  447. lowest_node_id = node->node_id;
  448. }
  449. }
  450. log_printf(LOGSYS_LEVEL_DEBUG, "lowest node id: %d us: %d", lowest_node_id, us->node_id);
  451. icmap_set_uint32("runtime.votequorum.lowest_node_id", lowest_node_id);
  452. LEAVE();
  453. }
  454. static void get_highest_node_id(void)
  455. {
  456. struct cluster_node *node = NULL;
  457. struct list_head *tmp;
  458. ENTER();
  459. highest_node_id = us->node_id;
  460. list_iterate(tmp, &cluster_members_list) {
  461. node = list_entry(tmp, struct cluster_node, list);
  462. if ((node->state == NODESTATE_MEMBER) &&
  463. (node->node_id > highest_node_id)) {
  464. highest_node_id = node->node_id;
  465. }
  466. }
  467. log_printf(LOGSYS_LEVEL_DEBUG, "highest node id: %d us: %d", highest_node_id, us->node_id);
  468. icmap_set_uint32("runtime.votequorum.highest_node_id", highest_node_id);
  469. LEAVE();
  470. }
  471. static int check_low_node_id_partition(void)
  472. {
  473. struct cluster_node *node = NULL;
  474. struct list_head *tmp;
  475. int found = 0;
  476. ENTER();
  477. list_iterate(tmp, &cluster_members_list) {
  478. node = list_entry(tmp, struct cluster_node, list);
  479. if ((node->state == NODESTATE_MEMBER) &&
  480. (node->node_id == lowest_node_id)) {
  481. found = 1;
  482. }
  483. }
  484. LEAVE();
  485. return found;
  486. }
  487. static int check_high_node_id_partition(void)
  488. {
  489. struct cluster_node *node = NULL;
  490. struct list_head *tmp;
  491. int found = 0;
  492. ENTER();
  493. list_iterate(tmp, &cluster_members_list) {
  494. node = list_entry(tmp, struct cluster_node, list);
  495. if ((node->state == NODESTATE_MEMBER) &&
  496. (node->node_id == highest_node_id)) {
  497. found = 1;
  498. }
  499. }
  500. LEAVE();
  501. return found;
  502. }
  503. static int is_in_nodelist(int nodeid, unsigned int *members, int entries)
  504. {
  505. int i;
  506. ENTER();
  507. for (i=0; i<entries; i++) {
  508. if (nodeid == members[i]) {
  509. LEAVE();
  510. return 1;
  511. }
  512. }
  513. LEAVE();
  514. return 0;
  515. }
  516. /*
  517. * The algorithm for a list of tie-breaker nodes is:
  518. * travel the list of nodes in the auto_tie_breaker list,
  519. * if the node IS in our current partition, check if the
  520. * nodes earlier in the atb list are in the 'previous' partition;
  521. * If none are found then we are safe to be quorate, if any are
  522. * then we cannot be as we don't know if that node is up or down.
  523. * If we don't have a node in the current list we are NOT quorate.
  524. * Obviously if we find the first node in the atb list in our
  525. * partition then we are quorate.
  526. *
  527. * Special cases lowest nodeid, and highest nodeid are handled separately.
  528. */
  529. static int check_auto_tie_breaker(void)
  530. {
  531. int i, j;
  532. int res;
  533. ENTER();
  534. if (auto_tie_breaker == ATB_LOWEST) {
  535. res = check_low_node_id_partition();
  536. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LOWEST decision: %d", res);
  537. LEAVE();
  538. return res;
  539. }
  540. if (auto_tie_breaker == ATB_HIGHEST) {
  541. res = check_high_node_id_partition();
  542. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_HIGHEST decision: %d", res);
  543. LEAVE();
  544. return res;
  545. }
  546. /* Assume ATB_LIST, we should never be called for ATB_NONE */
  547. for (i=0; i < atb_nodelist_entries; i++) {
  548. if (is_in_nodelist(atb_nodelist[i], quorum_members, quorum_members_entries)) {
  549. /*
  550. * Node is in our partition, if any of its predecessors are
  551. * in the previous quorum partition then it might be in the
  552. * 'other half' (as we've got this far without seeing it here)
  553. * and so we can't be quorate.
  554. */
  555. for (j=0; j<i; j++) {
  556. if (is_in_nodelist(atb_nodelist[j], previous_quorum_members, previous_quorum_members_entries)) {
  557. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found node %d in previous partition but not here, quorum denied", atb_nodelist[j]);
  558. LEAVE();
  559. return 0;
  560. }
  561. }
  562. /*
  563. * None of the other list nodes were in the previous partition, if there
  564. * are enough votes, we can be quorate
  565. */
  566. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found node %d in current partition, we can be quorate", atb_nodelist[i]);
  567. LEAVE();
  568. return 1;
  569. }
  570. }
  571. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found no list nodes in current partition, we cannot be quorate");
  572. LEAVE();
  573. return 0;
  574. }
  575. /*
  576. * atb_string can be either:
  577. * 'lowest'
  578. * 'highest'
  579. * a list of nodeids
  580. */
  581. static void parse_atb_string(char *atb_string)
  582. {
  583. char *ptr;
  584. long num;
  585. ENTER();
  586. auto_tie_breaker = ATB_NONE;
  587. if (!strcmp(atb_string, "lowest"))
  588. auto_tie_breaker = ATB_LOWEST;
  589. if (!strcmp(atb_string, "highest"))
  590. auto_tie_breaker = ATB_HIGHEST;
  591. if (atoi(atb_string)) {
  592. atb_nodelist_entries = 0;
  593. ptr = atb_string;
  594. do {
  595. num = strtol(ptr, &ptr, 10);
  596. if (num) {
  597. log_printf(LOGSYS_LEVEL_DEBUG, "ATB nodelist[%d] = %d", atb_nodelist_entries, num);
  598. atb_nodelist[atb_nodelist_entries++] = num;
  599. }
  600. } while (num);
  601. if (atb_nodelist_entries) {
  602. auto_tie_breaker = ATB_LIST;
  603. }
  604. }
  605. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  606. log_printf(LOGSYS_LEVEL_DEBUG, "ATB type = %d", auto_tie_breaker);
  607. /* Make sure we got something */
  608. if (auto_tie_breaker == ATB_NONE) {
  609. log_printf(LOGSYS_LEVEL_WARNING, "auto_tie_breaker_nodes is not valid. It must be 'lowest', 'highest' or a space-separated list of node IDs. auto_tie_breaker is disabled");
  610. auto_tie_breaker = ATB_NONE;
  611. }
  612. LEAVE();
  613. }
  614. static int check_qdevice_master(void)
  615. {
  616. struct cluster_node *node = NULL;
  617. struct list_head *tmp;
  618. int found = 0;
  619. ENTER();
  620. list_iterate(tmp, &cluster_members_list) {
  621. node = list_entry(tmp, struct cluster_node, list);
  622. if ((node->state == NODESTATE_MEMBER) &&
  623. (node->flags & NODE_FLAGS_QDEVICE_MASTER_WINS) &&
  624. (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE)) {
  625. found = 1;
  626. }
  627. }
  628. LEAVE();
  629. return found;
  630. }
  631. static void decode_flags(uint32_t flags)
  632. {
  633. ENTER();
  634. log_printf(LOGSYS_LEVEL_DEBUG,
  635. "flags: quorate: %s Leaving: %s WFA Status: %s First: %s Qdevice: %s QdeviceAlive: %s QdeviceCastVote: %s QdeviceMasterWins: %s",
  636. (flags & NODE_FLAGS_QUORATE)?"Yes":"No",
  637. (flags & NODE_FLAGS_LEAVING)?"Yes":"No",
  638. (flags & NODE_FLAGS_WFASTATUS)?"Yes":"No",
  639. (flags & NODE_FLAGS_FIRST)?"Yes":"No",
  640. (flags & NODE_FLAGS_QDEVICE_REGISTERED)?"Yes":"No",
  641. (flags & NODE_FLAGS_QDEVICE_ALIVE)?"Yes":"No",
  642. (flags & NODE_FLAGS_QDEVICE_CAST_VOTE)?"Yes":"No",
  643. (flags & NODE_FLAGS_QDEVICE_MASTER_WINS)?"Yes":"No");
  644. LEAVE();
  645. }
  646. /*
  647. * load/save are copied almost pristine from totemsrp,c
  648. */
  649. static int load_ev_tracking_barrier(void)
  650. {
  651. int res = 0;
  652. char filename[PATH_MAX];
  653. ENTER();
  654. snprintf(filename, sizeof(filename) - 1, "%s/ev_tracking", get_run_dir());
  655. ev_tracking_fd = open(filename, O_RDWR, 0700);
  656. if (ev_tracking_fd != -1) {
  657. res = read (ev_tracking_fd, &ev_tracking_barrier, sizeof(uint32_t));
  658. if (res == sizeof (uint32_t)) {
  659. LEAVE();
  660. return 0;
  661. }
  662. }
  663. ev_tracking_barrier = 0;
  664. umask(0);
  665. ev_tracking_fd = open (filename, O_CREAT|O_RDWR, 0700);
  666. if (ev_tracking_fd != -1) {
  667. res = write (ev_tracking_fd, &ev_tracking_barrier, sizeof (uint32_t));
  668. if ((res == -1) || (res != sizeof (uint32_t))) {
  669. log_printf(LOGSYS_LEVEL_WARNING,
  670. "Unable to write to %s", filename);
  671. }
  672. LEAVE();
  673. return 0;
  674. }
  675. log_printf(LOGSYS_LEVEL_WARNING,
  676. "Unable to create %s file", filename);
  677. LEAVE();
  678. return -1;
  679. }
  680. static void update_wait_for_all_status(uint8_t wfa_status)
  681. {
  682. ENTER();
  683. wait_for_all_status = wfa_status;
  684. if (wait_for_all_status) {
  685. us->flags |= NODE_FLAGS_WFASTATUS;
  686. } else {
  687. us->flags &= ~NODE_FLAGS_WFASTATUS;
  688. }
  689. icmap_set_uint8("runtime.votequorum.wait_for_all_status",
  690. wait_for_all_status);
  691. LEAVE();
  692. }
  693. static void update_two_node(void)
  694. {
  695. ENTER();
  696. icmap_set_uint8("runtime.votequorum.two_node", two_node);
  697. LEAVE();
  698. }
  699. static void update_ev_barrier(uint32_t expected_votes)
  700. {
  701. ENTER();
  702. ev_barrier = expected_votes;
  703. icmap_set_uint32("runtime.votequorum.ev_barrier", ev_barrier);
  704. LEAVE();
  705. }
  706. static void update_qdevice_can_operate(uint8_t status)
  707. {
  708. ENTER();
  709. qdevice_can_operate = status;
  710. icmap_set_uint8("runtime.votequorum.qdevice_can_operate", qdevice_can_operate);
  711. LEAVE();
  712. }
  713. static void update_qdevice_master_wins(uint8_t allow)
  714. {
  715. ENTER();
  716. qdevice_master_wins = allow;
  717. icmap_set_uint8("runtime.votequorum.qdevice_master_wins", qdevice_master_wins);
  718. LEAVE();
  719. }
  720. static void update_ev_tracking_barrier(uint32_t ev_t_barrier)
  721. {
  722. int res;
  723. ENTER();
  724. ev_tracking_barrier = ev_t_barrier;
  725. icmap_set_uint32("runtime.votequorum.ev_tracking_barrier", ev_tracking_barrier);
  726. if (lseek (ev_tracking_fd, 0, SEEK_SET) != 0) {
  727. log_printf(LOGSYS_LEVEL_WARNING,
  728. "Unable to update ev_tracking_barrier on disk data!!!");
  729. LEAVE();
  730. return;
  731. }
  732. res = write (ev_tracking_fd, &ev_tracking_barrier, sizeof (uint32_t));
  733. if (res != sizeof (uint32_t)) {
  734. log_printf(LOGSYS_LEVEL_WARNING,
  735. "Unable to update ev_tracking_barrier on disk data!!!");
  736. }
  737. #ifdef HAVE_FDATASYNC
  738. fdatasync(ev_tracking_fd);
  739. #else
  740. fsync(ev_tracking_fd);
  741. #endif
  742. LEAVE();
  743. }
  744. /*
  745. * quorum calculation core bits
  746. */
  747. static int calculate_quorum(int allow_decrease, unsigned int max_expected, unsigned int *ret_total_votes)
  748. {
  749. struct list_head *nodelist;
  750. struct cluster_node *node;
  751. unsigned int total_votes = 0;
  752. unsigned int highest_expected = 0;
  753. unsigned int newquorum, q1, q2;
  754. unsigned int total_nodes = 0;
  755. ENTER();
  756. if ((allow_downscale) && (allow_decrease) && (max_expected)) {
  757. max_expected = max(ev_barrier, max_expected);
  758. }
  759. list_iterate(nodelist, &cluster_members_list) {
  760. node = list_entry(nodelist, struct cluster_node, list);
  761. log_printf(LOGSYS_LEVEL_DEBUG, "node %u state=%d, votes=%u, expected=%u",
  762. node->node_id, node->state, node->votes, node->expected_votes);
  763. if (node->state == NODESTATE_MEMBER) {
  764. if (max_expected) {
  765. node->expected_votes = max_expected;
  766. } else {
  767. highest_expected = max(highest_expected, node->expected_votes);
  768. }
  769. total_votes += node->votes;
  770. total_nodes++;
  771. }
  772. }
  773. if (us->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  774. log_printf(LOGSYS_LEVEL_DEBUG, "node 0 state=1, votes=%u", qdevice->votes);
  775. total_votes += qdevice->votes;
  776. total_nodes++;
  777. }
  778. if (max_expected > 0) {
  779. highest_expected = max_expected;
  780. }
  781. /*
  782. * This quorum calculation is taken from the OpenVMS Cluster Systems
  783. * manual, but, then, you guessed that didn't you
  784. */
  785. q1 = (highest_expected + 2) / 2;
  786. q2 = (total_votes + 2) / 2;
  787. newquorum = max(q1, q2);
  788. /*
  789. * Normally quorum never decreases but the system administrator can
  790. * force it down by setting expected votes to a maximum value
  791. */
  792. if (!allow_decrease) {
  793. newquorum = max(quorum, newquorum);
  794. }
  795. /*
  796. * The special two_node mode allows each of the two nodes to retain
  797. * quorum if the other fails. Only one of the two should live past
  798. * fencing (as both nodes try to fence each other in split-brain.)
  799. * Also: if there are more than two nodes, force us inquorate to avoid
  800. * any damage or confusion.
  801. */
  802. if (two_node && total_nodes <= 2) {
  803. newquorum = 1;
  804. }
  805. if (ret_total_votes) {
  806. *ret_total_votes = total_votes;
  807. }
  808. LEAVE();
  809. return newquorum;
  810. }
  811. static void are_we_quorate(unsigned int total_votes)
  812. {
  813. int quorate;
  814. int quorum_change = 0;
  815. ENTER();
  816. /*
  817. * wait for all nodes to show up before granting quorum
  818. */
  819. if ((wait_for_all) && (wait_for_all_status)) {
  820. if (total_votes != us->expected_votes) {
  821. log_printf(LOGSYS_LEVEL_NOTICE,
  822. "Waiting for all cluster members. "
  823. "Current votes: %d expected_votes: %d",
  824. total_votes, us->expected_votes);
  825. cluster_is_quorate = 0;
  826. return;
  827. }
  828. update_wait_for_all_status(0);
  829. }
  830. if (quorum > total_votes) {
  831. quorate = 0;
  832. } else {
  833. quorate = 1;
  834. get_lowest_node_id();
  835. get_highest_node_id();
  836. }
  837. if ((auto_tie_breaker != ATB_NONE) &&
  838. /* Must be a half (or half-1) split */
  839. (total_votes == (us->expected_votes / 2)) &&
  840. /* If the 'other' partition in a split might have quorum then we can't run ATB */
  841. (previous_quorum_members_entries - quorum_members_entries < quorum) &&
  842. (check_auto_tie_breaker() == 1)) {
  843. quorate = 1;
  844. }
  845. if ((qdevice_master_wins) &&
  846. (!quorate) &&
  847. (check_qdevice_master() == 1)) {
  848. log_printf(LOGSYS_LEVEL_DEBUG, "node is quorate as part of master_wins partition");
  849. quorate = 1;
  850. }
  851. if (cluster_is_quorate && !quorate) {
  852. quorum_change = 1;
  853. log_printf(LOGSYS_LEVEL_DEBUG, "quorum lost, blocking activity");
  854. }
  855. if (!cluster_is_quorate && quorate) {
  856. quorum_change = 1;
  857. log_printf(LOGSYS_LEVEL_DEBUG, "quorum regained, resuming activity");
  858. }
  859. cluster_is_quorate = quorate;
  860. if (cluster_is_quorate) {
  861. us->flags |= NODE_FLAGS_QUORATE;
  862. } else {
  863. us->flags &= ~NODE_FLAGS_QUORATE;
  864. }
  865. if (wait_for_all) {
  866. if (quorate) {
  867. update_wait_for_all_status(0);
  868. } else {
  869. update_wait_for_all_status(1);
  870. }
  871. }
  872. if ((quorum_change) &&
  873. (sync_in_progress == 0)) {
  874. quorum_callback(quorum_members, quorum_members_entries,
  875. cluster_is_quorate, &quorum_ringid);
  876. votequorum_exec_send_quorum_notification(NULL, 0L);
  877. }
  878. LEAVE();
  879. }
  880. static void get_total_votes(unsigned int *totalvotes, unsigned int *current_members)
  881. {
  882. unsigned int total_votes = 0;
  883. unsigned int cluster_members = 0;
  884. struct list_head *nodelist;
  885. struct cluster_node *node;
  886. ENTER();
  887. list_iterate(nodelist, &cluster_members_list) {
  888. node = list_entry(nodelist, struct cluster_node, list);
  889. if (node->state == NODESTATE_MEMBER) {
  890. cluster_members++;
  891. total_votes += node->votes;
  892. }
  893. }
  894. if (qdevice->votes) {
  895. total_votes += qdevice->votes;
  896. cluster_members++;
  897. }
  898. *totalvotes = total_votes;
  899. *current_members = cluster_members;
  900. LEAVE();
  901. }
  902. /*
  903. * Recalculate cluster quorum, set quorate and notify changes
  904. */
  905. static void recalculate_quorum(int allow_decrease, int by_current_nodes)
  906. {
  907. unsigned int total_votes = 0;
  908. unsigned int cluster_members = 0;
  909. ENTER();
  910. get_total_votes(&total_votes, &cluster_members);
  911. if (!by_current_nodes) {
  912. cluster_members = 0;
  913. }
  914. /*
  915. * Keep expected_votes at the highest number of votes in the cluster
  916. */
  917. log_printf(LOGSYS_LEVEL_DEBUG, "total_votes=%d, expected_votes=%d", total_votes, us->expected_votes);
  918. if (total_votes > us->expected_votes) {
  919. us->expected_votes = total_votes;
  920. votequorum_exec_send_expectedvotes_notification();
  921. }
  922. if ((ev_tracking) &&
  923. (us->expected_votes > ev_tracking_barrier)) {
  924. update_ev_tracking_barrier(us->expected_votes);
  925. }
  926. quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
  927. are_we_quorate(total_votes);
  928. LEAVE();
  929. }
  930. /*
  931. * configuration bits and pieces
  932. */
  933. static int votequorum_read_nodelist_configuration(uint32_t *votes,
  934. uint32_t *nodes,
  935. uint32_t *expected_votes)
  936. {
  937. icmap_iter_t iter;
  938. const char *iter_key;
  939. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  940. uint32_t our_pos, node_pos;
  941. uint32_t nodecount = 0;
  942. uint32_t nodelist_expected_votes = 0;
  943. uint32_t node_votes = 0;
  944. int res = 0;
  945. ENTER();
  946. if (icmap_get_uint32("nodelist.local_node_pos", &our_pos) != CS_OK) {
  947. log_printf(LOGSYS_LEVEL_DEBUG,
  948. "No nodelist defined or our node is not in the nodelist");
  949. return 0;
  950. }
  951. iter = icmap_iter_init("nodelist.node.");
  952. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  953. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  954. if (res != 2) {
  955. continue;
  956. }
  957. if (strcmp(tmp_key, "ring0_addr") != 0) {
  958. continue;
  959. }
  960. nodecount++;
  961. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.quorum_votes", node_pos);
  962. if (icmap_get_uint32(tmp_key, &node_votes) != CS_OK) {
  963. node_votes = 1;
  964. }
  965. nodelist_expected_votes = nodelist_expected_votes + node_votes;
  966. if (node_pos == our_pos) {
  967. *votes = node_votes;
  968. }
  969. }
  970. *expected_votes = nodelist_expected_votes;
  971. *nodes = nodecount;
  972. icmap_iter_finalize(iter);
  973. LEAVE();
  974. return 1;
  975. }
  976. static int votequorum_qdevice_is_configured(uint32_t *qdevice_votes)
  977. {
  978. char *qdevice_model = NULL;
  979. int ret = 0;
  980. ENTER();
  981. if (icmap_get_string("quorum.device.model", &qdevice_model) == CS_OK) {
  982. if (strlen(qdevice_model)) {
  983. if (icmap_get_uint32("quorum.device.votes", qdevice_votes) != CS_OK) {
  984. *qdevice_votes = -1;
  985. }
  986. if (icmap_get_uint32("quorum.device.timeout", &qdevice_timeout) != CS_OK) {
  987. qdevice_timeout = VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT;
  988. }
  989. if (icmap_get_uint32("quorum.device.sync_timeout", &qdevice_sync_timeout) != CS_OK) {
  990. qdevice_sync_timeout = VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT;
  991. }
  992. update_qdevice_can_operate(1);
  993. ret = 1;
  994. }
  995. free(qdevice_model);
  996. }
  997. LEAVE();
  998. return ret;
  999. }
  1000. #define VOTEQUORUM_READCONFIG_STARTUP 0
  1001. #define VOTEQUORUM_READCONFIG_RUNTIME 1
  1002. static char *votequorum_readconfig(int runtime)
  1003. {
  1004. uint32_t node_votes = 0, qdevice_votes = 0;
  1005. uint32_t node_expected_votes = 0, expected_votes = 0;
  1006. uint32_t node_count = 0;
  1007. uint8_t atb = 0;
  1008. int have_nodelist, have_qdevice;
  1009. char *atb_string = NULL;
  1010. char *error = NULL;
  1011. ENTER();
  1012. log_printf(LOGSYS_LEVEL_DEBUG, "Reading configuration (runtime: %d)", runtime);
  1013. /*
  1014. * Set the few things we re-read at runtime back to their defaults
  1015. */
  1016. if (runtime) {
  1017. two_node = 0;
  1018. expected_votes = 0;
  1019. }
  1020. /*
  1021. * gather basic data here
  1022. */
  1023. icmap_get_uint32("quorum.expected_votes", &expected_votes);
  1024. have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
  1025. have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
  1026. icmap_get_uint8("quorum.two_node", &two_node);
  1027. /*
  1028. * do config verification and enablement
  1029. */
  1030. if ((!have_nodelist) && (!expected_votes)) {
  1031. if (!runtime) {
  1032. error = (char *)"configuration error: nodelist or quorum.expected_votes must be configured!";
  1033. } else {
  1034. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: nodelist or quorum.expected_votes must be configured!");
  1035. log_printf(LOGSYS_LEVEL_CRIT, "will continue with current runtime data");
  1036. }
  1037. goto out;
  1038. }
  1039. /*
  1040. * two_node and qdevice are not compatible in the same config.
  1041. * try to make an educated guess of what to do
  1042. */
  1043. if ((two_node) && (have_qdevice)) {
  1044. if (!runtime) {
  1045. error = (char *)"configuration error: two_node and quorum device cannot be configured at the same time!";
  1046. goto out;
  1047. } else {
  1048. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: two_node and quorum device cannot be configured at the same time!");
  1049. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1050. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is registered, disabling two_node");
  1051. two_node = 0;
  1052. } else {
  1053. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is not registered, allowing two_node");
  1054. update_qdevice_can_operate(0);
  1055. }
  1056. }
  1057. }
  1058. /*
  1059. * Enable special features
  1060. */
  1061. if (!runtime) {
  1062. if (two_node) {
  1063. wait_for_all = 1;
  1064. }
  1065. icmap_get_uint8("quorum.allow_downscale", &allow_downscale);
  1066. icmap_get_uint8("quorum.wait_for_all", &wait_for_all);
  1067. icmap_get_uint8("quorum.last_man_standing", &last_man_standing);
  1068. icmap_get_uint32("quorum.last_man_standing_window", &last_man_standing_window);
  1069. icmap_get_uint8("quorum.expected_votes_tracking", &ev_tracking);
  1070. icmap_get_uint8("quorum.auto_tie_breaker", &atb);
  1071. icmap_get_string("quorum.auto_tie_breaker_node", &atb_string);
  1072. /* auto_tie_breaker defaults to LOWEST */
  1073. if (atb) {
  1074. auto_tie_breaker = ATB_LOWEST;
  1075. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  1076. }
  1077. else {
  1078. auto_tie_breaker = ATB_NONE;
  1079. if (atb_string) {
  1080. log_printf(LOGSYS_LEVEL_WARNING,
  1081. "auto_tie_breaker_node: is meaningless if auto_tie_breaker is set to 0");
  1082. }
  1083. }
  1084. if (atb && atb_string) {
  1085. parse_atb_string(atb_string);
  1086. }
  1087. free(atb_string);
  1088. /* allow_downscale requires ev_tracking */
  1089. if (allow_downscale) {
  1090. ev_tracking = 1;
  1091. }
  1092. if (ev_tracking) {
  1093. if (load_ev_tracking_barrier() < 0) {
  1094. LEAVE();
  1095. return ((char *)"Unable to load ev_tracking file!");
  1096. }
  1097. update_ev_tracking_barrier(ev_tracking_barrier);
  1098. }
  1099. }
  1100. /* two_node and auto_tie_breaker are not compatible as two_node uses
  1101. * a fence race to decide quorum whereas ATB decides based on node id
  1102. */
  1103. if (two_node && auto_tie_breaker != ATB_NONE) {
  1104. log_printf(LOGSYS_LEVEL_CRIT, "two_node and auto_tie_breaker are both specified but are not compatible.");
  1105. log_printf(LOGSYS_LEVEL_CRIT, "two_node has been disabled, please fix your corosync.conf");
  1106. two_node = 0;
  1107. }
  1108. /* If ATB is set and the cluster has an odd number of nodes then wait_for_all needs
  1109. * to be set so that an isolated half+1 without the tie breaker node
  1110. * does not have quorum on reboot.
  1111. */
  1112. if ((auto_tie_breaker != ATB_NONE) && (node_expected_votes % 2) &&
  1113. (!wait_for_all)) {
  1114. if (last_man_standing) {
  1115. /* if LMS is set too, it's a fatal configuration error. We can't dictate to the user what
  1116. * they might want so we'll just quit.
  1117. */
  1118. log_printf(LOGSYS_LEVEL_CRIT, "auto_tie_breaker is set, the cluster has an odd number of nodes\n");
  1119. log_printf(LOGSYS_LEVEL_CRIT, "and last_man_standing is also set. With this situation a better\n");
  1120. log_printf(LOGSYS_LEVEL_CRIT, "solution would be to disable LMS, leave ATB enabled, and also\n");
  1121. log_printf(LOGSYS_LEVEL_CRIT, "enable wait_for_all (mandatory for ATB in odd-numbered clusters).\n");
  1122. log_printf(LOGSYS_LEVEL_CRIT, "Due to this ambiguity, corosync will fail to start. Please fix your corosync.conf\n");
  1123. error = (char *)"configuration error: auto_tie_breaker & last_man_standing not available in odd sized cluster";
  1124. goto out;
  1125. }
  1126. else {
  1127. log_printf(LOGSYS_LEVEL_CRIT, "auto_tie_breaker is set and the cluster has an odd number of nodes.\n");
  1128. log_printf(LOGSYS_LEVEL_CRIT, "wait_for_all needs to be set for this configuration but it is missing\n");
  1129. log_printf(LOGSYS_LEVEL_CRIT, "Therefore auto_tie_breaker has been disabled. Please fix your corosync.conf\n");
  1130. auto_tie_breaker = ATB_NONE;
  1131. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  1132. }
  1133. }
  1134. /*
  1135. * quorum device is not compatible with last_man_standing and auto_tie_breaker
  1136. * neither lms or atb can be set at runtime, so there is no need to check for
  1137. * runtime incompatibilities, but qdevice can be configured _after_ LMS and ATB have
  1138. * been enabled at startup.
  1139. */
  1140. if ((have_qdevice) && (last_man_standing)) {
  1141. if (!runtime) {
  1142. error = (char *)"configuration error: quorum.device is not compatible with last_man_standing";
  1143. goto out;
  1144. } else {
  1145. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with last_man_standing");
  1146. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1147. update_qdevice_can_operate(0);
  1148. }
  1149. }
  1150. if ((have_qdevice) && (auto_tie_breaker != ATB_NONE)) {
  1151. if (!runtime) {
  1152. error = (char *)"configuration error: quorum.device is not compatible with auto_tie_breaker";
  1153. goto out;
  1154. } else {
  1155. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with auto_tie_breaker");
  1156. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1157. update_qdevice_can_operate(0);
  1158. }
  1159. }
  1160. if ((have_qdevice) && (wait_for_all)) {
  1161. if (!runtime) {
  1162. error = (char *)"configuration error: quorum.device is not compatible with wait_for_all";
  1163. goto out;
  1164. } else {
  1165. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with wait_for_all");
  1166. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1167. update_qdevice_can_operate(0);
  1168. }
  1169. }
  1170. if ((have_qdevice) && (allow_downscale)) {
  1171. if (!runtime) {
  1172. error = (char *)"configuration error: quorum.device is not compatible with allow_downscale";
  1173. goto out;
  1174. } else {
  1175. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with allow_downscale");
  1176. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1177. update_qdevice_can_operate(0);
  1178. }
  1179. }
  1180. /*
  1181. * if user specifies quorum.expected_votes + quorum.device but NOT the device.votes
  1182. * we don't know what the quorum device should vote.
  1183. */
  1184. if ((expected_votes) && (have_qdevice) && (qdevice_votes == -1)) {
  1185. if (!runtime) {
  1186. error = (char *)"configuration error: quorum.device.votes must be specified when quorum.expected_votes is set";
  1187. goto out;
  1188. } else {
  1189. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when quorum.expected_votes is set");
  1190. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1191. update_qdevice_can_operate(0);
  1192. }
  1193. }
  1194. /*
  1195. * if user specifies a node list with uneven votes and no device.votes
  1196. * we cannot autocalculate the votes
  1197. */
  1198. if ((have_qdevice) &&
  1199. (qdevice_votes == -1) &&
  1200. (have_nodelist) &&
  1201. (node_count != node_expected_votes)) {
  1202. if (!runtime) {
  1203. error = (char *)"configuration error: quorum.device.votes must be specified when not all nodes votes 1";
  1204. goto out;
  1205. } else {
  1206. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when not all nodes votes 1");
  1207. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1208. update_qdevice_can_operate(0);
  1209. }
  1210. }
  1211. /*
  1212. * validate quorum device votes vs expected_votes
  1213. */
  1214. if ((qdevice_votes > 0) && (expected_votes)) {
  1215. int delta = expected_votes - qdevice_votes;
  1216. if (delta < 2) {
  1217. if (!runtime) {
  1218. error = (char *)"configuration error: quorum.device.votes is too high or expected_votes is too low";
  1219. goto out;
  1220. } else {
  1221. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes is too high or expected_votes is too low");
  1222. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1223. update_qdevice_can_operate(0);
  1224. }
  1225. }
  1226. }
  1227. /*
  1228. * automatically calculate device votes and adjust expected_votes from nodelist
  1229. */
  1230. if ((have_qdevice) &&
  1231. (qdevice_votes == -1) &&
  1232. (!expected_votes) &&
  1233. (have_nodelist) &&
  1234. (node_count == node_expected_votes)) {
  1235. qdevice_votes = node_expected_votes - 1;
  1236. node_expected_votes = node_expected_votes + qdevice_votes;
  1237. }
  1238. /*
  1239. * set this node votes and expected_votes
  1240. */
  1241. log_printf(LOGSYS_LEVEL_DEBUG, "ev_tracking=%d, ev_tracking_barrier = %d: expected_votes = %d\n", ev_tracking, ev_tracking_barrier, expected_votes);
  1242. if (ev_tracking) {
  1243. expected_votes = ev_tracking_barrier;
  1244. }
  1245. if (have_nodelist) {
  1246. us->votes = node_votes;
  1247. us->expected_votes = node_expected_votes;
  1248. } else {
  1249. us->votes = 1;
  1250. icmap_get_uint32("quorum.votes", &us->votes);
  1251. }
  1252. if (expected_votes) {
  1253. us->expected_votes = expected_votes;
  1254. }
  1255. /*
  1256. * set qdevice votes
  1257. */
  1258. if (!have_qdevice) {
  1259. qdevice->votes = 0;
  1260. }
  1261. if (qdevice_votes != -1) {
  1262. qdevice->votes = qdevice_votes;
  1263. }
  1264. update_ev_barrier(us->expected_votes);
  1265. update_two_node();
  1266. if (wait_for_all) {
  1267. update_wait_for_all_status(1);
  1268. }
  1269. out:
  1270. LEAVE();
  1271. return error;
  1272. }
  1273. static void votequorum_refresh_config(
  1274. int32_t event,
  1275. const char *key_name,
  1276. struct icmap_notify_value new_val,
  1277. struct icmap_notify_value old_val,
  1278. void *user_data)
  1279. {
  1280. int old_votes, old_expected_votes;
  1281. uint8_t reloading;
  1282. uint8_t cancel_wfa;
  1283. ENTER();
  1284. /*
  1285. * If a full reload is in progress then don't do anything until it's done and
  1286. * can reconfigure it all atomically
  1287. */
  1288. if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
  1289. return ;
  1290. }
  1291. icmap_get_uint8("quorum.cancel_wait_for_all", &cancel_wfa);
  1292. if (strcmp(key_name, "quorum.cancel_wait_for_all") == 0 &&
  1293. cancel_wfa >= 1) {
  1294. icmap_set_uint8("quorum.cancel_wait_for_all", 0);
  1295. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA,
  1296. us->node_id, 0);
  1297. return;
  1298. }
  1299. old_votes = us->votes;
  1300. old_expected_votes = us->expected_votes;
  1301. /*
  1302. * Reload the configuration
  1303. */
  1304. votequorum_readconfig(VOTEQUORUM_READCONFIG_RUNTIME);
  1305. /*
  1306. * activate new config
  1307. */
  1308. votequorum_exec_send_nodeinfo(us->node_id);
  1309. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1310. if (us->votes != old_votes) {
  1311. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES,
  1312. us->node_id, us->votes);
  1313. }
  1314. if (us->expected_votes != old_expected_votes) {
  1315. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES,
  1316. us->node_id, us->expected_votes);
  1317. }
  1318. LEAVE();
  1319. }
  1320. static void votequorum_exec_add_config_notification(void)
  1321. {
  1322. icmap_track_t icmap_track_nodelist = NULL;
  1323. icmap_track_t icmap_track_quorum = NULL;
  1324. icmap_track_t icmap_track_reload = NULL;
  1325. ENTER();
  1326. icmap_track_add("nodelist.",
  1327. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1328. votequorum_refresh_config,
  1329. NULL,
  1330. &icmap_track_nodelist);
  1331. icmap_track_add("quorum.",
  1332. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1333. votequorum_refresh_config,
  1334. NULL,
  1335. &icmap_track_quorum);
  1336. icmap_track_add("config.totemconfig_reload_in_progress",
  1337. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  1338. votequorum_refresh_config,
  1339. NULL,
  1340. &icmap_track_reload);
  1341. LEAVE();
  1342. }
  1343. /*
  1344. * votequorum_exec core
  1345. */
  1346. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value)
  1347. {
  1348. struct req_exec_quorum_reconfigure req_exec_quorum_reconfigure;
  1349. struct iovec iov[1];
  1350. int ret;
  1351. ENTER();
  1352. req_exec_quorum_reconfigure.nodeid = nodeid;
  1353. req_exec_quorum_reconfigure.value = value;
  1354. req_exec_quorum_reconfigure.param = param;
  1355. req_exec_quorum_reconfigure._pad0 = 0;
  1356. req_exec_quorum_reconfigure._pad1 = 0;
  1357. req_exec_quorum_reconfigure._pad2 = 0;
  1358. req_exec_quorum_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE);
  1359. req_exec_quorum_reconfigure.header.size = sizeof(req_exec_quorum_reconfigure);
  1360. iov[0].iov_base = (void *)&req_exec_quorum_reconfigure;
  1361. iov[0].iov_len = sizeof(req_exec_quorum_reconfigure);
  1362. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1363. LEAVE();
  1364. return ret;
  1365. }
  1366. static int votequorum_exec_send_nodeinfo(uint32_t nodeid)
  1367. {
  1368. struct req_exec_quorum_nodeinfo req_exec_quorum_nodeinfo;
  1369. struct iovec iov[1];
  1370. struct cluster_node *node;
  1371. int ret;
  1372. ENTER();
  1373. node = find_node_by_nodeid(nodeid);
  1374. if (!node) {
  1375. return -1;
  1376. }
  1377. req_exec_quorum_nodeinfo.nodeid = nodeid;
  1378. req_exec_quorum_nodeinfo.votes = node->votes;
  1379. req_exec_quorum_nodeinfo.expected_votes = node->expected_votes;
  1380. req_exec_quorum_nodeinfo.flags = node->flags;
  1381. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  1382. decode_flags(node->flags);
  1383. }
  1384. req_exec_quorum_nodeinfo.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO);
  1385. req_exec_quorum_nodeinfo.header.size = sizeof(req_exec_quorum_nodeinfo);
  1386. iov[0].iov_base = (void *)&req_exec_quorum_nodeinfo;
  1387. iov[0].iov_len = sizeof(req_exec_quorum_nodeinfo);
  1388. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1389. LEAVE();
  1390. return ret;
  1391. }
  1392. static int votequorum_exec_send_qdevice_reconfigure(const char *oldname, const char *newname)
  1393. {
  1394. struct req_exec_quorum_qdevice_reconfigure req_exec_quorum_qdevice_reconfigure;
  1395. struct iovec iov[1];
  1396. int ret;
  1397. ENTER();
  1398. req_exec_quorum_qdevice_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE);
  1399. req_exec_quorum_qdevice_reconfigure.header.size = sizeof(req_exec_quorum_qdevice_reconfigure);
  1400. strcpy(req_exec_quorum_qdevice_reconfigure.oldname, oldname);
  1401. strcpy(req_exec_quorum_qdevice_reconfigure.newname, newname);
  1402. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reconfigure;
  1403. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reconfigure);
  1404. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1405. LEAVE();
  1406. return ret;
  1407. }
  1408. static int votequorum_exec_send_qdevice_reg(uint32_t operation, const char *qdevice_name_req)
  1409. {
  1410. struct req_exec_quorum_qdevice_reg req_exec_quorum_qdevice_reg;
  1411. struct iovec iov[1];
  1412. int ret;
  1413. ENTER();
  1414. req_exec_quorum_qdevice_reg.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG);
  1415. req_exec_quorum_qdevice_reg.header.size = sizeof(req_exec_quorum_qdevice_reg);
  1416. req_exec_quorum_qdevice_reg.operation = operation;
  1417. strcpy(req_exec_quorum_qdevice_reg.qdevice_name, qdevice_name_req);
  1418. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reg;
  1419. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reg);
  1420. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1421. LEAVE();
  1422. return ret;
  1423. }
  1424. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context)
  1425. {
  1426. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  1427. struct list_head *tmp;
  1428. struct cluster_node *node;
  1429. int cluster_members = 0;
  1430. int i = 0;
  1431. int size;
  1432. char buf[sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * (PROCESSOR_COUNT_MAX + 2)];
  1433. ENTER();
  1434. list_iterate(tmp, &cluster_members_list) {
  1435. node = list_entry(tmp, struct cluster_node, list);
  1436. cluster_members++;
  1437. }
  1438. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1439. cluster_members++;
  1440. }
  1441. size = sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  1442. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)&buf;
  1443. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  1444. res_lib_votequorum_notification->node_list_entries = cluster_members;
  1445. res_lib_votequorum_notification->ring_id.nodeid = quorum_ringid.rep.nodeid;
  1446. res_lib_votequorum_notification->ring_id.seq = quorum_ringid.seq;
  1447. res_lib_votequorum_notification->context = context;
  1448. list_iterate(tmp, &cluster_members_list) {
  1449. node = list_entry(tmp, struct cluster_node, list);
  1450. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  1451. res_lib_votequorum_notification->node_list[i++].state = node->state;
  1452. }
  1453. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1454. res_lib_votequorum_notification->node_list[i].nodeid = VOTEQUORUM_QDEVICE_NODEID;
  1455. res_lib_votequorum_notification->node_list[i++].state = qdevice->state;
  1456. }
  1457. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NOTIFICATION;
  1458. res_lib_votequorum_notification->header.size = size;
  1459. res_lib_votequorum_notification->header.error = CS_OK;
  1460. /* Send it to all interested parties */
  1461. if (conn) {
  1462. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1463. LEAVE();
  1464. return ret;
  1465. } else {
  1466. struct quorum_pd *qpd;
  1467. list_iterate(tmp, &trackers_list) {
  1468. qpd = list_entry(tmp, struct quorum_pd, list);
  1469. res_lib_votequorum_notification->context = qpd->tracking_context;
  1470. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1471. }
  1472. }
  1473. LEAVE();
  1474. return 0;
  1475. }
  1476. static void votequorum_exec_send_expectedvotes_notification(void)
  1477. {
  1478. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  1479. struct quorum_pd *qpd;
  1480. struct list_head *tmp;
  1481. ENTER();
  1482. log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback");
  1483. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  1484. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  1485. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  1486. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  1487. list_iterate(tmp, &trackers_list) {
  1488. qpd = list_entry(tmp, struct quorum_pd, list);
  1489. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  1490. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  1491. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  1492. }
  1493. LEAVE();
  1494. }
  1495. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message)
  1496. {
  1497. ENTER();
  1498. LEAVE();
  1499. }
  1500. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  1501. const void *message,
  1502. unsigned int nodeid)
  1503. {
  1504. const struct req_exec_quorum_qdevice_reconfigure *req_exec_quorum_qdevice_reconfigure = message;
  1505. ENTER();
  1506. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice name change req from node %u [from: %s to: %s]",
  1507. nodeid,
  1508. req_exec_quorum_qdevice_reconfigure->oldname,
  1509. req_exec_quorum_qdevice_reconfigure->newname);
  1510. if (!strcmp(req_exec_quorum_qdevice_reconfigure->oldname, qdevice_name)) {
  1511. log_printf(LOGSYS_LEVEL_DEBUG, "Allowing qdevice rename");
  1512. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1513. strcpy(qdevice_name, req_exec_quorum_qdevice_reconfigure->newname);
  1514. /*
  1515. * TODO: notify qdevices about name change?
  1516. * this is not relevant for now and can wait later on since
  1517. * qdevices are local only and libvotequorum is not final
  1518. */
  1519. }
  1520. LEAVE();
  1521. }
  1522. static void exec_votequorum_qdevice_reg_endian_convert (void *message)
  1523. {
  1524. struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1525. ENTER();
  1526. req_exec_quorum_qdevice_reg->operation = swab32(req_exec_quorum_qdevice_reg->operation);
  1527. LEAVE();
  1528. }
  1529. static void message_handler_req_exec_votequorum_qdevice_reg (
  1530. const void *message,
  1531. unsigned int nodeid)
  1532. {
  1533. const struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1534. struct res_lib_votequorum_status res_lib_votequorum_status;
  1535. int wipe_qdevice_name = 1;
  1536. struct cluster_node *node = NULL;
  1537. struct list_head *tmp;
  1538. cs_error_t error = CS_OK;
  1539. ENTER();
  1540. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice op %u req from node %u [%s]",
  1541. req_exec_quorum_qdevice_reg->operation,
  1542. nodeid, req_exec_quorum_qdevice_reg->qdevice_name);
  1543. switch(req_exec_quorum_qdevice_reg->operation)
  1544. {
  1545. case VOTEQUORUM_QDEVICE_OPERATION_REGISTER:
  1546. if (nodeid != us->node_id) {
  1547. if (!strlen(qdevice_name)) {
  1548. log_printf(LOGSYS_LEVEL_DEBUG, "Remote qdevice name recorded");
  1549. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1550. }
  1551. LEAVE();
  1552. return;
  1553. }
  1554. /*
  1555. * protect against the case where we broadcast qdevice registration
  1556. * to new memebers, we receive the message back, but there is no registration
  1557. * connection in progress
  1558. */
  1559. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1560. LEAVE();
  1561. return;
  1562. }
  1563. /*
  1564. * this should NEVER happen
  1565. */
  1566. if (!qdevice_reg_conn) {
  1567. log_printf(LOGSYS_LEVEL_WARNING, "Unable to determine origin of the qdevice register call!");
  1568. LEAVE();
  1569. return;
  1570. }
  1571. /*
  1572. * registering our own device in this case
  1573. */
  1574. if (!strlen(qdevice_name)) {
  1575. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1576. }
  1577. /*
  1578. * check if it is our device or something else
  1579. */
  1580. if ((!strncmp(req_exec_quorum_qdevice_reg->qdevice_name,
  1581. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  1582. us->flags |= NODE_FLAGS_QDEVICE_REGISTERED;
  1583. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1584. votequorum_exec_send_nodeinfo(us->node_id);
  1585. } else {
  1586. log_printf(LOGSYS_LEVEL_WARNING,
  1587. "A new qdevice with different name (new: %s old: %s) is trying to register!",
  1588. req_exec_quorum_qdevice_reg->qdevice_name, qdevice_name);
  1589. error = CS_ERR_EXIST;
  1590. }
  1591. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1592. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1593. res_lib_votequorum_status.header.error = error;
  1594. corosync_api->ipc_response_send(qdevice_reg_conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1595. qdevice_reg_conn = NULL;
  1596. break;
  1597. case VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER:
  1598. list_iterate(tmp, &cluster_members_list) {
  1599. node = list_entry(tmp, struct cluster_node, list);
  1600. if ((node->state == NODESTATE_MEMBER) &&
  1601. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1602. wipe_qdevice_name = 0;
  1603. }
  1604. }
  1605. if (wipe_qdevice_name) {
  1606. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1607. }
  1608. break;
  1609. }
  1610. LEAVE();
  1611. }
  1612. static void exec_votequorum_nodeinfo_endian_convert (void *message)
  1613. {
  1614. struct req_exec_quorum_nodeinfo *nodeinfo = message;
  1615. ENTER();
  1616. nodeinfo->nodeid = swab32(nodeinfo->nodeid);
  1617. nodeinfo->votes = swab32(nodeinfo->votes);
  1618. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  1619. nodeinfo->flags = swab32(nodeinfo->flags);
  1620. LEAVE();
  1621. }
  1622. static void message_handler_req_exec_votequorum_nodeinfo (
  1623. const void *message,
  1624. unsigned int sender_nodeid)
  1625. {
  1626. const struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = message;
  1627. struct cluster_node *node = NULL;
  1628. int old_votes;
  1629. int old_expected;
  1630. uint32_t old_flags;
  1631. nodestate_t old_state;
  1632. int new_node = 0;
  1633. int allow_downgrade = 0;
  1634. int by_node = 0;
  1635. unsigned int nodeid = req_exec_quorum_nodeinfo->nodeid;
  1636. ENTER();
  1637. log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %u", sender_nodeid);
  1638. log_printf(LOGSYS_LEVEL_DEBUG, "nodeinfo message[%u]: votes: %d, expected: %d flags: %d",
  1639. nodeid,
  1640. req_exec_quorum_nodeinfo->votes,
  1641. req_exec_quorum_nodeinfo->expected_votes,
  1642. req_exec_quorum_nodeinfo->flags);
  1643. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  1644. decode_flags(req_exec_quorum_nodeinfo->flags);
  1645. }
  1646. node = find_node_by_nodeid(nodeid);
  1647. if (!node) {
  1648. node = allocate_node(nodeid);
  1649. new_node = 1;
  1650. }
  1651. if (!node) {
  1652. corosync_api->error_memory_failure();
  1653. LEAVE();
  1654. return;
  1655. }
  1656. if (new_node) {
  1657. old_votes = 0;
  1658. old_expected = 0;
  1659. old_state = NODESTATE_DEAD;
  1660. old_flags = 0;
  1661. } else {
  1662. old_votes = node->votes;
  1663. old_expected = node->expected_votes;
  1664. old_state = node->state;
  1665. old_flags = node->flags;
  1666. }
  1667. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  1668. struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
  1669. assert(sender_node != NULL);
  1670. if ((!cluster_is_quorate) &&
  1671. (sender_node->flags & NODE_FLAGS_QUORATE)) {
  1672. node->votes = req_exec_quorum_nodeinfo->votes;
  1673. } else {
  1674. node->votes = max(node->votes, req_exec_quorum_nodeinfo->votes);
  1675. }
  1676. goto recalculate;
  1677. }
  1678. /* Update node state */
  1679. node->flags = req_exec_quorum_nodeinfo->flags;
  1680. node->votes = req_exec_quorum_nodeinfo->votes;
  1681. node->state = NODESTATE_MEMBER;
  1682. if (node->flags & NODE_FLAGS_LEAVING) {
  1683. node->state = NODESTATE_LEAVING;
  1684. allow_downgrade = 1;
  1685. by_node = 1;
  1686. }
  1687. if ((!cluster_is_quorate) &&
  1688. (node->flags & NODE_FLAGS_QUORATE)) {
  1689. allow_downgrade = 1;
  1690. us->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1691. }
  1692. if (node->flags & NODE_FLAGS_QUORATE || (ev_tracking)) {
  1693. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1694. } else {
  1695. node->expected_votes = us->expected_votes;
  1696. }
  1697. if ((last_man_standing) && (node->votes > 1)) {
  1698. log_printf(LOGSYS_LEVEL_WARNING, "Last Man Standing feature is supported only when all"
  1699. "cluster nodes votes are set to 1. Disabling LMS.");
  1700. last_man_standing = 0;
  1701. if (last_man_standing_timer_set) {
  1702. corosync_api->timer_delete(last_man_standing_timer);
  1703. last_man_standing_timer_set = 0;
  1704. }
  1705. }
  1706. recalculate:
  1707. if ((new_node) ||
  1708. (nodeid == us->node_id) ||
  1709. (node->flags & NODE_FLAGS_FIRST) ||
  1710. (old_votes != node->votes) ||
  1711. (old_expected != node->expected_votes) ||
  1712. (old_flags != node->flags) ||
  1713. (old_state != node->state)) {
  1714. recalculate_quorum(allow_downgrade, by_node);
  1715. }
  1716. if ((wait_for_all) &&
  1717. (!(node->flags & NODE_FLAGS_WFASTATUS)) &&
  1718. (node->flags & NODE_FLAGS_QUORATE)) {
  1719. update_wait_for_all_status(0);
  1720. }
  1721. LEAVE();
  1722. }
  1723. static void exec_votequorum_reconfigure_endian_convert (void *message)
  1724. {
  1725. struct req_exec_quorum_reconfigure *reconfigure = message;
  1726. ENTER();
  1727. reconfigure->nodeid = swab32(reconfigure->nodeid);
  1728. reconfigure->value = swab32(reconfigure->value);
  1729. LEAVE();
  1730. }
  1731. static void message_handler_req_exec_votequorum_reconfigure (
  1732. const void *message,
  1733. unsigned int nodeid)
  1734. {
  1735. const struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = message;
  1736. struct cluster_node *node;
  1737. struct list_head *nodelist;
  1738. ENTER();
  1739. log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %u for %u",
  1740. nodeid, req_exec_quorum_reconfigure->nodeid);
  1741. switch(req_exec_quorum_reconfigure->param)
  1742. {
  1743. case VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES:
  1744. list_iterate(nodelist, &cluster_members_list) {
  1745. node = list_entry(nodelist, struct cluster_node, list);
  1746. if (node->state == NODESTATE_MEMBER) {
  1747. node->expected_votes = req_exec_quorum_reconfigure->value;
  1748. }
  1749. }
  1750. votequorum_exec_send_expectedvotes_notification();
  1751. update_ev_barrier(req_exec_quorum_reconfigure->value);
  1752. if (ev_tracking) {
  1753. us->expected_votes = max(us->expected_votes, ev_tracking_barrier);
  1754. }
  1755. recalculate_quorum(1, 0); /* Allow decrease */
  1756. break;
  1757. case VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES:
  1758. node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
  1759. if (!node) {
  1760. LEAVE();
  1761. return;
  1762. }
  1763. node->votes = req_exec_quorum_reconfigure->value;
  1764. recalculate_quorum(1, 0); /* Allow decrease */
  1765. break;
  1766. case VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA:
  1767. update_wait_for_all_status(0);
  1768. log_printf(LOGSYS_LEVEL_INFO, "wait_for_all_status reset by user on node %d.",
  1769. req_exec_quorum_reconfigure->nodeid);
  1770. recalculate_quorum(0, 0);
  1771. break;
  1772. }
  1773. LEAVE();
  1774. }
  1775. static int votequorum_exec_exit_fn (void)
  1776. {
  1777. int ret = 0;
  1778. ENTER();
  1779. /*
  1780. * tell the other nodes we are leaving
  1781. */
  1782. if (allow_downscale) {
  1783. us->flags |= NODE_FLAGS_LEAVING;
  1784. ret = votequorum_exec_send_nodeinfo(us->node_id);
  1785. }
  1786. if ((ev_tracking) && (ev_tracking_fd != -1)) {
  1787. close(ev_tracking_fd);
  1788. }
  1789. LEAVE();
  1790. return ret;
  1791. }
  1792. static void votequorum_set_icmap_ro_keys(void)
  1793. {
  1794. icmap_set_ro_access("quorum.allow_downscale", CS_FALSE, CS_TRUE);
  1795. icmap_set_ro_access("quorum.wait_for_all", CS_FALSE, CS_TRUE);
  1796. icmap_set_ro_access("quorum.last_man_standing", CS_FALSE, CS_TRUE);
  1797. icmap_set_ro_access("quorum.last_man_standing_window", CS_FALSE, CS_TRUE);
  1798. icmap_set_ro_access("quorum.expected_votes_tracking", CS_FALSE, CS_TRUE);
  1799. icmap_set_ro_access("quorum.auto_tie_breaker", CS_FALSE, CS_TRUE);
  1800. icmap_set_ro_access("quorum.auto_tie_breaker_node", CS_FALSE, CS_TRUE);
  1801. }
  1802. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api)
  1803. {
  1804. char *error = NULL;
  1805. ENTER();
  1806. /*
  1807. * make sure we start clean
  1808. */
  1809. list_init(&cluster_members_list);
  1810. list_init(&trackers_list);
  1811. qdevice = NULL;
  1812. us = NULL;
  1813. memset(cluster_nodes, 0, sizeof(cluster_nodes));
  1814. /*
  1815. * Allocate a cluster_node for qdevice
  1816. */
  1817. qdevice = allocate_node(VOTEQUORUM_QDEVICE_NODEID);
  1818. if (!qdevice) {
  1819. LEAVE();
  1820. return ((char *)"Could not allocate node.");
  1821. }
  1822. qdevice->votes = 0;
  1823. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1824. /*
  1825. * Allocate a cluster_node for us
  1826. */
  1827. us = allocate_node(corosync_api->totem_nodeid_get());
  1828. if (!us) {
  1829. LEAVE();
  1830. return ((char *)"Could not allocate node.");
  1831. }
  1832. icmap_set_uint32("runtime.votequorum.this_node_id", us->node_id);
  1833. us->state = NODESTATE_MEMBER;
  1834. us->votes = 1;
  1835. us->flags |= NODE_FLAGS_FIRST;
  1836. error = votequorum_readconfig(VOTEQUORUM_READCONFIG_STARTUP);
  1837. if (error) {
  1838. return error;
  1839. }
  1840. recalculate_quorum(0, 0);
  1841. /*
  1842. * Set RO keys in icmap
  1843. */
  1844. votequorum_set_icmap_ro_keys();
  1845. /*
  1846. * Listen for changes
  1847. */
  1848. votequorum_exec_add_config_notification();
  1849. /*
  1850. * Start us off with one node
  1851. */
  1852. votequorum_exec_send_nodeinfo(us->node_id);
  1853. LEAVE();
  1854. return (NULL);
  1855. }
  1856. /*
  1857. * votequorum service core
  1858. */
  1859. static void votequorum_last_man_standing_timer_fn(void *arg)
  1860. {
  1861. ENTER();
  1862. last_man_standing_timer_set = 0;
  1863. if (cluster_is_quorate) {
  1864. recalculate_quorum(1,1);
  1865. }
  1866. LEAVE();
  1867. }
  1868. static void votequorum_sync_init (
  1869. const unsigned int *trans_list, size_t trans_list_entries,
  1870. const unsigned int *member_list, size_t member_list_entries,
  1871. const struct memb_ring_id *ring_id)
  1872. {
  1873. int i, j;
  1874. int found;
  1875. int left_nodes;
  1876. struct cluster_node *node;
  1877. ENTER();
  1878. sync_in_progress = 1;
  1879. sync_nodeinfo_sent = 0;
  1880. sync_wait_for_poll_or_timeout = 0;
  1881. if (member_list_entries > 1) {
  1882. us->flags &= ~NODE_FLAGS_FIRST;
  1883. }
  1884. /*
  1885. * we don't need to track which nodes have left directly,
  1886. * since that info is in the node db, but we need to know
  1887. * if somebody has left for last_man_standing
  1888. */
  1889. left_nodes = 0;
  1890. for (i = 0; i < quorum_members_entries; i++) {
  1891. found = 0;
  1892. for (j = 0; j < member_list_entries; j++) {
  1893. if (quorum_members[i] == member_list[j]) {
  1894. found = 1;
  1895. break;
  1896. }
  1897. }
  1898. if (found == 0) {
  1899. left_nodes = 1;
  1900. node = find_node_by_nodeid(quorum_members[i]);
  1901. if (node) {
  1902. node->state = NODESTATE_DEAD;
  1903. }
  1904. }
  1905. }
  1906. if (last_man_standing) {
  1907. if (((member_list_entries >= quorum) && (left_nodes)) ||
  1908. ((member_list_entries <= quorum) && (auto_tie_breaker != ATB_NONE) && (check_low_node_id_partition() == 1))) {
  1909. if (last_man_standing_timer_set) {
  1910. corosync_api->timer_delete(last_man_standing_timer);
  1911. last_man_standing_timer_set = 0;
  1912. }
  1913. corosync_api->timer_add_duration((unsigned long long)last_man_standing_window*1000000,
  1914. NULL, votequorum_last_man_standing_timer_fn,
  1915. &last_man_standing_timer);
  1916. last_man_standing_timer_set = 1;
  1917. }
  1918. }
  1919. memcpy(previous_quorum_members, quorum_members, sizeof(unsigned int) * quorum_members_entries);
  1920. previous_quorum_members_entries = quorum_members_entries;
  1921. memcpy(quorum_members, member_list, sizeof(unsigned int) * member_list_entries);
  1922. quorum_members_entries = member_list_entries;
  1923. memcpy(&quorum_ringid, ring_id, sizeof(*ring_id));
  1924. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED && us->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  1925. /*
  1926. * Reset poll timer. Sync waiting is interrupted on valid qdevice poll or after timeout
  1927. */
  1928. if (qdevice_timer_set) {
  1929. corosync_api->timer_delete(qdevice_timer);
  1930. }
  1931. corosync_api->timer_add_duration((unsigned long long)qdevice_sync_timeout*1000000, qdevice,
  1932. qdevice_timer_fn, &qdevice_timer);
  1933. qdevice_timer_set = 1;
  1934. sync_wait_for_poll_or_timeout = 1;
  1935. log_printf(LOGSYS_LEVEL_INFO, "waiting for quorum device %s poll (but maximum for %u ms)",
  1936. qdevice_name, qdevice_sync_timeout);
  1937. }
  1938. LEAVE();
  1939. }
  1940. static int votequorum_sync_process (void)
  1941. {
  1942. if (!sync_nodeinfo_sent) {
  1943. votequorum_exec_send_nodeinfo(us->node_id);
  1944. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1945. if (strlen(qdevice_name)) {
  1946. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1947. qdevice_name);
  1948. }
  1949. sync_nodeinfo_sent = 1;
  1950. }
  1951. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED && sync_wait_for_poll_or_timeout) {
  1952. /*
  1953. * Waiting for qdevice to poll with new ringid or timeout
  1954. */
  1955. return (-1);
  1956. }
  1957. return 0;
  1958. }
  1959. static void votequorum_sync_activate (void)
  1960. {
  1961. recalculate_quorum(0, 0);
  1962. quorum_callback(quorum_members, quorum_members_entries,
  1963. cluster_is_quorate, &quorum_ringid);
  1964. votequorum_exec_send_quorum_notification(NULL, 0L);
  1965. sync_in_progress = 0;
  1966. }
  1967. static void votequorum_sync_abort (void)
  1968. {
  1969. }
  1970. char *votequorum_init(struct corosync_api_v1 *api,
  1971. quorum_set_quorate_fn_t q_set_quorate_fn)
  1972. {
  1973. char *error;
  1974. ENTER();
  1975. if (q_set_quorate_fn == NULL) {
  1976. return ((char *)"Quorate function not set");
  1977. }
  1978. corosync_api = api;
  1979. quorum_callback = q_set_quorate_fn;
  1980. error = corosync_service_link_and_init(corosync_api,
  1981. &votequorum_service[0]);
  1982. if (error) {
  1983. return (error);
  1984. }
  1985. LEAVE();
  1986. return (NULL);
  1987. }
  1988. /*
  1989. * Library Handler init/fini
  1990. */
  1991. static int quorum_lib_init_fn (void *conn)
  1992. {
  1993. struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1994. ENTER();
  1995. list_init (&pd->list);
  1996. pd->conn = conn;
  1997. LEAVE();
  1998. return (0);
  1999. }
  2000. static int quorum_lib_exit_fn (void *conn)
  2001. {
  2002. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2003. ENTER();
  2004. if (quorum_pd->tracking_enabled) {
  2005. list_del (&quorum_pd->list);
  2006. list_init (&quorum_pd->list);
  2007. }
  2008. LEAVE();
  2009. return (0);
  2010. }
  2011. /*
  2012. * library internal functions
  2013. */
  2014. static void qdevice_timer_fn(void *arg)
  2015. {
  2016. ENTER();
  2017. if ((!(us->flags & NODE_FLAGS_QDEVICE_ALIVE)) ||
  2018. (!qdevice_timer_set)) {
  2019. LEAVE();
  2020. return;
  2021. }
  2022. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  2023. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2024. log_printf(LOGSYS_LEVEL_INFO, "lost contact with quorum device %s", qdevice_name);
  2025. votequorum_exec_send_nodeinfo(us->node_id);
  2026. qdevice_timer_set = 0;
  2027. sync_wait_for_poll_or_timeout = 0;
  2028. LEAVE();
  2029. }
  2030. /*
  2031. * Library Handler Functions
  2032. */
  2033. static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *message)
  2034. {
  2035. const struct req_lib_votequorum_getinfo *req_lib_votequorum_getinfo = message;
  2036. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  2037. struct cluster_node *node;
  2038. unsigned int highest_expected = 0;
  2039. unsigned int total_votes = 0;
  2040. cs_error_t error = CS_OK;
  2041. uint32_t nodeid = req_lib_votequorum_getinfo->nodeid;
  2042. ENTER();
  2043. log_printf(LOGSYS_LEVEL_DEBUG, "got getinfo request on %p for node %u", conn, req_lib_votequorum_getinfo->nodeid);
  2044. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  2045. nodeid = us->node_id;
  2046. }
  2047. node = find_node_by_nodeid(nodeid);
  2048. if (node) {
  2049. struct cluster_node *iternode;
  2050. struct list_head *nodelist;
  2051. list_iterate(nodelist, &cluster_members_list) {
  2052. iternode = list_entry(nodelist, struct cluster_node, list);
  2053. if (iternode->state == NODESTATE_MEMBER) {
  2054. highest_expected =
  2055. max(highest_expected, iternode->expected_votes);
  2056. total_votes += iternode->votes;
  2057. }
  2058. }
  2059. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  2060. total_votes += qdevice->votes;
  2061. }
  2062. switch(node->state) {
  2063. case NODESTATE_MEMBER:
  2064. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_MEMBER;
  2065. break;
  2066. case NODESTATE_DEAD:
  2067. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_DEAD;
  2068. break;
  2069. case NODESTATE_LEAVING:
  2070. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_LEAVING;
  2071. break;
  2072. default:
  2073. res_lib_votequorum_getinfo.state = node->state;
  2074. break;
  2075. }
  2076. res_lib_votequorum_getinfo.state = node->state;
  2077. res_lib_votequorum_getinfo.votes = node->votes;
  2078. res_lib_votequorum_getinfo.expected_votes = node->expected_votes;
  2079. res_lib_votequorum_getinfo.highest_expected = highest_expected;
  2080. res_lib_votequorum_getinfo.quorum = quorum;
  2081. res_lib_votequorum_getinfo.total_votes = total_votes;
  2082. res_lib_votequorum_getinfo.flags = 0;
  2083. res_lib_votequorum_getinfo.nodeid = node->node_id;
  2084. if (two_node) {
  2085. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_TWONODE;
  2086. }
  2087. if (cluster_is_quorate) {
  2088. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QUORATE;
  2089. }
  2090. if (wait_for_all) {
  2091. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_WAIT_FOR_ALL;
  2092. }
  2093. if (last_man_standing) {
  2094. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_LAST_MAN_STANDING;
  2095. }
  2096. if (auto_tie_breaker != ATB_NONE) {
  2097. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_AUTO_TIE_BREAKER;
  2098. }
  2099. if (allow_downscale) {
  2100. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_ALLOW_DOWNSCALE;
  2101. }
  2102. memset(res_lib_votequorum_getinfo.qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  2103. strcpy(res_lib_votequorum_getinfo.qdevice_name, qdevice_name);
  2104. res_lib_votequorum_getinfo.qdevice_votes = qdevice->votes;
  2105. if (node->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2106. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_REGISTERED;
  2107. }
  2108. if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  2109. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_ALIVE;
  2110. }
  2111. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  2112. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_CAST_VOTE;
  2113. }
  2114. if (node->flags & NODE_FLAGS_QDEVICE_MASTER_WINS) {
  2115. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_MASTER_WINS;
  2116. }
  2117. } else {
  2118. error = CS_ERR_NOT_EXIST;
  2119. }
  2120. res_lib_votequorum_getinfo.header.size = sizeof(res_lib_votequorum_getinfo);
  2121. res_lib_votequorum_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  2122. res_lib_votequorum_getinfo.header.error = error;
  2123. corosync_api->ipc_response_send(conn, &res_lib_votequorum_getinfo, sizeof(res_lib_votequorum_getinfo));
  2124. log_printf(LOGSYS_LEVEL_DEBUG, "getinfo response error: %d", error);
  2125. LEAVE();
  2126. }
  2127. static void message_handler_req_lib_votequorum_setexpected (void *conn, const void *message)
  2128. {
  2129. const struct req_lib_votequorum_setexpected *req_lib_votequorum_setexpected = message;
  2130. struct res_lib_votequorum_status res_lib_votequorum_status;
  2131. cs_error_t error = CS_OK;
  2132. unsigned int newquorum;
  2133. unsigned int total_votes;
  2134. uint8_t allow_downscale_status = 0;
  2135. ENTER();
  2136. allow_downscale_status = allow_downscale;
  2137. allow_downscale = 0;
  2138. /*
  2139. * Validate new expected votes
  2140. */
  2141. newquorum = calculate_quorum(1, req_lib_votequorum_setexpected->expected_votes, &total_votes);
  2142. allow_downscale = allow_downscale_status;
  2143. if (newquorum < total_votes / 2 ||
  2144. newquorum > total_votes) {
  2145. error = CS_ERR_INVALID_PARAM;
  2146. goto error_exit;
  2147. }
  2148. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES, us->node_id,
  2149. req_lib_votequorum_setexpected->expected_votes);
  2150. error_exit:
  2151. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2152. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2153. res_lib_votequorum_status.header.error = error;
  2154. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2155. LEAVE();
  2156. }
  2157. static void message_handler_req_lib_votequorum_setvotes (void *conn, const void *message)
  2158. {
  2159. const struct req_lib_votequorum_setvotes *req_lib_votequorum_setvotes = message;
  2160. struct res_lib_votequorum_status res_lib_votequorum_status;
  2161. struct cluster_node *node;
  2162. unsigned int newquorum;
  2163. unsigned int total_votes;
  2164. unsigned int saved_votes;
  2165. cs_error_t error = CS_OK;
  2166. unsigned int nodeid;
  2167. ENTER();
  2168. nodeid = req_lib_votequorum_setvotes->nodeid;
  2169. node = find_node_by_nodeid(nodeid);
  2170. if (!node) {
  2171. error = CS_ERR_NAME_NOT_FOUND;
  2172. goto error_exit;
  2173. }
  2174. /*
  2175. * Check votes is valid
  2176. */
  2177. saved_votes = node->votes;
  2178. node->votes = req_lib_votequorum_setvotes->votes;
  2179. newquorum = calculate_quorum(1, 0, &total_votes);
  2180. if (newquorum < total_votes / 2 ||
  2181. newquorum > total_votes) {
  2182. node->votes = saved_votes;
  2183. error = CS_ERR_INVALID_PARAM;
  2184. goto error_exit;
  2185. }
  2186. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES, nodeid,
  2187. req_lib_votequorum_setvotes->votes);
  2188. error_exit:
  2189. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2190. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2191. res_lib_votequorum_status.header.error = error;
  2192. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2193. LEAVE();
  2194. }
  2195. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  2196. const void *message)
  2197. {
  2198. const struct req_lib_votequorum_trackstart *req_lib_votequorum_trackstart = message;
  2199. struct res_lib_votequorum_status res_lib_votequorum_status;
  2200. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2201. cs_error_t error = CS_OK;
  2202. ENTER();
  2203. /*
  2204. * If an immediate listing of the current cluster membership
  2205. * is requested, generate membership list
  2206. */
  2207. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
  2208. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
  2209. log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p", conn);
  2210. votequorum_exec_send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
  2211. }
  2212. if (quorum_pd->tracking_enabled) {
  2213. error = CS_ERR_EXIST;
  2214. goto response_send;
  2215. }
  2216. /*
  2217. * Record requests for tracking
  2218. */
  2219. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES ||
  2220. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
  2221. quorum_pd->track_flags = req_lib_votequorum_trackstart->track_flags;
  2222. quorum_pd->tracking_enabled = 1;
  2223. quorum_pd->tracking_context = req_lib_votequorum_trackstart->context;
  2224. list_add (&quorum_pd->list, &trackers_list);
  2225. }
  2226. response_send:
  2227. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2228. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2229. res_lib_votequorum_status.header.error = error;
  2230. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2231. LEAVE();
  2232. }
  2233. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  2234. const void *message)
  2235. {
  2236. struct res_lib_votequorum_status res_lib_votequorum_status;
  2237. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2238. int error = CS_OK;
  2239. ENTER();
  2240. if (quorum_pd->tracking_enabled) {
  2241. error = CS_OK;
  2242. quorum_pd->tracking_enabled = 0;
  2243. list_del (&quorum_pd->list);
  2244. list_init (&quorum_pd->list);
  2245. } else {
  2246. error = CS_ERR_NOT_EXIST;
  2247. }
  2248. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2249. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2250. res_lib_votequorum_status.header.error = error;
  2251. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2252. LEAVE();
  2253. }
  2254. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  2255. const void *message)
  2256. {
  2257. const struct req_lib_votequorum_qdevice_register *req_lib_votequorum_qdevice_register = message;
  2258. struct res_lib_votequorum_status res_lib_votequorum_status;
  2259. cs_error_t error = CS_OK;
  2260. ENTER();
  2261. if (!qdevice_can_operate) {
  2262. log_printf(LOGSYS_LEVEL_INFO, "Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
  2263. error = CS_ERR_ACCESS;
  2264. goto out;
  2265. }
  2266. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2267. if ((!strncmp(req_lib_votequorum_qdevice_register->name,
  2268. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  2269. goto out;
  2270. } else {
  2271. log_printf(LOGSYS_LEVEL_WARNING,
  2272. "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
  2273. req_lib_votequorum_qdevice_register->name, qdevice_name);
  2274. error = CS_ERR_EXIST;
  2275. goto out;
  2276. }
  2277. } else {
  2278. if (qdevice_reg_conn != NULL) {
  2279. log_printf(LOGSYS_LEVEL_WARNING,
  2280. "Registration request already in progress");
  2281. error = CS_ERR_TRY_AGAIN;
  2282. goto out;
  2283. }
  2284. qdevice_reg_conn = conn;
  2285. if (votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  2286. req_lib_votequorum_qdevice_register->name) != 0) {
  2287. log_printf(LOGSYS_LEVEL_WARNING,
  2288. "Unable to send qdevice registration request to cluster");
  2289. error = CS_ERR_TRY_AGAIN;
  2290. qdevice_reg_conn = NULL;
  2291. } else {
  2292. LEAVE();
  2293. return;
  2294. }
  2295. }
  2296. out:
  2297. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2298. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2299. res_lib_votequorum_status.header.error = error;
  2300. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2301. LEAVE();
  2302. }
  2303. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  2304. const void *message)
  2305. {
  2306. const struct req_lib_votequorum_qdevice_unregister *req_lib_votequorum_qdevice_unregister = message;
  2307. struct res_lib_votequorum_status res_lib_votequorum_status;
  2308. cs_error_t error = CS_OK;
  2309. ENTER();
  2310. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2311. if (strncmp(req_lib_votequorum_qdevice_unregister->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2312. error = CS_ERR_INVALID_PARAM;
  2313. goto out;
  2314. }
  2315. if (qdevice_timer_set) {
  2316. corosync_api->timer_delete(qdevice_timer);
  2317. qdevice_timer_set = 0;
  2318. sync_wait_for_poll_or_timeout = 0;
  2319. }
  2320. us->flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
  2321. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  2322. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2323. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2324. votequorum_exec_send_nodeinfo(us->node_id);
  2325. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER,
  2326. req_lib_votequorum_qdevice_unregister->name);
  2327. } else {
  2328. error = CS_ERR_NOT_EXIST;
  2329. }
  2330. out:
  2331. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2332. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2333. res_lib_votequorum_status.header.error = error;
  2334. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2335. LEAVE();
  2336. }
  2337. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  2338. const void *message)
  2339. {
  2340. const struct req_lib_votequorum_qdevice_update *req_lib_votequorum_qdevice_update = message;
  2341. struct res_lib_votequorum_status res_lib_votequorum_status;
  2342. cs_error_t error = CS_OK;
  2343. ENTER();
  2344. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2345. if (strncmp(req_lib_votequorum_qdevice_update->oldname, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2346. error = CS_ERR_INVALID_PARAM;
  2347. goto out;
  2348. }
  2349. votequorum_exec_send_qdevice_reconfigure(req_lib_votequorum_qdevice_update->oldname,
  2350. req_lib_votequorum_qdevice_update->newname);
  2351. } else {
  2352. error = CS_ERR_NOT_EXIST;
  2353. }
  2354. out:
  2355. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2356. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2357. res_lib_votequorum_status.header.error = error;
  2358. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2359. LEAVE();
  2360. }
  2361. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  2362. const void *message)
  2363. {
  2364. const struct req_lib_votequorum_qdevice_poll *req_lib_votequorum_qdevice_poll = message;
  2365. struct res_lib_votequorum_status res_lib_votequorum_status;
  2366. cs_error_t error = CS_OK;
  2367. uint32_t oldflags;
  2368. ENTER();
  2369. if (!qdevice_can_operate) {
  2370. error = CS_ERR_ACCESS;
  2371. goto out;
  2372. }
  2373. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2374. if (!(req_lib_votequorum_qdevice_poll->ring_id.nodeid == quorum_ringid.rep.nodeid &&
  2375. req_lib_votequorum_qdevice_poll->ring_id.seq == quorum_ringid.seq)) {
  2376. log_printf(LOGSYS_LEVEL_DEBUG, "Received poll ring id (%u.%"PRIu64") != last sync "
  2377. "ring id (%u.%"PRIu64"). Ignoring poll call.",
  2378. req_lib_votequorum_qdevice_poll->ring_id.nodeid, req_lib_votequorum_qdevice_poll->ring_id.seq,
  2379. quorum_ringid.rep.nodeid, quorum_ringid.seq);
  2380. error = CS_ERR_MESSAGE_ERROR;
  2381. goto out;
  2382. }
  2383. if (strncmp(req_lib_votequorum_qdevice_poll->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2384. error = CS_ERR_INVALID_PARAM;
  2385. goto out;
  2386. }
  2387. if (qdevice_timer_set) {
  2388. corosync_api->timer_delete(qdevice_timer);
  2389. qdevice_timer_set = 0;
  2390. }
  2391. oldflags = us->flags;
  2392. us->flags |= NODE_FLAGS_QDEVICE_ALIVE;
  2393. if (req_lib_votequorum_qdevice_poll->cast_vote) {
  2394. us->flags |= NODE_FLAGS_QDEVICE_CAST_VOTE;
  2395. } else {
  2396. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2397. }
  2398. if (us->flags != oldflags) {
  2399. votequorum_exec_send_nodeinfo(us->node_id);
  2400. }
  2401. corosync_api->timer_add_duration((unsigned long long)qdevice_timeout*1000000, qdevice,
  2402. qdevice_timer_fn, &qdevice_timer);
  2403. qdevice_timer_set = 1;
  2404. sync_wait_for_poll_or_timeout = 0;
  2405. } else {
  2406. error = CS_ERR_NOT_EXIST;
  2407. }
  2408. out:
  2409. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2410. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2411. res_lib_votequorum_status.header.error = error;
  2412. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2413. LEAVE();
  2414. }
  2415. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  2416. const void *message)
  2417. {
  2418. const struct req_lib_votequorum_qdevice_master_wins *req_lib_votequorum_qdevice_master_wins = message;
  2419. struct res_lib_votequorum_status res_lib_votequorum_status;
  2420. cs_error_t error = CS_OK;
  2421. uint32_t oldflags = us->flags;
  2422. ENTER();
  2423. if (!qdevice_can_operate) {
  2424. error = CS_ERR_ACCESS;
  2425. goto out;
  2426. }
  2427. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2428. if (strncmp(req_lib_votequorum_qdevice_master_wins->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2429. error = CS_ERR_INVALID_PARAM;
  2430. goto out;
  2431. }
  2432. if (req_lib_votequorum_qdevice_master_wins->allow) {
  2433. us->flags |= NODE_FLAGS_QDEVICE_MASTER_WINS;
  2434. } else {
  2435. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2436. }
  2437. if (us->flags != oldflags) {
  2438. votequorum_exec_send_nodeinfo(us->node_id);
  2439. }
  2440. update_qdevice_master_wins(req_lib_votequorum_qdevice_master_wins->allow);
  2441. } else {
  2442. error = CS_ERR_NOT_EXIST;
  2443. }
  2444. out:
  2445. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2446. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2447. res_lib_votequorum_status.header.error = error;
  2448. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2449. LEAVE();
  2450. }