4
0

votequorum.c 67 KB

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