cfg.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2020 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 <sys/uio.h>
  48. #include <qb/qbipcc.h>
  49. #include <corosync/corotypes.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_inst {
  59. qb_ipcc_connection_t *c;
  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. static void cfg_inst_free (void *inst);
  69. DECLARE_HDB_DATABASE (cfg_hdb, cfg_inst_free);
  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_inst *cfg_inst;
  79. cs_error_t error = CS_OK;
  80. error = hdb_error_to_cs (hdb_handle_create (&cfg_hdb, sizeof (struct cfg_inst), 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_inst));
  85. if (error != CS_OK) {
  86. goto error_destroy;
  87. }
  88. cfg_inst->finalize = 0;
  89. cfg_inst->c = qb_ipcc_connect ("cfg", IPC_REQUEST_SIZE);
  90. if (cfg_inst->c == NULL) {
  91. error = qb_to_cs_error(-errno);
  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_ONE_NONBLOCKING or CS_DISPATCH_ALL and
  141. * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
  142. */
  143. if (dispatch_flags == CS_DISPATCH_ALL || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
  144. timeout = 0;
  145. }
  146. dispatch_data = (struct qb_ipc_response_header *)dispatch_buf;
  147. do {
  148. error = qb_to_cs_error (qb_ipcc_event_recv (
  149. cfg_inst->c,
  150. dispatch_buf,
  151. IPC_DISPATCH_SIZE,
  152. timeout));
  153. if (error == CS_ERR_BAD_HANDLE) {
  154. error = CS_OK;
  155. goto error_put;
  156. }
  157. if (error == CS_ERR_TRY_AGAIN) {
  158. if (dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
  159. /*
  160. * Don't mask error
  161. */
  162. goto error_put;
  163. }
  164. error = CS_OK;
  165. if (dispatch_flags == CS_DISPATCH_ALL) {
  166. break; /* exit do while cont is 1 loop */
  167. } else {
  168. continue; /* next poll */
  169. }
  170. }
  171. if (error != CS_OK) {
  172. goto error_put;
  173. }
  174. /*
  175. * Make copy of callbacks, message data, unlock instance, and call callback
  176. * A risk of this dispatch method is that the callback routines may
  177. * operate at the same time that cfgFinalize has been called in another thread.
  178. */
  179. memcpy (&callbacks, &cfg_inst->callbacks, sizeof (corosync_cfg_callbacks_t));
  180. /*
  181. * Dispatch incoming response
  182. */
  183. switch (dispatch_data->id) {
  184. case MESSAGE_RES_CFG_TESTSHUTDOWN:
  185. if (callbacks.corosync_cfg_shutdown_callback == NULL) {
  186. break;
  187. }
  188. res_lib_cfg_testshutdown = (struct res_lib_cfg_testshutdown *)dispatch_data;
  189. callbacks.corosync_cfg_shutdown_callback(cfg_handle, res_lib_cfg_testshutdown->flags);
  190. break;
  191. default:
  192. error = CS_ERR_LIBRARY;
  193. goto error_nounlock;
  194. break;
  195. }
  196. if (cfg_inst->finalize) {
  197. /*
  198. * If the finalize has been called then get out of the dispatch.
  199. */
  200. error = CS_ERR_BAD_HANDLE;
  201. goto error_put;
  202. }
  203. /*
  204. * Determine if more messages should be processed
  205. */
  206. if (dispatch_flags == CS_DISPATCH_ONE || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
  207. cont = 0;
  208. }
  209. } while (cont);
  210. error_put:
  211. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  212. error_nounlock:
  213. return (error);
  214. }
  215. static void cfg_inst_free (void *inst)
  216. {
  217. struct cfg_inst *cfg_inst = (struct cfg_inst *)inst;
  218. qb_ipcc_disconnect(cfg_inst->c);
  219. }
  220. cs_error_t
  221. corosync_cfg_finalize (
  222. corosync_cfg_handle_t cfg_handle)
  223. {
  224. struct cfg_inst *cfg_inst;
  225. cs_error_t error;
  226. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst));
  227. if (error != CS_OK) {
  228. return (error);
  229. }
  230. /*
  231. * Another thread has already started finalizing
  232. */
  233. if (cfg_inst->finalize) {
  234. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  235. return (CS_ERR_BAD_HANDLE);
  236. }
  237. cfg_inst->finalize = 1;
  238. (void)hdb_handle_destroy (&cfg_hdb, cfg_handle);
  239. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  240. return (error);
  241. }
  242. cs_error_t
  243. corosync_cfg_ring_status_get (
  244. corosync_cfg_handle_t cfg_handle,
  245. char ***interface_names,
  246. char ***status,
  247. unsigned int *interface_count)
  248. {
  249. struct cfg_inst *cfg_inst;
  250. struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget;
  251. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  252. unsigned int i, j;
  253. cs_error_t error;
  254. struct iovec iov;
  255. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst));
  256. if (error != CS_OK) {
  257. return (error);
  258. }
  259. req_lib_cfg_ringstatusget.header.size = sizeof (struct req_lib_cfg_ringstatusget);
  260. req_lib_cfg_ringstatusget.header.id = MESSAGE_REQ_CFG_RINGSTATUSGET;
  261. iov.iov_base = (void *)&req_lib_cfg_ringstatusget,
  262. iov.iov_len = sizeof (struct req_lib_cfg_ringstatusget),
  263. error = qb_to_cs_error (qb_ipcc_sendv_recv(cfg_inst->c,
  264. &iov,
  265. 1,
  266. &res_lib_cfg_ringstatusget,
  267. sizeof (struct res_lib_cfg_ringstatusget), CS_IPC_TIMEOUT_MS));
  268. if (error != CS_OK) {
  269. goto exit_handle_put;
  270. }
  271. *interface_count = res_lib_cfg_ringstatusget.interface_count;
  272. *interface_names = malloc (sizeof (char *) * *interface_count);
  273. if (*interface_names == NULL) {
  274. return (CS_ERR_NO_MEMORY);
  275. }
  276. memset (*interface_names, 0, sizeof (char *) * *interface_count);
  277. *status = malloc (sizeof (char *) * *interface_count);
  278. if (*status == NULL) {
  279. error = CS_ERR_NO_MEMORY;
  280. goto error_free_interface_names_array;
  281. }
  282. memset (*status, 0, sizeof (char *) * *interface_count);
  283. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  284. (*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
  285. if ((*(interface_names))[i] == NULL) {
  286. error = CS_ERR_NO_MEMORY;
  287. goto error_free_interface_names;
  288. }
  289. }
  290. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  291. (*(status))[i] = strdup (res_lib_cfg_ringstatusget.interface_status[i]);
  292. if ((*(status))[i] == NULL) {
  293. error = CS_ERR_NO_MEMORY;
  294. goto error_free_status;
  295. }
  296. }
  297. goto exit_handle_put;
  298. error_free_status:
  299. for (j = 0; j < i; j++) {
  300. free ((*(status))[j]);
  301. }
  302. i = *interface_count;
  303. error_free_interface_names:
  304. for (j = 0; j < i; j++) {
  305. free ((*(interface_names))[j]);
  306. }
  307. free (*status);
  308. error_free_interface_names_array:
  309. free (*interface_names);
  310. exit_handle_put:
  311. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  312. return (error);
  313. }
  314. cs_error_t
  315. corosync_cfg_node_status_get (
  316. corosync_cfg_handle_t cfg_handle,
  317. unsigned int nodeid,
  318. corosync_cfg_node_status_version_t version,
  319. void *node_status)
  320. {
  321. struct cfg_inst *cfg_inst;
  322. struct req_lib_cfg_nodestatusget req_lib_cfg_nodestatusget;
  323. cs_error_t error;
  324. struct iovec iov;
  325. size_t cfg_node_status_size;
  326. void *res_lib_cfg_nodestatuget_ptr;
  327. struct res_lib_cfg_nodestatusget_v1 res_lib_cfg_nodestatusget_v1;
  328. struct res_lib_cfg_nodestatusget_version *res_lib_cfg_nodestatusget_version;
  329. if (!node_status) {
  330. return (CS_ERR_INVALID_PARAM);
  331. }
  332. switch (version) {
  333. case CFG_NODE_STATUS_V1:
  334. cfg_node_status_size = sizeof(struct res_lib_cfg_nodestatusget_v1);
  335. res_lib_cfg_nodestatuget_ptr = &res_lib_cfg_nodestatusget_v1;
  336. break;
  337. default:
  338. return (CS_ERR_INVALID_PARAM);
  339. break;
  340. }
  341. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst));
  342. if (error != CS_OK) {
  343. return (error);
  344. }
  345. req_lib_cfg_nodestatusget.header.size = sizeof (struct req_lib_cfg_nodestatusget);
  346. req_lib_cfg_nodestatusget.header.id = MESSAGE_REQ_CFG_NODESTATUSGET;
  347. req_lib_cfg_nodestatusget.nodeid = nodeid;
  348. req_lib_cfg_nodestatusget.version = version;
  349. iov.iov_base = (void *)&req_lib_cfg_nodestatusget,
  350. iov.iov_len = sizeof (struct req_lib_cfg_nodestatusget),
  351. error = qb_to_cs_error (qb_ipcc_sendv_recv(cfg_inst->c,
  352. &iov,
  353. 1,
  354. res_lib_cfg_nodestatuget_ptr,
  355. cfg_node_status_size, CS_IPC_TIMEOUT_MS));
  356. if (error != CS_OK) {
  357. goto error_put;
  358. }
  359. res_lib_cfg_nodestatusget_version = res_lib_cfg_nodestatuget_ptr;
  360. error = res_lib_cfg_nodestatusget_version->header.error;
  361. if (error != CS_OK) {
  362. goto error_put;
  363. }
  364. if (res_lib_cfg_nodestatusget_version->version != version) {
  365. /*
  366. * corosync sent us something we don't really understand.
  367. */
  368. error = CS_ERR_NOT_SUPPORTED;
  369. goto error_put;
  370. }
  371. switch (version) {
  372. case CFG_NODE_STATUS_V1:
  373. memcpy(node_status, &res_lib_cfg_nodestatusget_v1.node_status,
  374. sizeof(struct corosync_cfg_node_status_v1));
  375. break;
  376. }
  377. error_put:
  378. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  379. return (error);
  380. }
  381. cs_error_t
  382. corosync_cfg_kill_node (
  383. corosync_cfg_handle_t cfg_handle,
  384. unsigned int nodeid,
  385. const char *reason)
  386. {
  387. struct cfg_inst *cfg_inst;
  388. struct req_lib_cfg_killnode req_lib_cfg_killnode;
  389. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  390. cs_error_t error;
  391. struct iovec iov;
  392. if (strlen(reason) >= CS_MAX_NAME_LENGTH)
  393. return CS_ERR_NAME_TOO_LONG;
  394. error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle,
  395. (void *)&cfg_inst));
  396. if (error != CS_OK) {
  397. return (error);
  398. }
  399. req_lib_cfg_killnode.header.id = MESSAGE_REQ_CFG_KILLNODE;
  400. req_lib_cfg_killnode.header.size = sizeof (struct req_lib_cfg_killnode);
  401. req_lib_cfg_killnode.nodeid = nodeid;
  402. strcpy((char *)req_lib_cfg_killnode.reason.value, reason);
  403. req_lib_cfg_killnode.reason.length = strlen(reason)+1;
  404. iov.iov_base = (void *)&req_lib_cfg_killnode;
  405. iov.iov_len = sizeof (struct req_lib_cfg_killnode);
  406. error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c,
  407. &iov,
  408. 1,
  409. &res_lib_cfg_killnode,
  410. sizeof (struct res_lib_cfg_killnode), CS_IPC_TIMEOUT_MS));
  411. error = res_lib_cfg_killnode.header.error;
  412. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  413. return (error == CS_OK ? res_lib_cfg_killnode.header.error : error);
  414. }
  415. cs_error_t
  416. corosync_cfg_try_shutdown (
  417. corosync_cfg_handle_t cfg_handle,
  418. corosync_cfg_shutdown_flags_t flags)
  419. {
  420. struct cfg_inst *cfg_inst;
  421. struct req_lib_cfg_tryshutdown req_lib_cfg_tryshutdown;
  422. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  423. cs_error_t error;
  424. struct iovec iov;
  425. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle,
  426. (void *)&cfg_inst));
  427. if (error != CS_OK) {
  428. return (error);
  429. }
  430. req_lib_cfg_tryshutdown.header.id = MESSAGE_REQ_CFG_TRYSHUTDOWN;
  431. req_lib_cfg_tryshutdown.header.size = sizeof (struct req_lib_cfg_tryshutdown);
  432. req_lib_cfg_tryshutdown.flags = flags;
  433. iov.iov_base = (void *)&req_lib_cfg_tryshutdown;
  434. iov.iov_len = sizeof (req_lib_cfg_tryshutdown);
  435. error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c,
  436. &iov,
  437. 1,
  438. &res_lib_cfg_tryshutdown,
  439. sizeof (struct res_lib_cfg_tryshutdown), CS_IPC_TIMEOUT_MS));
  440. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  441. return (error == CS_OK ? res_lib_cfg_tryshutdown.header.error : error);
  442. }
  443. cs_error_t
  444. corosync_cfg_replyto_shutdown (
  445. corosync_cfg_handle_t cfg_handle,
  446. corosync_cfg_shutdown_reply_flags_t response)
  447. {
  448. struct cfg_inst *cfg_inst;
  449. struct req_lib_cfg_replytoshutdown req_lib_cfg_replytoshutdown;
  450. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  451. struct iovec iov;
  452. cs_error_t error;
  453. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle,
  454. (void *)&cfg_inst));
  455. if (error != CS_OK) {
  456. return (error);
  457. }
  458. req_lib_cfg_replytoshutdown.header.id = MESSAGE_REQ_CFG_REPLYTOSHUTDOWN;
  459. req_lib_cfg_replytoshutdown.header.size = sizeof (struct req_lib_cfg_replytoshutdown);
  460. req_lib_cfg_replytoshutdown.response = response;
  461. iov.iov_base = (void *)&req_lib_cfg_replytoshutdown;
  462. iov.iov_len = sizeof (struct req_lib_cfg_replytoshutdown);
  463. error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c,
  464. &iov,
  465. 1,
  466. &res_lib_cfg_replytoshutdown,
  467. sizeof (struct res_lib_cfg_replytoshutdown), CS_IPC_TIMEOUT_MS));
  468. return (error);
  469. }
  470. cs_error_t corosync_cfg_get_node_addrs (
  471. corosync_cfg_handle_t cfg_handle,
  472. unsigned int nodeid,
  473. size_t max_addrs,
  474. int *num_addrs,
  475. corosync_cfg_node_address_t *addrs)
  476. {
  477. cs_error_t error;
  478. struct req_lib_cfg_get_node_addrs req_lib_cfg_get_node_addrs;
  479. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs;
  480. struct cfg_inst *cfg_inst;
  481. int addrlen = 0;
  482. int i;
  483. struct iovec iov;
  484. const char *addr_buf;
  485. char response_buf[IPC_RESPONSE_SIZE];
  486. char zeroes[sizeof(struct sockaddr_storage)];
  487. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle,
  488. (void *)&cfg_inst));
  489. if (error != CS_OK) {
  490. return (error);
  491. }
  492. memset(zeroes, 0, sizeof(zeroes));
  493. req_lib_cfg_get_node_addrs.header.size = sizeof (req_lib_cfg_get_node_addrs);
  494. req_lib_cfg_get_node_addrs.header.id = MESSAGE_REQ_CFG_GET_NODE_ADDRS;
  495. req_lib_cfg_get_node_addrs.nodeid = nodeid;
  496. iov.iov_base = (char *)&req_lib_cfg_get_node_addrs;
  497. iov.iov_len = sizeof (req_lib_cfg_get_node_addrs);
  498. error = qb_to_cs_error (qb_ipcc_sendv_recv (
  499. cfg_inst->c,
  500. &iov, 1,
  501. response_buf, IPC_RESPONSE_SIZE, CS_IPC_TIMEOUT_MS));
  502. res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)response_buf;
  503. if (error != CS_OK) {
  504. goto error_put;
  505. }
  506. if (res_lib_cfg_get_node_addrs->family == AF_INET)
  507. addrlen = sizeof(struct sockaddr_in);
  508. if (res_lib_cfg_get_node_addrs->family == AF_INET6)
  509. addrlen = sizeof(struct sockaddr_in6);
  510. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  511. i < max_addrs && i<res_lib_cfg_get_node_addrs->num_addrs;
  512. i++, addr_buf += TOTEMIP_ADDRLEN) {
  513. struct sockaddr_in *in;
  514. struct sockaddr_in6 *in6;
  515. addrs[i].address_length = addrlen;
  516. if (res_lib_cfg_get_node_addrs->family == AF_INET) {
  517. in = (struct sockaddr_in *)addrs[i].address;
  518. if (memcmp(addr_buf, zeroes, addrlen) == 0) {
  519. in->sin_family = 0;
  520. } else {
  521. in->sin_family = AF_INET;
  522. }
  523. memcpy(&in->sin_addr, addr_buf, sizeof(struct in_addr));
  524. }
  525. if (res_lib_cfg_get_node_addrs->family == AF_INET6) {
  526. in6 = (struct sockaddr_in6 *)addrs[i].address;
  527. if (memcmp(addr_buf, zeroes, addrlen) == 0) {
  528. in6->sin6_family = 0;
  529. } else {
  530. in6->sin6_family = AF_INET6;
  531. }
  532. memcpy(&in6->sin6_addr, addr_buf, sizeof(struct in6_addr));
  533. }
  534. /* Mark it as unused */
  535. }
  536. *num_addrs = res_lib_cfg_get_node_addrs->num_addrs;
  537. errno = error = res_lib_cfg_get_node_addrs->header.error;
  538. error_put:
  539. hdb_handle_put (&cfg_hdb, cfg_handle);
  540. return (error);
  541. }
  542. cs_error_t corosync_cfg_local_get (
  543. corosync_cfg_handle_t handle,
  544. unsigned int *local_nodeid)
  545. {
  546. cs_error_t error;
  547. struct cfg_inst *cfg_inst;
  548. struct iovec iov;
  549. struct req_lib_cfg_local_get req_lib_cfg_local_get;
  550. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  551. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (void *)&cfg_inst));
  552. if (error != CS_OK) {
  553. return (error);
  554. }
  555. req_lib_cfg_local_get.header.size = sizeof (struct qb_ipc_request_header);
  556. req_lib_cfg_local_get.header.id = MESSAGE_REQ_CFG_LOCAL_GET;
  557. iov.iov_base = (void *)&req_lib_cfg_local_get;
  558. iov.iov_len = sizeof (struct req_lib_cfg_local_get);
  559. error = qb_to_cs_error (qb_ipcc_sendv_recv (
  560. cfg_inst->c,
  561. &iov,
  562. 1,
  563. &res_lib_cfg_local_get,
  564. sizeof (struct res_lib_cfg_local_get), CS_IPC_TIMEOUT_MS));
  565. if (error != CS_OK) {
  566. goto error_exit;
  567. }
  568. error = res_lib_cfg_local_get.header.error;
  569. *local_nodeid = res_lib_cfg_local_get.local_nodeid;
  570. error_exit:
  571. (void)hdb_handle_put (&cfg_hdb, handle);
  572. return (error);
  573. }
  574. cs_error_t corosync_cfg_reload_config (
  575. corosync_cfg_handle_t handle)
  576. {
  577. cs_error_t error;
  578. struct cfg_inst *cfg_inst;
  579. struct iovec iov;
  580. struct req_lib_cfg_reload_config req_lib_cfg_reload_config;
  581. struct res_lib_cfg_reload_config res_lib_cfg_reload_config;
  582. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (void *)&cfg_inst));
  583. if (error != CS_OK) {
  584. return (error);
  585. }
  586. req_lib_cfg_reload_config.header.size = sizeof (struct qb_ipc_request_header);
  587. req_lib_cfg_reload_config.header.id = MESSAGE_REQ_CFG_RELOAD_CONFIG;
  588. iov.iov_base = (void *)&req_lib_cfg_reload_config;
  589. iov.iov_len = sizeof (struct req_lib_cfg_reload_config);
  590. error = qb_to_cs_error (qb_ipcc_sendv_recv (
  591. cfg_inst->c,
  592. &iov,
  593. 1,
  594. &res_lib_cfg_reload_config,
  595. sizeof (struct res_lib_cfg_reload_config), CS_IPC_TIMEOUT_MS));
  596. if (error != CS_OK) {
  597. goto error_exit;
  598. }
  599. error = res_lib_cfg_reload_config.header.error;
  600. error_exit:
  601. (void)hdb_handle_put (&cfg_hdb, handle);
  602. return (error);
  603. }
  604. cs_error_t corosync_cfg_reopen_log_files (
  605. corosync_cfg_handle_t handle)
  606. {
  607. cs_error_t error;
  608. struct cfg_inst *cfg_inst;
  609. struct iovec iov;
  610. struct req_lib_cfg_reopen_log_files req_lib_cfg_reopen_log_files;
  611. struct res_lib_cfg_reopen_log_files res_lib_cfg_reopen_log_files;
  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_reopen_log_files.header.size = sizeof (struct qb_ipc_request_header);
  617. req_lib_cfg_reopen_log_files.header.id = MESSAGE_REQ_CFG_REOPEN_LOG_FILES;
  618. iov.iov_base = (void *)&req_lib_cfg_reopen_log_files;
  619. iov.iov_len = sizeof (struct req_lib_cfg_reopen_log_files);
  620. error = qb_to_cs_error (qb_ipcc_sendv_recv (
  621. cfg_inst->c,
  622. &iov,
  623. 1,
  624. &res_lib_cfg_reopen_log_files,
  625. sizeof (struct res_lib_cfg_reopen_log_files), CS_IPC_TIMEOUT_MS));
  626. if (error != CS_OK) {
  627. goto error_exit;
  628. }
  629. error = res_lib_cfg_reopen_log_files.header.error;
  630. error_exit:
  631. (void)hdb_handle_put (&cfg_hdb, handle);
  632. return (error);
  633. }