aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ocfs2/heartbeat.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ocfs2/heartbeat.c')
-rw-r--r--fs/ocfs2/heartbeat.c202
1 files changed, 17 insertions, 185 deletions
diff --git a/fs/ocfs2/heartbeat.c b/fs/ocfs2/heartbeat.c
index c0efd9489fe8..c6e7213db868 100644
--- a/fs/ocfs2/heartbeat.c
+++ b/fs/ocfs2/heartbeat.c
@@ -28,9 +28,6 @@
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/highmem.h> 30#include <linux/highmem.h>
31#include <linux/kmod.h>
32
33#include <dlm/dlmapi.h>
34 31
35#define MLOG_MASK_PREFIX ML_SUPER 32#define MLOG_MASK_PREFIX ML_SUPER
36#include <cluster/masklog.h> 33#include <cluster/masklog.h>
@@ -48,32 +45,36 @@ static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
48 int bit); 45 int bit);
49static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map, 46static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
50 int bit); 47 int bit);
51static inline int __ocfs2_node_map_is_empty(struct ocfs2_node_map *map); 48
52static void __ocfs2_node_map_dup(struct ocfs2_node_map *target, 49/* special case -1 for now
53 struct ocfs2_node_map *from); 50 * TODO: should *really* make sure the calling func never passes -1!! */
54static void __ocfs2_node_map_set(struct ocfs2_node_map *target, 51static void ocfs2_node_map_init(struct ocfs2_node_map *map)
55 struct ocfs2_node_map *from); 52{
53 map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
54 memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
55 sizeof(unsigned long));
56}
56 57
57void ocfs2_init_node_maps(struct ocfs2_super *osb) 58void ocfs2_init_node_maps(struct ocfs2_super *osb)
58{ 59{
59 spin_lock_init(&osb->node_map_lock); 60 spin_lock_init(&osb->node_map_lock);
60 ocfs2_node_map_init(&osb->recovery_map);
61 ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs); 61 ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
62} 62}
63 63
64static void ocfs2_do_node_down(int node_num, 64void ocfs2_do_node_down(int node_num, void *data)
65 struct ocfs2_super *osb)
66{ 65{
66 struct ocfs2_super *osb = data;
67
67 BUG_ON(osb->node_num == node_num); 68 BUG_ON(osb->node_num == node_num);
68 69
69 mlog(0, "ocfs2: node down event for %d\n", node_num); 70 mlog(0, "ocfs2: node down event for %d\n", node_num);
70 71
71 if (!osb->dlm) { 72 if (!osb->cconn) {
72 /* 73 /*
73 * No DLM means we're not even ready to participate yet. 74 * No cluster connection means we're not even ready to
74 * We check the slots after the DLM comes up, so we will 75 * participate yet. We check the slots after the cluster
75 * notice the node death then. We can safely ignore it 76 * comes up, so we will notice the node death then. We
76 * here. 77 * can safely ignore it here.
77 */ 78 */
78 return; 79 return;
79 } 80 }
@@ -81,70 +82,6 @@ static void ocfs2_do_node_down(int node_num,
81 ocfs2_recovery_thread(osb, node_num); 82 ocfs2_recovery_thread(osb, node_num);
82} 83}
83 84
84/* Called from the dlm when it's about to evict a node. We may also
85 * get a heartbeat callback later. */
86static void ocfs2_dlm_eviction_cb(int node_num,
87 void *data)
88{
89 struct ocfs2_super *osb = (struct ocfs2_super *) data;
90 struct super_block *sb = osb->sb;
91
92 mlog(ML_NOTICE, "device (%u,%u): dlm has evicted node %d\n",
93 MAJOR(sb->s_dev), MINOR(sb->s_dev), node_num);
94
95 ocfs2_do_node_down(node_num, osb);
96}
97
98void ocfs2_setup_hb_callbacks(struct ocfs2_super *osb)
99{
100 /* Not exactly a heartbeat callback, but leads to essentially
101 * the same path so we set it up here. */
102 dlm_setup_eviction_cb(&osb->osb_eviction_cb,
103 ocfs2_dlm_eviction_cb,
104 osb);
105}
106
107void ocfs2_stop_heartbeat(struct ocfs2_super *osb)
108{
109 int ret;
110 char *argv[5], *envp[3];
111
112 if (ocfs2_mount_local(osb))
113 return;
114
115 if (!osb->uuid_str) {
116 /* This can happen if we don't get far enough in mount... */
117 mlog(0, "No UUID with which to stop heartbeat!\n\n");
118 return;
119 }
120
121 argv[0] = (char *)o2nm_get_hb_ctl_path();
122 argv[1] = "-K";
123 argv[2] = "-u";
124 argv[3] = osb->uuid_str;
125 argv[4] = NULL;
126
127 mlog(0, "Run: %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
128
129 /* minimal command environment taken from cpu_run_sbin_hotplug */
130 envp[0] = "HOME=/";
131 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
132 envp[2] = NULL;
133
134 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
135 if (ret < 0)
136 mlog_errno(ret);
137}
138
139/* special case -1 for now
140 * TODO: should *really* make sure the calling func never passes -1!! */
141void ocfs2_node_map_init(struct ocfs2_node_map *map)
142{
143 map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
144 memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
145 sizeof(unsigned long));
146}
147
148static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map, 85static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
149 int bit) 86 int bit)
150{ 87{
@@ -196,108 +133,3 @@ int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
196 return ret; 133 return ret;
197} 134}
198 135
199static inline int __ocfs2_node_map_is_empty(struct ocfs2_node_map *map)
200{
201 int bit;
202 bit = find_next_bit(map->map, map->num_nodes, 0);
203 if (bit < map->num_nodes)
204 return 0;
205 return 1;
206}
207
208int ocfs2_node_map_is_empty(struct ocfs2_super *osb,
209 struct ocfs2_node_map *map)
210{
211 int ret;
212 BUG_ON(map->num_nodes == 0);
213 spin_lock(&osb->node_map_lock);
214 ret = __ocfs2_node_map_is_empty(map);
215 spin_unlock(&osb->node_map_lock);
216 return ret;
217}
218
219static void __ocfs2_node_map_dup(struct ocfs2_node_map *target,
220 struct ocfs2_node_map *from)
221{
222 BUG_ON(from->num_nodes == 0);
223 ocfs2_node_map_init(target);
224 __ocfs2_node_map_set(target, from);
225}
226
227/* returns 1 if bit is the only bit set in target, 0 otherwise */
228int ocfs2_node_map_is_only(struct ocfs2_super *osb,
229 struct ocfs2_node_map *target,
230 int bit)
231{
232 struct ocfs2_node_map temp;
233 int ret;
234
235 spin_lock(&osb->node_map_lock);
236 __ocfs2_node_map_dup(&temp, target);
237 __ocfs2_node_map_clear_bit(&temp, bit);
238 ret = __ocfs2_node_map_is_empty(&temp);
239 spin_unlock(&osb->node_map_lock);
240
241 return ret;
242}
243
244static void __ocfs2_node_map_set(struct ocfs2_node_map *target,
245 struct ocfs2_node_map *from)
246{
247 int num_longs, i;
248
249 BUG_ON(target->num_nodes != from->num_nodes);
250 BUG_ON(target->num_nodes == 0);
251
252 num_longs = BITS_TO_LONGS(target->num_nodes);
253 for (i = 0; i < num_longs; i++)
254 target->map[i] = from->map[i];
255}
256
257/* Returns whether the recovery bit was actually set - it may not be
258 * if a node is still marked as needing recovery */
259int ocfs2_recovery_map_set(struct ocfs2_super *osb,
260 int num)
261{
262 int set = 0;
263
264 spin_lock(&osb->node_map_lock);
265
266 if (!test_bit(num, osb->recovery_map.map)) {
267 __ocfs2_node_map_set_bit(&osb->recovery_map, num);
268 set = 1;
269 }
270
271 spin_unlock(&osb->node_map_lock);
272
273 return set;
274}
275
276void ocfs2_recovery_map_clear(struct ocfs2_super *osb,
277 int num)
278{
279 ocfs2_node_map_clear_bit(osb, &osb->recovery_map, num);
280}
281
282int ocfs2_node_map_iterate(struct ocfs2_super *osb,
283 struct ocfs2_node_map *map,
284 int idx)
285{
286 int i = idx;
287
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;
297 }
298 i++;
299 }
300 }
301 spin_unlock(&osb->node_map_lock);
302 return idx;
303}