1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
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.
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>
41 #include "heartbeat.h"
45 #include "buffer_head_io.h"
47 static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map
*map
,
49 static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map
*map
,
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
);
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
);
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
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
,
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
,
119 void ocfs2_stop_heartbeat(struct ocfs2_super
*osb
)
122 char *argv
[5], *envp
[3];
124 if (ocfs2_mount_local(osb
))
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");
133 argv
[0] = (char *)o2nm_get_hb_ctl_path();
136 argv
[3] = osb
->uuid_str
;
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 */
143 envp
[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
146 ret
= call_usermodehelper(argv
[0], argv
, envp
, UMH_WAIT_PROC
);
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));
162 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:fs
/ocfs2
/heartbeat
.c
163 static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map
*map
,
166 set_bit(bit
, map
->map
);
169 void ocfs2_node_map_set_bit(struct ocfs2_super
*osb
,
170 struct ocfs2_node_map
*map
,
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
,
184 clear_bit(bit
, map
->map
);
187 void ocfs2_node_map_clear_bit(struct ocfs2_super
*osb
,
188 struct ocfs2_node_map
*map
,
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
,
204 if (bit
>= map
->num_nodes
) {
205 mlog(ML_ERROR
, "bit=%d map->num_nodes=%d\n", bit
, map
->num_nodes
);
208 spin_lock(&osb
->node_map_lock
);
209 ret
= test_bit(bit
, map
->map
);
210 spin_unlock(&osb
->node_map_lock
);
214 static inline int __ocfs2_node_map_is_empty(struct ocfs2_node_map
*map
)
217 bit
= find_next_bit(map
->map
, map
->num_nodes
, 0);
218 if (bit
< map
->num_nodes
)
223 int ocfs2_node_map_is_empty(struct ocfs2_super
*osb
,
224 struct ocfs2_node_map
*map
)
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
);
234 <<<<<<< HEAD
:fs
/ocfs2
/heartbeat
.c
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
,
252 struct ocfs2_node_map temp
;
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
);
264 static void __ocfs2_node_map_set(struct ocfs2_node_map
*target
,
265 struct ocfs2_node_map
*from
)
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
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
,
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
);
296 spin_unlock(&osb
->node_map_lock
);
301 void ocfs2_recovery_map_clear(struct ocfs2_super
*osb
,
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
,
313 idx
= O2NM_INVALID_NODE_NUM
;
314 spin_lock(&osb
->node_map_lock
);
315 if ((i
!= O2NM_INVALID_NODE_NUM
) &&
317 (i
< map
->num_nodes
)) {
318 while(i
< map
->num_nodes
) {
319 if (test_bit(i
, map
->map
)) {
326 spin_unlock(&osb
->node_map_lock
);