votequorum.c 65 KB

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