votequorum.c 66 KB

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