~wb-munzinger/+junk/ocfs2-tools

« back to all changes in this revision

Viewing changes to ocfs2_controld/pacemaker.c

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2009-07-06 07:26:30 UTC
  • mfrom: (1.1.7 upstream) (0.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090706072630-59335sl51k3rvu74
Tags: 1.4.2-1
* New upstream release (Closes: #535471).
* Drop patch for limits.h, included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: c; c-basic-offset: 8; -*-
 
2
 * vim: noexpandtab sw=8 ts=8 sts=0:
 
3
 */
 
4
 
 
5
/*
 
6
 * Copyright (C) 2008 Novell.
 
7
 *
 
8
 * Some portions Copyright Oracle.
 
9
 *
 
10
 * This copyrighted material is made available to anyone wishing to use,
 
11
 * modify, copy, or redistribute it subject to the terms and conditions
 
12
 * of the GNU General Public License v.2.
 
13
 */
 
14
 
 
15
#include <stdio.h>
 
16
#include <string.h>
 
17
#include <stdlib.h>
 
18
#include <time.h>
 
19
#include <errno.h>
 
20
#include <unistd.h>
 
21
#include <syslog.h>
 
22
 
 
23
#include <bzlib.h>
 
24
 
 
25
#include <pacemaker/crm_config.h>
 
26
/* heartbeat support is irrelevant here */
 
27
#undef SUPPORT_HEARTBEAT
 
28
#define SUPPORT_HEARTBEAT 0
 
29
 
 
30
#include <pacemaker/crm/crm.h>
 
31
#include <pacemaker/crm/ais.h>
 
32
#include <pacemaker/crm/common/cluster.h>
 
33
#include <pacemaker/crm/common/stack.h>
 
34
 
 
35
#include "ocfs2-kernel/kernel-list.h"
 
36
#include "o2cb/o2cb.h"
 
37
 
 
38
#include "ocfs2_controld.h"
 
39
 
 
40
#include <sys/utsname.h>
 
41
 
 
42
int                     our_nodeid = 0;
 
43
static int              pcmk_ci;
 
44
static int              stonithd_ci;
 
45
static char *           clustername = "pacemaker";
 
46
extern struct list_head mounts;
 
47
const char *stackname = "pcmk";
 
48
 
 
49
extern int ais_fd_async;
 
50
char *local_node_uname = NULL;
 
51
 
 
52
static int pcmk_cluster_fd = 0;
 
53
 
 
54
static void stonith_callback(int ci)
 
55
{
 
56
    log_error("%s: Lost connection to the cluster", __FUNCTION__);
 
57
    pcmk_cluster_fd = 0;
 
58
    return;
 
59
}
 
60
 
 
61
int kill_stack_node(int nodeid)
 
62
{
 
63
        int fd = pcmk_cluster_fd;
 
64
        int rc = crm_terminate_member_no_mainloop(nodeid, NULL, &fd);
 
65
 
 
66
 
 
67
        if(fd > 0 && fd != pcmk_cluster_fd) {
 
68
                pcmk_cluster_fd = fd;
 
69
                connection_add(pcmk_cluster_fd, NULL, stonith_callback);
 
70
        }
 
71
 
 
72
        switch(rc) {
 
73
                case 1:
 
74
                        log_debug("Requested that node %d be kicked from the cluster", nodeid);
 
75
                        break;
 
76
                case -1:
 
77
                        log_error("Don't know how to kick node %d from the cluster", nodeid);
 
78
                        break;
 
79
                case 0:
 
80
                        log_error("Could not kick node %d from the cluster", nodeid);
 
81
                        break;
 
82
                default:
 
83
                        log_error("Unknown result when kicking node %d from the cluster", nodeid);
 
84
                        break;
 
85
        }
 
86
 
 
87
        return rc;
 
88
}
 
89
 
 
90
char *nodeid2name(int nodeid) {
 
91
        crm_node_t *node = crm_get_peer(nodeid, NULL);
 
92
 
 
93
        if(node->uname == NULL)
 
94
                return NULL;
 
95
 
 
96
        return strdup(node->uname);
 
97
}
 
98
 
 
99
int validate_cluster(const char *cluster)
 
100
{
 
101
        if (!clustername) {
 
102
                log_error("Trying to validate before pacemaker is alive");
 
103
                return 0;
 
104
        }
 
105
 
 
106
        if (!cluster)
 
107
                return 0;
 
108
 
 
109
        return !strcmp(cluster, clustername);
 
110
}
 
111
 
 
112
int get_clustername(const char **cluster)
 
113
{
 
114
        if (!clustername) {
 
115
                log_error("Trying to validate before pacemaker is alive");
 
116
                return -EIO;
 
117
        }
 
118
 
 
119
        if (!cluster) {
 
120
                log_error("NULL passed!");
 
121
                return -EINVAL;
 
122
        }
 
123
 
 
124
        *cluster = clustername;
 
125
        return 0;
 
126
}
 
127
 
 
128
static void dead_pcmk(int ci)
 
129
{
 
130
        if (ci != pcmk_ci) {
 
131
                log_error("Unknown connection %d", ci);
 
132
                return;
 
133
        }
 
134
 
 
135
        log_error("pacemaker connection died");
 
136
        shutdown_daemon();
 
137
        connection_dead(ci);
 
138
}
 
139
 
 
140
extern void terminate_ais_connection(void);
 
141
 
 
142
void exit_stack(void)
 
143
{
 
144
        log_debug("closing pacemaker connection");
 
145
        terminate_ais_connection();
 
146
}
 
147
 
 
148
static void process_pcmk(int ci)
 
149
{
 
150
        ais_dispatch(ais_fd_async, NULL);
 
151
}
 
152
 
 
153
int setup_stack(void)
 
154
{
 
155
        crm_log_init("ocfs2_controld", LOG_INFO, FALSE, TRUE, 0, NULL);
 
156
 
 
157
        if(init_ais_connection(NULL, NULL, NULL, &local_node_uname, &our_nodeid) == FALSE) {
 
158
                log_error("Connection to our AIS plugin (%d) failed", CRM_SERVICE);
 
159
                return -1;
 
160
        }
 
161
 
 
162
        /* Sign up for membership updates */
 
163
        send_ais_text(crm_class_notify, "true", TRUE, NULL, crm_msg_ais);
 
164
 
 
165
        /* Requesting the current list of known nodes */
 
166
        send_ais_text(crm_class_members, __FUNCTION__, TRUE, NULL, crm_msg_ais);
 
167
 
 
168
        log_debug("Cluster connection established.  Local node id: %d", our_nodeid);
 
169
 
 
170
        pcmk_ci = connection_add(ais_fd_async, process_pcmk, dead_pcmk);
 
171
        if (pcmk_ci >= 0) {
 
172
                log_debug("Added Pacemaker as client %d with fd %d", pcmk_ci, ais_fd_async);
 
173
                return ais_fd_async;
 
174
        }
 
175
 
 
176
        log_error("Unable to add pacemaker client: %s", strerror(-pcmk_ci));
 
177
        exit_stack();
 
178
        return pcmk_ci;
 
179
}