cfg.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2009 Red Hat, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Author: Steven Dake (sdake@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 CONTRIBUTORS "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 <stdio.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39. #include <unistd.h>
  40. #include <errno.h>
  41. #include <signal.h>
  42. #include <pthread.h>
  43. #include <limits.h>
  44. #include <sys/types.h>
  45. #include <sys/socket.h>
  46. #include <sys/select.h>
  47. #include <sys/un.h>
  48. #include <corosync/corotypes.h>
  49. #include <corosync/cfg.h>
  50. #include <corosync/totem/totemip.h>
  51. #include <corosync/mar_gen.h>
  52. #include <corosync/ipc_gen.h>
  53. #include <corosync/ipc_cfg.h>
  54. #include <corosync/coroipcc.h>
  55. struct cfg_res_overlay {
  56. mar_res_header_t header;
  57. char data[4096];
  58. };
  59. /*
  60. * Data structure for instance data
  61. */
  62. struct cfg_instance {
  63. void *ipc_ctx;
  64. corosync_cfg_callbacks_t callbacks;
  65. cs_name_t comp_name;
  66. int comp_registered;
  67. int finalize;
  68. pthread_mutex_t response_mutex;
  69. pthread_mutex_t dispatch_mutex;
  70. };
  71. static void cfg_handle_instance_destructor (void *);
  72. /*
  73. * All instances in one database
  74. */
  75. static struct saHandleDatabase cfg_hdb = {
  76. .handleCount = 0,
  77. .handles = 0,
  78. .mutex = PTHREAD_MUTEX_INITIALIZER,
  79. .handleInstanceDestructor = cfg_handle_instance_destructor
  80. };
  81. /*
  82. * Implementation
  83. */
  84. void cfg_handle_instance_destructor (void *instance)
  85. {
  86. struct cfg_instance *cfg_instance = instance;
  87. pthread_mutex_destroy (&cfg_instance->response_mutex);
  88. pthread_mutex_destroy (&cfg_instance->dispatch_mutex);
  89. }
  90. cs_error_t
  91. corosync_cfg_initialize (
  92. corosync_cfg_handle_t *cfg_handle,
  93. const corosync_cfg_callbacks_t *cfg_callbacks)
  94. {
  95. struct cfg_instance *cfg_instance;
  96. cs_error_t error = CS_OK;
  97. error = saHandleCreate (&cfg_hdb, sizeof (struct cfg_instance), cfg_handle);
  98. if (error != CS_OK) {
  99. goto error_no_destroy;
  100. }
  101. error = saHandleInstanceGet (&cfg_hdb, *cfg_handle, (void *)&cfg_instance);
  102. if (error != CS_OK) {
  103. goto error_destroy;
  104. }
  105. error = coroipcc_service_connect (IPC_SOCKET_NAME, CFG_SERVICE, &cfg_instance->ipc_ctx);
  106. if (error != CS_OK) {
  107. goto error_put_destroy;
  108. }
  109. if (cfg_callbacks) {
  110. memcpy (&cfg_instance->callbacks, cfg_callbacks, sizeof (corosync_cfg_callbacks_t));
  111. }
  112. pthread_mutex_init (&cfg_instance->response_mutex, NULL);
  113. pthread_mutex_init (&cfg_instance->dispatch_mutex, NULL);
  114. (void)saHandleInstancePut (&cfg_hdb, *cfg_handle);
  115. return (CS_OK);
  116. error_put_destroy:
  117. (void)saHandleInstancePut (&cfg_hdb, *cfg_handle);
  118. error_destroy:
  119. (void)saHandleDestroy (&cfg_hdb, *cfg_handle);
  120. error_no_destroy:
  121. return (error);
  122. }
  123. cs_error_t
  124. corosync_cfg_fd_get (
  125. corosync_cfg_handle_t cfg_handle,
  126. int32_t *selection_fd)
  127. {
  128. struct cfg_instance *cfg_instance;
  129. cs_error_t error;
  130. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  131. if (error != CS_OK) {
  132. return (error);
  133. }
  134. *selection_fd = coroipcc_fd_get (cfg_instance->ipc_ctx);
  135. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  136. return (CS_OK);
  137. }
  138. cs_error_t
  139. corosync_cfg_dispatch (
  140. corosync_cfg_handle_t cfg_handle,
  141. cs_dispatch_flags_t dispatch_flags)
  142. {
  143. int timeout = -1;
  144. cs_error_t error;
  145. int cont = 1; /* always continue do loop except when set to 0 */
  146. int dispatch_avail;
  147. struct cfg_instance *cfg_instance;
  148. struct res_lib_cfg_testshutdown *res_lib_cfg_testshutdown;
  149. #ifdef COMPILE_OUT
  150. struct res_lib_corosync_healthcheckcallback *res_lib_corosync_healthcheckcallback;
  151. struct res_lib_corosync_readinessstatesetcallback *res_lib_corosync_readinessstatesetcallback;
  152. struct res_lib_corosync_csisetcallback *res_lib_corosync_csisetcallback;
  153. struct res_lib_corosync_csiremovecallback *res_lib_corosync_csiremovecallback;
  154. struct res_lib_cfg_statetrackcallback *res_lib_cfg_statetrackcallback;
  155. #endif
  156. corosync_cfg_callbacks_t callbacks;
  157. struct cfg_res_overlay dispatch_data;
  158. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  159. (void *)&cfg_instance);
  160. if (error != CS_OK) {
  161. return (error);
  162. }
  163. /*
  164. * Timeout instantly for CS_DISPATCH_ALL
  165. */
  166. if (dispatch_flags == CS_DISPATCH_ALL) {
  167. timeout = 0;
  168. }
  169. do {
  170. dispatch_avail = coroipcc_dispatch_recv (cfg_instance->ipc_ctx,
  171. (void *)&dispatch_data,
  172. sizeof (dispatch_data),
  173. timeout);
  174. /*
  175. * Handle has been finalized in another thread
  176. */
  177. if (cfg_instance->finalize == 1) {
  178. error = CS_OK;
  179. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  180. goto error_unlock;
  181. }
  182. if (dispatch_avail == 0 && dispatch_flags == CS_DISPATCH_ALL) {
  183. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  184. break; /* exit do while cont is 1 loop */
  185. } else
  186. if (dispatch_avail == 0) {
  187. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  188. continue; /* next poll */
  189. }
  190. /*
  191. * Make copy of callbacks, message data, unlock instance, and call callback
  192. * A risk of this dispatch method is that the callback routines may
  193. * operate at the same time that cfgFinalize has been called in another thread.
  194. */
  195. memcpy (&callbacks, &cfg_instance->callbacks, sizeof (corosync_cfg_callbacks_t));
  196. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  197. /*
  198. * Dispatch incoming response
  199. */
  200. switch (dispatch_data.header.id) {
  201. case MESSAGE_RES_CFG_TESTSHUTDOWN:
  202. if (callbacks.corosync_cfg_shutdown_callback) {
  203. res_lib_cfg_testshutdown = (struct res_lib_cfg_testshutdown *)&dispatch_data;
  204. callbacks.corosync_cfg_shutdown_callback(cfg_handle, res_lib_cfg_testshutdown->flags);
  205. }
  206. break;
  207. default:
  208. error = CS_ERR_LIBRARY;
  209. goto error_nounlock;
  210. break;
  211. }
  212. /*
  213. * Determine if more messages should be processed
  214. */
  215. switch (dispatch_flags) {
  216. case CS_DISPATCH_ONE:
  217. cont = 0;
  218. break;
  219. case CS_DISPATCH_ALL:
  220. break;
  221. case CS_DISPATCH_BLOCKING:
  222. break;
  223. }
  224. } while (cont);
  225. error_unlock:
  226. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  227. error_nounlock:
  228. return (error);
  229. }
  230. cs_error_t
  231. corosync_cfg_finalize (
  232. corosync_cfg_handle_t cfg_handle)
  233. {
  234. struct cfg_instance *cfg_instance;
  235. cs_error_t error;
  236. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  237. if (error != CS_OK) {
  238. return (error);
  239. }
  240. pthread_mutex_lock (&cfg_instance->dispatch_mutex);
  241. pthread_mutex_lock (&cfg_instance->response_mutex);
  242. /*
  243. * Another thread has already started finalizing
  244. */
  245. if (cfg_instance->finalize) {
  246. pthread_mutex_unlock (&cfg_instance->response_mutex);
  247. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  248. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  249. return (CS_ERR_BAD_HANDLE);
  250. }
  251. cfg_instance->finalize = 1;
  252. coroipcc_service_disconnect (cfg_instance->ipc_ctx);
  253. pthread_mutex_unlock (&cfg_instance->response_mutex);
  254. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  255. pthread_mutex_destroy (&cfg_instance->response_mutex);
  256. pthread_mutex_destroy (&cfg_instance->dispatch_mutex);
  257. (void)saHandleDestroy (&cfg_hdb, cfg_handle);
  258. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  259. return (error);
  260. }
  261. cs_error_t
  262. corosync_cfg_ring_status_get (
  263. corosync_cfg_handle_t cfg_handle,
  264. char ***interface_names,
  265. char ***status,
  266. unsigned int *interface_count)
  267. {
  268. struct cfg_instance *cfg_instance;
  269. struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget;
  270. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  271. unsigned int i;
  272. cs_error_t error;
  273. struct iovec iov;
  274. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  275. if (error != CS_OK) {
  276. return (error);
  277. }
  278. req_lib_cfg_ringstatusget.header.size = sizeof (struct req_lib_cfg_ringstatusget);
  279. req_lib_cfg_ringstatusget.header.id = MESSAGE_REQ_CFG_RINGSTATUSGET;
  280. iov.iov_base = &req_lib_cfg_ringstatusget,
  281. iov.iov_len = sizeof (struct req_lib_cfg_ringstatusget),
  282. pthread_mutex_lock (&cfg_instance->response_mutex);
  283. error = coroipcc_msg_send_reply_receive(cfg_instance->ipc_ctx,
  284. &iov,
  285. 1,
  286. &res_lib_cfg_ringstatusget,
  287. sizeof (struct res_lib_cfg_ringstatusget));
  288. pthread_mutex_unlock (&cfg_instance->response_mutex);
  289. *interface_count = res_lib_cfg_ringstatusget.interface_count;
  290. *interface_names = malloc (sizeof (char *) * *interface_count);
  291. if (*interface_names == NULL) {
  292. return (CS_ERR_NO_MEMORY);
  293. }
  294. memset (*interface_names, 0, sizeof (char *) * *interface_count);
  295. *status = malloc (sizeof (char *) * *interface_count);
  296. if (*status == NULL) {
  297. error = CS_ERR_NO_MEMORY;
  298. goto error_free_interface_names;
  299. }
  300. memset (*status, 0, sizeof (char *) * *interface_count);
  301. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  302. (*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
  303. if ((*(interface_names))[i] == NULL) {
  304. error = CS_ERR_NO_MEMORY;
  305. goto error_free_contents;
  306. }
  307. (*(status))[i] = strdup (res_lib_cfg_ringstatusget.interface_status[i]);
  308. if ((*(status))[i] == NULL) {
  309. error = CS_ERR_NO_MEMORY;
  310. goto error_free_contents;
  311. }
  312. }
  313. goto no_error;
  314. error_free_contents:
  315. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  316. if ((*(interface_names))[i]) {
  317. free ((*(interface_names))[i]);
  318. }
  319. if ((*(status))[i]) {
  320. free ((*(status))[i]);
  321. }
  322. }
  323. free (*status);
  324. error_free_interface_names:
  325. free (*interface_names);
  326. no_error:
  327. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  328. return (error);
  329. }
  330. cs_error_t
  331. corosync_cfg_ring_reenable (
  332. corosync_cfg_handle_t cfg_handle)
  333. {
  334. struct cfg_instance *cfg_instance;
  335. struct req_lib_cfg_ringreenable req_lib_cfg_ringreenable;
  336. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  337. cs_error_t error;
  338. struct iovec iov;
  339. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  340. if (error != CS_OK) {
  341. return (error);
  342. }
  343. req_lib_cfg_ringreenable.header.size = sizeof (struct req_lib_cfg_ringreenable);
  344. req_lib_cfg_ringreenable.header.id = MESSAGE_REQ_CFG_RINGREENABLE;
  345. iov.iov_base = &req_lib_cfg_ringreenable,
  346. iov.iov_len = sizeof (struct req_lib_cfg_ringreenable);
  347. pthread_mutex_lock (&cfg_instance->response_mutex);
  348. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  349. &iov,
  350. 1,
  351. &res_lib_cfg_ringreenable,
  352. sizeof (struct res_lib_cfg_ringreenable));
  353. pthread_mutex_unlock (&cfg_instance->response_mutex);
  354. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  355. return (error);
  356. }
  357. cs_error_t
  358. corosync_cfg_service_load (
  359. corosync_cfg_handle_t cfg_handle,
  360. const char *service_name,
  361. unsigned int service_ver)
  362. {
  363. struct cfg_instance *cfg_instance;
  364. struct req_lib_cfg_serviceload req_lib_cfg_serviceload;
  365. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  366. cs_error_t error;
  367. struct iovec iov;
  368. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  369. if (error != CS_OK) {
  370. return (error);
  371. }
  372. req_lib_cfg_serviceload.header.size = sizeof (struct req_lib_cfg_serviceload);
  373. req_lib_cfg_serviceload.header.id = MESSAGE_REQ_CFG_SERVICELOAD;
  374. memset (&req_lib_cfg_serviceload.service_name, 0,
  375. sizeof (req_lib_cfg_serviceload.service_name));
  376. strncpy (req_lib_cfg_serviceload.service_name, service_name,
  377. sizeof (req_lib_cfg_serviceload.service_name) - 1);
  378. req_lib_cfg_serviceload.service_ver = service_ver;
  379. iov.iov_base = &req_lib_cfg_serviceload;
  380. iov.iov_len = sizeof (req_lib_cfg_serviceload);
  381. pthread_mutex_lock (&cfg_instance->response_mutex);
  382. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  383. &iov,
  384. 1,
  385. &res_lib_cfg_serviceload,
  386. sizeof (struct res_lib_cfg_serviceload));
  387. pthread_mutex_unlock (&cfg_instance->response_mutex);
  388. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  389. return (error);
  390. }
  391. cs_error_t
  392. corosync_cfg_service_unload (
  393. corosync_cfg_handle_t cfg_handle,
  394. const char *service_name,
  395. unsigned int service_ver)
  396. {
  397. struct cfg_instance *cfg_instance;
  398. struct req_lib_cfg_serviceunload req_lib_cfg_serviceunload;
  399. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  400. cs_error_t error;
  401. struct iovec iov;
  402. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  403. if (error != CS_OK) {
  404. return (error);
  405. }
  406. req_lib_cfg_serviceunload.header.size = sizeof (struct req_lib_cfg_serviceunload);
  407. req_lib_cfg_serviceunload.header.id = MESSAGE_REQ_CFG_SERVICEUNLOAD;
  408. memset (&req_lib_cfg_serviceunload.service_name, 0,
  409. sizeof (req_lib_cfg_serviceunload.service_name));
  410. strncpy (req_lib_cfg_serviceunload.service_name, service_name,
  411. sizeof (req_lib_cfg_serviceunload.service_name) - 1);
  412. req_lib_cfg_serviceunload.service_ver = service_ver;
  413. iov.iov_base = &req_lib_cfg_serviceunload;
  414. iov.iov_len = sizeof (req_lib_cfg_serviceunload);
  415. pthread_mutex_lock (&cfg_instance->response_mutex);
  416. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  417. &iov,
  418. 1,
  419. &res_lib_cfg_serviceunload,
  420. sizeof (struct res_lib_cfg_serviceunload));
  421. pthread_mutex_unlock (&cfg_instance->response_mutex);
  422. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  423. return (error);
  424. }
  425. cs_error_t
  426. corosync_cfg_state_track (
  427. corosync_cfg_handle_t cfg_handle,
  428. uint8_t track_flags,
  429. const corosync_cfg_state_notification_t *notification_buffer)
  430. {
  431. struct cfg_instance *cfg_instance;
  432. struct req_lib_cfg_statetrack req_lib_cfg_statetrack;
  433. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  434. cs_error_t error;
  435. struct iovec iov;
  436. req_lib_cfg_statetrack.header.size = sizeof (struct req_lib_cfg_statetrack);
  437. req_lib_cfg_statetrack.header.id = MESSAGE_REQ_CFG_STATETRACKSTART;
  438. req_lib_cfg_statetrack.track_flags = track_flags;
  439. req_lib_cfg_statetrack.notification_buffer_address = (corosync_cfg_state_notification_t *)notification_buffer;
  440. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  441. (void *)&cfg_instance);
  442. if (error != CS_OK) {
  443. return (error);
  444. }
  445. iov.iov_base = &req_lib_cfg_statetrack,
  446. iov.iov_len = sizeof (struct req_lib_cfg_statetrack),
  447. pthread_mutex_lock (&cfg_instance->response_mutex);
  448. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  449. &iov,
  450. 1,
  451. &res_lib_cfg_statetrack,
  452. sizeof (struct res_lib_cfg_statetrack));
  453. pthread_mutex_unlock (&cfg_instance->response_mutex);
  454. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  455. return (error == CS_OK ? res_lib_cfg_statetrack.header.error : error);
  456. }
  457. cs_error_t
  458. corosync_cfg_state_track_stop (
  459. corosync_cfg_handle_t cfg_handle)
  460. {
  461. struct cfg_instance *cfg_instance;
  462. struct req_lib_cfg_statetrackstop req_lib_cfg_statetrackstop;
  463. struct res_lib_cfg_statetrackstop res_lib_cfg_statetrackstop;
  464. cs_error_t error;
  465. struct iovec iov;
  466. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  467. (void *)&cfg_instance);
  468. if (error != CS_OK) {
  469. return (error);
  470. }
  471. req_lib_cfg_statetrackstop.header.size = sizeof (struct req_lib_cfg_statetrackstop);
  472. req_lib_cfg_statetrackstop.header.id = MESSAGE_REQ_CFG_STATETRACKSTOP;
  473. iov.iov_base = &req_lib_cfg_statetrackstop,
  474. iov.iov_len = sizeof (struct req_lib_cfg_statetrackstop),
  475. pthread_mutex_lock (&cfg_instance->response_mutex);
  476. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  477. &iov,
  478. 1,
  479. &res_lib_cfg_statetrackstop,
  480. sizeof (struct res_lib_cfg_statetrackstop));
  481. pthread_mutex_unlock (&cfg_instance->response_mutex);
  482. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  483. return (error == CS_OK ? res_lib_cfg_statetrackstop.header.error : error);
  484. }
  485. cs_error_t
  486. corosync_cfg_admin_state_get (
  487. corosync_cfg_handle_t cfg_handle,
  488. corosync_cfg_administrative_target_t administrative_target,
  489. corosync_cfg_administrative_state_t *administrative_state)
  490. {
  491. struct cfg_instance *cfg_instance;
  492. struct req_lib_cfg_administrativestateget req_lib_cfg_administrativestateget;
  493. struct res_lib_cfg_administrativestateget res_lib_cfg_administrativestateget;
  494. cs_error_t error;
  495. struct iovec iov;
  496. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  497. (void *)&cfg_instance);
  498. if (error != CS_OK) {
  499. return (error);
  500. }
  501. req_lib_cfg_administrativestateget.header.id = MESSAGE_REQ_CFG_ADMINISTRATIVESTATEGET;
  502. req_lib_cfg_administrativestateget.header.size = sizeof (struct req_lib_cfg_administrativestateget);
  503. req_lib_cfg_administrativestateget.administrative_target = administrative_target;
  504. pthread_mutex_lock (&cfg_instance->response_mutex);
  505. iov.iov_base = &req_lib_cfg_administrativestateget,
  506. iov.iov_len = sizeof (struct req_lib_cfg_administrativestateget),
  507. pthread_mutex_lock (&cfg_instance->response_mutex);
  508. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  509. &iov,
  510. 1,
  511. &res_lib_cfg_administrativestateget,
  512. sizeof (struct res_lib_cfg_administrativestateget));
  513. error = res_lib_cfg_administrativestateget.header.error;
  514. pthread_mutex_unlock (&cfg_instance->response_mutex);
  515. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  516. return (error == CS_OK ? res_lib_cfg_administrativestateget.header.error : error);
  517. }
  518. cs_error_t
  519. corosync_cfg_admin_state_set (
  520. corosync_cfg_handle_t cfg_handle,
  521. corosync_cfg_administrative_target_t administrative_target,
  522. corosync_cfg_administrative_state_t administrative_state)
  523. {
  524. struct cfg_instance *cfg_instance;
  525. struct req_lib_cfg_administrativestateset req_lib_cfg_administrativestateset;
  526. struct res_lib_cfg_administrativestateset res_lib_cfg_administrativestateset;
  527. cs_error_t error;
  528. struct iovec iov;
  529. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  530. (void *)&cfg_instance);
  531. if (error != CS_OK) {
  532. return (error);
  533. }
  534. req_lib_cfg_administrativestateset.header.id = MESSAGE_REQ_CFG_ADMINISTRATIVESTATEGET;
  535. req_lib_cfg_administrativestateset.header.size = sizeof (struct req_lib_cfg_administrativestateset);
  536. req_lib_cfg_administrativestateset.administrative_target = administrative_target;
  537. req_lib_cfg_administrativestateset.administrative_state = administrative_state;
  538. pthread_mutex_lock (&cfg_instance->response_mutex);
  539. iov.iov_base = &req_lib_cfg_administrativestateset,
  540. iov.iov_len = sizeof (struct req_lib_cfg_administrativestateset),
  541. pthread_mutex_lock (&cfg_instance->response_mutex);
  542. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  543. &iov,
  544. 1,
  545. &res_lib_cfg_administrativestateset,
  546. sizeof (struct res_lib_cfg_administrativestateset));
  547. error = res_lib_cfg_administrativestateset.header.error;
  548. pthread_mutex_unlock (&cfg_instance->response_mutex);
  549. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  550. return (error == CS_OK ? res_lib_cfg_administrativestateset.header.error : error);
  551. }
  552. cs_error_t
  553. corosync_cfg_kill_node (
  554. corosync_cfg_handle_t cfg_handle,
  555. unsigned int nodeid,
  556. char *reason)
  557. {
  558. struct cfg_instance *cfg_instance;
  559. struct req_lib_cfg_killnode req_lib_cfg_killnode;
  560. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  561. cs_error_t error;
  562. struct iovec iov;
  563. if (strlen(reason) >= CS_MAX_NAME_LENGTH)
  564. return CS_ERR_NAME_TOO_LONG;
  565. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  566. (void *)&cfg_instance);
  567. if (error != CS_OK) {
  568. return (error);
  569. }
  570. req_lib_cfg_killnode.header.id = MESSAGE_REQ_CFG_KILLNODE;
  571. req_lib_cfg_killnode.header.size = sizeof (struct req_lib_cfg_killnode);
  572. req_lib_cfg_killnode.nodeid = nodeid;
  573. strcpy((char *)req_lib_cfg_killnode.reason.value, reason);
  574. req_lib_cfg_killnode.reason.length = strlen(reason)+1;
  575. iov.iov_base = &req_lib_cfg_killnode;
  576. iov.iov_len = sizeof (struct req_lib_cfg_killnode);
  577. pthread_mutex_lock (&cfg_instance->response_mutex);
  578. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  579. &iov,
  580. 1,
  581. &res_lib_cfg_killnode,
  582. sizeof (struct res_lib_cfg_killnode));
  583. error = res_lib_cfg_killnode.header.error;
  584. pthread_mutex_unlock (&cfg_instance->response_mutex);
  585. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  586. return (error == CS_OK ? res_lib_cfg_killnode.header.error : error);
  587. }
  588. cs_error_t
  589. corosync_cfg_try_shutdown (
  590. corosync_cfg_handle_t cfg_handle,
  591. corosync_cfg_shutdown_flags_t flags)
  592. {
  593. struct cfg_instance *cfg_instance;
  594. struct req_lib_cfg_tryshutdown req_lib_cfg_tryshutdown;
  595. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  596. cs_error_t error;
  597. struct iovec iov;
  598. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  599. (void *)&cfg_instance);
  600. if (error != CS_OK) {
  601. return (error);
  602. }
  603. req_lib_cfg_tryshutdown.header.id = MESSAGE_REQ_CFG_TRYSHUTDOWN;
  604. req_lib_cfg_tryshutdown.header.size = sizeof (struct req_lib_cfg_tryshutdown);
  605. req_lib_cfg_tryshutdown.flags = flags;
  606. iov.iov_base = &req_lib_cfg_tryshutdown;
  607. iov.iov_len = sizeof (req_lib_cfg_tryshutdown);
  608. pthread_mutex_lock (&cfg_instance->response_mutex);
  609. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  610. &iov,
  611. 1,
  612. &res_lib_cfg_tryshutdown,
  613. sizeof (struct res_lib_cfg_tryshutdown));
  614. pthread_mutex_unlock (&cfg_instance->response_mutex);
  615. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  616. return (error == CS_OK ? res_lib_cfg_tryshutdown.header.error : error);
  617. }
  618. cs_error_t
  619. corosync_cfg_replyto_shutdown (
  620. corosync_cfg_handle_t cfg_handle,
  621. corosync_cfg_shutdown_reply_flags_t response)
  622. {
  623. struct cfg_instance *cfg_instance;
  624. struct req_lib_cfg_replytoshutdown req_lib_cfg_replytoshutdown;
  625. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  626. struct iovec iov;
  627. cs_error_t error;
  628. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  629. (void *)&cfg_instance);
  630. if (error != CS_OK) {
  631. return (error);
  632. }
  633. req_lib_cfg_replytoshutdown.header.id = MESSAGE_REQ_CFG_REPLYTOSHUTDOWN;
  634. req_lib_cfg_replytoshutdown.header.size = sizeof (struct req_lib_cfg_replytoshutdown);
  635. req_lib_cfg_replytoshutdown.response = response;
  636. iov.iov_base = &req_lib_cfg_replytoshutdown;
  637. iov.iov_len = sizeof (struct req_lib_cfg_replytoshutdown);
  638. pthread_mutex_lock (&cfg_instance->response_mutex);
  639. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  640. &iov,
  641. 1,
  642. &res_lib_cfg_replytoshutdown,
  643. sizeof (struct res_lib_cfg_replytoshutdown));
  644. pthread_mutex_unlock (&cfg_instance->response_mutex);
  645. return (error);
  646. }
  647. cs_error_t corosync_cfg_get_node_addrs (
  648. corosync_cfg_handle_t cfg_handle,
  649. int nodeid,
  650. int max_addrs,
  651. int *num_addrs,
  652. corosync_cfg_node_address_t *addrs)
  653. {
  654. cs_error_t error;
  655. struct req_lib_cfg_get_node_addrs req_lib_cfg_get_node_addrs;
  656. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs;
  657. struct cfg_instance *cfg_instance;
  658. int addrlen;
  659. int i;
  660. struct iovec iov;
  661. void *return_address;
  662. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  663. (void *)&cfg_instance);
  664. if (error != CS_OK) {
  665. return (error);
  666. }
  667. req_lib_cfg_get_node_addrs.header.size = sizeof (req_lib_cfg_get_node_addrs);
  668. req_lib_cfg_get_node_addrs.header.id = MESSAGE_REQ_CFG_GET_NODE_ADDRS;
  669. req_lib_cfg_get_node_addrs.nodeid = nodeid;
  670. iov.iov_base = (char *)&req_lib_cfg_get_node_addrs;
  671. iov.iov_len = sizeof (req_lib_cfg_get_node_addrs);
  672. pthread_mutex_lock (&cfg_instance->response_mutex);
  673. error = coroipcc_msg_send_reply_receive_in_buf (cfg_instance->ipc_ctx,
  674. &iov,
  675. 1,
  676. &return_address);
  677. res_lib_cfg_get_node_addrs = return_address;
  678. pthread_mutex_unlock (&cfg_instance->response_mutex);
  679. if (error != CS_OK) {
  680. goto error_exit;
  681. }
  682. if (res_lib_cfg_get_node_addrs->family == AF_INET)
  683. addrlen = sizeof(struct sockaddr_in);
  684. if (res_lib_cfg_get_node_addrs->family == AF_INET6)
  685. addrlen = sizeof(struct sockaddr_in6);
  686. for (i=0; i<max_addrs && i<res_lib_cfg_get_node_addrs->num_addrs; i++) {
  687. addrs[i].address_length = addrlen;
  688. struct sockaddr_in *in;
  689. struct sockaddr_in6 *in6;
  690. if (res_lib_cfg_get_node_addrs->family == AF_INET) {
  691. in = (struct sockaddr_in *)addrs[i].address;
  692. in->sin_family = AF_INET;
  693. memcpy(&in->sin_addr, &res_lib_cfg_get_node_addrs->addrs[i][0], sizeof(struct in_addr));
  694. }
  695. if (res_lib_cfg_get_node_addrs->family == AF_INET6) {
  696. in6 = (struct sockaddr_in6 *)addrs[i].address;
  697. in6->sin6_family = AF_INET6;
  698. memcpy(&in6->sin6_addr, &res_lib_cfg_get_node_addrs->addrs[i][0], sizeof(struct in6_addr));
  699. }
  700. }
  701. *num_addrs = res_lib_cfg_get_node_addrs->num_addrs;
  702. errno = error = res_lib_cfg_get_node_addrs->header.error;
  703. error_exit:
  704. return (error);
  705. }
  706. cs_error_t corosync_cfg_local_get (
  707. corosync_cfg_handle_t handle,
  708. unsigned int *local_nodeid)
  709. {
  710. cs_error_t error;
  711. struct cfg_instance *cfg_inst;
  712. struct iovec iov;
  713. struct req_lib_cfg_local_get req_lib_cfg_local_get;
  714. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  715. error = saHandleInstanceGet (&cfg_hdb, handle, (void *)&cfg_inst);
  716. if (error != CS_OK) {
  717. return (error);
  718. }
  719. req_lib_cfg_local_get.header.size = sizeof (mar_req_header_t);
  720. req_lib_cfg_local_get.header.id = MESSAGE_REQ_CFG_LOCAL_GET;
  721. iov.iov_base = &req_lib_cfg_local_get;
  722. iov.iov_len = sizeof (struct req_lib_cfg_local_get);
  723. pthread_mutex_lock (&cfg_inst->response_mutex);
  724. error = coroipcc_msg_send_reply_receive (
  725. cfg_inst->ipc_ctx,
  726. &iov,
  727. 1,
  728. &res_lib_cfg_local_get,
  729. sizeof (struct res_lib_cfg_local_get));
  730. pthread_mutex_unlock (&cfg_inst->response_mutex);
  731. if (error != CS_OK) {
  732. goto error_exit;
  733. }
  734. error = res_lib_cfg_local_get.header.error;
  735. *local_nodeid = res_lib_cfg_local_get.local_nodeid;
  736. error_exit:
  737. (void)saHandleInstancePut (&cfg_hdb, handle);
  738. return (error);
  739. }