cfg.c 22 KB

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