cfg.c 22 KB

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