votequorum.c 65 KB

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