4
0

votequorum.c 67 KB

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