votequorum.c 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031
  1. /*
  2. * Copyright (c) 2009-2015 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 <sys/stat.h>
  38. #include <fcntl.h>
  39. #include <stdint.h>
  40. #include <unistd.h>
  41. #include <qb/qbipc_common.h>
  42. #include "quorum.h"
  43. #include <corosync/corodefs.h>
  44. #include <corosync/list.h>
  45. #include <corosync/logsys.h>
  46. #include <corosync/coroapi.h>
  47. #include <corosync/icmap.h>
  48. #include <corosync/votequorum.h>
  49. #include <corosync/ipc_votequorum.h>
  50. #include "service.h"
  51. #include "util.h"
  52. LOGSYS_DECLARE_SUBSYS ("VOTEQ");
  53. /*
  54. * interface with corosync
  55. */
  56. static struct corosync_api_v1 *corosync_api;
  57. /*
  58. * votequorum global config vars
  59. */
  60. static char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  61. static struct cluster_node *qdevice = NULL;
  62. static unsigned int qdevice_timeout = VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT;
  63. static unsigned int qdevice_sync_timeout = VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT;
  64. static uint8_t qdevice_can_operate = 1;
  65. static void *qdevice_reg_conn = NULL;
  66. static uint8_t qdevice_master_wins = 0;
  67. static uint8_t two_node = 0;
  68. static uint8_t wait_for_all = 0;
  69. static uint8_t wait_for_all_status = 0;
  70. static enum {ATB_NONE, ATB_LOWEST, ATB_HIGHEST, ATB_LIST} auto_tie_breaker = ATB_NONE;
  71. static int lowest_node_id = -1;
  72. static int highest_node_id = -1;
  73. #define DEFAULT_LMS_WIN 10000
  74. static uint8_t last_man_standing = 0;
  75. static uint32_t last_man_standing_window = DEFAULT_LMS_WIN;
  76. static uint8_t allow_downscale = 0;
  77. static uint32_t ev_barrier = 0;
  78. static uint8_t ev_tracking = 0;
  79. static uint32_t ev_tracking_barrier = 0;
  80. static int ev_tracking_fd = -1;
  81. /*
  82. * votequorum_exec defines/structs/forward definitions
  83. */
  84. struct req_exec_quorum_nodeinfo {
  85. struct qb_ipc_request_header header __attribute__((aligned(8)));
  86. uint32_t nodeid;
  87. uint32_t votes;
  88. uint32_t expected_votes;
  89. uint32_t flags;
  90. } __attribute__((packed));
  91. struct req_exec_quorum_reconfigure {
  92. struct qb_ipc_request_header header __attribute__((aligned(8)));
  93. uint32_t nodeid;
  94. uint32_t value;
  95. uint8_t param;
  96. uint8_t _pad0;
  97. uint8_t _pad1;
  98. uint8_t _pad2;
  99. } __attribute__((packed));
  100. struct req_exec_quorum_qdevice_reg {
  101. struct qb_ipc_request_header header __attribute__((aligned(8)));
  102. uint32_t operation;
  103. char qdevice_name[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  104. } __attribute__((packed));
  105. struct req_exec_quorum_qdevice_reconfigure {
  106. struct qb_ipc_request_header header __attribute__((aligned(8)));
  107. char oldname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  108. char newname[VOTEQUORUM_QDEVICE_MAX_NAME_LEN];
  109. } __attribute__((packed));
  110. /*
  111. * votequorum_exec onwire version (via totem)
  112. */
  113. #include "votequorum.h"
  114. /*
  115. * votequorum_exec onwire messages (via totem)
  116. */
  117. #define MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO 0
  118. #define MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE 1
  119. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG 2
  120. #define MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE 3
  121. static void votequorum_exec_send_expectedvotes_notification(void);
  122. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context);
  123. static int votequorum_exec_send_nodelist_notification(void *conn, uint64_t context);
  124. #define VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES 1
  125. #define VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES 2
  126. #define VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA 3
  127. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value);
  128. /*
  129. * used by req_exec_quorum_qdevice_reg
  130. */
  131. #define VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER 0
  132. #define VOTEQUORUM_QDEVICE_OPERATION_REGISTER 1
  133. /*
  134. * votequorum internal node status/view
  135. */
  136. #define NODE_FLAGS_QUORATE 1
  137. #define NODE_FLAGS_LEAVING 2
  138. #define NODE_FLAGS_WFASTATUS 4
  139. #define NODE_FLAGS_FIRST 8
  140. #define NODE_FLAGS_QDEVICE_REGISTERED 16
  141. #define NODE_FLAGS_QDEVICE_ALIVE 32
  142. #define NODE_FLAGS_QDEVICE_CAST_VOTE 64
  143. #define NODE_FLAGS_QDEVICE_MASTER_WINS 128
  144. typedef enum {
  145. NODESTATE_MEMBER=1,
  146. NODESTATE_DEAD,
  147. NODESTATE_LEAVING
  148. } nodestate_t;
  149. struct cluster_node {
  150. int node_id;
  151. nodestate_t state;
  152. uint32_t votes;
  153. uint32_t expected_votes;
  154. uint32_t flags;
  155. struct list_head list;
  156. };
  157. /*
  158. * votequorum internal quorum status
  159. */
  160. static uint8_t quorum;
  161. static uint8_t cluster_is_quorate;
  162. /*
  163. * votequorum membership data
  164. */
  165. static struct cluster_node *us;
  166. static struct list_head cluster_members_list;
  167. static unsigned int quorum_members[PROCESSOR_COUNT_MAX];
  168. static unsigned int previous_quorum_members[PROCESSOR_COUNT_MAX];
  169. static unsigned int atb_nodelist[PROCESSOR_COUNT_MAX];
  170. static int quorum_members_entries = 0;
  171. static int previous_quorum_members_entries = 0;
  172. static int atb_nodelist_entries = 0;
  173. static struct memb_ring_id quorum_ringid;
  174. /*
  175. * pre allocate all cluster_nodes + one for qdevice
  176. */
  177. static struct cluster_node cluster_nodes[PROCESSOR_COUNT_MAX+2];
  178. static int cluster_nodes_entries = 0;
  179. /*
  180. * votequorum tracking
  181. */
  182. struct quorum_pd {
  183. unsigned char track_flags;
  184. int tracking_enabled;
  185. uint64_t tracking_context;
  186. struct list_head list;
  187. void *conn;
  188. };
  189. static struct list_head trackers_list;
  190. /*
  191. * votequorum timers
  192. */
  193. static corosync_timer_handle_t qdevice_timer;
  194. static int qdevice_timer_set = 0;
  195. static corosync_timer_handle_t last_man_standing_timer;
  196. static int last_man_standing_timer_set = 0;
  197. static int sync_nodeinfo_sent = 0;
  198. static int sync_wait_for_poll_or_timeout = 0;
  199. /*
  200. * Service Interfaces required by service_message_handler struct
  201. */
  202. static int sync_in_progress = 0;
  203. static void votequorum_sync_init (
  204. const unsigned int *trans_list,
  205. size_t trans_list_entries,
  206. const unsigned int *member_list,
  207. size_t member_list_entries,
  208. const struct memb_ring_id *ring_id);
  209. static int votequorum_sync_process (void);
  210. static void votequorum_sync_activate (void);
  211. static void votequorum_sync_abort (void);
  212. static quorum_set_quorate_fn_t quorum_callback;
  213. /*
  214. * votequorum_exec handler and definitions
  215. */
  216. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api);
  217. static int votequorum_exec_exit_fn (void);
  218. static int votequorum_exec_send_nodeinfo(uint32_t nodeid);
  219. static void message_handler_req_exec_votequorum_nodeinfo (
  220. const void *message,
  221. unsigned int nodeid);
  222. static void exec_votequorum_nodeinfo_endian_convert (void *message);
  223. static void message_handler_req_exec_votequorum_reconfigure (
  224. const void *message,
  225. unsigned int nodeid);
  226. static void exec_votequorum_reconfigure_endian_convert (void *message);
  227. static void message_handler_req_exec_votequorum_qdevice_reg (
  228. const void *message,
  229. unsigned int nodeid);
  230. static void exec_votequorum_qdevice_reg_endian_convert (void *message);
  231. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  232. const void *message,
  233. unsigned int nodeid);
  234. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message);
  235. static struct corosync_exec_handler votequorum_exec_engine[] =
  236. {
  237. { /* 0 */
  238. .exec_handler_fn = message_handler_req_exec_votequorum_nodeinfo,
  239. .exec_endian_convert_fn = exec_votequorum_nodeinfo_endian_convert
  240. },
  241. { /* 1 */
  242. .exec_handler_fn = message_handler_req_exec_votequorum_reconfigure,
  243. .exec_endian_convert_fn = exec_votequorum_reconfigure_endian_convert
  244. },
  245. { /* 2 */
  246. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reg,
  247. .exec_endian_convert_fn = exec_votequorum_qdevice_reg_endian_convert
  248. },
  249. { /* 3 */
  250. .exec_handler_fn = message_handler_req_exec_votequorum_qdevice_reconfigure,
  251. .exec_endian_convert_fn = exec_votequorum_qdevice_reconfigure_endian_convert
  252. },
  253. };
  254. /*
  255. * Library Handler and Functions Definitions
  256. */
  257. static int quorum_lib_init_fn (void *conn);
  258. static int quorum_lib_exit_fn (void *conn);
  259. static void qdevice_timer_fn(void *arg);
  260. static void message_handler_req_lib_votequorum_getinfo (void *conn,
  261. const void *message);
  262. static void message_handler_req_lib_votequorum_setexpected (void *conn,
  263. const void *message);
  264. static void message_handler_req_lib_votequorum_setvotes (void *conn,
  265. const void *message);
  266. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  267. const void *message);
  268. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  269. const void *message);
  270. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  271. const void *message);
  272. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  273. const void *message);
  274. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  275. const void *message);
  276. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  277. const void *message);
  278. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  279. const void *message);
  280. static struct corosync_lib_handler quorum_lib_service[] =
  281. {
  282. { /* 0 */
  283. .lib_handler_fn = message_handler_req_lib_votequorum_getinfo,
  284. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  285. },
  286. { /* 1 */
  287. .lib_handler_fn = message_handler_req_lib_votequorum_setexpected,
  288. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  289. },
  290. { /* 2 */
  291. .lib_handler_fn = message_handler_req_lib_votequorum_setvotes,
  292. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  293. },
  294. { /* 3 */
  295. .lib_handler_fn = message_handler_req_lib_votequorum_trackstart,
  296. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  297. },
  298. { /* 4 */
  299. .lib_handler_fn = message_handler_req_lib_votequorum_trackstop,
  300. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  301. },
  302. { /* 5 */
  303. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_register,
  304. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  305. },
  306. { /* 6 */
  307. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_unregister,
  308. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  309. },
  310. { /* 7 */
  311. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_update,
  312. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  313. },
  314. { /* 8 */
  315. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_poll,
  316. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  317. },
  318. { /* 9 */
  319. .lib_handler_fn = message_handler_req_lib_votequorum_qdevice_master_wins,
  320. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  321. }
  322. };
  323. static struct corosync_service_engine votequorum_service_engine = {
  324. .name = "corosync vote quorum service v1.0",
  325. .id = VOTEQUORUM_SERVICE,
  326. .priority = 2,
  327. .private_data_size = sizeof (struct quorum_pd),
  328. .allow_inquorate = CS_LIB_ALLOW_INQUORATE,
  329. .flow_control = COROSYNC_LIB_FLOW_CONTROL_REQUIRED,
  330. .lib_init_fn = quorum_lib_init_fn,
  331. .lib_exit_fn = quorum_lib_exit_fn,
  332. .lib_engine = quorum_lib_service,
  333. .lib_engine_count = sizeof (quorum_lib_service) / sizeof (struct corosync_lib_handler),
  334. .exec_init_fn = votequorum_exec_init_fn,
  335. .exec_exit_fn = votequorum_exec_exit_fn,
  336. .exec_engine = votequorum_exec_engine,
  337. .exec_engine_count = sizeof (votequorum_exec_engine) / sizeof (struct corosync_exec_handler),
  338. .sync_init = votequorum_sync_init,
  339. .sync_process = votequorum_sync_process,
  340. .sync_activate = votequorum_sync_activate,
  341. .sync_abort = votequorum_sync_abort
  342. };
  343. struct corosync_service_engine *votequorum_get_service_engine_ver0 (void)
  344. {
  345. return (&votequorum_service_engine);
  346. }
  347. static struct default_service votequorum_service[] = {
  348. {
  349. .name = "corosync_votequorum",
  350. .ver = 0,
  351. .loader = votequorum_get_service_engine_ver0
  352. },
  353. };
  354. /*
  355. * common/utility macros/functions
  356. */
  357. #define max(a,b) (((a) > (b)) ? (a) : (b))
  358. #define list_iterate(v, head) \
  359. for (v = (head)->next; v != head; v = v->next)
  360. static void node_add_ordered(struct cluster_node *newnode)
  361. {
  362. struct cluster_node *node = NULL;
  363. struct list_head *tmp;
  364. struct list_head *newlist = &newnode->list;
  365. ENTER();
  366. list_iterate(tmp, &cluster_members_list) {
  367. node = list_entry(tmp, struct cluster_node, list);
  368. if (newnode->node_id < node->node_id) {
  369. break;
  370. }
  371. }
  372. if (!node) {
  373. list_add(&newnode->list, &cluster_members_list);
  374. } else {
  375. newlist->prev = tmp->prev;
  376. newlist->next = tmp;
  377. tmp->prev->next = newlist;
  378. tmp->prev = newlist;
  379. }
  380. LEAVE();
  381. }
  382. static struct cluster_node *allocate_node(unsigned int nodeid)
  383. {
  384. struct cluster_node *cl = NULL;
  385. struct list_head *tmp;
  386. ENTER();
  387. if (cluster_nodes_entries <= PROCESSOR_COUNT_MAX + 1) {
  388. cl = (struct cluster_node *)&cluster_nodes[cluster_nodes_entries];
  389. cluster_nodes_entries++;
  390. } else {
  391. list_iterate(tmp, &cluster_members_list) {
  392. cl = list_entry(tmp, struct cluster_node, list);
  393. if (cl->state == NODESTATE_DEAD) {
  394. break;
  395. }
  396. }
  397. /*
  398. * this should never happen
  399. */
  400. if (!cl) {
  401. log_printf(LOGSYS_LEVEL_CRIT, "Unable to find memory for node %u data!!", nodeid);
  402. goto out;
  403. }
  404. list_del(tmp);
  405. }
  406. memset(cl, 0, sizeof(struct cluster_node));
  407. cl->node_id = nodeid;
  408. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  409. node_add_ordered(cl);
  410. }
  411. out:
  412. LEAVE();
  413. return cl;
  414. }
  415. static struct cluster_node *find_node_by_nodeid(unsigned int nodeid)
  416. {
  417. struct cluster_node *node;
  418. struct list_head *tmp;
  419. ENTER();
  420. if (nodeid == us->node_id) {
  421. LEAVE();
  422. return us;
  423. }
  424. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  425. LEAVE();
  426. return qdevice;
  427. }
  428. list_iterate(tmp, &cluster_members_list) {
  429. node = list_entry(tmp, struct cluster_node, list);
  430. if (node->node_id == nodeid) {
  431. LEAVE();
  432. return node;
  433. }
  434. }
  435. LEAVE();
  436. return NULL;
  437. }
  438. static void get_lowest_node_id(void)
  439. {
  440. struct cluster_node *node = NULL;
  441. struct list_head *tmp;
  442. ENTER();
  443. lowest_node_id = us->node_id;
  444. list_iterate(tmp, &cluster_members_list) {
  445. node = list_entry(tmp, struct cluster_node, list);
  446. if ((node->state == NODESTATE_MEMBER) &&
  447. (node->node_id < lowest_node_id)) {
  448. lowest_node_id = node->node_id;
  449. }
  450. }
  451. log_printf(LOGSYS_LEVEL_DEBUG, "lowest node id: %d us: %d", lowest_node_id, us->node_id);
  452. icmap_set_uint32("runtime.votequorum.lowest_node_id", lowest_node_id);
  453. LEAVE();
  454. }
  455. static void get_highest_node_id(void)
  456. {
  457. struct cluster_node *node = NULL;
  458. struct list_head *tmp;
  459. ENTER();
  460. highest_node_id = us->node_id;
  461. list_iterate(tmp, &cluster_members_list) {
  462. node = list_entry(tmp, struct cluster_node, list);
  463. if ((node->state == NODESTATE_MEMBER) &&
  464. (node->node_id > highest_node_id)) {
  465. highest_node_id = node->node_id;
  466. }
  467. }
  468. log_printf(LOGSYS_LEVEL_DEBUG, "highest node id: %d us: %d", highest_node_id, us->node_id);
  469. icmap_set_uint32("runtime.votequorum.highest_node_id", highest_node_id);
  470. LEAVE();
  471. }
  472. static int check_low_node_id_partition(void)
  473. {
  474. struct cluster_node *node = NULL;
  475. struct list_head *tmp;
  476. int found = 0;
  477. ENTER();
  478. list_iterate(tmp, &cluster_members_list) {
  479. node = list_entry(tmp, struct cluster_node, list);
  480. if ((node->state == NODESTATE_MEMBER) &&
  481. (node->node_id == lowest_node_id)) {
  482. found = 1;
  483. }
  484. }
  485. LEAVE();
  486. return found;
  487. }
  488. static int check_high_node_id_partition(void)
  489. {
  490. struct cluster_node *node = NULL;
  491. struct list_head *tmp;
  492. int found = 0;
  493. ENTER();
  494. list_iterate(tmp, &cluster_members_list) {
  495. node = list_entry(tmp, struct cluster_node, list);
  496. if ((node->state == NODESTATE_MEMBER) &&
  497. (node->node_id == highest_node_id)) {
  498. found = 1;
  499. }
  500. }
  501. LEAVE();
  502. return found;
  503. }
  504. static int is_in_nodelist(int nodeid, unsigned int *members, int entries)
  505. {
  506. int i;
  507. ENTER();
  508. for (i=0; i<entries; i++) {
  509. if (nodeid == members[i]) {
  510. LEAVE();
  511. return 1;
  512. }
  513. }
  514. LEAVE();
  515. return 0;
  516. }
  517. /*
  518. * The algorithm for a list of tie-breaker nodes is:
  519. * travel the list of nodes in the auto_tie_breaker list,
  520. * if the node IS in our current partition, check if the
  521. * nodes earlier in the atb list are in the 'previous' partition;
  522. * If none are found then we are safe to be quorate, if any are
  523. * then we cannot be as we don't know if that node is up or down.
  524. * If we don't have a node in the current list we are NOT quorate.
  525. * Obviously if we find the first node in the atb list in our
  526. * partition then we are quorate.
  527. *
  528. * Special cases lowest nodeid, and highest nodeid are handled separately.
  529. */
  530. static int check_auto_tie_breaker(void)
  531. {
  532. int i, j;
  533. int res;
  534. ENTER();
  535. if (auto_tie_breaker == ATB_LOWEST) {
  536. res = check_low_node_id_partition();
  537. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LOWEST decision: %d", res);
  538. LEAVE();
  539. return res;
  540. }
  541. if (auto_tie_breaker == ATB_HIGHEST) {
  542. res = check_high_node_id_partition();
  543. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_HIGHEST decision: %d", res);
  544. LEAVE();
  545. return res;
  546. }
  547. /* Assume ATB_LIST, we should never be called for ATB_NONE */
  548. for (i=0; i < atb_nodelist_entries; i++) {
  549. if (is_in_nodelist(atb_nodelist[i], quorum_members, quorum_members_entries)) {
  550. /*
  551. * Node is in our partition, if any of its predecessors are
  552. * in the previous quorum partition then it might be in the
  553. * 'other half' (as we've got this far without seeing it here)
  554. * and so we can't be quorate.
  555. */
  556. for (j=0; j<i; j++) {
  557. if (is_in_nodelist(atb_nodelist[j], previous_quorum_members, previous_quorum_members_entries)) {
  558. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found node %d in previous partition but not here, quorum denied", atb_nodelist[j]);
  559. LEAVE();
  560. return 0;
  561. }
  562. }
  563. /*
  564. * None of the other list nodes were in the previous partition, if there
  565. * are enough votes, we can be quorate
  566. */
  567. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found node %d in current partition, we can be quorate", atb_nodelist[i]);
  568. LEAVE();
  569. return 1;
  570. }
  571. }
  572. log_printf(LOGSYS_LEVEL_DEBUG, "ATB_LIST found no list nodes in current partition, we cannot be quorate");
  573. LEAVE();
  574. return 0;
  575. }
  576. /*
  577. * atb_string can be either:
  578. * 'lowest'
  579. * 'highest'
  580. * a list of nodeids
  581. */
  582. static void parse_atb_string(char *atb_string)
  583. {
  584. char *ptr;
  585. long num;
  586. ENTER();
  587. auto_tie_breaker = ATB_NONE;
  588. if (!strcmp(atb_string, "lowest"))
  589. auto_tie_breaker = ATB_LOWEST;
  590. if (!strcmp(atb_string, "highest"))
  591. auto_tie_breaker = ATB_HIGHEST;
  592. if (atoi(atb_string)) {
  593. atb_nodelist_entries = 0;
  594. ptr = atb_string;
  595. do {
  596. num = strtol(ptr, &ptr, 10);
  597. if (num) {
  598. log_printf(LOGSYS_LEVEL_DEBUG, "ATB nodelist[%d] = %d", atb_nodelist_entries, num);
  599. atb_nodelist[atb_nodelist_entries++] = num;
  600. }
  601. } while (num);
  602. if (atb_nodelist_entries) {
  603. auto_tie_breaker = ATB_LIST;
  604. }
  605. }
  606. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  607. log_printf(LOGSYS_LEVEL_DEBUG, "ATB type = %d", auto_tie_breaker);
  608. /* Make sure we got something */
  609. if (auto_tie_breaker == ATB_NONE) {
  610. log_printf(LOGSYS_LEVEL_WARNING, "auto_tie_breaker_nodes is not valid. It must be 'lowest', 'highest' or a space-separated list of node IDs. auto_tie_breaker is disabled");
  611. auto_tie_breaker = ATB_NONE;
  612. }
  613. LEAVE();
  614. }
  615. static int check_qdevice_master(void)
  616. {
  617. struct cluster_node *node = NULL;
  618. struct list_head *tmp;
  619. int found = 0;
  620. ENTER();
  621. list_iterate(tmp, &cluster_members_list) {
  622. node = list_entry(tmp, struct cluster_node, list);
  623. if ((node->state == NODESTATE_MEMBER) &&
  624. (node->flags & NODE_FLAGS_QDEVICE_MASTER_WINS) &&
  625. (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE)) {
  626. found = 1;
  627. }
  628. }
  629. LEAVE();
  630. return found;
  631. }
  632. static void decode_flags(uint32_t flags)
  633. {
  634. ENTER();
  635. log_printf(LOGSYS_LEVEL_DEBUG,
  636. "flags: quorate: %s Leaving: %s WFA Status: %s First: %s Qdevice: %s QdeviceAlive: %s QdeviceCastVote: %s QdeviceMasterWins: %s",
  637. (flags & NODE_FLAGS_QUORATE)?"Yes":"No",
  638. (flags & NODE_FLAGS_LEAVING)?"Yes":"No",
  639. (flags & NODE_FLAGS_WFASTATUS)?"Yes":"No",
  640. (flags & NODE_FLAGS_FIRST)?"Yes":"No",
  641. (flags & NODE_FLAGS_QDEVICE_REGISTERED)?"Yes":"No",
  642. (flags & NODE_FLAGS_QDEVICE_ALIVE)?"Yes":"No",
  643. (flags & NODE_FLAGS_QDEVICE_CAST_VOTE)?"Yes":"No",
  644. (flags & NODE_FLAGS_QDEVICE_MASTER_WINS)?"Yes":"No");
  645. LEAVE();
  646. }
  647. /*
  648. * load/save are copied almost pristine from totemsrp,c
  649. */
  650. static int load_ev_tracking_barrier(void)
  651. {
  652. int res = 0;
  653. char filename[PATH_MAX];
  654. ENTER();
  655. snprintf(filename, sizeof(filename) - 1, "%s/ev_tracking", get_run_dir());
  656. ev_tracking_fd = open(filename, O_RDWR, 0700);
  657. if (ev_tracking_fd != -1) {
  658. res = read (ev_tracking_fd, &ev_tracking_barrier, sizeof(uint32_t));
  659. close(ev_tracking_fd);
  660. if (res == sizeof (uint32_t)) {
  661. LEAVE();
  662. return 0;
  663. }
  664. }
  665. ev_tracking_barrier = 0;
  666. umask(0);
  667. ev_tracking_fd = open (filename, O_CREAT|O_RDWR, 0700);
  668. if (ev_tracking_fd != -1) {
  669. res = write (ev_tracking_fd, &ev_tracking_barrier, sizeof (uint32_t));
  670. if ((res == -1) || (res != sizeof (uint32_t))) {
  671. log_printf(LOGSYS_LEVEL_WARNING,
  672. "Unable to write to %s", filename);
  673. }
  674. close(ev_tracking_fd);
  675. LEAVE();
  676. return 0;
  677. }
  678. log_printf(LOGSYS_LEVEL_WARNING,
  679. "Unable to create %s file", filename);
  680. LEAVE();
  681. return -1;
  682. }
  683. static void update_wait_for_all_status(uint8_t wfa_status)
  684. {
  685. ENTER();
  686. wait_for_all_status = wfa_status;
  687. if (wait_for_all_status) {
  688. us->flags |= NODE_FLAGS_WFASTATUS;
  689. } else {
  690. us->flags &= ~NODE_FLAGS_WFASTATUS;
  691. }
  692. icmap_set_uint8("runtime.votequorum.wait_for_all_status",
  693. wait_for_all_status);
  694. LEAVE();
  695. }
  696. static void update_two_node(void)
  697. {
  698. ENTER();
  699. icmap_set_uint8("runtime.votequorum.two_node", two_node);
  700. LEAVE();
  701. }
  702. static void update_ev_barrier(uint32_t expected_votes)
  703. {
  704. ENTER();
  705. ev_barrier = expected_votes;
  706. icmap_set_uint32("runtime.votequorum.ev_barrier", ev_barrier);
  707. LEAVE();
  708. }
  709. static void update_qdevice_can_operate(uint8_t status)
  710. {
  711. ENTER();
  712. qdevice_can_operate = status;
  713. icmap_set_uint8("runtime.votequorum.qdevice_can_operate", qdevice_can_operate);
  714. LEAVE();
  715. }
  716. static void update_qdevice_master_wins(uint8_t allow)
  717. {
  718. ENTER();
  719. qdevice_master_wins = allow;
  720. icmap_set_uint8("runtime.votequorum.qdevice_master_wins", qdevice_master_wins);
  721. LEAVE();
  722. }
  723. static void update_ev_tracking_barrier(uint32_t ev_t_barrier)
  724. {
  725. int res;
  726. ENTER();
  727. ev_tracking_barrier = ev_t_barrier;
  728. icmap_set_uint32("runtime.votequorum.ev_tracking_barrier", ev_tracking_barrier);
  729. if (lseek (ev_tracking_fd, 0, SEEK_SET) != 0) {
  730. log_printf(LOGSYS_LEVEL_WARNING,
  731. "Unable to update ev_tracking_barrier on disk data!!!");
  732. LEAVE();
  733. return;
  734. }
  735. res = write (ev_tracking_fd, &ev_tracking_barrier, sizeof (uint32_t));
  736. if (res != sizeof (uint32_t)) {
  737. log_printf(LOGSYS_LEVEL_WARNING,
  738. "Unable to update ev_tracking_barrier on disk data!!!");
  739. }
  740. #ifdef HAVE_FDATASYNC
  741. fdatasync(ev_tracking_fd);
  742. #else
  743. fsync(ev_tracking_fd);
  744. #endif
  745. LEAVE();
  746. }
  747. /*
  748. * quorum calculation core bits
  749. */
  750. static int calculate_quorum(int allow_decrease, unsigned int max_expected, unsigned int *ret_total_votes)
  751. {
  752. struct list_head *nodelist;
  753. struct cluster_node *node;
  754. unsigned int total_votes = 0;
  755. unsigned int highest_expected = 0;
  756. unsigned int newquorum, q1, q2;
  757. unsigned int total_nodes = 0;
  758. ENTER();
  759. if ((allow_downscale) && (allow_decrease) && (max_expected)) {
  760. max_expected = max(ev_barrier, max_expected);
  761. }
  762. list_iterate(nodelist, &cluster_members_list) {
  763. node = list_entry(nodelist, struct cluster_node, list);
  764. log_printf(LOGSYS_LEVEL_DEBUG, "node %u state=%d, votes=%u, expected=%u",
  765. node->node_id, node->state, node->votes, node->expected_votes);
  766. if (node->state == NODESTATE_MEMBER) {
  767. highest_expected = max(highest_expected, node->expected_votes);
  768. total_votes += node->votes;
  769. total_nodes++;
  770. }
  771. }
  772. if (us->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  773. log_printf(LOGSYS_LEVEL_DEBUG, "node 0 state=1, votes=%u", qdevice->votes);
  774. total_votes += qdevice->votes;
  775. total_nodes++;
  776. }
  777. if (max_expected > 0) {
  778. highest_expected = max_expected;
  779. }
  780. /*
  781. * This quorum calculation is taken from the OpenVMS Cluster Systems
  782. * manual, but, then, you guessed that didn't you
  783. */
  784. q1 = (highest_expected + 2) / 2;
  785. q2 = (total_votes + 2) / 2;
  786. newquorum = max(q1, q2);
  787. /*
  788. * Normally quorum never decreases but the system administrator can
  789. * force it down by setting expected votes to a maximum value
  790. */
  791. if (!allow_decrease) {
  792. newquorum = max(quorum, newquorum);
  793. }
  794. /*
  795. * The special two_node mode allows each of the two nodes to retain
  796. * quorum if the other fails. Only one of the two should live past
  797. * fencing (as both nodes try to fence each other in split-brain.)
  798. * Also: if there are more than two nodes, force us inquorate to avoid
  799. * any damage or confusion.
  800. */
  801. if (two_node && total_nodes <= 2) {
  802. newquorum = 1;
  803. }
  804. if (ret_total_votes) {
  805. *ret_total_votes = total_votes;
  806. }
  807. LEAVE();
  808. return newquorum;
  809. }
  810. static void update_node_expected_votes(int new_expected_votes)
  811. {
  812. struct list_head *nodelist;
  813. struct cluster_node *node;
  814. if (new_expected_votes) {
  815. list_iterate(nodelist, &cluster_members_list) {
  816. node = list_entry(nodelist, struct cluster_node, list);
  817. if (node->state == NODESTATE_MEMBER) {
  818. node->expected_votes = new_expected_votes;
  819. }
  820. }
  821. }
  822. }
  823. static void are_we_quorate(unsigned int total_votes)
  824. {
  825. int quorate;
  826. int quorum_change = 0;
  827. ENTER();
  828. /*
  829. * wait for all nodes to show up before granting quorum
  830. */
  831. if ((wait_for_all) && (wait_for_all_status)) {
  832. if (total_votes != us->expected_votes) {
  833. log_printf(LOGSYS_LEVEL_NOTICE,
  834. "Waiting for all cluster members. "
  835. "Current votes: %d expected_votes: %d",
  836. total_votes, us->expected_votes);
  837. cluster_is_quorate = 0;
  838. return;
  839. }
  840. update_wait_for_all_status(0);
  841. }
  842. if (quorum > total_votes) {
  843. quorate = 0;
  844. } else {
  845. quorate = 1;
  846. get_lowest_node_id();
  847. get_highest_node_id();
  848. }
  849. if ((auto_tie_breaker != ATB_NONE) &&
  850. /* Must be a half (or half-1) split */
  851. (total_votes == (us->expected_votes / 2)) &&
  852. /* If the 'other' partition in a split might have quorum then we can't run ATB */
  853. (previous_quorum_members_entries - quorum_members_entries < quorum) &&
  854. (check_auto_tie_breaker() == 1)) {
  855. quorate = 1;
  856. }
  857. if ((qdevice_master_wins) &&
  858. (!quorate) &&
  859. (check_qdevice_master() == 1)) {
  860. log_printf(LOGSYS_LEVEL_DEBUG, "node is quorate as part of master_wins partition");
  861. quorate = 1;
  862. }
  863. if (cluster_is_quorate && !quorate) {
  864. quorum_change = 1;
  865. log_printf(LOGSYS_LEVEL_DEBUG, "quorum lost, blocking activity");
  866. }
  867. if (!cluster_is_quorate && quorate) {
  868. quorum_change = 1;
  869. log_printf(LOGSYS_LEVEL_DEBUG, "quorum regained, resuming activity");
  870. }
  871. cluster_is_quorate = quorate;
  872. if (cluster_is_quorate) {
  873. us->flags |= NODE_FLAGS_QUORATE;
  874. } else {
  875. us->flags &= ~NODE_FLAGS_QUORATE;
  876. }
  877. if (wait_for_all) {
  878. if (quorate) {
  879. update_wait_for_all_status(0);
  880. } else {
  881. update_wait_for_all_status(1);
  882. }
  883. }
  884. if ((quorum_change) &&
  885. (sync_in_progress == 0)) {
  886. quorum_callback(quorum_members, quorum_members_entries,
  887. cluster_is_quorate, &quorum_ringid);
  888. votequorum_exec_send_quorum_notification(NULL, 0L);
  889. }
  890. LEAVE();
  891. }
  892. static void get_total_votes(unsigned int *totalvotes, unsigned int *current_members)
  893. {
  894. unsigned int total_votes = 0;
  895. unsigned int cluster_members = 0;
  896. struct list_head *nodelist;
  897. struct cluster_node *node;
  898. ENTER();
  899. list_iterate(nodelist, &cluster_members_list) {
  900. node = list_entry(nodelist, struct cluster_node, list);
  901. if (node->state == NODESTATE_MEMBER) {
  902. cluster_members++;
  903. total_votes += node->votes;
  904. }
  905. }
  906. if (qdevice->votes) {
  907. total_votes += qdevice->votes;
  908. cluster_members++;
  909. }
  910. *totalvotes = total_votes;
  911. *current_members = cluster_members;
  912. LEAVE();
  913. }
  914. /*
  915. * Recalculate cluster quorum, set quorate and notify changes
  916. */
  917. static void recalculate_quorum(int allow_decrease, int by_current_nodes)
  918. {
  919. unsigned int total_votes = 0;
  920. unsigned int cluster_members = 0;
  921. ENTER();
  922. get_total_votes(&total_votes, &cluster_members);
  923. if (!by_current_nodes) {
  924. cluster_members = 0;
  925. }
  926. /*
  927. * Keep expected_votes at the highest number of votes in the cluster
  928. */
  929. log_printf(LOGSYS_LEVEL_DEBUG, "total_votes=%d, expected_votes=%d", total_votes, us->expected_votes);
  930. if (total_votes > us->expected_votes) {
  931. us->expected_votes = total_votes;
  932. votequorum_exec_send_expectedvotes_notification();
  933. }
  934. if ((ev_tracking) &&
  935. (us->expected_votes > ev_tracking_barrier)) {
  936. update_ev_tracking_barrier(us->expected_votes);
  937. }
  938. quorum = calculate_quorum(allow_decrease, cluster_members, &total_votes);
  939. update_node_expected_votes(cluster_members);
  940. are_we_quorate(total_votes);
  941. LEAVE();
  942. }
  943. /*
  944. * configuration bits and pieces
  945. */
  946. static int votequorum_read_nodelist_configuration(uint32_t *votes,
  947. uint32_t *nodes,
  948. uint32_t *expected_votes)
  949. {
  950. icmap_iter_t iter;
  951. const char *iter_key;
  952. char tmp_key[ICMAP_KEYNAME_MAXLEN];
  953. uint32_t our_pos, node_pos;
  954. uint32_t nodecount = 0;
  955. uint32_t nodelist_expected_votes = 0;
  956. uint32_t node_votes = 0;
  957. int res = 0;
  958. ENTER();
  959. if (icmap_get_uint32("nodelist.local_node_pos", &our_pos) != CS_OK) {
  960. log_printf(LOGSYS_LEVEL_DEBUG,
  961. "No nodelist defined or our node is not in the nodelist");
  962. return 0;
  963. }
  964. iter = icmap_iter_init("nodelist.node.");
  965. while ((iter_key = icmap_iter_next(iter, NULL, NULL)) != NULL) {
  966. res = sscanf(iter_key, "nodelist.node.%u.%s", &node_pos, tmp_key);
  967. if (res != 2) {
  968. continue;
  969. }
  970. if (strcmp(tmp_key, "ring0_addr") != 0) {
  971. continue;
  972. }
  973. nodecount++;
  974. snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.quorum_votes", node_pos);
  975. if (icmap_get_uint32(tmp_key, &node_votes) != CS_OK) {
  976. node_votes = 1;
  977. }
  978. nodelist_expected_votes = nodelist_expected_votes + node_votes;
  979. if (node_pos == our_pos) {
  980. *votes = node_votes;
  981. }
  982. }
  983. *expected_votes = nodelist_expected_votes;
  984. *nodes = nodecount;
  985. icmap_iter_finalize(iter);
  986. LEAVE();
  987. return 1;
  988. }
  989. static int votequorum_qdevice_is_configured(uint32_t *qdevice_votes)
  990. {
  991. char *qdevice_model = NULL;
  992. int ret = 0;
  993. ENTER();
  994. if (icmap_get_string("quorum.device.model", &qdevice_model) == CS_OK) {
  995. if (strlen(qdevice_model)) {
  996. if (icmap_get_uint32("quorum.device.votes", qdevice_votes) != CS_OK) {
  997. *qdevice_votes = -1;
  998. }
  999. if (icmap_get_uint32("quorum.device.timeout", &qdevice_timeout) != CS_OK) {
  1000. qdevice_timeout = VOTEQUORUM_QDEVICE_DEFAULT_TIMEOUT;
  1001. }
  1002. if (icmap_get_uint32("quorum.device.sync_timeout", &qdevice_sync_timeout) != CS_OK) {
  1003. qdevice_sync_timeout = VOTEQUORUM_QDEVICE_DEFAULT_SYNC_TIMEOUT;
  1004. }
  1005. update_qdevice_can_operate(1);
  1006. ret = 1;
  1007. }
  1008. free(qdevice_model);
  1009. }
  1010. LEAVE();
  1011. return ret;
  1012. }
  1013. #define VOTEQUORUM_READCONFIG_STARTUP 0
  1014. #define VOTEQUORUM_READCONFIG_RUNTIME 1
  1015. static char *votequorum_readconfig(int runtime)
  1016. {
  1017. uint32_t node_votes = 0, qdevice_votes = 0;
  1018. uint32_t node_expected_votes = 0, expected_votes = 0;
  1019. uint32_t node_count = 0;
  1020. uint8_t atb = 0;
  1021. int have_nodelist, have_qdevice;
  1022. char *atb_string = NULL;
  1023. char *error = NULL;
  1024. ENTER();
  1025. log_printf(LOGSYS_LEVEL_DEBUG, "Reading configuration (runtime: %d)", runtime);
  1026. /*
  1027. * Set the few things we re-read at runtime back to their defaults
  1028. */
  1029. if (runtime) {
  1030. two_node = 0;
  1031. expected_votes = 0;
  1032. }
  1033. /*
  1034. * gather basic data here
  1035. */
  1036. icmap_get_uint32("quorum.expected_votes", &expected_votes);
  1037. have_nodelist = votequorum_read_nodelist_configuration(&node_votes, &node_count, &node_expected_votes);
  1038. have_qdevice = votequorum_qdevice_is_configured(&qdevice_votes);
  1039. icmap_get_uint8("quorum.two_node", &two_node);
  1040. /*
  1041. * do config verification and enablement
  1042. */
  1043. if ((!have_nodelist) && (!expected_votes)) {
  1044. if (!runtime) {
  1045. error = (char *)"configuration error: nodelist or quorum.expected_votes must be configured!";
  1046. } else {
  1047. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: nodelist or quorum.expected_votes must be configured!");
  1048. log_printf(LOGSYS_LEVEL_CRIT, "will continue with current runtime data");
  1049. }
  1050. goto out;
  1051. }
  1052. /*
  1053. * two_node and qdevice are not compatible in the same config.
  1054. * try to make an educated guess of what to do
  1055. */
  1056. if ((two_node) && (have_qdevice)) {
  1057. if (!runtime) {
  1058. error = (char *)"configuration error: two_node and quorum device cannot be configured at the same time!";
  1059. goto out;
  1060. } else {
  1061. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: two_node and quorum device cannot be configured at the same time!");
  1062. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1063. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is registered, disabling two_node");
  1064. two_node = 0;
  1065. } else {
  1066. log_printf(LOGSYS_LEVEL_CRIT, "quorum device is not registered, allowing two_node");
  1067. update_qdevice_can_operate(0);
  1068. }
  1069. }
  1070. }
  1071. /*
  1072. * Enable special features
  1073. */
  1074. if (!runtime) {
  1075. if (two_node) {
  1076. wait_for_all = 1;
  1077. }
  1078. icmap_get_uint8("quorum.allow_downscale", &allow_downscale);
  1079. icmap_get_uint8("quorum.wait_for_all", &wait_for_all);
  1080. icmap_get_uint8("quorum.last_man_standing", &last_man_standing);
  1081. icmap_get_uint32("quorum.last_man_standing_window", &last_man_standing_window);
  1082. icmap_get_uint8("quorum.expected_votes_tracking", &ev_tracking);
  1083. icmap_get_uint8("quorum.auto_tie_breaker", &atb);
  1084. icmap_get_string("quorum.auto_tie_breaker_node", &atb_string);
  1085. /* auto_tie_breaker defaults to LOWEST */
  1086. if (atb) {
  1087. auto_tie_breaker = ATB_LOWEST;
  1088. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  1089. }
  1090. else {
  1091. auto_tie_breaker = ATB_NONE;
  1092. if (atb_string) {
  1093. log_printf(LOGSYS_LEVEL_WARNING,
  1094. "auto_tie_breaker_node: is meaningless if auto_tie_breaker is set to 0");
  1095. }
  1096. }
  1097. if (atb && atb_string) {
  1098. parse_atb_string(atb_string);
  1099. }
  1100. free(atb_string);
  1101. /* allow_downscale requires ev_tracking */
  1102. if (allow_downscale) {
  1103. ev_tracking = 1;
  1104. }
  1105. if (ev_tracking) {
  1106. if (load_ev_tracking_barrier() < 0) {
  1107. LEAVE();
  1108. return ((char *)"Unable to load ev_tracking file!");
  1109. }
  1110. update_ev_tracking_barrier(ev_tracking_barrier);
  1111. }
  1112. }
  1113. /* two_node and auto_tie_breaker are not compatible as two_node uses
  1114. * a fence race to decide quorum whereas ATB decides based on node id
  1115. */
  1116. if (two_node && auto_tie_breaker != ATB_NONE) {
  1117. log_printf(LOGSYS_LEVEL_CRIT, "two_node and auto_tie_breaker are both specified but are not compatible.");
  1118. log_printf(LOGSYS_LEVEL_CRIT, "two_node has been disabled, please fix your corosync.conf");
  1119. two_node = 0;
  1120. }
  1121. /* If ATB is set and the cluster has an odd number of nodes then wait_for_all needs
  1122. * to be set so that an isolated half+1 without the tie breaker node
  1123. * does not have quorum on reboot.
  1124. */
  1125. if ((auto_tie_breaker != ATB_NONE) && (node_expected_votes % 2) &&
  1126. (!wait_for_all)) {
  1127. if (last_man_standing) {
  1128. /* if LMS is set too, it's a fatal configuration error. We can't dictate to the user what
  1129. * they might want so we'll just quit.
  1130. */
  1131. log_printf(LOGSYS_LEVEL_CRIT, "auto_tie_breaker is set, the cluster has an odd number of nodes\n");
  1132. log_printf(LOGSYS_LEVEL_CRIT, "and last_man_standing is also set. With this situation a better\n");
  1133. log_printf(LOGSYS_LEVEL_CRIT, "solution would be to disable LMS, leave ATB enabled, and also\n");
  1134. log_printf(LOGSYS_LEVEL_CRIT, "enable wait_for_all (mandatory for ATB in odd-numbered clusters).\n");
  1135. log_printf(LOGSYS_LEVEL_CRIT, "Due to this ambiguity, corosync will fail to start. Please fix your corosync.conf\n");
  1136. error = (char *)"configuration error: auto_tie_breaker & last_man_standing not available in odd sized cluster";
  1137. goto out;
  1138. }
  1139. else {
  1140. log_printf(LOGSYS_LEVEL_CRIT, "auto_tie_breaker is set and the cluster has an odd number of nodes.\n");
  1141. log_printf(LOGSYS_LEVEL_CRIT, "wait_for_all needs to be set for this configuration but it is missing\n");
  1142. log_printf(LOGSYS_LEVEL_CRIT, "Therefore auto_tie_breaker has been disabled. Please fix your corosync.conf\n");
  1143. auto_tie_breaker = ATB_NONE;
  1144. icmap_set_uint32("runtime.votequorum.atb_type", auto_tie_breaker);
  1145. }
  1146. }
  1147. /*
  1148. * quorum device is not compatible with last_man_standing and auto_tie_breaker
  1149. * neither lms or atb can be set at runtime, so there is no need to check for
  1150. * runtime incompatibilities, but qdevice can be configured _after_ LMS and ATB have
  1151. * been enabled at startup.
  1152. */
  1153. if ((have_qdevice) && (last_man_standing)) {
  1154. if (!runtime) {
  1155. error = (char *)"configuration error: quorum.device is not compatible with last_man_standing";
  1156. goto out;
  1157. } else {
  1158. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with last_man_standing");
  1159. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1160. update_qdevice_can_operate(0);
  1161. }
  1162. }
  1163. if ((have_qdevice) && (auto_tie_breaker != ATB_NONE)) {
  1164. if (!runtime) {
  1165. error = (char *)"configuration error: quorum.device is not compatible with auto_tie_breaker";
  1166. goto out;
  1167. } else {
  1168. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with auto_tie_breaker");
  1169. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1170. update_qdevice_can_operate(0);
  1171. }
  1172. }
  1173. if ((have_qdevice) && (allow_downscale)) {
  1174. if (!runtime) {
  1175. error = (char *)"configuration error: quorum.device is not compatible with allow_downscale";
  1176. goto out;
  1177. } else {
  1178. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device is not compatible with allow_downscale");
  1179. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1180. update_qdevice_can_operate(0);
  1181. }
  1182. }
  1183. /*
  1184. * if user specifies quorum.expected_votes + quorum.device but NOT the device.votes
  1185. * we don't know what the quorum device should vote.
  1186. */
  1187. if ((expected_votes) && (have_qdevice) && (qdevice_votes == -1)) {
  1188. if (!runtime) {
  1189. error = (char *)"configuration error: quorum.device.votes must be specified when quorum.expected_votes is set";
  1190. goto out;
  1191. } else {
  1192. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when quorum.expected_votes is set");
  1193. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1194. update_qdevice_can_operate(0);
  1195. }
  1196. }
  1197. /*
  1198. * if user specifies a node list with uneven votes and no device.votes
  1199. * we cannot autocalculate the votes
  1200. */
  1201. if ((have_qdevice) &&
  1202. (qdevice_votes == -1) &&
  1203. (have_nodelist) &&
  1204. (node_count != node_expected_votes)) {
  1205. if (!runtime) {
  1206. error = (char *)"configuration error: quorum.device.votes must be specified when not all nodes votes 1";
  1207. goto out;
  1208. } else {
  1209. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes must be specified when not all nodes votes 1");
  1210. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1211. update_qdevice_can_operate(0);
  1212. }
  1213. }
  1214. /*
  1215. * validate quorum device votes vs expected_votes
  1216. */
  1217. if ((qdevice_votes > 0) && (expected_votes)) {
  1218. int delta = expected_votes - qdevice_votes;
  1219. if (delta < 2) {
  1220. if (!runtime) {
  1221. error = (char *)"configuration error: quorum.device.votes is too high or expected_votes is too low";
  1222. goto out;
  1223. } else {
  1224. log_printf(LOGSYS_LEVEL_CRIT, "configuration error: quorum.device.votes is too high or expected_votes is too low");
  1225. log_printf(LOGSYS_LEVEL_CRIT, "disabling quorum device operations");
  1226. update_qdevice_can_operate(0);
  1227. }
  1228. }
  1229. }
  1230. /*
  1231. * automatically calculate device votes and adjust expected_votes from nodelist
  1232. */
  1233. if ((have_qdevice) &&
  1234. (qdevice_votes == -1) &&
  1235. (!expected_votes) &&
  1236. (have_nodelist) &&
  1237. (node_count == node_expected_votes)) {
  1238. qdevice_votes = node_expected_votes - 1;
  1239. node_expected_votes = node_expected_votes + qdevice_votes;
  1240. }
  1241. /*
  1242. * set this node votes and expected_votes
  1243. */
  1244. log_printf(LOGSYS_LEVEL_DEBUG, "ev_tracking=%d, ev_tracking_barrier = %d: expected_votes = %d\n", ev_tracking, ev_tracking_barrier, expected_votes);
  1245. if (ev_tracking) {
  1246. expected_votes = ev_tracking_barrier;
  1247. }
  1248. if (have_nodelist) {
  1249. us->votes = node_votes;
  1250. us->expected_votes = node_expected_votes;
  1251. } else {
  1252. us->votes = 1;
  1253. icmap_get_uint32("quorum.votes", &us->votes);
  1254. }
  1255. if (expected_votes) {
  1256. us->expected_votes = expected_votes;
  1257. }
  1258. /*
  1259. * set qdevice votes
  1260. */
  1261. if (!have_qdevice) {
  1262. qdevice->votes = 0;
  1263. }
  1264. if (qdevice_votes != -1) {
  1265. qdevice->votes = qdevice_votes;
  1266. }
  1267. update_ev_barrier(us->expected_votes);
  1268. update_two_node();
  1269. if (wait_for_all) {
  1270. update_wait_for_all_status(1);
  1271. }
  1272. out:
  1273. LEAVE();
  1274. return error;
  1275. }
  1276. static void votequorum_refresh_config(
  1277. int32_t event,
  1278. const char *key_name,
  1279. struct icmap_notify_value new_val,
  1280. struct icmap_notify_value old_val,
  1281. void *user_data)
  1282. {
  1283. int old_votes, old_expected_votes;
  1284. uint8_t reloading;
  1285. uint8_t cancel_wfa;
  1286. ENTER();
  1287. /*
  1288. * If a full reload is in progress then don't do anything until it's done and
  1289. * can reconfigure it all atomically
  1290. */
  1291. if (icmap_get_uint8("config.totemconfig_reload_in_progress", &reloading) == CS_OK && reloading) {
  1292. return ;
  1293. }
  1294. icmap_get_uint8("quorum.cancel_wait_for_all", &cancel_wfa);
  1295. if (strcmp(key_name, "quorum.cancel_wait_for_all") == 0 &&
  1296. cancel_wfa >= 1) {
  1297. icmap_set_uint8("quorum.cancel_wait_for_all", 0);
  1298. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA,
  1299. us->node_id, 0);
  1300. return;
  1301. }
  1302. old_votes = us->votes;
  1303. old_expected_votes = us->expected_votes;
  1304. /*
  1305. * Reload the configuration
  1306. */
  1307. votequorum_readconfig(VOTEQUORUM_READCONFIG_RUNTIME);
  1308. /*
  1309. * activate new config
  1310. */
  1311. votequorum_exec_send_nodeinfo(us->node_id);
  1312. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1313. if (us->votes != old_votes) {
  1314. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES,
  1315. us->node_id, us->votes);
  1316. }
  1317. if (us->expected_votes != old_expected_votes) {
  1318. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES,
  1319. us->node_id, us->expected_votes);
  1320. }
  1321. LEAVE();
  1322. }
  1323. static void votequorum_exec_add_config_notification(void)
  1324. {
  1325. icmap_track_t icmap_track_nodelist = NULL;
  1326. icmap_track_t icmap_track_quorum = NULL;
  1327. icmap_track_t icmap_track_reload = NULL;
  1328. ENTER();
  1329. icmap_track_add("nodelist.",
  1330. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1331. votequorum_refresh_config,
  1332. NULL,
  1333. &icmap_track_nodelist);
  1334. icmap_track_add("quorum.",
  1335. ICMAP_TRACK_ADD | ICMAP_TRACK_DELETE | ICMAP_TRACK_MODIFY | ICMAP_TRACK_PREFIX,
  1336. votequorum_refresh_config,
  1337. NULL,
  1338. &icmap_track_quorum);
  1339. icmap_track_add("config.totemconfig_reload_in_progress",
  1340. ICMAP_TRACK_ADD | ICMAP_TRACK_MODIFY,
  1341. votequorum_refresh_config,
  1342. NULL,
  1343. &icmap_track_reload);
  1344. LEAVE();
  1345. }
  1346. /*
  1347. * votequorum_exec core
  1348. */
  1349. static int votequorum_exec_send_reconfigure(uint8_t param, unsigned int nodeid, uint32_t value)
  1350. {
  1351. struct req_exec_quorum_reconfigure req_exec_quorum_reconfigure;
  1352. struct iovec iov[1];
  1353. int ret;
  1354. ENTER();
  1355. req_exec_quorum_reconfigure.nodeid = nodeid;
  1356. req_exec_quorum_reconfigure.value = value;
  1357. req_exec_quorum_reconfigure.param = param;
  1358. req_exec_quorum_reconfigure._pad0 = 0;
  1359. req_exec_quorum_reconfigure._pad1 = 0;
  1360. req_exec_quorum_reconfigure._pad2 = 0;
  1361. req_exec_quorum_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_RECONFIGURE);
  1362. req_exec_quorum_reconfigure.header.size = sizeof(req_exec_quorum_reconfigure);
  1363. iov[0].iov_base = (void *)&req_exec_quorum_reconfigure;
  1364. iov[0].iov_len = sizeof(req_exec_quorum_reconfigure);
  1365. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1366. LEAVE();
  1367. return ret;
  1368. }
  1369. static int votequorum_exec_send_nodeinfo(uint32_t nodeid)
  1370. {
  1371. struct req_exec_quorum_nodeinfo req_exec_quorum_nodeinfo;
  1372. struct iovec iov[1];
  1373. struct cluster_node *node;
  1374. int ret;
  1375. ENTER();
  1376. node = find_node_by_nodeid(nodeid);
  1377. if (!node) {
  1378. return -1;
  1379. }
  1380. req_exec_quorum_nodeinfo.nodeid = nodeid;
  1381. req_exec_quorum_nodeinfo.votes = node->votes;
  1382. req_exec_quorum_nodeinfo.expected_votes = node->expected_votes;
  1383. req_exec_quorum_nodeinfo.flags = node->flags;
  1384. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  1385. decode_flags(node->flags);
  1386. }
  1387. req_exec_quorum_nodeinfo.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_NODEINFO);
  1388. req_exec_quorum_nodeinfo.header.size = sizeof(req_exec_quorum_nodeinfo);
  1389. iov[0].iov_base = (void *)&req_exec_quorum_nodeinfo;
  1390. iov[0].iov_len = sizeof(req_exec_quorum_nodeinfo);
  1391. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1392. LEAVE();
  1393. return ret;
  1394. }
  1395. static int votequorum_exec_send_qdevice_reconfigure(const char *oldname, const char *newname)
  1396. {
  1397. struct req_exec_quorum_qdevice_reconfigure req_exec_quorum_qdevice_reconfigure;
  1398. struct iovec iov[1];
  1399. int ret;
  1400. ENTER();
  1401. req_exec_quorum_qdevice_reconfigure.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_RECONFIGURE);
  1402. req_exec_quorum_qdevice_reconfigure.header.size = sizeof(req_exec_quorum_qdevice_reconfigure);
  1403. strcpy(req_exec_quorum_qdevice_reconfigure.oldname, oldname);
  1404. strcpy(req_exec_quorum_qdevice_reconfigure.newname, newname);
  1405. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reconfigure;
  1406. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reconfigure);
  1407. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1408. LEAVE();
  1409. return ret;
  1410. }
  1411. static int votequorum_exec_send_qdevice_reg(uint32_t operation, const char *qdevice_name_req)
  1412. {
  1413. struct req_exec_quorum_qdevice_reg req_exec_quorum_qdevice_reg;
  1414. struct iovec iov[1];
  1415. int ret;
  1416. ENTER();
  1417. req_exec_quorum_qdevice_reg.header.id = SERVICE_ID_MAKE(VOTEQUORUM_SERVICE, MESSAGE_REQ_EXEC_VOTEQUORUM_QDEVICE_REG);
  1418. req_exec_quorum_qdevice_reg.header.size = sizeof(req_exec_quorum_qdevice_reg);
  1419. req_exec_quorum_qdevice_reg.operation = operation;
  1420. strcpy(req_exec_quorum_qdevice_reg.qdevice_name, qdevice_name_req);
  1421. iov[0].iov_base = (void *)&req_exec_quorum_qdevice_reg;
  1422. iov[0].iov_len = sizeof(req_exec_quorum_qdevice_reg);
  1423. ret = corosync_api->totem_mcast (iov, 1, TOTEM_AGREED);
  1424. LEAVE();
  1425. return ret;
  1426. }
  1427. static int votequorum_exec_send_quorum_notification(void *conn, uint64_t context)
  1428. {
  1429. struct res_lib_votequorum_quorum_notification *res_lib_votequorum_notification;
  1430. struct list_head *tmp;
  1431. struct cluster_node *node;
  1432. int i = 0;
  1433. int cluster_members = 0;
  1434. int size;
  1435. char buf[sizeof(struct res_lib_votequorum_quorum_notification) + sizeof(struct votequorum_node) * (PROCESSOR_COUNT_MAX + 2)];
  1436. ENTER();
  1437. log_printf(LOGSYS_LEVEL_DEBUG, "Sending quorum callback, quorate = %d", cluster_is_quorate);
  1438. list_iterate(tmp, &cluster_members_list) {
  1439. node = list_entry(tmp, struct cluster_node, list);
  1440. cluster_members++;
  1441. }
  1442. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1443. cluster_members++;
  1444. }
  1445. size = sizeof(struct res_lib_votequorum_quorum_notification) + sizeof(struct votequorum_node) * cluster_members;
  1446. res_lib_votequorum_notification = (struct res_lib_votequorum_quorum_notification *)&buf;
  1447. res_lib_votequorum_notification->quorate = cluster_is_quorate;
  1448. res_lib_votequorum_notification->context = context;
  1449. res_lib_votequorum_notification->node_list_entries = cluster_members;
  1450. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_QUORUM_NOTIFICATION;
  1451. res_lib_votequorum_notification->header.size = size;
  1452. res_lib_votequorum_notification->header.error = CS_OK;
  1453. /* Send all known nodes and their states */
  1454. list_iterate(tmp, &cluster_members_list) {
  1455. node = list_entry(tmp, struct cluster_node, list);
  1456. res_lib_votequorum_notification->node_list[i].nodeid = node->node_id;
  1457. res_lib_votequorum_notification->node_list[i++].state = node->state;
  1458. }
  1459. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1460. res_lib_votequorum_notification->node_list[i].nodeid = VOTEQUORUM_QDEVICE_NODEID;
  1461. res_lib_votequorum_notification->node_list[i++].state = qdevice->state;
  1462. }
  1463. /* Send it to all interested parties */
  1464. if (conn) {
  1465. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1466. LEAVE();
  1467. return ret;
  1468. } else {
  1469. struct quorum_pd *qpd;
  1470. list_iterate(tmp, &trackers_list) {
  1471. qpd = list_entry(tmp, struct quorum_pd, list);
  1472. res_lib_votequorum_notification->context = qpd->tracking_context;
  1473. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1474. }
  1475. }
  1476. LEAVE();
  1477. return 0;
  1478. }
  1479. static int votequorum_exec_send_nodelist_notification(void *conn, uint64_t context)
  1480. {
  1481. struct res_lib_votequorum_nodelist_notification *res_lib_votequorum_notification;
  1482. int i = 0;
  1483. int size;
  1484. struct list_head *tmp;
  1485. char buf[sizeof(struct res_lib_votequorum_nodelist_notification) + sizeof(uint32_t) * quorum_members_entries];
  1486. ENTER();
  1487. log_printf(LOGSYS_LEVEL_DEBUG, "Sending nodelist callback. ring_id = %d/%lld", quorum_ringid.rep.nodeid, quorum_ringid.seq);
  1488. size = sizeof(struct res_lib_votequorum_nodelist_notification) + sizeof(uint32_t) * quorum_members_entries;
  1489. res_lib_votequorum_notification = (struct res_lib_votequorum_nodelist_notification *)&buf;
  1490. res_lib_votequorum_notification->node_list_entries = quorum_members_entries;
  1491. res_lib_votequorum_notification->ring_id.nodeid = quorum_ringid.rep.nodeid;
  1492. res_lib_votequorum_notification->ring_id.seq = quorum_ringid.seq;
  1493. res_lib_votequorum_notification->context = context;
  1494. for (i=0; i<quorum_members_entries; i++) {
  1495. res_lib_votequorum_notification->node_list[i] = quorum_members[i];
  1496. }
  1497. res_lib_votequorum_notification->header.id = MESSAGE_RES_VOTEQUORUM_NODELIST_NOTIFICATION;
  1498. res_lib_votequorum_notification->header.size = size;
  1499. res_lib_votequorum_notification->header.error = CS_OK;
  1500. /* Send it to all interested parties */
  1501. if (conn) {
  1502. int ret = corosync_api->ipc_dispatch_send(conn, &buf, size);
  1503. LEAVE();
  1504. return ret;
  1505. } else {
  1506. struct quorum_pd *qpd;
  1507. list_iterate(tmp, &trackers_list) {
  1508. qpd = list_entry(tmp, struct quorum_pd, list);
  1509. res_lib_votequorum_notification->context = qpd->tracking_context;
  1510. corosync_api->ipc_dispatch_send(qpd->conn, &buf, size);
  1511. }
  1512. }
  1513. LEAVE();
  1514. return 0;
  1515. }
  1516. static void votequorum_exec_send_expectedvotes_notification(void)
  1517. {
  1518. struct res_lib_votequorum_expectedvotes_notification res_lib_votequorum_expectedvotes_notification;
  1519. struct quorum_pd *qpd;
  1520. struct list_head *tmp;
  1521. ENTER();
  1522. log_printf(LOGSYS_LEVEL_DEBUG, "Sending expected votes callback");
  1523. res_lib_votequorum_expectedvotes_notification.header.id = MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION;
  1524. res_lib_votequorum_expectedvotes_notification.header.size = sizeof(res_lib_votequorum_expectedvotes_notification);
  1525. res_lib_votequorum_expectedvotes_notification.header.error = CS_OK;
  1526. res_lib_votequorum_expectedvotes_notification.expected_votes = us->expected_votes;
  1527. list_iterate(tmp, &trackers_list) {
  1528. qpd = list_entry(tmp, struct quorum_pd, list);
  1529. res_lib_votequorum_expectedvotes_notification.context = qpd->tracking_context;
  1530. corosync_api->ipc_dispatch_send(qpd->conn, &res_lib_votequorum_expectedvotes_notification,
  1531. sizeof(struct res_lib_votequorum_expectedvotes_notification));
  1532. }
  1533. LEAVE();
  1534. }
  1535. static void exec_votequorum_qdevice_reconfigure_endian_convert (void *message)
  1536. {
  1537. ENTER();
  1538. LEAVE();
  1539. }
  1540. static void message_handler_req_exec_votequorum_qdevice_reconfigure (
  1541. const void *message,
  1542. unsigned int nodeid)
  1543. {
  1544. const struct req_exec_quorum_qdevice_reconfigure *req_exec_quorum_qdevice_reconfigure = message;
  1545. ENTER();
  1546. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice name change req from node %u [from: %s to: %s]",
  1547. nodeid,
  1548. req_exec_quorum_qdevice_reconfigure->oldname,
  1549. req_exec_quorum_qdevice_reconfigure->newname);
  1550. if (!strcmp(req_exec_quorum_qdevice_reconfigure->oldname, qdevice_name)) {
  1551. log_printf(LOGSYS_LEVEL_DEBUG, "Allowing qdevice rename");
  1552. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1553. strcpy(qdevice_name, req_exec_quorum_qdevice_reconfigure->newname);
  1554. /*
  1555. * TODO: notify qdevices about name change?
  1556. * this is not relevant for now and can wait later on since
  1557. * qdevices are local only and libvotequorum is not final
  1558. */
  1559. }
  1560. LEAVE();
  1561. }
  1562. static void exec_votequorum_qdevice_reg_endian_convert (void *message)
  1563. {
  1564. struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1565. ENTER();
  1566. req_exec_quorum_qdevice_reg->operation = swab32(req_exec_quorum_qdevice_reg->operation);
  1567. LEAVE();
  1568. }
  1569. static void message_handler_req_exec_votequorum_qdevice_reg (
  1570. const void *message,
  1571. unsigned int nodeid)
  1572. {
  1573. const struct req_exec_quorum_qdevice_reg *req_exec_quorum_qdevice_reg = message;
  1574. struct res_lib_votequorum_status res_lib_votequorum_status;
  1575. int wipe_qdevice_name = 1;
  1576. struct cluster_node *node = NULL;
  1577. struct list_head *tmp;
  1578. cs_error_t error = CS_OK;
  1579. ENTER();
  1580. log_printf(LOGSYS_LEVEL_DEBUG, "Received qdevice op %u req from node %u [%s]",
  1581. req_exec_quorum_qdevice_reg->operation,
  1582. nodeid, req_exec_quorum_qdevice_reg->qdevice_name);
  1583. switch(req_exec_quorum_qdevice_reg->operation)
  1584. {
  1585. case VOTEQUORUM_QDEVICE_OPERATION_REGISTER:
  1586. if (nodeid != us->node_id) {
  1587. if (!strlen(qdevice_name)) {
  1588. log_printf(LOGSYS_LEVEL_DEBUG, "Remote qdevice name recorded");
  1589. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1590. }
  1591. LEAVE();
  1592. return;
  1593. }
  1594. /*
  1595. * protect against the case where we broadcast qdevice registration
  1596. * to new memebers, we receive the message back, but there is no registration
  1597. * connection in progress
  1598. */
  1599. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  1600. LEAVE();
  1601. return;
  1602. }
  1603. /*
  1604. * this should NEVER happen
  1605. */
  1606. if (!qdevice_reg_conn) {
  1607. log_printf(LOGSYS_LEVEL_WARNING, "Unable to determine origin of the qdevice register call!");
  1608. LEAVE();
  1609. return;
  1610. }
  1611. /*
  1612. * registering our own device in this case
  1613. */
  1614. if (!strlen(qdevice_name)) {
  1615. strcpy(qdevice_name, req_exec_quorum_qdevice_reg->qdevice_name);
  1616. }
  1617. /*
  1618. * check if it is our device or something else
  1619. */
  1620. if ((!strncmp(req_exec_quorum_qdevice_reg->qdevice_name,
  1621. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  1622. us->flags |= NODE_FLAGS_QDEVICE_REGISTERED;
  1623. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1624. votequorum_exec_send_nodeinfo(us->node_id);
  1625. } else {
  1626. log_printf(LOGSYS_LEVEL_WARNING,
  1627. "A new qdevice with different name (new: %s old: %s) is trying to register!",
  1628. req_exec_quorum_qdevice_reg->qdevice_name, qdevice_name);
  1629. error = CS_ERR_EXIST;
  1630. }
  1631. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  1632. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  1633. res_lib_votequorum_status.header.error = error;
  1634. corosync_api->ipc_response_send(qdevice_reg_conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  1635. qdevice_reg_conn = NULL;
  1636. break;
  1637. case VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER:
  1638. list_iterate(tmp, &cluster_members_list) {
  1639. node = list_entry(tmp, struct cluster_node, list);
  1640. if ((node->state == NODESTATE_MEMBER) &&
  1641. (node->flags & NODE_FLAGS_QDEVICE_REGISTERED)) {
  1642. wipe_qdevice_name = 0;
  1643. }
  1644. }
  1645. if (wipe_qdevice_name) {
  1646. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1647. }
  1648. break;
  1649. }
  1650. LEAVE();
  1651. }
  1652. static void exec_votequorum_nodeinfo_endian_convert (void *message)
  1653. {
  1654. struct req_exec_quorum_nodeinfo *nodeinfo = message;
  1655. ENTER();
  1656. nodeinfo->nodeid = swab32(nodeinfo->nodeid);
  1657. nodeinfo->votes = swab32(nodeinfo->votes);
  1658. nodeinfo->expected_votes = swab32(nodeinfo->expected_votes);
  1659. nodeinfo->flags = swab32(nodeinfo->flags);
  1660. LEAVE();
  1661. }
  1662. static void message_handler_req_exec_votequorum_nodeinfo (
  1663. const void *message,
  1664. unsigned int sender_nodeid)
  1665. {
  1666. const struct req_exec_quorum_nodeinfo *req_exec_quorum_nodeinfo = message;
  1667. struct cluster_node *node = NULL;
  1668. int old_votes;
  1669. int old_expected;
  1670. uint32_t old_flags;
  1671. nodestate_t old_state;
  1672. int new_node = 0;
  1673. int allow_downgrade = 0;
  1674. int by_node = 0;
  1675. unsigned int nodeid = req_exec_quorum_nodeinfo->nodeid;
  1676. ENTER();
  1677. log_printf(LOGSYS_LEVEL_DEBUG, "got nodeinfo message from cluster node %u", sender_nodeid);
  1678. log_printf(LOGSYS_LEVEL_DEBUG, "nodeinfo message[%u]: votes: %d, expected: %d flags: %d",
  1679. nodeid,
  1680. req_exec_quorum_nodeinfo->votes,
  1681. req_exec_quorum_nodeinfo->expected_votes,
  1682. req_exec_quorum_nodeinfo->flags);
  1683. if (nodeid != VOTEQUORUM_QDEVICE_NODEID) {
  1684. decode_flags(req_exec_quorum_nodeinfo->flags);
  1685. }
  1686. node = find_node_by_nodeid(nodeid);
  1687. if (!node) {
  1688. node = allocate_node(nodeid);
  1689. new_node = 1;
  1690. }
  1691. if (!node) {
  1692. corosync_api->error_memory_failure();
  1693. LEAVE();
  1694. return;
  1695. }
  1696. if (new_node) {
  1697. old_votes = 0;
  1698. old_expected = 0;
  1699. old_state = NODESTATE_DEAD;
  1700. old_flags = 0;
  1701. } else {
  1702. old_votes = node->votes;
  1703. old_expected = node->expected_votes;
  1704. old_state = node->state;
  1705. old_flags = node->flags;
  1706. }
  1707. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  1708. struct cluster_node *sender_node = find_node_by_nodeid(sender_nodeid);
  1709. assert(sender_node != NULL);
  1710. if ((!cluster_is_quorate) &&
  1711. (sender_node->flags & NODE_FLAGS_QUORATE)) {
  1712. node->votes = req_exec_quorum_nodeinfo->votes;
  1713. } else {
  1714. node->votes = max(node->votes, req_exec_quorum_nodeinfo->votes);
  1715. }
  1716. goto recalculate;
  1717. }
  1718. /* Update node state */
  1719. node->flags = req_exec_quorum_nodeinfo->flags;
  1720. node->votes = req_exec_quorum_nodeinfo->votes;
  1721. node->state = NODESTATE_MEMBER;
  1722. if (node->flags & NODE_FLAGS_LEAVING) {
  1723. node->state = NODESTATE_LEAVING;
  1724. allow_downgrade = 1;
  1725. by_node = 1;
  1726. }
  1727. if ((!cluster_is_quorate) &&
  1728. (node->flags & NODE_FLAGS_QUORATE)) {
  1729. allow_downgrade = 1;
  1730. us->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1731. }
  1732. if (node->flags & NODE_FLAGS_QUORATE || (ev_tracking)) {
  1733. node->expected_votes = req_exec_quorum_nodeinfo->expected_votes;
  1734. } else {
  1735. node->expected_votes = us->expected_votes;
  1736. }
  1737. if ((last_man_standing) && (node->votes > 1)) {
  1738. log_printf(LOGSYS_LEVEL_WARNING, "Last Man Standing feature is supported only when all"
  1739. "cluster nodes votes are set to 1. Disabling LMS.");
  1740. last_man_standing = 0;
  1741. if (last_man_standing_timer_set) {
  1742. corosync_api->timer_delete(last_man_standing_timer);
  1743. last_man_standing_timer_set = 0;
  1744. }
  1745. }
  1746. recalculate:
  1747. if ((new_node) ||
  1748. (nodeid == us->node_id) ||
  1749. (node->flags & NODE_FLAGS_FIRST) ||
  1750. (old_votes != node->votes) ||
  1751. (old_expected != node->expected_votes) ||
  1752. (old_flags != node->flags) ||
  1753. (old_state != node->state)) {
  1754. recalculate_quorum(allow_downgrade, by_node);
  1755. }
  1756. if ((wait_for_all) &&
  1757. (!(node->flags & NODE_FLAGS_WFASTATUS)) &&
  1758. (node->flags & NODE_FLAGS_QUORATE)) {
  1759. update_wait_for_all_status(0);
  1760. }
  1761. LEAVE();
  1762. }
  1763. static void exec_votequorum_reconfigure_endian_convert (void *message)
  1764. {
  1765. struct req_exec_quorum_reconfigure *reconfigure = message;
  1766. ENTER();
  1767. reconfigure->nodeid = swab32(reconfigure->nodeid);
  1768. reconfigure->value = swab32(reconfigure->value);
  1769. LEAVE();
  1770. }
  1771. static void message_handler_req_exec_votequorum_reconfigure (
  1772. const void *message,
  1773. unsigned int nodeid)
  1774. {
  1775. const struct req_exec_quorum_reconfigure *req_exec_quorum_reconfigure = message;
  1776. struct cluster_node *node;
  1777. ENTER();
  1778. log_printf(LOGSYS_LEVEL_DEBUG, "got reconfigure message from cluster node %u for %u",
  1779. nodeid, req_exec_quorum_reconfigure->nodeid);
  1780. switch(req_exec_quorum_reconfigure->param)
  1781. {
  1782. case VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES:
  1783. update_node_expected_votes(req_exec_quorum_reconfigure->value);
  1784. votequorum_exec_send_expectedvotes_notification();
  1785. update_ev_barrier(req_exec_quorum_reconfigure->value);
  1786. if (ev_tracking) {
  1787. us->expected_votes = max(us->expected_votes, ev_tracking_barrier);
  1788. }
  1789. recalculate_quorum(1, 0); /* Allow decrease */
  1790. break;
  1791. case VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES:
  1792. node = find_node_by_nodeid(req_exec_quorum_reconfigure->nodeid);
  1793. if (!node) {
  1794. LEAVE();
  1795. return;
  1796. }
  1797. node->votes = req_exec_quorum_reconfigure->value;
  1798. recalculate_quorum(1, 0); /* Allow decrease */
  1799. break;
  1800. case VOTEQUORUM_RECONFIG_PARAM_CANCEL_WFA:
  1801. update_wait_for_all_status(0);
  1802. log_printf(LOGSYS_LEVEL_INFO, "wait_for_all_status reset by user on node %d.",
  1803. req_exec_quorum_reconfigure->nodeid);
  1804. recalculate_quorum(0, 0);
  1805. break;
  1806. }
  1807. LEAVE();
  1808. }
  1809. static int votequorum_exec_exit_fn (void)
  1810. {
  1811. int ret = 0;
  1812. ENTER();
  1813. /*
  1814. * tell the other nodes we are leaving
  1815. */
  1816. if (allow_downscale) {
  1817. us->flags |= NODE_FLAGS_LEAVING;
  1818. ret = votequorum_exec_send_nodeinfo(us->node_id);
  1819. }
  1820. if ((ev_tracking) && (ev_tracking_fd != -1)) {
  1821. close(ev_tracking_fd);
  1822. }
  1823. LEAVE();
  1824. return ret;
  1825. }
  1826. static void votequorum_set_icmap_ro_keys(void)
  1827. {
  1828. icmap_set_ro_access("quorum.allow_downscale", CS_FALSE, CS_TRUE);
  1829. icmap_set_ro_access("quorum.wait_for_all", CS_FALSE, CS_TRUE);
  1830. icmap_set_ro_access("quorum.last_man_standing", CS_FALSE, CS_TRUE);
  1831. icmap_set_ro_access("quorum.last_man_standing_window", CS_FALSE, CS_TRUE);
  1832. icmap_set_ro_access("quorum.expected_votes_tracking", CS_FALSE, CS_TRUE);
  1833. icmap_set_ro_access("quorum.auto_tie_breaker", CS_FALSE, CS_TRUE);
  1834. icmap_set_ro_access("quorum.auto_tie_breaker_node", CS_FALSE, CS_TRUE);
  1835. }
  1836. static char *votequorum_exec_init_fn (struct corosync_api_v1 *api)
  1837. {
  1838. char *error = NULL;
  1839. ENTER();
  1840. /*
  1841. * make sure we start clean
  1842. */
  1843. list_init(&cluster_members_list);
  1844. list_init(&trackers_list);
  1845. qdevice = NULL;
  1846. us = NULL;
  1847. memset(cluster_nodes, 0, sizeof(cluster_nodes));
  1848. /*
  1849. * Allocate a cluster_node for qdevice
  1850. */
  1851. qdevice = allocate_node(VOTEQUORUM_QDEVICE_NODEID);
  1852. if (!qdevice) {
  1853. LEAVE();
  1854. return ((char *)"Could not allocate node.");
  1855. }
  1856. qdevice->votes = 0;
  1857. memset(qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  1858. /*
  1859. * Allocate a cluster_node for us
  1860. */
  1861. us = allocate_node(corosync_api->totem_nodeid_get());
  1862. if (!us) {
  1863. LEAVE();
  1864. return ((char *)"Could not allocate node.");
  1865. }
  1866. icmap_set_uint32("runtime.votequorum.this_node_id", us->node_id);
  1867. us->state = NODESTATE_MEMBER;
  1868. us->votes = 1;
  1869. us->flags |= NODE_FLAGS_FIRST;
  1870. error = votequorum_readconfig(VOTEQUORUM_READCONFIG_STARTUP);
  1871. if (error) {
  1872. return error;
  1873. }
  1874. recalculate_quorum(0, 0);
  1875. /*
  1876. * Set RO keys in icmap
  1877. */
  1878. votequorum_set_icmap_ro_keys();
  1879. /*
  1880. * Listen for changes
  1881. */
  1882. votequorum_exec_add_config_notification();
  1883. /*
  1884. * Start us off with one node
  1885. */
  1886. votequorum_exec_send_nodeinfo(us->node_id);
  1887. LEAVE();
  1888. return (NULL);
  1889. }
  1890. /*
  1891. * votequorum service core
  1892. */
  1893. static void votequorum_last_man_standing_timer_fn(void *arg)
  1894. {
  1895. ENTER();
  1896. last_man_standing_timer_set = 0;
  1897. if (cluster_is_quorate) {
  1898. recalculate_quorum(1,1);
  1899. }
  1900. LEAVE();
  1901. }
  1902. static void votequorum_sync_init (
  1903. const unsigned int *trans_list, size_t trans_list_entries,
  1904. const unsigned int *member_list, size_t member_list_entries,
  1905. const struct memb_ring_id *ring_id)
  1906. {
  1907. int i, j;
  1908. int found;
  1909. int left_nodes;
  1910. struct cluster_node *node;
  1911. ENTER();
  1912. sync_in_progress = 1;
  1913. sync_nodeinfo_sent = 0;
  1914. sync_wait_for_poll_or_timeout = 0;
  1915. if (member_list_entries > 1) {
  1916. us->flags &= ~NODE_FLAGS_FIRST;
  1917. }
  1918. /*
  1919. * we don't need to track which nodes have left directly,
  1920. * since that info is in the node db, but we need to know
  1921. * if somebody has left for last_man_standing
  1922. */
  1923. left_nodes = 0;
  1924. for (i = 0; i < quorum_members_entries; i++) {
  1925. found = 0;
  1926. for (j = 0; j < member_list_entries; j++) {
  1927. if (quorum_members[i] == member_list[j]) {
  1928. found = 1;
  1929. break;
  1930. }
  1931. }
  1932. if (found == 0) {
  1933. left_nodes = 1;
  1934. node = find_node_by_nodeid(quorum_members[i]);
  1935. if (node) {
  1936. node->state = NODESTATE_DEAD;
  1937. }
  1938. }
  1939. }
  1940. if (last_man_standing) {
  1941. if (((member_list_entries >= quorum) && (left_nodes)) ||
  1942. ((member_list_entries <= quorum) && (auto_tie_breaker != ATB_NONE) && (check_low_node_id_partition() == 1))) {
  1943. if (last_man_standing_timer_set) {
  1944. corosync_api->timer_delete(last_man_standing_timer);
  1945. last_man_standing_timer_set = 0;
  1946. }
  1947. corosync_api->timer_add_duration((unsigned long long)last_man_standing_window*1000000,
  1948. NULL, votequorum_last_man_standing_timer_fn,
  1949. &last_man_standing_timer);
  1950. last_man_standing_timer_set = 1;
  1951. }
  1952. }
  1953. memcpy(previous_quorum_members, quorum_members, sizeof(unsigned int) * quorum_members_entries);
  1954. previous_quorum_members_entries = quorum_members_entries;
  1955. memcpy(quorum_members, member_list, sizeof(unsigned int) * member_list_entries);
  1956. quorum_members_entries = member_list_entries;
  1957. memcpy(&quorum_ringid, ring_id, sizeof(*ring_id));
  1958. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED && us->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  1959. /*
  1960. * Reset poll timer. Sync waiting is interrupted on valid qdevice poll or after timeout
  1961. */
  1962. if (qdevice_timer_set) {
  1963. corosync_api->timer_delete(qdevice_timer);
  1964. }
  1965. corosync_api->timer_add_duration((unsigned long long)qdevice_sync_timeout*1000000, qdevice,
  1966. qdevice_timer_fn, &qdevice_timer);
  1967. qdevice_timer_set = 1;
  1968. sync_wait_for_poll_or_timeout = 1;
  1969. log_printf(LOGSYS_LEVEL_INFO, "waiting for quorum device %s poll (but maximum for %u ms)",
  1970. qdevice_name, qdevice_sync_timeout);
  1971. }
  1972. LEAVE();
  1973. }
  1974. static int votequorum_sync_process (void)
  1975. {
  1976. if (!sync_nodeinfo_sent) {
  1977. votequorum_exec_send_nodeinfo(us->node_id);
  1978. votequorum_exec_send_nodeinfo(VOTEQUORUM_QDEVICE_NODEID);
  1979. if (strlen(qdevice_name)) {
  1980. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  1981. qdevice_name);
  1982. }
  1983. votequorum_exec_send_nodelist_notification(NULL, 0LL);
  1984. sync_nodeinfo_sent = 1;
  1985. }
  1986. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED && sync_wait_for_poll_or_timeout) {
  1987. /*
  1988. * Waiting for qdevice to poll with new ringid or timeout
  1989. */
  1990. return (-1);
  1991. }
  1992. return 0;
  1993. }
  1994. static void votequorum_sync_activate (void)
  1995. {
  1996. recalculate_quorum(0, 0);
  1997. quorum_callback(quorum_members, quorum_members_entries,
  1998. cluster_is_quorate, &quorum_ringid);
  1999. votequorum_exec_send_quorum_notification(NULL, 0L);
  2000. sync_in_progress = 0;
  2001. }
  2002. static void votequorum_sync_abort (void)
  2003. {
  2004. }
  2005. char *votequorum_init(struct corosync_api_v1 *api,
  2006. quorum_set_quorate_fn_t q_set_quorate_fn)
  2007. {
  2008. char *error;
  2009. ENTER();
  2010. if (q_set_quorate_fn == NULL) {
  2011. return ((char *)"Quorate function not set");
  2012. }
  2013. corosync_api = api;
  2014. quorum_callback = q_set_quorate_fn;
  2015. error = corosync_service_link_and_init(corosync_api,
  2016. &votequorum_service[0]);
  2017. if (error) {
  2018. return (error);
  2019. }
  2020. LEAVE();
  2021. return (NULL);
  2022. }
  2023. /*
  2024. * Library Handler init/fini
  2025. */
  2026. static int quorum_lib_init_fn (void *conn)
  2027. {
  2028. struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2029. ENTER();
  2030. list_init (&pd->list);
  2031. pd->conn = conn;
  2032. LEAVE();
  2033. return (0);
  2034. }
  2035. static int quorum_lib_exit_fn (void *conn)
  2036. {
  2037. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2038. ENTER();
  2039. if (quorum_pd->tracking_enabled) {
  2040. list_del (&quorum_pd->list);
  2041. list_init (&quorum_pd->list);
  2042. }
  2043. LEAVE();
  2044. return (0);
  2045. }
  2046. /*
  2047. * library internal functions
  2048. */
  2049. static void qdevice_timer_fn(void *arg)
  2050. {
  2051. ENTER();
  2052. if ((!(us->flags & NODE_FLAGS_QDEVICE_ALIVE)) ||
  2053. (!qdevice_timer_set)) {
  2054. LEAVE();
  2055. return;
  2056. }
  2057. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  2058. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2059. log_printf(LOGSYS_LEVEL_INFO, "lost contact with quorum device %s", qdevice_name);
  2060. votequorum_exec_send_nodeinfo(us->node_id);
  2061. qdevice_timer_set = 0;
  2062. sync_wait_for_poll_or_timeout = 0;
  2063. LEAVE();
  2064. }
  2065. /*
  2066. * Library Handler Functions
  2067. */
  2068. static void message_handler_req_lib_votequorum_getinfo (void *conn, const void *message)
  2069. {
  2070. const struct req_lib_votequorum_getinfo *req_lib_votequorum_getinfo = message;
  2071. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  2072. struct cluster_node *node;
  2073. unsigned int highest_expected = 0;
  2074. unsigned int total_votes = 0;
  2075. cs_error_t error = CS_OK;
  2076. uint32_t nodeid = req_lib_votequorum_getinfo->nodeid;
  2077. ENTER();
  2078. log_printf(LOGSYS_LEVEL_DEBUG, "got getinfo request on %p for node %u", conn, req_lib_votequorum_getinfo->nodeid);
  2079. if (nodeid == VOTEQUORUM_QDEVICE_NODEID) {
  2080. nodeid = us->node_id;
  2081. }
  2082. node = find_node_by_nodeid(nodeid);
  2083. if (node) {
  2084. struct cluster_node *iternode;
  2085. struct list_head *nodelist;
  2086. list_iterate(nodelist, &cluster_members_list) {
  2087. iternode = list_entry(nodelist, struct cluster_node, list);
  2088. if (iternode->state == NODESTATE_MEMBER) {
  2089. highest_expected =
  2090. max(highest_expected, iternode->expected_votes);
  2091. total_votes += iternode->votes;
  2092. }
  2093. }
  2094. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  2095. total_votes += qdevice->votes;
  2096. }
  2097. switch(node->state) {
  2098. case NODESTATE_MEMBER:
  2099. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_MEMBER;
  2100. break;
  2101. case NODESTATE_DEAD:
  2102. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_DEAD;
  2103. break;
  2104. case NODESTATE_LEAVING:
  2105. res_lib_votequorum_getinfo.state = VOTEQUORUM_NODESTATE_LEAVING;
  2106. break;
  2107. default:
  2108. res_lib_votequorum_getinfo.state = node->state;
  2109. break;
  2110. }
  2111. res_lib_votequorum_getinfo.state = node->state;
  2112. res_lib_votequorum_getinfo.votes = node->votes;
  2113. res_lib_votequorum_getinfo.expected_votes = node->expected_votes;
  2114. res_lib_votequorum_getinfo.highest_expected = highest_expected;
  2115. res_lib_votequorum_getinfo.quorum = quorum;
  2116. res_lib_votequorum_getinfo.total_votes = total_votes;
  2117. res_lib_votequorum_getinfo.flags = 0;
  2118. res_lib_votequorum_getinfo.nodeid = node->node_id;
  2119. if (two_node) {
  2120. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_TWONODE;
  2121. }
  2122. if (cluster_is_quorate) {
  2123. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QUORATE;
  2124. }
  2125. if (wait_for_all) {
  2126. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_WAIT_FOR_ALL;
  2127. }
  2128. if (last_man_standing) {
  2129. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_LAST_MAN_STANDING;
  2130. }
  2131. if (auto_tie_breaker != ATB_NONE) {
  2132. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_AUTO_TIE_BREAKER;
  2133. }
  2134. if (allow_downscale) {
  2135. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_ALLOW_DOWNSCALE;
  2136. }
  2137. memset(res_lib_votequorum_getinfo.qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
  2138. strcpy(res_lib_votequorum_getinfo.qdevice_name, qdevice_name);
  2139. res_lib_votequorum_getinfo.qdevice_votes = qdevice->votes;
  2140. if (node->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2141. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_REGISTERED;
  2142. }
  2143. if (node->flags & NODE_FLAGS_QDEVICE_ALIVE) {
  2144. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_ALIVE;
  2145. }
  2146. if (node->flags & NODE_FLAGS_QDEVICE_CAST_VOTE) {
  2147. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_CAST_VOTE;
  2148. }
  2149. if (node->flags & NODE_FLAGS_QDEVICE_MASTER_WINS) {
  2150. res_lib_votequorum_getinfo.flags |= VOTEQUORUM_INFO_QDEVICE_MASTER_WINS;
  2151. }
  2152. } else {
  2153. error = CS_ERR_NOT_EXIST;
  2154. }
  2155. res_lib_votequorum_getinfo.header.size = sizeof(res_lib_votequorum_getinfo);
  2156. res_lib_votequorum_getinfo.header.id = MESSAGE_RES_VOTEQUORUM_GETINFO;
  2157. res_lib_votequorum_getinfo.header.error = error;
  2158. corosync_api->ipc_response_send(conn, &res_lib_votequorum_getinfo, sizeof(res_lib_votequorum_getinfo));
  2159. log_printf(LOGSYS_LEVEL_DEBUG, "getinfo response error: %d", error);
  2160. LEAVE();
  2161. }
  2162. static void message_handler_req_lib_votequorum_setexpected (void *conn, const void *message)
  2163. {
  2164. const struct req_lib_votequorum_setexpected *req_lib_votequorum_setexpected = message;
  2165. struct res_lib_votequorum_status res_lib_votequorum_status;
  2166. cs_error_t error = CS_OK;
  2167. unsigned int newquorum;
  2168. unsigned int total_votes;
  2169. uint8_t allow_downscale_status = 0;
  2170. ENTER();
  2171. allow_downscale_status = allow_downscale;
  2172. allow_downscale = 0;
  2173. /*
  2174. * Validate new expected votes
  2175. */
  2176. newquorum = calculate_quorum(1, req_lib_votequorum_setexpected->expected_votes, &total_votes);
  2177. allow_downscale = allow_downscale_status;
  2178. if (newquorum < total_votes / 2 ||
  2179. newquorum > total_votes) {
  2180. error = CS_ERR_INVALID_PARAM;
  2181. goto error_exit;
  2182. }
  2183. update_node_expected_votes(req_lib_votequorum_setexpected->expected_votes);
  2184. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_EXPECTED_VOTES, us->node_id,
  2185. req_lib_votequorum_setexpected->expected_votes);
  2186. error_exit:
  2187. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2188. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2189. res_lib_votequorum_status.header.error = error;
  2190. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2191. LEAVE();
  2192. }
  2193. static void message_handler_req_lib_votequorum_setvotes (void *conn, const void *message)
  2194. {
  2195. const struct req_lib_votequorum_setvotes *req_lib_votequorum_setvotes = message;
  2196. struct res_lib_votequorum_status res_lib_votequorum_status;
  2197. struct cluster_node *node;
  2198. unsigned int newquorum;
  2199. unsigned int total_votes;
  2200. unsigned int saved_votes;
  2201. cs_error_t error = CS_OK;
  2202. unsigned int nodeid;
  2203. ENTER();
  2204. nodeid = req_lib_votequorum_setvotes->nodeid;
  2205. node = find_node_by_nodeid(nodeid);
  2206. if (!node) {
  2207. error = CS_ERR_NAME_NOT_FOUND;
  2208. goto error_exit;
  2209. }
  2210. /*
  2211. * Check votes is valid
  2212. */
  2213. saved_votes = node->votes;
  2214. node->votes = req_lib_votequorum_setvotes->votes;
  2215. newquorum = calculate_quorum(1, 0, &total_votes);
  2216. if (newquorum < total_votes / 2 ||
  2217. newquorum > total_votes) {
  2218. node->votes = saved_votes;
  2219. error = CS_ERR_INVALID_PARAM;
  2220. goto error_exit;
  2221. }
  2222. votequorum_exec_send_reconfigure(VOTEQUORUM_RECONFIG_PARAM_NODE_VOTES, nodeid,
  2223. req_lib_votequorum_setvotes->votes);
  2224. error_exit:
  2225. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2226. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2227. res_lib_votequorum_status.header.error = error;
  2228. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2229. LEAVE();
  2230. }
  2231. static void message_handler_req_lib_votequorum_trackstart (void *conn,
  2232. const void *message)
  2233. {
  2234. const struct req_lib_votequorum_trackstart *req_lib_votequorum_trackstart = message;
  2235. struct res_lib_votequorum_status res_lib_votequorum_status;
  2236. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2237. cs_error_t error = CS_OK;
  2238. ENTER();
  2239. /*
  2240. * If an immediate listing of the current cluster membership
  2241. * is requested, generate membership list
  2242. */
  2243. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CURRENT ||
  2244. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES) {
  2245. log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p", conn);
  2246. votequorum_exec_send_nodelist_notification(conn, req_lib_votequorum_trackstart->context);
  2247. votequorum_exec_send_quorum_notification(conn, req_lib_votequorum_trackstart->context);
  2248. }
  2249. if (quorum_pd->tracking_enabled) {
  2250. error = CS_ERR_EXIST;
  2251. goto response_send;
  2252. }
  2253. /*
  2254. * Record requests for tracking
  2255. */
  2256. if (req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES ||
  2257. req_lib_votequorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
  2258. quorum_pd->track_flags = req_lib_votequorum_trackstart->track_flags;
  2259. quorum_pd->tracking_enabled = 1;
  2260. quorum_pd->tracking_context = req_lib_votequorum_trackstart->context;
  2261. list_add (&quorum_pd->list, &trackers_list);
  2262. }
  2263. response_send:
  2264. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2265. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2266. res_lib_votequorum_status.header.error = error;
  2267. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2268. LEAVE();
  2269. }
  2270. static void message_handler_req_lib_votequorum_trackstop (void *conn,
  2271. const void *message)
  2272. {
  2273. struct res_lib_votequorum_status res_lib_votequorum_status;
  2274. struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
  2275. int error = CS_OK;
  2276. ENTER();
  2277. if (quorum_pd->tracking_enabled) {
  2278. error = CS_OK;
  2279. quorum_pd->tracking_enabled = 0;
  2280. list_del (&quorum_pd->list);
  2281. list_init (&quorum_pd->list);
  2282. } else {
  2283. error = CS_ERR_NOT_EXIST;
  2284. }
  2285. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2286. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2287. res_lib_votequorum_status.header.error = error;
  2288. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2289. LEAVE();
  2290. }
  2291. static void message_handler_req_lib_votequorum_qdevice_register (void *conn,
  2292. const void *message)
  2293. {
  2294. const struct req_lib_votequorum_qdevice_register *req_lib_votequorum_qdevice_register = message;
  2295. struct res_lib_votequorum_status res_lib_votequorum_status;
  2296. cs_error_t error = CS_OK;
  2297. ENTER();
  2298. if (!qdevice_can_operate) {
  2299. log_printf(LOGSYS_LEVEL_INFO, "Registration of quorum device is disabled by incorrect corosync.conf. See logs for more information");
  2300. error = CS_ERR_ACCESS;
  2301. goto out;
  2302. }
  2303. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2304. if ((!strncmp(req_lib_votequorum_qdevice_register->name,
  2305. qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN))) {
  2306. goto out;
  2307. } else {
  2308. log_printf(LOGSYS_LEVEL_WARNING,
  2309. "A new qdevice with different name (new: %s old: %s) is trying to re-register!",
  2310. req_lib_votequorum_qdevice_register->name, qdevice_name);
  2311. error = CS_ERR_EXIST;
  2312. goto out;
  2313. }
  2314. } else {
  2315. if (qdevice_reg_conn != NULL) {
  2316. log_printf(LOGSYS_LEVEL_WARNING,
  2317. "Registration request already in progress");
  2318. error = CS_ERR_TRY_AGAIN;
  2319. goto out;
  2320. }
  2321. qdevice_reg_conn = conn;
  2322. if (votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_REGISTER,
  2323. req_lib_votequorum_qdevice_register->name) != 0) {
  2324. log_printf(LOGSYS_LEVEL_WARNING,
  2325. "Unable to send qdevice registration request to cluster");
  2326. error = CS_ERR_TRY_AGAIN;
  2327. qdevice_reg_conn = NULL;
  2328. } else {
  2329. LEAVE();
  2330. return;
  2331. }
  2332. }
  2333. out:
  2334. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2335. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2336. res_lib_votequorum_status.header.error = error;
  2337. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2338. LEAVE();
  2339. }
  2340. static void message_handler_req_lib_votequorum_qdevice_unregister (void *conn,
  2341. const void *message)
  2342. {
  2343. const struct req_lib_votequorum_qdevice_unregister *req_lib_votequorum_qdevice_unregister = message;
  2344. struct res_lib_votequorum_status res_lib_votequorum_status;
  2345. cs_error_t error = CS_OK;
  2346. ENTER();
  2347. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2348. if (strncmp(req_lib_votequorum_qdevice_unregister->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2349. error = CS_ERR_INVALID_PARAM;
  2350. goto out;
  2351. }
  2352. if (qdevice_timer_set) {
  2353. corosync_api->timer_delete(qdevice_timer);
  2354. qdevice_timer_set = 0;
  2355. sync_wait_for_poll_or_timeout = 0;
  2356. }
  2357. us->flags &= ~NODE_FLAGS_QDEVICE_REGISTERED;
  2358. us->flags &= ~NODE_FLAGS_QDEVICE_ALIVE;
  2359. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2360. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2361. votequorum_exec_send_nodeinfo(us->node_id);
  2362. votequorum_exec_send_qdevice_reg(VOTEQUORUM_QDEVICE_OPERATION_UNREGISTER,
  2363. req_lib_votequorum_qdevice_unregister->name);
  2364. } else {
  2365. error = CS_ERR_NOT_EXIST;
  2366. }
  2367. out:
  2368. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2369. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2370. res_lib_votequorum_status.header.error = error;
  2371. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2372. LEAVE();
  2373. }
  2374. static void message_handler_req_lib_votequorum_qdevice_update (void *conn,
  2375. const void *message)
  2376. {
  2377. const struct req_lib_votequorum_qdevice_update *req_lib_votequorum_qdevice_update = message;
  2378. struct res_lib_votequorum_status res_lib_votequorum_status;
  2379. cs_error_t error = CS_OK;
  2380. ENTER();
  2381. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2382. if (strncmp(req_lib_votequorum_qdevice_update->oldname, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2383. error = CS_ERR_INVALID_PARAM;
  2384. goto out;
  2385. }
  2386. votequorum_exec_send_qdevice_reconfigure(req_lib_votequorum_qdevice_update->oldname,
  2387. req_lib_votequorum_qdevice_update->newname);
  2388. } else {
  2389. error = CS_ERR_NOT_EXIST;
  2390. }
  2391. out:
  2392. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2393. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2394. res_lib_votequorum_status.header.error = error;
  2395. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2396. LEAVE();
  2397. }
  2398. static void message_handler_req_lib_votequorum_qdevice_poll (void *conn,
  2399. const void *message)
  2400. {
  2401. const struct req_lib_votequorum_qdevice_poll *req_lib_votequorum_qdevice_poll = message;
  2402. struct res_lib_votequorum_status res_lib_votequorum_status;
  2403. cs_error_t error = CS_OK;
  2404. uint32_t oldflags;
  2405. ENTER();
  2406. if (!qdevice_can_operate) {
  2407. error = CS_ERR_ACCESS;
  2408. goto out;
  2409. }
  2410. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2411. if (!(req_lib_votequorum_qdevice_poll->ring_id.nodeid == quorum_ringid.rep.nodeid &&
  2412. req_lib_votequorum_qdevice_poll->ring_id.seq == quorum_ringid.seq)) {
  2413. log_printf(LOGSYS_LEVEL_DEBUG, "Received poll ring id (%u.%"PRIu64") != last sync "
  2414. "ring id (%u.%"PRIu64"). Ignoring poll call.",
  2415. req_lib_votequorum_qdevice_poll->ring_id.nodeid, req_lib_votequorum_qdevice_poll->ring_id.seq,
  2416. quorum_ringid.rep.nodeid, quorum_ringid.seq);
  2417. error = CS_ERR_MESSAGE_ERROR;
  2418. goto out;
  2419. }
  2420. if (strncmp(req_lib_votequorum_qdevice_poll->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2421. error = CS_ERR_INVALID_PARAM;
  2422. goto out;
  2423. }
  2424. if (qdevice_timer_set) {
  2425. corosync_api->timer_delete(qdevice_timer);
  2426. qdevice_timer_set = 0;
  2427. }
  2428. oldflags = us->flags;
  2429. us->flags |= NODE_FLAGS_QDEVICE_ALIVE;
  2430. if (req_lib_votequorum_qdevice_poll->cast_vote) {
  2431. us->flags |= NODE_FLAGS_QDEVICE_CAST_VOTE;
  2432. } else {
  2433. us->flags &= ~NODE_FLAGS_QDEVICE_CAST_VOTE;
  2434. }
  2435. if (us->flags != oldflags) {
  2436. votequorum_exec_send_nodeinfo(us->node_id);
  2437. }
  2438. corosync_api->timer_add_duration((unsigned long long)qdevice_timeout*1000000, qdevice,
  2439. qdevice_timer_fn, &qdevice_timer);
  2440. qdevice_timer_set = 1;
  2441. sync_wait_for_poll_or_timeout = 0;
  2442. } else {
  2443. error = CS_ERR_NOT_EXIST;
  2444. }
  2445. out:
  2446. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2447. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2448. res_lib_votequorum_status.header.error = error;
  2449. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2450. LEAVE();
  2451. }
  2452. static void message_handler_req_lib_votequorum_qdevice_master_wins (void *conn,
  2453. const void *message)
  2454. {
  2455. const struct req_lib_votequorum_qdevice_master_wins *req_lib_votequorum_qdevice_master_wins = message;
  2456. struct res_lib_votequorum_status res_lib_votequorum_status;
  2457. cs_error_t error = CS_OK;
  2458. uint32_t oldflags = us->flags;
  2459. ENTER();
  2460. if (!qdevice_can_operate) {
  2461. error = CS_ERR_ACCESS;
  2462. goto out;
  2463. }
  2464. if (us->flags & NODE_FLAGS_QDEVICE_REGISTERED) {
  2465. if (strncmp(req_lib_votequorum_qdevice_master_wins->name, qdevice_name, VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  2466. error = CS_ERR_INVALID_PARAM;
  2467. goto out;
  2468. }
  2469. if (req_lib_votequorum_qdevice_master_wins->allow) {
  2470. us->flags |= NODE_FLAGS_QDEVICE_MASTER_WINS;
  2471. } else {
  2472. us->flags &= ~NODE_FLAGS_QDEVICE_MASTER_WINS;
  2473. }
  2474. if (us->flags != oldflags) {
  2475. votequorum_exec_send_nodeinfo(us->node_id);
  2476. }
  2477. update_qdevice_master_wins(req_lib_votequorum_qdevice_master_wins->allow);
  2478. } else {
  2479. error = CS_ERR_NOT_EXIST;
  2480. }
  2481. out:
  2482. res_lib_votequorum_status.header.size = sizeof(res_lib_votequorum_status);
  2483. res_lib_votequorum_status.header.id = MESSAGE_RES_VOTEQUORUM_STATUS;
  2484. res_lib_votequorum_status.header.error = error;
  2485. corosync_api->ipc_response_send(conn, &res_lib_votequorum_status, sizeof(res_lib_votequorum_status));
  2486. LEAVE();
  2487. }