votequorum.c 83 KB

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