votequorum.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478
  1. /*
  2. * Copyright (c) 2009-2012 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 <stdint.h>
  38. #include <qb/qbipc_common.h>
  39. #include "quorum.h"
  40. #include <corosync/corodefs.h>
  41. #include <corosync/list.h>
  42. #include <corosync/logsys.h>
  43. #include <corosync/coroapi.h>
  44. #include <corosync/icmap.h>
  45. #include <corosync/ipc_votequorum.h>
  46. #include "service.h"
  47. LOGSYS_DECLARE_SUBSYS ("VOTEQ");
  48. /*
  49. * interface with corosync
  50. */
  51. static struct corosync_api_v1 *corosync_api;
  52. /*
  53. * votequorum global config vars
  54. */
  55. #define DEFAULT_QDEVICE_TIMEOUT 10000
  56. static char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  57. static struct cluster_node *qdevice = NULL;
  58. static unsigned int qdevice_timeout = DEFAULT_QDEVICE_TIMEOUT;
  59. static uint8_t qdevice_can_operate = 1;
  60. static void *qdevice_reg_conn = NULL;
  61. static uint8_t qdevice_master_wins = 0;
  62. static uint8_t two_node = 0;
  63. static uint8_t wait_for_all = 0;
  64. static uint8_t wait_for_all_status = 0;
  65. static uint8_t auto_tie_breaker = 0;
  66. static int lowest_node_id = -1;
  67. #define DEFAULT_LMS_WIN 10000
  68. static uint8_t last_man_standing = 0;
  69. static uint32_t last_man_standing_window = DEFAULT_LMS_WIN;
  70. static uint8_t allow_downscale = 0;
  71. static uint32_t ev_barrier = 0;
  72. /*
  73. * votequorum_exec defines/structs/forward definitions
  74. */
  75. struct req_exec_quorum_nodeinfo {
  76. struct qb_ipc_request_header header __attribute__((aligned(8)));
  77. uint32_t nodeid;
  78. uint32_t votes;
  79. uint32_t expected_votes;
  80. uint32_t flags;
  81. } __attribute__((packed));
  82. struct req_exec_quorum_reconfigure {
  83. struct qb_ipc_request_header header __attribute__((aligned(8)));
  84. uint32_t nodeid;
  85. uint32_t value;
  86. uint8_t param;
  87. uint8_t _pad0;
  88. uint8_t _pad1;
  89. uint8_t _pad2;
  90. } __attribute__((packed));
  91. struct req_exec_quorum_qdevice_reg {
  92. struct qb_ipc_request_header header __attribute__((aligned(8)));
  93. uint32_t operation;
  94. char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  95. } __attribute__((packed));
  96. struct req_exec_quorum_qdevice_reconfigure {
  97. struct qb_ipc_request_header header __attribute__((aligned(8)));
  98. char oldname[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  99. char newname[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  100. } __attribute__((packed));
  101. /*
  102. * votequorum_exec onwire version (via totem)
  103. */
  104. #include "votequorum.h"
  105. /*
  106. * votequorum_exec onwire messages (via totem)
  107. */
  108. #define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO 0
  109. #define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE 1
  110. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG 2
  111. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE 3
  112. static void votequorum_exec_send_expectedvotes_notification(void);
  113. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context);
  114. #define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES 1
  115. #define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES 2
  116. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value);
  117. /*
  118. * used by req_exec_quorum_qdevice_reg
  119. */
  120. #define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER 0
  121. #define VOTEQUORUM_QDEVICE_OPERATION_REGISTER 1
  122. /*
  123. * votequorum internal node status/view
  124. */
  125. #define NODE_FLAGS_QUORATE 1
  126. #define NODE_FLAGS_LEAVING 2
  127. #define NODE_FLAGS_WFASTATUS 4
  128. #define NODE_FLAGS_FIRST 8
  129. #define NODE_FLAGS_QDEVICE_REGISTERED 16
  130. #define NODE_FLAGS_QDEVICE_ALIVE 32
  131. #define NODE_FLAGS_QDEVICE_CAST_VOTE 64
  132. #define NODE_FLAGS_QDEVICE_MASTER_WINS 128
  133. #define NODEID_QDEVICE 0
  134. typedef enum {
  135. NODESTATE_MEMBER=1,
  136. NODESTATE_DEAD,
  137. NODESTATE_LEAVING
  138. } nodestate_t;
  139. struct cluster_node {
  140. int node_id;
  141. nodestate_t state;
  142. uint32_t votes;
  143. uint32_t expected_votes;
  144. uint32_t flags;
  145. struct list_head list;
  146. };
  147. /*
  148. * votequorum internal quorum status
  149. */
  150. static uint8_t quorum;
  151. static uint8_t cluster_is_quorate;
  152. /*
  153. * votequorum membership data
  154. */
  155. static struct cluster_node *us;
  156. static struct list_head cluster_members_list;
  157. static unsigned int quorum_members[PROCESSOR_COUNT_MAX];
  158. static int quorum_members_entries = 0;
  159. static struct memb_ring_id quorum_ringid;
  160. /*
  161. * pre allocate all cluster_nodes + one for qdevice
  162. */
  163. static struct cluster_node cluster_nodes[PROCESSOR_COUNT_MAX+2];
  164. static int cluster_nodes_entries = 0;
  165. /*
  166. * votequorum tracking
  167. */
  168. struct quorum_pd {
  169. unsigned char track_flags;
  170. int tracking_enabled;
  171. uint64_t tracking_context;
  172. struct list_head list;
  173. void *conn;
  174. };
  175. static struct list_head trackers_list;
  176. /*
  177. * votequorum timers
  178. */
  179. static corosync_timer_handle_t qdevice_timer;
  180. static int qdevice_timer_set = 0;
  181. static corosync_timer_handle_t last_man_standing_timer;
  182. static int last_man_standing_timer_set = 0;
  183. /*
  184. * Service Interfaces required by service_message_handler struct
  185. */
  186. static void votequorum_confchg_fn (
  187. enum totem_configuration_type configuration_type,
  188. const unsigned int *member_list, size_t member_list_entries,
  189. const unsigned int *left_list, size_t left_list_entries,
  190. const unsigned int *joined_list, size_t joined_list_entries,
  191. const struct memb_ring_id *ring_id);
  192. static quorum_set_quorate_fn_t quorum_callback;
  193. /*
  194. * votequorum_exec handler and definitions
  195. */
  196. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api);
  197. static int votequorum_exec_exit_fn (void);
  198. static int votequorum_exec_send_nodeinfo(uint32_t nodeid);
  199. static void message_handler_req_exec_votequorum_nodeinfo (
  200. const void *message,
  201. unsigned int nodeid);
  202. static void exec_votequorum_nodeinfo_endian_convert (void *message);
  203. static void message_handler_req_exec_votequorum_reconfigure (
  204. const void *message,
  205. unsigned int nodeid);
  206. static void exec_votequorum_reconfigure_endian_convert (void *message);
  207. static void message_handler_req_exec_votequorum_qdevice_reg (
  208. const void *message,
  209. unsigned int nodeid);
  210. static void exec_votequorum_qdevice_reg_endian_convert (void *message);
  211. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  212. const void *message,
  213. unsigned int nodeid);
  214. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message);
  215. static struct corosync_exec_handler votequorum_exec_engine[] =
  216. {
  217. { /* 0 */
  218. .exec_handler_fn = message_handler_req_exec_votequorum_nodeinfo,
  219. .exec_endian_convert_fn = exec_votequorum_nodeinfo_endian_convert
  220. },
  221. { /* 1 */
  222. .exec_handler_fn = message_handler_req_exec_votequorum_reconfigure,
  223. .exec_endian_convert_fn = exec_votequorum_reconfigure_endian_convert
  224. },
  225. { /* 2 */
  226. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reg,
  227. .exec_endian_convert_fn = exec_votequorum_qdevice_reg_endian_convert
  228. },
  229. { /* 3 */
  230. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reconfigure,
  231. .exec_endian_convert_fn = exec_votequorum_qdevice_reconfigure_endian_convert
  232. },
  233. };
  234. /*
  235. * Library Handler and Functions Definitions
  236. */
  237. static int quorum_lib_init_fn (void *conn);
  238. static int quorum_lib_exit_fn (void *conn);
  239. static void message_handler_req_lib_votequorum_getinfo (void *conn,
  240. const void *message);
  241. static void message_handler_req_lib_votequorum_setexpected (void *conn,
  242. const void *message);
  243. static void message_handler_req_lib_votequorum_setvotes (void *conn,
  244. const void *message);
  245. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  246. const void *message);
  247. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  248. const void *message);
  249. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  250. const void *message);
  251. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  252. const void *message);
  253. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  254. const void *message);
  255. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  256. const void *message);
  257. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  258. const void *message);
  259. static struct corosync_lib_handler quorum_lib_service[] =
  260. {
  261. { /* 0 */
  262. .lib_handler_fn = message_handler_req_lib_votequorum_getinfo,
  263. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  264. },
  265. { /* 1 */
  266. .lib_handler_fn = message_handler_req_lib_votequorum_setexpected,
  267. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  268. },
  269. { /* 2 */
  270. .lib_handler_fn = message_handler_req_lib_votequorum_setvotes,
  271. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  272. },
  273. { /* 3 */
  274. .lib_handler_fn = message_handler_req_lib_votequorum_trackstart,
  275. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  276. },
  277. { /* 4 */
  278. .lib_handler_fn = message_handler_req_lib_votequorum_trackstop,
  279. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  280. },
  281. { /* 5 */
  282. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_register,
  283. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  284. },
  285. { /* 6 */
  286. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_unregister,
  287. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  288. },
  289. { /* 7 */
  290. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_update,
  291. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  292. },
  293. { /* 8 */
  294. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_poll,
  295. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  296. },
  297. { /* 9 */
  298. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_master_wins,
  299. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  300. }
  301. };
  302. static struct corosync_service_engine votequorum_service_engine = {
  303. .name = "corosync vote quorum service v1.0",
  304. .id = VOTEQUORUM_SERVICE,
  305. .priority = 2,
  306. .private_data_size = sizeof (struct quorum_pd),
  307. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  308. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED,
  309. .lib_init_fn = quorum_lib_init_fn,
  310. .lib_exit_fn = quorum_lib_exit_fn,
  311. .lib_engine = quorum_lib_service,
  312. .lib_engine_count = sizeof (quorum_lib_service) / sizeof (struct corosync_lib_handler),
  313. .exec_init_fn = votequorum_exec_init_fn,
  314. .exec_exit_fn = votequorum_exec_exit_fn,
  315. .exec_engine = votequorum_exec_engine,
  316. .exec_engine_count = sizeof (votequorum_exec_engine) / sizeof (struct corosync_exec_handler),
  317. .confchg_fn = votequorum_confchg_fn
  318. };
  319. struct corosync_service_engine *votequorum_get_service_engine_ver0 (void)
  320. {
  321. return (&votequorum_service_engine);
  322. }
  323. static struct default_service votequorum_service[] = {
  324. {
  325. .name = "corosync_votequorum",
  326. .ver = 0,
  327. .loader = votequorum_get_service_engine_ver0
  328. },
  329. };
  330. /*
  331. * common/utility macros/functions
  332. */
  333. #define max(a,b) (((a) > (b)) ? (a) : (b))
  334. #define list_iterate(v, head) \
  335. for (v = (head)->next; v != head; v = v->next)
  336. static void node_add_ordered(struct cluster_node *newnode)
  337. {
  338. struct cluster_node *node = NULL;
  339. struct list_head *tmp;
  340. struct list_head *newlist = &newnode->list;
  341. ENTER();
  342. list_iterate(tmp, &cluster_members_list) {
  343. node = list_entry(tmp, struct cluster_node, list);
  344. if (newnode->node_id < node->node_id) {
  345. break;
  346. }
  347. }
  348. if (!node) {
  349. list_add(&newnode->list, &cluster_members_list);
  350. } else {
  351. newlist->prev = tmp->prev;
  352. newlist->next = tmp;
  353. tmp->prev->next = newlist;
  354. tmp->prev = newlist;
  355. }
  356. LEAVE();
  357. }
  358. static struct cluster_node *allocate_node(unsigned int nodeid)
  359. {
  360. struct cluster_node *cl = NULL;
  361. struct list_head *tmp;
  362. ENTER();
  363. if (cluster_nodes_entries <= PROCESSOR_COUNT_MAX + 1) {
  364. cl = (struct cluster_node *)&cluster_nodes[cluster_nodes_entries];
  365. cluster_nodes_entries++;
  366. } else {
  367. list_iterate(tmp, &cluster_members_list) {
  368. cl = list_entry(tmp, struct cluster_node, list);
  369. if (cl->state == NODESTATE_DEAD) {
  370. break;
  371. }
  372. }
  373. /*
  374. * this should never happen
  375. */
  376. if (!cl) {
  377. log_printf(LOGSYS_LEVEL_CRIT, "Unable to find memory for node %u data!!", nodeid);
  378. goto out;
  379. }
  380. list_del(tmp);
  381. }
  382. memset(cl, 0, sizeof(struct cluster_node));
  383. cl->node_id = nodeid;
  384. if (nodeid != NODEID_QDEVICE) {
  385. node_add_ordered(cl);
  386. }
  387. out:
  388. LEAVE();
  389. return cl;
  390. }
  391. static struct cluster_node *find_node_by_nodeid(unsigned int nodeid)
  392. {
  393. struct cluster_node *node;
  394. struct list_head *tmp;
  395. ENTER();
  396. if (nodeid == us->node_id) {
  397. LEAVE();
  398. return us;
  399. }
  400. if (nodeid == NODEID_QDEVICE) {
  401. LEAVE();
  402. return qdevice;
  403. }
  404. list_iterate(tmp, &cluster_members_list) {
  405. node = list_entry(tmp, struct cluster_node, list);
  406. if (node->node_id == nodeid) {
  407. LEAVE();
  408. return node;
  409. }
  410. }
  411. LEAVE();
  412. return NULL;
  413. }
  414. static void get_lowest_node_id(void)
  415. {
  416. struct cluster_node *node = NULL;
  417. struct list_head *tmp;
  418. ENTER();
  419. lowest_node_id = us->node_id;
  420. list_iterate(tmp, &cluster_members_list) {
  421. node = list_entry(tmp, struct cluster_node, list);
  422. if ((node->state == NODESTATE_MEMBER) &&
  423. (node->node_id < lowest_node_id)) {
  424. lowest_node_id = node->node_id;
  425. }
  426. }
  427. log_printf(LOGSYS_LEVEL_DEBUG, "lowest node id: %d us: %d", lowest_node_id, us->node_id);
  428. icmap_set_uint32("runtime.votequorum.lowest_node_id", lowest_node_id);
  429. LEAVE();
  430. }
  431. static int check_low_node_id_partition(void)
  432. {
  433. struct cluster_node *node = NULL;
  434. struct list_head *tmp;
  435. int found = 0;
  436. ENTER();
  437. list_iterate(tmp, &cluster_members_list) {
  438. node = list_entry(tmp, struct cluster_node, list);
  439. if ((node->state == NODESTATE_MEMBER) &&
  440. (node->node_id == lowest_node_id)) {
  441. found = 1;
  442. }
  443. }
  444. LEAVE();
  445. return found;
  446. }
  447. static int check_qdevice_master(void)
  448. {
  449. struct cluster_node *node = NULL;
  450. struct list_head *tmp;
  451. int found = 0;
  452. ENTER();
  453. list_iterate(tmp, &cluster_members_list) {
  454. node = list_entry(tmp, struct cluster_node, list);
  455. if ((node->state == NODESTATE_MEMBER) &&
  456. (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE)) {
  457. found = 1;
  458. }
  459. }
  460. LEAVE();
  461. return found;
  462. }
  463. static void decode_flags(uint32_t flags)
  464. {
  465. ENTER();
  466. log_printf(LOGSYS_LEVEL_DEBUG,
  467. "flags: quorate: %s Leaving: %s WFA Status: %s First: %s Qdevice: %s QdeviceAlive: %s QdeviceCastVote: %s QdeviceMasterWins: %s",
  468. (flags & NODE_FLAGS_QUORATE)?"Yes":"No",
  469. (flags & NODE_FLAGS_LEAVING)?"Yes":"No",
  470. (flags & NODE_FLAGS_WFASTATUS)?"Yes":"No",
  471. (flags & NODE_FLAGS_FIRST)?"Yes":"No",
  472. (flags & NODE_FLAGS_QDEVICE_REGISTERED)?"Yes":"No",
  473. (flags & NODE_FLAGS_QDEVICE_ALIVE)?"Yes":"No",
  474. (flags & NODE_FLAGS_QDEVICE_CAST_VOTE)?"Yes":"No",
  475. (flags & NODE_FLAGS_QDEVICE_MASTER_WINS)?"Yes":"No");
  476. LEAVE();
  477. }
  478. static void update_wait_for_all_status(uint8_t wfa_status)
  479. {
  480. ENTER();
  481. wait_for_all_status = wfa_status;
  482. if (wait_for_all_status) {
  483. us->flags |= NODE_FLAGS_WFASTATUS;
  484. } else {
  485. us->flags &= ~NODE_FLAGS_WFASTATUS;
  486. }
  487. icmap_set_uint8("runtime.votequorum.wait_for_all_status",
  488. wait_for_all_status);
  489. LEAVE();
  490. }
  491. static void update_two_node(void)
  492. {
  493. ENTER();
  494. icmap_set_uint8("runtime.votequorum.two_node", two_node);
  495. LEAVE();
  496. }
  497. static void update_ev_barrier(uint32_t expected_votes)
  498. {
  499. ENTER();
  500. ev_barrier = expected_votes;
  501. icmap_set_uint32("runtime.votequorum.ev_barrier", ev_barrier);
  502. LEAVE();
  503. }
  504. static void update_qdevice_can_operate(uint8_t status)
  505. {
  506. ENTER();
  507. qdevice_can_operate = status;
  508. icmap_set_uint8("runtime.votequorum.qdevice_can_operate", qdevice_can_operate);
  509. LEAVE();
  510. }
  511. static void update_qdevice_master_wins(uint8_t allow)
  512. {
  513. ENTER();
  514. qdevice_master_wins = allow;
  515. icmap_set_uint8("runtime.votequorum.qdevice_master_wins", qdevice_master_wins);
  516. LEAVE();
  517. }
  518. /*
  519. * quorum calculation core bits
  520. */
  521. static int calculate_quorum(int allow_decrease, unsigned int max_expected, unsigned int *ret_total_votes)
  522. {
  523. struct list_head *nodelist;
  524. struct cluster_node *node;
  525. unsigned int total_votes = 0;
  526. unsigned int highest_expected = 0;
  527. unsigned int newquorum, q1, q2;
  528. unsigned int total_nodes = 0;
  529. ENTER();
  530. if ((allow_downscale) && (allow_decrease) && (max_expected)) {
  531. max_expected = max(ev_barrier, max_expected);
  532. }
  533. list_iterate(nodelist, &cluster_members_list) {
  534. node = list_entry(nodelist, struct cluster_node, list);
  535. log_printf(LOGSYS_LEVEL_DEBUG, "node %u state=%d, votes=%u, expected=%u",
  536. node->node_id, node->state, node->votes, node->expected_votes);
  537. if (node->state == NODESTATE_MEMBER) {
  538. if (max_expected) {
  539. node->expected_votes = max_expected;
  540. } else {
  541. highest_expected = max(highest_expected, node->expected_votes);
  542. }
  543. total_votes += node->votes;
  544. total_nodes++;
  545. }
  546. }
  547. if (us->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  548. log_printf(LOGSYS_LEVEL_DEBUG, "node 0 state=1, votes=%u", qdevice->votes);
  549. total_votes += qdevice->votes;
  550. total_nodes++;
  551. }
  552. if (max_expected > 0) {
  553. highest_expected = max_expected;
  554. }
  555. /*
  556. * This quorum calculation is taken from the OpenVMS Cluster Systems
  557. * manual, but, then, you guessed that didn't you
  558. */
  559. q1 = (highest_expected + 2) / 2;
  560. q2 = (total_votes + 2) / 2;
  561. newquorum = max(q1, q2);
  562. /*
  563. * Normally quorum never decreases but the system administrator can
  564. * force it down by setting expected votes to a maximum value
  565. */
  566. if (!allow_decrease) {
  567. newquorum = max(quorum, newquorum);
  568. }
  569. /*
  570. * The special two_node mode allows each of the two nodes to retain
  571. * quorum if the other fails. Only one of the two should live past
  572. * fencing (as both nodes try to fence each other in split-brain.)
  573. * Also: if there are more than two nodes, force us inquorate to avoid
  574. * any damage or confusion.
  575. */
  576. if (two_node && total_nodes <= 2) {
  577. newquorum = 1;
  578. }
  579. if (ret_total_votes) {
  580. *ret_total_votes = total_votes;
  581. }
  582. LEAVE();
  583. return newquorum;
  584. }
  585. static void are_we_quorate(unsigned int total_votes)
  586. {
  587. int quorate;
  588. int quorum_change = 0;
  589. ENTER();
  590. /*
  591. * wait for all nodes to show up before granting quorum
  592. */
  593. if ((wait_for_all) && (wait_for_all_status)) {
  594. if (total_votes != us->expected_votes) {
  595. log_printf(LOGSYS_LEVEL_NOTICE,
  596. "Waiting for all cluster members. "
  597. "Current votes: %d expected_votes: %d",
  598. total_votes, us->expected_votes);
  599. cluster_is_quorate = 0;
  600. return;
  601. }
  602. update_wait_for_all_status(0);
  603. }
  604. if (quorum > total_votes) {
  605. quorate = 0;
  606. } else {
  607. quorate = 1;
  608. get_lowest_node_id();
  609. }
  610. if ((auto_tie_breaker) &&
  611. (total_votes == (us->expected_votes / 2)) &&
  612. (check_low_node_id_partition() == 1)) {
  613. quorate = 1;
  614. }
  615. if ((qdevice_master_wins) &&
  616. (!quorate) &&
  617. (check_qdevice_master() == 1)) {
  618. log_printf(LOGSYS_LEVEL_DEBUG, "node is quorate as part of master_wins partition");
  619. quorate = 1;
  620. }
  621. if (cluster_is_quorate && !quorate) {
  622. quorum_change = 1;
  623. log_printf(LOGSYS_LEVEL_DEBUG, "quorum lost, blocking activity");
  624. }
  625. if (!cluster_is_quorate && quorate) {
  626. quorum_change = 1;
  627. log_printf(LOGSYS_LEVEL_DEBUG, "quorum regained, resuming activity");
  628. }
  629. cluster_is_quorate = quorate;
  630. if (cluster_is_quorate) {
  631. us->flags |= NODE_FLAGS_QUORATE;
  632. } else {
  633. us->flags &= ~NODE_FLAGS_QUORATE;
  634. }
  635. if (wait_for_all) {
  636. if (quorate) {
  637. update_wait_for_all_status(0);
  638. } else {
  639. update_wait_for_all_status(1);
  640. }
  641. }
  642. if (quorum_change) {
  643. quorum_callback(quorum_members, quorum_members_entries,
  644. cluster_is_quorate, &quorum_ringid);
  645. }
  646. LEAVE();
  647. }
  648. static void get_total_votes(unsigned int *totalvotes, unsigned int *current_members)
  649. {
  650. unsigned int total_votes = 0;
  651. unsigned int cluster_members = 0;
  652. struct list_head *nodelist;
  653. struct cluster_node *node;
  654. ENTER();
  655. list_iterate(nodelist, &cluster_members_list) {
  656. node = list_entry(nodelist, struct cluster_node, list);
  657. if (node->state == NODESTATE_MEMBER) {
  658. cluster_members++;
  659. total_votes += node->votes;
  660. }
  661. }
  662. if (qdevice->votes) {
  663. total_votes += qdevice->votes;
  664. cluster_members++;
  665. }
  666. *totalvotes = total_votes;
  667. *current_members = cluster_members;
  668. LEAVE();
  669. }
  670. /*
  671. * Recalculate cluster quorum, set quorate and notify changes
  672. */
  673. static void recalculate_quorum(int allow_decrease, int by_current_nodes)
  674. {
  675. unsigned int total_votes = 0;
  676. unsigned int cluster_members = 0;
  677. ENTER();
  678. get_total_votes(&total_votes, &cluster_members);
  679. if (!by_current_nodes) {
  680. cluster_members = 0;
  681. }
  682. /*
  683. * Keep expected_votes at the highest number of votes in the cluster
  684. */
  685. log_printf(LOGSYS_LEVEL_DEBUG, "total_votes=%d, expected_votes=%d", total_votes, us->expected_votes);
  686. if (total_votes > us->expected_votes) {
  687. us->expected_votes = total_votes;
  688. votequorum_exec_send_expectedvotes_notification();
  689. }
  690. quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
  691. are_we_quorate(total_votes);
  692. votequorum_exec_send_quorum_notification(NULL, 0L);
  693. LEAVE();
  694. }
  695. /*
  696. * configuration bits and pieces
  697. */
  698. static int votequorum_read_nodelist_configuration(uint32_t *votes,
  699. uint32_t *nodes,
  700. uint32_t *expected_votes)
  701. {
  702. icmap_iter_t iter;
  703. const char *iter_key;
  704. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  705. uint32_t our_pos, node_pos;
  706. uint32_t nodecount = 0;
  707. uint32_t nodelist_expected_votes = 0;
  708. uint32_t node_votes = 0;
  709. int res = 0;
  710. ENTER();
  711. if (icmap_get_uint32("nodelist.local_node_pos", &our_pos) != CS_OK) {
  712. log_printf(LOGSYS_LEVEL_DEBUG,
  713. "No nodelist defined or our node is not in the nodelist");
  714. return 0;
  715. }
  716. iter = icmap_iter_init("nodelist.node.");
  717. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  718. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  719. if (res != 2) {
  720. continue;
  721. }
  722. if (strcmp(tmp_key, "ring0_addr") != 0) {
  723. continue;
  724. }
  725. nodecount++;
  726. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.quorum_votes", node_pos);
  727. if (icmap_get_uint32(tmp_key, &node_votes) != CS_OK) {
  728. node_votes = 1;
  729. }
  730. nodelist_expected_votes = nodelist_expected_votes + node_votes;
  731. if (node_pos == our_pos) {
  732. *votes = node_votes;
  733. }
  734. }
  735. *expected_votes = nodelist_expected_votes;
  736. *nodes = nodecount;
  737. icmap_iter_finalize(iter);
  738. LEAVE();
  739. return 1;
  740. }
  741. static int votequorum_qdevice_is_configured(uint32_t *qdevice_votes)
  742. {
  743. char *qdevice_model = NULL;
  744. ENTER();
  745. if ((icmap_get_string("quorum.device.model", &qdevice_model) == CS_OK) &&
  746. (strlen(qdevice_model))) {
  747. free(qdevice_model);
  748. if (icmap_get_uint32("quorum.device.votes", qdevice_votes) != CS_OK) {
  749. *qdevice_votes = -1;
  750. }
  751. if (icmap_get_uint32("quorum.device.timeout", &qdevice_timeout) != CS_OK) {
  752. qdevice_timeout = DEFAULT_QDEVICE_TIMEOUT;
  753. }
  754. update_qdevice_can_operate(1);
  755. return 1;
  756. }
  757. LEAVE();
  758. return 0;
  759. }
  760. #define VOTEQUORUM_READCONFIG_STARTUP 0
  761. #define VOTEQUORUM_READCONFIG_RUNTIME 1
  762. static char *votequorum_readconfig(int runtime)
  763. {
  764. uint32_t node_votes = 0, qdevice_votes = 0;
  765. uint32_t node_expected_votes = 0, expected_votes = 0;
  766. uint32_t node_count = 0;
  767. int have_nodelist, have_qdevice;
  768. char *error = NULL;
  769. ENTER();
  770. log_printf(LOGSYS_LEVEL_DEBUG, "Reading configuration (runtime: %d)", runtime);
  771. /*
  772. * gather basic data here
  773. */
  774. icmap_get_uint32("quorum.expected_votes", &expected_votes);
  775. have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
  776. have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
  777. icmap_get_uint8("quorum.two_node", &two_node);
  778. /*
  779. * do config verification and enablement
  780. */
  781. if ((!have_nodelist) && (!expected_votes)) {
  782. if (!runtime) {
  783. error = (char *)"configuration error: nodelist or quorum.expected_votes must be configured!";
  784. } else {
  785. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: nodelist or quorum.expected_votes must be configured!");
  786. log_printf(LOGSYS_LEVEL_CRIT, "will continue with current runtime data");
  787. }
  788. goto out;
  789. }
  790. /*
  791. * two_node and qdevice are not compatible in the same config.
  792. * try to make an educated guess of what to do
  793. */
  794. if ((two_node) && (have_qdevice)) {
  795. if (!runtime) {
  796. error = (char *)"configuration error: two_node and quorum device cannot be configured at the same time!";
  797. goto out;
  798. } else {
  799. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: two_node and quorum device cannot be configured at the same time!");
  800. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  801. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is registered, disabling two_node");
  802. two_node = 0;
  803. } else {
  804. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is not registered, allowing two_node");
  805. update_qdevice_can_operate(0);
  806. }
  807. }
  808. }
  809. /*
  810. * Enable special features
  811. */
  812. if (!runtime) {
  813. if (two_node) {
  814. wait_for_all = 1;
  815. }
  816. icmap_get_uint8("quorum.allow_downscale", &allow_downscale);
  817. icmap_get_uint8("quorum.wait_for_all", &wait_for_all);
  818. icmap_get_uint8("quorum.auto_tie_breaker", &auto_tie_breaker);
  819. icmap_get_uint8("quorum.last_man_standing", &last_man_standing);
  820. icmap_get_uint32("quorum.last_man_standing_window", &last_man_standing_window);
  821. }
  822. /*
  823. * quorum device is not compatible with last_man_standing and auto_tie_breaker
  824. * neither lms or atb can be set at runtime, so there is no need to check for
  825. * runtime incompatibilities, but qdevice can be configured _after_ LMS and ATB have
  826. * been enabled at startup.
  827. */
  828. if ((have_qdevice) && (last_man_standing)) {
  829. if (!runtime) {
  830. error = (char *)"configuration error: quorum.device is not compatible with last_man_standing";
  831. goto out;
  832. } else {
  833. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with last_man_standing");
  834. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  835. update_qdevice_can_operate(0);
  836. }
  837. }
  838. if ((have_qdevice) && (auto_tie_breaker)) {
  839. if (!runtime) {
  840. error = (char *)"configuration error: quorum.device is not compatible with auto_tie_breaker";
  841. goto out;
  842. } else {
  843. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with auto_tie_breaker");
  844. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  845. update_qdevice_can_operate(0);
  846. }
  847. }
  848. if ((have_qdevice) && (wait_for_all)) {
  849. if (!runtime) {
  850. error = (char *)"configuration error: quorum.device is not compatible with wait_for_all";
  851. goto out;
  852. } else {
  853. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with wait_for_all");
  854. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  855. update_qdevice_can_operate(0);
  856. }
  857. }
  858. if ((have_qdevice) && (allow_downscale)) {
  859. if (!runtime) {
  860. error = (char *)"configuration error: quorum.device is not compatible with allow_downscale";
  861. goto out;
  862. } else {
  863. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with allow_downscale");
  864. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  865. update_qdevice_can_operate(0);
  866. }
  867. }
  868. /*
  869. * if user specifies quorum.expected_votes + quorum.device but NOT the device.votes
  870. * we don't know what the quorum device should vote.
  871. */
  872. if ((expected_votes) && (have_qdevice) && (qdevice_votes == -1)) {
  873. if (!runtime) {
  874. error = (char *)"configuration error: quorum.device.votes must be specified when quorum.expected_votes is set";
  875. goto out;
  876. } else {
  877. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when quorum.expected_votes is set");
  878. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  879. update_qdevice_can_operate(0);
  880. }
  881. }
  882. /*
  883. * if user specifies a node list with uneven votes and no device.votes
  884. * we cannot autocalculate the votes
  885. */
  886. if ((have_qdevice) &&
  887. (qdevice_votes == -1) &&
  888. (have_nodelist) &&
  889. (node_count != node_expected_votes)) {
  890. if (!runtime) {
  891. error = (char *)"configuration error: quorum.device.votes must be specified when not all nodes votes 1";
  892. goto out;
  893. } else {
  894. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when not all nodes votes 1");
  895. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  896. update_qdevice_can_operate(0);
  897. }
  898. }
  899. /*
  900. * validate quorum device votes vs expected_votes
  901. */
  902. if ((qdevice_votes > 0) && (expected_votes)) {
  903. int delta = expected_votes - qdevice_votes;
  904. if (delta < 2) {
  905. if (!runtime) {
  906. error = (char *)"configuration error: quorum.device.votes is too high or expected_votes is too low";
  907. goto out;
  908. } else {
  909. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes is too high or expected_votes is too low");
  910. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  911. update_qdevice_can_operate(0);
  912. }
  913. }
  914. }
  915. /*
  916. * automatically calculate device votes and adjust expected_votes from nodelist
  917. */
  918. if ((have_qdevice) &&
  919. (qdevice_votes == -1) &&
  920. (!expected_votes) &&
  921. (have_nodelist) &&
  922. (node_count == node_expected_votes)) {
  923. qdevice_votes = node_expected_votes - 1;
  924. node_expected_votes = node_expected_votes + qdevice_votes;
  925. }
  926. /*
  927. * set this node votes and expected_votes
  928. */
  929. if (have_nodelist) {
  930. us->votes = node_votes;
  931. us->expected_votes = node_expected_votes;
  932. } else {
  933. us->votes = 1;
  934. icmap_get_uint32("quorum.votes", &us->votes);
  935. }
  936. if (expected_votes) {
  937. us->expected_votes = expected_votes;
  938. }
  939. /*
  940. * set qdevice votes
  941. */
  942. if (!have_qdevice) {
  943. qdevice->votes = 0;
  944. }
  945. if (qdevice_votes != -1) {
  946. qdevice->votes = qdevice_votes;
  947. }
  948. update_ev_barrier(us->expected_votes);
  949. update_two_node();
  950. if (wait_for_all) {
  951. update_wait_for_all_status(1);
  952. }
  953. out:
  954. LEAVE();
  955. return error;
  956. }
  957. static void votequorum_refresh_config(
  958. int32_t event,
  959. const char *key_name,
  960. struct icmap_notify_value new_val,
  961. struct icmap_notify_value old_val,
  962. void *user_data)
  963. {
  964. ENTER();
  965. /*
  966. * Reload the configuration
  967. */
  968. votequorum_readconfig(VOTEQUORUM_READCONFIG_RUNTIME);
  969. /*
  970. * activate new config
  971. */
  972. votequorum_exec_send_nodeinfo(us->node_id);
  973. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  974. LEAVE();
  975. }
  976. static void votequorum_exec_add_config_notification(void)
  977. {
  978. icmap_track_t icmap_track_nodelist = NULL;
  979. icmap_track_t icmap_track_quorum = NULL;
  980. ENTER();
  981. icmap_track_add("nodelist.",
  982. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  983. votequorum_refresh_config,
  984. NULL,
  985. &icmap_track_nodelist);
  986. icmap_track_add("quorum.",
  987. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  988. votequorum_refresh_config,
  989. NULL,
  990. &icmap_track_quorum);
  991. LEAVE();
  992. }
  993. /*
  994. * votequorum_exec core
  995. */
  996. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value)
  997. {
  998. struct req_exec_quorum_reconfigure req_exec_quorum_reconfigure;
  999. struct iovec iov[1];
  1000. int ret;
  1001. ENTER();
  1002. req_exec_quorum_reconfigure.nodeid = nodeid;
  1003. req_exec_quorum_reconfigure.value = value;
  1004. req_exec_quorum_reconfigure.param = param;
  1005. req_exec_quorum_reconfigure._pad0 = 0;
  1006. req_exec_quorum_reconfigure._pad1 = 0;
  1007. req_exec_quorum_reconfigure._pad2 = 0;
  1008. req_exec_quorum_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE);
  1009. req_exec_quorum_reconfigure.header.size = sizeof(req_exec_quorum_reconfigure);
  1010. iov[0].iov_base = (void *)&req_exec_quorum_reconfigure;
  1011. iov[0].iov_len = sizeof(req_exec_quorum_reconfigure);
  1012. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1013. LEAVE();
  1014. return ret;
  1015. }
  1016. static int votequorum_exec_send_nodeinfo(uint32_t nodeid)
  1017. {
  1018. struct req_exec_quorum_nodeinfo req_exec_quorum_nodeinfo;
  1019. struct iovec iov[1];
  1020. struct cluster_node *node;
  1021. int ret;
  1022. ENTER();
  1023. node = find_node_by_nodeid(nodeid);
  1024. if (!node) {
  1025. return -1;
  1026. }
  1027. req_exec_quorum_nodeinfo.nodeid = nodeid;
  1028. req_exec_quorum_nodeinfo.votes = node->votes;
  1029. req_exec_quorum_nodeinfo.expected_votes = node->expected_votes;
  1030. req_exec_quorum_nodeinfo.flags = node->flags;
  1031. if (nodeid != NODEID_QDEVICE) {
  1032. decode_flags(node->flags);
  1033. }
  1034. req_exec_quorum_nodeinfo.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO);
  1035. req_exec_quorum_nodeinfo.header.size = sizeof(req_exec_quorum_nodeinfo);
  1036. iov[0].iov_base = (void *)&req_exec_quorum_nodeinfo;
  1037. iov[0].iov_len = sizeof(req_exec_quorum_nodeinfo);
  1038. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1039. LEAVE();
  1040. return ret;
  1041. }
  1042. static int votequorum_exec_send_qdevice_reconfigure(const char *oldname, const char *newname)
  1043. {
  1044. struct req_exec_quorum_qdevice_reconfigure req_exec_quorum_qdevice_reconfigure;
  1045. struct iovec iov[1];
  1046. int ret;
  1047. ENTER();
  1048. req_exec_quorum_qdevice_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE);
  1049. req_exec_quorum_qdevice_reconfigure.header.size = sizeof(req_exec_quorum_qdevice_reconfigure);
  1050. strcpy(req_exec_quorum_qdevice_reconfigure.oldname, oldname);
  1051. strcpy(req_exec_quorum_qdevice_reconfigure.newname, newname);
  1052. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reconfigure;
  1053. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reconfigure);
  1054. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1055. LEAVE();
  1056. return ret;
  1057. }
  1058. static int votequorum_exec_send_qdevice_reg(uint32_t operation, const char *qdevice_name_req)
  1059. {
  1060. struct req_exec_quorum_qdevice_reg req_exec_quorum_qdevice_reg;
  1061. struct iovec iov[1];
  1062. int ret;
  1063. ENTER();
  1064. req_exec_quorum_qdevice_reg.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG);
  1065. req_exec_quorum_qdevice_reg.header.size = sizeof(req_exec_quorum_qdevice_reg);
  1066. req_exec_quorum_qdevice_reg.operation = operation;
  1067. strcpy(req_exec_quorum_qdevice_reg.qdevice_name, qdevice_name_req);
  1068. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reg;
  1069. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reg);
  1070. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1071. LEAVE();
  1072. return ret;
  1073. }
  1074. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context)
  1075. {
  1076. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  1077. struct list_head *tmp;
  1078. struct cluster_node *node;
  1079. int cluster_members = 0;
  1080. int i = 0;
  1081. int size;
  1082. char buf[sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * (PROCESSOR_COUNT_MAX + 2)];
  1083. ENTER();
  1084. list_iterate(tmp, &cluster_members_list) {
  1085. node = list_entry(tmp, struct cluster_node, list);
  1086. cluster_members++;
  1087. }
  1088. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1089. cluster_members++;
  1090. }
  1091. size = sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  1092. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)&buf;
  1093. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  1094. res_lib_votequorum_notification->node_list_entries = cluster_members;
  1095. res_lib_votequorum_notification->context = context;
  1096. list_iterate(tmp, &cluster_members_list) {
  1097. node = list_entry(tmp, struct cluster_node, list);
  1098. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  1099. res_lib_votequorum_notification->node_list[i++].state = node->state;
  1100. }
  1101. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1102. res_lib_votequorum_notification->node_list[i].nodeid = NODEID_QDEVICE;
  1103. res_lib_votequorum_notification->node_list[i++].state = qdevice->state;
  1104. }
  1105. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NOTIFICATION;
  1106. res_lib_votequorum_notification->header.size = size;
  1107. res_lib_votequorum_notification->header.error = CS_OK;
  1108. /* Send it to all interested parties */
  1109. if (conn) {
  1110. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1111. LEAVE();
  1112. return ret;
  1113. } else {
  1114. struct quorum_pd *qpd;
  1115. list_iterate(tmp, &trackers_list) {
  1116. qpd = list_entry(tmp, struct quorum_pd, list);
  1117. res_lib_votequorum_notification->context = qpd->tracking_context;
  1118. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1119. }
  1120. }
  1121. LEAVE();
  1122. return 0;
  1123. }
  1124. static void votequorum_exec_send_expectedvotes_notification(void)
  1125. {
  1126. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  1127. struct quorum_pd *qpd;
  1128. struct list_head *tmp;
  1129. ENTER();
  1130. log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback");
  1131. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  1132. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  1133. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  1134. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  1135. list_iterate(tmp, &trackers_list) {
  1136. qpd = list_entry(tmp, struct quorum_pd, list);
  1137. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  1138. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  1139. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  1140. }
  1141. LEAVE();
  1142. }
  1143. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message)
  1144. {
  1145. ENTER();
  1146. LEAVE();
  1147. }
  1148. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  1149. const void *message,
  1150. unsigned int nodeid)
  1151. {
  1152. const struct req_exec_quorum_qdevice_reconfigure *req_exec_quorum_qdevice_reconfigure = message;
  1153. ENTER();
  1154. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice name change req from node %u [from: %s to: %s]",
  1155. nodeid,
  1156. req_exec_quorum_qdevice_reconfigure->oldname,
  1157. req_exec_quorum_qdevice_reconfigure->newname);
  1158. if (!strcmp(req_exec_quorum_qdevice_reconfigure->oldname, qdevice_name)) {
  1159. log_printf(LOGSYS_LEVEL_DEBUG, "Allowing qdevice rename");
  1160. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1161. strcpy(qdevice_name, req_exec_quorum_qdevice_reconfigure->newname);
  1162. /*
  1163. * TODO: notify qdevices about name change?
  1164. * this is not relevant for now and can wait later on since
  1165. * qdevices are local only and libvotequorum is not final
  1166. */
  1167. }
  1168. LEAVE();
  1169. }
  1170. static void exec_votequorum_qdevice_reg_endian_convert (void *message)
  1171. {
  1172. struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1173. ENTER();
  1174. req_exec_quorum_qdevice_reg->operation = swab32(req_exec_quorum_qdevice_reg->operation);
  1175. LEAVE();
  1176. }
  1177. static void message_handler_req_exec_votequorum_qdevice_reg (
  1178. const void *message,
  1179. unsigned int nodeid)
  1180. {
  1181. const struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1182. struct res_lib_votequorum_status res_lib_votequorum_status;
  1183. int wipe_qdevice_name = 1;
  1184. struct cluster_node *node = NULL;
  1185. struct list_head *tmp;
  1186. cs_error_t error = CS_OK;
  1187. ENTER();
  1188. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice op %u req from node %u [%s]",
  1189. req_exec_quorum_qdevice_reg->operation,
  1190. nodeid, req_exec_quorum_qdevice_reg->qdevice_name);
  1191. switch(req_exec_quorum_qdevice_reg->operation)
  1192. {
  1193. case VOTEQUORUM_QDEVICE_OPERATION_REGISTER:
  1194. if (nodeid != us->node_id) {
  1195. if (!strlen(qdevice_name)) {
  1196. log_printf(LOGSYS_LEVEL_DEBUG, "Remote qdevice name recorded");
  1197. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1198. }
  1199. LEAVE();
  1200. return;
  1201. }
  1202. /*
  1203. * protect against the case where we broadcast qdevice registration
  1204. * to new memebers, we receive the message back, but there is no registration
  1205. * connection in progress
  1206. */
  1207. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1208. LEAVE();
  1209. }
  1210. /*
  1211. * this should NEVER happen
  1212. */
  1213. if (!qdevice_reg_conn) {
  1214. log_printf(LOGSYS_LEVEL_WARNING, "Unable to determine origin of the qdevice register call!");
  1215. LEAVE();
  1216. return;
  1217. }
  1218. /*
  1219. * registering our own device in this case
  1220. */
  1221. if (!strlen(qdevice_name)) {
  1222. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1223. }
  1224. /*
  1225. * check if it is our device or something else
  1226. */
  1227. if ((!strncmp(req_exec_quorum_qdevice_reg->qdevice_name,
  1228. qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN))) {
  1229. us->flags |= NODE_FLAGS_QDEVICE_REGISTERED;
  1230. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  1231. votequorum_exec_send_nodeinfo(us->node_id);
  1232. } else {
  1233. log_printf(LOGSYS_LEVEL_WARNING,
  1234. "A new qdevice with different name (new: %s old: %s) is trying to register!",
  1235. req_exec_quorum_qdevice_reg->qdevice_name, qdevice_name);
  1236. error = CS_ERR_EXIST;
  1237. }
  1238. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1239. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1240. res_lib_votequorum_status.header.error = error;
  1241. corosync_api->ipc_response_send(qdevice_reg_conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1242. qdevice_reg_conn = NULL;
  1243. break;
  1244. case VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER:
  1245. list_iterate(tmp, &cluster_members_list) {
  1246. node = list_entry(tmp, struct cluster_node, list);
  1247. if ((node->state == NODESTATE_MEMBER) &&
  1248. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1249. wipe_qdevice_name = 0;
  1250. }
  1251. }
  1252. if (wipe_qdevice_name) {
  1253. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1254. }
  1255. break;
  1256. }
  1257. LEAVE();
  1258. }
  1259. static void exec_votequorum_nodeinfo_endian_convert (void *message)
  1260. {
  1261. struct req_exec_quorum_nodeinfo *nodeinfo = message;
  1262. ENTER();
  1263. nodeinfo->nodeid = swab32(nodeinfo->nodeid);
  1264. nodeinfo->votes = swab32(nodeinfo->votes);
  1265. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  1266. nodeinfo->flags = swab32(nodeinfo->flags);
  1267. LEAVE();
  1268. }
  1269. static void message_handler_req_exec_votequorum_nodeinfo (
  1270. const void *message,
  1271. unsigned int sender_nodeid)
  1272. {
  1273. const struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = message;
  1274. struct cluster_node *node = NULL;
  1275. int old_votes;
  1276. int old_expected;
  1277. uint32_t old_flags;
  1278. nodestate_t old_state;
  1279. int new_node = 0;
  1280. int allow_downgrade = 0;
  1281. int by_node = 0;
  1282. unsigned int nodeid = req_exec_quorum_nodeinfo->nodeid;
  1283. ENTER();
  1284. log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %u", sender_nodeid);
  1285. log_printf(LOGSYS_LEVEL_DEBUG, "nodeinfo message[%u]: votes: %d, expected: %d flags: %d",
  1286. nodeid,
  1287. req_exec_quorum_nodeinfo->votes,
  1288. req_exec_quorum_nodeinfo->expected_votes,
  1289. req_exec_quorum_nodeinfo->flags);
  1290. if (nodeid != NODEID_QDEVICE) {
  1291. decode_flags(req_exec_quorum_nodeinfo->flags);
  1292. }
  1293. node = find_node_by_nodeid(nodeid);
  1294. if (!node) {
  1295. node = allocate_node(nodeid);
  1296. new_node = 1;
  1297. }
  1298. if (!node) {
  1299. corosync_api->error_memory_failure();
  1300. LEAVE();
  1301. return;
  1302. }
  1303. if (new_node) {
  1304. old_votes = 0;
  1305. old_expected = 0;
  1306. old_state = NODESTATE_DEAD;
  1307. old_flags = 0;
  1308. } else {
  1309. old_votes = node->votes;
  1310. old_expected = node->expected_votes;
  1311. old_state = node->state;
  1312. old_flags = node->flags;
  1313. }
  1314. if (nodeid == NODEID_QDEVICE) {
  1315. struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
  1316. if ((!cluster_is_quorate) &&
  1317. (sender_node->flags & NODE_FLAGS_QUORATE)) {
  1318. node->votes = req_exec_quorum_nodeinfo->votes;
  1319. } else {
  1320. node->votes = max(node->votes, req_exec_quorum_nodeinfo->votes);
  1321. }
  1322. goto recalculate;
  1323. }
  1324. /* Update node state */
  1325. node->flags = req_exec_quorum_nodeinfo->flags;
  1326. node->votes = req_exec_quorum_nodeinfo->votes;
  1327. node->state = NODESTATE_MEMBER;
  1328. if (node->flags & NODE_FLAGS_LEAVING) {
  1329. node->state = NODESTATE_LEAVING;
  1330. allow_downgrade = 1;
  1331. by_node = 1;
  1332. }
  1333. if ((!cluster_is_quorate) &&
  1334. (node->flags & NODE_FLAGS_QUORATE)) {
  1335. allow_downgrade = 1;
  1336. us->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1337. }
  1338. if (node->flags & NODE_FLAGS_QUORATE) {
  1339. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1340. } else {
  1341. node->expected_votes = us->expected_votes;
  1342. }
  1343. if ((last_man_standing) && (node->votes > 1)) {
  1344. log_printf(LOGSYS_LEVEL_WARNING, "Last Man Standing feature is supported only when all"
  1345. "cluster nodes votes are set to 1. Disabling LMS.");
  1346. last_man_standing = 0;
  1347. if (last_man_standing_timer_set) {
  1348. corosync_api->timer_delete(last_man_standing_timer);
  1349. last_man_standing_timer_set = 0;
  1350. }
  1351. }
  1352. recalculate:
  1353. if ((new_node) ||
  1354. (nodeid == us->node_id) ||
  1355. (node->flags & NODE_FLAGS_FIRST) ||
  1356. (old_votes != node->votes) ||
  1357. (old_expected != node->expected_votes) ||
  1358. (old_flags != node->flags) ||
  1359. (old_state != node->state)) {
  1360. recalculate_quorum(allow_downgrade, by_node);
  1361. }
  1362. if ((wait_for_all) &&
  1363. (!(node->flags & NODE_FLAGS_WFASTATUS)) &&
  1364. (node->flags & NODE_FLAGS_QUORATE)) {
  1365. update_wait_for_all_status(0);
  1366. }
  1367. LEAVE();
  1368. }
  1369. static void exec_votequorum_reconfigure_endian_convert (void *message)
  1370. {
  1371. struct req_exec_quorum_reconfigure *reconfigure = message;
  1372. ENTER();
  1373. reconfigure->nodeid = swab32(reconfigure->nodeid);
  1374. reconfigure->value = swab32(reconfigure->value);
  1375. LEAVE();
  1376. }
  1377. static void message_handler_req_exec_votequorum_reconfigure (
  1378. const void *message,
  1379. unsigned int nodeid)
  1380. {
  1381. const struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = message;
  1382. struct cluster_node *node;
  1383. struct list_head *nodelist;
  1384. ENTER();
  1385. log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %u for %u",
  1386. nodeid, req_exec_quorum_reconfigure->nodeid);
  1387. switch(req_exec_quorum_reconfigure->param)
  1388. {
  1389. case VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES:
  1390. list_iterate(nodelist, &cluster_members_list) {
  1391. node = list_entry(nodelist, struct cluster_node, list);
  1392. if (node->state == NODESTATE_MEMBER) {
  1393. node->expected_votes = req_exec_quorum_reconfigure->value;
  1394. }
  1395. }
  1396. votequorum_exec_send_expectedvotes_notification();
  1397. update_ev_barrier(req_exec_quorum_reconfigure->value);
  1398. recalculate_quorum(1, 0); /* Allow decrease */
  1399. break;
  1400. case VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES:
  1401. node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
  1402. if (!node) {
  1403. LEAVE();
  1404. return;
  1405. }
  1406. node->votes = req_exec_quorum_reconfigure->value;
  1407. recalculate_quorum(1, 0); /* Allow decrease */
  1408. break;
  1409. }
  1410. LEAVE();
  1411. }
  1412. static int votequorum_exec_exit_fn (void)
  1413. {
  1414. int ret = 0;
  1415. ENTER();
  1416. /*
  1417. * tell the other nodes we are leaving
  1418. */
  1419. if (allow_downscale) {
  1420. us->flags |= NODE_FLAGS_LEAVING;
  1421. ret = votequorum_exec_send_nodeinfo(us->node_id);
  1422. }
  1423. /*
  1424. * clean up our internals
  1425. */
  1426. /*
  1427. * free the node list and qdevice
  1428. */
  1429. list_init(&cluster_members_list);
  1430. qdevice = NULL;
  1431. us = NULL;
  1432. memset(cluster_nodes, 0, sizeof(cluster_nodes));
  1433. /*
  1434. * clean the tracking list
  1435. */
  1436. list_init(&trackers_list);
  1437. LEAVE();
  1438. return ret;
  1439. }
  1440. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api)
  1441. {
  1442. char *error = NULL;
  1443. #ifdef COROSYNC_SOLARIS
  1444. logsys_subsys_init();
  1445. #endif
  1446. ENTER();
  1447. list_init(&cluster_members_list);
  1448. list_init(&trackers_list);
  1449. /*
  1450. * Allocate a cluster_node for qdevice
  1451. */
  1452. qdevice = allocate_node(NODEID_QDEVICE);
  1453. if (!qdevice) {
  1454. LEAVE();
  1455. return ((char *)"Could not allocate node.");
  1456. }
  1457. qdevice->votes = 0;
  1458. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1459. /*
  1460. * Allocate a cluster_node for us
  1461. */
  1462. us = allocate_node(corosync_api->totem_nodeid_get());
  1463. if (!us) {
  1464. LEAVE();
  1465. return ((char *)"Could not allocate node.");
  1466. }
  1467. icmap_set_uint32("runtime.votequorum.this_node_id", us->node_id);
  1468. us->state = NODESTATE_MEMBER;
  1469. us->votes = 1;
  1470. us->flags |= NODE_FLAGS_FIRST;
  1471. error = votequorum_readconfig(VOTEQUORUM_READCONFIG_STARTUP);
  1472. if (error) {
  1473. return error;
  1474. }
  1475. recalculate_quorum(0, 0);
  1476. /*
  1477. * Listen for changes
  1478. */
  1479. votequorum_exec_add_config_notification();
  1480. /*
  1481. * Start us off with one node
  1482. */
  1483. votequorum_exec_send_nodeinfo(us->node_id);
  1484. LEAVE();
  1485. return (NULL);
  1486. }
  1487. /*
  1488. * votequorum service core
  1489. */
  1490. static void votequorum_last_man_standing_timer_fn(void *arg)
  1491. {
  1492. ENTER();
  1493. last_man_standing_timer_set = 0;
  1494. if (cluster_is_quorate) {
  1495. recalculate_quorum(1,1);
  1496. }
  1497. LEAVE();
  1498. }
  1499. static void votequorum_confchg_fn (
  1500. enum totem_configuration_type configuration_type,
  1501. const unsigned int *member_list, size_t member_list_entries,
  1502. const unsigned int *left_list, size_t left_list_entries,
  1503. const unsigned int *joined_list, size_t joined_list_entries,
  1504. const struct memb_ring_id *ring_id)
  1505. {
  1506. int i;
  1507. struct cluster_node *node;
  1508. ENTER();
  1509. if (member_list_entries > 1) {
  1510. us->flags &= ~NODE_FLAGS_FIRST;
  1511. }
  1512. if (left_list_entries) {
  1513. for (i = 0; i< left_list_entries; i++) {
  1514. node = find_node_by_nodeid(left_list[i]);
  1515. if (node) {
  1516. node->state = NODESTATE_DEAD;
  1517. }
  1518. }
  1519. }
  1520. if (last_man_standing) {
  1521. if (((member_list_entries >= quorum) && (left_list_entries)) ||
  1522. ((member_list_entries <= quorum) && (auto_tie_breaker) && (check_low_node_id_partition() == 1))) {
  1523. if (last_man_standing_timer_set) {
  1524. corosync_api->timer_delete(last_man_standing_timer);
  1525. last_man_standing_timer_set = 0;
  1526. }
  1527. corosync_api->timer_add_duration((unsigned long long)last_man_standing_window*1000000,
  1528. NULL, votequorum_last_man_standing_timer_fn,
  1529. &last_man_standing_timer);
  1530. last_man_standing_timer_set = 1;
  1531. }
  1532. }
  1533. if (member_list_entries) {
  1534. memcpy(quorum_members, member_list, sizeof(unsigned int) * member_list_entries);
  1535. quorum_members_entries = member_list_entries;
  1536. votequorum_exec_send_nodeinfo(us->node_id);
  1537. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  1538. if (strlen(qdevice_name)) {
  1539. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1540. qdevice_name);
  1541. }
  1542. }
  1543. memcpy(&quorum_ringid, ring_id, sizeof(*ring_id));
  1544. if (left_list_entries) {
  1545. recalculate_quorum(0, 0);
  1546. }
  1547. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  1548. quorum_callback(quorum_members, quorum_members_entries,
  1549. cluster_is_quorate, &quorum_ringid);
  1550. }
  1551. LEAVE();
  1552. }
  1553. char *votequorum_init(struct corosync_api_v1 *api,
  1554. quorum_set_quorate_fn_t q_set_quorate_fn)
  1555. {
  1556. char *error;
  1557. ENTER();
  1558. if (q_set_quorate_fn == NULL) {
  1559. return ((char *)"Quorate function not set");
  1560. }
  1561. corosync_api = api;
  1562. quorum_callback = q_set_quorate_fn;
  1563. error = corosync_service_link_and_init(corosync_api,
  1564. &votequorum_service[0]);
  1565. if (error) {
  1566. return (error);
  1567. }
  1568. LEAVE();
  1569. return (NULL);
  1570. }
  1571. /*
  1572. * Library Handler init/fini
  1573. */
  1574. static int quorum_lib_init_fn (void *conn)
  1575. {
  1576. struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1577. ENTER();
  1578. list_init (&pd->list);
  1579. pd->conn = conn;
  1580. LEAVE();
  1581. return (0);
  1582. }
  1583. static int quorum_lib_exit_fn (void *conn)
  1584. {
  1585. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1586. ENTER();
  1587. if (quorum_pd->tracking_enabled) {
  1588. list_del (&quorum_pd->list);
  1589. list_init (&quorum_pd->list);
  1590. }
  1591. LEAVE();
  1592. return (0);
  1593. }
  1594. /*
  1595. * library internal functions
  1596. */
  1597. static void qdevice_timer_fn(void *arg)
  1598. {
  1599. ENTER();
  1600. if ((!(us->flags & NODE_FLAGS_QDEVICE_ALIVE)) ||
  1601. (!qdevice_timer_set)) {
  1602. LEAVE();
  1603. return;
  1604. }
  1605. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1606. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1607. log_printf(LOGSYS_LEVEL_INFO, "lost contact with quorum device %s", qdevice_name);
  1608. votequorum_exec_send_nodeinfo(us->node_id);
  1609. qdevice_timer_set = 0;
  1610. LEAVE();
  1611. }
  1612. /*
  1613. * Library Handler Functions
  1614. */
  1615. static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *message)
  1616. {
  1617. const struct req_lib_votequorum_getinfo *req_lib_votequorum_getinfo = message;
  1618. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  1619. struct cluster_node *node;
  1620. unsigned int highest_expected = 0;
  1621. unsigned int total_votes = 0;
  1622. cs_error_t error = CS_OK;
  1623. uint32_t nodeid = req_lib_votequorum_getinfo->nodeid;
  1624. ENTER();
  1625. log_printf(LOGSYS_LEVEL_DEBUG, "got getinfo request on %p for node %u", conn, req_lib_votequorum_getinfo->nodeid);
  1626. if (nodeid == NODEID_QDEVICE) {
  1627. nodeid = us->node_id;
  1628. }
  1629. node = find_node_by_nodeid(nodeid);
  1630. if (node) {
  1631. struct cluster_node *iternode;
  1632. struct list_head *nodelist;
  1633. list_iterate(nodelist, &cluster_members_list) {
  1634. iternode = list_entry(nodelist, struct cluster_node, list);
  1635. if (iternode->state == NODESTATE_MEMBER) {
  1636. highest_expected =
  1637. max(highest_expected, iternode->expected_votes);
  1638. total_votes += iternode->votes;
  1639. }
  1640. }
  1641. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1642. total_votes += qdevice->votes;
  1643. }
  1644. switch(node->state) {
  1645. case NODESTATE_MEMBER:
  1646. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_MEMBER;
  1647. break;
  1648. case NODESTATE_DEAD:
  1649. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_DEAD;
  1650. break;
  1651. case NODESTATE_LEAVING:
  1652. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_LEAVING;
  1653. break;
  1654. default:
  1655. res_lib_votequorum_getinfo.state = node->state;
  1656. break;
  1657. }
  1658. res_lib_votequorum_getinfo.state = node->state;
  1659. res_lib_votequorum_getinfo.votes = node->votes;
  1660. res_lib_votequorum_getinfo.expected_votes = node->expected_votes;
  1661. res_lib_votequorum_getinfo.highest_expected = highest_expected;
  1662. res_lib_votequorum_getinfo.quorum = quorum;
  1663. res_lib_votequorum_getinfo.total_votes = total_votes;
  1664. res_lib_votequorum_getinfo.flags = 0;
  1665. res_lib_votequorum_getinfo.nodeid = node->node_id;
  1666. if (two_node) {
  1667. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_TWONODE;
  1668. }
  1669. if (cluster_is_quorate) {
  1670. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QUORATE;
  1671. }
  1672. if (wait_for_all) {
  1673. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_WAIT_FOR_ALL;
  1674. }
  1675. if (last_man_standing) {
  1676. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_LAST_MAN_STANDING;
  1677. }
  1678. if (auto_tie_breaker) {
  1679. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_AUTO_TIE_BREAKER;
  1680. }
  1681. if (allow_downscale) {
  1682. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_ALLOW_DOWNSCALE;
  1683. }
  1684. memset(res_lib_votequorum_getinfo.qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1685. res_lib_votequorum_getinfo.qdevice_votes = 0;
  1686. if (node->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1687. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_REGISTERED;
  1688. res_lib_votequorum_getinfo.qdevice_votes = qdevice->votes;
  1689. strcpy(res_lib_votequorum_getinfo.qdevice_name, qdevice_name);
  1690. }
  1691. if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  1692. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_ALIVE;
  1693. }
  1694. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1695. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_CAST_VOTE;
  1696. }
  1697. if (node->flags & NODE_FLAGS_QDEVICE_MASTER_WINS) {
  1698. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_MASTER_WINS;
  1699. }
  1700. } else {
  1701. error = CS_ERR_NOT_EXIST;
  1702. }
  1703. res_lib_votequorum_getinfo.header.size = sizeof(res_lib_votequorum_getinfo);
  1704. res_lib_votequorum_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  1705. res_lib_votequorum_getinfo.header.error = error;
  1706. corosync_api->ipc_response_send(conn, &res_lib_votequorum_getinfo, sizeof(res_lib_votequorum_getinfo));
  1707. log_printf(LOGSYS_LEVEL_DEBUG, "getinfo response error: %d", error);
  1708. LEAVE();
  1709. }
  1710. static void message_handler_req_lib_votequorum_setexpected (void *conn, const void *message)
  1711. {
  1712. const struct req_lib_votequorum_setexpected *req_lib_votequorum_setexpected = message;
  1713. struct res_lib_votequorum_status res_lib_votequorum_status;
  1714. cs_error_t error = CS_OK;
  1715. unsigned int newquorum;
  1716. unsigned int total_votes;
  1717. uint8_t allow_downscale_status = 0;
  1718. ENTER();
  1719. allow_downscale_status = allow_downscale;
  1720. allow_downscale = 0;
  1721. /*
  1722. * Validate new expected votes
  1723. */
  1724. newquorum = calculate_quorum(1, req_lib_votequorum_setexpected->expected_votes, &total_votes);
  1725. allow_downscale = allow_downscale_status;
  1726. if (newquorum < total_votes / 2 ||
  1727. newquorum > total_votes) {
  1728. error = CS_ERR_INVALID_PARAM;
  1729. goto error_exit;
  1730. }
  1731. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES, us->node_id,
  1732. req_lib_votequorum_setexpected->expected_votes);
  1733. error_exit:
  1734. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1735. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1736. res_lib_votequorum_status.header.error = error;
  1737. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1738. LEAVE();
  1739. }
  1740. static void message_handler_req_lib_votequorum_setvotes (void *conn, const void *message)
  1741. {
  1742. const struct req_lib_votequorum_setvotes *req_lib_votequorum_setvotes = message;
  1743. struct res_lib_votequorum_status res_lib_votequorum_status;
  1744. struct cluster_node *node;
  1745. unsigned int newquorum;
  1746. unsigned int total_votes;
  1747. unsigned int saved_votes;
  1748. cs_error_t error = CS_OK;
  1749. unsigned int nodeid;
  1750. ENTER();
  1751. nodeid = req_lib_votequorum_setvotes->nodeid;
  1752. node = find_node_by_nodeid(nodeid);
  1753. if (!node) {
  1754. error = CS_ERR_NAME_NOT_FOUND;
  1755. goto error_exit;
  1756. }
  1757. /*
  1758. * Check votes is valid
  1759. */
  1760. saved_votes = node->votes;
  1761. node->votes = req_lib_votequorum_setvotes->votes;
  1762. newquorum = calculate_quorum(1, 0, &total_votes);
  1763. if (newquorum < total_votes / 2 ||
  1764. newquorum > total_votes) {
  1765. node->votes = saved_votes;
  1766. error = CS_ERR_INVALID_PARAM;
  1767. goto error_exit;
  1768. }
  1769. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES, nodeid,
  1770. req_lib_votequorum_setvotes->votes);
  1771. error_exit:
  1772. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1773. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1774. res_lib_votequorum_status.header.error = error;
  1775. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1776. LEAVE();
  1777. }
  1778. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  1779. const void *message)
  1780. {
  1781. const struct req_lib_votequorum_trackstart *req_lib_votequorum_trackstart = message;
  1782. struct res_lib_votequorum_status res_lib_votequorum_status;
  1783. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1784. ENTER();
  1785. /*
  1786. * If an immediate listing of the current cluster membership
  1787. * is requested, generate membership list
  1788. */
  1789. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
  1790. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
  1791. log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p", conn);
  1792. votequorum_exec_send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
  1793. }
  1794. /*
  1795. * Record requests for tracking
  1796. */
  1797. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES ||
  1798. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
  1799. quorum_pd->track_flags = req_lib_votequorum_trackstart->track_flags;
  1800. quorum_pd->tracking_enabled = 1;
  1801. quorum_pd->tracking_context = req_lib_votequorum_trackstart->context;
  1802. list_add (&quorum_pd->list, &trackers_list);
  1803. }
  1804. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1805. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1806. res_lib_votequorum_status.header.error = CS_OK;
  1807. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1808. LEAVE();
  1809. }
  1810. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  1811. const void *message)
  1812. {
  1813. struct res_lib_votequorum_status res_lib_votequorum_status;
  1814. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1815. int error = CS_OK;
  1816. ENTER();
  1817. if (quorum_pd->tracking_enabled) {
  1818. error = CS_OK;
  1819. quorum_pd->tracking_enabled = 0;
  1820. list_del (&quorum_pd->list);
  1821. list_init (&quorum_pd->list);
  1822. } else {
  1823. error = CS_ERR_NOT_EXIST;
  1824. }
  1825. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1826. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1827. res_lib_votequorum_status.header.error = error;
  1828. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1829. LEAVE();
  1830. }
  1831. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  1832. const void *message)
  1833. {
  1834. const struct req_lib_votequorum_qdevice_register *req_lib_votequorum_qdevice_register = message;
  1835. struct res_lib_votequorum_status res_lib_votequorum_status;
  1836. cs_error_t error = CS_OK;
  1837. ENTER();
  1838. if (!qdevice_can_operate) {
  1839. log_printf(LOGSYS_LEVEL_INFO, "Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
  1840. error = CS_ERR_ACCESS;
  1841. goto out;
  1842. }
  1843. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1844. if ((!strncmp(req_lib_votequorum_qdevice_register->name,
  1845. qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN))) {
  1846. goto out;
  1847. } else {
  1848. log_printf(LOGSYS_LEVEL_WARNING,
  1849. "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
  1850. req_lib_votequorum_qdevice_register->name, qdevice_name);
  1851. error = CS_ERR_EXIST;
  1852. goto out;
  1853. }
  1854. } else {
  1855. if (qdevice_reg_conn != NULL) {
  1856. log_printf(LOGSYS_LEVEL_WARNING,
  1857. "Registration request already in progress");
  1858. error = CS_ERR_TRY_AGAIN;
  1859. goto out;
  1860. }
  1861. qdevice_reg_conn = conn;
  1862. if (votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1863. req_lib_votequorum_qdevice_register->name) != 0) {
  1864. log_printf(LOGSYS_LEVEL_WARNING,
  1865. "Unable to send qdevice registration request to cluster");
  1866. error = CS_ERR_TRY_AGAIN;
  1867. qdevice_reg_conn = NULL;
  1868. } else {
  1869. LEAVE();
  1870. return;
  1871. }
  1872. }
  1873. out:
  1874. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1875. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1876. res_lib_votequorum_status.header.error = error;
  1877. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1878. LEAVE();
  1879. }
  1880. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  1881. const void *message)
  1882. {
  1883. const struct req_lib_votequorum_qdevice_unregister *req_lib_votequorum_qdevice_unregister = message;
  1884. struct res_lib_votequorum_status res_lib_votequorum_status;
  1885. cs_error_t error = CS_OK;
  1886. ENTER();
  1887. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1888. if (strncmp(req_lib_votequorum_qdevice_unregister->name, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1889. error = CS_ERR_INVALID_PARAM;
  1890. goto out;
  1891. }
  1892. if (qdevice_timer_set) {
  1893. corosync_api->timer_delete(qdevice_timer);
  1894. qdevice_timer_set = 0;
  1895. }
  1896. us->flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
  1897. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1898. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1899. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  1900. votequorum_exec_send_nodeinfo(us->node_id);
  1901. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER,
  1902. req_lib_votequorum_qdevice_unregister->name);
  1903. } else {
  1904. error = CS_ERR_NOT_EXIST;
  1905. }
  1906. out:
  1907. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1908. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1909. res_lib_votequorum_status.header.error = error;
  1910. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1911. LEAVE();
  1912. }
  1913. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  1914. const void *message)
  1915. {
  1916. const struct req_lib_votequorum_qdevice_update *req_lib_votequorum_qdevice_update = message;
  1917. struct res_lib_votequorum_status res_lib_votequorum_status;
  1918. cs_error_t error = CS_OK;
  1919. ENTER();
  1920. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1921. if (strncmp(req_lib_votequorum_qdevice_update->oldname, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1922. error = CS_ERR_INVALID_PARAM;
  1923. goto out;
  1924. }
  1925. votequorum_exec_send_qdevice_reconfigure(req_lib_votequorum_qdevice_update->oldname,
  1926. req_lib_votequorum_qdevice_update->newname);
  1927. } else {
  1928. error = CS_ERR_NOT_EXIST;
  1929. }
  1930. out:
  1931. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1932. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1933. res_lib_votequorum_status.header.error = error;
  1934. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1935. LEAVE();
  1936. }
  1937. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  1938. const void *message)
  1939. {
  1940. const struct req_lib_votequorum_qdevice_poll *req_lib_votequorum_qdevice_poll = message;
  1941. struct res_lib_votequorum_status res_lib_votequorum_status;
  1942. cs_error_t error = CS_OK;
  1943. uint32_t oldflags;
  1944. ENTER();
  1945. if (!qdevice_can_operate) {
  1946. error = CS_ERR_ACCESS;
  1947. goto out;
  1948. }
  1949. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1950. if (strncmp(req_lib_votequorum_qdevice_poll->name, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1951. error = CS_ERR_INVALID_PARAM;
  1952. goto out;
  1953. }
  1954. if (qdevice_timer_set) {
  1955. corosync_api->timer_delete(qdevice_timer);
  1956. qdevice_timer_set = 0;
  1957. }
  1958. oldflags = us->flags;
  1959. us->flags |= NODE_FLAGS_QDEVICE_ALIVE;
  1960. if (req_lib_votequorum_qdevice_poll->cast_vote) {
  1961. us->flags |= NODE_FLAGS_QDEVICE_CAST_VOTE;
  1962. } else {
  1963. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1964. }
  1965. if (us->flags != oldflags) {
  1966. votequorum_exec_send_nodeinfo(us->node_id);
  1967. }
  1968. corosync_api->timer_add_duration((unsigned long long)qdevice_timeout*1000000, qdevice,
  1969. qdevice_timer_fn, &qdevice_timer);
  1970. qdevice_timer_set = 1;
  1971. } else {
  1972. error = CS_ERR_NOT_EXIST;
  1973. }
  1974. out:
  1975. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1976. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1977. res_lib_votequorum_status.header.error = error;
  1978. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1979. LEAVE();
  1980. }
  1981. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  1982. const void *message)
  1983. {
  1984. const struct req_lib_votequorum_qdevice_master_wins *req_lib_votequorum_qdevice_master_wins = message;
  1985. struct res_lib_votequorum_status res_lib_votequorum_status;
  1986. cs_error_t error = CS_OK;
  1987. uint32_t oldflags = us->flags;
  1988. ENTER();
  1989. if (!qdevice_can_operate) {
  1990. error = CS_ERR_ACCESS;
  1991. goto out;
  1992. }
  1993. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1994. if (strncmp(req_lib_votequorum_qdevice_master_wins->name, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1995. error = CS_ERR_INVALID_PARAM;
  1996. goto out;
  1997. }
  1998. if (req_lib_votequorum_qdevice_master_wins->allow) {
  1999. us->flags |= NODE_FLAGS_QDEVICE_MASTER_WINS;
  2000. } else {
  2001. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2002. }
  2003. if (us->flags != oldflags) {
  2004. votequorum_exec_send_nodeinfo(us->node_id);
  2005. }
  2006. update_qdevice_master_wins(req_lib_votequorum_qdevice_master_wins->allow);
  2007. } else {
  2008. error = CS_ERR_NOT_EXIST;
  2009. }
  2010. out:
  2011. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2012. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2013. res_lib_votequorum_status.header.error = error;
  2014. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2015. LEAVE();
  2016. }