votequorum.c 65 KB

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