votequorum.c 65 KB

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