votequorum.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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. votequorum_ring_id_t ring_id;
  350. if (dispatch_types != CS_DISPATCH_ONE &&
  351. dispatch_types != CS_DISPATCH_ALL &&
  352. dispatch_types != CS_DISPATCH_BLOCKING &&
  353. dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) {
  354. return (CS_ERR_INVALID_PARAM);
  355. }
  356. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
  357. (void *)&votequorum_inst));
  358. if (error != CS_OK) {
  359. return (error);
  360. }
  361. /*
  362. * Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
  363. * wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
  364. */
  365. if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  366. timeout = 0;
  367. }
  368. dispatch_data = (struct qb_ipc_response_header *)dispatch_buf;
  369. do {
  370. error = qb_to_cs_error (qb_ipcc_event_recv (
  371. votequorum_inst->c,
  372. dispatch_buf,
  373. IPC_DISPATCH_SIZE,
  374. timeout));
  375. if (error == CS_ERR_BAD_HANDLE) {
  376. error = CS_OK;
  377. goto error_put;
  378. }
  379. if (error == CS_ERR_TRY_AGAIN) {
  380. if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  381. /*
  382. * Don't mask error
  383. */
  384. goto error_put;
  385. }
  386. error = CS_OK;
  387. if (dispatch_types == CS_DISPATCH_ALL) {
  388. break; /* exit do while cont is 1 loop */
  389. } else {
  390. continue; /* next poll */
  391. }
  392. }
  393. if (error != CS_OK) {
  394. goto error_put;
  395. }
  396. /*
  397. * Make copy of callbacks, message data, unlock instance, and call callback
  398. * A risk of this dispatch method is that the callback routines may
  399. * operate at the same time that votequorum_finalize has been called in another thread.
  400. */
  401. memcpy (&callbacks, &votequorum_inst->callbacks, sizeof (votequorum_callbacks_t));
  402. /*
  403. * Dispatch incoming message
  404. */
  405. switch (dispatch_data->id) {
  406. case MESSAGE_RES_VOTEQUORUM_NOTIFICATION:
  407. if (callbacks.votequorum_notify_fn == NULL) {
  408. break;
  409. }
  410. res_lib_votequorum_notification = (struct res_lib_votequorum_notification *)dispatch_data;
  411. marshall_from_mar_votequorum_ring_id (&ring_id, &res_lib_votequorum_notification->ring_id);
  412. callbacks.votequorum_notify_fn ( handle,
  413. res_lib_votequorum_notification->context,
  414. res_lib_votequorum_notification->quorate,
  415. ring_id,
  416. res_lib_votequorum_notification->node_list_entries,
  417. (votequorum_node_t *)res_lib_votequorum_notification->node_list );
  418. ;
  419. break;
  420. case MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION:
  421. if (callbacks.votequorum_expectedvotes_notify_fn == NULL) {
  422. break;
  423. }
  424. res_lib_votequorum_expectedvotes_notification = (struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
  425. callbacks.votequorum_expectedvotes_notify_fn ( handle,
  426. res_lib_votequorum_expectedvotes_notification->context,
  427. res_lib_votequorum_expectedvotes_notification->expected_votes);
  428. break;
  429. default:
  430. error = CS_ERR_LIBRARY;
  431. goto error_put;
  432. break;
  433. }
  434. if (votequorum_inst->finalize) {
  435. /*
  436. * If the finalize has been called then get out of the dispatch.
  437. */
  438. error = CS_ERR_BAD_HANDLE;
  439. goto error_put;
  440. }
  441. /*
  442. * Determine if more messages should be processed
  443. */
  444. if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  445. cont = 0;
  446. }
  447. } while (cont);
  448. error_put:
  449. hdb_handle_put (&votequorum_handle_t_db, handle);
  450. return (error);
  451. }
  452. cs_error_t votequorum_qdevice_register (
  453. votequorum_handle_t handle,
  454. const char *name)
  455. {
  456. cs_error_t error;
  457. struct votequorum_inst *votequorum_inst;
  458. struct iovec iov;
  459. struct req_lib_votequorum_qdevice_register req_lib_votequorum_qdevice_register;
  460. struct res_lib_votequorum_status res_lib_votequorum_status;
  461. if ((strlen(name) == 0) ||
  462. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  463. return CS_ERR_INVALID_PARAM;
  464. }
  465. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  466. if (error != CS_OK) {
  467. return (error);
  468. }
  469. req_lib_votequorum_qdevice_register.header.size = sizeof (struct req_lib_votequorum_qdevice_register);
  470. req_lib_votequorum_qdevice_register.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_REGISTER;
  471. strcpy(req_lib_votequorum_qdevice_register.name, name);
  472. iov.iov_base = (char *)&req_lib_votequorum_qdevice_register;
  473. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_register);
  474. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  475. votequorum_inst->c,
  476. &iov,
  477. 1,
  478. &res_lib_votequorum_status,
  479. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  480. if (error != CS_OK) {
  481. goto error_exit;
  482. }
  483. error = res_lib_votequorum_status.header.error;
  484. error_exit:
  485. hdb_handle_put (&votequorum_handle_t_db, handle);
  486. return (error);
  487. }
  488. cs_error_t votequorum_qdevice_poll (
  489. votequorum_handle_t handle,
  490. const char *name,
  491. unsigned int cast_vote,
  492. votequorum_ring_id_t ring_id)
  493. {
  494. cs_error_t error;
  495. struct votequorum_inst *votequorum_inst;
  496. struct iovec iov;
  497. struct req_lib_votequorum_qdevice_poll req_lib_votequorum_qdevice_poll;
  498. struct res_lib_votequorum_status res_lib_votequorum_status;
  499. if ((strlen(name) == 0) ||
  500. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  501. return CS_ERR_INVALID_PARAM;
  502. }
  503. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  504. if (error != CS_OK) {
  505. return (error);
  506. }
  507. req_lib_votequorum_qdevice_poll.header.size = sizeof (struct req_lib_votequorum_qdevice_poll);
  508. req_lib_votequorum_qdevice_poll.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_POLL;
  509. strcpy(req_lib_votequorum_qdevice_poll.name, name);
  510. req_lib_votequorum_qdevice_poll.cast_vote = cast_vote;
  511. marshall_to_mar_votequorum_ring_id(&req_lib_votequorum_qdevice_poll.ring_id, &ring_id);
  512. iov.iov_base = (char *)&req_lib_votequorum_qdevice_poll;
  513. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_poll);
  514. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  515. votequorum_inst->c,
  516. &iov,
  517. 1,
  518. &res_lib_votequorum_status,
  519. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  520. if (error != CS_OK) {
  521. goto error_exit;
  522. }
  523. error = res_lib_votequorum_status.header.error;
  524. error_exit:
  525. hdb_handle_put (&votequorum_handle_t_db, handle);
  526. return (error);
  527. }
  528. cs_error_t votequorum_qdevice_master_wins (
  529. votequorum_handle_t handle,
  530. const char *name,
  531. unsigned int allow)
  532. {
  533. cs_error_t error;
  534. struct votequorum_inst *votequorum_inst;
  535. struct iovec iov;
  536. struct req_lib_votequorum_qdevice_master_wins req_lib_votequorum_qdevice_master_wins;
  537. struct res_lib_votequorum_status res_lib_votequorum_status;
  538. if ((strlen(name) == 0) ||
  539. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  540. return CS_ERR_INVALID_PARAM;
  541. }
  542. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  543. if (error != CS_OK) {
  544. return (error);
  545. }
  546. req_lib_votequorum_qdevice_master_wins.header.size = sizeof (struct req_lib_votequorum_qdevice_master_wins);
  547. req_lib_votequorum_qdevice_master_wins.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_MASTER_WINS;
  548. strcpy(req_lib_votequorum_qdevice_master_wins.name, name);
  549. req_lib_votequorum_qdevice_master_wins.allow = allow;
  550. iov.iov_base = (char *)&req_lib_votequorum_qdevice_master_wins;
  551. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_master_wins);
  552. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  553. votequorum_inst->c,
  554. &iov,
  555. 1,
  556. &res_lib_votequorum_status,
  557. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  558. if (error != CS_OK) {
  559. goto error_exit;
  560. }
  561. error = res_lib_votequorum_status.header.error;
  562. error_exit:
  563. hdb_handle_put (&votequorum_handle_t_db, handle);
  564. return (error);
  565. }
  566. cs_error_t votequorum_qdevice_update (
  567. votequorum_handle_t handle,
  568. const char *oldname,
  569. const char *newname)
  570. {
  571. cs_error_t error;
  572. struct votequorum_inst *votequorum_inst;
  573. struct iovec iov;
  574. struct req_lib_votequorum_qdevice_update req_lib_votequorum_qdevice_update;
  575. struct res_lib_votequorum_status res_lib_votequorum_status;
  576. if ((strlen(oldname) == 0) ||
  577. (strlen(oldname) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN) ||
  578. (strlen(newname) == 0) ||
  579. (strlen(newname) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  580. return CS_ERR_INVALID_PARAM;
  581. }
  582. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  583. if (error != CS_OK) {
  584. return (error);
  585. }
  586. req_lib_votequorum_qdevice_update.header.size = sizeof (struct req_lib_votequorum_qdevice_update);
  587. req_lib_votequorum_qdevice_update.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UPDATE;
  588. strcpy(req_lib_votequorum_qdevice_update.oldname, oldname);
  589. strcpy(req_lib_votequorum_qdevice_update.newname, newname);
  590. iov.iov_base = (char *)&req_lib_votequorum_qdevice_update;
  591. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_update);
  592. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  593. votequorum_inst->c,
  594. &iov,
  595. 1,
  596. &res_lib_votequorum_status,
  597. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  598. if (error != CS_OK) {
  599. goto error_exit;
  600. }
  601. error = res_lib_votequorum_status.header.error;
  602. error_exit:
  603. hdb_handle_put (&votequorum_handle_t_db, handle);
  604. return (error);
  605. }
  606. cs_error_t votequorum_qdevice_unregister (
  607. votequorum_handle_t handle,
  608. const char *name)
  609. {
  610. cs_error_t error;
  611. struct votequorum_inst *votequorum_inst;
  612. struct iovec iov;
  613. struct req_lib_votequorum_qdevice_unregister req_lib_votequorum_qdevice_unregister;
  614. struct res_lib_votequorum_status res_lib_votequorum_status;
  615. if ((strlen(name) == 0) ||
  616. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  617. return CS_ERR_INVALID_PARAM;
  618. }
  619. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  620. if (error != CS_OK) {
  621. return (error);
  622. }
  623. req_lib_votequorum_qdevice_unregister.header.size = sizeof (struct req_lib_votequorum_qdevice_unregister);
  624. req_lib_votequorum_qdevice_unregister.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UNREGISTER;
  625. strcpy(req_lib_votequorum_qdevice_unregister.name, name);
  626. iov.iov_base = (char *)&req_lib_votequorum_qdevice_unregister;
  627. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_unregister);
  628. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  629. votequorum_inst->c,
  630. &iov,
  631. 1,
  632. &res_lib_votequorum_status,
  633. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  634. if (error != CS_OK) {
  635. goto error_exit;
  636. }
  637. error = res_lib_votequorum_status.header.error;
  638. error_exit:
  639. hdb_handle_put (&votequorum_handle_t_db, handle);
  640. return (error);
  641. }