cfg.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2011 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. static void cfg_inst_free (void *inst);
  68. DECLARE_HDB_DATABASE (cfg_hdb, cfg_inst_free);
  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_inst *cfg_inst;
  78. cs_error_t error = CS_OK;
  79. error = hdb_error_to_cs (hdb_handle_create (&cfg_hdb, sizeof (struct cfg_inst), 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_inst));
  84. if (error != CS_OK) {
  85. goto error_destroy;
  86. }
  87. cfg_inst->finalize = 0;
  88. cfg_inst->c = qb_ipcc_connect ("cfg", IPC_REQUEST_SIZE);
  89. if (cfg_inst->c == NULL) {
  90. error = qb_to_cs_error(-errno);
  91. goto error_put_destroy;
  92. }
  93. if (cfg_callbacks) {
  94. memcpy (&cfg_inst->callbacks, cfg_callbacks, sizeof (corosync_cfg_callbacks_t));
  95. }
  96. (void)hdb_handle_put (&cfg_hdb, *cfg_handle);
  97. return (CS_OK);
  98. error_put_destroy:
  99. (void)hdb_handle_put (&cfg_hdb, *cfg_handle);
  100. error_destroy:
  101. (void)hdb_handle_destroy (&cfg_hdb, *cfg_handle);
  102. error_no_destroy:
  103. return (error);
  104. }
  105. cs_error_t
  106. corosync_cfg_fd_get (
  107. corosync_cfg_handle_t cfg_handle,
  108. int32_t *selection_fd)
  109. {
  110. struct cfg_inst *cfg_inst;
  111. cs_error_t error;
  112. error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst));
  113. if (error != CS_OK) {
  114. return (error);
  115. }
  116. error = qb_to_cs_error (qb_ipcc_fd_get (cfg_inst->c, selection_fd));
  117. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  118. return (error);
  119. }
  120. cs_error_t
  121. corosync_cfg_dispatch (
  122. corosync_cfg_handle_t cfg_handle,
  123. cs_dispatch_flags_t dispatch_flags)
  124. {
  125. int timeout = -1;
  126. cs_error_t error;
  127. int cont = 1; /* always continue do loop except when set to 0 */
  128. struct cfg_inst *cfg_inst;
  129. struct res_lib_cfg_testshutdown *res_lib_cfg_testshutdown;
  130. corosync_cfg_callbacks_t callbacks;
  131. struct qb_ipc_response_header *dispatch_data;
  132. char dispatch_buf[IPC_DISPATCH_SIZE];
  133. error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle,
  134. (void *)&cfg_inst));
  135. if (error != CS_OK) {
  136. return (error);
  137. }
  138. /*
  139. * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
  140. * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
  141. */
  142. if (dispatch_flags == CS_DISPATCH_ALL || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
  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. if (dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
  158. /*
  159. * Don't mask error
  160. */
  161. goto error_put;
  162. }
  163. error = CS_OK;
  164. if (dispatch_flags == CS_DISPATCH_ALL) {
  165. break; /* exit do while cont is 1 loop */
  166. } else {
  167. continue; /* next poll */
  168. }
  169. }
  170. if (error != CS_OK) {
  171. goto error_put;
  172. }
  173. /*
  174. * Make copy of callbacks, message data, unlock instance, and call callback
  175. * A risk of this dispatch method is that the callback routines may
  176. * operate at the same time that cfgFinalize has been called in another thread.
  177. */
  178. memcpy (&callbacks, &cfg_inst->callbacks, sizeof (corosync_cfg_callbacks_t));
  179. /*
  180. * Dispatch incoming response
  181. */
  182. switch (dispatch_data->id) {
  183. case MESSAGE_RES_CFG_TESTSHUTDOWN:
  184. if (callbacks.corosync_cfg_shutdown_callback == NULL) {
  185. break;
  186. }
  187. res_lib_cfg_testshutdown = (struct res_lib_cfg_testshutdown *)dispatch_data;
  188. callbacks.corosync_cfg_shutdown_callback(cfg_handle, res_lib_cfg_testshutdown->flags);
  189. break;
  190. default:
  191. error = CS_ERR_LIBRARY;
  192. goto error_nounlock;
  193. break;
  194. }
  195. if (cfg_inst->finalize) {
  196. /*
  197. * If the finalize has been called then get out of the dispatch.
  198. */
  199. error = CS_ERR_BAD_HANDLE;
  200. goto error_put;
  201. }
  202. /*
  203. * Determine if more messages should be processed
  204. */
  205. if (dispatch_flags == CS_DISPATCH_ONE || dispatch_flags == CS_DISPATCH_ONE_NONBLOCKING) {
  206. cont = 0;
  207. }
  208. } while (cont);
  209. error_put:
  210. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  211. error_nounlock:
  212. return (error);
  213. }
  214. static void cfg_inst_free (void *inst)
  215. {
  216. struct cfg_inst *cfg_inst = (struct cfg_inst *)inst;
  217. qb_ipcc_disconnect(cfg_inst->c);
  218. }
  219. cs_error_t
  220. corosync_cfg_finalize (
  221. corosync_cfg_handle_t cfg_handle)
  222. {
  223. struct cfg_inst *cfg_inst;
  224. cs_error_t error;
  225. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst));
  226. if (error != CS_OK) {
  227. return (error);
  228. }
  229. /*
  230. * Another thread has already started finalizing
  231. */
  232. if (cfg_inst->finalize) {
  233. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  234. return (CS_ERR_BAD_HANDLE);
  235. }
  236. cfg_inst->finalize = 1;
  237. (void)hdb_handle_destroy (&cfg_hdb, cfg_handle);
  238. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  239. return (error);
  240. }
  241. cs_error_t
  242. corosync_cfg_ring_status_get (
  243. corosync_cfg_handle_t cfg_handle,
  244. char ***interface_names,
  245. char ***status,
  246. unsigned int *interface_count)
  247. {
  248. struct cfg_inst *cfg_inst;
  249. struct req_lib_cfg_ringstatusget req_lib_cfg_ringstatusget;
  250. struct res_lib_cfg_ringstatusget res_lib_cfg_ringstatusget;
  251. unsigned int i, j;
  252. cs_error_t error;
  253. struct iovec iov;
  254. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst));
  255. if (error != CS_OK) {
  256. return (error);
  257. }
  258. req_lib_cfg_ringstatusget.header.size = sizeof (struct req_lib_cfg_ringstatusget);
  259. req_lib_cfg_ringstatusget.header.id = MESSAGE_REQ_CFG_RINGSTATUSGET;
  260. iov.iov_base = (void *)&req_lib_cfg_ringstatusget,
  261. iov.iov_len = sizeof (struct req_lib_cfg_ringstatusget),
  262. error = qb_to_cs_error (qb_ipcc_sendv_recv(cfg_inst->c,
  263. &iov,
  264. 1,
  265. &res_lib_cfg_ringstatusget,
  266. sizeof (struct res_lib_cfg_ringstatusget), CS_IPC_TIMEOUT_MS));
  267. *interface_count = res_lib_cfg_ringstatusget.interface_count;
  268. *interface_names = malloc (sizeof (char *) * *interface_count);
  269. if (*interface_names == NULL) {
  270. return (CS_ERR_NO_MEMORY);
  271. }
  272. memset (*interface_names, 0, sizeof (char *) * *interface_count);
  273. *status = malloc (sizeof (char *) * *interface_count);
  274. if (*status == NULL) {
  275. error = CS_ERR_NO_MEMORY;
  276. goto error_free_interface_names_array;
  277. }
  278. memset (*status, 0, sizeof (char *) * *interface_count);
  279. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  280. (*(interface_names))[i] = strdup (res_lib_cfg_ringstatusget.interface_name[i]);
  281. if ((*(interface_names))[i] == NULL) {
  282. error = CS_ERR_NO_MEMORY;
  283. goto error_free_interface_names;
  284. }
  285. }
  286. for (i = 0; i < res_lib_cfg_ringstatusget.interface_count; i++) {
  287. (*(status))[i] = strdup (res_lib_cfg_ringstatusget.interface_status[i]);
  288. if ((*(status))[i] == NULL) {
  289. error = CS_ERR_NO_MEMORY;
  290. goto error_free_status;
  291. }
  292. }
  293. goto no_error;
  294. error_free_status:
  295. for (j = 0; j < i; j++) {
  296. free ((*(status))[j]);
  297. }
  298. i = *interface_count;
  299. error_free_interface_names:
  300. for (j = 0; j < i; j++) {
  301. free ((*(interface_names))[j]);
  302. }
  303. free (*status);
  304. error_free_interface_names_array:
  305. free (*interface_names);
  306. no_error:
  307. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  308. return (error);
  309. }
  310. cs_error_t
  311. corosync_cfg_ring_reenable (
  312. corosync_cfg_handle_t cfg_handle)
  313. {
  314. struct cfg_inst *cfg_inst;
  315. struct req_lib_cfg_ringreenable req_lib_cfg_ringreenable;
  316. struct res_lib_cfg_ringreenable res_lib_cfg_ringreenable;
  317. cs_error_t error;
  318. struct iovec iov;
  319. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle, (void *)&cfg_inst));
  320. if (error != CS_OK) {
  321. return (error);
  322. }
  323. req_lib_cfg_ringreenable.header.size = sizeof (struct req_lib_cfg_ringreenable);
  324. req_lib_cfg_ringreenable.header.id = MESSAGE_REQ_CFG_RINGREENABLE;
  325. iov.iov_base = (void *)&req_lib_cfg_ringreenable,
  326. iov.iov_len = sizeof (struct req_lib_cfg_ringreenable);
  327. error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c,
  328. &iov,
  329. 1,
  330. &res_lib_cfg_ringreenable,
  331. sizeof (struct res_lib_cfg_ringreenable), CS_IPC_TIMEOUT_MS));
  332. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  333. return (error);
  334. }
  335. cs_error_t
  336. corosync_cfg_kill_node (
  337. corosync_cfg_handle_t cfg_handle,
  338. unsigned int nodeid,
  339. const char *reason)
  340. {
  341. struct cfg_inst *cfg_inst;
  342. struct req_lib_cfg_killnode req_lib_cfg_killnode;
  343. struct res_lib_cfg_killnode res_lib_cfg_killnode;
  344. cs_error_t error;
  345. struct iovec iov;
  346. if (strlen(reason) >= CS_MAX_NAME_LENGTH)
  347. return CS_ERR_NAME_TOO_LONG;
  348. error = hdb_error_to_cs (hdb_handle_get (&cfg_hdb, cfg_handle,
  349. (void *)&cfg_inst));
  350. if (error != CS_OK) {
  351. return (error);
  352. }
  353. req_lib_cfg_killnode.header.id = MESSAGE_REQ_CFG_KILLNODE;
  354. req_lib_cfg_killnode.header.size = sizeof (struct req_lib_cfg_killnode);
  355. req_lib_cfg_killnode.nodeid = nodeid;
  356. strcpy((char *)req_lib_cfg_killnode.reason.value, reason);
  357. req_lib_cfg_killnode.reason.length = strlen(reason)+1;
  358. iov.iov_base = (void *)&req_lib_cfg_killnode;
  359. iov.iov_len = sizeof (struct req_lib_cfg_killnode);
  360. error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c,
  361. &iov,
  362. 1,
  363. &res_lib_cfg_killnode,
  364. sizeof (struct res_lib_cfg_killnode), CS_IPC_TIMEOUT_MS));
  365. error = res_lib_cfg_killnode.header.error;
  366. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  367. return (error == CS_OK ? res_lib_cfg_killnode.header.error : error);
  368. }
  369. cs_error_t
  370. corosync_cfg_try_shutdown (
  371. corosync_cfg_handle_t cfg_handle,
  372. corosync_cfg_shutdown_flags_t flags)
  373. {
  374. struct cfg_inst *cfg_inst;
  375. struct req_lib_cfg_tryshutdown req_lib_cfg_tryshutdown;
  376. struct res_lib_cfg_tryshutdown res_lib_cfg_tryshutdown;
  377. cs_error_t error;
  378. struct iovec iov;
  379. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle,
  380. (void *)&cfg_inst));
  381. if (error != CS_OK) {
  382. return (error);
  383. }
  384. req_lib_cfg_tryshutdown.header.id = MESSAGE_REQ_CFG_TRYSHUTDOWN;
  385. req_lib_cfg_tryshutdown.header.size = sizeof (struct req_lib_cfg_tryshutdown);
  386. req_lib_cfg_tryshutdown.flags = flags;
  387. iov.iov_base = (void *)&req_lib_cfg_tryshutdown;
  388. iov.iov_len = sizeof (req_lib_cfg_tryshutdown);
  389. error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c,
  390. &iov,
  391. 1,
  392. &res_lib_cfg_tryshutdown,
  393. sizeof (struct res_lib_cfg_tryshutdown), CS_IPC_TIMEOUT_MS));
  394. (void)hdb_handle_put (&cfg_hdb, cfg_handle);
  395. return (error == CS_OK ? res_lib_cfg_tryshutdown.header.error : error);
  396. }
  397. cs_error_t
  398. corosync_cfg_replyto_shutdown (
  399. corosync_cfg_handle_t cfg_handle,
  400. corosync_cfg_shutdown_reply_flags_t response)
  401. {
  402. struct cfg_inst *cfg_inst;
  403. struct req_lib_cfg_replytoshutdown req_lib_cfg_replytoshutdown;
  404. struct res_lib_cfg_replytoshutdown res_lib_cfg_replytoshutdown;
  405. struct iovec iov;
  406. cs_error_t error;
  407. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle,
  408. (void *)&cfg_inst));
  409. if (error != CS_OK) {
  410. return (error);
  411. }
  412. req_lib_cfg_replytoshutdown.header.id = MESSAGE_REQ_CFG_REPLYTOSHUTDOWN;
  413. req_lib_cfg_replytoshutdown.header.size = sizeof (struct req_lib_cfg_replytoshutdown);
  414. req_lib_cfg_replytoshutdown.response = response;
  415. iov.iov_base = (void *)&req_lib_cfg_replytoshutdown;
  416. iov.iov_len = sizeof (struct req_lib_cfg_replytoshutdown);
  417. error = qb_to_cs_error (qb_ipcc_sendv_recv (cfg_inst->c,
  418. &iov,
  419. 1,
  420. &res_lib_cfg_replytoshutdown,
  421. sizeof (struct res_lib_cfg_replytoshutdown), CS_IPC_TIMEOUT_MS));
  422. return (error);
  423. }
  424. cs_error_t corosync_cfg_get_node_addrs (
  425. corosync_cfg_handle_t cfg_handle,
  426. int nodeid,
  427. size_t max_addrs,
  428. int *num_addrs,
  429. corosync_cfg_node_address_t *addrs)
  430. {
  431. cs_error_t error;
  432. struct req_lib_cfg_get_node_addrs req_lib_cfg_get_node_addrs;
  433. struct res_lib_cfg_get_node_addrs *res_lib_cfg_get_node_addrs;
  434. struct cfg_inst *cfg_inst;
  435. int addrlen = 0;
  436. int i;
  437. struct iovec iov;
  438. const char *addr_buf;
  439. char response_buf[IPC_RESPONSE_SIZE];
  440. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, cfg_handle,
  441. (void *)&cfg_inst));
  442. if (error != CS_OK) {
  443. return (error);
  444. }
  445. req_lib_cfg_get_node_addrs.header.size = sizeof (req_lib_cfg_get_node_addrs);
  446. req_lib_cfg_get_node_addrs.header.id = MESSAGE_REQ_CFG_GET_NODE_ADDRS;
  447. req_lib_cfg_get_node_addrs.nodeid = nodeid;
  448. iov.iov_base = (char *)&req_lib_cfg_get_node_addrs;
  449. iov.iov_len = sizeof (req_lib_cfg_get_node_addrs);
  450. error = qb_to_cs_error (qb_ipcc_sendv_recv (
  451. cfg_inst->c,
  452. &iov, 1,
  453. response_buf, IPC_RESPONSE_SIZE, CS_IPC_TIMEOUT_MS));
  454. res_lib_cfg_get_node_addrs = (struct res_lib_cfg_get_node_addrs *)response_buf;
  455. if (error != CS_OK) {
  456. goto error_put;
  457. }
  458. if (res_lib_cfg_get_node_addrs->family == AF_INET)
  459. addrlen = sizeof(struct sockaddr_in);
  460. if (res_lib_cfg_get_node_addrs->family == AF_INET6)
  461. addrlen = sizeof(struct sockaddr_in6);
  462. for (i = 0, addr_buf = (char *)res_lib_cfg_get_node_addrs->addrs;
  463. i < max_addrs && i<res_lib_cfg_get_node_addrs->num_addrs;
  464. i++, addr_buf += TOTEMIP_ADDRLEN) {
  465. struct sockaddr_in *in;
  466. struct sockaddr_in6 *in6;
  467. addrs[i].address_length = addrlen;
  468. if (res_lib_cfg_get_node_addrs->family == AF_INET) {
  469. in = (struct sockaddr_in *)addrs[i].address;
  470. in->sin_family = AF_INET;
  471. memcpy(&in->sin_addr, addr_buf, sizeof(struct in_addr));
  472. }
  473. if (res_lib_cfg_get_node_addrs->family == AF_INET6) {
  474. in6 = (struct sockaddr_in6 *)addrs[i].address;
  475. in6->sin6_family = AF_INET6;
  476. memcpy(&in6->sin6_addr, addr_buf, sizeof(struct in6_addr));
  477. }
  478. }
  479. *num_addrs = res_lib_cfg_get_node_addrs->num_addrs;
  480. errno = error = res_lib_cfg_get_node_addrs->header.error;
  481. error_put:
  482. hdb_handle_put (&cfg_hdb, cfg_handle);
  483. return (error);
  484. }
  485. cs_error_t corosync_cfg_local_get (
  486. corosync_cfg_handle_t handle,
  487. unsigned int *local_nodeid)
  488. {
  489. cs_error_t error;
  490. struct cfg_inst *cfg_inst;
  491. struct iovec iov;
  492. struct req_lib_cfg_local_get req_lib_cfg_local_get;
  493. struct res_lib_cfg_local_get res_lib_cfg_local_get;
  494. error = hdb_error_to_cs(hdb_handle_get (&cfg_hdb, handle, (void *)&cfg_inst));
  495. if (error != CS_OK) {
  496. return (error);
  497. }
  498. req_lib_cfg_local_get.header.size = sizeof (struct qb_ipc_request_header);
  499. req_lib_cfg_local_get.header.id = MESSAGE_REQ_CFG_LOCAL_GET;
  500. iov.iov_base = (void *)&req_lib_cfg_local_get;
  501. iov.iov_len = sizeof (struct req_lib_cfg_local_get);
  502. error = qb_to_cs_error (qb_ipcc_sendv_recv (
  503. cfg_inst->c,
  504. &iov,
  505. 1,
  506. &res_lib_cfg_local_get,
  507. sizeof (struct res_lib_cfg_local_get), CS_IPC_TIMEOUT_MS));
  508. if (error != CS_OK) {
  509. goto error_exit;
  510. }
  511. error = res_lib_cfg_local_get.header.error;
  512. *local_nodeid = res_lib_cfg_local_get.local_nodeid;
  513. error_exit:
  514. (void)hdb_handle_put (&cfg_hdb, handle);
  515. return (error);
  516. }