1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
|
/*
* Copyright (c) 2009-2012 Red Hat, Inc.
*
* All rights reserved.
*
* Author: Christine Caulfield (ccaulfie@redhat.com)
*
* This software licensed under BSD license, the text of which follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the MontaVista Software, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Provides a quorum API using the corosync executive
*/
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <errno.h>
#include <qb/qbdefs.h>
#include <qb/qbipcc.h>
#include <corosync/corotypes.h>
#include <corosync/corodefs.h>
#include <corosync/hdb.h>
#include <corosync/votequorum.h>
#include <corosync/ipc_votequorum.h>
#include "util.h"
struct votequorum_inst {
qb_ipcc_connection_t *c;
int finalize;
void *context;
votequorum_callbacks_t callbacks;
};
static void votequorum_inst_free (void *inst);
DECLARE_HDB_DATABASE(votequorum_handle_t_db, votequorum_inst_free);
cs_error_t votequorum_initialize (
votequorum_handle_t *handle,
votequorum_callbacks_t *callbacks)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
error = hdb_error_to_cs(hdb_handle_create (&votequorum_handle_t_db, sizeof (struct votequorum_inst), handle));
if (error != CS_OK) {
goto error_no_destroy;
}
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, *handle, (void *)&votequorum_inst));
if (error != CS_OK) {
goto error_destroy;
}
votequorum_inst->finalize = 0;
votequorum_inst->c = qb_ipcc_connect ("votequorum", IPC_REQUEST_SIZE);
if (votequorum_inst->c == NULL) {
error = qb_to_cs_error(-errno);
goto error_put_destroy;
}
if (callbacks)
memcpy(&votequorum_inst->callbacks, callbacks, sizeof (*callbacks));
else
memset(&votequorum_inst->callbacks, 0, sizeof (*callbacks));
hdb_handle_put (&votequorum_handle_t_db, *handle);
return (CS_OK);
error_put_destroy:
hdb_handle_put (&votequorum_handle_t_db, *handle);
error_destroy:
hdb_handle_destroy (&votequorum_handle_t_db, *handle);
error_no_destroy:
return (error);
}
static void votequorum_inst_free (void *inst)
{
struct votequorum_inst *vq_inst = (struct votequorum_inst *)inst;
qb_ipcc_disconnect(vq_inst->c);
}
cs_error_t votequorum_finalize (
votequorum_handle_t handle)
{
struct votequorum_inst *votequorum_inst;
cs_error_t error;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
/*
* Another thread has already started finalizing
*/
if (votequorum_inst->finalize) {
hdb_handle_put (&votequorum_handle_t_db, handle);
return (CS_ERR_BAD_HANDLE);
}
votequorum_inst->finalize = 1;
hdb_handle_destroy (&votequorum_handle_t_db, handle);
hdb_handle_put (&votequorum_handle_t_db, handle);
return (CS_OK);
}
cs_error_t votequorum_getinfo (
votequorum_handle_t handle,
unsigned int nodeid,
struct votequorum_info *info)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_getinfo req_lib_votequorum_getinfo;
struct res_lib_votequorum_getinfo res_lib_votequorum_getinfo;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_getinfo.header.size = sizeof (struct req_lib_votequorum_getinfo);
req_lib_votequorum_getinfo.header.id = MESSAGE_REQ_VOTEQUORUM_GETINFO;
req_lib_votequorum_getinfo.nodeid = nodeid;
iov.iov_base = (char *)&req_lib_votequorum_getinfo;
iov.iov_len = sizeof (struct req_lib_votequorum_getinfo);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_getinfo,
sizeof (struct res_lib_votequorum_getinfo), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_getinfo.header.error;
info->node_id = res_lib_votequorum_getinfo.nodeid;
info->node_state = res_lib_votequorum_getinfo.state;
info->node_votes = res_lib_votequorum_getinfo.votes;
info->node_expected_votes = res_lib_votequorum_getinfo.expected_votes;
info->highest_expected = res_lib_votequorum_getinfo.highest_expected;
info->total_votes = res_lib_votequorum_getinfo.total_votes;
info->quorum = res_lib_votequorum_getinfo.quorum;
info->flags = res_lib_votequorum_getinfo.flags;
info->qdevice_votes = res_lib_votequorum_getinfo.qdevice_votes;
memset(info->qdevice_name, 0, VOTEQUORUM_QDEVICE_MAX_NAME_LEN);
strcpy(info->qdevice_name, res_lib_votequorum_getinfo.qdevice_name);
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_setexpected (
votequorum_handle_t handle,
unsigned int expected_votes)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_setexpected req_lib_votequorum_setexpected;
struct res_lib_votequorum_status res_lib_votequorum_status;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_setexpected.header.size = sizeof (struct req_lib_votequorum_setexpected);
req_lib_votequorum_setexpected.header.id = MESSAGE_REQ_VOTEQUORUM_SETEXPECTED;
req_lib_votequorum_setexpected.expected_votes = expected_votes;
iov.iov_base = (char *)&req_lib_votequorum_setexpected;
iov.iov_len = sizeof (struct req_lib_votequorum_setexpected);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_setvotes (
votequorum_handle_t handle,
unsigned int nodeid,
unsigned int votes)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_setvotes req_lib_votequorum_setvotes;
struct res_lib_votequorum_status res_lib_votequorum_status;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_setvotes.header.size = sizeof (struct req_lib_votequorum_setvotes);
req_lib_votequorum_setvotes.header.id = MESSAGE_REQ_VOTEQUORUM_SETVOTES;
req_lib_votequorum_setvotes.nodeid = nodeid;
req_lib_votequorum_setvotes.votes = votes;
iov.iov_base = (char *)&req_lib_votequorum_setvotes;
iov.iov_len = sizeof (struct req_lib_votequorum_setvotes);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_trackstart (
votequorum_handle_t handle,
uint64_t context,
unsigned int flags)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_trackstart req_lib_votequorum_trackstart;
struct res_lib_votequorum_status res_lib_votequorum_status;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_trackstart.header.size = sizeof (struct req_lib_votequorum_trackstart);
req_lib_votequorum_trackstart.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTART;
req_lib_votequorum_trackstart.track_flags = flags;
req_lib_votequorum_trackstart.context = context;
iov.iov_base = (char *)&req_lib_votequorum_trackstart;
iov.iov_len = sizeof (struct req_lib_votequorum_trackstart);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_trackstop (
votequorum_handle_t handle)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_general req_lib_votequorum_general;
struct res_lib_votequorum_status res_lib_votequorum_status;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_general.header.size = sizeof (struct req_lib_votequorum_general);
req_lib_votequorum_general.header.id = MESSAGE_REQ_VOTEQUORUM_TRACKSTOP;
iov.iov_base = (char *)&req_lib_votequorum_general;
iov.iov_len = sizeof (struct req_lib_votequorum_general);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_context_get (
votequorum_handle_t handle,
void **context)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
*context = votequorum_inst->context;
hdb_handle_put (&votequorum_handle_t_db, handle);
return (CS_OK);
}
cs_error_t votequorum_context_set (
votequorum_handle_t handle,
void *context)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
votequorum_inst->context = context;
hdb_handle_put (&votequorum_handle_t_db, handle);
return (CS_OK);
}
cs_error_t votequorum_fd_get (
votequorum_handle_t handle,
int *fd)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
error = qb_to_cs_error(qb_ipcc_fd_get (votequorum_inst->c, fd));
(void)hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_dispatch (
votequorum_handle_t handle,
cs_dispatch_flags_t dispatch_types)
{
int timeout = -1;
cs_error_t error;
int cont = 1; /* always continue do loop except when set to 0 */
struct votequorum_inst *votequorum_inst;
votequorum_callbacks_t callbacks;
struct qb_ipc_response_header *dispatch_data;
struct res_lib_votequorum_quorum_notification *res_lib_votequorum_quorum_notification;
struct res_lib_votequorum_nodelist_notification *res_lib_votequorum_nodelist_notification;
struct res_lib_votequorum_expectedvotes_notification *res_lib_votequorum_expectedvotes_notification;
char dispatch_buf[IPC_DISPATCH_SIZE];
votequorum_ring_id_t ring_id;
if (dispatch_types != CS_DISPATCH_ONE &&
dispatch_types != CS_DISPATCH_ALL &&
dispatch_types != CS_DISPATCH_BLOCKING &&
dispatch_types != CS_DISPATCH_ONE_NONBLOCKING) {
return (CS_ERR_INVALID_PARAM);
}
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle,
(void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
/*
* Timeout instantly for CS_DISPATCH_ONE_NONBLOCKING or CS_DISPATCH_ALL and
* wait indefinately for CS_DISPATCH_ONE or CS_DISPATCH_BLOCKING
*/
if (dispatch_types == CS_DISPATCH_ALL || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
timeout = 0;
}
dispatch_data = (struct qb_ipc_response_header *)dispatch_buf;
do {
error = qb_to_cs_error (qb_ipcc_event_recv (
votequorum_inst->c,
dispatch_buf,
IPC_DISPATCH_SIZE,
timeout));
if (error == CS_ERR_BAD_HANDLE) {
error = CS_OK;
goto error_put;
}
if (error == CS_ERR_TRY_AGAIN) {
if (dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
/*
* Don't mask error
*/
goto error_put;
}
error = CS_OK;
if (dispatch_types == CS_DISPATCH_ALL) {
break; /* exit do while cont is 1 loop */
} else {
continue; /* next poll */
}
}
if (error != CS_OK) {
goto error_put;
}
/*
* Make copy of callbacks, message data, unlock instance, and call callback
* A risk of this dispatch method is that the callback routines may
* operate at the same time that votequorum_finalize has been called in another thread.
*/
memcpy (&callbacks, &votequorum_inst->callbacks, sizeof (votequorum_callbacks_t));
/*
* Dispatch incoming message
*/
switch (dispatch_data->id) {
case MESSAGE_RES_VOTEQUORUM_QUORUM_NOTIFICATION:
if (callbacks.votequorum_quorum_notify_fn == NULL) {
break;
}
res_lib_votequorum_quorum_notification = (struct res_lib_votequorum_quorum_notification *)dispatch_data;
callbacks.votequorum_quorum_notify_fn ( handle,
res_lib_votequorum_quorum_notification->context,
res_lib_votequorum_quorum_notification->quorate,
res_lib_votequorum_quorum_notification->node_list_entries,
(votequorum_node_t *)res_lib_votequorum_quorum_notification->node_list );
break;
case MESSAGE_RES_VOTEQUORUM_NODELIST_NOTIFICATION:
if (callbacks.votequorum_nodelist_notify_fn == NULL) {
break;
}
res_lib_votequorum_nodelist_notification = (struct res_lib_votequorum_nodelist_notification *)dispatch_data;
marshall_from_mar_votequorum_ring_id (&ring_id, &res_lib_votequorum_nodelist_notification->ring_id);
callbacks.votequorum_nodelist_notify_fn ( handle,
res_lib_votequorum_nodelist_notification->context,
ring_id,
res_lib_votequorum_nodelist_notification->node_list_entries,
res_lib_votequorum_nodelist_notification->node_list );
break;
case MESSAGE_RES_VOTEQUORUM_EXPECTEDVOTES_NOTIFICATION:
if (callbacks.votequorum_expectedvotes_notify_fn == NULL) {
break;
}
res_lib_votequorum_expectedvotes_notification = (struct res_lib_votequorum_expectedvotes_notification *)dispatch_data;
callbacks.votequorum_expectedvotes_notify_fn ( handle,
res_lib_votequorum_expectedvotes_notification->context,
res_lib_votequorum_expectedvotes_notification->expected_votes);
break;
default:
error = CS_ERR_LIBRARY;
goto error_put;
break;
}
if (votequorum_inst->finalize) {
/*
* If the finalize has been called then get out of the dispatch.
*/
error = CS_ERR_BAD_HANDLE;
goto error_put;
}
/*
* Determine if more messages should be processed
*/
if (dispatch_types == CS_DISPATCH_ONE || dispatch_types == CS_DISPATCH_ONE_NONBLOCKING) {
cont = 0;
}
} while (cont);
error_put:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_qdevice_register (
votequorum_handle_t handle,
const char *name)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_qdevice_register req_lib_votequorum_qdevice_register;
struct res_lib_votequorum_status res_lib_votequorum_status;
if ((strlen(name) == 0) ||
(strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
return CS_ERR_INVALID_PARAM;
}
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_qdevice_register.header.size = sizeof (struct req_lib_votequorum_qdevice_register);
req_lib_votequorum_qdevice_register.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_REGISTER;
strcpy(req_lib_votequorum_qdevice_register.name, name);
iov.iov_base = (char *)&req_lib_votequorum_qdevice_register;
iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_register);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_qdevice_poll (
votequorum_handle_t handle,
const char *name,
unsigned int cast_vote,
votequorum_ring_id_t ring_id)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_qdevice_poll req_lib_votequorum_qdevice_poll;
struct res_lib_votequorum_status res_lib_votequorum_status;
if ((strlen(name) == 0) ||
(strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
return CS_ERR_INVALID_PARAM;
}
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_qdevice_poll.header.size = sizeof (struct req_lib_votequorum_qdevice_poll);
req_lib_votequorum_qdevice_poll.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_POLL;
strcpy(req_lib_votequorum_qdevice_poll.name, name);
req_lib_votequorum_qdevice_poll.cast_vote = cast_vote;
marshall_to_mar_votequorum_ring_id(&req_lib_votequorum_qdevice_poll.ring_id, &ring_id);
iov.iov_base = (char *)&req_lib_votequorum_qdevice_poll;
iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_poll);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_qdevice_master_wins (
votequorum_handle_t handle,
const char *name,
unsigned int allow)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_qdevice_master_wins req_lib_votequorum_qdevice_master_wins;
struct res_lib_votequorum_status res_lib_votequorum_status;
if ((strlen(name) == 0) ||
(strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
return CS_ERR_INVALID_PARAM;
}
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_qdevice_master_wins.header.size = sizeof (struct req_lib_votequorum_qdevice_master_wins);
req_lib_votequorum_qdevice_master_wins.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_MASTER_WINS;
strcpy(req_lib_votequorum_qdevice_master_wins.name, name);
req_lib_votequorum_qdevice_master_wins.allow = allow;
iov.iov_base = (char *)&req_lib_votequorum_qdevice_master_wins;
iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_master_wins);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_qdevice_update (
votequorum_handle_t handle,
const char *oldname,
const char *newname)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_qdevice_update req_lib_votequorum_qdevice_update;
struct res_lib_votequorum_status res_lib_votequorum_status;
if ((strlen(oldname) == 0) ||
(strlen(oldname) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN) ||
(strlen(newname) == 0) ||
(strlen(newname) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
return CS_ERR_INVALID_PARAM;
}
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_qdevice_update.header.size = sizeof (struct req_lib_votequorum_qdevice_update);
req_lib_votequorum_qdevice_update.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UPDATE;
strcpy(req_lib_votequorum_qdevice_update.oldname, oldname);
strcpy(req_lib_votequorum_qdevice_update.newname, newname);
iov.iov_base = (char *)&req_lib_votequorum_qdevice_update;
iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_update);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
cs_error_t votequorum_qdevice_unregister (
votequorum_handle_t handle,
const char *name)
{
cs_error_t error;
struct votequorum_inst *votequorum_inst;
struct iovec iov;
struct req_lib_votequorum_qdevice_unregister req_lib_votequorum_qdevice_unregister;
struct res_lib_votequorum_status res_lib_votequorum_status;
if ((strlen(name) == 0) ||
(strlen(name) >= VOTEQUORUM_QDEVICE_MAX_NAME_LEN)) {
return CS_ERR_INVALID_PARAM;
}
error = hdb_error_to_cs(hdb_handle_get (&votequorum_handle_t_db, handle, (void *)&votequorum_inst));
if (error != CS_OK) {
return (error);
}
req_lib_votequorum_qdevice_unregister.header.size = sizeof (struct req_lib_votequorum_qdevice_unregister);
req_lib_votequorum_qdevice_unregister.header.id = MESSAGE_REQ_VOTEQUORUM_QDEVICE_UNREGISTER;
strcpy(req_lib_votequorum_qdevice_unregister.name, name);
iov.iov_base = (char *)&req_lib_votequorum_qdevice_unregister;
iov.iov_len = sizeof (struct req_lib_votequorum_qdevice_unregister);
error = qb_to_cs_error(qb_ipcc_sendv_recv (
votequorum_inst->c,
&iov,
1,
&res_lib_votequorum_status,
sizeof (struct res_lib_votequorum_status), CS_IPC_TIMEOUT_MS));
if (error != CS_OK) {
goto error_exit;
}
error = res_lib_votequorum_status.header.error;
error_exit:
hdb_handle_put (&votequorum_handle_t_db, handle);
return (error);
}
|