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
|
/*
* Copyright (c) 2008-2020 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 Red Hat 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 CONTRIBUTORS "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.
*/
#include <config.h>
#include <pwd.h>
#include <grp.h>
#include <sys/types.h>
#include <sys/poll.h>
#include <sys/uio.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sched.h>
#include <time.h>
#include "quorum.h"
#include <corosync/corotypes.h>
#include <qb/qbipc_common.h>
#include <corosync/corodefs.h>
#include <corosync/swab.h>
#include <qb/qblist.h>
#include <corosync/mar_gen.h>
#include <corosync/ipc_quorum.h>
#include <corosync/coroapi.h>
#include <corosync/logsys.h>
#include <corosync/icmap.h>
#include "service.h"
#include "votequorum.h"
#include "vsf_ykd.h"
LOGSYS_DECLARE_SUBSYS ("QUORUM");
struct quorum_pd {
unsigned char track_flags;
int tracking_enabled;
struct qb_list_head list;
void *conn;
enum lib_quorum_model model;
};
struct internal_callback_pd {
struct qb_list_head list;
quorum_callback_fn_t callback;
void *context;
};
static void quorum_sync_init (
const unsigned int *trans_list,
size_t trans_list_entries,
const unsigned int *member_list,
size_t member_list_entries,
const struct memb_ring_id *ring_id);
static int quorum_sync_process (void);
static void quorum_sync_activate (void);
static void quorum_sync_abort (void);
static void message_handler_req_lib_quorum_getquorate (void *conn,
const void *msg);
static void message_handler_req_lib_quorum_trackstart (void *conn,
const void *msg);
static void message_handler_req_lib_quorum_trackstop (void *conn,
const void *msg);
static void message_handler_req_lib_quorum_gettype (void *conn,
const void *msg);
static void message_handler_req_lib_quorum_model_gettype (void *conn,
const void *msg);
static void send_library_notification(void *conn);
static void send_internal_notification(void);
static void send_nodelist_library_notification(void *conn, int send_joined_left_list);
static char *quorum_exec_init_fn (struct corosync_api_v1 *api);
static int quorum_lib_init_fn (void *conn);
static int quorum_lib_exit_fn (void *conn);
static int primary_designated = 0;
static int quorum_type = 0;
static struct corosync_api_v1 *corosync_api;
static struct qb_list_head lib_trackers_list;
static struct qb_list_head internal_trackers_list;
static struct memb_ring_id quorum_ring_id;
static struct memb_ring_id last_sync_ring_id;
static size_t quorum_view_list_entries = 0;
static int quorum_view_list[PROCESSOR_COUNT_MAX];
struct quorum_services_api_ver1 *quorum_iface = NULL;
static char view_buf[64];
static unsigned int my_member_list[PROCESSOR_COUNT_MAX];
static size_t my_member_list_entries;
static unsigned int my_old_member_list[PROCESSOR_COUNT_MAX];
static size_t my_old_member_list_entries = 0;
static unsigned int my_left_list[PROCESSOR_COUNT_MAX];
static size_t my_left_list_entries;
static unsigned int my_joined_list[PROCESSOR_COUNT_MAX];
static size_t my_joined_list_entries;
static void log_view_list(const unsigned int *view_list, size_t view_list_entries,
const char *view_list_type_str)
{
int total = (int)view_list_entries;
int len, pos, ret;
int i = 0;
while (1) {
len = sizeof(view_buf);
pos = 0;
memset(view_buf, 0, len);
for (; i < total; i++) {
ret = snprintf(view_buf + pos, len - pos, " " CS_PRI_NODE_ID, view_list[i]);
if (ret >= len - pos)
break;
pos += ret;
}
log_printf (LOGSYS_LEVEL_NOTICE, "%s[%d]:%s%s",
view_list_type_str, total, view_buf, i < total ? "\\" : "");
if (i == total)
break;
}
}
/* Internal quorum API function */
static void quorum_api_set_quorum(const unsigned int *view_list,
size_t view_list_entries,
int quorum, struct memb_ring_id *ring_id)
{
int old_quorum = primary_designated;
primary_designated = quorum;
if (primary_designated && !old_quorum) {
log_printf (LOGSYS_LEVEL_NOTICE, "This node is within the primary component and will provide service.");
} else if (!primary_designated && old_quorum) {
log_printf (LOGSYS_LEVEL_NOTICE, "This node is within the non-primary component and will NOT provide any services.");
}
quorum_view_list_entries = view_list_entries;
memcpy(&quorum_ring_id, ring_id, sizeof (quorum_ring_id));
memcpy(quorum_view_list, view_list, sizeof(unsigned int)*view_list_entries);
log_view_list(view_list, view_list_entries, "Members");
/* Tell internal listeners */
send_internal_notification();
/* Tell IPC listeners */
send_library_notification(NULL);
}
static struct corosync_lib_handler quorum_lib_service[] =
{
{ /* 0 */
.lib_handler_fn = message_handler_req_lib_quorum_getquorate,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
},
{ /* 1 */
.lib_handler_fn = message_handler_req_lib_quorum_trackstart,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
},
{ /* 2 */
.lib_handler_fn = message_handler_req_lib_quorum_trackstop,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
},
{ /* 3 */
.lib_handler_fn = message_handler_req_lib_quorum_gettype,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
},
{ /* 4 */
.lib_handler_fn = message_handler_req_lib_quorum_model_gettype,
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED
}
};
static struct corosync_service_engine quorum_service_handler = {
.name = "corosync cluster quorum service v0.1",
.id = QUORUM_SERVICE,
.priority = 1,
.private_data_size = sizeof (struct quorum_pd),
.flow_control = CS_LIB_FLOW_CONTROL_NOT_REQUIRED,
.allow_inquorate = CS_LIB_ALLOW_INQUORATE,
.lib_init_fn = quorum_lib_init_fn,
.lib_exit_fn = quorum_lib_exit_fn,
.lib_engine = quorum_lib_service,
.exec_init_fn = quorum_exec_init_fn,
.sync_init = quorum_sync_init,
.sync_process = quorum_sync_process,
.sync_activate = quorum_sync_activate,
.sync_abort = quorum_sync_abort,
.lib_engine_count = sizeof (quorum_lib_service) / sizeof (struct corosync_lib_handler)
};
struct corosync_service_engine *vsf_quorum_get_service_engine_ver0 (void)
{
return (&quorum_service_handler);
}
/* -------------------------------------------------- */
/*
* Internal API functions for corosync
*/
static int quorum_quorate(void)
{
return primary_designated;
}
static int quorum_register_callback(quorum_callback_fn_t function, void *context)
{
struct internal_callback_pd *pd = malloc(sizeof(struct internal_callback_pd));
if (!pd)
return -1;
pd->context = context;
pd->callback = function;
qb_list_add (&pd->list, &internal_trackers_list);
return 0;
}
static int quorum_unregister_callback(quorum_callback_fn_t function, void *context)
{
struct internal_callback_pd *pd;
struct qb_list_head *tmp, *tmp_iter;
qb_list_for_each_safe(tmp, tmp_iter, &internal_trackers_list) {
pd = qb_list_entry(tmp, struct internal_callback_pd, list);
if (pd->callback == function && pd->context == context) {
qb_list_del(&pd->list);
free(pd);
return 0;
}
}
return -1;
}
static struct quorum_callin_functions callins = {
.quorate = quorum_quorate,
.register_callback = quorum_register_callback,
.unregister_callback = quorum_unregister_callback
};
/* --------------------------------------------------------------------- */
static void quorum_sync_init (
const unsigned int *trans_list,
size_t trans_list_entries,
const unsigned int *member_list,
size_t member_list_entries,
const struct memb_ring_id *ring_id)
{
int found;
int i, j;
int entries;
int node_joined;
memcpy (my_member_list, member_list, member_list_entries *
sizeof (unsigned int));
my_member_list_entries = member_list_entries;
last_sync_ring_id = *ring_id;
/*
* Determine left list of nodeids
*/
entries = 0;
for (i = 0; i < my_old_member_list_entries; i++) {
found = 0;
for (j = 0; j < trans_list_entries; j++) {
if (my_old_member_list[i] == trans_list[j]) {
found = 1;
break;
}
}
if (found == 0) {
my_left_list[entries++] = my_old_member_list[i];
} else {
/*
* Check it is really in new membership
*/
found = 0;
for (j = 0; j < my_member_list_entries; j++) {
if (my_old_member_list[i] == my_member_list[j]) {
found = 1;
break;
}
}
/*
* Node is in both old_member_list and trans list but not in my_member_list.
* (This shouldn't really happen).
*/
if (!found) {
my_left_list[entries++] = my_old_member_list[i];
}
}
}
my_left_list_entries = entries;
/*
* Determine joined list of nodeids
*/
entries = 0;
for (i = 0; i < my_member_list_entries; i++) {
node_joined = 1;
for (j = 0; j < my_old_member_list_entries; j++) {
if (my_member_list[i] == my_old_member_list[j]) {
/*
* Node is in member list and also in my_old_member list -> check
* if it is in left_list.
*/
node_joined = 0;
break;
}
}
if (!node_joined) {
/*
* Check if node is in left list.
*/
for (j = 0; j < my_left_list_entries; j++) {
if (my_member_list[i] == my_left_list[j]) {
/*
* Node is both in left and also in member list -> joined
*/
node_joined = 1;
break;
}
}
}
if (node_joined) {
my_joined_list[entries++] = my_member_list[i];
}
}
my_joined_list_entries = entries;
log_view_list(my_member_list, my_member_list_entries, "Sync members");
if (my_joined_list_entries > 0) {
log_view_list(my_joined_list, my_joined_list_entries, "Sync joined");
}
if (my_left_list_entries > 0) {
log_view_list(my_left_list, my_left_list_entries, "Sync left");
}
}
static int quorum_sync_process (void)
{
return (0);
}
static void quorum_sync_activate (void)
{
memcpy (my_old_member_list, my_member_list,
my_member_list_entries * sizeof (unsigned int));
my_old_member_list_entries = my_member_list_entries;
/* Tell IPC listeners */
send_nodelist_library_notification(NULL, 1);
}
static void quorum_sync_abort (void)
{
}
static char *quorum_exec_init_fn (struct corosync_api_v1 *api)
{
char *quorum_module = NULL;
char *error;
corosync_api = api;
qb_list_init (&lib_trackers_list);
qb_list_init (&internal_trackers_list);
/*
* Tell corosync we have a quorum engine.
*/
api->quorum_initialize(&callins);
/*
* Look for a quorum provider
*/
if (icmap_get_string("quorum.provider", &quorum_module) == CS_OK) {
log_printf (LOGSYS_LEVEL_NOTICE,
"Using quorum provider %s", quorum_module);
error = (char *)"Invalid quorum provider";
if (strcmp (quorum_module, "corosync_votequorum") == 0) {
error = votequorum_init (api, quorum_api_set_quorum);
quorum_type = 1;
}
if (strcmp (quorum_module, "corosync_ykd") == 0) {
error = ykd_init (api, quorum_api_set_quorum);
quorum_type = 1;
}
if (error) {
log_printf (LOGSYS_LEVEL_CRIT,
"Quorum provider: %s failed to initialize.",
quorum_module);
free(quorum_module);
return (error);
}
}
if (quorum_module) {
free(quorum_module);
quorum_module = NULL;
}
/*
* setting quorum_type and primary_designated in the right order is important
* always try to lookup/init a quorum module, then revert back to be quorate
*/
if (quorum_type == 0) {
primary_designated = 1;
}
return (NULL);
}
static int quorum_lib_init_fn (void *conn)
{
struct quorum_pd *pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
log_printf(LOGSYS_LEVEL_DEBUG, "lib_init_fn: conn=%p", conn);
qb_list_init (&pd->list);
pd->conn = conn;
pd->model = LIB_QUORUM_MODEL_V0;
return (0);
}
static int quorum_lib_exit_fn (void *conn)
{
struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
log_printf(LOGSYS_LEVEL_DEBUG, "lib_exit_fn: conn=%p", conn);
if (quorum_pd->tracking_enabled) {
qb_list_del (&quorum_pd->list);
qb_list_init (&quorum_pd->list);
}
return (0);
}
static void send_internal_notification(void)
{
struct qb_list_head *tmp;
struct internal_callback_pd *pd;
qb_list_for_each(tmp, &internal_trackers_list) {
pd = qb_list_entry(tmp, struct internal_callback_pd, list);
pd->callback(primary_designated, pd->context);
}
}
static void prepare_library_notification_v0(char *buf, size_t size)
{
struct res_lib_quorum_notification *res_lib_quorum_notification = (struct res_lib_quorum_notification *)buf;
int i;
res_lib_quorum_notification->quorate = primary_designated;
res_lib_quorum_notification->ring_seq = quorum_ring_id.seq;
res_lib_quorum_notification->view_list_entries = quorum_view_list_entries;
for (i=0; i<quorum_view_list_entries; i++) {
res_lib_quorum_notification->view_list[i] = quorum_view_list[i];
}
res_lib_quorum_notification->header.id = MESSAGE_RES_QUORUM_NOTIFICATION;
res_lib_quorum_notification->header.size = size;
res_lib_quorum_notification->header.error = CS_OK;
}
static void prepare_library_notification_v1(char *buf, size_t size)
{
struct res_lib_quorum_v1_quorum_notification *res_lib_quorum_v1_quorum_notification =
(struct res_lib_quorum_v1_quorum_notification *)buf;
int i;
res_lib_quorum_v1_quorum_notification->quorate = primary_designated;
res_lib_quorum_v1_quorum_notification->ring_id.nodeid = quorum_ring_id.nodeid;
res_lib_quorum_v1_quorum_notification->ring_id.seq = quorum_ring_id.seq;
res_lib_quorum_v1_quorum_notification->view_list_entries = quorum_view_list_entries;
for (i=0; i<quorum_view_list_entries; i++) {
res_lib_quorum_v1_quorum_notification->view_list[i] = quorum_view_list[i];
}
res_lib_quorum_v1_quorum_notification->header.id = MESSAGE_RES_QUORUM_V1_QUORUM_NOTIFICATION;
res_lib_quorum_v1_quorum_notification->header.size = size;
res_lib_quorum_v1_quorum_notification->header.error = CS_OK;
}
static void send_library_notification(void *conn)
{
int size_v0 = sizeof(struct res_lib_quorum_notification) +
sizeof(mar_uint32_t) * quorum_view_list_entries;
int size_v1 = sizeof(struct res_lib_quorum_v1_quorum_notification) +
sizeof(mar_uint32_t)*quorum_view_list_entries;
char buf_v0[size_v0];
char buf_v1[size_v1];
struct res_lib_quorum_notification *res_lib_quorum_notification =
(struct res_lib_quorum_notification *)buf_v0;
struct res_lib_quorum_v1_quorum_notification *res_lib_quorum_v1_quorum_notification =
(struct res_lib_quorum_v1_quorum_notification *)buf_v1;
struct quorum_pd *qpd;
struct qb_list_head *tmp;
log_printf(LOGSYS_LEVEL_DEBUG, "sending quorum notification to %p, length = %u/%u", conn, size_v0, size_v1);
prepare_library_notification_v0(buf_v0, size_v0);
prepare_library_notification_v1(buf_v1, size_v1);
/* Send it to all interested parties */
if (conn) {
qpd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
if (qpd->model == LIB_QUORUM_MODEL_V0) {
corosync_api->ipc_dispatch_send(conn, res_lib_quorum_notification, size_v0);
} else if (qpd->model == LIB_QUORUM_MODEL_V1) {
corosync_api->ipc_dispatch_send(conn, res_lib_quorum_v1_quorum_notification, size_v1);
}
}
else {
qb_list_for_each(tmp, &lib_trackers_list) {
qpd = qb_list_entry(tmp, struct quorum_pd, list);
if (qpd->model == LIB_QUORUM_MODEL_V0) {
corosync_api->ipc_dispatch_send(qpd->conn,
res_lib_quorum_notification, size_v0);
} else if (qpd->model == LIB_QUORUM_MODEL_V1) {
corosync_api->ipc_dispatch_send(qpd->conn,
res_lib_quorum_v1_quorum_notification, size_v1);
}
}
}
return;
}
static void send_nodelist_library_notification(void *conn, int send_joined_left_list)
{
int size = sizeof(struct res_lib_quorum_v1_nodelist_notification) +
sizeof(mar_uint32_t) * my_member_list_entries;
char *buf;
struct res_lib_quorum_v1_nodelist_notification *res_lib_quorum_v1_nodelist_notification;
struct quorum_pd *qpd;
struct qb_list_head *tmp;
mar_uint32_t *ptr;
int i;
if (send_joined_left_list) {
size += sizeof(mar_uint32_t) * my_joined_list_entries;
size += sizeof(mar_uint32_t) * my_left_list_entries;
}
buf = alloca(size);
memset(buf, 0, size);
res_lib_quorum_v1_nodelist_notification = (struct res_lib_quorum_v1_nodelist_notification *)buf;
res_lib_quorum_v1_nodelist_notification->ring_id.nodeid = last_sync_ring_id.nodeid;
res_lib_quorum_v1_nodelist_notification->ring_id.seq = last_sync_ring_id.seq;
res_lib_quorum_v1_nodelist_notification->member_list_entries = my_member_list_entries;
if (send_joined_left_list) {
res_lib_quorum_v1_nodelist_notification->joined_list_entries = my_joined_list_entries;
res_lib_quorum_v1_nodelist_notification->left_list_entries = my_left_list_entries;
}
ptr = res_lib_quorum_v1_nodelist_notification->member_list;
for (i=0; i<my_member_list_entries; i++, ptr++) {
*ptr = my_member_list[i];
}
if (send_joined_left_list) {
for (i=0; i<my_joined_list_entries; i++, ptr++) {
*ptr = my_joined_list[i];
}
for (i=0; i<my_left_list_entries; i++, ptr++) {
*ptr = my_left_list[i];
}
}
res_lib_quorum_v1_nodelist_notification->header.id = MESSAGE_RES_QUORUM_V1_NODELIST_NOTIFICATION;
res_lib_quorum_v1_nodelist_notification->header.size = size;
res_lib_quorum_v1_nodelist_notification->header.error = CS_OK;
log_printf(LOGSYS_LEVEL_DEBUG, "sending nodelist notification to %p, length = %u", conn, size);
/* Send it to all interested parties */
if (conn) {
qpd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
if (qpd->model == LIB_QUORUM_MODEL_V1) {
corosync_api->ipc_dispatch_send(conn, res_lib_quorum_v1_nodelist_notification, size);
}
}
else {
qb_list_for_each(tmp, &lib_trackers_list) {
qpd = qb_list_entry(tmp, struct quorum_pd, list);
if (qpd->model == LIB_QUORUM_MODEL_V1) {
corosync_api->ipc_dispatch_send(qpd->conn,
res_lib_quorum_v1_nodelist_notification, size);
}
}
}
return;
}
static void message_handler_req_lib_quorum_getquorate (void *conn,
const void *msg)
{
struct res_lib_quorum_getquorate res_lib_quorum_getquorate;
log_printf(LOGSYS_LEVEL_DEBUG, "got quorate request on %p", conn);
/* send status */
res_lib_quorum_getquorate.quorate = primary_designated;
res_lib_quorum_getquorate.header.size = sizeof(res_lib_quorum_getquorate);
res_lib_quorum_getquorate.header.id = MESSAGE_RES_QUORUM_GETQUORATE;
res_lib_quorum_getquorate.header.error = CS_OK;
corosync_api->ipc_response_send(conn, &res_lib_quorum_getquorate, sizeof(res_lib_quorum_getquorate));
}
static void message_handler_req_lib_quorum_trackstart (void *conn,
const void *msg)
{
const struct req_lib_quorum_trackstart *req_lib_quorum_trackstart = msg;
struct qb_ipc_response_header res;
struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
cs_error_t error = CS_OK;
log_printf(LOGSYS_LEVEL_DEBUG, "got trackstart request on %p", conn);
/*
* If an immediate listing of the current cluster membership
* is requested, generate membership list
*/
if (req_lib_quorum_trackstart->track_flags & CS_TRACK_CURRENT ||
req_lib_quorum_trackstart->track_flags & CS_TRACK_CHANGES) {
log_printf(LOGSYS_LEVEL_DEBUG, "sending initial status to %p", conn);
send_nodelist_library_notification(conn, 0);
send_library_notification(conn);
}
if (quorum_pd->tracking_enabled) {
error = CS_ERR_EXIST;
goto response_send;
}
/*
* Record requests for tracking
*/
if (req_lib_quorum_trackstart->track_flags & CS_TRACK_CHANGES ||
req_lib_quorum_trackstart->track_flags & CS_TRACK_CHANGES_ONLY) {
quorum_pd->track_flags = req_lib_quorum_trackstart->track_flags;
quorum_pd->tracking_enabled = 1;
qb_list_add (&quorum_pd->list, &lib_trackers_list);
}
response_send:
/* send status */
res.size = sizeof(res);
res.id = MESSAGE_RES_QUORUM_TRACKSTART;
res.error = error;
corosync_api->ipc_response_send(conn, &res, sizeof(struct qb_ipc_response_header));
}
static void message_handler_req_lib_quorum_trackstop (void *conn, const void *msg)
{
struct qb_ipc_response_header res;
struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
log_printf(LOGSYS_LEVEL_DEBUG, "got trackstop request on %p", conn);
if (quorum_pd->tracking_enabled) {
res.error = CS_OK;
quorum_pd->tracking_enabled = 0;
qb_list_del (&quorum_pd->list);
qb_list_init (&quorum_pd->list);
} else {
res.error = CS_ERR_NOT_EXIST;
}
/* send status */
res.size = sizeof(res);
res.id = MESSAGE_RES_QUORUM_TRACKSTOP;
res.error = CS_OK;
corosync_api->ipc_response_send(conn, &res, sizeof(struct qb_ipc_response_header));
}
static void message_handler_req_lib_quorum_gettype (void *conn,
const void *msg)
{
struct res_lib_quorum_gettype res_lib_quorum_gettype;
log_printf(LOGSYS_LEVEL_DEBUG, "got quorum_type request on %p", conn);
/* send status */
res_lib_quorum_gettype.quorum_type = quorum_type;
res_lib_quorum_gettype.header.size = sizeof(res_lib_quorum_gettype);
res_lib_quorum_gettype.header.id = MESSAGE_RES_QUORUM_GETTYPE;
res_lib_quorum_gettype.header.error = CS_OK;
corosync_api->ipc_response_send(conn, &res_lib_quorum_gettype, sizeof(res_lib_quorum_gettype));
}
static void message_handler_req_lib_quorum_model_gettype (void *conn,
const void *msg)
{
const struct req_lib_quorum_model_gettype *req_lib_quorum_model_gettype = msg;
struct res_lib_quorum_model_gettype res_lib_quorum_model_gettype;
struct quorum_pd *quorum_pd = (struct quorum_pd *)corosync_api->ipc_private_data_get (conn);
cs_error_t ret_err;
log_printf(LOGSYS_LEVEL_DEBUG, "got quorum_model_type request on %p", conn);
ret_err = CS_OK;
if (req_lib_quorum_model_gettype->model != LIB_QUORUM_MODEL_V0 &&
req_lib_quorum_model_gettype->model != LIB_QUORUM_MODEL_V1) {
log_printf(LOGSYS_LEVEL_ERROR, "quorum_model_type request for unsupported model %u",
req_lib_quorum_model_gettype->model);
ret_err = CS_ERR_INVALID_PARAM;
} else {
quorum_pd->model = req_lib_quorum_model_gettype->model;
}
/* send status */
res_lib_quorum_model_gettype.quorum_type = quorum_type;
res_lib_quorum_model_gettype.header.size = sizeof(res_lib_quorum_model_gettype);
res_lib_quorum_model_gettype.header.id = MESSAGE_RES_QUORUM_MODEL_GETTYPE;
res_lib_quorum_model_gettype.header.error = ret_err;
corosync_api->ipc_response_send(conn, &res_lib_quorum_model_gettype, sizeof(res_lib_quorum_model_gettype));
}
|