votequorum.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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. res_lib_votequorum_quorum_notification->node_list_entries,
  416. (votequorum_node_t *)res_lib_votequorum_quorum_notification->node_list );
  417. break;
  418. case MESSAGE_RES_VOTEQUORUM_NODELIST_NOTIFICATION:
  419. if (callbacks.votequorum_nodelist_notify_fn == NULL) {
  420. break;
  421. }
  422. res_lib_votequorum_nodelist_notification = (struct res_lib_votequorum_nodelist_notification *)dispatch_data;
  423. marshall_from_mar_votequorum_ring_id (&ring_id, &res_lib_votequorum_nodelist_notification->ring_id);
  424. callbacks.votequorum_nodelist_notify_fn ( handle,
  425. res_lib_votequorum_nodelist_notification->context,
  426. ring_id,
  427. res_lib_votequorum_nodelist_notification->node_list_entries,
  428. res_lib_votequorum_nodelist_notification->node_list );
  429. break;
  430. case MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION:
  431. if (callbacks.votequorum_expectedvotes_notify_fn == NULL) {
  432. break;
  433. }
  434. res_lib_votequorum_expectedvotes_notification = (struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
  435. callbacks.votequorum_expectedvotes_notify_fn ( handle,
  436. res_lib_votequorum_expectedvotes_notification->context,
  437. res_lib_votequorum_expectedvotes_notification->expected_votes);
  438. break;
  439. default:
  440. error = CS_ERR_LIBRARY;
  441. goto error_put;
  442. break;
  443. }
  444. if (votequorum_inst->finalize) {
  445. /*
  446. * If the finalize has been called then get out of the dispatch.
  447. */
  448. error = CS_ERR_BAD_HANDLE;
  449. goto error_put;
  450. }
  451. /*
  452. * Determine if more messages should be processed
  453. */
  454. if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
  455. cont = 0;
  456. }
  457. } while (cont);
  458. error_put:
  459. hdb_handle_put (&votequorum_handle_t_db, handle);
  460. return (error);
  461. }
  462. cs_error_t votequorum_qdevice_register (
  463. votequorum_handle_t handle,
  464. const char *name)
  465. {
  466. cs_error_t error;
  467. struct votequorum_inst *votequorum_inst;
  468. struct iovec iov;
  469. struct req_lib_votequorum_qdevice_register req_lib_votequorum_qdevice_register;
  470. struct res_lib_votequorum_status res_lib_votequorum_status;
  471. if ((strlen(name) == 0) ||
  472. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  473. return CS_ERR_INVALID_PARAM;
  474. }
  475. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  476. if (error != CS_OK) {
  477. return (error);
  478. }
  479. req_lib_votequorum_qdevice_register.header.size = sizeof (struct req_lib_votequorum_qdevice_register);
  480. req_lib_votequorum_qdevice_register.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_REGISTER;
  481. strcpy(req_lib_votequorum_qdevice_register.name, name);
  482. iov.iov_base = (char *)&req_lib_votequorum_qdevice_register;
  483. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_register);
  484. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  485. votequorum_inst->c,
  486. &iov,
  487. 1,
  488. &res_lib_votequorum_status,
  489. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  490. if (error != CS_OK) {
  491. goto error_exit;
  492. }
  493. error = res_lib_votequorum_status.header.error;
  494. error_exit:
  495. hdb_handle_put (&votequorum_handle_t_db, handle);
  496. return (error);
  497. }
  498. cs_error_t votequorum_qdevice_poll (
  499. votequorum_handle_t handle,
  500. const char *name,
  501. unsigned int cast_vote,
  502. votequorum_ring_id_t ring_id)
  503. {
  504. cs_error_t error;
  505. struct votequorum_inst *votequorum_inst;
  506. struct iovec iov;
  507. struct req_lib_votequorum_qdevice_poll req_lib_votequorum_qdevice_poll;
  508. struct res_lib_votequorum_status res_lib_votequorum_status;
  509. if ((strlen(name) == 0) ||
  510. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  511. return CS_ERR_INVALID_PARAM;
  512. }
  513. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  514. if (error != CS_OK) {
  515. return (error);
  516. }
  517. req_lib_votequorum_qdevice_poll.header.size = sizeof (struct req_lib_votequorum_qdevice_poll);
  518. req_lib_votequorum_qdevice_poll.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_POLL;
  519. strcpy(req_lib_votequorum_qdevice_poll.name, name);
  520. req_lib_votequorum_qdevice_poll.cast_vote = cast_vote;
  521. marshall_to_mar_votequorum_ring_id(&req_lib_votequorum_qdevice_poll.ring_id, &ring_id);
  522. iov.iov_base = (char *)&req_lib_votequorum_qdevice_poll;
  523. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_poll);
  524. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  525. votequorum_inst->c,
  526. &iov,
  527. 1,
  528. &res_lib_votequorum_status,
  529. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  530. if (error != CS_OK) {
  531. goto error_exit;
  532. }
  533. error = res_lib_votequorum_status.header.error;
  534. error_exit:
  535. hdb_handle_put (&votequorum_handle_t_db, handle);
  536. return (error);
  537. }
  538. cs_error_t votequorum_qdevice_master_wins (
  539. votequorum_handle_t handle,
  540. const char *name,
  541. unsigned int allow)
  542. {
  543. cs_error_t error;
  544. struct votequorum_inst *votequorum_inst;
  545. struct iovec iov;
  546. struct req_lib_votequorum_qdevice_master_wins req_lib_votequorum_qdevice_master_wins;
  547. struct res_lib_votequorum_status res_lib_votequorum_status;
  548. if ((strlen(name) == 0) ||
  549. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  550. return CS_ERR_INVALID_PARAM;
  551. }
  552. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  553. if (error != CS_OK) {
  554. return (error);
  555. }
  556. req_lib_votequorum_qdevice_master_wins.header.size = sizeof (struct req_lib_votequorum_qdevice_master_wins);
  557. req_lib_votequorum_qdevice_master_wins.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_MASTER_WINS;
  558. strcpy(req_lib_votequorum_qdevice_master_wins.name, name);
  559. req_lib_votequorum_qdevice_master_wins.allow = allow;
  560. iov.iov_base = (char *)&req_lib_votequorum_qdevice_master_wins;
  561. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_master_wins);
  562. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  563. votequorum_inst->c,
  564. &iov,
  565. 1,
  566. &res_lib_votequorum_status,
  567. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  568. if (error != CS_OK) {
  569. goto error_exit;
  570. }
  571. error = res_lib_votequorum_status.header.error;
  572. error_exit:
  573. hdb_handle_put (&votequorum_handle_t_db, handle);
  574. return (error);
  575. }
  576. cs_error_t votequorum_qdevice_update (
  577. votequorum_handle_t handle,
  578. const char *oldname,
  579. const char *newname)
  580. {
  581. cs_error_t error;
  582. struct votequorum_inst *votequorum_inst;
  583. struct iovec iov;
  584. struct req_lib_votequorum_qdevice_update req_lib_votequorum_qdevice_update;
  585. struct res_lib_votequorum_status res_lib_votequorum_status;
  586. if ((strlen(oldname) == 0) ||
  587. (strlen(oldname) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN) ||
  588. (strlen(newname) == 0) ||
  589. (strlen(newname) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  590. return CS_ERR_INVALID_PARAM;
  591. }
  592. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  593. if (error != CS_OK) {
  594. return (error);
  595. }
  596. req_lib_votequorum_qdevice_update.header.size = sizeof (struct req_lib_votequorum_qdevice_update);
  597. req_lib_votequorum_qdevice_update.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UPDATE;
  598. strcpy(req_lib_votequorum_qdevice_update.oldname, oldname);
  599. strcpy(req_lib_votequorum_qdevice_update.newname, newname);
  600. iov.iov_base = (char *)&req_lib_votequorum_qdevice_update;
  601. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_update);
  602. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  603. votequorum_inst->c,
  604. &iov,
  605. 1,
  606. &res_lib_votequorum_status,
  607. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  608. if (error != CS_OK) {
  609. goto error_exit;
  610. }
  611. error = res_lib_votequorum_status.header.error;
  612. error_exit:
  613. hdb_handle_put (&votequorum_handle_t_db, handle);
  614. return (error);
  615. }
  616. cs_error_t votequorum_qdevice_unregister (
  617. votequorum_handle_t handle,
  618. const char *name)
  619. {
  620. cs_error_t error;
  621. struct votequorum_inst *votequorum_inst;
  622. struct iovec iov;
  623. struct req_lib_votequorum_qdevice_unregister req_lib_votequorum_qdevice_unregister;
  624. struct res_lib_votequorum_status res_lib_votequorum_status;
  625. if ((strlen(name) == 0) ||
  626. (strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
  627. return CS_ERR_INVALID_PARAM;
  628. }
  629. error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
  630. if (error != CS_OK) {
  631. return (error);
  632. }
  633. req_lib_votequorum_qdevice_unregister.header.size = sizeof (struct req_lib_votequorum_qdevice_unregister);
  634. req_lib_votequorum_qdevice_unregister.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UNREGISTER;
  635. strcpy(req_lib_votequorum_qdevice_unregister.name, name);
  636. iov.iov_base = (char *)&req_lib_votequorum_qdevice_unregister;
  637. iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_unregister);
  638. error = qb_to_cs_error(qb_ipcc_sendv_recv (
  639. votequorum_inst->c,
  640. &iov,
  641. 1,
  642. &res_lib_votequorum_status,
  643. sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
  644. if (error != CS_OK) {
  645. goto error_exit;
  646. }
  647. error = res_lib_votequorum_status.header.error;
  648. error_exit:
  649. hdb_handle_put (&votequorum_handle_t_db, handle);
  650. return (error);
  651. }