votequorum.c 81 KB

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