votequorum.c 99 KB

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