votequorum.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392
  1. /*
  2. * Copyright (c) 2009-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Authors: Christine Caulfield (ccaulfie@redhat.com)
  7. * Fabio M. Di Nitto (fdinitto@redhat.com)
  8. *
  9. * This software licensed under BSD license, the text of which follows:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright notice,
  15. * this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright notice,
  17. * this list of conditions and the following disclaimer in the documentation
  18. * and/or other materials provided with the distribution.
  19. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  33. * THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. #include <config.h>
  36. #include <sys/types.h>
  37. #include <stdint.h>
  38. #include <qb/qbipc_common.h>
  39. #include "quorum.h"
  40. #include <corosync/corodefs.h>
  41. #include <corosync/list.h>
  42. #include <corosync/logsys.h>
  43. #include <corosync/coroapi.h>
  44. #include <corosync/icmap.h>
  45. #include <corosync/ipc_votequorum.h>
  46. #include "service.h"
  47. LOGSYS_DECLARE_SUBSYS ("VOTEQ");
  48. /*
  49. * interface with corosync
  50. */
  51. static struct corosync_api_v1 *corosync_api;
  52. /*
  53. * votequorum global config vars
  54. */
  55. #define DEFAULT_QDEVICE_TIMEOUT 10000
  56. static char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  57. static struct cluster_node *qdevice = NULL;
  58. static unsigned int qdevice_timeout = DEFAULT_QDEVICE_TIMEOUT;
  59. static uint8_t qdevice_can_operate = 1;
  60. static void *qdevice_reg_conn = NULL;
  61. static uint8_t two_node = 0;
  62. static uint8_t wait_for_all = 0;
  63. static uint8_t wait_for_all_status = 0;
  64. static uint8_t auto_tie_breaker = 0;
  65. static int lowest_node_id = -1;
  66. #define DEFAULT_LMS_WIN 10000
  67. static uint8_t last_man_standing = 0;
  68. static uint32_t last_man_standing_window = DEFAULT_LMS_WIN;
  69. static uint8_t allow_downscale = 0;
  70. static uint32_t ev_barrier = 0;
  71. /*
  72. * votequorum_exec defines/structs/forward definitions
  73. */
  74. struct req_exec_quorum_nodeinfo {
  75. struct qb_ipc_request_header header __attribute__((aligned(8)));
  76. uint32_t nodeid;
  77. uint32_t votes;
  78. uint32_t expected_votes;
  79. uint32_t flags;
  80. } __attribute__((packed));
  81. struct req_exec_quorum_reconfigure {
  82. struct qb_ipc_request_header header __attribute__((aligned(8)));
  83. uint32_t nodeid;
  84. uint32_t value;
  85. uint8_t param;
  86. uint8_t _pad0;
  87. uint8_t _pad1;
  88. uint8_t _pad2;
  89. } __attribute__((packed));
  90. struct req_exec_quorum_qdevice_reg {
  91. struct qb_ipc_request_header header __attribute__((aligned(8)));
  92. uint32_t operation;
  93. char qdevice_name[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  94. } __attribute__((packed));
  95. struct req_exec_quorum_qdevice_reconfigure {
  96. struct qb_ipc_request_header header __attribute__((aligned(8)));
  97. char oldname[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  98. char newname[VOTEQUORUM_MAX_QDEVICE_NAME_LEN];
  99. } __attribute__((packed));
  100. /*
  101. * votequorum_exec onwire version (via totem)
  102. */
  103. #include "votequorum.h"
  104. /*
  105. * votequorum_exec onwire messages (via totem)
  106. */
  107. #define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO 0
  108. #define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE 1
  109. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG 2
  110. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE 3
  111. static void votequorum_exec_send_expectedvotes_notification(void);
  112. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context);
  113. #define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES 1
  114. #define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES 2
  115. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value);
  116. /*
  117. * used by req_exec_quorum_qdevice_reg
  118. */
  119. #define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER 0
  120. #define VOTEQUORUM_QDEVICE_OPERATION_REGISTER 1
  121. /*
  122. * votequorum internal node status/view
  123. */
  124. #define NODE_FLAGS_QUORATE 1
  125. #define NODE_FLAGS_LEAVING 2
  126. #define NODE_FLAGS_WFASTATUS 4
  127. #define NODE_FLAGS_FIRST 8
  128. #define NODE_FLAGS_QDEVICE_REGISTERED 16
  129. #define NODE_FLAGS_QDEVICE_ALIVE 32
  130. #define NODE_FLAGS_QDEVICE_CAST_VOTE 64
  131. #define 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 QdeviceAlive: %s QdeviceCastVote: %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. (flags & NODE_FLAGS_QDEVICE_CAST_VOTE)?"Yes":"No");
  456. }
  457. static void update_wait_for_all_status(uint8_t wfa_status)
  458. {
  459. wait_for_all_status = wfa_status;
  460. if (wait_for_all_status) {
  461. us->flags |= NODE_FLAGS_WFASTATUS;
  462. } else {
  463. us->flags &= ~NODE_FLAGS_WFASTATUS;
  464. }
  465. icmap_set_uint8("runtime.votequorum.wait_for_all_status",
  466. wait_for_all_status);
  467. }
  468. static void update_two_node(void)
  469. {
  470. icmap_set_uint8("runtime.votequorum.two_node", two_node);
  471. }
  472. static void update_ev_barrier(uint32_t expected_votes)
  473. {
  474. ev_barrier = expected_votes;
  475. icmap_set_uint32("runtime.votequorum.ev_barrier", ev_barrier);
  476. }
  477. static void update_qdevice_can_operate(uint8_t status)
  478. {
  479. qdevice_can_operate = status;
  480. icmap_set_uint8("runtime.votequorum.qdevice_can_operate", qdevice_can_operate);
  481. }
  482. /*
  483. * quorum calculation core bits
  484. */
  485. static int calculate_quorum(int allow_decrease, unsigned int max_expected, unsigned int *ret_total_votes)
  486. {
  487. struct list_head *nodelist;
  488. struct cluster_node *node;
  489. unsigned int total_votes = 0;
  490. unsigned int highest_expected = 0;
  491. unsigned int newquorum, q1, q2;
  492. unsigned int total_nodes = 0;
  493. ENTER();
  494. if ((allow_downscale) && (allow_decrease) && (max_expected)) {
  495. max_expected = max(ev_barrier, max_expected);
  496. }
  497. list_iterate(nodelist, &cluster_members_list) {
  498. node = list_entry(nodelist, struct cluster_node, list);
  499. log_printf(LOGSYS_LEVEL_DEBUG, "node %u state=%d, votes=%u, expected=%u",
  500. node->node_id, node->state, node->votes, node->expected_votes);
  501. if (node->state == NODESTATE_MEMBER) {
  502. if (max_expected) {
  503. node->expected_votes = max_expected;
  504. } else {
  505. highest_expected = max(highest_expected, node->expected_votes);
  506. }
  507. total_votes += node->votes;
  508. total_nodes++;
  509. }
  510. }
  511. if (us->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  512. log_printf(LOGSYS_LEVEL_DEBUG, "node 0 state=1, votes=%u", qdevice->votes);
  513. total_votes += qdevice->votes;
  514. total_nodes++;
  515. }
  516. if (max_expected > 0) {
  517. highest_expected = max_expected;
  518. }
  519. /*
  520. * This quorum calculation is taken from the OpenVMS Cluster Systems
  521. * manual, but, then, you guessed that didn't you
  522. */
  523. q1 = (highest_expected + 2) / 2;
  524. q2 = (total_votes + 2) / 2;
  525. newquorum = max(q1, q2);
  526. /*
  527. * Normally quorum never decreases but the system administrator can
  528. * force it down by setting expected votes to a maximum value
  529. */
  530. if (!allow_decrease) {
  531. newquorum = max(quorum, newquorum);
  532. }
  533. /*
  534. * The special two_node mode allows each of the two nodes to retain
  535. * quorum if the other fails. Only one of the two should live past
  536. * fencing (as both nodes try to fence each other in split-brain.)
  537. * Also: if there are more than two nodes, force us inquorate to avoid
  538. * any damage or confusion.
  539. */
  540. if (two_node && total_nodes <= 2) {
  541. newquorum = 1;
  542. }
  543. if (ret_total_votes) {
  544. *ret_total_votes = total_votes;
  545. }
  546. LEAVE();
  547. return newquorum;
  548. }
  549. static void are_we_quorate(unsigned int total_votes)
  550. {
  551. int quorate;
  552. int quorum_change = 0;
  553. ENTER();
  554. /*
  555. * wait for all nodes to show up before granting quorum
  556. */
  557. if ((wait_for_all) && (wait_for_all_status)) {
  558. if (total_votes != us->expected_votes) {
  559. log_printf(LOGSYS_LEVEL_NOTICE,
  560. "Waiting for all cluster members. "
  561. "Current votes: %d expected_votes: %d",
  562. total_votes, us->expected_votes);
  563. cluster_is_quorate = 0;
  564. return;
  565. }
  566. update_wait_for_all_status(0);
  567. }
  568. if (quorum > total_votes) {
  569. quorate = 0;
  570. } else {
  571. quorate = 1;
  572. get_lowest_node_id();
  573. }
  574. if ((auto_tie_breaker) &&
  575. (total_votes == (us->expected_votes / 2)) &&
  576. (check_low_node_id_partition() == 1)) {
  577. quorate = 1;
  578. }
  579. if (cluster_is_quorate && !quorate) {
  580. quorum_change = 1;
  581. log_printf(LOGSYS_LEVEL_DEBUG, "quorum lost, blocking activity");
  582. }
  583. if (!cluster_is_quorate && quorate) {
  584. quorum_change = 1;
  585. log_printf(LOGSYS_LEVEL_DEBUG, "quorum regained, resuming activity");
  586. }
  587. cluster_is_quorate = quorate;
  588. if (cluster_is_quorate) {
  589. us->flags |= NODE_FLAGS_QUORATE;
  590. } else {
  591. us->flags &= ~NODE_FLAGS_QUORATE;
  592. }
  593. if (wait_for_all) {
  594. if (quorate) {
  595. update_wait_for_all_status(0);
  596. } else {
  597. update_wait_for_all_status(1);
  598. }
  599. }
  600. if (quorum_change) {
  601. quorum_callback(quorum_members, quorum_members_entries,
  602. cluster_is_quorate, &quorum_ringid);
  603. }
  604. LEAVE();
  605. }
  606. static void get_total_votes(unsigned int *totalvotes, unsigned int *current_members)
  607. {
  608. unsigned int total_votes = 0;
  609. unsigned int cluster_members = 0;
  610. struct list_head *nodelist;
  611. struct cluster_node *node;
  612. ENTER();
  613. list_iterate(nodelist, &cluster_members_list) {
  614. node = list_entry(nodelist, struct cluster_node, list);
  615. if (node->state == NODESTATE_MEMBER) {
  616. cluster_members++;
  617. total_votes += node->votes;
  618. }
  619. }
  620. if (qdevice->votes) {
  621. total_votes += qdevice->votes;
  622. cluster_members++;
  623. }
  624. *totalvotes = total_votes;
  625. *current_members = cluster_members;
  626. LEAVE();
  627. }
  628. /*
  629. * Recalculate cluster quorum, set quorate and notify changes
  630. */
  631. static void recalculate_quorum(int allow_decrease, int by_current_nodes)
  632. {
  633. unsigned int total_votes = 0;
  634. unsigned int cluster_members = 0;
  635. ENTER();
  636. get_total_votes(&total_votes, &cluster_members);
  637. if (!by_current_nodes) {
  638. cluster_members = 0;
  639. }
  640. /*
  641. * Keep expected_votes at the highest number of votes in the cluster
  642. */
  643. log_printf(LOGSYS_LEVEL_DEBUG, "total_votes=%d, expected_votes=%d", total_votes, us->expected_votes);
  644. if (total_votes > us->expected_votes) {
  645. us->expected_votes = total_votes;
  646. votequorum_exec_send_expectedvotes_notification();
  647. }
  648. quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
  649. are_we_quorate(total_votes);
  650. votequorum_exec_send_quorum_notification(NULL, 0L);
  651. LEAVE();
  652. }
  653. /*
  654. * configuration bits and pieces
  655. */
  656. static int votequorum_read_nodelist_configuration(uint32_t *votes,
  657. uint32_t *nodes,
  658. uint32_t *expected_votes)
  659. {
  660. icmap_iter_t iter;
  661. const char *iter_key;
  662. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  663. uint32_t our_pos, node_pos;
  664. uint32_t nodecount = 0;
  665. uint32_t nodelist_expected_votes = 0;
  666. uint32_t node_votes = 0;
  667. int res = 0;
  668. ENTER();
  669. if (icmap_get_uint32("nodelist.local_node_pos", &our_pos) != CS_OK) {
  670. log_printf(LOGSYS_LEVEL_DEBUG,
  671. "No nodelist defined or our node is not in the nodelist");
  672. return 0;
  673. }
  674. iter = icmap_iter_init("nodelist.node.");
  675. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  676. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  677. if (res != 2) {
  678. continue;
  679. }
  680. if (strcmp(tmp_key, "ring0_addr") != 0) {
  681. continue;
  682. }
  683. nodecount++;
  684. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.quorum_votes", node_pos);
  685. if (icmap_get_uint32(tmp_key, &node_votes) != CS_OK) {
  686. node_votes = 1;
  687. }
  688. nodelist_expected_votes = nodelist_expected_votes + node_votes;
  689. if (node_pos == our_pos) {
  690. *votes = node_votes;
  691. }
  692. }
  693. *expected_votes = nodelist_expected_votes;
  694. *nodes = nodecount;
  695. icmap_iter_finalize(iter);
  696. LEAVE();
  697. return 1;
  698. }
  699. static int votequorum_qdevice_is_configured(uint32_t *qdevice_votes)
  700. {
  701. char *qdevice_model = NULL;
  702. ENTER();
  703. if ((icmap_get_string("quorum.device.model", &qdevice_model) == CS_OK) &&
  704. (strlen(qdevice_model))) {
  705. free(qdevice_model);
  706. if (icmap_get_uint32("quorum.device.votes", qdevice_votes) != CS_OK) {
  707. *qdevice_votes = -1;
  708. }
  709. if (icmap_get_uint32("quorum.device.timeout", &qdevice_timeout) != CS_OK) {
  710. qdevice_timeout = DEFAULT_QDEVICE_TIMEOUT;
  711. }
  712. update_qdevice_can_operate(1);
  713. return 1;
  714. }
  715. LEAVE();
  716. return 0;
  717. }
  718. #define VOTEQUORUM_READCONFIG_STARTUP 0
  719. #define VOTEQUORUM_READCONFIG_RUNTIME 1
  720. static char *votequorum_readconfig(int runtime)
  721. {
  722. uint32_t node_votes = 0, qdevice_votes = 0;
  723. uint32_t node_expected_votes = 0, expected_votes = 0;
  724. uint32_t node_count = 0;
  725. int have_nodelist, have_qdevice;
  726. char *error = NULL;
  727. ENTER();
  728. log_printf(LOGSYS_LEVEL_DEBUG, "Reading configuration (runtime: %d)", runtime);
  729. /*
  730. * gather basic data here
  731. */
  732. icmap_get_uint32("quorum.expected_votes", &expected_votes);
  733. have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
  734. have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
  735. icmap_get_uint8("quorum.two_node", &two_node);
  736. /*
  737. * do config verification and enablement
  738. */
  739. if ((!have_nodelist) && (!expected_votes)) {
  740. if (!runtime) {
  741. error = (char *)"configuration error: nodelist or quorum.expected_votes must be configured!";
  742. } else {
  743. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: nodelist or quorum.expected_votes must be configured!");
  744. log_printf(LOGSYS_LEVEL_CRIT, "will continue with current runtime data");
  745. }
  746. goto out;
  747. }
  748. /*
  749. * two_node and qdevice are not compatible in the same config.
  750. * try to make an educated guess of what to do
  751. */
  752. if ((two_node) && (have_qdevice)) {
  753. if (!runtime) {
  754. error = (char *)"configuration error: two_node and quorum device cannot be configured at the same time!";
  755. goto out;
  756. } else {
  757. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: two_node and quorum device cannot be configured at the same time!");
  758. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  759. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is registered, disabling two_node");
  760. two_node = 0;
  761. } else {
  762. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is not registered, allowing two_node");
  763. update_qdevice_can_operate(0);
  764. }
  765. }
  766. }
  767. /*
  768. * Enable special features
  769. */
  770. if (!runtime) {
  771. if (two_node) {
  772. wait_for_all = 1;
  773. }
  774. icmap_get_uint8("quorum.allow_downscale", &allow_downscale);
  775. icmap_get_uint8("quorum.wait_for_all", &wait_for_all);
  776. icmap_get_uint8("quorum.auto_tie_breaker", &auto_tie_breaker);
  777. icmap_get_uint8("quorum.last_man_standing", &last_man_standing);
  778. icmap_get_uint32("quorum.last_man_standing_window", &last_man_standing_window);
  779. }
  780. /*
  781. * quorum device is not compatible with last_man_standing and auto_tie_breaker
  782. * neither lms or atb can be set at runtime, so there is no need to check for
  783. * runtime incompatibilities, but qdevice can be configured _after_ LMS and ATB have
  784. * been enabled at startup.
  785. */
  786. if ((have_qdevice) && (last_man_standing)) {
  787. if (!runtime) {
  788. error = (char *)"configuration error: quorum.device is not compatible with last_man_standing";
  789. goto out;
  790. } else {
  791. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with last_man_standing");
  792. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  793. update_qdevice_can_operate(0);
  794. }
  795. }
  796. if ((have_qdevice) && (auto_tie_breaker)) {
  797. if (!runtime) {
  798. error = (char *)"configuration error: quorum.device is not compatible with auto_tie_breaker";
  799. goto out;
  800. } else {
  801. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with auto_tie_breaker");
  802. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  803. update_qdevice_can_operate(0);
  804. }
  805. }
  806. if ((have_qdevice) && (wait_for_all)) {
  807. if (!runtime) {
  808. error = (char *)"configuration error: quorum.device is not compatible with wait_for_all";
  809. goto out;
  810. } else {
  811. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with wait_for_all");
  812. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  813. update_qdevice_can_operate(0);
  814. }
  815. }
  816. if ((have_qdevice) && (allow_downscale)) {
  817. if (!runtime) {
  818. error = (char *)"configuration error: quorum.device is not compatible with allow_downscale";
  819. goto out;
  820. } else {
  821. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with allow_downscale");
  822. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  823. update_qdevice_can_operate(0);
  824. }
  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. if (!runtime) {
  832. error = (char *)"configuration error: quorum.device.votes must be specified when quorum.expected_votes is set";
  833. goto out;
  834. } else {
  835. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when quorum.expected_votes is set");
  836. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  837. update_qdevice_can_operate(0);
  838. }
  839. }
  840. /*
  841. * if user specifies a node list with uneven votes and no device.votes
  842. * we cannot autocalculate the votes
  843. */
  844. if ((have_qdevice) &&
  845. (qdevice_votes == -1) &&
  846. (have_nodelist) &&
  847. (node_count != node_expected_votes)) {
  848. if (!runtime) {
  849. error = (char *)"configuration error: quorum.device.votes must be specified when not all nodes votes 1";
  850. goto out;
  851. } else {
  852. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when not all nodes votes 1");
  853. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  854. update_qdevice_can_operate(0);
  855. }
  856. }
  857. /*
  858. * validate quorum device votes vs expected_votes
  859. */
  860. if ((qdevice_votes > 0) && (expected_votes)) {
  861. int delta = expected_votes - qdevice_votes;
  862. if (delta < 2) {
  863. if (!runtime) {
  864. error = (char *)"configuration error: quorum.device.votes is too high or expected_votes is too low";
  865. goto out;
  866. } else {
  867. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes is too high or expected_votes is too low");
  868. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  869. update_qdevice_can_operate(0);
  870. }
  871. }
  872. }
  873. /*
  874. * automatically calculate device votes and adjust expected_votes from nodelist
  875. */
  876. if ((have_qdevice) &&
  877. (qdevice_votes == -1) &&
  878. (!expected_votes) &&
  879. (have_nodelist) &&
  880. (node_count == node_expected_votes)) {
  881. qdevice_votes = node_expected_votes - 1;
  882. node_expected_votes = node_expected_votes + qdevice_votes;
  883. }
  884. /*
  885. * set this node votes and expected_votes
  886. */
  887. if (have_nodelist) {
  888. us->votes = node_votes;
  889. us->expected_votes = node_expected_votes;
  890. } else {
  891. us->votes = 1;
  892. icmap_get_uint32("quorum.votes", &us->votes);
  893. }
  894. if (expected_votes) {
  895. us->expected_votes = expected_votes;
  896. }
  897. /*
  898. * set qdevice votes
  899. */
  900. if (!have_qdevice) {
  901. qdevice->votes = 0;
  902. }
  903. if (qdevice_votes != -1) {
  904. qdevice->votes = qdevice_votes;
  905. }
  906. update_ev_barrier(us->expected_votes);
  907. update_two_node();
  908. if (wait_for_all) {
  909. update_wait_for_all_status(1);
  910. }
  911. out:
  912. LEAVE();
  913. return error;
  914. }
  915. static void votequorum_refresh_config(
  916. int32_t event,
  917. const char *key_name,
  918. struct icmap_notify_value new_val,
  919. struct icmap_notify_value old_val,
  920. void *user_data)
  921. {
  922. ENTER();
  923. /*
  924. * Reload the configuration
  925. */
  926. votequorum_readconfig(VOTEQUORUM_READCONFIG_RUNTIME);
  927. /*
  928. * activate new config
  929. */
  930. votequorum_exec_send_nodeinfo(us->node_id);
  931. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  932. LEAVE();
  933. }
  934. static void votequorum_exec_add_config_notification(void)
  935. {
  936. icmap_track_t icmap_track_nodelist = NULL;
  937. icmap_track_t icmap_track_quorum = NULL;
  938. ENTER();
  939. icmap_track_add("nodelist.",
  940. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  941. votequorum_refresh_config,
  942. NULL,
  943. &icmap_track_nodelist);
  944. icmap_track_add("quorum.",
  945. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  946. votequorum_refresh_config,
  947. NULL,
  948. &icmap_track_quorum);
  949. LEAVE();
  950. }
  951. /*
  952. * votequorum_exec core
  953. */
  954. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value)
  955. {
  956. struct req_exec_quorum_reconfigure req_exec_quorum_reconfigure;
  957. struct iovec iov[1];
  958. int ret;
  959. ENTER();
  960. req_exec_quorum_reconfigure.nodeid = nodeid;
  961. req_exec_quorum_reconfigure.value = value;
  962. req_exec_quorum_reconfigure.param = param;
  963. req_exec_quorum_reconfigure._pad0 = 0;
  964. req_exec_quorum_reconfigure._pad1 = 0;
  965. req_exec_quorum_reconfigure._pad2 = 0;
  966. req_exec_quorum_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE);
  967. req_exec_quorum_reconfigure.header.size = sizeof(req_exec_quorum_reconfigure);
  968. iov[0].iov_base = (void *)&req_exec_quorum_reconfigure;
  969. iov[0].iov_len = sizeof(req_exec_quorum_reconfigure);
  970. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  971. LEAVE();
  972. return ret;
  973. }
  974. static int votequorum_exec_send_nodeinfo(uint32_t nodeid)
  975. {
  976. struct req_exec_quorum_nodeinfo req_exec_quorum_nodeinfo;
  977. struct iovec iov[1];
  978. struct cluster_node *node;
  979. int ret;
  980. ENTER();
  981. node = find_node_by_nodeid(nodeid);
  982. if (!node) {
  983. return -1;
  984. }
  985. req_exec_quorum_nodeinfo.nodeid = nodeid;
  986. req_exec_quorum_nodeinfo.votes = node->votes;
  987. req_exec_quorum_nodeinfo.expected_votes = node->expected_votes;
  988. req_exec_quorum_nodeinfo.flags = node->flags;
  989. if (nodeid != NODEID_QDEVICE) {
  990. decode_flags(node->flags);
  991. }
  992. req_exec_quorum_nodeinfo.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO);
  993. req_exec_quorum_nodeinfo.header.size = sizeof(req_exec_quorum_nodeinfo);
  994. iov[0].iov_base = (void *)&req_exec_quorum_nodeinfo;
  995. iov[0].iov_len = sizeof(req_exec_quorum_nodeinfo);
  996. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  997. LEAVE();
  998. return ret;
  999. }
  1000. static int votequorum_exec_send_qdevice_reconfigure(const char *oldname, const char *newname)
  1001. {
  1002. struct req_exec_quorum_qdevice_reconfigure req_exec_quorum_qdevice_reconfigure;
  1003. struct iovec iov[1];
  1004. int ret;
  1005. ENTER();
  1006. req_exec_quorum_qdevice_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE);
  1007. req_exec_quorum_qdevice_reconfigure.header.size = sizeof(req_exec_quorum_qdevice_reconfigure);
  1008. strcpy(req_exec_quorum_qdevice_reconfigure.oldname, oldname);
  1009. strcpy(req_exec_quorum_qdevice_reconfigure.newname, newname);
  1010. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reconfigure;
  1011. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reconfigure);
  1012. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1013. LEAVE();
  1014. return ret;
  1015. }
  1016. static int votequorum_exec_send_qdevice_reg(uint32_t operation, const char *qdevice_name_req)
  1017. {
  1018. struct req_exec_quorum_qdevice_reg req_exec_quorum_qdevice_reg;
  1019. struct iovec iov[1];
  1020. int ret;
  1021. ENTER();
  1022. req_exec_quorum_qdevice_reg.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG);
  1023. req_exec_quorum_qdevice_reg.header.size = sizeof(req_exec_quorum_qdevice_reg);
  1024. req_exec_quorum_qdevice_reg.operation = operation;
  1025. strcpy(req_exec_quorum_qdevice_reg.qdevice_name, qdevice_name_req);
  1026. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reg;
  1027. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reg);
  1028. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1029. LEAVE();
  1030. return ret;
  1031. }
  1032. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context)
  1033. {
  1034. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  1035. struct list_head *tmp;
  1036. struct cluster_node *node;
  1037. int cluster_members = 0;
  1038. int i = 0;
  1039. int size;
  1040. char buf[sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * (PROCESSOR_COUNT_MAX + 2)];
  1041. ENTER();
  1042. list_iterate(tmp, &cluster_members_list) {
  1043. node = list_entry(tmp, struct cluster_node, list);
  1044. cluster_members++;
  1045. }
  1046. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1047. cluster_members++;
  1048. }
  1049. size = sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  1050. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)&buf;
  1051. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  1052. res_lib_votequorum_notification->node_list_entries = cluster_members;
  1053. res_lib_votequorum_notification->context = context;
  1054. list_iterate(tmp, &cluster_members_list) {
  1055. node = list_entry(tmp, struct cluster_node, list);
  1056. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  1057. res_lib_votequorum_notification->node_list[i++].state = node->state;
  1058. }
  1059. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1060. res_lib_votequorum_notification->node_list[i].nodeid = NODEID_QDEVICE;
  1061. res_lib_votequorum_notification->node_list[i++].state = qdevice->state;
  1062. }
  1063. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NOTIFICATION;
  1064. res_lib_votequorum_notification->header.size = size;
  1065. res_lib_votequorum_notification->header.error = CS_OK;
  1066. /* Send it to all interested parties */
  1067. if (conn) {
  1068. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1069. LEAVE();
  1070. return ret;
  1071. } else {
  1072. struct quorum_pd *qpd;
  1073. list_iterate(tmp, &trackers_list) {
  1074. qpd = list_entry(tmp, struct quorum_pd, list);
  1075. res_lib_votequorum_notification->context = qpd->tracking_context;
  1076. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1077. }
  1078. }
  1079. LEAVE();
  1080. return 0;
  1081. }
  1082. static void votequorum_exec_send_expectedvotes_notification(void)
  1083. {
  1084. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  1085. struct quorum_pd *qpd;
  1086. struct list_head *tmp;
  1087. ENTER();
  1088. log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback");
  1089. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  1090. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  1091. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  1092. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  1093. list_iterate(tmp, &trackers_list) {
  1094. qpd = list_entry(tmp, struct quorum_pd, list);
  1095. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  1096. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  1097. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  1098. }
  1099. LEAVE();
  1100. }
  1101. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message)
  1102. {
  1103. ENTER();
  1104. LEAVE();
  1105. }
  1106. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  1107. const void *message,
  1108. unsigned int nodeid)
  1109. {
  1110. const struct req_exec_quorum_qdevice_reconfigure *req_exec_quorum_qdevice_reconfigure = message;
  1111. ENTER();
  1112. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice name change req from node %u [from: %s to: %s]",
  1113. nodeid,
  1114. req_exec_quorum_qdevice_reconfigure->oldname,
  1115. req_exec_quorum_qdevice_reconfigure->newname);
  1116. if (!strcmp(req_exec_quorum_qdevice_reconfigure->oldname, qdevice_name)) {
  1117. log_printf(LOGSYS_LEVEL_DEBUG, "Allowing qdevice rename");
  1118. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1119. strcpy(qdevice_name, req_exec_quorum_qdevice_reconfigure->newname);
  1120. /*
  1121. * TODO: notify qdevices about name change?
  1122. * this is not relevant for now and can wait later on since
  1123. * qdevices are local only and libvotequorum is not final
  1124. */
  1125. }
  1126. LEAVE();
  1127. }
  1128. static void exec_votequorum_qdevice_reg_endian_convert (void *message)
  1129. {
  1130. struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1131. ENTER();
  1132. req_exec_quorum_qdevice_reg->operation = swab32(req_exec_quorum_qdevice_reg->operation);
  1133. LEAVE();
  1134. }
  1135. static void message_handler_req_exec_votequorum_qdevice_reg (
  1136. const void *message,
  1137. unsigned int nodeid)
  1138. {
  1139. const struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1140. struct res_lib_votequorum_status res_lib_votequorum_status;
  1141. int wipe_qdevice_name = 1;
  1142. struct cluster_node *node = NULL;
  1143. struct list_head *tmp;
  1144. cs_error_t error = CS_OK;
  1145. ENTER();
  1146. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice op %u req from node %u [%s]",
  1147. req_exec_quorum_qdevice_reg->operation,
  1148. nodeid, req_exec_quorum_qdevice_reg->qdevice_name);
  1149. switch(req_exec_quorum_qdevice_reg->operation)
  1150. {
  1151. case VOTEQUORUM_QDEVICE_OPERATION_REGISTER:
  1152. if (nodeid != us->node_id) {
  1153. if (!strlen(qdevice_name)) {
  1154. log_printf(LOGSYS_LEVEL_DEBUG, "Remote qdevice name recorded");
  1155. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1156. }
  1157. LEAVE();
  1158. return;
  1159. }
  1160. /*
  1161. * protect against the case where we broadcast qdevice registration
  1162. * to new memebers, we receive the message back, but there is no registration
  1163. * connection in progress
  1164. */
  1165. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1166. LEAVE();
  1167. }
  1168. /*
  1169. * this should NEVER happen
  1170. */
  1171. if (!qdevice_reg_conn) {
  1172. log_printf(LOGSYS_LEVEL_WARNING, "Unable to determine origin of the qdevice register call!");
  1173. LEAVE();
  1174. return;
  1175. }
  1176. /*
  1177. * registering our own device in this case
  1178. */
  1179. if (!strlen(qdevice_name)) {
  1180. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1181. }
  1182. /*
  1183. * check if it is our device or something else
  1184. */
  1185. if ((!strncmp(req_exec_quorum_qdevice_reg->qdevice_name,
  1186. qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN))) {
  1187. us->flags |= NODE_FLAGS_QDEVICE_REGISTERED;
  1188. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  1189. votequorum_exec_send_nodeinfo(us->node_id);
  1190. } else {
  1191. log_printf(LOGSYS_LEVEL_WARNING,
  1192. "A new qdevice with different name (new: %s old: %s) is trying to register!",
  1193. req_exec_quorum_qdevice_reg->qdevice_name, qdevice_name);
  1194. error = CS_ERR_EXIST;
  1195. }
  1196. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1197. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1198. res_lib_votequorum_status.header.error = error;
  1199. corosync_api->ipc_response_send(qdevice_reg_conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1200. qdevice_reg_conn = NULL;
  1201. break;
  1202. case VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER:
  1203. list_iterate(tmp, &cluster_members_list) {
  1204. node = list_entry(tmp, struct cluster_node, list);
  1205. if ((node->state == NODESTATE_MEMBER) &&
  1206. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1207. wipe_qdevice_name = 0;
  1208. }
  1209. }
  1210. if (wipe_qdevice_name) {
  1211. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1212. }
  1213. break;
  1214. }
  1215. LEAVE();
  1216. }
  1217. static void exec_votequorum_nodeinfo_endian_convert (void *message)
  1218. {
  1219. struct req_exec_quorum_nodeinfo *nodeinfo = message;
  1220. ENTER();
  1221. nodeinfo->nodeid = swab32(nodeinfo->nodeid);
  1222. nodeinfo->votes = swab32(nodeinfo->votes);
  1223. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  1224. nodeinfo->flags = swab32(nodeinfo->flags);
  1225. LEAVE();
  1226. }
  1227. static void message_handler_req_exec_votequorum_nodeinfo (
  1228. const void *message,
  1229. unsigned int sender_nodeid)
  1230. {
  1231. const struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = message;
  1232. struct cluster_node *node = NULL;
  1233. int old_votes;
  1234. int old_expected;
  1235. uint32_t old_flags;
  1236. nodestate_t old_state;
  1237. int new_node = 0;
  1238. int allow_downgrade = 0;
  1239. int by_node = 0;
  1240. unsigned int nodeid = req_exec_quorum_nodeinfo->nodeid;
  1241. ENTER();
  1242. log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %u", sender_nodeid);
  1243. log_printf(LOGSYS_LEVEL_DEBUG, "nodeinfo message[%u]: votes: %d, expected: %d flags: %d",
  1244. nodeid,
  1245. req_exec_quorum_nodeinfo->votes,
  1246. req_exec_quorum_nodeinfo->expected_votes,
  1247. req_exec_quorum_nodeinfo->flags);
  1248. if (nodeid != NODEID_QDEVICE) {
  1249. decode_flags(req_exec_quorum_nodeinfo->flags);
  1250. }
  1251. node = find_node_by_nodeid(nodeid);
  1252. if (!node) {
  1253. node = allocate_node(nodeid);
  1254. new_node = 1;
  1255. }
  1256. if (!node) {
  1257. corosync_api->error_memory_failure();
  1258. LEAVE();
  1259. return;
  1260. }
  1261. if (new_node) {
  1262. old_votes = 0;
  1263. old_expected = 0;
  1264. old_state = NODESTATE_DEAD;
  1265. old_flags = 0;
  1266. } else {
  1267. old_votes = node->votes;
  1268. old_expected = node->expected_votes;
  1269. old_state = node->state;
  1270. old_flags = node->flags;
  1271. }
  1272. if (nodeid == NODEID_QDEVICE) {
  1273. if ((!cluster_is_quorate) &&
  1274. (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_QUORATE)) {
  1275. node->votes = req_exec_quorum_nodeinfo->votes;
  1276. } else {
  1277. node->votes = max(node->votes, req_exec_quorum_nodeinfo->votes);
  1278. }
  1279. goto recalculate;
  1280. }
  1281. /* Update node state */
  1282. node->flags = req_exec_quorum_nodeinfo->flags;
  1283. node->votes = req_exec_quorum_nodeinfo->votes;
  1284. node->state = NODESTATE_MEMBER;
  1285. if (node->flags & NODE_FLAGS_LEAVING) {
  1286. node->state = NODESTATE_LEAVING;
  1287. allow_downgrade = 1;
  1288. by_node = 1;
  1289. }
  1290. if ((!cluster_is_quorate) &&
  1291. (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_QUORATE)) {
  1292. allow_downgrade = 1;
  1293. us->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1294. }
  1295. if (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_QUORATE) {
  1296. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1297. } else {
  1298. node->expected_votes = us->expected_votes;
  1299. }
  1300. if ((last_man_standing) && (req_exec_quorum_nodeinfo->votes > 1)) {
  1301. log_printf(LOGSYS_LEVEL_WARNING, "Last Man Standing feature is supported only when all"
  1302. "cluster nodes votes are set to 1. Disabling LMS.");
  1303. last_man_standing = 0;
  1304. if (last_man_standing_timer_set) {
  1305. corosync_api->timer_delete(last_man_standing_timer);
  1306. last_man_standing_timer_set = 0;
  1307. }
  1308. }
  1309. recalculate:
  1310. if ((new_node) ||
  1311. (nodeid == us->node_id) ||
  1312. (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_FIRST) ||
  1313. (old_votes != node->votes) ||
  1314. (old_expected != node->expected_votes) ||
  1315. (old_flags != node->flags) ||
  1316. (old_state != node->state)) {
  1317. recalculate_quorum(allow_downgrade, by_node);
  1318. }
  1319. if ((wait_for_all) &&
  1320. (!(req_exec_quorum_nodeinfo->flags & NODE_FLAGS_WFASTATUS)) &&
  1321. (req_exec_quorum_nodeinfo->flags & NODE_FLAGS_QUORATE)) {
  1322. update_wait_for_all_status(0);
  1323. }
  1324. LEAVE();
  1325. }
  1326. static void exec_votequorum_reconfigure_endian_convert (void *message)
  1327. {
  1328. struct req_exec_quorum_reconfigure *reconfigure = message;
  1329. ENTER();
  1330. reconfigure->nodeid = swab32(reconfigure->nodeid);
  1331. reconfigure->value = swab32(reconfigure->value);
  1332. LEAVE();
  1333. }
  1334. static void message_handler_req_exec_votequorum_reconfigure (
  1335. const void *message,
  1336. unsigned int nodeid)
  1337. {
  1338. const struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = message;
  1339. struct cluster_node *node;
  1340. struct list_head *nodelist;
  1341. ENTER();
  1342. log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %u for %u",
  1343. nodeid, req_exec_quorum_reconfigure->nodeid);
  1344. switch(req_exec_quorum_reconfigure->param)
  1345. {
  1346. case VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES:
  1347. list_iterate(nodelist, &cluster_members_list) {
  1348. node = list_entry(nodelist, struct cluster_node, list);
  1349. if (node->state == NODESTATE_MEMBER) {
  1350. node->expected_votes = req_exec_quorum_reconfigure->value;
  1351. }
  1352. }
  1353. votequorum_exec_send_expectedvotes_notification();
  1354. update_ev_barrier(req_exec_quorum_reconfigure->value);
  1355. recalculate_quorum(1, 0); /* Allow decrease */
  1356. break;
  1357. case VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES:
  1358. node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
  1359. if (!node) {
  1360. LEAVE();
  1361. return;
  1362. }
  1363. node->votes = req_exec_quorum_reconfigure->value;
  1364. recalculate_quorum(1, 0); /* Allow decrease */
  1365. break;
  1366. }
  1367. LEAVE();
  1368. }
  1369. static int votequorum_exec_exit_fn (void)
  1370. {
  1371. int ret = 0;
  1372. ENTER();
  1373. /*
  1374. * tell the other nodes we are leaving
  1375. */
  1376. if (allow_downscale) {
  1377. us->flags |= NODE_FLAGS_LEAVING;
  1378. ret = votequorum_exec_send_nodeinfo(us->node_id);
  1379. }
  1380. /*
  1381. * clean up our internals
  1382. */
  1383. /*
  1384. * free the node list and qdevice
  1385. */
  1386. list_init(&cluster_members_list);
  1387. qdevice = NULL;
  1388. us = NULL;
  1389. memset(cluster_nodes, 0, sizeof(cluster_nodes));
  1390. /*
  1391. * clean the tracking list
  1392. */
  1393. list_init(&trackers_list);
  1394. LEAVE();
  1395. return ret;
  1396. }
  1397. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api)
  1398. {
  1399. char *error = NULL;
  1400. #ifdef COROSYNC_SOLARIS
  1401. logsys_subsys_init();
  1402. #endif
  1403. ENTER();
  1404. list_init(&cluster_members_list);
  1405. list_init(&trackers_list);
  1406. /*
  1407. * Allocate a cluster_node for qdevice
  1408. */
  1409. qdevice = allocate_node(NODEID_QDEVICE);
  1410. if (!qdevice) {
  1411. LEAVE();
  1412. return ((char *)"Could not allocate node.");
  1413. }
  1414. qdevice->votes = 0;
  1415. memset(qdevice_name, 0, VOTEQUORUM_MAX_QDEVICE_NAME_LEN);
  1416. /*
  1417. * Allocate a cluster_node for us
  1418. */
  1419. us = allocate_node(corosync_api->totem_nodeid_get());
  1420. if (!us) {
  1421. LEAVE();
  1422. return ((char *)"Could not allocate node.");
  1423. }
  1424. icmap_set_uint32("runtime.votequorum.this_node_id", us->node_id);
  1425. us->state = NODESTATE_MEMBER;
  1426. us->votes = 1;
  1427. us->flags |= NODE_FLAGS_FIRST;
  1428. error = votequorum_readconfig(VOTEQUORUM_READCONFIG_STARTUP);
  1429. if (error) {
  1430. return error;
  1431. }
  1432. recalculate_quorum(0, 0);
  1433. /*
  1434. * Listen for changes
  1435. */
  1436. votequorum_exec_add_config_notification();
  1437. /*
  1438. * Start us off with one node
  1439. */
  1440. votequorum_exec_send_nodeinfo(us->node_id);
  1441. LEAVE();
  1442. return (NULL);
  1443. }
  1444. /*
  1445. * votequorum service core
  1446. */
  1447. static void votequorum_last_man_standing_timer_fn(void *arg)
  1448. {
  1449. ENTER();
  1450. last_man_standing_timer_set = 0;
  1451. if (cluster_is_quorate) {
  1452. recalculate_quorum(1,1);
  1453. }
  1454. LEAVE();
  1455. }
  1456. static void votequorum_confchg_fn (
  1457. enum totem_configuration_type configuration_type,
  1458. const unsigned int *member_list, size_t member_list_entries,
  1459. const unsigned int *left_list, size_t left_list_entries,
  1460. const unsigned int *joined_list, size_t joined_list_entries,
  1461. const struct memb_ring_id *ring_id)
  1462. {
  1463. int i;
  1464. struct cluster_node *node;
  1465. ENTER();
  1466. if (member_list_entries > 1) {
  1467. us->flags &= ~NODE_FLAGS_FIRST;
  1468. }
  1469. if (left_list_entries) {
  1470. for (i = 0; i< left_list_entries; i++) {
  1471. node = find_node_by_nodeid(left_list[i]);
  1472. if (node) {
  1473. node->state = NODESTATE_DEAD;
  1474. }
  1475. }
  1476. }
  1477. if (last_man_standing) {
  1478. if (((member_list_entries >= quorum) && (left_list_entries)) ||
  1479. ((member_list_entries <= quorum) && (auto_tie_breaker) && (check_low_node_id_partition() == 1))) {
  1480. if (last_man_standing_timer_set) {
  1481. corosync_api->timer_delete(last_man_standing_timer);
  1482. last_man_standing_timer_set = 0;
  1483. }
  1484. corosync_api->timer_add_duration((unsigned long long)last_man_standing_window*1000000,
  1485. NULL, votequorum_last_man_standing_timer_fn,
  1486. &last_man_standing_timer);
  1487. last_man_standing_timer_set = 1;
  1488. }
  1489. }
  1490. if (member_list_entries) {
  1491. memcpy(quorum_members, member_list, sizeof(unsigned int) * member_list_entries);
  1492. quorum_members_entries = member_list_entries;
  1493. votequorum_exec_send_nodeinfo(us->node_id);
  1494. votequorum_exec_send_nodeinfo(NODEID_QDEVICE);
  1495. if (strlen(qdevice_name)) {
  1496. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1497. qdevice_name);
  1498. }
  1499. }
  1500. memcpy(&quorum_ringid, ring_id, sizeof(*ring_id));
  1501. if (left_list_entries) {
  1502. recalculate_quorum(0, 0);
  1503. }
  1504. if (configuration_type == TOTEM_CONFIGURATION_REGULAR) {
  1505. quorum_callback(quorum_members, quorum_members_entries,
  1506. cluster_is_quorate, &quorum_ringid);
  1507. }
  1508. LEAVE();
  1509. }
  1510. char *votequorum_init(struct corosync_api_v1 *api,
  1511. quorum_set_quorate_fn_t q_set_quorate_fn)
  1512. {
  1513. char *error;
  1514. ENTER();
  1515. if (q_set_quorate_fn == NULL) {
  1516. return ((char *)"Quorate function not set");
  1517. }
  1518. corosync_api = api;
  1519. quorum_callback = q_set_quorate_fn;
  1520. error = corosync_service_link_and_init(corosync_api,
  1521. &votequorum_service[0]);
  1522. if (error) {
  1523. return (error);
  1524. }
  1525. LEAVE();
  1526. return (NULL);
  1527. }
  1528. /*
  1529. * Library Handler init/fini
  1530. */
  1531. static int quorum_lib_init_fn (void *conn)
  1532. {
  1533. struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1534. ENTER();
  1535. list_init (&pd->list);
  1536. pd->conn = conn;
  1537. LEAVE();
  1538. return (0);
  1539. }
  1540. static int quorum_lib_exit_fn (void *conn)
  1541. {
  1542. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1543. ENTER();
  1544. if (quorum_pd->tracking_enabled) {
  1545. list_del (&quorum_pd->list);
  1546. list_init (&quorum_pd->list);
  1547. }
  1548. LEAVE();
  1549. return (0);
  1550. }
  1551. /*
  1552. * library internal functions
  1553. */
  1554. static void qdevice_timer_fn(void *arg)
  1555. {
  1556. ENTER();
  1557. if ((!(us->flags & NODE_FLAGS_QDEVICE_ALIVE)) ||
  1558. (!qdevice_timer_set)) {
  1559. LEAVE();
  1560. return;
  1561. }
  1562. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1563. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1564. log_printf(LOGSYS_LEVEL_INFO, "lost contact with quorum device %s", qdevice_name);
  1565. votequorum_exec_send_nodeinfo(us->node_id);
  1566. qdevice_timer_set = 0;
  1567. LEAVE();
  1568. }
  1569. /*
  1570. * Library Handler Functions
  1571. */
  1572. static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *message)
  1573. {
  1574. const struct req_lib_votequorum_getinfo *req_lib_votequorum_getinfo = message;
  1575. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  1576. struct cluster_node *node;
  1577. unsigned int highest_expected = 0;
  1578. unsigned int total_votes = 0;
  1579. cs_error_t error = CS_OK;
  1580. uint32_t nodeid = req_lib_votequorum_getinfo->nodeid;
  1581. ENTER();
  1582. log_printf(LOGSYS_LEVEL_DEBUG, "got getinfo request on %p for node %u", conn, req_lib_votequorum_getinfo->nodeid);
  1583. if (nodeid == NODEID_QDEVICE) {
  1584. nodeid = us->node_id;
  1585. }
  1586. node = find_node_by_nodeid(nodeid);
  1587. if (node) {
  1588. struct cluster_node *iternode;
  1589. struct list_head *nodelist;
  1590. list_iterate(nodelist, &cluster_members_list) {
  1591. iternode = list_entry(nodelist, struct cluster_node, list);
  1592. if (iternode->state == NODESTATE_MEMBER) {
  1593. highest_expected =
  1594. max(highest_expected, iternode->expected_votes);
  1595. total_votes += iternode->votes;
  1596. }
  1597. }
  1598. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1599. total_votes += qdevice->votes;
  1600. }
  1601. res_lib_votequorum_getinfo.state = node->state;
  1602. res_lib_votequorum_getinfo.votes = node->votes;
  1603. res_lib_votequorum_getinfo.expected_votes = node->expected_votes;
  1604. res_lib_votequorum_getinfo.highest_expected = highest_expected;
  1605. res_lib_votequorum_getinfo.quorum = quorum;
  1606. res_lib_votequorum_getinfo.total_votes = total_votes;
  1607. res_lib_votequorum_getinfo.flags = 0;
  1608. res_lib_votequorum_getinfo.nodeid = node->node_id;
  1609. if (two_node) {
  1610. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_FLAG_TWONODE;
  1611. }
  1612. if (cluster_is_quorate) {
  1613. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_FLAG_QUORATE;
  1614. }
  1615. if (wait_for_all) {
  1616. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_WAIT_FOR_ALL;
  1617. }
  1618. if (last_man_standing) {
  1619. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_LAST_MAN_STANDING;
  1620. }
  1621. if (auto_tie_breaker) {
  1622. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_AUTO_TIE_BREAKER;
  1623. }
  1624. if (allow_downscale) {
  1625. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_LEAVE_REMOVE;
  1626. }
  1627. if (node->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1628. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_REGISTERED;
  1629. }
  1630. if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  1631. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_ALIVE;
  1632. }
  1633. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1634. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_CAST_VOTE;
  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 (us->flags & NODE_FLAGS_QDEVICE_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 (us->flags & NODE_FLAGS_QDEVICE_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. us->flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
  1833. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1834. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1835. votequorum_exec_send_nodeinfo(us->node_id);
  1836. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER,
  1837. req_lib_votequorum_qdevice_unregister->name);
  1838. } else {
  1839. error = CS_ERR_NOT_EXIST;
  1840. }
  1841. out:
  1842. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1843. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1844. res_lib_votequorum_status.header.error = error;
  1845. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1846. LEAVE();
  1847. }
  1848. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  1849. const void *message)
  1850. {
  1851. const struct req_lib_votequorum_qdevice_update *req_lib_votequorum_qdevice_update = message;
  1852. struct res_lib_votequorum_status res_lib_votequorum_status;
  1853. cs_error_t error = CS_OK;
  1854. ENTER();
  1855. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1856. if (strncmp(req_lib_votequorum_qdevice_update->oldname, qdevice_name, VOTEQUORUM_MAX_QDEVICE_NAME_LEN)) {
  1857. error = CS_ERR_INVALID_PARAM;
  1858. goto out;
  1859. }
  1860. votequorum_exec_send_qdevice_reconfigure(req_lib_votequorum_qdevice_update->oldname,
  1861. req_lib_votequorum_qdevice_update->newname);
  1862. } else {
  1863. error = CS_ERR_NOT_EXIST;
  1864. }
  1865. out:
  1866. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1867. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1868. res_lib_votequorum_status.header.error = error;
  1869. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1870. LEAVE();
  1871. }
  1872. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  1873. const void *message)
  1874. {
  1875. const struct req_lib_votequorum_qdevice_poll *req_lib_votequorum_qdevice_poll = message;
  1876. struct res_lib_votequorum_status res_lib_votequorum_status;
  1877. cs_error_t error = CS_OK;
  1878. uint32_t oldflags;
  1879. ENTER();
  1880. if (!qdevice_can_operate) {
  1881. error = CS_ERR_ACCESS;
  1882. goto out;
  1883. }
  1884. if (us->flags & NODE_FLAGS_QDEVICE_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. oldflags = us->flags;
  1894. us->flags |= NODE_FLAGS_QDEVICE_ALIVE;
  1895. if (req_lib_votequorum_qdevice_poll->cast_vote) {
  1896. us->flags |= NODE_FLAGS_QDEVICE_CAST_VOTE;
  1897. } else {
  1898. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1899. }
  1900. if (us->flags != oldflags) {
  1901. votequorum_exec_send_nodeinfo(us->node_id);
  1902. }
  1903. corosync_api->timer_add_duration((unsigned long long)qdevice_timeout*1000000, qdevice,
  1904. qdevice_timer_fn, &qdevice_timer);
  1905. qdevice_timer_set = 1;
  1906. } else {
  1907. error = CS_ERR_NOT_EXIST;
  1908. }
  1909. out:
  1910. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1911. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1912. res_lib_votequorum_status.header.error = error;
  1913. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1914. LEAVE();
  1915. }
  1916. static void message_handler_req_lib_votequorum_qdevice_getinfo (void *conn,
  1917. const void *message)
  1918. {
  1919. const struct req_lib_votequorum_qdevice_getinfo *req_lib_votequorum_qdevice_getinfo = message;
  1920. struct res_lib_votequorum_qdevice_getinfo res_lib_votequorum_qdevice_getinfo;
  1921. cs_error_t error = CS_OK;
  1922. struct cluster_node *node;
  1923. uint32_t nodeid = req_lib_votequorum_qdevice_getinfo->nodeid;
  1924. ENTER();
  1925. if (nodeid == NODEID_QDEVICE) {
  1926. nodeid = us->node_id;
  1927. }
  1928. node = find_node_by_nodeid(nodeid);
  1929. if ((node) &&
  1930. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1931. int alive_status = 0, vote_status = 0;
  1932. if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  1933. alive_status = 1;
  1934. }
  1935. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1936. vote_status = 1;
  1937. }
  1938. log_printf(LOGSYS_LEVEL_DEBUG, "got qdevice_getinfo node %u alive_status %d vote_status %d",
  1939. nodeid, alive_status, vote_status);
  1940. res_lib_votequorum_qdevice_getinfo.votes = qdevice->votes;
  1941. res_lib_votequorum_qdevice_getinfo.alive = alive_status;
  1942. res_lib_votequorum_qdevice_getinfo.cast_vote = vote_status;
  1943. strcpy(res_lib_votequorum_qdevice_getinfo.name, qdevice_name);
  1944. } else {
  1945. error = CS_ERR_NOT_EXIST;
  1946. }
  1947. res_lib_votequorum_qdevice_getinfo.header.size = sizeof(res_lib_votequorum_qdevice_getinfo);
  1948. res_lib_votequorum_qdevice_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  1949. res_lib_votequorum_qdevice_getinfo.header.error = error;
  1950. corosync_api->ipc_response_send(conn, &res_lib_votequorum_qdevice_getinfo, sizeof(res_lib_votequorum_qdevice_getinfo));
  1951. LEAVE();
  1952. }