votequorum.c 22 KB

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