votequorum.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. * Copyright (c) 2009-2012 Red Hat, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Christine Caulfield (ccaulfie@redhat.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. /*
  35. * Provides a quorum API using the corosync executive
  36. */
  37. #include <config.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <unistd.h>
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #include <errno.h>
  44. #include <qb/qbdefs.h>
  45. #include <qb/qbipcc.h>
  46. #include <corosync/corotypes.h>
  47. #include <corosync/corodefs.h>
  48. #include <corosync/hdb.h>
  49. #include <corosync/votequorum.h>
  50. #include <corosync/ipc_votequorum.h>
  51. #include "util.h"
  52. struct votequorum_inst {
  53. qb_ipcc_connection_t *c;
  54. int finalize;
  55. void *context;
  56. votequorum_callbacks_t callbacks;
  57. };
  58. DECLARE_HDB_DATABASE(votequorum_handle_t_db,NULL);
  59. cs_error_t votequorum_initialize (
  60. votequorum_handle_t *handle,
  61. votequorum_callbacks_t *callbacks)
  62. {
  63. cs_error_t error;
  64. struct votequorum_inst *votequorum_inst;
  65. error = hdb_error_to_cs(hdb_handle_create (&votequorum_handle_t_db, sizeof (struct votequorum_inst), handle));
  66. if (error != CS_OK) {
  67. goto error_no_destroy;
  68. }
  69. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, *handle, (void *)&votequorum_inst));
  70. if (error != CS_OK) {
  71. goto error_destroy;
  72. }
  73. votequorum_inst->c = qb_ipcc_connect ("votequorum", IPC_REQUEST_SIZE);
  74. if (votequorum_inst->c == NULL) {
  75. error = qb_to_cs_error(-errno);
  76. goto error_put_destroy;
  77. }
  78. if (callbacks)
  79. memcpy(&votequorum_inst->callbacks, callbacks, sizeof (*callbacks));
  80. else
  81. memset(&votequorum_inst->callbacks, 0, sizeof (*callbacks));
  82. hdb_handle_put (&votequorum_handle_t_db, *handle);
  83. return (CS_OK);
  84. error_put_destroy:
  85. hdb_handle_put (&votequorum_handle_t_db, *handle);
  86. error_destroy:
  87. hdb_handle_destroy (&votequorum_handle_t_db, *handle);
  88. error_no_destroy:
  89. return (error);
  90. }
  91. cs_error_t votequorum_finalize (
  92. votequorum_handle_t handle)
  93. {
  94. struct votequorum_inst *votequorum_inst;
  95. cs_error_t error;
  96. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  97. if (error != CS_OK) {
  98. return (error);
  99. }
  100. /*
  101. * Another thread has already started finalizing
  102. */
  103. if (votequorum_inst->finalize) {
  104. hdb_handle_put (&votequorum_handle_t_db, handle);
  105. return (CS_ERR_BAD_HANDLE);
  106. }
  107. votequorum_inst->finalize = 1;
  108. qb_ipcc_disconnect (votequorum_inst->c);
  109. hdb_handle_destroy (&votequorum_handle_t_db, handle);
  110. hdb_handle_put (&votequorum_handle_t_db, handle);
  111. return (CS_OK);
  112. }
  113. cs_error_t votequorum_getinfo (
  114. votequorum_handle_t handle,
  115. unsigned int nodeid,
  116. struct votequorum_info *info)
  117. {
  118. cs_error_t error;
  119. struct votequorum_inst *votequorum_inst;
  120. struct iovec iov;
  121. struct req_lib_votequorum_getinfo req_lib_votequorum_getinfo;
  122. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  123. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  124. if (error != CS_OK) {
  125. return (error);
  126. }
  127. req_lib_votequorum_getinfo.header.size = sizeof (struct req_lib_votequorum_getinfo);
  128. req_lib_votequorum_getinfo.header.id = MESSAGE_REQ_VOTEQUORUM_GETINFO;
  129. req_lib_votequorum_getinfo.nodeid = nodeid;
  130. iov.iov_base = (char *)&req_lib_votequorum_getinfo;
  131. iov.iov_len = sizeof (struct req_lib_votequorum_getinfo);
  132. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  133. votequorum_inst->c,
  134. &iov,
  135. 1,
  136. &res_lib_votequorum_getinfo,
  137. sizeof (struct res_lib_votequorum_getinfo), CS_IPC_TIMEOUT_MS));
  138. if (error != CS_OK) {
  139. goto error_exit;
  140. }
  141. error = res_lib_votequorum_getinfo.header.error;
  142. info->node_id = res_lib_votequorum_getinfo.nodeid;
  143. info->node_state = res_lib_votequorum_getinfo.state;
  144. info->node_votes = res_lib_votequorum_getinfo.votes;
  145. info->node_expected_votes = res_lib_votequorum_getinfo.expected_votes;
  146. info->highest_expected = res_lib_votequorum_getinfo.highest_expected;
  147. info->total_votes = res_lib_votequorum_getinfo.total_votes;
  148. info->quorum = res_lib_votequorum_getinfo.quorum;
  149. info->flags = res_lib_votequorum_getinfo.flags;
  150. error_exit:
  151. hdb_handle_put (&votequorum_handle_t_db, handle);
  152. return (error);
  153. }
  154. cs_error_t votequorum_setexpected (
  155. votequorum_handle_t handle,
  156. unsigned int expected_votes)
  157. {
  158. cs_error_t error;
  159. struct votequorum_inst *votequorum_inst;
  160. struct iovec iov;
  161. struct req_lib_votequorum_setexpected req_lib_votequorum_setexpected;
  162. struct res_lib_votequorum_status res_lib_votequorum_status;
  163. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  164. if (error != CS_OK) {
  165. return (error);
  166. }
  167. req_lib_votequorum_setexpected.header.size = sizeof (struct req_lib_votequorum_setexpected);
  168. req_lib_votequorum_setexpected.header.id = MESSAGE_REQ_VOTEQUORUM_SETEXPECTED;
  169. req_lib_votequorum_setexpected.expected_votes = expected_votes;
  170. iov.iov_base = (char *)&req_lib_votequorum_setexpected;
  171. iov.iov_len = sizeof (struct req_lib_votequorum_setexpected);
  172. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  173. votequorum_inst->c,
  174. &iov,
  175. 1,
  176. &res_lib_votequorum_status,
  177. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  178. if (error != CS_OK) {
  179. goto error_exit;
  180. }
  181. error = res_lib_votequorum_status.header.error;
  182. error_exit:
  183. hdb_handle_put (&votequorum_handle_t_db, handle);
  184. return (error);
  185. }
  186. cs_error_t votequorum_setvotes (
  187. votequorum_handle_t handle,
  188. unsigned int nodeid,
  189. unsigned int votes)
  190. {
  191. cs_error_t error;
  192. struct votequorum_inst *votequorum_inst;
  193. struct iovec iov;
  194. struct req_lib_votequorum_setvotes req_lib_votequorum_setvotes;
  195. struct res_lib_votequorum_status res_lib_votequorum_status;
  196. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  197. if (error != CS_OK) {
  198. return (error);
  199. }
  200. req_lib_votequorum_setvotes.header.size = sizeof (struct req_lib_votequorum_setvotes);
  201. req_lib_votequorum_setvotes.header.id = MESSAGE_REQ_VOTEQUORUM_SETVOTES;
  202. req_lib_votequorum_setvotes.nodeid = nodeid;
  203. req_lib_votequorum_setvotes.votes = votes;
  204. iov.iov_base = (char *)&req_lib_votequorum_setvotes;
  205. iov.iov_len = sizeof (struct req_lib_votequorum_setvotes);
  206. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  207. votequorum_inst->c,
  208. &iov,
  209. 1,
  210. &res_lib_votequorum_status,
  211. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  212. if (error != CS_OK) {
  213. goto error_exit;
  214. }
  215. error = res_lib_votequorum_status.header.error;
  216. error_exit:
  217. hdb_handle_put (&votequorum_handle_t_db, handle);
  218. return (error);
  219. }
  220. cs_error_t votequorum_trackstart (
  221. votequorum_handle_t handle,
  222. uint64_t context,
  223. unsigned int flags)
  224. {
  225. cs_error_t error;
  226. struct votequorum_inst *votequorum_inst;
  227. struct iovec iov;
  228. struct req_lib_votequorum_trackstart req_lib_votequorum_trackstart;
  229. struct res_lib_votequorum_status res_lib_votequorum_status;
  230. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  231. if (error != CS_OK) {
  232. return (error);
  233. }
  234. req_lib_votequorum_trackstart.header.size = sizeof (struct req_lib_votequorum_trackstart);
  235. req_lib_votequorum_trackstart.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTART;
  236. req_lib_votequorum_trackstart.track_flags = flags;
  237. req_lib_votequorum_trackstart.context = context;
  238. iov.iov_base = (char *)&req_lib_votequorum_trackstart;
  239. iov.iov_len = sizeof (struct req_lib_votequorum_trackstart);
  240. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  241. votequorum_inst->c,
  242. &iov,
  243. 1,
  244. &res_lib_votequorum_status,
  245. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  246. if (error != CS_OK) {
  247. goto error_exit;
  248. }
  249. error = res_lib_votequorum_status.header.error;
  250. error_exit:
  251. hdb_handle_put (&votequorum_handle_t_db, handle);
  252. return (error);
  253. }
  254. cs_error_t votequorum_trackstop (
  255. votequorum_handle_t handle)
  256. {
  257. cs_error_t error;
  258. struct votequorum_inst *votequorum_inst;
  259. struct iovec iov;
  260. struct req_lib_votequorum_general req_lib_votequorum_general;
  261. struct res_lib_votequorum_status res_lib_votequorum_status;
  262. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  263. if (error != CS_OK) {
  264. return (error);
  265. }
  266. req_lib_votequorum_general.header.size = sizeof (struct req_lib_votequorum_general);
  267. req_lib_votequorum_general.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTOP;
  268. iov.iov_base = (char *)&req_lib_votequorum_general;
  269. iov.iov_len = sizeof (struct req_lib_votequorum_general);
  270. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  271. votequorum_inst->c,
  272. &iov,
  273. 1,
  274. &res_lib_votequorum_status,
  275. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  276. if (error != CS_OK) {
  277. goto error_exit;
  278. }
  279. error = res_lib_votequorum_status.header.error;
  280. error_exit:
  281. hdb_handle_put (&votequorum_handle_t_db, handle);
  282. return (error);
  283. }
  284. cs_error_t votequorum_context_get (
  285. votequorum_handle_t handle,
  286. void **context)
  287. {
  288. cs_error_t error;
  289. struct votequorum_inst *votequorum_inst;
  290. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  291. if (error != CS_OK) {
  292. return (error);
  293. }
  294. *context = votequorum_inst->context;
  295. hdb_handle_put (&votequorum_handle_t_db, handle);
  296. return (CS_OK);
  297. }
  298. cs_error_t votequorum_context_set (
  299. votequorum_handle_t handle,
  300. void *context)
  301. {
  302. cs_error_t error;
  303. struct votequorum_inst *votequorum_inst;
  304. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  305. if (error != CS_OK) {
  306. return (error);
  307. }
  308. votequorum_inst->context = context;
  309. hdb_handle_put (&votequorum_handle_t_db, handle);
  310. return (CS_OK);
  311. }
  312. cs_error_t votequorum_fd_get (
  313. votequorum_handle_t handle,
  314. int *fd)
  315. {
  316. cs_error_t error;
  317. struct votequorum_inst *votequorum_inst;
  318. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  319. if (error != CS_OK) {
  320. return (error);
  321. }
  322. error = qb_to_cs_error(qb_ipcc_fd_get (votequorum_inst->c, fd));
  323. (void)hdb_handle_put (&votequorum_handle_t_db, handle);
  324. return (error);
  325. }
  326. cs_error_t votequorum_dispatch (
  327. votequorum_handle_t handle,
  328. cs_dispatch_flags_t dispatch_types)
  329. {
  330. int timeout = -1;
  331. cs_error_t error;
  332. int cont = 1; /* always continue do loop except when set to 0 */
  333. struct votequorum_inst *votequorum_inst;
  334. votequorum_callbacks_t callbacks;
  335. struct qb_ipc_response_header *dispatch_data;
  336. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  337. struct res_lib_votequorum_expectedvotes_notification *res_lib_votequorum_expectedvotes_notification;
  338. char dispatch_buf[IPC_DISPATCH_SIZE];
  339. if (dispatch_types != CS_DISPATCH_ONE &&
  340. dispatch_types != CS_DISPATCH_ALL &&
  341. dispatch_types != CS_DISPATCH_BLOCKING &&
  342. dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) {
  343. return (CS_ERR_INVALID_PARAM);
  344. }
  345. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
  346. (void *)&votequorum_inst));
  347. if (error != CS_OK) {
  348. return (error);
  349. }
  350. /*
  351. * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
  352. * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
  353. */
  354. if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  355. timeout = 0;
  356. }
  357. dispatch_data = (struct qb_ipc_response_header *)dispatch_buf;
  358. do {
  359. error = qb_to_cs_error (qb_ipcc_event_recv (
  360. votequorum_inst->c,
  361. dispatch_buf,
  362. IPC_DISPATCH_SIZE,
  363. timeout));
  364. if (error == CS_ERR_BAD_HANDLE) {
  365. error = CS_OK;
  366. goto error_put;
  367. }
  368. if (error == CS_ERR_TRY_AGAIN) {
  369. if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  370. /*
  371. * Don't mask error
  372. */
  373. goto error_put;
  374. }
  375. error = CS_OK;
  376. if (dispatch_types == CS_DISPATCH_ALL) {
  377. break; /* exit do while cont is 1 loop */
  378. } else {
  379. continue; /* next poll */
  380. }
  381. }
  382. if (error != CS_OK) {
  383. goto error_put;
  384. }
  385. /*
  386. * Make copy of callbacks, message data, unlock instance, and call callback
  387. * A risk of this dispatch method is that the callback routines may
  388. * operate at the same time that votequorum_finalize has been called in another thread.
  389. */
  390. memcpy (&callbacks, &votequorum_inst->callbacks, sizeof (votequorum_callbacks_t));
  391. /*
  392. * Dispatch incoming message
  393. */
  394. switch (dispatch_data->id) {
  395. case MESSAGE_RES_VOTEQUORUM_NOTIFICATION:
  396. if (callbacks.votequorum_notify_fn == NULL) {
  397. break;
  398. }
  399. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)dispatch_data;
  400. callbacks.votequorum_notify_fn ( handle,
  401. res_lib_votequorum_notification->context,
  402. res_lib_votequorum_notification->quorate,
  403. res_lib_votequorum_notification->node_list_entries,
  404. (votequorum_node_t *)res_lib_votequorum_notification->node_list );
  405. ;
  406. break;
  407. case MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION:
  408. if (callbacks.votequorum_expectedvotes_notify_fn == NULL) {
  409. break;
  410. }
  411. res_lib_votequorum_expectedvotes_notification = (struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
  412. callbacks.votequorum_expectedvotes_notify_fn ( handle,
  413. res_lib_votequorum_expectedvotes_notification->context,
  414. res_lib_votequorum_expectedvotes_notification->expected_votes);
  415. break;
  416. default:
  417. error = CS_ERR_LIBRARY;
  418. goto error_put;
  419. break;
  420. }
  421. /*
  422. * Determine if more messages should be processed
  423. */
  424. if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  425. cont = 0;
  426. }
  427. } while (cont);
  428. goto error_put;
  429. error_put:
  430. hdb_handle_put (&votequorum_handle_t_db, handle);
  431. return (error);
  432. }
  433. #ifdef EXPERIMENTAL_QUORUM_DEVICE_API
  434. cs_error_t votequorum_qdevice_register (
  435. votequorum_handle_t handle,
  436. const char *name)
  437. {
  438. cs_error_t error;
  439. struct votequorum_inst *votequorum_inst;
  440. struct iovec iov;
  441. struct req_lib_votequorum_qdevice_register req_lib_votequorum_qdevice_register;
  442. struct res_lib_votequorum_status res_lib_votequorum_status;
  443. if (strlen(name) >= VOTEQUORUM_MAX_QDEVICE_NAME_LEN) {
  444. return CS_ERR_INVALID_PARAM;
  445. }
  446. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  447. if (error != CS_OK) {
  448. return (error);
  449. }
  450. req_lib_votequorum_qdevice_register.header.size = sizeof (struct req_lib_votequorum_qdevice_register);
  451. req_lib_votequorum_qdevice_register.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_REGISTER;
  452. strcpy(req_lib_votequorum_qdevice_register.name, name);
  453. iov.iov_base = (char *)&req_lib_votequorum_qdevice_register;
  454. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_register);
  455. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  456. votequorum_inst->c,
  457. &iov,
  458. 1,
  459. &res_lib_votequorum_status,
  460. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  461. if (error != CS_OK) {
  462. goto error_exit;
  463. }
  464. error = res_lib_votequorum_status.header.error;
  465. error_exit:
  466. hdb_handle_put (&votequorum_handle_t_db, handle);
  467. return (error);
  468. }
  469. cs_error_t votequorum_qdevice_poll (
  470. votequorum_handle_t handle,
  471. const char *name,
  472. unsigned int state)
  473. {
  474. cs_error_t error;
  475. struct votequorum_inst *votequorum_inst;
  476. struct iovec iov;
  477. struct req_lib_votequorum_qdevice_poll req_lib_votequorum_qdevice_poll;
  478. struct res_lib_votequorum_status res_lib_votequorum_status;
  479. if (strlen(name) >= VOTEQUORUM_MAX_QDEVICE_NAME_LEN) {
  480. return CS_ERR_INVALID_PARAM;
  481. }
  482. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  483. if (error != CS_OK) {
  484. return (error);
  485. }
  486. req_lib_votequorum_qdevice_poll.header.size = sizeof (struct req_lib_votequorum_qdevice_poll);
  487. req_lib_votequorum_qdevice_poll.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_POLL;
  488. strcpy(req_lib_votequorum_qdevice_poll.name, name);
  489. req_lib_votequorum_qdevice_poll.state = state;
  490. iov.iov_base = (char *)&req_lib_votequorum_qdevice_poll;
  491. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_poll);
  492. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  493. votequorum_inst->c,
  494. &iov,
  495. 1,
  496. &res_lib_votequorum_status,
  497. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  498. if (error != CS_OK) {
  499. goto error_exit;
  500. }
  501. error = res_lib_votequorum_status.header.error;
  502. error_exit:
  503. hdb_handle_put (&votequorum_handle_t_db, handle);
  504. return (error);
  505. }
  506. cs_error_t votequorum_qdevice_unregister (
  507. votequorum_handle_t handle,
  508. const char *name)
  509. {
  510. cs_error_t error;
  511. struct votequorum_inst *votequorum_inst;
  512. struct iovec iov;
  513. struct req_lib_votequorum_qdevice_unregister req_lib_votequorum_qdevice_unregister;
  514. struct res_lib_votequorum_status res_lib_votequorum_status;
  515. if (strlen(name) >= VOTEQUORUM_MAX_QDEVICE_NAME_LEN) {
  516. return CS_ERR_INVALID_PARAM;
  517. }
  518. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  519. if (error != CS_OK) {
  520. return (error);
  521. }
  522. req_lib_votequorum_qdevice_unregister.header.size = sizeof (struct req_lib_votequorum_qdevice_unregister);
  523. req_lib_votequorum_qdevice_unregister.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UNREGISTER;
  524. strcpy(req_lib_votequorum_qdevice_unregister.name, name);
  525. iov.iov_base = (char *)&req_lib_votequorum_qdevice_unregister;
  526. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_unregister);
  527. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  528. votequorum_inst->c,
  529. &iov,
  530. 1,
  531. &res_lib_votequorum_status,
  532. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  533. if (error != CS_OK) {
  534. goto error_exit;
  535. }
  536. error = res_lib_votequorum_status.header.error;
  537. error_exit:
  538. hdb_handle_put (&votequorum_handle_t_db, handle);
  539. return (error);
  540. }
  541. cs_error_t votequorum_qdevice_getinfo (
  542. votequorum_handle_t handle,
  543. unsigned int nodeid,
  544. struct votequorum_qdevice_info *qinfo)
  545. {
  546. cs_error_t error;
  547. struct votequorum_inst *votequorum_inst;
  548. struct iovec iov;
  549. struct req_lib_votequorum_qdevice_getinfo req_lib_votequorum_qdevice_getinfo;
  550. struct res_lib_votequorum_qdevice_getinfo res_lib_votequorum_qdevice_getinfo;
  551. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  552. if (error != CS_OK) {
  553. return (error);
  554. }
  555. req_lib_votequorum_qdevice_getinfo.header.size = sizeof (struct req_lib_votequorum_qdevice_getinfo);
  556. req_lib_votequorum_qdevice_getinfo.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_GETINFO;
  557. req_lib_votequorum_qdevice_getinfo.nodeid = nodeid;
  558. iov.iov_base = (char *)&req_lib_votequorum_qdevice_getinfo;
  559. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_getinfo);
  560. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  561. votequorum_inst->c,
  562. &iov,
  563. 1,
  564. &res_lib_votequorum_qdevice_getinfo,
  565. sizeof (struct res_lib_votequorum_qdevice_getinfo), CS_IPC_TIMEOUT_MS));
  566. if (error != CS_OK) {
  567. goto error_exit;
  568. }
  569. error = res_lib_votequorum_qdevice_getinfo.header.error;
  570. qinfo->votes = res_lib_votequorum_qdevice_getinfo.votes;
  571. qinfo->state = res_lib_votequorum_qdevice_getinfo.state;
  572. strcpy(qinfo->name, res_lib_votequorum_qdevice_getinfo.name);
  573. error_exit:
  574. hdb_handle_put (&votequorum_handle_t_db, handle);
  575. return (error);
  576. }
  577. #endif