[ARM] 4956/1: Scoop: sparse cleanup
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / ocfs2 / heartbeat.c
blob0758daf64da07c41fcf4f73a7b55d634589ab87d
1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
4 * heartbeat.c
6 * Register ourselves with the heartbaet service, keep our node maps
7 * up to date, and fire off recovery when needed.
9 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public
22 * License along with this program; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 021110-1307, USA.
27 #include <linux/fs.h>
28 #include <linux/types.h>
29 #include <linux/slab.h>
30 #include <linux/highmem.h>
31 #include <linux/kmod.h>
33 #include <dlm/dlmapi.h>
35 #define MLOG_MASK_PREFIX ML_SUPER
36 #include <cluster/masklog.h>
38 #include "ocfs2.h"
40 #include "alloc.h"
41 #include "heartbeat.h"
42 #include "inode.h"
43 #include "journal.h"
45 #include "buffer_head_io.h"
47 static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
48 int bit);
49 static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
50 int bit);
51 static inline int __ocfs2_node_map_is_empty(struct ocfs2_node_map *map);
53 /* special case -1 for now
54 * TODO: should *really* make sure the calling func never passes -1!! */
55 static void ocfs2_node_map_init(struct ocfs2_node_map *map)
57 map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
58 memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
59 sizeof(unsigned long));
62 void ocfs2_init_node_maps(struct ocfs2_super *osb)
64 spin_lock_init(&osb->node_map_lock);
65 ocfs2_node_map_init(&osb->recovery_map);
66 ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
69 static void ocfs2_do_node_down(int node_num,
70 struct ocfs2_super *osb)
72 BUG_ON(osb->node_num == node_num);
74 mlog(0, "ocfs2: node down event for %d\n", node_num);
76 if (!osb->dlm) {
78 * No DLM means we're not even ready to participate yet.
79 * We check the slots after the DLM comes up, so we will
80 * notice the node death then. We can safely ignore it
81 * here.
83 return;
86 ocfs2_recovery_thread(osb, node_num);
89 /* Called from the dlm when it's about to evict a node. We may also
90 * get a heartbeat callback later. */
91 static void ocfs2_dlm_eviction_cb(int node_num,
92 void *data)
94 struct ocfs2_super *osb = (struct ocfs2_super *) data;
95 struct super_block *sb = osb->sb;
97 mlog(ML_NOTICE, "device (%u,%u): dlm has evicted node %d\n",
98 MAJOR(sb->s_dev), MINOR(sb->s_dev), node_num);
100 ocfs2_do_node_down(node_num, osb);
103 void ocfs2_setup_hb_callbacks(struct ocfs2_super *osb)
105 /* Not exactly a heartbeat callback, but leads to essentially
106 * the same path so we set it up here. */
107 dlm_setup_eviction_cb(&osb->osb_eviction_cb,
108 ocfs2_dlm_eviction_cb,
109 osb);
112 void ocfs2_stop_heartbeat(struct ocfs2_super *osb)
114 int ret;
115 char *argv[5], *envp[3];
117 if (ocfs2_mount_local(osb))
118 return;
120 if (!osb->uuid_str) {
121 /* This can happen if we don't get far enough in mount... */
122 mlog(0, "No UUID with which to stop heartbeat!\n\n");
123 return;
126 argv[0] = (char *)o2nm_get_hb_ctl_path();
127 argv[1] = "-K";
128 argv[2] = "-u";
129 argv[3] = osb->uuid_str;
130 argv[4] = NULL;
132 mlog(0, "Run: %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
134 /* minimal command environment taken from cpu_run_sbin_hotplug */
135 envp[0] = "HOME=/";
136 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
137 envp[2] = NULL;
139 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
140 if (ret < 0)
141 mlog_errno(ret);
144 static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
145 int bit)
147 set_bit(bit, map->map);
150 void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
151 struct ocfs2_node_map *map,
152 int bit)
154 if (bit==-1)
155 return;
156 BUG_ON(bit >= map->num_nodes);
157 spin_lock(&osb->node_map_lock);
158 __ocfs2_node_map_set_bit(map, bit);
159 spin_unlock(&osb->node_map_lock);
162 static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
163 int bit)
165 clear_bit(bit, map->map);
168 void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
169 struct ocfs2_node_map *map,
170 int bit)
172 if (bit==-1)
173 return;
174 BUG_ON(bit >= map->num_nodes);
175 spin_lock(&osb->node_map_lock);
176 __ocfs2_node_map_clear_bit(map, bit);
177 spin_unlock(&osb->node_map_lock);
180 int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
181 struct ocfs2_node_map *map,
182 int bit)
184 int ret;
185 if (bit >= map->num_nodes) {
186 mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
187 BUG();
189 spin_lock(&osb->node_map_lock);
190 ret = test_bit(bit, map->map);
191 spin_unlock(&osb->node_map_lock);
192 return ret;
195 static inline int __ocfs2_node_map_is_empty(struct ocfs2_node_map *map)
197 int bit;
198 bit = find_next_bit(map->map, map->num_nodes, 0);
199 if (bit < map->num_nodes)
200 return 0;
201 return 1;
204 int ocfs2_node_map_is_empty(struct ocfs2_super *osb,
205 struct ocfs2_node_map *map)
207 int ret;
208 BUG_ON(map->num_nodes == 0);
209 spin_lock(&osb->node_map_lock);
210 ret = __ocfs2_node_map_is_empty(map);
211 spin_unlock(&osb->node_map_lock);
212 return ret;
215 #if 0
217 static void __ocfs2_node_map_dup(struct ocfs2_node_map *target,
218 struct ocfs2_node_map *from)
220 BUG_ON(from->num_nodes == 0);
221 ocfs2_node_map_init(target);
222 __ocfs2_node_map_set(target, from);
225 /* returns 1 if bit is the only bit set in target, 0 otherwise */
226 int ocfs2_node_map_is_only(struct ocfs2_super *osb,
227 struct ocfs2_node_map *target,
228 int bit)
230 struct ocfs2_node_map temp;
231 int ret;
233 spin_lock(&osb->node_map_lock);
234 __ocfs2_node_map_dup(&temp, target);
235 __ocfs2_node_map_clear_bit(&temp, bit);
236 ret = __ocfs2_node_map_is_empty(&temp);
237 spin_unlock(&osb->node_map_lock);
239 return ret;
242 static void __ocfs2_node_map_set(struct ocfs2_node_map *target,
243 struct ocfs2_node_map *from)
245 int num_longs, i;
247 BUG_ON(target->num_nodes != from->num_nodes);
248 BUG_ON(target->num_nodes == 0);
250 num_longs = BITS_TO_LONGS(target->num_nodes);
251 for (i = 0; i < num_longs; i++)
252 target->map[i] = from->map[i];
255 #endif /* 0 */
257 /* Returns whether the recovery bit was actually set - it may not be
258 * if a node is still marked as needing recovery */
259 int ocfs2_recovery_map_set(struct ocfs2_super *osb,
260 int num)
262 int set = 0;
264 spin_lock(&osb->node_map_lock);
266 if (!test_bit(num, osb->recovery_map.map)) {
267 __ocfs2_node_map_set_bit(&osb->recovery_map, num);
268 set = 1;
271 spin_unlock(&osb->node_map_lock);
273 return set;
276 void ocfs2_recovery_map_clear(struct ocfs2_super *osb,
277 int num)
279 ocfs2_node_map_clear_bit(osb, &osb->recovery_map, num);
282 int ocfs2_node_map_iterate(struct ocfs2_super *osb,
283 struct ocfs2_node_map *map,
284 int idx)
286 int i = idx;
288 idx = O2NM_INVALID_NODE_NUM;
289 spin_lock(&osb->node_map_lock);
290 if ((i != O2NM_INVALID_NODE_NUM) &&
291 (i >= 0) &&
292 (i < map->num_nodes)) {
293 while(i < map->num_nodes) {
294 if (test_bit(i, map->map)) {
295 idx = i;
296 break;
298 i++;
301 spin_unlock(&osb->node_map_lock);
302 return idx;