cfg.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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, timeout);
  172. /*
  173. * Handle has been finalized in another thread
  174. */
  175. if (cfg_instance->finalize == 1) {
  176. error = CS_OK;
  177. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  178. goto error_unlock;
  179. }
  180. if (dispatch_avail == 0 && dispatch_flags == CS_DISPATCH_ALL) {
  181. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  182. break; /* exit do while cont is 1 loop */
  183. } else
  184. if (dispatch_avail == 0) {
  185. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  186. continue; /* next poll */
  187. }
  188. /*
  189. * Make copy of callbacks, message data, unlock instance, and call callback
  190. * A risk of this dispatch method is that the callback routines may
  191. * operate at the same time that cfgFinalize has been called in another thread.
  192. */
  193. memcpy (&callbacks, &cfg_instance->callbacks, sizeof (corosync_cfg_callbacks_t));
  194. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  195. /*
  196. * Dispatch incoming response
  197. */
  198. switch (dispatch_data.header.id) {
  199. case MESSAGE_RES_CFG_TESTSHUTDOWN:
  200. if (callbacks.corosync_cfg_shutdown_callback) {
  201. res_lib_cfg_testshutdown = (struct res_lib_cfg_testshutdown *)&dispatch_data;
  202. callbacks.corosync_cfg_shutdown_callback(cfg_handle, res_lib_cfg_testshutdown->flags);
  203. }
  204. break;
  205. default:
  206. error = CS_ERR_LIBRARY;
  207. goto error_nounlock;
  208. break;
  209. }
  210. /*
  211. * Determine if more messages should be processed
  212. */
  213. switch (dispatch_flags) {
  214. case CS_DISPATCH_ONE:
  215. cont = 0;
  216. break;
  217. case CS_DISPATCH_ALL:
  218. break;
  219. case CS_DISPATCH_BLOCKING:
  220. break;
  221. }
  222. } while (cont);
  223. error_unlock:
  224. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  225. error_nounlock:
  226. return (error);
  227. }
  228. cs_error_t
  229. corosync_cfg_finalize (
  230. corosync_cfg_handle_t cfg_handle)
  231. {
  232. struct cfg_instance *cfg_instance;
  233. cs_error_t error;
  234. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  235. if (error != CS_OK) {
  236. return (error);
  237. }
  238. pthread_mutex_lock (&cfg_instance->dispatch_mutex);
  239. pthread_mutex_lock (&cfg_instance->response_mutex);
  240. /*
  241. * Another thread has already started finalizing
  242. */
  243. if (cfg_instance->finalize) {
  244. pthread_mutex_unlock (&cfg_instance->response_mutex);
  245. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  246. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  247. return (CS_ERR_BAD_HANDLE);
  248. }
  249. cfg_instance->finalize = 1;
  250. coroipcc_service_disconnect (cfg_instance->ipc_ctx);
  251. pthread_mutex_unlock (&cfg_instance->response_mutex);
  252. pthread_mutex_unlock (&cfg_instance->dispatch_mutex);
  253. pthread_mutex_destroy (&cfg_instance->response_mutex);
  254. pthread_mutex_destroy (&cfg_instance->dispatch_mutex);
  255. (void)saHandleDestroy (&cfg_hdb, cfg_handle);
  256. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  257. return (error);
  258. }
  259. cs_error_t
  260. corosync_cfg_ring_status_get (
  261. corosync_cfg_handle_t cfg_handle,
  262. char ***interface_names,
  263. char ***status,
  264. unsigned int *interface_count)
  265. {
  266. struct cfg_instance *cfg_instance;
  267. struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget;
  268. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  269. unsigned int i;
  270. cs_error_t error;
  271. struct iovec iov;
  272. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  273. if (error != CS_OK) {
  274. return (error);
  275. }
  276. req_lib_cfg_ringstatusget.header.size = sizeof (struct req_lib_cfg_ringstatusget);
  277. req_lib_cfg_ringstatusget.header.id = MESSAGE_REQ_CFG_RINGSTATUSGET;
  278. iov.iov_base = &req_lib_cfg_ringstatusget,
  279. iov.iov_len = sizeof (struct req_lib_cfg_ringstatusget),
  280. pthread_mutex_lock (&cfg_instance->response_mutex);
  281. error = coroipcc_msg_send_reply_receive(cfg_instance->ipc_ctx,
  282. &iov,
  283. 1,
  284. &res_lib_cfg_ringstatusget,
  285. sizeof (struct res_lib_cfg_ringstatusget));
  286. pthread_mutex_unlock (&cfg_instance->response_mutex);
  287. *interface_count = res_lib_cfg_ringstatusget.interface_count;
  288. *interface_names = malloc (sizeof (char *) * *interface_count);
  289. if (*interface_names == NULL) {
  290. return (CS_ERR_NO_MEMORY);
  291. }
  292. memset (*interface_names, 0, sizeof (char *) * *interface_count);
  293. *status = malloc (sizeof (char *) * *interface_count);
  294. if (*status == NULL) {
  295. error = CS_ERR_NO_MEMORY;
  296. goto error_free_interface_names;
  297. }
  298. memset (*status, 0, sizeof (char *) * *interface_count);
  299. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  300. (*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
  301. if ((*(interface_names))[i] == NULL) {
  302. error = CS_ERR_NO_MEMORY;
  303. goto error_free_contents;
  304. }
  305. (*(status))[i] = strdup (res_lib_cfg_ringstatusget.interface_status[i]);
  306. if ((*(status))[i] == NULL) {
  307. error = CS_ERR_NO_MEMORY;
  308. goto error_free_contents;
  309. }
  310. }
  311. goto no_error;
  312. error_free_contents:
  313. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  314. if ((*(interface_names))[i]) {
  315. free ((*(interface_names))[i]);
  316. }
  317. if ((*(status))[i]) {
  318. free ((*(status))[i]);
  319. }
  320. }
  321. free (*status);
  322. error_free_interface_names:
  323. free (*interface_names);
  324. no_error:
  325. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  326. return (error);
  327. }
  328. cs_error_t
  329. corosync_cfg_ring_reenable (
  330. corosync_cfg_handle_t cfg_handle)
  331. {
  332. struct cfg_instance *cfg_instance;
  333. struct req_lib_cfg_ringreenable req_lib_cfg_ringreenable;
  334. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  335. cs_error_t error;
  336. struct iovec iov;
  337. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  338. if (error != CS_OK) {
  339. return (error);
  340. }
  341. req_lib_cfg_ringreenable.header.size = sizeof (struct req_lib_cfg_ringreenable);
  342. req_lib_cfg_ringreenable.header.id = MESSAGE_REQ_CFG_RINGREENABLE;
  343. iov.iov_base = &req_lib_cfg_ringreenable,
  344. iov.iov_len = sizeof (struct req_lib_cfg_ringreenable);
  345. pthread_mutex_lock (&cfg_instance->response_mutex);
  346. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  347. &iov,
  348. 1,
  349. &res_lib_cfg_ringreenable,
  350. sizeof (struct res_lib_cfg_ringreenable));
  351. pthread_mutex_unlock (&cfg_instance->response_mutex);
  352. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  353. return (error);
  354. }
  355. cs_error_t
  356. corosync_cfg_service_load (
  357. corosync_cfg_handle_t cfg_handle,
  358. char *service_name,
  359. unsigned int service_ver)
  360. {
  361. struct cfg_instance *cfg_instance;
  362. struct req_lib_cfg_serviceload req_lib_cfg_serviceload;
  363. struct res_lib_cfg_serviceload res_lib_cfg_serviceload;
  364. cs_error_t error;
  365. struct iovec iov;
  366. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  367. if (error != CS_OK) {
  368. return (error);
  369. }
  370. req_lib_cfg_serviceload.header.size = sizeof (struct req_lib_cfg_serviceload);
  371. req_lib_cfg_serviceload.header.id = MESSAGE_REQ_CFG_SERVICELOAD;
  372. memset (&req_lib_cfg_serviceload.service_name, 0,
  373. sizeof (req_lib_cfg_serviceload.service_name));
  374. strncpy (req_lib_cfg_serviceload.service_name, service_name,
  375. sizeof (req_lib_cfg_serviceload.service_name) - 1);
  376. req_lib_cfg_serviceload.service_ver = service_ver;
  377. iov.iov_base = &req_lib_cfg_serviceload;
  378. iov.iov_len = sizeof (req_lib_cfg_serviceload);
  379. pthread_mutex_lock (&cfg_instance->response_mutex);
  380. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  381. &iov,
  382. 1,
  383. &res_lib_cfg_serviceload,
  384. sizeof (struct res_lib_cfg_serviceload));
  385. pthread_mutex_unlock (&cfg_instance->response_mutex);
  386. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  387. return (error);
  388. }
  389. cs_error_t
  390. corosync_cfg_service_unload (
  391. corosync_cfg_handle_t cfg_handle,
  392. char *service_name,
  393. unsigned int service_ver)
  394. {
  395. struct cfg_instance *cfg_instance;
  396. struct req_lib_cfg_serviceunload req_lib_cfg_serviceunload;
  397. struct res_lib_cfg_serviceunload res_lib_cfg_serviceunload;
  398. cs_error_t error;
  399. struct iovec iov;
  400. error = saHandleInstanceGet (&cfg_hdb, cfg_handle, (void *)&cfg_instance);
  401. if (error != CS_OK) {
  402. return (error);
  403. }
  404. req_lib_cfg_serviceunload.header.size = sizeof (struct req_lib_cfg_serviceunload);
  405. req_lib_cfg_serviceunload.header.id = MESSAGE_REQ_CFG_SERVICEUNLOAD;
  406. memset (&req_lib_cfg_serviceunload.service_name, 0,
  407. sizeof (req_lib_cfg_serviceunload.service_name));
  408. strncpy (req_lib_cfg_serviceunload.service_name, service_name,
  409. sizeof (req_lib_cfg_serviceunload.service_name) - 1);
  410. req_lib_cfg_serviceunload.service_ver = service_ver;
  411. iov.iov_base = &req_lib_cfg_serviceunload;
  412. iov.iov_len = sizeof (req_lib_cfg_serviceunload);
  413. pthread_mutex_lock (&cfg_instance->response_mutex);
  414. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  415. &iov,
  416. 1,
  417. &res_lib_cfg_serviceunload,
  418. sizeof (struct res_lib_cfg_serviceunload));
  419. pthread_mutex_unlock (&cfg_instance->response_mutex);
  420. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  421. return (error);
  422. }
  423. cs_error_t
  424. corosync_cfg_state_track (
  425. corosync_cfg_handle_t cfg_handle,
  426. uint8_t track_flags,
  427. const corosync_cfg_state_notification_t *notification_buffer)
  428. {
  429. struct cfg_instance *cfg_instance;
  430. struct req_lib_cfg_statetrack req_lib_cfg_statetrack;
  431. struct res_lib_cfg_statetrack res_lib_cfg_statetrack;
  432. cs_error_t error;
  433. struct iovec iov;
  434. req_lib_cfg_statetrack.header.size = sizeof (struct req_lib_cfg_statetrack);
  435. req_lib_cfg_statetrack.header.id = MESSAGE_REQ_CFG_STATETRACKSTART;
  436. req_lib_cfg_statetrack.track_flags = track_flags;
  437. req_lib_cfg_statetrack.notification_buffer_address = (corosync_cfg_state_notification_t *)notification_buffer;
  438. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  439. (void *)&cfg_instance);
  440. if (error != CS_OK) {
  441. return (error);
  442. }
  443. iov.iov_base = &req_lib_cfg_statetrack,
  444. iov.iov_len = sizeof (struct req_lib_cfg_statetrack),
  445. pthread_mutex_lock (&cfg_instance->response_mutex);
  446. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  447. &iov,
  448. 1,
  449. &res_lib_cfg_statetrack,
  450. sizeof (struct res_lib_cfg_statetrack));
  451. pthread_mutex_unlock (&cfg_instance->response_mutex);
  452. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  453. return (error == CS_OK ? res_lib_cfg_statetrack.header.error : error);
  454. }
  455. cs_error_t
  456. corosync_cfg_state_track_stop (
  457. corosync_cfg_handle_t cfg_handle)
  458. {
  459. struct cfg_instance *cfg_instance;
  460. struct req_lib_cfg_statetrackstop req_lib_cfg_statetrackstop;
  461. struct res_lib_cfg_statetrackstop res_lib_cfg_statetrackstop;
  462. cs_error_t error;
  463. struct iovec iov;
  464. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  465. (void *)&cfg_instance);
  466. if (error != CS_OK) {
  467. return (error);
  468. }
  469. req_lib_cfg_statetrackstop.header.size = sizeof (struct req_lib_cfg_statetrackstop);
  470. req_lib_cfg_statetrackstop.header.id = MESSAGE_REQ_CFG_STATETRACKSTOP;
  471. iov.iov_base = &req_lib_cfg_statetrackstop,
  472. iov.iov_len = sizeof (struct req_lib_cfg_statetrackstop),
  473. pthread_mutex_lock (&cfg_instance->response_mutex);
  474. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  475. &iov,
  476. 1,
  477. &res_lib_cfg_statetrackstop,
  478. sizeof (struct res_lib_cfg_statetrackstop));
  479. pthread_mutex_unlock (&cfg_instance->response_mutex);
  480. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  481. return (error == CS_OK ? res_lib_cfg_statetrackstop.header.error : error);
  482. }
  483. cs_error_t
  484. corosync_cfg_admin_state_get (
  485. corosync_cfg_handle_t cfg_handle,
  486. corosync_cfg_administrative_target_t administrative_target,
  487. corosync_cfg_administrative_state_t *administrative_state)
  488. {
  489. struct cfg_instance *cfg_instance;
  490. struct req_lib_cfg_administrativestateget req_lib_cfg_administrativestateget;
  491. struct res_lib_cfg_administrativestateget res_lib_cfg_administrativestateget;
  492. cs_error_t error;
  493. struct iovec iov;
  494. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  495. (void *)&cfg_instance);
  496. if (error != CS_OK) {
  497. return (error);
  498. }
  499. req_lib_cfg_administrativestateget.header.id = MESSAGE_REQ_CFG_ADMINISTRATIVESTATEGET;
  500. req_lib_cfg_administrativestateget.header.size = sizeof (struct req_lib_cfg_administrativestateget);
  501. req_lib_cfg_administrativestateget.administrative_target = administrative_target;
  502. pthread_mutex_lock (&cfg_instance->response_mutex);
  503. iov.iov_base = &req_lib_cfg_administrativestateget,
  504. iov.iov_len = sizeof (struct req_lib_cfg_administrativestateget),
  505. pthread_mutex_lock (&cfg_instance->response_mutex);
  506. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  507. &iov,
  508. 1,
  509. &res_lib_cfg_administrativestateget,
  510. sizeof (struct res_lib_cfg_administrativestateget));
  511. error = res_lib_cfg_administrativestateget.header.error;
  512. pthread_mutex_unlock (&cfg_instance->response_mutex);
  513. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  514. return (error == CS_OK ? res_lib_cfg_administrativestateget.header.error : error);
  515. }
  516. cs_error_t
  517. corosync_cfg_admin_state_set (
  518. corosync_cfg_handle_t cfg_handle,
  519. corosync_cfg_administrative_target_t administrative_target,
  520. corosync_cfg_administrative_state_t administrative_state)
  521. {
  522. struct cfg_instance *cfg_instance;
  523. struct req_lib_cfg_administrativestateset req_lib_cfg_administrativestateset;
  524. struct res_lib_cfg_administrativestateset res_lib_cfg_administrativestateset;
  525. cs_error_t error;
  526. struct iovec iov;
  527. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  528. (void *)&cfg_instance);
  529. if (error != CS_OK) {
  530. return (error);
  531. }
  532. req_lib_cfg_administrativestateset.header.id = MESSAGE_REQ_CFG_ADMINISTRATIVESTATEGET;
  533. req_lib_cfg_administrativestateset.header.size = sizeof (struct req_lib_cfg_administrativestateset);
  534. req_lib_cfg_administrativestateset.administrative_target = administrative_target;
  535. req_lib_cfg_administrativestateset.administrative_state = administrative_state;
  536. pthread_mutex_lock (&cfg_instance->response_mutex);
  537. iov.iov_base = &req_lib_cfg_administrativestateset,
  538. iov.iov_len = sizeof (struct req_lib_cfg_administrativestateset),
  539. pthread_mutex_lock (&cfg_instance->response_mutex);
  540. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  541. &iov,
  542. 1,
  543. &res_lib_cfg_administrativestateset,
  544. sizeof (struct res_lib_cfg_administrativestateset));
  545. error = res_lib_cfg_administrativestateset.header.error;
  546. pthread_mutex_unlock (&cfg_instance->response_mutex);
  547. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  548. return (error == CS_OK ? res_lib_cfg_administrativestateset.header.error : error);
  549. }
  550. cs_error_t
  551. corosync_cfg_kill_node (
  552. corosync_cfg_handle_t cfg_handle,
  553. unsigned int nodeid,
  554. char *reason)
  555. {
  556. struct cfg_instance *cfg_instance;
  557. struct req_lib_cfg_killnode req_lib_cfg_killnode;
  558. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  559. cs_error_t error;
  560. struct iovec iov;
  561. if (strlen(reason) >= CS_MAX_NAME_LENGTH)
  562. return CS_ERR_NAME_TOO_LONG;
  563. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  564. (void *)&cfg_instance);
  565. if (error != CS_OK) {
  566. return (error);
  567. }
  568. req_lib_cfg_killnode.header.id = MESSAGE_REQ_CFG_KILLNODE;
  569. req_lib_cfg_killnode.header.size = sizeof (struct req_lib_cfg_killnode);
  570. req_lib_cfg_killnode.nodeid = nodeid;
  571. strcpy((char *)req_lib_cfg_killnode.reason.value, reason);
  572. req_lib_cfg_killnode.reason.length = strlen(reason)+1;
  573. iov.iov_base = &req_lib_cfg_killnode;
  574. iov.iov_len = sizeof (struct req_lib_cfg_killnode);
  575. pthread_mutex_lock (&cfg_instance->response_mutex);
  576. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  577. &iov,
  578. 1,
  579. &res_lib_cfg_killnode,
  580. sizeof (struct res_lib_cfg_killnode));
  581. error = res_lib_cfg_killnode.header.error;
  582. pthread_mutex_unlock (&cfg_instance->response_mutex);
  583. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  584. return (error == CS_OK ? res_lib_cfg_killnode.header.error : error);
  585. }
  586. cs_error_t
  587. corosync_cfg_try_shutdown (
  588. corosync_cfg_handle_t cfg_handle,
  589. corosync_cfg_shutdown_flags_t flags)
  590. {
  591. struct cfg_instance *cfg_instance;
  592. struct req_lib_cfg_tryshutdown req_lib_cfg_tryshutdown;
  593. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  594. cs_error_t error;
  595. struct iovec iov;
  596. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  597. (void *)&cfg_instance);
  598. if (error != CS_OK) {
  599. return (error);
  600. }
  601. req_lib_cfg_tryshutdown.header.id = MESSAGE_REQ_CFG_TRYSHUTDOWN;
  602. req_lib_cfg_tryshutdown.header.size = sizeof (struct req_lib_cfg_tryshutdown);
  603. req_lib_cfg_tryshutdown.flags = flags;
  604. iov.iov_base = &req_lib_cfg_tryshutdown;
  605. iov.iov_len = sizeof (req_lib_cfg_tryshutdown);
  606. pthread_mutex_lock (&cfg_instance->response_mutex);
  607. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  608. &iov,
  609. 1,
  610. &res_lib_cfg_tryshutdown,
  611. sizeof (struct res_lib_cfg_tryshutdown));
  612. pthread_mutex_unlock (&cfg_instance->response_mutex);
  613. (void)saHandleInstancePut (&cfg_hdb, cfg_handle);
  614. return (error == CS_OK ? res_lib_cfg_tryshutdown.header.error : error);
  615. }
  616. cs_error_t
  617. corosync_cfg_replyto_shutdown (
  618. corosync_cfg_handle_t cfg_handle,
  619. corosync_cfg_shutdown_reply_flags_t response)
  620. {
  621. struct cfg_instance *cfg_instance;
  622. struct req_lib_cfg_replytoshutdown req_lib_cfg_replytoshutdown;
  623. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  624. struct iovec iov;
  625. cs_error_t error;
  626. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  627. (void *)&cfg_instance);
  628. if (error != CS_OK) {
  629. return (error);
  630. }
  631. req_lib_cfg_replytoshutdown.header.id = MESSAGE_REQ_CFG_REPLYTOSHUTDOWN;
  632. req_lib_cfg_replytoshutdown.header.size = sizeof (struct req_lib_cfg_replytoshutdown);
  633. req_lib_cfg_replytoshutdown.response = response;
  634. iov.iov_base = &req_lib_cfg_replytoshutdown;
  635. iov.iov_len = sizeof (struct req_lib_cfg_replytoshutdown);
  636. pthread_mutex_lock (&cfg_instance->response_mutex);
  637. error = coroipcc_msg_send_reply_receive (cfg_instance->ipc_ctx,
  638. &iov,
  639. 1,
  640. &res_lib_cfg_replytoshutdown,
  641. sizeof (struct res_lib_cfg_replytoshutdown));
  642. pthread_mutex_unlock (&cfg_instance->response_mutex);
  643. return (error);
  644. }
  645. cs_error_t corosync_cfg_get_node_addrs (
  646. corosync_cfg_handle_t cfg_handle,
  647. int nodeid,
  648. int max_addrs,
  649. int *num_addrs,
  650. corosync_cfg_node_address_t *addrs)
  651. {
  652. cs_error_t error;
  653. struct req_lib_cfg_get_node_addrs req_lib_cfg_get_node_addrs;
  654. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs;
  655. struct cfg_instance *cfg_instance;
  656. int addrlen;
  657. int i;
  658. struct iovec iov;
  659. void *return_address;
  660. error = saHandleInstanceGet (&cfg_hdb, cfg_handle,
  661. (void *)&cfg_instance);
  662. if (error != CS_OK) {
  663. return (error);
  664. }
  665. req_lib_cfg_get_node_addrs.header.size = sizeof (req_lib_cfg_get_node_addrs);
  666. req_lib_cfg_get_node_addrs.header.id = MESSAGE_REQ_CFG_GET_NODE_ADDRS;
  667. req_lib_cfg_get_node_addrs.nodeid = nodeid;
  668. iov.iov_base = (char *)&req_lib_cfg_get_node_addrs;
  669. iov.iov_len = sizeof (req_lib_cfg_get_node_addrs);
  670. pthread_mutex_lock (&cfg_instance->response_mutex);
  671. error = coroipcc_msg_send_reply_receive_in_buf (cfg_instance->ipc_ctx,
  672. &iov,
  673. 1,
  674. &return_address);
  675. res_lib_cfg_get_node_addrs = return_address;
  676. pthread_mutex_unlock (&cfg_instance->response_mutex);
  677. if (error != CS_OK) {
  678. goto error_exit;
  679. }
  680. if (res_lib_cfg_get_node_addrs->family == AF_INET)
  681. addrlen = sizeof(struct sockaddr_in);
  682. if (res_lib_cfg_get_node_addrs->family == AF_INET6)
  683. addrlen = sizeof(struct sockaddr_in6);
  684. for (i=0; i<max_addrs && i<res_lib_cfg_get_node_addrs->num_addrs; i++) {
  685. addrs[i].address_length = addrlen;
  686. struct sockaddr_in *in;
  687. struct sockaddr_in6 *in6;
  688. if (res_lib_cfg_get_node_addrs->family == AF_INET) {
  689. in = (struct sockaddr_in *)addrs[i].address;
  690. in->sin_family = AF_INET;
  691. memcpy(&in->sin_addr, &res_lib_cfg_get_node_addrs->addrs[i][0], sizeof(struct in_addr));
  692. }
  693. if (res_lib_cfg_get_node_addrs->family == AF_INET6) {
  694. in6 = (struct sockaddr_in6 *)addrs[i].address;
  695. in6->sin6_family = AF_INET6;
  696. memcpy(&in6->sin6_addr, &res_lib_cfg_get_node_addrs->addrs[i][0], sizeof(struct in6_addr));
  697. }
  698. }
  699. *num_addrs = res_lib_cfg_get_node_addrs->num_addrs;
  700. errno = error = res_lib_cfg_get_node_addrs->header.error;
  701. error_exit:
  702. return (error);
  703. }
  704. cs_error_t corosync_cfg_local_get (
  705. corosync_cfg_handle_t handle,
  706. unsigned int *local_nodeid)
  707. {
  708. cs_error_t error;
  709. struct cfg_instance *cfg_inst;
  710. struct iovec iov;
  711. struct req_lib_cfg_local_get req_lib_cfg_local_get;
  712. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  713. error = saHandleInstanceGet (&cfg_hdb, handle, (void *)&cfg_inst);
  714. if (error != CS_OK) {
  715. return (error);
  716. }
  717. req_lib_cfg_local_get.header.size = sizeof (mar_req_header_t);
  718. req_lib_cfg_local_get.header.id = MESSAGE_REQ_CFG_LOCAL_GET;
  719. iov.iov_base = &req_lib_cfg_local_get;
  720. iov.iov_len = sizeof (struct req_lib_cfg_local_get);
  721. pthread_mutex_lock (&cfg_inst->response_mutex);
  722. error = coroipcc_msg_send_reply_receive (
  723. cfg_inst->ipc_ctx,
  724. &iov,
  725. 1,
  726. &res_lib_cfg_local_get,
  727. sizeof (struct res_lib_cfg_local_get));
  728. pthread_mutex_unlock (&cfg_inst->response_mutex);
  729. if (error != CS_OK) {
  730. goto error_exit;
  731. }
  732. error = res_lib_cfg_local_get.header.error;
  733. *local_nodeid = res_lib_cfg_local_get.local_nodeid;
  734. error_exit:
  735. (void)saHandleInstancePut (&cfg_hdb, handle);
  736. return (error);
  737. }