votequorum.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  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. static void votequorum_inst_free (void *inst);
  59. DECLARE_HDB_DATABASE(votequorum_handle_t_db, votequorum_inst_free);
  60. cs_error_t votequorum_initialize (
  61. votequorum_handle_t *handle,
  62. votequorum_callbacks_t *callbacks)
  63. {
  64. cs_error_t error;
  65. struct votequorum_inst *votequorum_inst;
  66. error = hdb_error_to_cs(hdb_handle_create (&votequorum_handle_t_db, sizeof (struct votequorum_inst), handle));
  67. if (error != CS_OK) {
  68. goto error_no_destroy;
  69. }
  70. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, *handle, (void *)&votequorum_inst));
  71. if (error != CS_OK) {
  72. goto error_destroy;
  73. }
  74. votequorum_inst->finalize = 0;
  75. votequorum_inst->c = qb_ipcc_connect ("votequorum", IPC_REQUEST_SIZE);
  76. if (votequorum_inst->c == NULL) {
  77. error = qb_to_cs_error(-errno);
  78. goto error_put_destroy;
  79. }
  80. if (callbacks)
  81. memcpy(&votequorum_inst->callbacks, callbacks, sizeof (*callbacks));
  82. else
  83. memset(&votequorum_inst->callbacks, 0, sizeof (*callbacks));
  84. hdb_handle_put (&votequorum_handle_t_db, *handle);
  85. return (CS_OK);
  86. error_put_destroy:
  87. hdb_handle_put (&votequorum_handle_t_db, *handle);
  88. error_destroy:
  89. hdb_handle_destroy (&votequorum_handle_t_db, *handle);
  90. error_no_destroy:
  91. return (error);
  92. }
  93. static void votequorum_inst_free (void *inst)
  94. {
  95. struct votequorum_inst *vq_inst = (struct votequorum_inst *)inst;
  96. qb_ipcc_disconnect(vq_inst->c);
  97. }
  98. cs_error_t votequorum_finalize (
  99. votequorum_handle_t handle)
  100. {
  101. struct votequorum_inst *votequorum_inst;
  102. cs_error_t error;
  103. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  104. if (error != CS_OK) {
  105. return (error);
  106. }
  107. /*
  108. * Another thread has already started finalizing
  109. */
  110. if (votequorum_inst->finalize) {
  111. hdb_handle_put (&votequorum_handle_t_db, handle);
  112. return (CS_ERR_BAD_HANDLE);
  113. }
  114. votequorum_inst->finalize = 1;
  115. hdb_handle_destroy (&votequorum_handle_t_db, handle);
  116. hdb_handle_put (&votequorum_handle_t_db, handle);
  117. return (CS_OK);
  118. }
  119. cs_error_t votequorum_getinfo (
  120. votequorum_handle_t handle,
  121. unsigned int nodeid,
  122. struct votequorum_info *info)
  123. {
  124. cs_error_t error;
  125. struct votequorum_inst *votequorum_inst;
  126. struct iovec iov;
  127. struct req_lib_votequorum_getinfo req_lib_votequorum_getinfo;
  128. struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
  129. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  130. if (error != CS_OK) {
  131. return (error);
  132. }
  133. req_lib_votequorum_getinfo.header.size = sizeof (struct req_lib_votequorum_getinfo);
  134. req_lib_votequorum_getinfo.header.id = MESSAGE_REQ_VOTEQUORUM_GETINFO;
  135. req_lib_votequorum_getinfo.nodeid = nodeid;
  136. iov.iov_base = (char *)&req_lib_votequorum_getinfo;
  137. iov.iov_len = sizeof (struct req_lib_votequorum_getinfo);
  138. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  139. votequorum_inst->c,
  140. &iov,
  141. 1,
  142. &res_lib_votequorum_getinfo,
  143. sizeof (struct res_lib_votequorum_getinfo), CS_IPC_TIMEOUT_MS));
  144. if (error != CS_OK) {
  145. goto error_exit;
  146. }
  147. error = res_lib_votequorum_getinfo.header.error;
  148. info->node_id = res_lib_votequorum_getinfo.nodeid;
  149. info->node_state = res_lib_votequorum_getinfo.state;
  150. info->node_votes = res_lib_votequorum_getinfo.votes;
  151. info->node_expected_votes = res_lib_votequorum_getinfo.expected_votes;
  152. info->highest_expected = res_lib_votequorum_getinfo.highest_expected;
  153. info->total_votes = res_lib_votequorum_getinfo.total_votes;
  154. info->quorum = res_lib_votequorum_getinfo.quorum;
  155. info->flags = res_lib_votequorum_getinfo.flags;
  156. error_exit:
  157. hdb_handle_put (&votequorum_handle_t_db, handle);
  158. return (error);
  159. }
  160. cs_error_t votequorum_setexpected (
  161. votequorum_handle_t handle,
  162. unsigned int expected_votes)
  163. {
  164. cs_error_t error;
  165. struct votequorum_inst *votequorum_inst;
  166. struct iovec iov;
  167. struct req_lib_votequorum_setexpected req_lib_votequorum_setexpected;
  168. struct res_lib_votequorum_status res_lib_votequorum_status;
  169. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  170. if (error != CS_OK) {
  171. return (error);
  172. }
  173. req_lib_votequorum_setexpected.header.size = sizeof (struct req_lib_votequorum_setexpected);
  174. req_lib_votequorum_setexpected.header.id = MESSAGE_REQ_VOTEQUORUM_SETEXPECTED;
  175. req_lib_votequorum_setexpected.expected_votes = expected_votes;
  176. iov.iov_base = (char *)&req_lib_votequorum_setexpected;
  177. iov.iov_len = sizeof (struct req_lib_votequorum_setexpected);
  178. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  179. votequorum_inst->c,
  180. &iov,
  181. 1,
  182. &res_lib_votequorum_status,
  183. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  184. if (error != CS_OK) {
  185. goto error_exit;
  186. }
  187. error = res_lib_votequorum_status.header.error;
  188. error_exit:
  189. hdb_handle_put (&votequorum_handle_t_db, handle);
  190. return (error);
  191. }
  192. cs_error_t votequorum_setvotes (
  193. votequorum_handle_t handle,
  194. unsigned int nodeid,
  195. unsigned int votes)
  196. {
  197. cs_error_t error;
  198. struct votequorum_inst *votequorum_inst;
  199. struct iovec iov;
  200. struct req_lib_votequorum_setvotes req_lib_votequorum_setvotes;
  201. struct res_lib_votequorum_status res_lib_votequorum_status;
  202. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  203. if (error != CS_OK) {
  204. return (error);
  205. }
  206. req_lib_votequorum_setvotes.header.size = sizeof (struct req_lib_votequorum_setvotes);
  207. req_lib_votequorum_setvotes.header.id = MESSAGE_REQ_VOTEQUORUM_SETVOTES;
  208. req_lib_votequorum_setvotes.nodeid = nodeid;
  209. req_lib_votequorum_setvotes.votes = votes;
  210. iov.iov_base = (char *)&req_lib_votequorum_setvotes;
  211. iov.iov_len = sizeof (struct req_lib_votequorum_setvotes);
  212. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  213. votequorum_inst->c,
  214. &iov,
  215. 1,
  216. &res_lib_votequorum_status,
  217. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  218. if (error != CS_OK) {
  219. goto error_exit;
  220. }
  221. error = res_lib_votequorum_status.header.error;
  222. error_exit:
  223. hdb_handle_put (&votequorum_handle_t_db, handle);
  224. return (error);
  225. }
  226. cs_error_t votequorum_trackstart (
  227. votequorum_handle_t handle,
  228. uint64_t context,
  229. unsigned int flags)
  230. {
  231. cs_error_t error;
  232. struct votequorum_inst *votequorum_inst;
  233. struct iovec iov;
  234. struct req_lib_votequorum_trackstart req_lib_votequorum_trackstart;
  235. struct res_lib_votequorum_status res_lib_votequorum_status;
  236. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  237. if (error != CS_OK) {
  238. return (error);
  239. }
  240. req_lib_votequorum_trackstart.header.size = sizeof (struct req_lib_votequorum_trackstart);
  241. req_lib_votequorum_trackstart.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTART;
  242. req_lib_votequorum_trackstart.track_flags = flags;
  243. req_lib_votequorum_trackstart.context = context;
  244. iov.iov_base = (char *)&req_lib_votequorum_trackstart;
  245. iov.iov_len = sizeof (struct req_lib_votequorum_trackstart);
  246. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  247. votequorum_inst->c,
  248. &iov,
  249. 1,
  250. &res_lib_votequorum_status,
  251. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  252. if (error != CS_OK) {
  253. goto error_exit;
  254. }
  255. error = res_lib_votequorum_status.header.error;
  256. error_exit:
  257. hdb_handle_put (&votequorum_handle_t_db, handle);
  258. return (error);
  259. }
  260. cs_error_t votequorum_trackstop (
  261. votequorum_handle_t handle)
  262. {
  263. cs_error_t error;
  264. struct votequorum_inst *votequorum_inst;
  265. struct iovec iov;
  266. struct req_lib_votequorum_general req_lib_votequorum_general;
  267. struct res_lib_votequorum_status res_lib_votequorum_status;
  268. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  269. if (error != CS_OK) {
  270. return (error);
  271. }
  272. req_lib_votequorum_general.header.size = sizeof (struct req_lib_votequorum_general);
  273. req_lib_votequorum_general.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTOP;
  274. iov.iov_base = (char *)&req_lib_votequorum_general;
  275. iov.iov_len = sizeof (struct req_lib_votequorum_general);
  276. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  277. votequorum_inst->c,
  278. &iov,
  279. 1,
  280. &res_lib_votequorum_status,
  281. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  282. if (error != CS_OK) {
  283. goto error_exit;
  284. }
  285. error = res_lib_votequorum_status.header.error;
  286. error_exit:
  287. hdb_handle_put (&votequorum_handle_t_db, handle);
  288. return (error);
  289. }
  290. cs_error_t votequorum_context_get (
  291. votequorum_handle_t handle,
  292. void **context)
  293. {
  294. cs_error_t error;
  295. struct votequorum_inst *votequorum_inst;
  296. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  297. if (error != CS_OK) {
  298. return (error);
  299. }
  300. *context = votequorum_inst->context;
  301. hdb_handle_put (&votequorum_handle_t_db, handle);
  302. return (CS_OK);
  303. }
  304. cs_error_t votequorum_context_set (
  305. votequorum_handle_t handle,
  306. void *context)
  307. {
  308. cs_error_t error;
  309. struct votequorum_inst *votequorum_inst;
  310. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  311. if (error != CS_OK) {
  312. return (error);
  313. }
  314. votequorum_inst->context = context;
  315. hdb_handle_put (&votequorum_handle_t_db, handle);
  316. return (CS_OK);
  317. }
  318. cs_error_t votequorum_fd_get (
  319. votequorum_handle_t handle,
  320. int *fd)
  321. {
  322. cs_error_t error;
  323. struct votequorum_inst *votequorum_inst;
  324. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  325. if (error != CS_OK) {
  326. return (error);
  327. }
  328. error = qb_to_cs_error(qb_ipcc_fd_get (votequorum_inst->c, fd));
  329. (void)hdb_handle_put (&votequorum_handle_t_db, handle);
  330. return (error);
  331. }
  332. cs_error_t votequorum_dispatch (
  333. votequorum_handle_t handle,
  334. cs_dispatch_flags_t dispatch_types)
  335. {
  336. int timeout = -1;
  337. cs_error_t error;
  338. int cont = 1; /* always continue do loop except when set to 0 */
  339. struct votequorum_inst *votequorum_inst;
  340. votequorum_callbacks_t callbacks;
  341. struct qb_ipc_response_header *dispatch_data;
  342. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  343. struct res_lib_votequorum_expectedvotes_notification *res_lib_votequorum_expectedvotes_notification;
  344. char dispatch_buf[IPC_DISPATCH_SIZE];
  345. if (dispatch_types != CS_DISPATCH_ONE &&
  346. dispatch_types != CS_DISPATCH_ALL &&
  347. dispatch_types != CS_DISPATCH_BLOCKING &&
  348. dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) {
  349. return (CS_ERR_INVALID_PARAM);
  350. }
  351. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
  352. (void *)&votequorum_inst));
  353. if (error != CS_OK) {
  354. return (error);
  355. }
  356. /*
  357. * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
  358. * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
  359. */
  360. if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  361. timeout = 0;
  362. }
  363. dispatch_data = (struct qb_ipc_response_header *)dispatch_buf;
  364. do {
  365. error = qb_to_cs_error (qb_ipcc_event_recv (
  366. votequorum_inst->c,
  367. dispatch_buf,
  368. IPC_DISPATCH_SIZE,
  369. timeout));
  370. if (error == CS_ERR_BAD_HANDLE) {
  371. error = CS_OK;
  372. goto error_put;
  373. }
  374. if (error == CS_ERR_TRY_AGAIN) {
  375. if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  376. /*
  377. * Don't mask error
  378. */
  379. goto error_put;
  380. }
  381. error = CS_OK;
  382. if (dispatch_types == CS_DISPATCH_ALL) {
  383. break; /* exit do while cont is 1 loop */
  384. } else {
  385. continue; /* next poll */
  386. }
  387. }
  388. if (error != CS_OK) {
  389. goto error_put;
  390. }
  391. /*
  392. * Make copy of callbacks, message data, unlock instance, and call callback
  393. * A risk of this dispatch method is that the callback routines may
  394. * operate at the same time that votequorum_finalize has been called in another thread.
  395. */
  396. memcpy (&callbacks, &votequorum_inst->callbacks, sizeof (votequorum_callbacks_t));
  397. /*
  398. * Dispatch incoming message
  399. */
  400. switch (dispatch_data->id) {
  401. case MESSAGE_RES_VOTEQUORUM_NOTIFICATION:
  402. if (callbacks.votequorum_notify_fn == NULL) {
  403. break;
  404. }
  405. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)dispatch_data;
  406. callbacks.votequorum_notify_fn ( handle,
  407. res_lib_votequorum_notification->context,
  408. res_lib_votequorum_notification->quorate,
  409. res_lib_votequorum_notification->node_list_entries,
  410. (votequorum_node_t *)res_lib_votequorum_notification->node_list );
  411. ;
  412. break;
  413. case MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION:
  414. if (callbacks.votequorum_expectedvotes_notify_fn == NULL) {
  415. break;
  416. }
  417. res_lib_votequorum_expectedvotes_notification = (struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
  418. callbacks.votequorum_expectedvotes_notify_fn ( handle,
  419. res_lib_votequorum_expectedvotes_notification->context,
  420. res_lib_votequorum_expectedvotes_notification->expected_votes);
  421. break;
  422. default:
  423. error = CS_ERR_LIBRARY;
  424. goto error_put;
  425. break;
  426. }
  427. if (votequorum_inst->finalize) {
  428. /*
  429. * If the finalize has been called then get out of the dispatch.
  430. */
  431. error = CS_ERR_BAD_HANDLE;
  432. goto error_put;
  433. }
  434. /*
  435. * Determine if more messages should be processed
  436. */
  437. if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  438. cont = 0;
  439. }
  440. } while (cont);
  441. error_put:
  442. hdb_handle_put (&votequorum_handle_t_db, handle);
  443. return (error);
  444. }
  445. cs_error_t votequorum_qdevice_register (
  446. votequorum_handle_t handle,
  447. const char *name)
  448. {
  449. cs_error_t error;
  450. struct votequorum_inst *votequorum_inst;
  451. struct iovec iov;
  452. struct req_lib_votequorum_qdevice_register req_lib_votequorum_qdevice_register;
  453. struct res_lib_votequorum_status res_lib_votequorum_status;
  454. if (strlen(name) >= VOTEQUORUM_MAX_QDEVICE_NAME_LEN) {
  455. return CS_ERR_INVALID_PARAM;
  456. }
  457. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  458. if (error != CS_OK) {
  459. return (error);
  460. }
  461. req_lib_votequorum_qdevice_register.header.size = sizeof (struct req_lib_votequorum_qdevice_register);
  462. req_lib_votequorum_qdevice_register.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_REGISTER;
  463. strcpy(req_lib_votequorum_qdevice_register.name, name);
  464. iov.iov_base = (char *)&req_lib_votequorum_qdevice_register;
  465. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_register);
  466. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  467. votequorum_inst->c,
  468. &iov,
  469. 1,
  470. &res_lib_votequorum_status,
  471. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  472. if (error != CS_OK) {
  473. goto error_exit;
  474. }
  475. error = res_lib_votequorum_status.header.error;
  476. error_exit:
  477. hdb_handle_put (&votequorum_handle_t_db, handle);
  478. return (error);
  479. }
  480. cs_error_t votequorum_qdevice_poll (
  481. votequorum_handle_t handle,
  482. const char *name,
  483. unsigned int cast_vote)
  484. {
  485. cs_error_t error;
  486. struct votequorum_inst *votequorum_inst;
  487. struct iovec iov;
  488. struct req_lib_votequorum_qdevice_poll req_lib_votequorum_qdevice_poll;
  489. struct res_lib_votequorum_status res_lib_votequorum_status;
  490. if (strlen(name) >= VOTEQUORUM_MAX_QDEVICE_NAME_LEN) {
  491. return CS_ERR_INVALID_PARAM;
  492. }
  493. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  494. if (error != CS_OK) {
  495. return (error);
  496. }
  497. req_lib_votequorum_qdevice_poll.header.size = sizeof (struct req_lib_votequorum_qdevice_poll);
  498. req_lib_votequorum_qdevice_poll.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_POLL;
  499. strcpy(req_lib_votequorum_qdevice_poll.name, name);
  500. req_lib_votequorum_qdevice_poll.cast_vote = cast_vote;
  501. iov.iov_base = (char *)&req_lib_votequorum_qdevice_poll;
  502. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_poll);
  503. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  504. votequorum_inst->c,
  505. &iov,
  506. 1,
  507. &res_lib_votequorum_status,
  508. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  509. if (error != CS_OK) {
  510. goto error_exit;
  511. }
  512. error = res_lib_votequorum_status.header.error;
  513. error_exit:
  514. hdb_handle_put (&votequorum_handle_t_db, handle);
  515. return (error);
  516. }
  517. cs_error_t votequorum_qdevice_unregister (
  518. votequorum_handle_t handle,
  519. const char *name)
  520. {
  521. cs_error_t error;
  522. struct votequorum_inst *votequorum_inst;
  523. struct iovec iov;
  524. struct req_lib_votequorum_qdevice_unregister req_lib_votequorum_qdevice_unregister;
  525. struct res_lib_votequorum_status res_lib_votequorum_status;
  526. if (strlen(name) >= VOTEQUORUM_MAX_QDEVICE_NAME_LEN) {
  527. return CS_ERR_INVALID_PARAM;
  528. }
  529. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  530. if (error != CS_OK) {
  531. return (error);
  532. }
  533. req_lib_votequorum_qdevice_unregister.header.size = sizeof (struct req_lib_votequorum_qdevice_unregister);
  534. req_lib_votequorum_qdevice_unregister.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UNREGISTER;
  535. strcpy(req_lib_votequorum_qdevice_unregister.name, name);
  536. iov.iov_base = (char *)&req_lib_votequorum_qdevice_unregister;
  537. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_unregister);
  538. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  539. votequorum_inst->c,
  540. &iov,
  541. 1,
  542. &res_lib_votequorum_status,
  543. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  544. if (error != CS_OK) {
  545. goto error_exit;
  546. }
  547. error = res_lib_votequorum_status.header.error;
  548. error_exit:
  549. hdb_handle_put (&votequorum_handle_t_db, handle);
  550. return (error);
  551. }
  552. cs_error_t votequorum_qdevice_getinfo (
  553. votequorum_handle_t handle,
  554. unsigned int nodeid,
  555. struct votequorum_qdevice_info *qinfo)
  556. {
  557. cs_error_t error;
  558. struct votequorum_inst *votequorum_inst;
  559. struct iovec iov;
  560. struct req_lib_votequorum_qdevice_getinfo req_lib_votequorum_qdevice_getinfo;
  561. struct res_lib_votequorum_qdevice_getinfo res_lib_votequorum_qdevice_getinfo;
  562. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  563. if (error != CS_OK) {
  564. return (error);
  565. }
  566. req_lib_votequorum_qdevice_getinfo.header.size = sizeof (struct req_lib_votequorum_qdevice_getinfo);
  567. req_lib_votequorum_qdevice_getinfo.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_GETINFO;
  568. req_lib_votequorum_qdevice_getinfo.nodeid = nodeid;
  569. iov.iov_base = (char *)&req_lib_votequorum_qdevice_getinfo;
  570. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_getinfo);
  571. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  572. votequorum_inst->c,
  573. &iov,
  574. 1,
  575. &res_lib_votequorum_qdevice_getinfo,
  576. sizeof (struct res_lib_votequorum_qdevice_getinfo), CS_IPC_TIMEOUT_MS));
  577. if (error != CS_OK) {
  578. goto error_exit;
  579. }
  580. error = res_lib_votequorum_qdevice_getinfo.header.error;
  581. qinfo->votes = res_lib_votequorum_qdevice_getinfo.votes;
  582. qinfo->alive = res_lib_votequorum_qdevice_getinfo.alive;
  583. qinfo->cast_vote = res_lib_votequorum_qdevice_getinfo.cast_vote;
  584. strcpy(qinfo->name, res_lib_votequorum_qdevice_getinfo.name);
  585. error_exit:
  586. hdb_handle_put (&votequorum_handle_t_db, handle);
  587. return (error);
  588. }