~ubuntu-branches/ubuntu/precise/corosync/precise-proposed

« back to all changes in this revision

Viewing changes to exec/totemrrp.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2009-08-21 09:29:56 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090821092956-w9qxxxx3zeoh8dem
Tags: 1.0.0-4ubuntu2
* debian/control:
  - 'Ubuntu Developers' instead of 'Ubuntu Core Developers'
    as maintainer
  - Bump debhelper dependecy to 7

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 2005 MontaVista Software, Inc.
3
 
 * Copyright (c) 2006-2008 Red Hat, Inc.
 
3
 * Copyright (c) 2006-2009 Red Hat, Inc.
4
4
 *
5
5
 * All rights reserved.
6
6
 *
7
7
 * Author: Steven Dake (sdake@redhat.com)
8
8
 *
9
9
 * This software licensed under BSD license, the text of which follows:
10
 
 * 
 
10
 *
11
11
 * Redistribution and use in source and binary forms, with or without
12
12
 * modification, are permitted provided that the following conditions are met:
13
13
 *
33
33
 * THE POSSIBILITY OF SUCH DAMAGE.
34
34
 */
35
35
 
 
36
#include <config.h>
 
37
 
36
38
#include <assert.h>
37
39
#include <pthread.h>
38
40
#include <sys/mman.h>
50
52
#include <stdlib.h>
51
53
#include <stdio.h>
52
54
#include <errno.h>
53
 
#include <signal.h>
54
55
#include <sched.h>
55
56
#include <time.h>
56
57
#include <sys/time.h>
57
58
#include <sys/poll.h>
 
59
#include <limits.h>
58
60
 
59
 
#include <corosync/queue.h>
60
61
#include <corosync/sq.h>
61
62
#include <corosync/list.h>
62
63
#include <corosync/hdb.h>
63
64
#include <corosync/swab.h>
64
65
#include <corosync/totem/coropoll.h>
 
66
#define LOGSYS_UTILS_ONLY 1
 
67
#include <corosync/engine/logsys.h>
65
68
 
66
69
#include "totemnet.h"
67
70
#include "totemrrp.h"
68
71
 
 
72
void rrp_deliver_fn (
 
73
        void *context,
 
74
        const void *msg,
 
75
        unsigned int msg_len);
 
76
 
 
77
void rrp_iface_change_fn (
 
78
        void *context,
 
79
        const struct totem_ip_address *iface_addr);
 
80
 
69
81
struct totemrrp_instance;
70
82
struct passive_instance {
71
83
        struct totemrrp_instance *rrp_instance;
95
107
};
96
108
 
97
109
struct rrp_algo {
98
 
        char *name;
 
110
        const char *name;
99
111
 
100
112
        void * (*initialize) (
101
113
                struct totemrrp_instance *rrp_instance,
105
117
                struct totemrrp_instance *instance,
106
118
                unsigned int iface_no,
107
119
                void *context,
108
 
                void *msg,
 
120
                const void *msg,
109
121
                unsigned int msg_len);
110
122
 
111
123
        void (*mcast_noflush_send) (
112
124
                struct totemrrp_instance *instance,
113
 
                struct iovec *iovec,
114
 
                unsigned int iov_len);
 
125
                const void *msg,
 
126
                unsigned int msg_len);
115
127
 
116
128
        void (*mcast_flush_send) (
117
129
                struct totemrrp_instance *instance,
118
 
                struct iovec *iovec,
119
 
                unsigned int iov_len);
 
130
                const void *msg,
 
131
                unsigned int msg_len);
120
132
 
121
133
        void (*token_recv) (
122
134
                struct totemrrp_instance *instance,
123
135
                unsigned int iface_no,
124
136
                void *context,
125
 
                void *msg,
 
137
                const void *msg,
126
138
                unsigned int msg_len,
127
139
                unsigned int token_seqid);
128
140
 
129
141
        void (*token_send) (
130
142
                struct totemrrp_instance *instance,
131
 
                struct iovec *iovec,
132
 
                unsigned int iov_len);  
 
143
                const void *msg,
 
144
                unsigned int msg_len);
133
145
 
134
146
        void (*recv_flush) (
135
147
                struct totemrrp_instance *instance);
151
163
 
152
164
        void (*ring_reenable) (
153
165
                struct totemrrp_instance *instance);
 
166
 
 
167
        int (*mcast_recv_empty) (
 
168
                struct totemrrp_instance *instance);
154
169
};
155
170
 
156
171
struct totemrrp_instance {
157
 
        poll_handle totemrrp_poll_handle;
 
172
        hdb_handle_t totemrrp_poll_handle;
158
173
 
159
174
        struct totem_interface *interfaces;
160
175
 
161
176
        struct rrp_algo *rrp_algo;
162
177
 
163
178
        void *context;
164
 
        
 
179
 
165
180
        char *status[INTERFACE_MAX];
166
181
 
167
182
        void (*totemrrp_deliver_fn) (
168
183
                void *context,
169
 
                void *msg,
170
 
                int msg_len);
 
184
                const void *msg,
 
185
                unsigned int msg_len);
171
186
 
172
187
        void (*totemrrp_iface_change_fn) (
173
188
                void *context,
174
 
                struct totem_ip_address *iface_addr,
 
189
                const struct totem_ip_address *iface_addr,
175
190
                unsigned int iface_no);
176
191
 
177
192
        void (*totemrrp_token_seqid_get) (
178
 
                void *msg,
 
193
                const void *msg,
179
194
                unsigned int *seqid,
180
195
                unsigned int *token_is);
181
196
 
194
209
 
195
210
        int totemrrp_log_level_debug;
196
211
 
197
 
        void (*totemrrp_log_printf) (char *file, int line, int level, char *format, ...) __attribute__((format(printf, 4, 5)));
198
 
 
199
 
        totemrrp_handle handle;
200
 
 
201
 
        totemnet_handle *net_handles;
 
212
        int totemrrp_subsys_id;
 
213
 
 
214
        void (*totemrrp_log_printf) (
 
215
                unsigned int rec_ident,
 
216
                const char *function,
 
217
                const char *file,
 
218
                int line,
 
219
                const char *format, ...)__attribute__((format(printf, 5, 6)));
 
220
 
 
221
        hdb_handle_t handle;
 
222
 
 
223
        hdb_handle_t *net_handles;
202
224
 
203
225
        void *rrp_algo_instance;
204
226
 
205
227
        int interface_count;
206
228
 
207
 
        int poll_handle;
 
229
        hdb_handle_t poll_handle;
208
230
 
209
231
        int processor_count;
210
232
 
218
240
        struct totemrrp_instance *instance,
219
241
        unsigned int iface_no,
220
242
        void *context,
221
 
        void *msg,
 
243
        const void *msg,
222
244
        unsigned int msg_len);
223
245
 
224
246
static void none_mcast_noflush_send (
225
247
        struct totemrrp_instance *instance,
226
 
        struct iovec *iovec,
227
 
        unsigned int iov_len);
 
248
        const void *msg,
 
249
        unsigned int msg_len);
228
250
 
229
251
static void none_mcast_flush_send (
230
252
        struct totemrrp_instance *instance,
231
 
        struct iovec *iovec,
232
 
        unsigned int iov_len);
 
253
        const void *msg,
 
254
        unsigned int msg_len);
233
255
 
234
256
static void none_token_recv (
235
257
        struct totemrrp_instance *instance,
236
258
        unsigned int iface_no,
237
259
        void *context,
238
 
        void *msg,
 
260
        const void *msg,
239
261
        unsigned int msg_len,
240
262
        unsigned int token_seqid);
241
263
 
242
264
static void none_token_send (
243
265
        struct totemrrp_instance *instance,
244
 
        struct iovec *iovec,
245
 
        unsigned int iov_len);  
 
266
        const void *msg,
 
267
        unsigned int msg_len);
246
268
 
247
269
static void none_recv_flush (
248
270
        struct totemrrp_instance *instance);
265
287
static void none_ring_reenable (
266
288
        struct totemrrp_instance *instance);
267
289
 
 
290
static int none_mcast_recv_empty (
 
291
        struct totemrrp_instance *instance);
 
292
 
268
293
/*
269
294
 * Passive Replication Forward Declerations
270
295
 */
276
301
        struct totemrrp_instance *instance,
277
302
        unsigned int iface_no,
278
303
        void *context,
279
 
        void *msg,
 
304
        const void *msg,
280
305
        unsigned int msg_len);
281
306
 
282
307
static void passive_mcast_noflush_send (
283
308
        struct totemrrp_instance *instance,
284
 
        struct iovec *iovec,
285
 
        unsigned int iov_len);
 
309
        const void *msg,
 
310
        unsigned int msg_len);
286
311
 
287
312
static void passive_mcast_flush_send (
288
313
        struct totemrrp_instance *instance,
289
 
        struct iovec *iovec,
290
 
        unsigned int iov_len);
 
314
        const void *msg,
 
315
        unsigned int msg_len);
291
316
 
292
317
static void passive_token_recv (
293
318
        struct totemrrp_instance *instance,
294
319
        unsigned int iface_no,
295
320
        void *context,
296
 
        void *msg,
 
321
        const void *msg,
297
322
        unsigned int msg_len,
298
323
        unsigned int token_seqid);
299
324
 
300
325
static void passive_token_send (
301
326
        struct totemrrp_instance *instance,
302
 
        struct iovec *iovec,
303
 
        unsigned int iov_len);  
 
327
        const void *msg,
 
328
        unsigned int msg_len);
304
329
 
305
330
static void passive_recv_flush (
306
331
        struct totemrrp_instance *instance);
323
348
static void passive_ring_reenable (
324
349
        struct totemrrp_instance *instance);
325
350
 
 
351
static int passive_mcast_recv_empty (
 
352
        struct totemrrp_instance *instance);
 
353
 
326
354
/*
327
355
 * Active Replication Forward Definitions
328
356
 */
334
362
        struct totemrrp_instance *instance,
335
363
        unsigned int iface_no,
336
364
        void *context,
337
 
        void *msg,
 
365
        const void *msg,
338
366
        unsigned int msg_len);
339
367
 
340
368
static void active_mcast_noflush_send (
341
369
        struct totemrrp_instance *instance,
342
 
        struct iovec *iovec,
343
 
        unsigned int iov_len);
 
370
        const void *msg,
 
371
        unsigned int msg_len);
344
372
 
345
373
static void active_mcast_flush_send (
346
374
        struct totemrrp_instance *instance,
347
 
        struct iovec *iovec,
348
 
        unsigned int iov_len);
 
375
        const void *msg,
 
376
        unsigned int msg_len);
349
377
 
350
378
static void active_token_recv (
351
379
        struct totemrrp_instance *instance,
352
380
        unsigned int iface_no,
353
381
        void *context,
354
 
        void *msg,
 
382
        const void *msg,
355
383
        unsigned int msg_len,
356
384
        unsigned int token_seqid);
357
385
 
358
386
static void active_token_send (
359
387
        struct totemrrp_instance *instance,
360
 
        struct iovec *iovec,
361
 
        unsigned int iov_len);  
 
388
        const void *msg,
 
389
        unsigned int msg_len);
362
390
 
363
391
static void active_recv_flush (
364
392
        struct totemrrp_instance *instance);
381
409
static void active_ring_reenable (
382
410
        struct totemrrp_instance *instance);
383
411
 
 
412
static int active_mcast_recv_empty (
 
413
        struct totemrrp_instance *instance);
 
414
 
384
415
static void active_timer_expired_token_start (
385
416
        struct active_instance *active_instance);
386
417
 
406
437
        .iface_check            = none_iface_check,
407
438
        .processor_count_set    = none_processor_count_set,
408
439
        .token_target_set       = none_token_target_set,
409
 
        .ring_reenable          = none_ring_reenable
 
440
        .ring_reenable          = none_ring_reenable,
 
441
        .mcast_recv_empty       = none_mcast_recv_empty
410
442
};
411
443
 
412
444
struct rrp_algo passive_algo = {
422
454
        .iface_check            = passive_iface_check,
423
455
        .processor_count_set    = passive_processor_count_set,
424
456
        .token_target_set       = passive_token_target_set,
425
 
        .ring_reenable          = passive_ring_reenable
 
457
        .ring_reenable          = passive_ring_reenable,
 
458
        .mcast_recv_empty       = passive_mcast_recv_empty
426
459
};
427
460
 
428
461
struct rrp_algo active_algo = {
438
471
        .iface_check            = active_iface_check,
439
472
        .processor_count_set    = active_processor_count_set,
440
473
        .token_target_set       = active_token_target_set,
441
 
        .ring_reenable          = active_ring_reenable
 
474
        .ring_reenable          = active_ring_reenable,
 
475
        .mcast_recv_empty       = active_mcast_recv_empty
442
476
};
443
477
 
444
478
struct rrp_algo *rrp_algos[] = {
452
486
/*
453
487
 * All instances in one database
454
488
 */
455
 
static struct hdb_handle_database totemrrp_instance_database = {
456
 
        .handle_count   = 0,
457
 
        .handles        = 0,
458
 
        .iterator       = 0,
459
 
        .mutex          = PTHREAD_MUTEX_INITIALIZER
460
 
};
 
489
DECLARE_HDB_DATABASE (totemrrp_instance_database,NULL);
461
490
 
462
 
#define log_printf(level, format, args...) \
463
 
    rrp_instance->totemrrp_log_printf (__FILE__, __LINE__, level, format, ##args)
 
491
#define log_printf(level, format, args...)                              \
 
492
do {                                                                    \
 
493
        rrp_instance->totemrrp_log_printf (                             \
 
494
                LOGSYS_ENCODE_RECID(level,                              \
 
495
                                    rrp_instance->totemrrp_subsys_id,   \
 
496
                                    LOGSYS_RECID_LOG),                  \
 
497
                __FUNCTION__, __FILE__, __LINE__,                       \
 
498
                format, ##args);                                        \
 
499
} while (0);
464
500
 
465
501
/*
466
502
 * None Replication Implementation
470
506
        struct totemrrp_instance *rrp_instance,
471
507
        unsigned int iface_no,
472
508
        void *context,
473
 
        void *msg,
 
509
        const void *msg,
474
510
        unsigned int msg_len)
475
511
{
476
512
        rrp_instance->totemrrp_deliver_fn (
481
517
 
482
518
static void none_mcast_flush_send (
483
519
        struct totemrrp_instance *instance,
484
 
        struct iovec *iovec,
485
 
        unsigned int iov_len)
 
520
        const void *msg,
 
521
        unsigned int msg_len)
486
522
{
487
 
        totemnet_mcast_flush_send (instance->net_handles[0], iovec, iov_len);
 
523
        totemnet_mcast_flush_send (instance->net_handles[0], msg, msg_len);
488
524
}
489
525
 
490
526
static void none_mcast_noflush_send (
491
527
        struct totemrrp_instance *instance,
492
 
        struct iovec *iovec,
493
 
        unsigned int iov_len)
 
528
        const void *msg,
 
529
        unsigned int msg_len)
494
530
{
495
 
        totemnet_mcast_noflush_send (instance->net_handles[0], iovec, iov_len);
 
531
        totemnet_mcast_noflush_send (instance->net_handles[0], msg, msg_len);
496
532
}
497
533
 
498
534
static void none_token_recv (
499
535
        struct totemrrp_instance *rrp_instance,
500
536
        unsigned int iface_no,
501
537
        void *context,
502
 
        void *msg,
 
538
        const void *msg,
503
539
        unsigned int msg_len,
504
540
        unsigned int token_seq)
505
541
{
511
547
 
512
548
static void none_token_send (
513
549
        struct totemrrp_instance *instance,
514
 
        struct iovec *iovec,
515
 
        unsigned int iov_len)
 
550
        const void *msg,
 
551
        unsigned int msg_len)
516
552
{
517
553
        totemnet_token_send (
518
554
                instance->net_handles[0],
519
 
                iovec, iov_len);
 
555
                msg, msg_len);
520
556
}
521
557
 
522
558
static void none_recv_flush (struct totemrrp_instance *instance)
558
594
         */
559
595
}
560
596
 
 
597
static int none_mcast_recv_empty (
 
598
        struct totemrrp_instance *instance)
 
599
{
 
600
        int res;
 
601
 
 
602
        res = totemnet_recv_mcast_empty (instance->net_handles[0]);
 
603
 
 
604
        return (res);
 
605
}
 
606
 
561
607
/*
562
608
 * Passive Replication Implementation
563
609
 */
670
716
        struct totemrrp_instance *rrp_instance,
671
717
        unsigned int iface_no,
672
718
        void *context,
673
 
        void *msg,
 
719
        const void *msg,
674
720
        unsigned int msg_len)
675
721
{
676
722
        struct passive_instance *passive_instance = (struct passive_instance *)rrp_instance->rrp_algo_instance;
708
754
 
709
755
        for (i = 0; i < rrp_instance->interface_count; i++) {
710
756
                if ((passive_instance->faulty[i] == 0) &&
711
 
                        (max - passive_instance->mcast_recv_count[i] > 
 
757
                        (max - passive_instance->mcast_recv_count[i] >
712
758
                        rrp_instance->totem_config->rrp_problem_count_threshold)) {
713
759
                        passive_instance->faulty[i] = 1;
714
 
                        sprintf (rrp_instance->status[i], 
 
760
                        sprintf (rrp_instance->status[i],
715
761
                                "Marking ringid %u interface %s FAULTY - adminisrtative intervention required.",
716
762
                                i,
717
763
                                totemnet_iface_print (rrp_instance->net_handles[i]));
718
764
                        log_printf (
719
765
                                rrp_instance->totemrrp_log_level_error,
 
766
                                "%s",
720
767
                                rrp_instance->status[i]);
721
768
                }
722
769
        }
724
771
 
725
772
static void passive_mcast_flush_send (
726
773
        struct totemrrp_instance *instance,
727
 
        struct iovec *iovec,
728
 
        unsigned int iov_len)
 
774
        const void *msg,
 
775
        unsigned int msg_len)
729
776
{
730
777
        struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
731
778
 
732
779
        do {
733
780
                passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
734
781
        } while (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1);
735
 
        
736
 
        totemnet_mcast_flush_send (instance->net_handles[passive_instance->msg_xmit_iface], iovec, iov_len);
 
782
 
 
783
        totemnet_mcast_flush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
737
784
}
738
785
 
739
786
static void passive_mcast_noflush_send (
740
787
        struct totemrrp_instance *instance,
741
 
        struct iovec *iovec,
742
 
        unsigned int iov_len)
 
788
        const void *msg,
 
789
        unsigned int msg_len)
743
790
{
744
791
        struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
745
792
 
746
793
        do {
747
794
                passive_instance->msg_xmit_iface = (passive_instance->msg_xmit_iface + 1) % instance->interface_count;
748
795
        } while (passive_instance->faulty[passive_instance->msg_xmit_iface] == 1);
749
 
        
750
 
        
751
 
        totemnet_mcast_noflush_send (instance->net_handles[passive_instance->msg_xmit_iface], iovec, iov_len);
 
796
 
 
797
 
 
798
        totemnet_mcast_noflush_send (instance->net_handles[passive_instance->msg_xmit_iface], msg, msg_len);
752
799
}
753
800
 
754
801
static void passive_token_recv (
755
802
        struct totemrrp_instance *rrp_instance,
756
803
        unsigned int iface_no,
757
804
        void *context,
758
 
        void *msg,
 
805
        const void *msg,
759
806
        unsigned int msg_len,
760
807
        unsigned int token_seq)
761
808
{
790
837
 
791
838
        for (i = 0; i < rrp_instance->interface_count; i++) {
792
839
                if ((passive_instance->faulty[i] == 0) &&
793
 
                        (max - passive_instance->token_recv_count[i] > 
 
840
                        (max - passive_instance->token_recv_count[i] >
794
841
                        rrp_instance->totem_config->rrp_problem_count_threshold)) {
795
842
                        passive_instance->faulty[i] = 1;
796
 
                        sprintf (rrp_instance->status[i], 
 
843
                        sprintf (rrp_instance->status[i],
797
844
                                "Marking seqid %d ringid %u interface %s FAULTY - adminisrtative intervention required.",
798
845
                                token_seq,
799
846
                                i,
800
847
                                totemnet_iface_print (rrp_instance->net_handles[i]));
801
848
                        log_printf (
802
849
                                rrp_instance->totemrrp_log_level_error,
 
850
                                "%s",
803
851
                                rrp_instance->status[i]);
804
852
                }
805
853
        }
807
855
 
808
856
static void passive_token_send (
809
857
        struct totemrrp_instance *instance,
810
 
        struct iovec *iovec,
811
 
        unsigned int iov_len)
 
858
        const void *msg,
 
859
        unsigned int msg_len)
812
860
{
813
861
        struct passive_instance *passive_instance = (struct passive_instance *)instance->rrp_algo_instance;
814
862
 
815
863
        do {
816
864
                passive_instance->token_xmit_iface = (passive_instance->token_xmit_iface + 1) % instance->interface_count;
817
865
        } while (passive_instance->faulty[passive_instance->token_xmit_iface] == 1);
818
 
        
 
866
 
819
867
        totemnet_token_send (
820
868
                instance->net_handles[passive_instance->token_xmit_iface],
821
 
                iovec, iov_len);
 
869
                msg, msg_len);
822
870
 
823
871
}
824
872
 
885
933
        totemnet_token_target_set (instance->net_handles[iface_no], token_target);
886
934
}
887
935
 
 
936
static int passive_mcast_recv_empty (
 
937
        struct totemrrp_instance *instance)
 
938
{
 
939
        int res;
 
940
        int msgs_emptied = 0;
 
941
        int i;
 
942
 
 
943
        for (i = 0; i < instance->interface_count; i++) {
 
944
                res = totemnet_recv_mcast_empty (instance->net_handles[i]);
 
945
                if (res == -1) {
 
946
                        return (-1);
 
947
                }
 
948
                if (res == 1) {
 
949
                        msgs_emptied = 1;
 
950
                }
 
951
        }
 
952
 
 
953
        return (msgs_emptied);
 
954
}
 
955
 
888
956
static void passive_ring_reenable (
889
957
        struct totemrrp_instance *instance)
890
958
{
955
1023
        struct totemrrp_instance *rrp_instance = active_instance->rrp_instance;
956
1024
        unsigned int problem_found = 0;
957
1025
        unsigned int i;
958
 
        
 
1026
 
959
1027
        for (i = 0; i < rrp_instance->interface_count; i++) {
960
1028
                if (active_instance->counter_problems[i] > 0) {
961
1029
                        problem_found = 1;
962
1030
                        active_instance->counter_problems[i] -= 1;
963
1031
                        if (active_instance->counter_problems[i] == 0) {
964
 
                                sprintf (rrp_instance->status[i], 
 
1032
                                sprintf (rrp_instance->status[i],
965
1033
                                        "ring %d active with no faults", i);
966
1034
                        } else {
967
 
                                sprintf (rrp_instance->status[i], 
 
1035
                                sprintf (rrp_instance->status[i],
968
1036
                                        "Decrementing problem counter for iface %s to [%d of %d]",
969
1037
                                        totemnet_iface_print (rrp_instance->net_handles[i]),
970
1038
                                        active_instance->counter_problems[i],
972
1040
                        }
973
1041
                                log_printf (
974
1042
                                        rrp_instance->totemrrp_log_level_warning,
 
1043
                                        "%s",
975
1044
                                        rrp_instance->status[i]);
976
1045
                }
977
1046
        }
995
1064
                        if (active_instance->timer_problem_decrementer == 0) {
996
1065
                                active_timer_problem_decrementer_start (active_instance);
997
1066
                        }
998
 
                        sprintf (rrp_instance->status[i], 
 
1067
                        sprintf (rrp_instance->status[i],
999
1068
                                "Incrementing problem counter for seqid %d iface %s to [%d of %d]",
1000
1069
                                active_instance->last_token_seq,
1001
1070
                                totemnet_iface_print (rrp_instance->net_handles[i]),
1003
1072
                                rrp_instance->totem_config->rrp_problem_count_threshold);
1004
1073
                        log_printf (
1005
1074
                                rrp_instance->totemrrp_log_level_warning,
 
1075
                                "%s",
1006
1076
                                rrp_instance->status[i]);
1007
1077
                }
1008
1078
        }
1010
1080
                if (active_instance->counter_problems[i] >= rrp_instance->totem_config->rrp_problem_count_threshold)
1011
1081
                {
1012
1082
                        active_instance->faulty[i] = 1;
1013
 
                        sprintf (rrp_instance->status[i], 
 
1083
                        sprintf (rrp_instance->status[i],
1014
1084
                                "Marking seqid %d ringid %u interface %s FAULTY - adminisrtative intervention required.",
1015
1085
                                active_instance->last_token_seq,
1016
1086
                                i,
1017
1087
                                totemnet_iface_print (rrp_instance->net_handles[i]));
1018
1088
                        log_printf (
1019
1089
                                rrp_instance->totemrrp_log_level_error,
 
1090
                                "%s",
1020
1091
                                rrp_instance->status[i]);
1021
1092
                        active_timer_problem_decrementer_cancel (active_instance);
1022
1093
                }
1074
1145
        struct totemrrp_instance *instance,
1075
1146
        unsigned int iface_no,
1076
1147
        void *context,
1077
 
        void *msg,
 
1148
        const void *msg,
1078
1149
        unsigned int msg_len)
1079
1150
{
1080
1151
        instance->totemrrp_deliver_fn (
1085
1156
 
1086
1157
static void active_mcast_flush_send (
1087
1158
        struct totemrrp_instance *instance,
1088
 
        struct iovec *iovec,
1089
 
        unsigned int iov_len)
 
1159
        const void *msg,
 
1160
        unsigned int msg_len)
1090
1161
{
1091
1162
        int i;
1092
1163
        struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
1093
1164
 
1094
1165
        for (i = 0; i < instance->interface_count; i++) {
1095
1166
                if (rrp_algo_instance->faulty[i] == 0) {
1096
 
                        totemnet_mcast_flush_send (instance->net_handles[i], iovec, iov_len);
 
1167
                        totemnet_mcast_flush_send (instance->net_handles[i], msg, msg_len);
1097
1168
                }
1098
1169
        }
1099
1170
}
1100
1171
 
1101
1172
static void active_mcast_noflush_send (
1102
1173
        struct totemrrp_instance *instance,
1103
 
        struct iovec *iovec,
1104
 
        unsigned int iov_len)
 
1174
        const void *msg,
 
1175
        unsigned int msg_len)
1105
1176
{
1106
1177
        int i;
1107
1178
        struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
1108
1179
 
1109
1180
        for (i = 0; i < instance->interface_count; i++) {
1110
1181
                if (rrp_algo_instance->faulty[i] == 0) {
1111
 
                        totemnet_mcast_noflush_send (instance->net_handles[i], iovec, iov_len);
 
1182
                        totemnet_mcast_noflush_send (instance->net_handles[i], msg, msg_len);
1112
1183
                }
1113
1184
        }
1114
1185
}
1117
1188
        struct totemrrp_instance *instance,
1118
1189
        unsigned int iface_no,
1119
1190
        void *context,
1120
 
        void *msg,
 
1191
        const void *msg,
1121
1192
        unsigned int msg_len,
1122
1193
        unsigned int token_seq)
1123
1194
{
1157
1228
 
1158
1229
static void active_token_send (
1159
1230
        struct totemrrp_instance *instance,
1160
 
        struct iovec *iovec,
1161
 
        unsigned int iov_len)
 
1231
        const void *msg,
 
1232
        unsigned int msg_len)
1162
1233
{
1163
1234
        struct active_instance *rrp_algo_instance = (struct active_instance *)instance->rrp_algo_instance;
1164
1235
        int i;
1167
1238
                if (rrp_algo_instance->faulty[i] == 0) {
1168
1239
                        totemnet_token_send (
1169
1240
                                instance->net_handles[i],
1170
 
                                iovec, iov_len);
 
1241
                                msg, msg_len);
1171
1242
 
1172
1243
                }
1173
1244
        }
1236
1307
        totemnet_token_target_set (instance->net_handles[iface_no], token_target);
1237
1308
}
1238
1309
 
 
1310
static int active_mcast_recv_empty (
 
1311
        struct totemrrp_instance *instance)
 
1312
{
 
1313
        int res;
 
1314
        int msgs_emptied = 0;
 
1315
        int i;
 
1316
 
 
1317
        for (i = 0; i < instance->interface_count; i++) {
 
1318
                res = totemnet_recv_mcast_empty (instance->net_handles[i]);
 
1319
                if (res == -1) {
 
1320
                        return (-1);
 
1321
                }
 
1322
                if (res == 1) {
 
1323
                        msgs_emptied = 1;
 
1324
                }
 
1325
        }
 
1326
 
 
1327
        return (msgs_emptied);
 
1328
}
 
1329
 
1239
1330
static void active_ring_reenable (
1240
1331
        struct totemrrp_instance *instance)
1241
1332
{
1288
1379
 
1289
1380
void rrp_deliver_fn (
1290
1381
        void *context,
1291
 
        void *msg,
1292
 
        int msg_len)
 
1382
        const void *msg,
 
1383
        unsigned int msg_len)
1293
1384
{
1294
1385
        unsigned int token_seqid;
1295
1386
        unsigned int token_is;
1303
1394
 
1304
1395
        if (token_is) {
1305
1396
                /*
1306
 
                 * Deliver to the token receiver for this rrp algorithm 
 
1397
                 * Deliver to the token receiver for this rrp algorithm
1307
1398
                 */
1308
1399
                deliver_fn_context->instance->rrp_algo->token_recv (
1309
1400
                        deliver_fn_context->instance,
1314
1405
                        token_seqid);
1315
1406
        } else {
1316
1407
                /*
1317
 
                 * Deliver to the mcast receiver for this rrp algorithm 
 
1408
                 * Deliver to the mcast receiver for this rrp algorithm
1318
1409
                 */
1319
1410
                deliver_fn_context->instance->rrp_algo->mcast_recv (
1320
1411
                        deliver_fn_context->instance,
1327
1418
 
1328
1419
void rrp_iface_change_fn (
1329
1420
        void *context,
1330
 
        struct totem_ip_address *iface_addr)
 
1421
        const struct totem_ip_address *iface_addr)
1331
1422
{
1332
1423
        struct deliver_fn_context *deliver_fn_context = (struct deliver_fn_context *)context;
1333
1424
 
1338
1429
}
1339
1430
 
1340
1431
int totemrrp_finalize (
1341
 
        totemrrp_handle handle)
 
1432
        hdb_handle_t handle)
1342
1433
{
1343
1434
        struct totemrrp_instance *instance;
1344
1435
        int res = 0;
1370
1461
 * Create an instance
1371
1462
 */
1372
1463
int totemrrp_initialize (
1373
 
        poll_handle poll_handle,
1374
 
        totemrrp_handle *handle,
 
1464
        hdb_handle_t poll_handle,
 
1465
        hdb_handle_t *handle,
1375
1466
        struct totem_config *totem_config,
1376
1467
        void *context,
1377
1468
 
1378
1469
        void (*deliver_fn) (
1379
1470
                void *context,
1380
 
                void *msg,
1381
 
                int msg_len),
 
1471
                const void *msg,
 
1472
                unsigned int msg_len),
1382
1473
 
1383
1474
        void (*iface_change_fn) (
1384
1475
                void *context,
1385
 
                struct totem_ip_address *iface_addr,
 
1476
                const struct totem_ip_address *iface_addr,
1386
1477
                unsigned int iface_no),
1387
1478
 
1388
1479
        void (*token_seqid_get) (
1389
 
                void *msg,
 
1480
                const void *msg,
1390
1481
                unsigned int *seqid,
1391
1482
                unsigned int *token_is),
1392
1483
 
1426
1517
        instance->totemrrp_log_level_warning = totem_config->totem_logging_configuration.log_level_warning;
1427
1518
        instance->totemrrp_log_level_notice = totem_config->totem_logging_configuration.log_level_notice;
1428
1519
        instance->totemrrp_log_level_debug = totem_config->totem_logging_configuration.log_level_debug;
 
1520
        instance->totemrrp_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
1429
1521
        instance->totemrrp_log_printf = totem_config->totem_logging_configuration.log_printf;
1430
1522
 
1431
1523
        instance->interfaces = totem_config->interfaces;
1442
1534
 
1443
1535
        instance->interface_count = totem_config->interface_count;
1444
1536
 
1445
 
        instance->net_handles = malloc (sizeof (totemnet_handle) * totem_config->interface_count);
 
1537
        instance->net_handles = malloc (sizeof (hdb_handle_t) * totem_config->interface_count);
1446
1538
 
1447
1539
        instance->context = context;
1448
1540
 
1481
1573
}
1482
1574
 
1483
1575
int totemrrp_processor_count_set (
1484
 
        totemrrp_handle handle,
 
1576
        hdb_handle_t handle,
1485
1577
        unsigned int processor_count)
1486
1578
{
1487
1579
        struct totemrrp_instance *instance;
1505
1597
}
1506
1598
 
1507
1599
int totemrrp_token_target_set (
1508
 
        totemrrp_handle handle,
 
1600
        hdb_handle_t handle,
1509
1601
        struct totem_ip_address *addr,
1510
1602
        unsigned int iface_no)
1511
1603
{
1526
1618
error_exit:
1527
1619
        return (res);
1528
1620
}
1529
 
int totemrrp_recv_flush (totemrrp_handle handle)
 
1621
int totemrrp_recv_flush (hdb_handle_t handle)
1530
1622
{
1531
1623
        struct totemrrp_instance *instance;
1532
1624
        int res = 0;
1546
1638
        return (res);
1547
1639
}
1548
1640
 
1549
 
int totemrrp_send_flush (totemrrp_handle handle)
 
1641
int totemrrp_send_flush (hdb_handle_t handle)
1550
1642
{
1551
1643
        struct totemrrp_instance *instance;
1552
1644
        int res = 0;
1557
1649
                res = ENOENT;
1558
1650
                goto error_exit;
1559
1651
        }
1560
 
        
 
1652
 
1561
1653
        instance->rrp_algo->send_flush (instance);
1562
1654
 
1563
1655
        hdb_handle_put (&totemrrp_instance_database, handle);
1567
1659
}
1568
1660
 
1569
1661
int totemrrp_token_send (
1570
 
        totemrrp_handle handle,
1571
 
        struct iovec *iovec,
1572
 
        unsigned int iov_len)
 
1662
        hdb_handle_t handle,
 
1663
        const void *msg,
 
1664
        unsigned int msg_len)
1573
1665
{
1574
1666
        struct totemrrp_instance *instance;
1575
1667
        int res = 0;
1581
1673
                goto error_exit;
1582
1674
        }
1583
1675
 
1584
 
        instance->rrp_algo->token_send (instance, iovec, iov_len);
 
1676
        instance->rrp_algo->token_send (instance, msg, msg_len);
1585
1677
 
1586
1678
        hdb_handle_put (&totemrrp_instance_database, handle);
1587
1679
 
1590
1682
}
1591
1683
 
1592
1684
int totemrrp_mcast_flush_send (
1593
 
        totemrrp_handle handle,
1594
 
        struct iovec *iovec,
1595
 
        unsigned int iov_len)
 
1685
        hdb_handle_t handle,
 
1686
        const void *msg,
 
1687
        unsigned int msg_len)
1596
1688
{
1597
1689
        struct totemrrp_instance *instance;
1598
1690
        int res = 0;
1603
1695
                res = ENOENT;
1604
1696
                goto error_exit;
1605
1697
        }
1606
 
        
 
1698
 
1607
1699
// TODO this needs to return the result
1608
 
        instance->rrp_algo->mcast_flush_send (instance, iovec, iov_len);
 
1700
        instance->rrp_algo->mcast_flush_send (instance, msg, msg_len);
1609
1701
 
1610
1702
        hdb_handle_put (&totemrrp_instance_database, handle);
1611
1703
error_exit:
1613
1705
}
1614
1706
 
1615
1707
int totemrrp_mcast_noflush_send (
1616
 
        totemrrp_handle handle,
1617
 
        struct iovec *iovec,
1618
 
        unsigned int iov_len)
 
1708
        hdb_handle_t handle,
 
1709
        const void *msg,
 
1710
        unsigned int msg_len)
1619
1711
{
1620
1712
        struct totemrrp_instance *instance;
1621
1713
        int res = 0;
1626
1718
                res = ENOENT;
1627
1719
                goto error_exit;
1628
1720
        }
1629
 
        
 
1721
 
1630
1722
        /*
1631
1723
         * merge detects go out through mcast_flush_send so it is safe to
1632
1724
         * flush these messages if we are only one processor.  This avoids
1635
1727
        if (instance->processor_count > 1) {
1636
1728
 
1637
1729
// TODO this needs to return the result
1638
 
                instance->rrp_algo->mcast_noflush_send (instance, iovec, iov_len);
 
1730
                instance->rrp_algo->mcast_noflush_send (instance, msg, msg_len);
1639
1731
        }
1640
1732
 
1641
1733
        hdb_handle_put (&totemrrp_instance_database, handle);
1643
1735
        return (res);
1644
1736
}
1645
1737
 
1646
 
int totemrrp_iface_check (totemrrp_handle handle)
 
1738
int totemrrp_iface_check (hdb_handle_t handle)
1647
1739
{
1648
1740
        struct totemrrp_instance *instance;
1649
1741
        int res = 0;
1654
1746
                res = ENOENT;
1655
1747
                goto error_exit;
1656
1748
        }
1657
 
        
 
1749
 
1658
1750
        instance->rrp_algo->iface_check (instance);
1659
1751
 
1660
1752
        hdb_handle_put (&totemrrp_instance_database, handle);
1663
1755
}
1664
1756
 
1665
1757
int totemrrp_ifaces_get (
1666
 
        totemrrp_handle handle,
 
1758
        hdb_handle_t handle,
1667
1759
        char ***status,
1668
1760
        unsigned int *iface_count)
1669
1761
{
1676
1768
                res = ENOENT;
1677
1769
                goto error_exit;
1678
1770
        }
1679
 
        
 
1771
 
1680
1772
        *status = instance->status;
1681
 
        
 
1773
 
1682
1774
        if (iface_count) {
1683
1775
                *iface_count = instance->interface_count;
1684
1776
        }
1689
1781
        return (res);
1690
1782
}
1691
1783
 
 
1784
int totemrrp_crypto_set (
 
1785
        hdb_handle_t handle,
 
1786
        unsigned int type)
 
1787
{
 
1788
        int res;
 
1789
        struct totemrrp_instance *instance;
 
1790
 
 
1791
        res = hdb_handle_get (&totemrrp_instance_database, handle,
 
1792
                (void *)&instance);
 
1793
        if (res != 0) {
 
1794
                return (0);
 
1795
        }
 
1796
 
 
1797
        res = totemnet_crypto_set(instance->net_handles[0], type);
 
1798
 
 
1799
        hdb_handle_put (&totemrrp_instance_database, handle);
 
1800
        return (res);
 
1801
}
 
1802
 
 
1803
 
1692
1804
int totemrrp_ring_reenable (
1693
 
        totemrrp_handle handle)
 
1805
        hdb_handle_t handle)
1694
1806
{
1695
1807
        struct totemrrp_instance *instance;
1696
1808
        int res = 0;
1697
1809
        unsigned int i;
1698
1810
 
 
1811
printf ("totemrrp ring reenable\n");
1699
1812
        res = hdb_handle_get (&totemrrp_instance_database, handle,
1700
1813
                (void *)&instance);
1701
1814
        if (res != 0) {
1702
1815
                res = ENOENT;
1703
1816
                goto error_exit;
1704
1817
        }
1705
 
        
 
1818
 
1706
1819
        instance->rrp_algo->ring_reenable (instance);
1707
1820
 
1708
1821
        for (i = 0; i < instance->interface_count; i++) {
1714
1827
error_exit:
1715
1828
        return (res);
1716
1829
}
 
1830
 
 
1831
extern int totemrrp_mcast_recv_empty (
 
1832
        hdb_handle_t handle)
 
1833
{
 
1834
        struct totemrrp_instance *instance;
 
1835
        int res;
 
1836
 
 
1837
        res = hdb_handle_get (&totemrrp_instance_database, handle,
 
1838
                (void *)&instance);
 
1839
        if (res != 0) {
 
1840
                res = ENOENT;
 
1841
                goto error_exit;
 
1842
        }
 
1843
 
 
1844
        res = instance->rrp_algo->mcast_recv_empty (instance);
 
1845
 
 
1846
        hdb_handle_put (&totemrrp_instance_database, handle);
 
1847
 
 
1848
error_exit:
 
1849
        return (res);
 
1850
}
 
1851