votequorum.c 66 KB

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