votequorum.c 66 KB

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