votequorum.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503
  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. ENTER();
  752. if ((icmap_get_string("quorum.device.model", &qdevice_model) == CS_OK) &&
  753. (strlen(qdevice_model))) {
  754. free(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. return 1;
  763. }
  764. LEAVE();
  765. return 0;
  766. }
  767. #define VOTEQUORUM_READCONFIG_STARTUP 0
  768. #define VOTEQUORUM_READCONFIG_RUNTIME 1
  769. static char *votequorum_readconfig(int runtime)
  770. {
  771. uint32_t node_votes = 0, qdevice_votes = 0;
  772. uint32_t node_expected_votes = 0, expected_votes = 0;
  773. uint32_t node_count = 0;
  774. int have_nodelist, have_qdevice;
  775. char *error = NULL;
  776. ENTER();
  777. log_printf(LOGSYS_LEVEL_DEBUG, "Reading configuration (runtime: %d)", runtime);
  778. /*
  779. * gather basic data here
  780. */
  781. icmap_get_uint32("quorum.expected_votes", &expected_votes);
  782. have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
  783. have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
  784. icmap_get_uint8("quorum.two_node", &two_node);
  785. /*
  786. * do config verification and enablement
  787. */
  788. if ((!have_nodelist) && (!expected_votes)) {
  789. if (!runtime) {
  790. error = (char *)"configuration error: nodelist or quorum.expected_votes must be configured!";
  791. } else {
  792. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: nodelist or quorum.expected_votes must be configured!");
  793. log_printf(LOGSYS_LEVEL_CRIT, "will continue with current runtime data");
  794. }
  795. goto out;
  796. }
  797. /*
  798. * two_node and qdevice are not compatible in the same config.
  799. * try to make an educated guess of what to do
  800. */
  801. if ((two_node) && (have_qdevice)) {
  802. if (!runtime) {
  803. error = (char *)"configuration error: two_node and quorum device cannot be configured at the same time!";
  804. goto out;
  805. } else {
  806. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: two_node and quorum device cannot be configured at the same time!");
  807. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  808. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is registered, disabling two_node");
  809. two_node = 0;
  810. } else {
  811. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is not registered, allowing two_node");
  812. update_qdevice_can_operate(0);
  813. }
  814. }
  815. }
  816. /*
  817. * Enable special features
  818. */
  819. if (!runtime) {
  820. if (two_node) {
  821. wait_for_all = 1;
  822. }
  823. icmap_get_uint8("quorum.allow_downscale", &allow_downscale);
  824. icmap_get_uint8("quorum.wait_for_all", &wait_for_all);
  825. icmap_get_uint8("quorum.auto_tie_breaker", &auto_tie_breaker);
  826. icmap_get_uint8("quorum.last_man_standing", &last_man_standing);
  827. icmap_get_uint32("quorum.last_man_standing_window", &last_man_standing_window);
  828. }
  829. /*
  830. * quorum device is not compatible with last_man_standing and auto_tie_breaker
  831. * neither lms or atb can be set at runtime, so there is no need to check for
  832. * runtime incompatibilities, but qdevice can be configured _after_ LMS and ATB have
  833. * been enabled at startup.
  834. */
  835. if ((have_qdevice) && (last_man_standing)) {
  836. if (!runtime) {
  837. error = (char *)"configuration error: quorum.device is not compatible with last_man_standing";
  838. goto out;
  839. } else {
  840. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with last_man_standing");
  841. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  842. update_qdevice_can_operate(0);
  843. }
  844. }
  845. if ((have_qdevice) && (auto_tie_breaker)) {
  846. if (!runtime) {
  847. error = (char *)"configuration error: quorum.device is not compatible with auto_tie_breaker";
  848. goto out;
  849. } else {
  850. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with auto_tie_breaker");
  851. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  852. update_qdevice_can_operate(0);
  853. }
  854. }
  855. if ((have_qdevice) && (wait_for_all)) {
  856. if (!runtime) {
  857. error = (char *)"configuration error: quorum.device is not compatible with wait_for_all";
  858. goto out;
  859. } else {
  860. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with wait_for_all");
  861. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  862. update_qdevice_can_operate(0);
  863. }
  864. }
  865. if ((have_qdevice) && (allow_downscale)) {
  866. if (!runtime) {
  867. error = (char *)"configuration error: quorum.device is not compatible with allow_downscale";
  868. goto out;
  869. } else {
  870. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with allow_downscale");
  871. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  872. update_qdevice_can_operate(0);
  873. }
  874. }
  875. /*
  876. * if user specifies quorum.expected_votes + quorum.device but NOT the device.votes
  877. * we don't know what the quorum device should vote.
  878. */
  879. if ((expected_votes) && (have_qdevice) && (qdevice_votes == -1)) {
  880. if (!runtime) {
  881. error = (char *)"configuration error: quorum.device.votes must be specified when quorum.expected_votes is set";
  882. goto out;
  883. } else {
  884. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when quorum.expected_votes is set");
  885. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  886. update_qdevice_can_operate(0);
  887. }
  888. }
  889. /*
  890. * if user specifies a node list with uneven votes and no device.votes
  891. * we cannot autocalculate the votes
  892. */
  893. if ((have_qdevice) &&
  894. (qdevice_votes == -1) &&
  895. (have_nodelist) &&
  896. (node_count != node_expected_votes)) {
  897. if (!runtime) {
  898. error = (char *)"configuration error: quorum.device.votes must be specified when not all nodes votes 1";
  899. goto out;
  900. } else {
  901. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when not all nodes votes 1");
  902. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  903. update_qdevice_can_operate(0);
  904. }
  905. }
  906. /*
  907. * validate quorum device votes vs expected_votes
  908. */
  909. if ((qdevice_votes > 0) && (expected_votes)) {
  910. int delta = expected_votes - qdevice_votes;
  911. if (delta < 2) {
  912. if (!runtime) {
  913. error = (char *)"configuration error: quorum.device.votes is too high or expected_votes is too low";
  914. goto out;
  915. } else {
  916. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes is too high or expected_votes is too low");
  917. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  918. update_qdevice_can_operate(0);
  919. }
  920. }
  921. }
  922. /*
  923. * automatically calculate device votes and adjust expected_votes from nodelist
  924. */
  925. if ((have_qdevice) &&
  926. (qdevice_votes == -1) &&
  927. (!expected_votes) &&
  928. (have_nodelist) &&
  929. (node_count == node_expected_votes)) {
  930. qdevice_votes = node_expected_votes - 1;
  931. node_expected_votes = node_expected_votes + qdevice_votes;
  932. }
  933. /*
  934. * set this node votes and expected_votes
  935. */
  936. if (have_nodelist) {
  937. us->votes = node_votes;
  938. us->expected_votes = node_expected_votes;
  939. } else {
  940. us->votes = 1;
  941. icmap_get_uint32("quorum.votes", &us->votes);
  942. }
  943. if (expected_votes) {
  944. us->expected_votes = expected_votes;
  945. }
  946. /*
  947. * set qdevice votes
  948. */
  949. if (!have_qdevice) {
  950. qdevice->votes = 0;
  951. }
  952. if (qdevice_votes != -1) {
  953. qdevice->votes = qdevice_votes;
  954. }
  955. update_ev_barrier(us->expected_votes);
  956. update_two_node();
  957. if (wait_for_all) {
  958. update_wait_for_all_status(1);
  959. }
  960. out:
  961. LEAVE();
  962. return error;
  963. }
  964. static void votequorum_refresh_config(
  965. int32_t event,
  966. const char *key_name,
  967. struct icmap_notify_value new_val,
  968. struct icmap_notify_value old_val,
  969. void *user_data)
  970. {
  971. int old_votes, old_expected_votes;
  972. ENTER();
  973. old_votes = us->votes;
  974. old_expected_votes = us->expected_votes;
  975. /*
  976. * Reload the configuration
  977. */
  978. votequorum_readconfig(VOTEQUORUM_READCONFIG_RUNTIME);
  979. /*
  980. * activate new config
  981. */
  982. votequorum_exec_send_nodeinfo(us->node_id);
  983. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  984. if (us->votes != old_votes) {
  985. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES,
  986. us->node_id, us->votes);
  987. }
  988. if (us->expected_votes != old_expected_votes) {
  989. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES,
  990. us->node_id, us->expected_votes);
  991. }
  992. LEAVE();
  993. }
  994. static void votequorum_exec_add_config_notification(void)
  995. {
  996. icmap_track_t icmap_track_nodelist = NULL;
  997. icmap_track_t icmap_track_quorum = NULL;
  998. ENTER();
  999. icmap_track_add("nodelist.",
  1000. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1001. votequorum_refresh_config,
  1002. NULL,
  1003. &icmap_track_nodelist);
  1004. icmap_track_add("quorum.",
  1005. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1006. votequorum_refresh_config,
  1007. NULL,
  1008. &icmap_track_quorum);
  1009. LEAVE();
  1010. }
  1011. /*
  1012. * votequorum_exec core
  1013. */
  1014. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value)
  1015. {
  1016. struct req_exec_quorum_reconfigure req_exec_quorum_reconfigure;
  1017. struct iovec iov[1];
  1018. int ret;
  1019. ENTER();
  1020. req_exec_quorum_reconfigure.nodeid = nodeid;
  1021. req_exec_quorum_reconfigure.value = value;
  1022. req_exec_quorum_reconfigure.param = param;
  1023. req_exec_quorum_reconfigure._pad0 = 0;
  1024. req_exec_quorum_reconfigure._pad1 = 0;
  1025. req_exec_quorum_reconfigure._pad2 = 0;
  1026. req_exec_quorum_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE);
  1027. req_exec_quorum_reconfigure.header.size = sizeof(req_exec_quorum_reconfigure);
  1028. iov[0].iov_base = (void *)&req_exec_quorum_reconfigure;
  1029. iov[0].iov_len = sizeof(req_exec_quorum_reconfigure);
  1030. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1031. LEAVE();
  1032. return ret;
  1033. }
  1034. static int votequorum_exec_send_nodeinfo(uint32_t nodeid)
  1035. {
  1036. struct req_exec_quorum_nodeinfo req_exec_quorum_nodeinfo;
  1037. struct iovec iov[1];
  1038. struct cluster_node *node;
  1039. int ret;
  1040. ENTER();
  1041. node = find_node_by_nodeid(nodeid);
  1042. if (!node) {
  1043. return -1;
  1044. }
  1045. req_exec_quorum_nodeinfo.nodeid = nodeid;
  1046. req_exec_quorum_nodeinfo.votes = node->votes;
  1047. req_exec_quorum_nodeinfo.expected_votes = node->expected_votes;
  1048. req_exec_quorum_nodeinfo.flags = node->flags;
  1049. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  1050. decode_flags(node->flags);
  1051. }
  1052. req_exec_quorum_nodeinfo.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO);
  1053. req_exec_quorum_nodeinfo.header.size = sizeof(req_exec_quorum_nodeinfo);
  1054. iov[0].iov_base = (void *)&req_exec_quorum_nodeinfo;
  1055. iov[0].iov_len = sizeof(req_exec_quorum_nodeinfo);
  1056. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1057. LEAVE();
  1058. return ret;
  1059. }
  1060. static int votequorum_exec_send_qdevice_reconfigure(const char *oldname, const char *newname)
  1061. {
  1062. struct req_exec_quorum_qdevice_reconfigure req_exec_quorum_qdevice_reconfigure;
  1063. struct iovec iov[1];
  1064. int ret;
  1065. ENTER();
  1066. req_exec_quorum_qdevice_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE);
  1067. req_exec_quorum_qdevice_reconfigure.header.size = sizeof(req_exec_quorum_qdevice_reconfigure);
  1068. strcpy(req_exec_quorum_qdevice_reconfigure.oldname, oldname);
  1069. strcpy(req_exec_quorum_qdevice_reconfigure.newname, newname);
  1070. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reconfigure;
  1071. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reconfigure);
  1072. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1073. LEAVE();
  1074. return ret;
  1075. }
  1076. static int votequorum_exec_send_qdevice_reg(uint32_t operation, const char *qdevice_name_req)
  1077. {
  1078. struct req_exec_quorum_qdevice_reg req_exec_quorum_qdevice_reg;
  1079. struct iovec iov[1];
  1080. int ret;
  1081. ENTER();
  1082. req_exec_quorum_qdevice_reg.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG);
  1083. req_exec_quorum_qdevice_reg.header.size = sizeof(req_exec_quorum_qdevice_reg);
  1084. req_exec_quorum_qdevice_reg.operation = operation;
  1085. strcpy(req_exec_quorum_qdevice_reg.qdevice_name, qdevice_name_req);
  1086. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reg;
  1087. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reg);
  1088. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1089. LEAVE();
  1090. return ret;
  1091. }
  1092. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context)
  1093. {
  1094. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  1095. struct list_head *tmp;
  1096. struct cluster_node *node;
  1097. int cluster_members = 0;
  1098. int i = 0;
  1099. int size;
  1100. char buf[sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * (PROCESSOR_COUNT_MAX + 2)];
  1101. ENTER();
  1102. list_iterate(tmp, &cluster_members_list) {
  1103. node = list_entry(tmp, struct cluster_node, list);
  1104. cluster_members++;
  1105. }
  1106. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1107. cluster_members++;
  1108. }
  1109. size = sizeof(struct res_lib_votequorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  1110. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)&buf;
  1111. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  1112. res_lib_votequorum_notification->node_list_entries = cluster_members;
  1113. res_lib_votequorum_notification->context = context;
  1114. list_iterate(tmp, &cluster_members_list) {
  1115. node = list_entry(tmp, struct cluster_node, list);
  1116. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  1117. res_lib_votequorum_notification->node_list[i++].state = node->state;
  1118. }
  1119. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1120. res_lib_votequorum_notification->node_list[i].nodeid = VOTEQUORUM_QDEVICE_NODEID;
  1121. res_lib_votequorum_notification->node_list[i++].state = qdevice->state;
  1122. }
  1123. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NOTIFICATION;
  1124. res_lib_votequorum_notification->header.size = size;
  1125. res_lib_votequorum_notification->header.error = CS_OK;
  1126. /* Send it to all interested parties */
  1127. if (conn) {
  1128. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1129. LEAVE();
  1130. return ret;
  1131. } else {
  1132. struct quorum_pd *qpd;
  1133. list_iterate(tmp, &trackers_list) {
  1134. qpd = list_entry(tmp, struct quorum_pd, list);
  1135. res_lib_votequorum_notification->context = qpd->tracking_context;
  1136. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1137. }
  1138. }
  1139. LEAVE();
  1140. return 0;
  1141. }
  1142. static void votequorum_exec_send_expectedvotes_notification(void)
  1143. {
  1144. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  1145. struct quorum_pd *qpd;
  1146. struct list_head *tmp;
  1147. ENTER();
  1148. log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback");
  1149. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  1150. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  1151. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  1152. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  1153. list_iterate(tmp, &trackers_list) {
  1154. qpd = list_entry(tmp, struct quorum_pd, list);
  1155. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  1156. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  1157. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  1158. }
  1159. LEAVE();
  1160. }
  1161. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message)
  1162. {
  1163. ENTER();
  1164. LEAVE();
  1165. }
  1166. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  1167. const void *message,
  1168. unsigned int nodeid)
  1169. {
  1170. const struct req_exec_quorum_qdevice_reconfigure *req_exec_quorum_qdevice_reconfigure = message;
  1171. ENTER();
  1172. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice name change req from node %u [from: %s to: %s]",
  1173. nodeid,
  1174. req_exec_quorum_qdevice_reconfigure->oldname,
  1175. req_exec_quorum_qdevice_reconfigure->newname);
  1176. if (!strcmp(req_exec_quorum_qdevice_reconfigure->oldname, qdevice_name)) {
  1177. log_printf(LOGSYS_LEVEL_DEBUG, "Allowing qdevice rename");
  1178. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1179. strcpy(qdevice_name, req_exec_quorum_qdevice_reconfigure->newname);
  1180. /*
  1181. * TODO: notify qdevices about name change?
  1182. * this is not relevant for now and can wait later on since
  1183. * qdevices are local only and libvotequorum is not final
  1184. */
  1185. }
  1186. LEAVE();
  1187. }
  1188. static void exec_votequorum_qdevice_reg_endian_convert (void *message)
  1189. {
  1190. struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1191. ENTER();
  1192. req_exec_quorum_qdevice_reg->operation = swab32(req_exec_quorum_qdevice_reg->operation);
  1193. LEAVE();
  1194. }
  1195. static void message_handler_req_exec_votequorum_qdevice_reg (
  1196. const void *message,
  1197. unsigned int nodeid)
  1198. {
  1199. const struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1200. struct res_lib_votequorum_status res_lib_votequorum_status;
  1201. int wipe_qdevice_name = 1;
  1202. struct cluster_node *node = NULL;
  1203. struct list_head *tmp;
  1204. cs_error_t error = CS_OK;
  1205. ENTER();
  1206. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice op %u req from node %u [%s]",
  1207. req_exec_quorum_qdevice_reg->operation,
  1208. nodeid, req_exec_quorum_qdevice_reg->qdevice_name);
  1209. switch(req_exec_quorum_qdevice_reg->operation)
  1210. {
  1211. case VOTEQUORUM_QDEVICE_OPERATION_REGISTER:
  1212. if (nodeid != us->node_id) {
  1213. if (!strlen(qdevice_name)) {
  1214. log_printf(LOGSYS_LEVEL_DEBUG, "Remote qdevice name recorded");
  1215. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1216. }
  1217. LEAVE();
  1218. return;
  1219. }
  1220. /*
  1221. * protect against the case where we broadcast qdevice registration
  1222. * to new memebers, we receive the message back, but there is no registration
  1223. * connection in progress
  1224. */
  1225. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1226. LEAVE();
  1227. return;
  1228. }
  1229. /*
  1230. * this should NEVER happen
  1231. */
  1232. if (!qdevice_reg_conn) {
  1233. log_printf(LOGSYS_LEVEL_WARNING, "Unable to determine origin of the qdevice register call!");
  1234. LEAVE();
  1235. return;
  1236. }
  1237. /*
  1238. * registering our own device in this case
  1239. */
  1240. if (!strlen(qdevice_name)) {
  1241. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1242. }
  1243. /*
  1244. * check if it is our device or something else
  1245. */
  1246. if ((!strncmp(req_exec_quorum_qdevice_reg->qdevice_name,
  1247. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  1248. us->flags |= NODE_FLAGS_QDEVICE_REGISTERED;
  1249. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1250. votequorum_exec_send_nodeinfo(us->node_id);
  1251. } else {
  1252. log_printf(LOGSYS_LEVEL_WARNING,
  1253. "A new qdevice with different name (new: %s old: %s) is trying to register!",
  1254. req_exec_quorum_qdevice_reg->qdevice_name, qdevice_name);
  1255. error = CS_ERR_EXIST;
  1256. }
  1257. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1258. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1259. res_lib_votequorum_status.header.error = error;
  1260. corosync_api->ipc_response_send(qdevice_reg_conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1261. qdevice_reg_conn = NULL;
  1262. break;
  1263. case VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER:
  1264. list_iterate(tmp, &cluster_members_list) {
  1265. node = list_entry(tmp, struct cluster_node, list);
  1266. if ((node->state == NODESTATE_MEMBER) &&
  1267. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1268. wipe_qdevice_name = 0;
  1269. }
  1270. }
  1271. if (wipe_qdevice_name) {
  1272. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1273. }
  1274. break;
  1275. }
  1276. LEAVE();
  1277. }
  1278. static void exec_votequorum_nodeinfo_endian_convert (void *message)
  1279. {
  1280. struct req_exec_quorum_nodeinfo *nodeinfo = message;
  1281. ENTER();
  1282. nodeinfo->nodeid = swab32(nodeinfo->nodeid);
  1283. nodeinfo->votes = swab32(nodeinfo->votes);
  1284. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  1285. nodeinfo->flags = swab32(nodeinfo->flags);
  1286. LEAVE();
  1287. }
  1288. static void message_handler_req_exec_votequorum_nodeinfo (
  1289. const void *message,
  1290. unsigned int sender_nodeid)
  1291. {
  1292. const struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = message;
  1293. struct cluster_node *node = NULL;
  1294. int old_votes;
  1295. int old_expected;
  1296. uint32_t old_flags;
  1297. nodestate_t old_state;
  1298. int new_node = 0;
  1299. int allow_downgrade = 0;
  1300. int by_node = 0;
  1301. unsigned int nodeid = req_exec_quorum_nodeinfo->nodeid;
  1302. ENTER();
  1303. log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %u", sender_nodeid);
  1304. log_printf(LOGSYS_LEVEL_DEBUG, "nodeinfo message[%u]: votes: %d, expected: %d flags: %d",
  1305. nodeid,
  1306. req_exec_quorum_nodeinfo->votes,
  1307. req_exec_quorum_nodeinfo->expected_votes,
  1308. req_exec_quorum_nodeinfo->flags);
  1309. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  1310. decode_flags(req_exec_quorum_nodeinfo->flags);
  1311. }
  1312. node = find_node_by_nodeid(nodeid);
  1313. if (!node) {
  1314. node = allocate_node(nodeid);
  1315. new_node = 1;
  1316. }
  1317. if (!node) {
  1318. corosync_api->error_memory_failure();
  1319. LEAVE();
  1320. return;
  1321. }
  1322. if (new_node) {
  1323. old_votes = 0;
  1324. old_expected = 0;
  1325. old_state = NODESTATE_DEAD;
  1326. old_flags = 0;
  1327. } else {
  1328. old_votes = node->votes;
  1329. old_expected = node->expected_votes;
  1330. old_state = node->state;
  1331. old_flags = node->flags;
  1332. }
  1333. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  1334. struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
  1335. if ((!cluster_is_quorate) &&
  1336. (sender_node->flags & NODE_FLAGS_QUORATE)) {
  1337. node->votes = req_exec_quorum_nodeinfo->votes;
  1338. } else {
  1339. node->votes = max(node->votes, req_exec_quorum_nodeinfo->votes);
  1340. }
  1341. goto recalculate;
  1342. }
  1343. /* Update node state */
  1344. node->flags = req_exec_quorum_nodeinfo->flags;
  1345. node->votes = req_exec_quorum_nodeinfo->votes;
  1346. node->state = NODESTATE_MEMBER;
  1347. if (node->flags & NODE_FLAGS_LEAVING) {
  1348. node->state = NODESTATE_LEAVING;
  1349. allow_downgrade = 1;
  1350. by_node = 1;
  1351. }
  1352. if ((!cluster_is_quorate) &&
  1353. (node->flags & NODE_FLAGS_QUORATE)) {
  1354. allow_downgrade = 1;
  1355. us->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1356. }
  1357. if (node->flags & NODE_FLAGS_QUORATE) {
  1358. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1359. } else {
  1360. node->expected_votes = us->expected_votes;
  1361. }
  1362. if ((last_man_standing) && (node->votes > 1)) {
  1363. log_printf(LOGSYS_LEVEL_WARNING, "Last Man Standing feature is supported only when all"
  1364. "cluster nodes votes are set to 1. Disabling LMS.");
  1365. last_man_standing = 0;
  1366. if (last_man_standing_timer_set) {
  1367. corosync_api->timer_delete(last_man_standing_timer);
  1368. last_man_standing_timer_set = 0;
  1369. }
  1370. }
  1371. recalculate:
  1372. if ((new_node) ||
  1373. (nodeid == us->node_id) ||
  1374. (node->flags & NODE_FLAGS_FIRST) ||
  1375. (old_votes != node->votes) ||
  1376. (old_expected != node->expected_votes) ||
  1377. (old_flags != node->flags) ||
  1378. (old_state != node->state)) {
  1379. recalculate_quorum(allow_downgrade, by_node);
  1380. }
  1381. if ((wait_for_all) &&
  1382. (!(node->flags & NODE_FLAGS_WFASTATUS)) &&
  1383. (node->flags & NODE_FLAGS_QUORATE)) {
  1384. update_wait_for_all_status(0);
  1385. }
  1386. LEAVE();
  1387. }
  1388. static void exec_votequorum_reconfigure_endian_convert (void *message)
  1389. {
  1390. struct req_exec_quorum_reconfigure *reconfigure = message;
  1391. ENTER();
  1392. reconfigure->nodeid = swab32(reconfigure->nodeid);
  1393. reconfigure->value = swab32(reconfigure->value);
  1394. LEAVE();
  1395. }
  1396. static void message_handler_req_exec_votequorum_reconfigure (
  1397. const void *message,
  1398. unsigned int nodeid)
  1399. {
  1400. const struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = message;
  1401. struct cluster_node *node;
  1402. struct list_head *nodelist;
  1403. ENTER();
  1404. log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %u for %u",
  1405. nodeid, req_exec_quorum_reconfigure->nodeid);
  1406. switch(req_exec_quorum_reconfigure->param)
  1407. {
  1408. case VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES:
  1409. list_iterate(nodelist, &cluster_members_list) {
  1410. node = list_entry(nodelist, struct cluster_node, list);
  1411. if (node->state == NODESTATE_MEMBER) {
  1412. node->expected_votes = req_exec_quorum_reconfigure->value;
  1413. }
  1414. }
  1415. votequorum_exec_send_expectedvotes_notification();
  1416. update_ev_barrier(req_exec_quorum_reconfigure->value);
  1417. recalculate_quorum(1, 0); /* Allow decrease */
  1418. break;
  1419. case VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES:
  1420. node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
  1421. if (!node) {
  1422. LEAVE();
  1423. return;
  1424. }
  1425. node->votes = req_exec_quorum_reconfigure->value;
  1426. recalculate_quorum(1, 0); /* Allow decrease */
  1427. break;
  1428. }
  1429. LEAVE();
  1430. }
  1431. static int votequorum_exec_exit_fn (void)
  1432. {
  1433. int ret = 0;
  1434. ENTER();
  1435. /*
  1436. * tell the other nodes we are leaving
  1437. */
  1438. if (allow_downscale) {
  1439. us->flags |= NODE_FLAGS_LEAVING;
  1440. ret = votequorum_exec_send_nodeinfo(us->node_id);
  1441. }
  1442. LEAVE();
  1443. return ret;
  1444. }
  1445. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api)
  1446. {
  1447. char *error = NULL;
  1448. ENTER();
  1449. /*
  1450. * make sure we start clean
  1451. */
  1452. list_init(&cluster_members_list);
  1453. list_init(&trackers_list);
  1454. qdevice = NULL;
  1455. us = NULL;
  1456. memset(cluster_nodes, 0, sizeof(cluster_nodes));
  1457. /*
  1458. * Allocate a cluster_node for qdevice
  1459. */
  1460. qdevice = allocate_node(VOTEQUORUM_QDEVICE_NODEID);
  1461. if (!qdevice) {
  1462. LEAVE();
  1463. return ((char *)"Could not allocate node.");
  1464. }
  1465. qdevice->votes = 0;
  1466. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1467. /*
  1468. * Allocate a cluster_node for us
  1469. */
  1470. us = allocate_node(corosync_api->totem_nodeid_get());
  1471. if (!us) {
  1472. LEAVE();
  1473. return ((char *)"Could not allocate node.");
  1474. }
  1475. icmap_set_uint32("runtime.votequorum.this_node_id", us->node_id);
  1476. us->state = NODESTATE_MEMBER;
  1477. us->votes = 1;
  1478. us->flags |= NODE_FLAGS_FIRST;
  1479. error = votequorum_readconfig(VOTEQUORUM_READCONFIG_STARTUP);
  1480. if (error) {
  1481. return error;
  1482. }
  1483. recalculate_quorum(0, 0);
  1484. /*
  1485. * Listen for changes
  1486. */
  1487. votequorum_exec_add_config_notification();
  1488. /*
  1489. * Start us off with one node
  1490. */
  1491. votequorum_exec_send_nodeinfo(us->node_id);
  1492. LEAVE();
  1493. return (NULL);
  1494. }
  1495. /*
  1496. * votequorum service core
  1497. */
  1498. static void votequorum_last_man_standing_timer_fn(void *arg)
  1499. {
  1500. ENTER();
  1501. last_man_standing_timer_set = 0;
  1502. if (cluster_is_quorate) {
  1503. recalculate_quorum(1,1);
  1504. }
  1505. LEAVE();
  1506. }
  1507. static void votequorum_sync_init (
  1508. const unsigned int *trans_list, size_t trans_list_entries,
  1509. const unsigned int *member_list, size_t member_list_entries,
  1510. const struct memb_ring_id *ring_id)
  1511. {
  1512. int i, j;
  1513. int found;
  1514. int left_nodes;
  1515. struct cluster_node *node;
  1516. ENTER();
  1517. sync_in_progress = 1;
  1518. if (member_list_entries > 1) {
  1519. us->flags &= ~NODE_FLAGS_FIRST;
  1520. }
  1521. /*
  1522. * we don't need to track which nodes have left directly,
  1523. * since that info is in the node db, but we need to know
  1524. * if somebody has left for last_man_standing
  1525. */
  1526. left_nodes = 0;
  1527. for (i = 0; i < quorum_members_entries; i++) {
  1528. found = 0;
  1529. for (j = 0; j < member_list_entries; j++) {
  1530. if (quorum_members[i] == member_list[j]) {
  1531. found = 1;
  1532. break;
  1533. }
  1534. }
  1535. if (found == 0) {
  1536. left_nodes = 1;
  1537. node = find_node_by_nodeid(quorum_members[i]);
  1538. if (node) {
  1539. node->state = NODESTATE_DEAD;
  1540. }
  1541. }
  1542. }
  1543. if (last_man_standing) {
  1544. if (((member_list_entries >= quorum) && (left_nodes)) ||
  1545. ((member_list_entries <= quorum) && (auto_tie_breaker) && (check_low_node_id_partition() == 1))) {
  1546. if (last_man_standing_timer_set) {
  1547. corosync_api->timer_delete(last_man_standing_timer);
  1548. last_man_standing_timer_set = 0;
  1549. }
  1550. corosync_api->timer_add_duration((unsigned long long)last_man_standing_window*1000000,
  1551. NULL, votequorum_last_man_standing_timer_fn,
  1552. &last_man_standing_timer);
  1553. last_man_standing_timer_set = 1;
  1554. }
  1555. }
  1556. memcpy(quorum_members, member_list, sizeof(unsigned int) * member_list_entries);
  1557. quorum_members_entries = member_list_entries;
  1558. memcpy(&quorum_ringid, ring_id, sizeof(*ring_id));
  1559. LEAVE();
  1560. }
  1561. static int votequorum_sync_process (void)
  1562. {
  1563. votequorum_exec_send_nodeinfo(us->node_id);
  1564. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1565. if (strlen(qdevice_name)) {
  1566. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1567. qdevice_name);
  1568. }
  1569. return 0;
  1570. }
  1571. static void votequorum_sync_activate (void)
  1572. {
  1573. recalculate_quorum(0, 0);
  1574. quorum_callback(quorum_members, quorum_members_entries,
  1575. cluster_is_quorate, &quorum_ringid);
  1576. sync_in_progress = 0;
  1577. }
  1578. static void votequorum_sync_abort (void)
  1579. {
  1580. }
  1581. char *votequorum_init(struct corosync_api_v1 *api,
  1582. quorum_set_quorate_fn_t q_set_quorate_fn)
  1583. {
  1584. char *error;
  1585. ENTER();
  1586. if (q_set_quorate_fn == NULL) {
  1587. return ((char *)"Quorate function not set");
  1588. }
  1589. corosync_api = api;
  1590. quorum_callback = q_set_quorate_fn;
  1591. error = corosync_service_link_and_init(corosync_api,
  1592. &votequorum_service[0]);
  1593. if (error) {
  1594. return (error);
  1595. }
  1596. LEAVE();
  1597. return (NULL);
  1598. }
  1599. /*
  1600. * Library Handler init/fini
  1601. */
  1602. static int quorum_lib_init_fn (void *conn)
  1603. {
  1604. struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1605. ENTER();
  1606. list_init (&pd->list);
  1607. pd->conn = conn;
  1608. LEAVE();
  1609. return (0);
  1610. }
  1611. static int quorum_lib_exit_fn (void *conn)
  1612. {
  1613. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1614. ENTER();
  1615. if (quorum_pd->tracking_enabled) {
  1616. list_del (&quorum_pd->list);
  1617. list_init (&quorum_pd->list);
  1618. }
  1619. LEAVE();
  1620. return (0);
  1621. }
  1622. /*
  1623. * library internal functions
  1624. */
  1625. static void qdevice_timer_fn(void *arg)
  1626. {
  1627. ENTER();
  1628. if ((!(us->flags & NODE_FLAGS_QDEVICE_ALIVE)) ||
  1629. (!qdevice_timer_set)) {
  1630. LEAVE();
  1631. return;
  1632. }
  1633. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1634. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1635. log_printf(LOGSYS_LEVEL_INFO, "lost contact with quorum device %s", qdevice_name);
  1636. votequorum_exec_send_nodeinfo(us->node_id);
  1637. qdevice_timer_set = 0;
  1638. LEAVE();
  1639. }
  1640. /*
  1641. * Library Handler Functions
  1642. */
  1643. static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *message)
  1644. {
  1645. const struct req_lib_votequorum_getinfo *req_lib_votequorum_getinfo = message;
  1646. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  1647. struct cluster_node *node;
  1648. unsigned int highest_expected = 0;
  1649. unsigned int total_votes = 0;
  1650. cs_error_t error = CS_OK;
  1651. uint32_t nodeid = req_lib_votequorum_getinfo->nodeid;
  1652. ENTER();
  1653. log_printf(LOGSYS_LEVEL_DEBUG, "got getinfo request on %p for node %u", conn, req_lib_votequorum_getinfo->nodeid);
  1654. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  1655. nodeid = us->node_id;
  1656. }
  1657. node = find_node_by_nodeid(nodeid);
  1658. if (node) {
  1659. struct cluster_node *iternode;
  1660. struct list_head *nodelist;
  1661. list_iterate(nodelist, &cluster_members_list) {
  1662. iternode = list_entry(nodelist, struct cluster_node, list);
  1663. if (iternode->state == NODESTATE_MEMBER) {
  1664. highest_expected =
  1665. max(highest_expected, iternode->expected_votes);
  1666. total_votes += iternode->votes;
  1667. }
  1668. }
  1669. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1670. total_votes += qdevice->votes;
  1671. }
  1672. switch(node->state) {
  1673. case NODESTATE_MEMBER:
  1674. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_MEMBER;
  1675. break;
  1676. case NODESTATE_DEAD:
  1677. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_DEAD;
  1678. break;
  1679. case NODESTATE_LEAVING:
  1680. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_LEAVING;
  1681. break;
  1682. default:
  1683. res_lib_votequorum_getinfo.state = node->state;
  1684. break;
  1685. }
  1686. res_lib_votequorum_getinfo.state = node->state;
  1687. res_lib_votequorum_getinfo.votes = node->votes;
  1688. res_lib_votequorum_getinfo.expected_votes = node->expected_votes;
  1689. res_lib_votequorum_getinfo.highest_expected = highest_expected;
  1690. res_lib_votequorum_getinfo.quorum = quorum;
  1691. res_lib_votequorum_getinfo.total_votes = total_votes;
  1692. res_lib_votequorum_getinfo.flags = 0;
  1693. res_lib_votequorum_getinfo.nodeid = node->node_id;
  1694. if (two_node) {
  1695. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_TWONODE;
  1696. }
  1697. if (cluster_is_quorate) {
  1698. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QUORATE;
  1699. }
  1700. if (wait_for_all) {
  1701. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_WAIT_FOR_ALL;
  1702. }
  1703. if (last_man_standing) {
  1704. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_LAST_MAN_STANDING;
  1705. }
  1706. if (auto_tie_breaker) {
  1707. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_AUTO_TIE_BREAKER;
  1708. }
  1709. if (allow_downscale) {
  1710. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_ALLOW_DOWNSCALE;
  1711. }
  1712. memset(res_lib_votequorum_getinfo.qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1713. strcpy(res_lib_votequorum_getinfo.qdevice_name, qdevice_name);
  1714. res_lib_votequorum_getinfo.qdevice_votes = qdevice->votes;
  1715. if (node->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1716. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_REGISTERED;
  1717. }
  1718. if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  1719. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_ALIVE;
  1720. }
  1721. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  1722. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_CAST_VOTE;
  1723. }
  1724. if (node->flags & NODE_FLAGS_QDEVICE_MASTER_WINS) {
  1725. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_MASTER_WINS;
  1726. }
  1727. } else {
  1728. error = CS_ERR_NOT_EXIST;
  1729. }
  1730. res_lib_votequorum_getinfo.header.size = sizeof(res_lib_votequorum_getinfo);
  1731. res_lib_votequorum_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  1732. res_lib_votequorum_getinfo.header.error = error;
  1733. corosync_api->ipc_response_send(conn, &res_lib_votequorum_getinfo, sizeof(res_lib_votequorum_getinfo));
  1734. log_printf(LOGSYS_LEVEL_DEBUG, "getinfo response error: %d", error);
  1735. LEAVE();
  1736. }
  1737. static void message_handler_req_lib_votequorum_setexpected (void *conn, const void *message)
  1738. {
  1739. const struct req_lib_votequorum_setexpected *req_lib_votequorum_setexpected = message;
  1740. struct res_lib_votequorum_status res_lib_votequorum_status;
  1741. cs_error_t error = CS_OK;
  1742. unsigned int newquorum;
  1743. unsigned int total_votes;
  1744. uint8_t allow_downscale_status = 0;
  1745. ENTER();
  1746. allow_downscale_status = allow_downscale;
  1747. allow_downscale = 0;
  1748. /*
  1749. * Validate new expected votes
  1750. */
  1751. newquorum = calculate_quorum(1, req_lib_votequorum_setexpected->expected_votes, &total_votes);
  1752. allow_downscale = allow_downscale_status;
  1753. if (newquorum < total_votes / 2 ||
  1754. newquorum > total_votes) {
  1755. error = CS_ERR_INVALID_PARAM;
  1756. goto error_exit;
  1757. }
  1758. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES, us->node_id,
  1759. req_lib_votequorum_setexpected->expected_votes);
  1760. error_exit:
  1761. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1762. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1763. res_lib_votequorum_status.header.error = error;
  1764. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1765. LEAVE();
  1766. }
  1767. static void message_handler_req_lib_votequorum_setvotes (void *conn, const void *message)
  1768. {
  1769. const struct req_lib_votequorum_setvotes *req_lib_votequorum_setvotes = message;
  1770. struct res_lib_votequorum_status res_lib_votequorum_status;
  1771. struct cluster_node *node;
  1772. unsigned int newquorum;
  1773. unsigned int total_votes;
  1774. unsigned int saved_votes;
  1775. cs_error_t error = CS_OK;
  1776. unsigned int nodeid;
  1777. ENTER();
  1778. nodeid = req_lib_votequorum_setvotes->nodeid;
  1779. node = find_node_by_nodeid(nodeid);
  1780. if (!node) {
  1781. error = CS_ERR_NAME_NOT_FOUND;
  1782. goto error_exit;
  1783. }
  1784. /*
  1785. * Check votes is valid
  1786. */
  1787. saved_votes = node->votes;
  1788. node->votes = req_lib_votequorum_setvotes->votes;
  1789. newquorum = calculate_quorum(1, 0, &total_votes);
  1790. if (newquorum < total_votes / 2 ||
  1791. newquorum > total_votes) {
  1792. node->votes = saved_votes;
  1793. error = CS_ERR_INVALID_PARAM;
  1794. goto error_exit;
  1795. }
  1796. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES, nodeid,
  1797. req_lib_votequorum_setvotes->votes);
  1798. error_exit:
  1799. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1800. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1801. res_lib_votequorum_status.header.error = error;
  1802. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1803. LEAVE();
  1804. }
  1805. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  1806. const void *message)
  1807. {
  1808. const struct req_lib_votequorum_trackstart *req_lib_votequorum_trackstart = message;
  1809. struct res_lib_votequorum_status res_lib_votequorum_status;
  1810. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1811. ENTER();
  1812. /*
  1813. * If an immediate listing of the current cluster membership
  1814. * is requested, generate membership list
  1815. */
  1816. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
  1817. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
  1818. log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p", conn);
  1819. votequorum_exec_send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
  1820. }
  1821. /*
  1822. * Record requests for tracking
  1823. */
  1824. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES ||
  1825. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
  1826. quorum_pd->track_flags = req_lib_votequorum_trackstart->track_flags;
  1827. quorum_pd->tracking_enabled = 1;
  1828. quorum_pd->tracking_context = req_lib_votequorum_trackstart->context;
  1829. list_add (&quorum_pd->list, &trackers_list);
  1830. }
  1831. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1832. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1833. res_lib_votequorum_status.header.error = CS_OK;
  1834. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1835. LEAVE();
  1836. }
  1837. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  1838. const void *message)
  1839. {
  1840. struct res_lib_votequorum_status res_lib_votequorum_status;
  1841. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  1842. int error = CS_OK;
  1843. ENTER();
  1844. if (quorum_pd->tracking_enabled) {
  1845. error = CS_OK;
  1846. quorum_pd->tracking_enabled = 0;
  1847. list_del (&quorum_pd->list);
  1848. list_init (&quorum_pd->list);
  1849. } else {
  1850. error = CS_ERR_NOT_EXIST;
  1851. }
  1852. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1853. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1854. res_lib_votequorum_status.header.error = error;
  1855. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1856. LEAVE();
  1857. }
  1858. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  1859. const void *message)
  1860. {
  1861. const struct req_lib_votequorum_qdevice_register *req_lib_votequorum_qdevice_register = message;
  1862. struct res_lib_votequorum_status res_lib_votequorum_status;
  1863. cs_error_t error = CS_OK;
  1864. ENTER();
  1865. if (!qdevice_can_operate) {
  1866. log_printf(LOGSYS_LEVEL_INFO, "Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
  1867. error = CS_ERR_ACCESS;
  1868. goto out;
  1869. }
  1870. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1871. if ((!strncmp(req_lib_votequorum_qdevice_register->name,
  1872. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  1873. goto out;
  1874. } else {
  1875. log_printf(LOGSYS_LEVEL_WARNING,
  1876. "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
  1877. req_lib_votequorum_qdevice_register->name, qdevice_name);
  1878. error = CS_ERR_EXIST;
  1879. goto out;
  1880. }
  1881. } else {
  1882. if (qdevice_reg_conn != NULL) {
  1883. log_printf(LOGSYS_LEVEL_WARNING,
  1884. "Registration request already in progress");
  1885. error = CS_ERR_TRY_AGAIN;
  1886. goto out;
  1887. }
  1888. qdevice_reg_conn = conn;
  1889. if (votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1890. req_lib_votequorum_qdevice_register->name) != 0) {
  1891. log_printf(LOGSYS_LEVEL_WARNING,
  1892. "Unable to send qdevice registration request to cluster");
  1893. error = CS_ERR_TRY_AGAIN;
  1894. qdevice_reg_conn = NULL;
  1895. } else {
  1896. LEAVE();
  1897. return;
  1898. }
  1899. }
  1900. out:
  1901. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1902. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1903. res_lib_votequorum_status.header.error = error;
  1904. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1905. LEAVE();
  1906. }
  1907. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  1908. const void *message)
  1909. {
  1910. const struct req_lib_votequorum_qdevice_unregister *req_lib_votequorum_qdevice_unregister = message;
  1911. struct res_lib_votequorum_status res_lib_votequorum_status;
  1912. cs_error_t error = CS_OK;
  1913. ENTER();
  1914. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1915. if (strncmp(req_lib_votequorum_qdevice_unregister->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  1916. error = CS_ERR_INVALID_PARAM;
  1917. goto out;
  1918. }
  1919. if (qdevice_timer_set) {
  1920. corosync_api->timer_delete(qdevice_timer);
  1921. qdevice_timer_set = 0;
  1922. }
  1923. us->flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
  1924. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  1925. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1926. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  1927. votequorum_exec_send_nodeinfo(us->node_id);
  1928. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER,
  1929. req_lib_votequorum_qdevice_unregister->name);
  1930. } else {
  1931. error = CS_ERR_NOT_EXIST;
  1932. }
  1933. out:
  1934. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1935. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1936. res_lib_votequorum_status.header.error = error;
  1937. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1938. LEAVE();
  1939. }
  1940. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  1941. const void *message)
  1942. {
  1943. const struct req_lib_votequorum_qdevice_update *req_lib_votequorum_qdevice_update = message;
  1944. struct res_lib_votequorum_status res_lib_votequorum_status;
  1945. cs_error_t error = CS_OK;
  1946. ENTER();
  1947. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1948. if (strncmp(req_lib_votequorum_qdevice_update->oldname, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  1949. error = CS_ERR_INVALID_PARAM;
  1950. goto out;
  1951. }
  1952. votequorum_exec_send_qdevice_reconfigure(req_lib_votequorum_qdevice_update->oldname,
  1953. req_lib_votequorum_qdevice_update->newname);
  1954. } else {
  1955. error = CS_ERR_NOT_EXIST;
  1956. }
  1957. out:
  1958. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1959. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1960. res_lib_votequorum_status.header.error = error;
  1961. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1962. LEAVE();
  1963. }
  1964. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  1965. const void *message)
  1966. {
  1967. const struct req_lib_votequorum_qdevice_poll *req_lib_votequorum_qdevice_poll = message;
  1968. struct res_lib_votequorum_status res_lib_votequorum_status;
  1969. cs_error_t error = CS_OK;
  1970. uint32_t oldflags;
  1971. ENTER();
  1972. if (!qdevice_can_operate) {
  1973. error = CS_ERR_ACCESS;
  1974. goto out;
  1975. }
  1976. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1977. if (strncmp(req_lib_votequorum_qdevice_poll->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  1978. error = CS_ERR_INVALID_PARAM;
  1979. goto out;
  1980. }
  1981. if (qdevice_timer_set) {
  1982. corosync_api->timer_delete(qdevice_timer);
  1983. qdevice_timer_set = 0;
  1984. }
  1985. oldflags = us->flags;
  1986. us->flags |= NODE_FLAGS_QDEVICE_ALIVE;
  1987. if (req_lib_votequorum_qdevice_poll->cast_vote) {
  1988. us->flags |= NODE_FLAGS_QDEVICE_CAST_VOTE;
  1989. } else {
  1990. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  1991. }
  1992. if (us->flags != oldflags) {
  1993. votequorum_exec_send_nodeinfo(us->node_id);
  1994. }
  1995. corosync_api->timer_add_duration((unsigned long long)qdevice_timeout*1000000, qdevice,
  1996. qdevice_timer_fn, &qdevice_timer);
  1997. qdevice_timer_set = 1;
  1998. } else {
  1999. error = CS_ERR_NOT_EXIST;
  2000. }
  2001. out:
  2002. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2003. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2004. res_lib_votequorum_status.header.error = error;
  2005. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2006. LEAVE();
  2007. }
  2008. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  2009. const void *message)
  2010. {
  2011. const struct req_lib_votequorum_qdevice_master_wins *req_lib_votequorum_qdevice_master_wins = message;
  2012. struct res_lib_votequorum_status res_lib_votequorum_status;
  2013. cs_error_t error = CS_OK;
  2014. uint32_t oldflags = us->flags;
  2015. ENTER();
  2016. if (!qdevice_can_operate) {
  2017. error = CS_ERR_ACCESS;
  2018. goto out;
  2019. }
  2020. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2021. if (strncmp(req_lib_votequorum_qdevice_master_wins->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2022. error = CS_ERR_INVALID_PARAM;
  2023. goto out;
  2024. }
  2025. if (req_lib_votequorum_qdevice_master_wins->allow) {
  2026. us->flags |= NODE_FLAGS_QDEVICE_MASTER_WINS;
  2027. } else {
  2028. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2029. }
  2030. if (us->flags != oldflags) {
  2031. votequorum_exec_send_nodeinfo(us->node_id);
  2032. }
  2033. update_qdevice_master_wins(req_lib_votequorum_qdevice_master_wins->allow);
  2034. } else {
  2035. error = CS_ERR_NOT_EXIST;
  2036. }
  2037. out:
  2038. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2039. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2040. res_lib_votequorum_status.header.error = error;
  2041. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2042. LEAVE();
  2043. }