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