cfg.c 21 KB

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