Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / fs / ocfs2 / heartbeat.c
blob1c80c6a8d48db1c74055499a79daf1b11901d1d0
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);
52 <<<<<<< HEAD:fs/ocfs2/heartbeat.c
53 static void __ocfs2_node_map_dup(struct ocfs2_node_map *target,
54 struct ocfs2_node_map *from);
55 static void __ocfs2_node_map_set(struct ocfs2_node_map *target,
56 struct ocfs2_node_map *from);
57 =======
59 /* special case -1 for now
60 * TODO: should *really* make sure the calling func never passes -1!! */
61 static void ocfs2_node_map_init(struct ocfs2_node_map *map)
63 map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
64 memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
65 sizeof(unsigned long));
67 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/ocfs2/heartbeat.c
69 void ocfs2_init_node_maps(struct ocfs2_super *osb)
71 spin_lock_init(&osb->node_map_lock);
72 ocfs2_node_map_init(&osb->recovery_map);
73 ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
76 static void ocfs2_do_node_down(int node_num,
77 struct ocfs2_super *osb)
79 BUG_ON(osb->node_num == node_num);
81 mlog(0, "ocfs2: node down event for %d\n", node_num);
83 if (!osb->dlm) {
85 * No DLM means we're not even ready to participate yet.
86 * We check the slots after the DLM comes up, so we will
87 * notice the node death then. We can safely ignore it
88 * here.
90 return;
93 ocfs2_recovery_thread(osb, node_num);
96 /* Called from the dlm when it's about to evict a node. We may also
97 * get a heartbeat callback later. */
98 static void ocfs2_dlm_eviction_cb(int node_num,
99 void *data)
101 struct ocfs2_super *osb = (struct ocfs2_super *) data;
102 struct super_block *sb = osb->sb;
104 mlog(ML_NOTICE, "device (%u,%u): dlm has evicted node %d\n",
105 MAJOR(sb->s_dev), MINOR(sb->s_dev), node_num);
107 ocfs2_do_node_down(node_num, osb);
110 void ocfs2_setup_hb_callbacks(struct ocfs2_super *osb)
112 /* Not exactly a heartbeat callback, but leads to essentially
113 * the same path so we set it up here. */
114 dlm_setup_eviction_cb(&osb->osb_eviction_cb,
115 ocfs2_dlm_eviction_cb,
116 osb);
119 void ocfs2_stop_heartbeat(struct ocfs2_super *osb)
121 int ret;
122 char *argv[5], *envp[3];
124 if (ocfs2_mount_local(osb))
125 return;
127 if (!osb->uuid_str) {
128 /* This can happen if we don't get far enough in mount... */
129 mlog(0, "No UUID with which to stop heartbeat!\n\n");
130 return;
133 argv[0] = (char *)o2nm_get_hb_ctl_path();
134 argv[1] = "-K";
135 argv[2] = "-u";
136 argv[3] = osb->uuid_str;
137 argv[4] = NULL;
139 mlog(0, "Run: %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
141 /* minimal command environment taken from cpu_run_sbin_hotplug */
142 envp[0] = "HOME=/";
143 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
144 envp[2] = NULL;
146 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
147 if (ret < 0)
148 mlog_errno(ret);
151 <<<<<<< HEAD:fs/ocfs2/heartbeat.c
152 /* special case -1 for now
153 * TODO: should *really* make sure the calling func never passes -1!! */
154 void ocfs2_node_map_init(struct ocfs2_node_map *map)
156 map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
157 memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
158 sizeof(unsigned long));
161 =======
162 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/ocfs2/heartbeat.c
163 static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
164 int bit)
166 set_bit(bit, map->map);
169 void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
170 struct ocfs2_node_map *map,
171 int bit)
173 if (bit==-1)
174 return;
175 BUG_ON(bit >= map->num_nodes);
176 spin_lock(&osb->node_map_lock);
177 __ocfs2_node_map_set_bit(map, bit);
178 spin_unlock(&osb->node_map_lock);
181 static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
182 int bit)
184 clear_bit(bit, map->map);
187 void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
188 struct ocfs2_node_map *map,
189 int bit)
191 if (bit==-1)
192 return;
193 BUG_ON(bit >= map->num_nodes);
194 spin_lock(&osb->node_map_lock);
195 __ocfs2_node_map_clear_bit(map, bit);
196 spin_unlock(&osb->node_map_lock);
199 int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
200 struct ocfs2_node_map *map,
201 int bit)
203 int ret;
204 if (bit >= map->num_nodes) {
205 mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
206 BUG();
208 spin_lock(&osb->node_map_lock);
209 ret = test_bit(bit, map->map);
210 spin_unlock(&osb->node_map_lock);
211 return ret;
214 static inline int __ocfs2_node_map_is_empty(struct ocfs2_node_map *map)
216 int bit;
217 bit = find_next_bit(map->map, map->num_nodes, 0);
218 if (bit < map->num_nodes)
219 return 0;
220 return 1;
223 int ocfs2_node_map_is_empty(struct ocfs2_super *osb,
224 struct ocfs2_node_map *map)
226 int ret;
227 BUG_ON(map->num_nodes == 0);
228 spin_lock(&osb->node_map_lock);
229 ret = __ocfs2_node_map_is_empty(map);
230 spin_unlock(&osb->node_map_lock);
231 return ret;
234 <<<<<<< HEAD:fs/ocfs2/heartbeat.c
235 =======
236 #if 0
238 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/ocfs2/heartbeat.c
239 static void __ocfs2_node_map_dup(struct ocfs2_node_map *target,
240 struct ocfs2_node_map *from)
242 BUG_ON(from->num_nodes == 0);
243 ocfs2_node_map_init(target);
244 __ocfs2_node_map_set(target, from);
247 /* returns 1 if bit is the only bit set in target, 0 otherwise */
248 int ocfs2_node_map_is_only(struct ocfs2_super *osb,
249 struct ocfs2_node_map *target,
250 int bit)
252 struct ocfs2_node_map temp;
253 int ret;
255 spin_lock(&osb->node_map_lock);
256 __ocfs2_node_map_dup(&temp, target);
257 __ocfs2_node_map_clear_bit(&temp, bit);
258 ret = __ocfs2_node_map_is_empty(&temp);
259 spin_unlock(&osb->node_map_lock);
261 return ret;
264 static void __ocfs2_node_map_set(struct ocfs2_node_map *target,
265 struct ocfs2_node_map *from)
267 int num_longs, i;
269 BUG_ON(target->num_nodes != from->num_nodes);
270 BUG_ON(target->num_nodes == 0);
272 num_longs = BITS_TO_LONGS(target->num_nodes);
273 for (i = 0; i < num_longs; i++)
274 target->map[i] = from->map[i];
277 <<<<<<< HEAD:fs/ocfs2/heartbeat.c
278 =======
279 #endif /* 0 */
281 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:fs/ocfs2/heartbeat.c
282 /* Returns whether the recovery bit was actually set - it may not be
283 * if a node is still marked as needing recovery */
284 int ocfs2_recovery_map_set(struct ocfs2_super *osb,
285 int num)
287 int set = 0;
289 spin_lock(&osb->node_map_lock);
291 if (!test_bit(num, osb->recovery_map.map)) {
292 __ocfs2_node_map_set_bit(&osb->recovery_map, num);
293 set = 1;
296 spin_unlock(&osb->node_map_lock);
298 return set;
301 void ocfs2_recovery_map_clear(struct ocfs2_super *osb,
302 int num)
304 ocfs2_node_map_clear_bit(osb, &osb->recovery_map, num);
307 int ocfs2_node_map_iterate(struct ocfs2_super *osb,
308 struct ocfs2_node_map *map,
309 int idx)
311 int i = idx;
313 idx = O2NM_INVALID_NODE_NUM;
314 spin_lock(&osb->node_map_lock);
315 if ((i != O2NM_INVALID_NODE_NUM) &&
316 (i >= 0) &&
317 (i < map->num_nodes)) {
318 while(i < map->num_nodes) {
319 if (test_bit(i, map->map)) {
320 idx = i;
321 break;
323 i++;
326 spin_unlock(&osb->node_map_lock);
327 return idx;