votequorum.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * Copyright (c) 2009 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_votes = res_lib_votequorum_getinfo.votes;
  144. info->node_expected_votes = res_lib_votequorum_getinfo.expected_votes;
  145. info->highest_expected = res_lib_votequorum_getinfo.highest_expected;
  146. info->total_votes = res_lib_votequorum_getinfo.total_votes;
  147. info->quorum = res_lib_votequorum_getinfo.quorum;
  148. info->flags = res_lib_votequorum_getinfo.flags;
  149. error_exit:
  150. hdb_handle_put (&votequorum_handle_t_db, handle);
  151. return (error);
  152. }
  153. cs_error_t votequorum_setexpected (
  154. votequorum_handle_t handle,
  155. unsigned int expected_votes)
  156. {
  157. cs_error_t error;
  158. struct votequorum_inst *votequorum_inst;
  159. struct iovec iov;
  160. struct req_lib_votequorum_setexpected req_lib_votequorum_setexpected;
  161. struct res_lib_votequorum_status res_lib_votequorum_status;
  162. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  163. if (error != CS_OK) {
  164. return (error);
  165. }
  166. req_lib_votequorum_setexpected.header.size = sizeof (struct req_lib_votequorum_setexpected);
  167. req_lib_votequorum_setexpected.header.id = MESSAGE_REQ_VOTEQUORUM_SETEXPECTED;
  168. req_lib_votequorum_setexpected.expected_votes = expected_votes;
  169. iov.iov_base = (char *)&req_lib_votequorum_setexpected;
  170. iov.iov_len = sizeof (struct req_lib_votequorum_setexpected);
  171. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  172. votequorum_inst->c,
  173. &iov,
  174. 1,
  175. &res_lib_votequorum_status,
  176. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  177. if (error != CS_OK) {
  178. goto error_exit;
  179. }
  180. error = res_lib_votequorum_status.header.error;
  181. error_exit:
  182. hdb_handle_put (&votequorum_handle_t_db, handle);
  183. return (error);
  184. }
  185. cs_error_t votequorum_setvotes (
  186. votequorum_handle_t handle,
  187. unsigned int nodeid,
  188. unsigned int votes)
  189. {
  190. cs_error_t error;
  191. struct votequorum_inst *votequorum_inst;
  192. struct iovec iov;
  193. struct req_lib_votequorum_setvotes req_lib_votequorum_setvotes;
  194. struct res_lib_votequorum_status res_lib_votequorum_status;
  195. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  196. if (error != CS_OK) {
  197. return (error);
  198. }
  199. req_lib_votequorum_setvotes.header.size = sizeof (struct req_lib_votequorum_setvotes);
  200. req_lib_votequorum_setvotes.header.id = MESSAGE_REQ_VOTEQUORUM_SETVOTES;
  201. req_lib_votequorum_setvotes.nodeid = nodeid;
  202. req_lib_votequorum_setvotes.votes = votes;
  203. iov.iov_base = (char *)&req_lib_votequorum_setvotes;
  204. iov.iov_len = sizeof (struct req_lib_votequorum_setvotes);
  205. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  206. votequorum_inst->c,
  207. &iov,
  208. 1,
  209. &res_lib_votequorum_status,
  210. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  211. if (error != CS_OK) {
  212. goto error_exit;
  213. }
  214. error = res_lib_votequorum_status.header.error;
  215. error_exit:
  216. hdb_handle_put (&votequorum_handle_t_db, handle);
  217. return (error);
  218. }
  219. cs_error_t votequorum_trackstart (
  220. votequorum_handle_t handle,
  221. uint64_t context,
  222. unsigned int flags)
  223. {
  224. cs_error_t error;
  225. struct votequorum_inst *votequorum_inst;
  226. struct iovec iov;
  227. struct req_lib_votequorum_trackstart req_lib_votequorum_trackstart;
  228. struct res_lib_votequorum_status res_lib_votequorum_status;
  229. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  230. if (error != CS_OK) {
  231. return (error);
  232. }
  233. req_lib_votequorum_trackstart.header.size = sizeof (struct req_lib_votequorum_trackstart);
  234. req_lib_votequorum_trackstart.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTART;
  235. req_lib_votequorum_trackstart.track_flags = flags;
  236. req_lib_votequorum_trackstart.context = context;
  237. iov.iov_base = (char *)&req_lib_votequorum_trackstart;
  238. iov.iov_len = sizeof (struct req_lib_votequorum_trackstart);
  239. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  240. votequorum_inst->c,
  241. &iov,
  242. 1,
  243. &res_lib_votequorum_status,
  244. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  245. if (error != CS_OK) {
  246. goto error_exit;
  247. }
  248. error = res_lib_votequorum_status.header.error;
  249. error_exit:
  250. hdb_handle_put (&votequorum_handle_t_db, handle);
  251. return (error);
  252. }
  253. cs_error_t votequorum_trackstop (
  254. votequorum_handle_t handle)
  255. {
  256. cs_error_t error;
  257. struct votequorum_inst *votequorum_inst;
  258. struct iovec iov;
  259. struct req_lib_votequorum_general req_lib_votequorum_general;
  260. struct res_lib_votequorum_status res_lib_votequorum_status;
  261. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  262. if (error != CS_OK) {
  263. return (error);
  264. }
  265. req_lib_votequorum_general.header.size = sizeof (struct req_lib_votequorum_general);
  266. req_lib_votequorum_general.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTOP;
  267. iov.iov_base = (char *)&req_lib_votequorum_general;
  268. iov.iov_len = sizeof (struct req_lib_votequorum_general);
  269. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  270. votequorum_inst->c,
  271. &iov,
  272. 1,
  273. &res_lib_votequorum_status,
  274. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  275. if (error != CS_OK) {
  276. goto error_exit;
  277. }
  278. error = res_lib_votequorum_status.header.error;
  279. error_exit:
  280. hdb_handle_put (&votequorum_handle_t_db, handle);
  281. return (error);
  282. }
  283. cs_error_t votequorum_context_get (
  284. votequorum_handle_t handle,
  285. void **context)
  286. {
  287. cs_error_t error;
  288. struct votequorum_inst *votequorum_inst;
  289. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  290. if (error != CS_OK) {
  291. return (error);
  292. }
  293. *context = votequorum_inst->context;
  294. hdb_handle_put (&votequorum_handle_t_db, handle);
  295. return (CS_OK);
  296. }
  297. cs_error_t votequorum_context_set (
  298. votequorum_handle_t handle,
  299. void *context)
  300. {
  301. cs_error_t error;
  302. struct votequorum_inst *votequorum_inst;
  303. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  304. if (error != CS_OK) {
  305. return (error);
  306. }
  307. votequorum_inst->context = context;
  308. hdb_handle_put (&votequorum_handle_t_db, handle);
  309. return (CS_OK);
  310. }
  311. cs_error_t votequorum_fd_get (
  312. votequorum_handle_t handle,
  313. int *fd)
  314. {
  315. cs_error_t error;
  316. struct votequorum_inst *votequorum_inst;
  317. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  318. if (error != CS_OK) {
  319. return (error);
  320. }
  321. error = qb_to_cs_error(qb_ipcc_fd_get (votequorum_inst->c, fd));
  322. (void)hdb_handle_put (&votequorum_handle_t_db, handle);
  323. return (error);
  324. }
  325. cs_error_t votequorum_dispatch (
  326. votequorum_handle_t handle,
  327. cs_dispatch_flags_t dispatch_types)
  328. {
  329. int timeout = -1;
  330. cs_error_t error;
  331. int cont = 1; /* always continue do loop except when set to 0 */
  332. struct votequorum_inst *votequorum_inst;
  333. votequorum_callbacks_t callbacks;
  334. struct qb_ipc_response_header *dispatch_data;
  335. struct res_lib_votequorum_notification *res_lib_votequorum_notification;
  336. struct res_lib_votequorum_expectedvotes_notification *res_lib_votequorum_expectedvotes_notification;
  337. char dispatch_buf[IPC_DISPATCH_SIZE];
  338. if (dispatch_types != CS_DISPATCH_ONE &&
  339. dispatch_types != CS_DISPATCH_ALL &&
  340. dispatch_types != CS_DISPATCH_BLOCKING) {
  341. return (CS_ERR_INVALID_PARAM);
  342. }
  343. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
  344. (void *)&votequorum_inst));
  345. if (error != CS_OK) {
  346. return (error);
  347. }
  348. /*
  349. * Timeout instantly for CS_DISPATCH_ONE or CS_DISPATCH_ALL and
  350. * wait indefinitely for CS_DISPATCH_BLOCKING
  351. */
  352. if (dispatch_types == CS_DISPATCH_ALL) {
  353. timeout = 0;
  354. }
  355. dispatch_data = (struct qb_ipc_response_header *)dispatch_buf;
  356. do {
  357. error = qb_to_cs_error (qb_ipcc_event_recv (
  358. votequorum_inst->c,
  359. dispatch_buf,
  360. IPC_DISPATCH_SIZE,
  361. timeout));
  362. if (error == CS_ERR_BAD_HANDLE) {
  363. error = CS_OK;
  364. goto error_put;
  365. }
  366. if (error == CS_ERR_TRY_AGAIN) {
  367. error = CS_OK;
  368. if (dispatch_types == CPG_DISPATCH_ALL) {
  369. break; /* exit do while cont is 1 loop */
  370. } else {
  371. continue; /* next poll */
  372. }
  373. }
  374. if (error != CS_OK) {
  375. goto error_put;
  376. }
  377. /*
  378. * Make copy of callbacks, message data, unlock instance, and call callback
  379. * A risk of this dispatch method is that the callback routines may
  380. * operate at the same time that votequorum_finalize has been called in another thread.
  381. */
  382. memcpy (&callbacks, &votequorum_inst->callbacks, sizeof (votequorum_callbacks_t));
  383. /*
  384. * Dispatch incoming message
  385. */
  386. switch (dispatch_data->id) {
  387. case MESSAGE_RES_VOTEQUORUM_NOTIFICATION:
  388. if (callbacks.votequorum_notify_fn == NULL) {
  389. break;
  390. }
  391. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)dispatch_data;
  392. callbacks.votequorum_notify_fn ( handle,
  393. res_lib_votequorum_notification->context,
  394. res_lib_votequorum_notification->quorate,
  395. res_lib_votequorum_notification->node_list_entries,
  396. (votequorum_node_t *)res_lib_votequorum_notification->node_list );
  397. ;
  398. break;
  399. case MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION:
  400. if (callbacks.votequorum_expectedvotes_notify_fn == NULL) {
  401. break;
  402. }
  403. res_lib_votequorum_expectedvotes_notification = (struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
  404. callbacks.votequorum_expectedvotes_notify_fn ( handle,
  405. res_lib_votequorum_expectedvotes_notification->context,
  406. res_lib_votequorum_expectedvotes_notification->expected_votes);
  407. break;
  408. default:
  409. error = CS_ERR_LIBRARY;
  410. goto error_put;
  411. break;
  412. }
  413. /*
  414. * Determine if more messages should be processed
  415. */
  416. if (dispatch_types == CS_DISPATCH_ONE) {
  417. cont = 0;
  418. }
  419. } while (cont);
  420. goto error_put;
  421. error_put:
  422. hdb_handle_put (&votequorum_handle_t_db, handle);
  423. return (error);
  424. }
  425. #ifdef EXPERIMENTAL_QUORUM_DEVICE_API
  426. cs_error_t votequorum_qdisk_register (
  427. votequorum_handle_t handle,
  428. const char *name,
  429. unsigned int votes)
  430. {
  431. cs_error_t error;
  432. struct votequorum_inst *votequorum_inst;
  433. struct iovec iov;
  434. struct req_lib_votequorum_qdisk_register req_lib_votequorum_qdisk_register;
  435. struct res_lib_votequorum_status res_lib_votequorum_status;
  436. if (strlen(name) > VOTEQUORUM_MAX_QDISK_NAME_LEN)
  437. return CS_ERR_INVALID_PARAM;
  438. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  439. if (error != CS_OK) {
  440. return (error);
  441. }
  442. req_lib_votequorum_qdisk_register.header.size = sizeof (struct req_lib_votequorum_qdisk_register);
  443. req_lib_votequorum_qdisk_register.header.id = MESSAGE_REQ_VOTEQUORUM_QDISK_REGISTER;
  444. strcpy(req_lib_votequorum_qdisk_register.name, name);
  445. req_lib_votequorum_qdisk_register.votes = votes;
  446. iov.iov_base = (char *)&req_lib_votequorum_qdisk_register;
  447. iov.iov_len = sizeof (struct req_lib_votequorum_qdisk_register);
  448. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  449. votequorum_inst->c,
  450. &iov,
  451. 1,
  452. &res_lib_votequorum_status,
  453. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  454. if (error != CS_OK) {
  455. goto error_exit;
  456. }
  457. error = res_lib_votequorum_status.header.error;
  458. error_exit:
  459. hdb_handle_put (&votequorum_handle_t_db, handle);
  460. return (error);
  461. }
  462. cs_error_t votequorum_qdisk_poll (
  463. votequorum_handle_t handle,
  464. unsigned int state)
  465. {
  466. cs_error_t error;
  467. struct votequorum_inst *votequorum_inst;
  468. struct iovec iov;
  469. struct req_lib_votequorum_qdisk_poll req_lib_votequorum_qdisk_poll;
  470. struct res_lib_votequorum_status res_lib_votequorum_status;
  471. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  472. if (error != CS_OK) {
  473. return (error);
  474. }
  475. req_lib_votequorum_qdisk_poll.header.size = sizeof (struct req_lib_votequorum_qdisk_poll);
  476. req_lib_votequorum_qdisk_poll.header.id = MESSAGE_REQ_VOTEQUORUM_QDISK_POLL;
  477. req_lib_votequorum_qdisk_poll.state = state;
  478. iov.iov_base = (char *)&req_lib_votequorum_qdisk_poll;
  479. iov.iov_len = sizeof (struct req_lib_votequorum_qdisk_poll);
  480. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  481. votequorum_inst->c,
  482. &iov,
  483. 1,
  484. &res_lib_votequorum_status,
  485. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  486. if (error != CS_OK) {
  487. goto error_exit;
  488. }
  489. error = res_lib_votequorum_status.header.error;
  490. error_exit:
  491. hdb_handle_put (&votequorum_handle_t_db, handle);
  492. return (error);
  493. }
  494. cs_error_t votequorum_qdisk_unregister (
  495. votequorum_handle_t handle)
  496. {
  497. cs_error_t error;
  498. struct votequorum_inst *votequorum_inst;
  499. struct iovec iov;
  500. struct req_lib_votequorum_general req_lib_votequorum_general;
  501. struct res_lib_votequorum_status res_lib_votequorum_status;
  502. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  503. if (error != CS_OK) {
  504. return (error);
  505. }
  506. req_lib_votequorum_general.header.size = sizeof (struct req_lib_votequorum_general);
  507. req_lib_votequorum_general.header.id = MESSAGE_REQ_VOTEQUORUM_QDISK_UNREGISTER;
  508. iov.iov_base = (char *)&req_lib_votequorum_general;
  509. iov.iov_len = sizeof (struct req_lib_votequorum_general);
  510. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  511. votequorum_inst->c,
  512. &iov,
  513. 1,
  514. &res_lib_votequorum_status,
  515. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  516. if (error != CS_OK) {
  517. goto error_exit;
  518. }
  519. error = res_lib_votequorum_status.header.error;
  520. error_exit:
  521. hdb_handle_put (&votequorum_handle_t_db, handle);
  522. return (error);
  523. }
  524. cs_error_t votequorum_qdisk_getinfo (
  525. votequorum_handle_t handle,
  526. struct votequorum_qdisk_info *qinfo)
  527. {
  528. cs_error_t error;
  529. struct votequorum_inst *votequorum_inst;
  530. struct iovec iov;
  531. struct req_lib_votequorum_general req_lib_votequorum_general;
  532. struct res_lib_votequorum_qdisk_getinfo res_lib_votequorum_qdisk_getinfo;
  533. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  534. if (error != CS_OK) {
  535. return (error);
  536. }
  537. req_lib_votequorum_general.header.size = sizeof (struct req_lib_votequorum_general);
  538. req_lib_votequorum_general.header.id = MESSAGE_REQ_VOTEQUORUM_QDISK_GETINFO;
  539. iov.iov_base = (char *)&req_lib_votequorum_general;
  540. iov.iov_len = sizeof (struct req_lib_votequorum_general);
  541. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  542. votequorum_inst->c,
  543. &iov,
  544. 1,
  545. &res_lib_votequorum_qdisk_getinfo,
  546. sizeof (struct res_lib_votequorum_qdisk_getinfo), CS_IPC_TIMEOUT_MS));
  547. if (error != CS_OK) {
  548. goto error_exit;
  549. }
  550. error = res_lib_votequorum_qdisk_getinfo.header.error;
  551. qinfo->votes = res_lib_votequorum_qdisk_getinfo.votes;
  552. qinfo->state = res_lib_votequorum_qdisk_getinfo.state;
  553. strcpy(qinfo->name, res_lib_votequorum_qdisk_getinfo.name);
  554. error_exit:
  555. hdb_handle_put (&votequorum_handle_t_db, handle);
  556. return (error);
  557. }
  558. #endif