Debian Codegraph @

membership/ccm/ccmlib_memapi.c

raw
1 /*
2 * ccmlib_memapi.c: Consensus Cluster Membership API
3 *
4 * Copyright (c) International Business Machines Corp., 2002
5 * Author: Ram Pai ([email protected])
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include <lha_internal.h>
23 #define __CCM_LIBRARY__
24 #include <ccmlib.h>
25 #include <ccm.h>
26 /*#include <syslog.h> */
27 #include <clplumbing/cl_log.h>
28
29 /* structure to track the membership delivered to client */
30 typedef struct mbr_track_s {
31 int quorum;
32 int m_size;
33 oc_ev_membership_t m_mem;
34 } mbr_track_t;
35
36
37 typedef struct mbr_private_s {
38 int magiccookie;
39 gboolean client_report; /* report to client */
40 oc_ev_callback_t *callback; /* the callback function registered
41 by the client */
42 struct IPC_CHANNEL *channel; /* the channel to talk to ccm */
43 ccm_llm_t *llm; /* list of all nodes */
44 GHashTable *bornon; /* list of born time
45 for all nodes */
46 void *cookie; /* the last known
47 membership event cookie */
48 gboolean special; /* publish non primary membership.
49 * This is a kludge to accomodate
50 * special behaviour not provided
51 * but desired from the 0.2 API.
52 * By default this behaviour is
53 * turned off.
54 */
55 } mbr_private_t;
56
57
58 static char event_strings[5][32]={
59 "OC_EV_MS_INVALID",
60 "OC_EV_MS_NEW_MEMBERSHIP",
61 "OC_EV_MS_NOT_PRIMARY",
62 "OC_EV_MS_PRIMARY_RESTORED",
63 "OC_EV_MS_EVICTED"
64 };
65
66 #define EVENT_STRING(x) event_strings[x - OC_EV_MS_INVALID]
67 #define OC_EV_SET_INSTANCE(m,trans) m->m_mem.m_instance=trans
68 #define OC_EV_SET_N_MEMBER(m,n) m->m_mem.m_n_member=n
69 #define OC_EV_SET_MEMB_IDX(m,idx) m->m_mem.m_memb_idx=idx
70 #define OC_EV_SET_N_OUT(m,n) m->m_mem.m_n_out=n
71 #define OC_EV_SET_OUT_IDX(m,idx) m->m_mem.m_out_idx=idx
72 #define OC_EV_SET_N_IN(m,n) m->m_mem.m_n_in=n
73 #define OC_EV_SET_IN_IDX(m,idx) m->m_mem.m_in_idx=idx
74 #define OC_EV_SET_NODEID(m,idx,nodeid) m->m_mem.m_array[idx].node_id=nodeid
75 #define OC_EV_SET_BORN(m,idx,born) m->m_mem.m_array[idx].node_born_on=born
76
77 #define OC_EV_INC_N_MEMBER(m) m->m_mem.m_n_member++
78 #define OC_EV_INC_N_IN(m) m->m_mem.m_n_in++
79 #define OC_EV_INC_N_OUT(m) m->m_mem.m_n_out++
80
81
82 #define OC_EV_SET_SIZE(m,size) m->m_size=size
83 #define OC_EV_SET_DONEFUNC(m,f) m->m_func=f
84
85 #define OC_EV_GET_INSTANCE(m) m->m_mem.m_instance
86 #define OC_EV_GET_N_MEMBER(m) m->m_mem.m_n_member
87 #define OC_EV_GET_MEMB_IDX(m) m->m_mem.m_memb_idx
88 #define OC_EV_GET_N_OUT(m) m->m_mem.m_n_out
89 #define OC_EV_GET_OUT_IDX(m) m->m_mem.m_out_idx
90 #define OC_EV_GET_N_IN(m) m->m_mem.m_n_in
91 #define OC_EV_GET_IN(m) m->m_mem.m_in_idx
92 #define OC_EV_GET_NODEARRY(m) m->m_mem.m_array
93 #define OC_EV_GET_NODE(m,idx) m->m_mem.m_array[idx]
94 #define OC_EV_GET_NODEID(m,idx) m->m_mem.m_array[idx].node_id
95 #define OC_EV_GET_BORN(m,idx) m->m_mem.m_array[idx].node_born_on
96
97 #define OC_EV_COPY_NODE_WITHOUT_UNAME(m1,idx1,m2,idx2) \
98 m1->m_mem.m_array[idx1]=m2->m_mem.m_array[idx2]
99
100 #define OC_EV_COPY_NODE(m1,idx1,m2,idx2) \
101 m1->m_mem.m_array[idx1]=m2->m_mem.m_array[idx2]; \
102 m1->m_mem.m_array[idx1].node_uname = \
103 strdup(m2->m_mem.m_array[idx2].node_uname)
104
105 #define OC_EV_GET_SIZE(m) m->m_size
106
107
108 /* prototypes of external functions used in this file
109 * Should be made part of some header file
110 */
111 void *cookie_construct(void (*f)(void *), void (*free_f)(void *), void *);
112 void * cookie_get_data(void *ck);
113 void * cookie_get_func(void *ck);
114 void cookie_ref(void *ck);
115 void cookie_unref(void *ck);
116 static const char *llm_get_Id_from_Uuid(ccm_llm_t *stuff, uint uuid);
117
118
119
120 static void
121 on_llm_msg(mbr_private_t *mem, struct IPC_MESSAGE *msg)
122 {
123 unsigned long len = msg->msg_len;
124
125 if (mem->llm != NULL) {
126 g_free(mem->llm);
127 }
128 mem->llm = (ccm_llm_t *)g_malloc(len);
129 memcpy(mem->llm, msg->msg_body, len);
130 return;
131 }
132
133
134
135 static void
136 reset_bornon(mbr_private_t *private)
137 {
138 g_hash_table_destroy(private->bornon);
139 private->bornon = NULL;
140 }
141
142 static void
143 reset_llm(mbr_private_t *private)
144 {
145 g_free(private->llm);
146 private->llm = NULL;
147 }
148
149 static int
150 init_llm(mbr_private_t *private)
151 {
152 struct IPC_CHANNEL *ch;
153 int ret;
154 struct IPC_MESSAGE *msg;
155
156 if(private->llm) {
157 return 0;
158 }
159
160 ch = private->channel;
161 ch->ops->get_recv_select_fd(ch);
162 while(1) {
163 if(ch->ops->waitin(ch) != IPC_OK){
164 ch->ops->destroy(ch);
165 return -1;
166 }
167 ret = ch->ops->recv(ch,&msg);
168 if(ret == IPC_BROKEN) {
169 fprintf(stderr, "connection denied\n");
170 return -1;
171 }
172 if(ret == IPC_FAIL){
173 fprintf(stderr, ".");
174 cl_shortsleep();
175 continue;
176 }
177 break;
178 }
179 on_llm_msg(private, msg);
180
181 private->bornon = g_hash_table_new(g_direct_hash,
182 g_direct_equal);
183 private->cookie = NULL;
184
185 private->client_report = TRUE;
186 msg->msg_done(msg);
187 return 0;
188 }
189
190
191 static gboolean
192 class_valid(class_t *class)
193 {
194 mbr_private_t *private;
195
196 if(class->type != OC_EV_MEMB_CLASS) {
197 return FALSE;
198 }
199
200 private = (mbr_private_t *)class->private;
201
202 if(!private ||
203 private->magiccookie != 0xabcdef){
204 return FALSE;
205 }
206 return TRUE;
207 }
208
209
210
211 static gboolean
212 already_present(oc_node_t *arr, uint size, oc_node_t node)
213 {
214 uint i;
215 for ( i = 0 ; i < size ; i ++ ) {
216 if(arr[i].node_id == node.node_id) {
217 return TRUE;
218 }
219 }
220 return FALSE;
221 }
222
223 static int
224 compare(const void *value1, const void *value2)
225 {
226 const oc_node_t *t1 = (const oc_node_t *)value1;
227 const oc_node_t *t2 = (const oc_node_t *)value2;
228
229 if (t1->node_born_on < t2->node_born_on){
230 return -1;
231 }
232
233 if (t1->node_born_on > t2->node_born_on){
234 return 1;
235 }
236
237 if (t1->node_id < t2->node_id) {
238 return -1;
239 }
240
241 if (t1->node_id > t2->node_id) {
242 return 1;
243 }
244
245 return 0;
246 }
247
248 static const char *
249 llm_get_Id_from_Uuid(ccm_llm_t *stuff, uint uuid)
250 {
251 uint lpc = 0;
252 for (; lpc < stuff->n; lpc++) {
253 if(stuff->node[lpc].Uuid == uuid){
254 return stuff->node[lpc].Id;
255 }
256 }
257 return NULL;
258 }
259
260
261
262 static int
263 get_new_membership(mbr_private_t *private,
264 ccm_meminfo_t *mbrinfo,
265 int len,
266 mbr_track_t **mbr)
267 {
268 mbr_track_t *newmbr, *oldmbr;
269 int i, j, in_index, out_index, born;
270 int n_members;
271
272 int n_nodes = CLLM_GET_NODECOUNT(private->llm);
273
274 int size = sizeof(oc_ev_membership_t) +
275 2*n_nodes*sizeof(oc_node_t);
276
277 newmbr = *mbr = (mbr_track_t *)g_malloc(size +
278 sizeof(mbr_track_t)-sizeof(newmbr->m_mem));
279
280 OC_EV_SET_INSTANCE(newmbr,mbrinfo->trans);
281 n_members = OC_EV_SET_N_MEMBER(newmbr,mbrinfo->n);
282 OC_EV_SET_SIZE(newmbr, size);
283
284 j = OC_EV_SET_MEMB_IDX(newmbr,0);
285
286 for ( i = 0 ; i < n_members; i++ ) {
287 const char *uname = NULL;
288 int index;
289
290 index = mbrinfo->member[i].index;
291
292 uname = llm_get_Id_from_Uuid(private->llm, index);
293
294 newmbr->m_mem.m_array[j].node_uname = strdup(uname);
295
296 OC_EV_SET_NODEID(newmbr,j,index);
297
298 /* gborn was an int to begin with - so this is safe */
299 born = mbrinfo->member[i].bornon;
300
301 /* if there is already a born entry for the
302 * node, use it. Otherwise create a born entry
303 * for the node.
304 *
305 * NOTE: born==0 implies the entry has not been
306 * initialized.
307 */
308 OC_EV_SET_BORN(newmbr,j, born);
309 j++;
310 }
311 /* sort the m_arry */
312 qsort(OC_EV_GET_NODEARRY(newmbr), n_members,
313 sizeof(oc_node_t), compare);
314
315 in_index = OC_EV_SET_IN_IDX(newmbr,j);
316 out_index = OC_EV_SET_OUT_IDX(newmbr,(j+n_nodes));
317
318 OC_EV_SET_N_IN(newmbr,0);
319 OC_EV_SET_N_OUT(newmbr,0);
320
321 oldmbr = (mbr_track_t *) cookie_get_data(private->cookie);
322
323 if(oldmbr) {
324 for ( i = 0 ; i < n_members; i++ ) {
325 if(!already_present(OC_EV_GET_NODEARRY(oldmbr),
326 OC_EV_GET_N_MEMBER(oldmbr),
327 OC_EV_GET_NODE(newmbr,i))){
328 OC_EV_COPY_NODE_WITHOUT_UNAME(newmbr
329 , in_index, newmbr, i);
330 in_index++;
331 OC_EV_INC_N_IN(newmbr);
332 }
333 }
334
335 for ( i = 0 ; (uint)i < OC_EV_GET_N_MEMBER(oldmbr) ; i++ ) {
336 if(!already_present(OC_EV_GET_NODEARRY(newmbr),
337 OC_EV_GET_N_MEMBER(newmbr),
338 OC_EV_GET_NODE(oldmbr,i))){
339 OC_EV_COPY_NODE(newmbr, out_index, oldmbr, i);
340 out_index++;
341 OC_EV_INC_N_OUT(newmbr);
342 }
343 }
344 } else {
345 OC_EV_SET_IN_IDX(newmbr,0);
346 OC_EV_SET_N_IN(newmbr,OC_EV_GET_N_MEMBER(newmbr));
347 }
348
349 return size;
350 }
351
352 static void
353 mem_free_func(void *data)
354 {
355 unsigned lpc = 0;
356 char * uname;
357 mbr_track_t *mbr_track = (mbr_track_t *)data;
358
359 if(mbr_track) {
360 /* free m_n_member uname, m_n_in is actually the same ptr */
361 for (lpc = 0 ; lpc < OC_EV_GET_N_MEMBER(mbr_track); lpc++ ) {
362 if ((uname = OC_EV_GET_NODE(mbr_track, lpc).node_uname)){
363 g_free(uname);
364 }
365 }
366 /* free m_n_out uname */
367 for (lpc = OC_EV_GET_OUT_IDX(mbr_track)
368 ; lpc < OC_EV_GET_OUT_IDX(mbr_track)
369 + OC_EV_GET_N_OUT(mbr_track)
370 ; lpc++) {
371
372 if ((uname = OC_EV_GET_NODE(mbr_track, lpc).node_uname)){
373 g_free(uname);
374 }
375 }
376 g_free(mbr_track);
377 }
378
379
380 return;
381 }
382
383 static void
384 mem_callback_done(void *cookie)
385 {
386 cookie_unref(cookie);
387 return;
388 }
389
390
391
392 static void
393 update_bornons(mbr_private_t *private, mbr_track_t *mbr)
394 {
395 uint i,j;
396 for(i=0; i < OC_EV_GET_N_MEMBER(mbr); i++) {
397 g_hash_table_insert(private->bornon,
398 GINT_TO_POINTER(OC_EV_GET_NODEID(mbr,i)),
399 GINT_TO_POINTER(OC_EV_GET_BORN(mbr,i)+1));
400 }
401 j=OC_EV_GET_OUT_IDX(mbr);
402 for(i=OC_EV_GET_OUT_IDX(mbr); i<j+OC_EV_GET_N_OUT(mbr); i++){
403 g_hash_table_insert(private->bornon,
404 GINT_TO_POINTER(OC_EV_GET_NODEID(mbr,i)),
405 GINT_TO_POINTER(0));
406 }
407 }
408
409 static gboolean
410 membership_unchanged(mbr_private_t *private, mbr_track_t *mbr)
411 {
412 uint i;
413 mbr_track_t *oldmbr = (mbr_track_t *)
414 cookie_get_data(private->cookie);
415
416 if(!oldmbr) {
417 return FALSE;
418 }
419
420 if(OC_EV_GET_N_MEMBER(mbr) != OC_EV_GET_N_MEMBER(oldmbr)){
421 return FALSE;
422 }
423
424 for(i=0; i < OC_EV_GET_N_MEMBER(mbr); i++) {
425 if((OC_EV_GET_NODEID(mbr,i)
426 != OC_EV_GET_NODEID(oldmbr,i)) ||
427 OC_EV_GET_BORN(mbr,i)
428 != OC_EV_GET_BORN(oldmbr,i)) {
429 return FALSE;
430 }
431 }
432 return TRUE;
433 }
434
435 static gboolean
436 mem_handle_event(class_t *class)
437 {
438 struct IPC_MESSAGE *msg;
439 mbr_private_t *private;
440 struct IPC_CHANNEL *ch;
441 mbr_track_t *mbr_track;
442 int size;
443 int type;
444 oc_memb_event_t oc_type;
445 void *cookie;
446 int ret;
447 gboolean quorum;
448
449 if(!class_valid(class)){
450 return FALSE;
451 }
452
453 private = (mbr_private_t *)class->private;
454 ch = private->channel;
455
456 if(init_llm(private)){
457 return FALSE;
458 }
459
460
461
462 while(ch->ops->is_message_pending(ch)){
463 /* receive the message and call the callback*/
464 ret=ch->ops->recv(ch,&msg);
465
466 if(ret != IPC_OK){
467 /* If IPC is broken
468 * the we return FALSE, which results in removing of
469 * this class in handle function
470 * This should only happen when ccm is shutdown before the client
471 *
472 */
473 cl_log(LOG_INFO, "mem_handle_func:IPC broken, ccm is dead before the client!");
474 return FALSE;
475 }
476
477 type = ((ccm_meminfo_t *)msg->msg_body)->ev;
478
479
480 cookie= mbr_track = NULL;
481 size=0;
482 oc_type = OC_EV_MS_INVALID;
483
484 switch(type) {
485 case CCM_NEW_MEMBERSHIP :{
486
487 ccm_meminfo_t* cmi = (ccm_meminfo_t*)msg->msg_body;
488
489 size = get_new_membership(private,
490 cmi,
491 msg->msg_len,
492 &mbr_track);
493
494
495 mbr_track->quorum = quorum = cmi->quorum;
496
497 /* if no quorum, delete the bornon dates for lost
498 * nodes, add bornon dates for the new nodes and
499 * return
500 *
501 * however if special behaviour is being asked
502 * for report the membership even when this node
503 * has no quorum.
504 */
505 if (!private->special && !quorum){
506 update_bornons(private, mbr_track);
507 private->client_report = FALSE;
508 mem_free_func(mbr_track);
509 break;
510 }
511 private->client_report = TRUE;
512
513 /* if quorum and old membership is same as the new
514 * membership set type to OC_EV_MS_RESTORED ,
515 * pick the old membership and deliver it.
516 * Do not construct a new membership
517 */
518 if (membership_unchanged(private, mbr_track)){
519 mbr_track_t* old_mbr_track;
520
521 old_mbr_track = (mbr_track_t *)
522 cookie_get_data(private->cookie);
523
524 if (mbr_track->quorum == old_mbr_track->quorum){
525 oc_type = OC_EV_MS_PRIMARY_RESTORED;
526 }else {
527 cl_log(LOG_DEBUG, "membership unchanged but quorum changed");
528 oc_type = quorum?
529 OC_EV_MS_NEW_MEMBERSHIP:
530 OC_EV_MS_INVALID;
531 }
532
533 } else {
534 oc_type = quorum?
535 OC_EV_MS_NEW_MEMBERSHIP:
536 OC_EV_MS_INVALID;
537 /* NOTE: OC_EV_MS_INVALID overloaded to
538 * mean that the membership has no quorum.
539 * This is returned only when special behaviour
540 * is asked for. In normal behaviour case
541 * (as per 0.2 version of the api),
542 * OC_EV_MS_INVALID is never returned.
543 * I agree this is a kludge!!
544 */
545 if(!private->special) {
546 assert(oc_type == OC_EV_MS_NEW_MEMBERSHIP);
547 }
548 }
549
550 update_bornons(private, mbr_track);
551 cookie_unref(private->cookie);
552 cookie = cookie_construct(mem_callback_done,
553 mem_free_func, mbr_track);
554 private->cookie = cookie;
555 size = OC_EV_GET_SIZE(mbr_track);
556 break;
557 }
558 case CCM_EVICTED:
559 oc_type = OC_EV_MS_EVICTED;
560 private->client_report = TRUE;
561
562 size = 0;
563 mbr_track = NULL;
564
565 if (private->cookie){
566 cookie_unref(private->cookie);
567 }
568 cookie= cookie_construct(mem_callback_done, NULL,NULL);
569 if ( cookie == NULL){
570 cl_log(LOG_ERR, "mem_handle_event: coookie construction failed");
571 abort();
572 }
573 private->cookie=cookie;
574 break;
575
576 case CCM_INFLUX:
577
578 if(type==CCM_INFLUX){
579 oc_type = OC_EV_MS_NOT_PRIMARY;
580 }
581
582
583 cookie = private->cookie;
584 if(cookie) {
585 mbr_track = (mbr_track_t *)
586 cookie_get_data(cookie);
587 size=mbr_track? OC_EV_GET_SIZE(mbr_track): 0;
588 } else {
589 /* if no cookie exists, create one.
590 * This can happen if no membership
591 * has been delivered.
592 */
593 mbr_track=NULL;
594 size=0;
595 cookie = private->cookie =
596 cookie_construct(mem_callback_done,
597 NULL,NULL);
598 }
599 break;
600 case CCM_LLM:
601 on_llm_msg(private, msg);
602 }
603
604
605 cl_log(LOG_INFO, "%s: Got an event %s from ccm"
606 , __FUNCTION__
607 , EVENT_STRING(oc_type));
608 #define ALAN_DEBUG 1
609 #ifdef ALAN_DEBUG
610 if (!mbr_track) {
611 cl_log(LOG_INFO, "%s: no mbr_track info"
612 , __FUNCTION__);
613 }else{
614 cl_log(LOG_INFO
615 , "%s: instance=%d, nodes=%d, new=%d, lost=%d"
616 ", n_idx=%d, new_idx=%d, old_idx=%d"
617 , __FUNCTION__
618 , mbr_track->m_mem.m_instance
619 , mbr_track->m_mem.m_n_member
620 , mbr_track->m_mem.m_n_in
621 , mbr_track->m_mem.m_n_out
622 , mbr_track->m_mem.m_memb_idx
623 , mbr_track->m_mem.m_in_idx
624 , mbr_track->m_mem.m_out_idx);
625 }
626 #endif
627
628 if(private->callback && private->client_report && cookie){
629 cookie_ref(cookie);
630 private->callback(oc_type,
631 (uint *)cookie,
632 size,
633 mbr_track?&(mbr_track->m_mem):NULL);
634 }
635
636 if(ret==IPC_OK) {
637 msg->msg_done(msg);
638 } else {
639 return FALSE;
640 }
641
642 if(type == CCM_EVICTED) {
643 /* clean up the dynamic information in the
644 * private structure
645 */
646 reset_llm(private);
647 reset_bornon(private);
648 cookie_unref(private->cookie);
649 private->cookie = NULL;
650 }
651 }
652 return TRUE;
653 }
654
655
656 static int
657 mem_activate(class_t *class)
658 {
659 mbr_private_t *private;
660 struct IPC_CHANNEL *ch;
661 int sockfd;
662
663 if(!class_valid(class)) {
664 return -1;
665 }
666
667 /* if already activated */
668
669 private = (mbr_private_t *)class->private;
670 if(private->llm){
671 return -1;
672 }
673
674 ch = private->channel;
675
676 if(!ch || ch->ops->initiate_connection(ch) != IPC_OK) {
677 return -1;
678 }
679
680 ch->ops->set_recv_qlen(ch, 0);
681 sockfd = ch->ops->get_recv_select_fd(ch);
682
683 return sockfd;
684 }
685
686
687 static void
688 mem_unregister(class_t *class)
689 {
690 mbr_private_t *private;
691 struct IPC_CHANNEL *ch;
692
693 private = (mbr_private_t *)class->private;
694 ch = private->channel;
695
696 /* TOBEDONE
697 * call all instances, of message done
698 * on channel ch.
699 */
700
701 ch->ops->destroy(ch);
702
703 g_free(private->llm);
704 g_free(private);
705 }
706
707
708 static oc_ev_callback_t *
709 mem_set_callback(class_t *class, oc_ev_callback_t f)
710 {
711 mbr_private_t *private;
712 oc_ev_callback_t *ret_f;
713
714 if(!class_valid(class)){
715 return NULL;
716 }
717
718 private = (mbr_private_t *)class->private;
719
720 ret_f = private->callback;
721 private->callback = f;
722
723 return ret_f;
724 }
725
726
727 /* this function is a kludge, to accomodate special behaviour not
728 * supported by 0.2 version of the API
729 */
730 static void
731 mem_set_special(class_t *class, int type)
732 {
733 mbr_private_t *private;
734
735 if(!class_valid(class)) {
736 return;
737 }
738
739 private = (mbr_private_t *)class->private;
740
741 private->special = 1; /* turn on the special behaviour not supported
742 by 0.2 version of the API */
743
744
745 return;
746 }
747
748 static gboolean
749 mem_is_my_nodeid(class_t *class, const oc_node_t *node)
750 {
751 mbr_private_t *private;
752
753 if(!class_valid(class)){
754 return FALSE;
755 }
756 private = (mbr_private_t *)class->private;
757
758 if (node->node_id == CLLM_GET_MYUUID(private->llm)){
759 return TRUE;
760 }
761
762 return FALSE;
763 }
764
765
766 class_t *
767 oc_ev_memb_class(oc_ev_callback_t *fn)
768 {
769 mbr_private_t *private;
770 class_t *memclass;
771 struct IPC_CHANNEL *ch;
772 GHashTable * attrs;
773 static char path[] = IPC_PATH_ATTR;
774 static char ccmfifo[] = CCMFIFO;
775
776 memclass = g_malloc(sizeof(class_t));
777
778 if (!memclass){
779 return NULL;
780 }
781
782 private = (mbr_private_t *)g_malloc0(sizeof(mbr_private_t));
783 if (!private) {
784 g_free(memclass);
785 return NULL;
786 }
787
788 memclass->type = OC_EV_MEMB_CLASS;
789 memclass->set_callback = mem_set_callback;
790 memclass->handle_event = mem_handle_event;
791 memclass->activate = mem_activate;
792 memclass->unregister = mem_unregister;
793 memclass->is_my_nodeid = mem_is_my_nodeid;
794 memclass->special = mem_set_special;
795
796 memclass->private = (void *)private;
797 private->callback = fn;
798 private->magiccookie = 0xabcdef;
799 private->client_report = FALSE;
800 private->special = 0; /* no special behaviour */
801 private->llm = NULL;
802
803 attrs = g_hash_table_new(g_str_hash,g_str_equal);
804 g_hash_table_insert(attrs, path, ccmfifo);
805 ch = ipc_channel_constructor(IPC_DOMAIN_SOCKET, attrs);
806 g_hash_table_destroy(attrs);
807
808 if(!ch) {
809 g_free(memclass);
810 g_free(private);
811 return NULL;
812 }
813
814 private->channel = ch;
815
816 return memclass;
817 }