| 1 |
/* |
| 2 |
* ccm.c: A consensus cluster membership sample client |
| 3 |
* |
| 4 |
* Copyright (c) International Business Machines Corp., 2000 |
| 5 |
* Author: Ram Pai ([email protected]) |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of the GNU General Public License as published by |
| 9 |
* the Free Software Foundation; either version 2 of the License, or |
| 10 |
* (at your option) any later version. |
| 11 |
* |
| 12 |
* This program 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 |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
#include <lha_internal.h> |
| 23 |
#include <ocf/oc_event.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <sys/time.h> |
| 26 |
#include <sys/types.h> |
| 27 |
#include <string.h> |
| 28 |
#include <unistd.h> |
| 29 |
#include <syslog.h> |
| 30 |
#include <clplumbing/cl_log.h> |
| 31 |
|
| 32 |
|
| 33 |
static oc_ev_t *ev_token; |
| 34 |
|
| 35 |
extern void oc_ev_special(const oc_ev_t *, oc_ev_class_t , int ); |
| 36 |
|
| 37 |
|
| 38 |
static void |
| 39 |
my_ms_events(oc_ed_t event, void *cookie, |
| 40 |
size_t size, const void *data) |
| 41 |
{ |
| 42 |
const oc_ev_membership_t *oc = (const oc_ev_membership_t *)data; |
| 43 |
uint i; |
| 44 |
int i_am_in; |
| 45 |
|
| 46 |
cl_log(LOG_INFO,"event=%s:", |
| 47 |
event==OC_EV_MS_NEW_MEMBERSHIP?"NEW MEMBERSHIP": |
| 48 |
event==OC_EV_MS_NOT_PRIMARY?"NOT PRIMARY": |
| 49 |
event==OC_EV_MS_PRIMARY_RESTORED?"PRIMARY RESTORED": |
| 50 |
event==OC_EV_MS_EVICTED?"EVICTED": |
| 51 |
"NO QUORUM MEMBERSHIP" |
| 52 |
); |
| 53 |
|
| 54 |
if(OC_EV_MS_EVICTED == event) { |
| 55 |
oc_ev_callback_done(cookie); |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
cl_log(LOG_INFO,"instance=%d\n" |
| 60 |
"# ttl members=%d, ttl_idx=%d\n" |
| 61 |
"# new members=%d, new_idx=%d\n" |
| 62 |
"# out members=%d, out_idx=%d", |
| 63 |
oc->m_instance, |
| 64 |
oc->m_n_member, |
| 65 |
oc->m_memb_idx, |
| 66 |
oc->m_n_in, |
| 67 |
oc->m_in_idx, |
| 68 |
oc->m_n_out, |
| 69 |
oc->m_out_idx); |
| 70 |
|
| 71 |
i_am_in=0; |
| 72 |
cl_log(LOG_INFO, "NODES IN THE PRIMARY MEMBERSHIP"); |
| 73 |
for(i=0; i<oc->m_n_member; i++) { |
| 74 |
cl_log(LOG_INFO,"\tnodeid=%d, uname=%s, born=%d", |
| 75 |
oc->m_array[oc->m_memb_idx+i].node_id, |
| 76 |
oc->m_array[oc->m_memb_idx+i].node_uname, |
| 77 |
oc->m_array[oc->m_memb_idx+i].node_born_on); |
| 78 |
if(oc_ev_is_my_nodeid(ev_token, &(oc->m_array[i]))){ |
| 79 |
i_am_in=1; |
| 80 |
} |
| 81 |
} |
| 82 |
if(i_am_in) { |
| 83 |
cl_log(LOG_INFO,"MY NODE IS A MEMBER OF THE MEMBERSHIP LIST"); |
| 84 |
} |
| 85 |
|
| 86 |
cl_log(LOG_INFO, "NEW MEMBERS"); |
| 87 |
if(oc->m_n_in==0) |
| 88 |
cl_log(LOG_INFO, "\tNONE"); |
| 89 |
for(i=0; i<oc->m_n_in; i++) { |
| 90 |
cl_log(LOG_INFO,"\tnodeid=%d, uname=%s, born=%d", |
| 91 |
oc->m_array[oc->m_in_idx+i].node_id, |
| 92 |
oc->m_array[oc->m_in_idx+i].node_uname, |
| 93 |
oc->m_array[oc->m_in_idx+i].node_born_on); |
| 94 |
} |
| 95 |
cl_log(LOG_INFO, "MEMBERS LOST"); |
| 96 |
if(oc->m_n_out==0) |
| 97 |
cl_log(LOG_INFO, "\tNONE"); |
| 98 |
for(i=0; i<oc->m_n_out; i++) { |
| 99 |
cl_log(LOG_INFO,"\tnodeid=%d, uname=%s, born=%d", |
| 100 |
oc->m_array[oc->m_out_idx+i].node_id, |
| 101 |
oc->m_array[oc->m_out_idx+i].node_uname, |
| 102 |
oc->m_array[oc->m_out_idx+i].node_born_on); |
| 103 |
} |
| 104 |
cl_log(LOG_INFO, "-----------------------"); |
| 105 |
oc_ev_callback_done(cookie); |
| 106 |
} |
| 107 |
|
| 108 |
int |
| 109 |
main(int argc, char *argv[]) |
| 110 |
{ |
| 111 |
int ret; |
| 112 |
fd_set rset; |
| 113 |
int my_ev_fd; |
| 114 |
|
| 115 |
cl_log_set_entity(argv[0]); |
| 116 |
cl_log_enable_stderr(TRUE); |
| 117 |
cl_log_set_facility(LOG_USER); |
| 118 |
oc_ev_register(&ev_token); |
| 119 |
|
| 120 |
oc_ev_set_callback(ev_token, OC_EV_MEMB_CLASS, my_ms_events, NULL); |
| 121 |
oc_ev_special(ev_token, OC_EV_MEMB_CLASS, 0/*don't care*/); |
| 122 |
|
| 123 |
ret = oc_ev_activate(ev_token, &my_ev_fd); |
| 124 |
if(ret){ |
| 125 |
oc_ev_unregister(ev_token); |
| 126 |
return(1); |
| 127 |
} |
| 128 |
|
| 129 |
for (;;) { |
| 130 |
|
| 131 |
FD_ZERO(&rset); |
| 132 |
FD_SET(my_ev_fd, &rset); |
| 133 |
|
| 134 |
if(select(my_ev_fd + 1, &rset, NULL,NULL,NULL) == -1){ |
| 135 |
perror("select"); |
| 136 |
return(1); |
| 137 |
} |
| 138 |
if(oc_ev_handle_event(ev_token)){ |
| 139 |
cl_log(LOG_ERR,"terminating"); |
| 140 |
return(1); |
| 141 |
} |
| 142 |
} |
| 143 |
return 0; |
| 144 |
} |