cfg.c 21 KB

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