votequorum.c 23 KB

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