votequorum.c 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027
  1. /*
  2. * Copyright (c) 2009-2015 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Authors: Christine Caulfield (ccaulfie@redhat.com)
  7. * Fabio M. Di Nitto (fdinitto@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <config.h>
  36. #include <sys/types.h>
  37. #include <sys/stat.h>
  38. #include <fcntl.h>
  39. #include <stdint.h>
  40. #include <unistd.h>
  41. #include <qb/qblist.h>
  42. #include <qb/qbipc_common.h>
  43. #include "quorum.h"
  44. #include <corosync/corodefs.h>
  45. #include <corosync/logsys.h>
  46. #include <corosync/coroapi.h>
  47. #include <corosync/icmap.h>
  48. #include <corosync/votequorum.h>
  49. #include <corosync/ipc_votequorum.h>
  50. #include "service.h"
  51. #include "util.h"
  52. LOGSYS_DECLARE_SUBSYS ("VOTEQ");
  53. /*
  54. * interface with corosync
  55. */
  56. static struct corosync_api_v1 *corosync_api;
  57. /*
  58. * votequorum global config vars
  59. */
  60. static char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  61. static struct cluster_node *qdevice = NULL;
  62. static unsigned int qdevice_timeout = VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT;
  63. static unsigned int qdevice_sync_timeout = VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT;
  64. static uint8_t qdevice_can_operate = 1;
  65. static void *qdevice_reg_conn = NULL;
  66. static uint8_t qdevice_master_wins = 0;
  67. static uint8_t two_node = 0;
  68. static uint8_t wait_for_all = 0;
  69. static uint8_t wait_for_all_status = 0;
  70. static enum {ATB_NONE, ATB_LOWEST, ATB_HIGHEST, ATB_LIST} auto_tie_breaker = ATB_NONE;
  71. static int lowest_node_id = -1;
  72. static int highest_node_id = -1;
  73. #define DEFAULT_LMS_WIN 10000
  74. static uint8_t last_man_standing = 0;
  75. static uint32_t last_man_standing_window = DEFAULT_LMS_WIN;
  76. static uint8_t allow_downscale = 0;
  77. static uint32_t ev_barrier = 0;
  78. static uint8_t ev_tracking = 0;
  79. static uint32_t ev_tracking_barrier = 0;
  80. static int ev_tracking_fd = -1;
  81. /*
  82. * votequorum_exec defines/structs/forward definitions
  83. */
  84. struct req_exec_quorum_nodeinfo {
  85. struct qb_ipc_request_header header __attribute__((aligned(8)));
  86. uint32_t nodeid;
  87. uint32_t votes;
  88. uint32_t expected_votes;
  89. uint32_t flags;
  90. } __attribute__((packed));
  91. struct req_exec_quorum_reconfigure {
  92. struct qb_ipc_request_header header __attribute__((aligned(8)));
  93. uint32_t nodeid;
  94. uint32_t value;
  95. uint8_t param;
  96. uint8_t _pad0;
  97. uint8_t _pad1;
  98. uint8_t _pad2;
  99. } __attribute__((packed));
  100. struct req_exec_quorum_qdevice_reg {
  101. struct qb_ipc_request_header header __attribute__((aligned(8)));
  102. uint32_t operation;
  103. char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  104. } __attribute__((packed));
  105. struct req_exec_quorum_qdevice_reconfigure {
  106. struct qb_ipc_request_header header __attribute__((aligned(8)));
  107. char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  108. char newname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  109. } __attribute__((packed));
  110. /*
  111. * votequorum_exec onwire version (via totem)
  112. */
  113. #include "votequorum.h"
  114. /*
  115. * votequorum_exec onwire messages (via totem)
  116. */
  117. #define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO 0
  118. #define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE 1
  119. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG 2
  120. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE 3
  121. static void votequorum_exec_send_expectedvotes_notification(void);
  122. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context);
  123. static int votequorum_exec_send_nodelist_notification(void *conn, uint64_t context);
  124. #define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES 1
  125. #define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES 2
  126. #define VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA 3
  127. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value);
  128. /*
  129. * used by req_exec_quorum_qdevice_reg
  130. */
  131. #define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER 0
  132. #define VOTEQUORUM_QDEVICE_OPERATION_REGISTER 1
  133. /*
  134. * votequorum internal node status/view
  135. */
  136. #define NODE_FLAGS_QUORATE 1
  137. #define NODE_FLAGS_LEAVING 2
  138. #define NODE_FLAGS_WFASTATUS 4
  139. #define NODE_FLAGS_FIRST 8
  140. #define NODE_FLAGS_QDEVICE_REGISTERED 16
  141. #define NODE_FLAGS_QDEVICE_ALIVE 32
  142. #define NODE_FLAGS_QDEVICE_CAST_VOTE 64
  143. #define NODE_FLAGS_QDEVICE_MASTER_WINS 128
  144. typedef enum {
  145. NODESTATE_MEMBER=1,
  146. NODESTATE_DEAD,
  147. NODESTATE_LEAVING
  148. } nodestate_t;
  149. struct cluster_node {
  150. int node_id;
  151. nodestate_t state;
  152. uint32_t votes;
  153. uint32_t expected_votes;
  154. uint32_t flags;
  155. struct qb_list_head list;
  156. };
  157. /*
  158. * votequorum internal quorum status
  159. */
  160. static uint8_t quorum;
  161. static uint8_t cluster_is_quorate;
  162. /*
  163. * votequorum membership data
  164. */
  165. static struct cluster_node *us;
  166. static struct qb_list_head cluster_members_list;
  167. static unsigned int quorum_members[PROCESSOR_COUNT_MAX];
  168. static unsigned int previous_quorum_members[PROCESSOR_COUNT_MAX];
  169. static unsigned int atb_nodelist[PROCESSOR_COUNT_MAX];
  170. static int quorum_members_entries = 0;
  171. static int previous_quorum_members_entries = 0;
  172. static int atb_nodelist_entries = 0;
  173. static struct memb_ring_id quorum_ringid;
  174. /*
  175. * pre allocate all cluster_nodes + one for qdevice
  176. */
  177. static struct cluster_node cluster_nodes[PROCESSOR_COUNT_MAX+2];
  178. static int cluster_nodes_entries = 0;
  179. /*
  180. * votequorum tracking
  181. */
  182. struct quorum_pd {
  183. unsigned char track_flags;
  184. int tracking_enabled;
  185. uint64_t tracking_context;
  186. struct qb_list_head list;
  187. void *conn;
  188. };
  189. static struct qb_list_head trackers_list;
  190. /*
  191. * votequorum timers
  192. */
  193. static corosync_timer_handle_t qdevice_timer;
  194. static int qdevice_timer_set = 0;
  195. static corosync_timer_handle_t last_man_standing_timer;
  196. static int last_man_standing_timer_set = 0;
  197. static int sync_nodeinfo_sent = 0;
  198. static int sync_wait_for_poll_or_timeout = 0;
  199. /*
  200. * Service Interfaces required by service_message_handler struct
  201. */
  202. static int sync_in_progress = 0;
  203. static void votequorum_sync_init (
  204. const unsigned int *trans_list,
  205. size_t trans_list_entries,
  206. const unsigned int *member_list,
  207. size_t member_list_entries,
  208. const struct memb_ring_id *ring_id);
  209. static int votequorum_sync_process (void);
  210. static void votequorum_sync_activate (void);
  211. static void votequorum_sync_abort (void);
  212. static quorum_set_quorate_fn_t quorum_callback;
  213. /*
  214. * votequorum_exec handler and definitions
  215. */
  216. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api);
  217. static int votequorum_exec_exit_fn (void);
  218. static int votequorum_exec_send_nodeinfo(uint32_t nodeid);
  219. static void message_handler_req_exec_votequorum_nodeinfo (
  220. const void *message,
  221. unsigned int nodeid);
  222. static void exec_votequorum_nodeinfo_endian_convert (void *message);
  223. static void message_handler_req_exec_votequorum_reconfigure (
  224. const void *message,
  225. unsigned int nodeid);
  226. static void exec_votequorum_reconfigure_endian_convert (void *message);
  227. static void message_handler_req_exec_votequorum_qdevice_reg (
  228. const void *message,
  229. unsigned int nodeid);
  230. static void exec_votequorum_qdevice_reg_endian_convert (void *message);
  231. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  232. const void *message,
  233. unsigned int nodeid);
  234. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message);
  235. static struct corosync_exec_handler votequorum_exec_engine[] =
  236. {
  237. { /* 0 */
  238. .exec_handler_fn = message_handler_req_exec_votequorum_nodeinfo,
  239. .exec_endian_convert_fn = exec_votequorum_nodeinfo_endian_convert
  240. },
  241. { /* 1 */
  242. .exec_handler_fn = message_handler_req_exec_votequorum_reconfigure,
  243. .exec_endian_convert_fn = exec_votequorum_reconfigure_endian_convert
  244. },
  245. { /* 2 */
  246. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reg,
  247. .exec_endian_convert_fn = exec_votequorum_qdevice_reg_endian_convert
  248. },
  249. { /* 3 */
  250. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reconfigure,
  251. .exec_endian_convert_fn = exec_votequorum_qdevice_reconfigure_endian_convert
  252. },
  253. };
  254. /*
  255. * Library Handler and Functions Definitions
  256. */
  257. static int quorum_lib_init_fn (void *conn);
  258. static int quorum_lib_exit_fn (void *conn);
  259. static void qdevice_timer_fn(void *arg);
  260. static void message_handler_req_lib_votequorum_getinfo (void *conn,
  261. const void *message);
  262. static void message_handler_req_lib_votequorum_setexpected (void *conn,
  263. const void *message);
  264. static void message_handler_req_lib_votequorum_setvotes (void *conn,
  265. const void *message);
  266. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  267. const void *message);
  268. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  269. const void *message);
  270. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  271. const void *message);
  272. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  273. const void *message);
  274. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  275. const void *message);
  276. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  277. const void *message);
  278. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  279. const void *message);
  280. static struct corosync_lib_handler quorum_lib_service[] =
  281. {
  282. { /* 0 */
  283. .lib_handler_fn = message_handler_req_lib_votequorum_getinfo,
  284. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  285. },
  286. { /* 1 */
  287. .lib_handler_fn = message_handler_req_lib_votequorum_setexpected,
  288. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  289. },
  290. { /* 2 */
  291. .lib_handler_fn = message_handler_req_lib_votequorum_setvotes,
  292. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  293. },
  294. { /* 3 */
  295. .lib_handler_fn = message_handler_req_lib_votequorum_trackstart,
  296. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  297. },
  298. { /* 4 */
  299. .lib_handler_fn = message_handler_req_lib_votequorum_trackstop,
  300. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  301. },
  302. { /* 5 */
  303. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_register,
  304. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  305. },
  306. { /* 6 */
  307. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_unregister,
  308. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  309. },
  310. { /* 7 */
  311. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_update,
  312. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  313. },
  314. { /* 8 */
  315. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_poll,
  316. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  317. },
  318. { /* 9 */
  319. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_master_wins,
  320. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  321. }
  322. };
  323. static struct corosync_service_engine votequorum_service_engine = {
  324. .name = "corosync vote quorum service v1.0",
  325. .id = VOTEQUORUM_SERVICE,
  326. .priority = 2,
  327. .private_data_size = sizeof (struct quorum_pd),
  328. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  329. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED,
  330. .lib_init_fn = quorum_lib_init_fn,
  331. .lib_exit_fn = quorum_lib_exit_fn,
  332. .lib_engine = quorum_lib_service,
  333. .lib_engine_count = sizeof (quorum_lib_service) / sizeof (struct corosync_lib_handler),
  334. .exec_init_fn = votequorum_exec_init_fn,
  335. .exec_exit_fn = votequorum_exec_exit_fn,
  336. .exec_engine = votequorum_exec_engine,
  337. .exec_engine_count = sizeof (votequorum_exec_engine) / sizeof (struct corosync_exec_handler),
  338. .sync_init = votequorum_sync_init,
  339. .sync_process = votequorum_sync_process,
  340. .sync_activate = votequorum_sync_activate,
  341. .sync_abort = votequorum_sync_abort
  342. };
  343. struct corosync_service_engine *votequorum_get_service_engine_ver0 (void)
  344. {
  345. return (&votequorum_service_engine);
  346. }
  347. static struct default_service votequorum_service[] = {
  348. {
  349. .name = "corosync_votequorum",
  350. .ver = 0,
  351. .loader = votequorum_get_service_engine_ver0
  352. },
  353. };
  354. /*
  355. * common/utility macros/functions
  356. */
  357. #define max(a,b) (((a) > (b)) ? (a) : (b))
  358. static void node_add_ordered(struct cluster_node *newnode)
  359. {
  360. struct cluster_node *node = NULL;
  361. struct qb_list_head *tmp;
  362. struct qb_list_head *newlist = &newnode->list;
  363. ENTER();
  364. qb_list_for_each(tmp, &cluster_members_list) {
  365. node = qb_list_entry(tmp, struct cluster_node, list);
  366. if (newnode->node_id < node->node_id) {
  367. break;
  368. }
  369. }
  370. if (!node) {
  371. qb_list_add(&newnode->list, &cluster_members_list);
  372. } else {
  373. newlist->prev = tmp->prev;
  374. newlist->next = tmp;
  375. tmp->prev->next = newlist;
  376. tmp->prev = newlist;
  377. }
  378. LEAVE();
  379. }
  380. static struct cluster_node *allocate_node(unsigned int nodeid)
  381. {
  382. struct cluster_node *cl = NULL;
  383. struct qb_list_head *tmp;
  384. ENTER();
  385. if (cluster_nodes_entries <= PROCESSOR_COUNT_MAX + 1) {
  386. cl = (struct cluster_node *)&cluster_nodes[cluster_nodes_entries];
  387. cluster_nodes_entries++;
  388. } else {
  389. qb_list_for_each(tmp, &cluster_members_list) {
  390. cl = qb_list_entry(tmp, struct cluster_node, list);
  391. if (cl->state == NODESTATE_DEAD) {
  392. break;
  393. }
  394. }
  395. /*
  396. * this should never happen
  397. */
  398. if (!cl) {
  399. log_printf(LOGSYS_LEVEL_CRIT, "Unable to find memory for node %u data!!", nodeid);
  400. goto out;
  401. }
  402. qb_list_del(tmp);
  403. }
  404. memset(cl, 0, sizeof(struct cluster_node));
  405. cl->node_id = nodeid;
  406. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  407. node_add_ordered(cl);
  408. }
  409. out:
  410. LEAVE();
  411. return cl;
  412. }
  413. static struct cluster_node *find_node_by_nodeid(unsigned int nodeid)
  414. {
  415. struct cluster_node *node;
  416. struct qb_list_head *tmp;
  417. ENTER();
  418. if (nodeid == us->node_id) {
  419. LEAVE();
  420. return us;
  421. }
  422. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  423. LEAVE();
  424. return qdevice;
  425. }
  426. qb_list_for_each(tmp, &cluster_members_list) {
  427. node = qb_list_entry(tmp, struct cluster_node, list);
  428. if (node->node_id == nodeid) {
  429. LEAVE();
  430. return node;
  431. }
  432. }
  433. LEAVE();
  434. return NULL;
  435. }
  436. static void get_lowest_node_id(void)
  437. {
  438. struct cluster_node *node = NULL;
  439. struct qb_list_head *tmp;
  440. ENTER();
  441. lowest_node_id = us->node_id;
  442. qb_list_for_each(tmp, &cluster_members_list) {
  443. node = qb_list_entry(tmp, struct cluster_node, list);
  444. if ((node->state == NODESTATE_MEMBER) &&
  445. (node->node_id < lowest_node_id)) {
  446. lowest_node_id = node->node_id;
  447. }
  448. }
  449. log_printf(LOGSYS_LEVEL_DEBUG, "lowest node id: %d us: %d", lowest_node_id, us->node_id);
  450. icmap_set_uint32("runtime.votequorum.lowest_node_id", lowest_node_id);
  451. LEAVE();
  452. }
  453. static void get_highest_node_id(void)
  454. {
  455. struct cluster_node *node = NULL;
  456. struct qb_list_head *tmp;
  457. ENTER();
  458. highest_node_id = us->node_id;
  459. qb_list_for_each(tmp, &cluster_members_list) {
  460. node = qb_list_entry(tmp, struct cluster_node, list);
  461. if ((node->state == NODESTATE_MEMBER) &&
  462. (node->node_id > highest_node_id)) {
  463. highest_node_id = node->node_id;
  464. }
  465. }
  466. log_printf(LOGSYS_LEVEL_DEBUG, "highest node id: %d us: %d", highest_node_id, us->node_id);
  467. icmap_set_uint32("runtime.votequorum.highest_node_id", highest_node_id);
  468. LEAVE();
  469. }
  470. static int check_low_node_id_partition(void)
  471. {
  472. struct cluster_node *node = NULL;
  473. struct qb_list_head *tmp;
  474. int found = 0;
  475. ENTER();
  476. qb_list_for_each(tmp, &cluster_members_list) {
  477. node = qb_list_entry(tmp, struct cluster_node, list);
  478. if ((node->state == NODESTATE_MEMBER) &&
  479. (node->node_id == lowest_node_id)) {
  480. found = 1;
  481. }
  482. }
  483. LEAVE();
  484. return found;
  485. }
  486. static int check_high_node_id_partition(void)
  487. {
  488. struct cluster_node *node = NULL;
  489. struct qb_list_head *tmp;
  490. int found = 0;
  491. ENTER();
  492. qb_list_for_each(tmp, &cluster_members_list) {
  493. node = qb_list_entry(tmp, struct cluster_node, list);
  494. if ((node->state == NODESTATE_MEMBER) &&
  495. (node->node_id == highest_node_id)) {
  496. found = 1;
  497. }
  498. }
  499. LEAVE();
  500. return found;
  501. }
  502. static int is_in_nodelist(int nodeid, unsigned int *members, int entries)
  503. {
  504. int i;
  505. ENTER();
  506. for (i=0; i<entries; i++) {
  507. if (nodeid == members[i]) {
  508. LEAVE();
  509. return 1;
  510. }
  511. }
  512. LEAVE();
  513. return 0;
  514. }
  515. /*
  516. * The algorithm for a list of tie-breaker nodes is:
  517. * travel the list of nodes in the auto_tie_breaker list,
  518. * if the node IS in our current partition, check if the
  519. * nodes earlier in the atb list are in the 'previous' partition;
  520. * If none are found then we are safe to be quorate, if any are
  521. * then we cannot be as we don't know if that node is up or down.
  522. * If we don't have a node in the current list we are NOT quorate.
  523. * Obviously if we find the first node in the atb list in our
  524. * partition then we are quorate.
  525. *
  526. * Special cases lowest nodeid, and highest nodeid are handled separately.
  527. */
  528. static int check_auto_tie_breaker(void)
  529. {
  530. int i, j;
  531. int res;
  532. ENTER();
  533. if (auto_tie_breaker == ATB_LOWEST) {
  534. res = check_low_node_id_partition();
  535. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LOWEST decision: %d", res);
  536. LEAVE();
  537. return res;
  538. }
  539. if (auto_tie_breaker == ATB_HIGHEST) {
  540. res = check_high_node_id_partition();
  541. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_HIGHEST decision: %d", res);
  542. LEAVE();
  543. return res;
  544. }
  545. /* Assume ATB_LIST, we should never be called for ATB_NONE */
  546. for (i=0; i < atb_nodelist_entries; i++) {
  547. if (is_in_nodelist(atb_nodelist[i], quorum_members, quorum_members_entries)) {
  548. /*
  549. * Node is in our partition, if any of its predecessors are
  550. * in the previous quorum partition then it might be in the
  551. * 'other half' (as we've got this far without seeing it here)
  552. * and so we can't be quorate.
  553. */
  554. for (j=0; j<i; j++) {
  555. if (is_in_nodelist(atb_nodelist[j], previous_quorum_members, previous_quorum_members_entries)) {
  556. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found node %d in previous partition but not here, quorum denied", atb_nodelist[j]);
  557. LEAVE();
  558. return 0;
  559. }
  560. }
  561. /*
  562. * None of the other list nodes were in the previous partition, if there
  563. * are enough votes, we can be quorate
  564. */
  565. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found node %d in current partition, we can be quorate", atb_nodelist[i]);
  566. LEAVE();
  567. return 1;
  568. }
  569. }
  570. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found no list nodes in current partition, we cannot be quorate");
  571. LEAVE();
  572. return 0;
  573. }
  574. /*
  575. * atb_string can be either:
  576. * 'lowest'
  577. * 'highest'
  578. * a list of nodeids
  579. */
  580. static void parse_atb_string(char *atb_string)
  581. {
  582. char *ptr;
  583. long num;
  584. ENTER();
  585. auto_tie_breaker = ATB_NONE;
  586. if (!strcmp(atb_string, "lowest"))
  587. auto_tie_breaker = ATB_LOWEST;
  588. if (!strcmp(atb_string, "highest"))
  589. auto_tie_breaker = ATB_HIGHEST;
  590. if (atoi(atb_string)) {
  591. atb_nodelist_entries = 0;
  592. ptr = atb_string;
  593. do {
  594. num = strtol(ptr, &ptr, 10);
  595. if (num) {
  596. log_printf(LOGSYS_LEVEL_DEBUG, "ATB nodelist[%d] = %d", atb_nodelist_entries, num);
  597. atb_nodelist[atb_nodelist_entries++] = num;
  598. }
  599. } while (num);
  600. if (atb_nodelist_entries) {
  601. auto_tie_breaker = ATB_LIST;
  602. }
  603. }
  604. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  605. log_printf(LOGSYS_LEVEL_DEBUG, "ATB type = %d", auto_tie_breaker);
  606. /* Make sure we got something */
  607. if (auto_tie_breaker == ATB_NONE) {
  608. 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");
  609. auto_tie_breaker = ATB_NONE;
  610. }
  611. LEAVE();
  612. }
  613. static int check_qdevice_master(void)
  614. {
  615. struct cluster_node *node = NULL;
  616. struct qb_list_head *tmp;
  617. int found = 0;
  618. ENTER();
  619. qb_list_for_each(tmp, &cluster_members_list) {
  620. node = qb_list_entry(tmp, struct cluster_node, list);
  621. if ((node->state == NODESTATE_MEMBER) &&
  622. (node->flags & NODE_FLAGS_QDEVICE_MASTER_WINS) &&
  623. (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE)) {
  624. found = 1;
  625. }
  626. }
  627. LEAVE();
  628. return found;
  629. }
  630. static void decode_flags(uint32_t flags)
  631. {
  632. ENTER();
  633. log_printf(LOGSYS_LEVEL_DEBUG,
  634. "flags: quorate: %s Leaving: %s WFA Status: %s First: %s Qdevice: %s QdeviceAlive: %s QdeviceCastVote: %s QdeviceMasterWins: %s",
  635. (flags & NODE_FLAGS_QUORATE)?"Yes":"No",
  636. (flags & NODE_FLAGS_LEAVING)?"Yes":"No",
  637. (flags & NODE_FLAGS_WFASTATUS)?"Yes":"No",
  638. (flags & NODE_FLAGS_FIRST)?"Yes":"No",
  639. (flags & NODE_FLAGS_QDEVICE_REGISTERED)?"Yes":"No",
  640. (flags & NODE_FLAGS_QDEVICE_ALIVE)?"Yes":"No",
  641. (flags & NODE_FLAGS_QDEVICE_CAST_VOTE)?"Yes":"No",
  642. (flags & NODE_FLAGS_QDEVICE_MASTER_WINS)?"Yes":"No");
  643. LEAVE();
  644. }
  645. /*
  646. * load/save are copied almost pristine from totemsrp,c
  647. */
  648. static int load_ev_tracking_barrier(void)
  649. {
  650. int res = 0;
  651. char filename[PATH_MAX];
  652. ENTER();
  653. snprintf(filename, sizeof(filename) - 1, "%s/ev_tracking", get_run_dir());
  654. ev_tracking_fd = open(filename, O_RDWR, 0700);
  655. if (ev_tracking_fd != -1) {
  656. res = read (ev_tracking_fd, &ev_tracking_barrier, sizeof(uint32_t));
  657. close(ev_tracking_fd);
  658. if (res == sizeof (uint32_t)) {
  659. LEAVE();
  660. return 0;
  661. }
  662. }
  663. ev_tracking_barrier = 0;
  664. umask(0);
  665. ev_tracking_fd = open (filename, O_CREAT|O_RDWR, 0700);
  666. if (ev_tracking_fd != -1) {
  667. res = write (ev_tracking_fd, &ev_tracking_barrier, sizeof (uint32_t));
  668. if ((res == -1) || (res != sizeof (uint32_t))) {
  669. log_printf(LOGSYS_LEVEL_WARNING,
  670. "Unable to write to %s", filename);
  671. }
  672. close(ev_tracking_fd);
  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 qb_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. qb_list_for_each(nodelist, &cluster_members_list) {
  761. node = qb_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. highest_expected = max(highest_expected, node->expected_votes);
  766. total_votes += node->votes;
  767. total_nodes++;
  768. }
  769. }
  770. if (us->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  771. log_printf(LOGSYS_LEVEL_DEBUG, "node 0 state=1, votes=%u", qdevice->votes);
  772. total_votes += qdevice->votes;
  773. total_nodes++;
  774. }
  775. if (max_expected > 0) {
  776. highest_expected = max_expected;
  777. }
  778. /*
  779. * This quorum calculation is taken from the OpenVMS Cluster Systems
  780. * manual, but, then, you guessed that didn't you
  781. */
  782. q1 = (highest_expected + 2) / 2;
  783. q2 = (total_votes + 2) / 2;
  784. newquorum = max(q1, q2);
  785. /*
  786. * Normally quorum never decreases but the system administrator can
  787. * force it down by setting expected votes to a maximum value
  788. */
  789. if (!allow_decrease) {
  790. newquorum = max(quorum, newquorum);
  791. }
  792. /*
  793. * The special two_node mode allows each of the two nodes to retain
  794. * quorum if the other fails. Only one of the two should live past
  795. * fencing (as both nodes try to fence each other in split-brain.)
  796. * Also: if there are more than two nodes, force us inquorate to avoid
  797. * any damage or confusion.
  798. */
  799. if (two_node && total_nodes <= 2) {
  800. newquorum = 1;
  801. }
  802. if (ret_total_votes) {
  803. *ret_total_votes = total_votes;
  804. }
  805. LEAVE();
  806. return newquorum;
  807. }
  808. static void update_node_expected_votes(int new_expected_votes)
  809. {
  810. struct qb_list_head *nodelist;
  811. struct cluster_node *node;
  812. if (new_expected_votes) {
  813. qb_list_for_each(nodelist, &cluster_members_list) {
  814. node = qb_list_entry(nodelist, struct cluster_node, list);
  815. if (node->state == NODESTATE_MEMBER) {
  816. node->expected_votes = new_expected_votes;
  817. }
  818. }
  819. }
  820. }
  821. static void are_we_quorate(unsigned int total_votes)
  822. {
  823. int quorate;
  824. int quorum_change = 0;
  825. ENTER();
  826. /*
  827. * wait for all nodes to show up before granting quorum
  828. */
  829. if ((wait_for_all) && (wait_for_all_status)) {
  830. if (total_votes != us->expected_votes) {
  831. log_printf(LOGSYS_LEVEL_NOTICE,
  832. "Waiting for all cluster members. "
  833. "Current votes: %d expected_votes: %d",
  834. total_votes, us->expected_votes);
  835. cluster_is_quorate = 0;
  836. return;
  837. }
  838. update_wait_for_all_status(0);
  839. }
  840. if (quorum > total_votes) {
  841. quorate = 0;
  842. } else {
  843. quorate = 1;
  844. get_lowest_node_id();
  845. get_highest_node_id();
  846. }
  847. if ((auto_tie_breaker != ATB_NONE) &&
  848. /* Must be a half (or half-1) split */
  849. (total_votes == (us->expected_votes / 2)) &&
  850. /* If the 'other' partition in a split might have quorum then we can't run ATB */
  851. (previous_quorum_members_entries - quorum_members_entries < quorum) &&
  852. (check_auto_tie_breaker() == 1)) {
  853. quorate = 1;
  854. }
  855. if ((qdevice_master_wins) &&
  856. (!quorate) &&
  857. (check_qdevice_master() == 1)) {
  858. log_printf(LOGSYS_LEVEL_DEBUG, "node is quorate as part of master_wins partition");
  859. quorate = 1;
  860. }
  861. if (cluster_is_quorate && !quorate) {
  862. quorum_change = 1;
  863. log_printf(LOGSYS_LEVEL_DEBUG, "quorum lost, blocking activity");
  864. }
  865. if (!cluster_is_quorate && quorate) {
  866. quorum_change = 1;
  867. log_printf(LOGSYS_LEVEL_DEBUG, "quorum regained, resuming activity");
  868. }
  869. cluster_is_quorate = quorate;
  870. if (cluster_is_quorate) {
  871. us->flags |= NODE_FLAGS_QUORATE;
  872. } else {
  873. us->flags &= ~NODE_FLAGS_QUORATE;
  874. }
  875. if (wait_for_all) {
  876. if (quorate) {
  877. update_wait_for_all_status(0);
  878. } else {
  879. update_wait_for_all_status(1);
  880. }
  881. }
  882. if ((quorum_change) &&
  883. (sync_in_progress == 0)) {
  884. quorum_callback(quorum_members, quorum_members_entries,
  885. cluster_is_quorate, &quorum_ringid);
  886. votequorum_exec_send_quorum_notification(NULL, 0L);
  887. }
  888. LEAVE();
  889. }
  890. static void get_total_votes(unsigned int *totalvotes, unsigned int *current_members)
  891. {
  892. unsigned int total_votes = 0;
  893. unsigned int cluster_members = 0;
  894. struct qb_list_head *nodelist;
  895. struct cluster_node *node;
  896. ENTER();
  897. qb_list_for_each(nodelist, &cluster_members_list) {
  898. node = qb_list_entry(nodelist, struct cluster_node, list);
  899. if (node->state == NODESTATE_MEMBER) {
  900. cluster_members++;
  901. total_votes += node->votes;
  902. }
  903. }
  904. if (qdevice->votes) {
  905. total_votes += qdevice->votes;
  906. cluster_members++;
  907. }
  908. *totalvotes = total_votes;
  909. *current_members = cluster_members;
  910. LEAVE();
  911. }
  912. /*
  913. * Recalculate cluster quorum, set quorate and notify changes
  914. */
  915. static void recalculate_quorum(int allow_decrease, int by_current_nodes)
  916. {
  917. unsigned int total_votes = 0;
  918. unsigned int cluster_members = 0;
  919. ENTER();
  920. get_total_votes(&total_votes, &cluster_members);
  921. if (!by_current_nodes) {
  922. cluster_members = 0;
  923. }
  924. /*
  925. * Keep expected_votes at the highest number of votes in the cluster
  926. */
  927. log_printf(LOGSYS_LEVEL_DEBUG, "total_votes=%d, expected_votes=%d", total_votes, us->expected_votes);
  928. if (total_votes > us->expected_votes) {
  929. us->expected_votes = total_votes;
  930. votequorum_exec_send_expectedvotes_notification();
  931. }
  932. if ((ev_tracking) &&
  933. (us->expected_votes > ev_tracking_barrier)) {
  934. update_ev_tracking_barrier(us->expected_votes);
  935. }
  936. quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
  937. update_node_expected_votes(cluster_members);
  938. are_we_quorate(total_votes);
  939. LEAVE();
  940. }
  941. /*
  942. * configuration bits and pieces
  943. */
  944. static int votequorum_read_nodelist_configuration(uint32_t *votes,
  945. uint32_t *nodes,
  946. uint32_t *expected_votes)
  947. {
  948. icmap_iter_t iter;
  949. const char *iter_key;
  950. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  951. uint32_t our_pos, node_pos;
  952. uint32_t nodecount = 0;
  953. uint32_t nodelist_expected_votes = 0;
  954. uint32_t node_votes = 0;
  955. int res = 0;
  956. ENTER();
  957. if (icmap_get_uint32("nodelist.local_node_pos", &our_pos) != CS_OK) {
  958. log_printf(LOGSYS_LEVEL_DEBUG,
  959. "No nodelist defined or our node is not in the nodelist");
  960. return 0;
  961. }
  962. iter = icmap_iter_init("nodelist.node.");
  963. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  964. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  965. if (res != 2) {
  966. continue;
  967. }
  968. if (strcmp(tmp_key, "ring0_addr") != 0) {
  969. continue;
  970. }
  971. nodecount++;
  972. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.quorum_votes", node_pos);
  973. if (icmap_get_uint32(tmp_key, &node_votes) != CS_OK) {
  974. node_votes = 1;
  975. }
  976. nodelist_expected_votes = nodelist_expected_votes + node_votes;
  977. if (node_pos == our_pos) {
  978. *votes = node_votes;
  979. }
  980. }
  981. *expected_votes = nodelist_expected_votes;
  982. *nodes = nodecount;
  983. icmap_iter_finalize(iter);
  984. LEAVE();
  985. return 1;
  986. }
  987. static int votequorum_qdevice_is_configured(uint32_t *qdevice_votes)
  988. {
  989. char *qdevice_model = NULL;
  990. int ret = 0;
  991. ENTER();
  992. if (icmap_get_string("quorum.device.model", &qdevice_model) == CS_OK) {
  993. if (strlen(qdevice_model)) {
  994. if (icmap_get_uint32("quorum.device.votes", qdevice_votes) != CS_OK) {
  995. *qdevice_votes = -1;
  996. }
  997. if (icmap_get_uint32("quorum.device.timeout", &qdevice_timeout) != CS_OK) {
  998. qdevice_timeout = VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT;
  999. }
  1000. if (icmap_get_uint32("quorum.device.sync_timeout", &qdevice_sync_timeout) != CS_OK) {
  1001. qdevice_sync_timeout = VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT;
  1002. }
  1003. update_qdevice_can_operate(1);
  1004. ret = 1;
  1005. }
  1006. free(qdevice_model);
  1007. }
  1008. LEAVE();
  1009. return ret;
  1010. }
  1011. #define VOTEQUORUM_READCONFIG_STARTUP 0
  1012. #define VOTEQUORUM_READCONFIG_RUNTIME 1
  1013. static char *votequorum_readconfig(int runtime)
  1014. {
  1015. uint32_t node_votes = 0, qdevice_votes = 0;
  1016. uint32_t node_expected_votes = 0, expected_votes = 0;
  1017. uint32_t node_count = 0;
  1018. uint8_t atb = 0;
  1019. int have_nodelist, have_qdevice;
  1020. char *atb_string = NULL;
  1021. char *error = NULL;
  1022. ENTER();
  1023. log_printf(LOGSYS_LEVEL_DEBUG, "Reading configuration (runtime: %d)", runtime);
  1024. /*
  1025. * Set the few things we re-read at runtime back to their defaults
  1026. */
  1027. if (runtime) {
  1028. two_node = 0;
  1029. expected_votes = 0;
  1030. }
  1031. /*
  1032. * gather basic data here
  1033. */
  1034. icmap_get_uint32("quorum.expected_votes", &expected_votes);
  1035. have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
  1036. have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
  1037. icmap_get_uint8("quorum.two_node", &two_node);
  1038. /*
  1039. * do config verification and enablement
  1040. */
  1041. if ((!have_nodelist) && (!expected_votes)) {
  1042. if (!runtime) {
  1043. error = (char *)"configuration error: nodelist or quorum.expected_votes must be configured!";
  1044. } else {
  1045. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: nodelist or quorum.expected_votes must be configured!");
  1046. log_printf(LOGSYS_LEVEL_CRIT, "will continue with current runtime data");
  1047. }
  1048. goto out;
  1049. }
  1050. /*
  1051. * two_node and qdevice are not compatible in the same config.
  1052. * try to make an educated guess of what to do
  1053. */
  1054. if ((two_node) && (have_qdevice)) {
  1055. if (!runtime) {
  1056. error = (char *)"configuration error: two_node and quorum device cannot be configured at the same time!";
  1057. goto out;
  1058. } else {
  1059. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: two_node and quorum device cannot be configured at the same time!");
  1060. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1061. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is registered, disabling two_node");
  1062. two_node = 0;
  1063. } else {
  1064. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is not registered, allowing two_node");
  1065. update_qdevice_can_operate(0);
  1066. }
  1067. }
  1068. }
  1069. /*
  1070. * Enable special features
  1071. */
  1072. if (!runtime) {
  1073. if (two_node) {
  1074. wait_for_all = 1;
  1075. }
  1076. icmap_get_uint8("quorum.allow_downscale", &allow_downscale);
  1077. icmap_get_uint8("quorum.wait_for_all", &wait_for_all);
  1078. icmap_get_uint8("quorum.last_man_standing", &last_man_standing);
  1079. icmap_get_uint32("quorum.last_man_standing_window", &last_man_standing_window);
  1080. icmap_get_uint8("quorum.expected_votes_tracking", &ev_tracking);
  1081. icmap_get_uint8("quorum.auto_tie_breaker", &atb);
  1082. icmap_get_string("quorum.auto_tie_breaker_node", &atb_string);
  1083. /* auto_tie_breaker defaults to LOWEST */
  1084. if (atb) {
  1085. auto_tie_breaker = ATB_LOWEST;
  1086. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  1087. }
  1088. else {
  1089. auto_tie_breaker = ATB_NONE;
  1090. if (atb_string) {
  1091. log_printf(LOGSYS_LEVEL_WARNING,
  1092. "auto_tie_breaker_node: is meaningless if auto_tie_breaker is set to 0");
  1093. }
  1094. }
  1095. if (atb && atb_string) {
  1096. parse_atb_string(atb_string);
  1097. }
  1098. free(atb_string);
  1099. /* allow_downscale requires ev_tracking */
  1100. if (allow_downscale) {
  1101. ev_tracking = 1;
  1102. }
  1103. if (ev_tracking) {
  1104. if (load_ev_tracking_barrier() < 0) {
  1105. LEAVE();
  1106. return ((char *)"Unable to load ev_tracking file!");
  1107. }
  1108. update_ev_tracking_barrier(ev_tracking_barrier);
  1109. }
  1110. }
  1111. /* two_node and auto_tie_breaker are not compatible as two_node uses
  1112. * a fence race to decide quorum whereas ATB decides based on node id
  1113. */
  1114. if (two_node && auto_tie_breaker != ATB_NONE) {
  1115. log_printf(LOGSYS_LEVEL_CRIT, "two_node and auto_tie_breaker are both specified but are not compatible.");
  1116. log_printf(LOGSYS_LEVEL_CRIT, "two_node has been disabled, please fix your corosync.conf");
  1117. two_node = 0;
  1118. }
  1119. /* If ATB is set and the cluster has an odd number of nodes then wait_for_all needs
  1120. * to be set so that an isolated half+1 without the tie breaker node
  1121. * does not have quorum on reboot.
  1122. */
  1123. if ((auto_tie_breaker != ATB_NONE) && (node_expected_votes % 2) &&
  1124. (!wait_for_all)) {
  1125. if (last_man_standing) {
  1126. /* if LMS is set too, it's a fatal configuration error. We can't dictate to the user what
  1127. * they might want so we'll just quit.
  1128. */
  1129. log_printf(LOGSYS_LEVEL_CRIT, "auto_tie_breaker is set, the cluster has an odd number of nodes\n");
  1130. log_printf(LOGSYS_LEVEL_CRIT, "and last_man_standing is also set. With this situation a better\n");
  1131. log_printf(LOGSYS_LEVEL_CRIT, "solution would be to disable LMS, leave ATB enabled, and also\n");
  1132. log_printf(LOGSYS_LEVEL_CRIT, "enable wait_for_all (mandatory for ATB in odd-numbered clusters).\n");
  1133. log_printf(LOGSYS_LEVEL_CRIT, "Due to this ambiguity, corosync will fail to start. Please fix your corosync.conf\n");
  1134. error = (char *)"configuration error: auto_tie_breaker & last_man_standing not available in odd sized cluster";
  1135. goto out;
  1136. }
  1137. else {
  1138. log_printf(LOGSYS_LEVEL_CRIT, "auto_tie_breaker is set and the cluster has an odd number of nodes.\n");
  1139. log_printf(LOGSYS_LEVEL_CRIT, "wait_for_all needs to be set for this configuration but it is missing\n");
  1140. log_printf(LOGSYS_LEVEL_CRIT, "Therefore auto_tie_breaker has been disabled. Please fix your corosync.conf\n");
  1141. auto_tie_breaker = ATB_NONE;
  1142. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  1143. }
  1144. }
  1145. /*
  1146. * quorum device is not compatible with last_man_standing and auto_tie_breaker
  1147. * neither lms or atb can be set at runtime, so there is no need to check for
  1148. * runtime incompatibilities, but qdevice can be configured _after_ LMS and ATB have
  1149. * been enabled at startup.
  1150. */
  1151. if ((have_qdevice) && (last_man_standing)) {
  1152. if (!runtime) {
  1153. error = (char *)"configuration error: quorum.device is not compatible with last_man_standing";
  1154. goto out;
  1155. } else {
  1156. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with last_man_standing");
  1157. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1158. update_qdevice_can_operate(0);
  1159. }
  1160. }
  1161. if ((have_qdevice) && (auto_tie_breaker != ATB_NONE)) {
  1162. if (!runtime) {
  1163. error = (char *)"configuration error: quorum.device is not compatible with auto_tie_breaker";
  1164. goto out;
  1165. } else {
  1166. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with auto_tie_breaker");
  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 qb_list_head *tmp;
  1429. struct cluster_node *node;
  1430. int i = 0;
  1431. int cluster_members = 0;
  1432. int size;
  1433. char buf[sizeof(struct res_lib_votequorum_quorum_notification) + sizeof(struct votequorum_node) * (PROCESSOR_COUNT_MAX + 2)];
  1434. ENTER();
  1435. log_printf(LOGSYS_LEVEL_DEBUG, "Sending quorum callback, quorate = %d", cluster_is_quorate);
  1436. qb_list_for_each(tmp, &cluster_members_list) {
  1437. node = qb_list_entry(tmp, struct cluster_node, list);
  1438. cluster_members++;
  1439. }
  1440. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1441. cluster_members++;
  1442. }
  1443. size = sizeof(struct res_lib_votequorum_quorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  1444. res_lib_votequorum_notification = (struct res_lib_votequorum_quorum_notification *)&buf;
  1445. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  1446. res_lib_votequorum_notification->context = context;
  1447. res_lib_votequorum_notification->node_list_entries = cluster_members;
  1448. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_QUORUM_NOTIFICATION;
  1449. res_lib_votequorum_notification->header.size = size;
  1450. res_lib_votequorum_notification->header.error = CS_OK;
  1451. /* Send all known nodes and their states */
  1452. qb_list_for_each(tmp, &cluster_members_list) {
  1453. node = qb_list_entry(tmp, struct cluster_node, list);
  1454. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  1455. res_lib_votequorum_notification->node_list[i++].state = node->state;
  1456. }
  1457. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1458. res_lib_votequorum_notification->node_list[i].nodeid = VOTEQUORUM_QDEVICE_NODEID;
  1459. res_lib_votequorum_notification->node_list[i++].state = qdevice->state;
  1460. }
  1461. /* Send it to all interested parties */
  1462. if (conn) {
  1463. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1464. LEAVE();
  1465. return ret;
  1466. } else {
  1467. struct quorum_pd *qpd;
  1468. qb_list_for_each(tmp, &trackers_list) {
  1469. qpd = qb_list_entry(tmp, struct quorum_pd, list);
  1470. res_lib_votequorum_notification->context = qpd->tracking_context;
  1471. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1472. }
  1473. }
  1474. LEAVE();
  1475. return 0;
  1476. }
  1477. static int votequorum_exec_send_nodelist_notification(void *conn, uint64_t context)
  1478. {
  1479. struct res_lib_votequorum_nodelist_notification *res_lib_votequorum_notification;
  1480. int i = 0;
  1481. int size;
  1482. struct qb_list_head *tmp;
  1483. char buf[sizeof(struct res_lib_votequorum_nodelist_notification) + sizeof(uint32_t) * quorum_members_entries];
  1484. ENTER();
  1485. log_printf(LOGSYS_LEVEL_DEBUG, "Sending nodelist callback. ring_id = %d/%lld", quorum_ringid.rep.nodeid, quorum_ringid.seq);
  1486. size = sizeof(struct res_lib_votequorum_nodelist_notification) + sizeof(uint32_t) * quorum_members_entries;
  1487. res_lib_votequorum_notification = (struct res_lib_votequorum_nodelist_notification *)&buf;
  1488. res_lib_votequorum_notification->node_list_entries = quorum_members_entries;
  1489. res_lib_votequorum_notification->ring_id.nodeid = quorum_ringid.rep.nodeid;
  1490. res_lib_votequorum_notification->ring_id.seq = quorum_ringid.seq;
  1491. res_lib_votequorum_notification->context = context;
  1492. for (i=0; i<quorum_members_entries; i++) {
  1493. res_lib_votequorum_notification->node_list[i] = quorum_members[i];
  1494. }
  1495. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NODELIST_NOTIFICATION;
  1496. res_lib_votequorum_notification->header.size = size;
  1497. res_lib_votequorum_notification->header.error = CS_OK;
  1498. /* Send it to all interested parties */
  1499. if (conn) {
  1500. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1501. LEAVE();
  1502. return ret;
  1503. } else {
  1504. struct quorum_pd *qpd;
  1505. qb_list_for_each(tmp, &trackers_list) {
  1506. qpd = qb_list_entry(tmp, struct quorum_pd, list);
  1507. res_lib_votequorum_notification->context = qpd->tracking_context;
  1508. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1509. }
  1510. }
  1511. LEAVE();
  1512. return 0;
  1513. }
  1514. static void votequorum_exec_send_expectedvotes_notification(void)
  1515. {
  1516. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  1517. struct quorum_pd *qpd;
  1518. struct qb_list_head *tmp;
  1519. ENTER();
  1520. log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback");
  1521. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  1522. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  1523. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  1524. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  1525. qb_list_for_each(tmp, &trackers_list) {
  1526. qpd = qb_list_entry(tmp, struct quorum_pd, list);
  1527. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  1528. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  1529. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  1530. }
  1531. LEAVE();
  1532. }
  1533. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message)
  1534. {
  1535. ENTER();
  1536. LEAVE();
  1537. }
  1538. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  1539. const void *message,
  1540. unsigned int nodeid)
  1541. {
  1542. const struct req_exec_quorum_qdevice_reconfigure *req_exec_quorum_qdevice_reconfigure = message;
  1543. ENTER();
  1544. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice name change req from node %u [from: %s to: %s]",
  1545. nodeid,
  1546. req_exec_quorum_qdevice_reconfigure->oldname,
  1547. req_exec_quorum_qdevice_reconfigure->newname);
  1548. if (!strcmp(req_exec_quorum_qdevice_reconfigure->oldname, qdevice_name)) {
  1549. log_printf(LOGSYS_LEVEL_DEBUG, "Allowing qdevice rename");
  1550. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1551. strcpy(qdevice_name, req_exec_quorum_qdevice_reconfigure->newname);
  1552. /*
  1553. * TODO: notify qdevices about name change?
  1554. * this is not relevant for now and can wait later on since
  1555. * qdevices are local only and libvotequorum is not final
  1556. */
  1557. }
  1558. LEAVE();
  1559. }
  1560. static void exec_votequorum_qdevice_reg_endian_convert (void *message)
  1561. {
  1562. struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1563. ENTER();
  1564. req_exec_quorum_qdevice_reg->operation = swab32(req_exec_quorum_qdevice_reg->operation);
  1565. LEAVE();
  1566. }
  1567. static void message_handler_req_exec_votequorum_qdevice_reg (
  1568. const void *message,
  1569. unsigned int nodeid)
  1570. {
  1571. const struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1572. struct res_lib_votequorum_status res_lib_votequorum_status;
  1573. int wipe_qdevice_name = 1;
  1574. struct cluster_node *node = NULL;
  1575. struct qb_list_head *tmp;
  1576. cs_error_t error = CS_OK;
  1577. ENTER();
  1578. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice op %u req from node %u [%s]",
  1579. req_exec_quorum_qdevice_reg->operation,
  1580. nodeid, req_exec_quorum_qdevice_reg->qdevice_name);
  1581. switch(req_exec_quorum_qdevice_reg->operation)
  1582. {
  1583. case VOTEQUORUM_QDEVICE_OPERATION_REGISTER:
  1584. if (nodeid != us->node_id) {
  1585. if (!strlen(qdevice_name)) {
  1586. log_printf(LOGSYS_LEVEL_DEBUG, "Remote qdevice name recorded");
  1587. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1588. }
  1589. LEAVE();
  1590. return;
  1591. }
  1592. /*
  1593. * protect against the case where we broadcast qdevice registration
  1594. * to new memebers, we receive the message back, but there is no registration
  1595. * connection in progress
  1596. */
  1597. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1598. LEAVE();
  1599. return;
  1600. }
  1601. /*
  1602. * this should NEVER happen
  1603. */
  1604. if (!qdevice_reg_conn) {
  1605. log_printf(LOGSYS_LEVEL_WARNING, "Unable to determine origin of the qdevice register call!");
  1606. LEAVE();
  1607. return;
  1608. }
  1609. /*
  1610. * registering our own device in this case
  1611. */
  1612. if (!strlen(qdevice_name)) {
  1613. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1614. }
  1615. /*
  1616. * check if it is our device or something else
  1617. */
  1618. if ((!strncmp(req_exec_quorum_qdevice_reg->qdevice_name,
  1619. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  1620. us->flags |= NODE_FLAGS_QDEVICE_REGISTERED;
  1621. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1622. votequorum_exec_send_nodeinfo(us->node_id);
  1623. } else {
  1624. log_printf(LOGSYS_LEVEL_WARNING,
  1625. "A new qdevice with different name (new: %s old: %s) is trying to register!",
  1626. req_exec_quorum_qdevice_reg->qdevice_name, qdevice_name);
  1627. error = CS_ERR_EXIST;
  1628. }
  1629. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1630. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1631. res_lib_votequorum_status.header.error = error;
  1632. corosync_api->ipc_response_send(qdevice_reg_conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1633. qdevice_reg_conn = NULL;
  1634. break;
  1635. case VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER:
  1636. qb_list_for_each(tmp, &cluster_members_list) {
  1637. node = qb_list_entry(tmp, struct cluster_node, list);
  1638. if ((node->state == NODESTATE_MEMBER) &&
  1639. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1640. wipe_qdevice_name = 0;
  1641. }
  1642. }
  1643. if (wipe_qdevice_name) {
  1644. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1645. }
  1646. break;
  1647. }
  1648. LEAVE();
  1649. }
  1650. static void exec_votequorum_nodeinfo_endian_convert (void *message)
  1651. {
  1652. struct req_exec_quorum_nodeinfo *nodeinfo = message;
  1653. ENTER();
  1654. nodeinfo->nodeid = swab32(nodeinfo->nodeid);
  1655. nodeinfo->votes = swab32(nodeinfo->votes);
  1656. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  1657. nodeinfo->flags = swab32(nodeinfo->flags);
  1658. LEAVE();
  1659. }
  1660. static void message_handler_req_exec_votequorum_nodeinfo (
  1661. const void *message,
  1662. unsigned int sender_nodeid)
  1663. {
  1664. const struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = message;
  1665. struct cluster_node *node = NULL;
  1666. int old_votes;
  1667. int old_expected;
  1668. uint32_t old_flags;
  1669. nodestate_t old_state;
  1670. int new_node = 0;
  1671. int allow_downgrade = 0;
  1672. int by_node = 0;
  1673. unsigned int nodeid = req_exec_quorum_nodeinfo->nodeid;
  1674. ENTER();
  1675. log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %u", sender_nodeid);
  1676. log_printf(LOGSYS_LEVEL_DEBUG, "nodeinfo message[%u]: votes: %d, expected: %d flags: %d",
  1677. nodeid,
  1678. req_exec_quorum_nodeinfo->votes,
  1679. req_exec_quorum_nodeinfo->expected_votes,
  1680. req_exec_quorum_nodeinfo->flags);
  1681. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  1682. decode_flags(req_exec_quorum_nodeinfo->flags);
  1683. }
  1684. node = find_node_by_nodeid(nodeid);
  1685. if (!node) {
  1686. node = allocate_node(nodeid);
  1687. new_node = 1;
  1688. }
  1689. if (!node) {
  1690. corosync_api->error_memory_failure();
  1691. LEAVE();
  1692. return;
  1693. }
  1694. if (new_node) {
  1695. old_votes = 0;
  1696. old_expected = 0;
  1697. old_state = NODESTATE_DEAD;
  1698. old_flags = 0;
  1699. } else {
  1700. old_votes = node->votes;
  1701. old_expected = node->expected_votes;
  1702. old_state = node->state;
  1703. old_flags = node->flags;
  1704. }
  1705. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  1706. struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
  1707. assert(sender_node != NULL);
  1708. if ((!cluster_is_quorate) &&
  1709. (sender_node->flags & NODE_FLAGS_QUORATE)) {
  1710. node->votes = req_exec_quorum_nodeinfo->votes;
  1711. } else {
  1712. node->votes = max(node->votes, req_exec_quorum_nodeinfo->votes);
  1713. }
  1714. goto recalculate;
  1715. }
  1716. /* Update node state */
  1717. node->flags = req_exec_quorum_nodeinfo->flags;
  1718. node->votes = req_exec_quorum_nodeinfo->votes;
  1719. node->state = NODESTATE_MEMBER;
  1720. if (node->flags & NODE_FLAGS_LEAVING) {
  1721. node->state = NODESTATE_LEAVING;
  1722. allow_downgrade = 1;
  1723. by_node = 1;
  1724. }
  1725. if ((!cluster_is_quorate) &&
  1726. (node->flags & NODE_FLAGS_QUORATE)) {
  1727. allow_downgrade = 1;
  1728. us->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1729. }
  1730. if (node->flags & NODE_FLAGS_QUORATE || (ev_tracking)) {
  1731. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1732. } else {
  1733. node->expected_votes = us->expected_votes;
  1734. }
  1735. if ((last_man_standing) && (node->votes > 1)) {
  1736. log_printf(LOGSYS_LEVEL_WARNING, "Last Man Standing feature is supported only when all"
  1737. "cluster nodes votes are set to 1. Disabling LMS.");
  1738. last_man_standing = 0;
  1739. if (last_man_standing_timer_set) {
  1740. corosync_api->timer_delete(last_man_standing_timer);
  1741. last_man_standing_timer_set = 0;
  1742. }
  1743. }
  1744. recalculate:
  1745. if ((new_node) ||
  1746. (nodeid == us->node_id) ||
  1747. (node->flags & NODE_FLAGS_FIRST) ||
  1748. (old_votes != node->votes) ||
  1749. (old_expected != node->expected_votes) ||
  1750. (old_flags != node->flags) ||
  1751. (old_state != node->state)) {
  1752. recalculate_quorum(allow_downgrade, by_node);
  1753. }
  1754. if ((wait_for_all) &&
  1755. (!(node->flags & NODE_FLAGS_WFASTATUS)) &&
  1756. (node->flags & NODE_FLAGS_QUORATE)) {
  1757. update_wait_for_all_status(0);
  1758. }
  1759. LEAVE();
  1760. }
  1761. static void exec_votequorum_reconfigure_endian_convert (void *message)
  1762. {
  1763. struct req_exec_quorum_reconfigure *reconfigure = message;
  1764. ENTER();
  1765. reconfigure->nodeid = swab32(reconfigure->nodeid);
  1766. reconfigure->value = swab32(reconfigure->value);
  1767. LEAVE();
  1768. }
  1769. static void message_handler_req_exec_votequorum_reconfigure (
  1770. const void *message,
  1771. unsigned int nodeid)
  1772. {
  1773. const struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = message;
  1774. struct cluster_node *node;
  1775. ENTER();
  1776. log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %u for %u",
  1777. nodeid, req_exec_quorum_reconfigure->nodeid);
  1778. switch(req_exec_quorum_reconfigure->param)
  1779. {
  1780. case VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES:
  1781. update_node_expected_votes(req_exec_quorum_reconfigure->value);
  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. qb_list_init(&cluster_members_list);
  1842. qb_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. qb_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. qb_list_del (&quorum_pd->list);
  2039. qb_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 qb_list_head *nodelist;
  2084. qb_list_for_each(nodelist, &cluster_members_list) {
  2085. iternode = qb_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. update_node_expected_votes(req_lib_votequorum_setexpected->expected_votes);
  2182. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES, us->node_id,
  2183. req_lib_votequorum_setexpected->expected_votes);
  2184. error_exit:
  2185. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2186. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2187. res_lib_votequorum_status.header.error = error;
  2188. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2189. LEAVE();
  2190. }
  2191. static void message_handler_req_lib_votequorum_setvotes (void *conn, const void *message)
  2192. {
  2193. const struct req_lib_votequorum_setvotes *req_lib_votequorum_setvotes = message;
  2194. struct res_lib_votequorum_status res_lib_votequorum_status;
  2195. struct cluster_node *node;
  2196. unsigned int newquorum;
  2197. unsigned int total_votes;
  2198. unsigned int saved_votes;
  2199. cs_error_t error = CS_OK;
  2200. unsigned int nodeid;
  2201. ENTER();
  2202. nodeid = req_lib_votequorum_setvotes->nodeid;
  2203. node = find_node_by_nodeid(nodeid);
  2204. if (!node) {
  2205. error = CS_ERR_NAME_NOT_FOUND;
  2206. goto error_exit;
  2207. }
  2208. /*
  2209. * Check votes is valid
  2210. */
  2211. saved_votes = node->votes;
  2212. node->votes = req_lib_votequorum_setvotes->votes;
  2213. newquorum = calculate_quorum(1, 0, &total_votes);
  2214. if (newquorum < total_votes / 2 ||
  2215. newquorum > total_votes) {
  2216. node->votes = saved_votes;
  2217. error = CS_ERR_INVALID_PARAM;
  2218. goto error_exit;
  2219. }
  2220. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES, nodeid,
  2221. req_lib_votequorum_setvotes->votes);
  2222. error_exit:
  2223. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2224. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2225. res_lib_votequorum_status.header.error = error;
  2226. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2227. LEAVE();
  2228. }
  2229. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  2230. const void *message)
  2231. {
  2232. const struct req_lib_votequorum_trackstart *req_lib_votequorum_trackstart = message;
  2233. struct res_lib_votequorum_status res_lib_votequorum_status;
  2234. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2235. cs_error_t error = CS_OK;
  2236. ENTER();
  2237. /*
  2238. * If an immediate listing of the current cluster membership
  2239. * is requested, generate membership list
  2240. */
  2241. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
  2242. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
  2243. log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p", conn);
  2244. votequorum_exec_send_nodelist_notification(conn, req_lib_votequorum_trackstart->context);
  2245. votequorum_exec_send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
  2246. }
  2247. if (quorum_pd->tracking_enabled) {
  2248. error = CS_ERR_EXIST;
  2249. goto response_send;
  2250. }
  2251. /*
  2252. * Record requests for tracking
  2253. */
  2254. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES ||
  2255. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
  2256. quorum_pd->track_flags = req_lib_votequorum_trackstart->track_flags;
  2257. quorum_pd->tracking_enabled = 1;
  2258. quorum_pd->tracking_context = req_lib_votequorum_trackstart->context;
  2259. qb_list_add (&quorum_pd->list, &trackers_list);
  2260. }
  2261. response_send:
  2262. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2263. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2264. res_lib_votequorum_status.header.error = error;
  2265. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2266. LEAVE();
  2267. }
  2268. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  2269. const void *message)
  2270. {
  2271. struct res_lib_votequorum_status res_lib_votequorum_status;
  2272. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2273. int error = CS_OK;
  2274. ENTER();
  2275. if (quorum_pd->tracking_enabled) {
  2276. error = CS_OK;
  2277. quorum_pd->tracking_enabled = 0;
  2278. qb_list_del (&quorum_pd->list);
  2279. qb_list_init (&quorum_pd->list);
  2280. } else {
  2281. error = CS_ERR_NOT_EXIST;
  2282. }
  2283. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2284. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2285. res_lib_votequorum_status.header.error = error;
  2286. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2287. LEAVE();
  2288. }
  2289. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  2290. const void *message)
  2291. {
  2292. const struct req_lib_votequorum_qdevice_register *req_lib_votequorum_qdevice_register = message;
  2293. struct res_lib_votequorum_status res_lib_votequorum_status;
  2294. cs_error_t error = CS_OK;
  2295. ENTER();
  2296. if (!qdevice_can_operate) {
  2297. log_printf(LOGSYS_LEVEL_INFO, "Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
  2298. error = CS_ERR_ACCESS;
  2299. goto out;
  2300. }
  2301. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2302. if ((!strncmp(req_lib_votequorum_qdevice_register->name,
  2303. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  2304. goto out;
  2305. } else {
  2306. log_printf(LOGSYS_LEVEL_WARNING,
  2307. "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
  2308. req_lib_votequorum_qdevice_register->name, qdevice_name);
  2309. error = CS_ERR_EXIST;
  2310. goto out;
  2311. }
  2312. } else {
  2313. if (qdevice_reg_conn != NULL) {
  2314. log_printf(LOGSYS_LEVEL_WARNING,
  2315. "Registration request already in progress");
  2316. error = CS_ERR_TRY_AGAIN;
  2317. goto out;
  2318. }
  2319. qdevice_reg_conn = conn;
  2320. if (votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  2321. req_lib_votequorum_qdevice_register->name) != 0) {
  2322. log_printf(LOGSYS_LEVEL_WARNING,
  2323. "Unable to send qdevice registration request to cluster");
  2324. error = CS_ERR_TRY_AGAIN;
  2325. qdevice_reg_conn = NULL;
  2326. } else {
  2327. LEAVE();
  2328. return;
  2329. }
  2330. }
  2331. out:
  2332. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2333. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2334. res_lib_votequorum_status.header.error = error;
  2335. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2336. LEAVE();
  2337. }
  2338. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  2339. const void *message)
  2340. {
  2341. const struct req_lib_votequorum_qdevice_unregister *req_lib_votequorum_qdevice_unregister = message;
  2342. struct res_lib_votequorum_status res_lib_votequorum_status;
  2343. cs_error_t error = CS_OK;
  2344. ENTER();
  2345. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2346. if (strncmp(req_lib_votequorum_qdevice_unregister->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2347. error = CS_ERR_INVALID_PARAM;
  2348. goto out;
  2349. }
  2350. if (qdevice_timer_set) {
  2351. corosync_api->timer_delete(qdevice_timer);
  2352. qdevice_timer_set = 0;
  2353. sync_wait_for_poll_or_timeout = 0;
  2354. }
  2355. us->flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
  2356. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  2357. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2358. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2359. votequorum_exec_send_nodeinfo(us->node_id);
  2360. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER,
  2361. req_lib_votequorum_qdevice_unregister->name);
  2362. } else {
  2363. error = CS_ERR_NOT_EXIST;
  2364. }
  2365. out:
  2366. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2367. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2368. res_lib_votequorum_status.header.error = error;
  2369. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2370. LEAVE();
  2371. }
  2372. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  2373. const void *message)
  2374. {
  2375. const struct req_lib_votequorum_qdevice_update *req_lib_votequorum_qdevice_update = message;
  2376. struct res_lib_votequorum_status res_lib_votequorum_status;
  2377. cs_error_t error = CS_OK;
  2378. ENTER();
  2379. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2380. if (strncmp(req_lib_votequorum_qdevice_update->oldname, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2381. error = CS_ERR_INVALID_PARAM;
  2382. goto out;
  2383. }
  2384. votequorum_exec_send_qdevice_reconfigure(req_lib_votequorum_qdevice_update->oldname,
  2385. req_lib_votequorum_qdevice_update->newname);
  2386. } else {
  2387. error = CS_ERR_NOT_EXIST;
  2388. }
  2389. out:
  2390. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2391. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2392. res_lib_votequorum_status.header.error = error;
  2393. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2394. LEAVE();
  2395. }
  2396. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  2397. const void *message)
  2398. {
  2399. const struct req_lib_votequorum_qdevice_poll *req_lib_votequorum_qdevice_poll = message;
  2400. struct res_lib_votequorum_status res_lib_votequorum_status;
  2401. cs_error_t error = CS_OK;
  2402. uint32_t oldflags;
  2403. ENTER();
  2404. if (!qdevice_can_operate) {
  2405. error = CS_ERR_ACCESS;
  2406. goto out;
  2407. }
  2408. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2409. if (!(req_lib_votequorum_qdevice_poll->ring_id.nodeid == quorum_ringid.rep.nodeid &&
  2410. req_lib_votequorum_qdevice_poll->ring_id.seq == quorum_ringid.seq)) {
  2411. log_printf(LOGSYS_LEVEL_DEBUG, "Received poll ring id (%u.%"PRIu64") != last sync "
  2412. "ring id (%u.%"PRIu64"). Ignoring poll call.",
  2413. req_lib_votequorum_qdevice_poll->ring_id.nodeid, req_lib_votequorum_qdevice_poll->ring_id.seq,
  2414. quorum_ringid.rep.nodeid, quorum_ringid.seq);
  2415. error = CS_ERR_MESSAGE_ERROR;
  2416. goto out;
  2417. }
  2418. if (strncmp(req_lib_votequorum_qdevice_poll->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2419. error = CS_ERR_INVALID_PARAM;
  2420. goto out;
  2421. }
  2422. if (qdevice_timer_set) {
  2423. corosync_api->timer_delete(qdevice_timer);
  2424. qdevice_timer_set = 0;
  2425. }
  2426. oldflags = us->flags;
  2427. us->flags |= NODE_FLAGS_QDEVICE_ALIVE;
  2428. if (req_lib_votequorum_qdevice_poll->cast_vote) {
  2429. us->flags |= NODE_FLAGS_QDEVICE_CAST_VOTE;
  2430. } else {
  2431. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2432. }
  2433. if (us->flags != oldflags) {
  2434. votequorum_exec_send_nodeinfo(us->node_id);
  2435. }
  2436. corosync_api->timer_add_duration((unsigned long long)qdevice_timeout*1000000, qdevice,
  2437. qdevice_timer_fn, &qdevice_timer);
  2438. qdevice_timer_set = 1;
  2439. sync_wait_for_poll_or_timeout = 0;
  2440. } else {
  2441. error = CS_ERR_NOT_EXIST;
  2442. }
  2443. out:
  2444. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2445. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2446. res_lib_votequorum_status.header.error = error;
  2447. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2448. LEAVE();
  2449. }
  2450. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  2451. const void *message)
  2452. {
  2453. const struct req_lib_votequorum_qdevice_master_wins *req_lib_votequorum_qdevice_master_wins = message;
  2454. struct res_lib_votequorum_status res_lib_votequorum_status;
  2455. cs_error_t error = CS_OK;
  2456. uint32_t oldflags = us->flags;
  2457. ENTER();
  2458. if (!qdevice_can_operate) {
  2459. error = CS_ERR_ACCESS;
  2460. goto out;
  2461. }
  2462. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2463. if (strncmp(req_lib_votequorum_qdevice_master_wins->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2464. error = CS_ERR_INVALID_PARAM;
  2465. goto out;
  2466. }
  2467. if (req_lib_votequorum_qdevice_master_wins->allow) {
  2468. us->flags |= NODE_FLAGS_QDEVICE_MASTER_WINS;
  2469. } else {
  2470. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2471. }
  2472. if (us->flags != oldflags) {
  2473. votequorum_exec_send_nodeinfo(us->node_id);
  2474. }
  2475. update_qdevice_master_wins(req_lib_votequorum_qdevice_master_wins->allow);
  2476. } else {
  2477. error = CS_ERR_NOT_EXIST;
  2478. }
  2479. out:
  2480. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2481. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2482. res_lib_votequorum_status.header.error = error;
  2483. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2484. LEAVE();
  2485. }