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,
52 /* special case -1 for now
53 * TODO: should *really* make sure the calling func never passes -1!! */
54 static void ocfs2_node_map_init(struct ocfs2_node_map *map)
56 map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
57 memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
58 sizeof(unsigned long));
61 void ocfs2_init_node_maps(struct ocfs2_super *osb)
63 spin_lock_init(&osb->node_map_lock);
64 ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
67 static void ocfs2_do_node_down(int node_num,
68 struct ocfs2_super *osb)
70 BUG_ON(osb->node_num == node_num);
72 mlog(0, "ocfs2: node down event for %d\n", node_num);
76 * No DLM means we're not even ready to participate yet.
77 * We check the slots after the DLM comes up, so we will
78 * notice the node death then. We can safely ignore it
84 ocfs2_recovery_thread(osb, node_num);
87 /* Called from the dlm when it's about to evict a node. We may also
88 * get a heartbeat callback later. */
89 static void ocfs2_dlm_eviction_cb(int node_num,
92 struct ocfs2_super *osb = (struct ocfs2_super *) data;
93 struct super_block *sb = osb->sb;
95 mlog(ML_NOTICE, "device (%u,%u): dlm has evicted node %d\n",
96 MAJOR(sb->s_dev), MINOR(sb->s_dev), node_num);
98 ocfs2_do_node_down(node_num, osb);
101 void ocfs2_setup_hb_callbacks(struct ocfs2_super *osb)
103 /* Not exactly a heartbeat callback, but leads to essentially
104 * the same path so we set it up here. */
105 dlm_setup_eviction_cb(&osb->osb_eviction_cb,
106 ocfs2_dlm_eviction_cb,
110 void ocfs2_stop_heartbeat(struct ocfs2_super *osb)
113 char *argv[5], *envp[3];
115 if (ocfs2_mount_local(osb))
118 if (!osb->uuid_str) {
119 /* This can happen if we don't get far enough in mount... */
120 mlog(0, "No UUID with which to stop heartbeat!\n\n");
124 argv[0] = (char *)o2nm_get_hb_ctl_path();
127 argv[3] = osb->uuid_str;
130 mlog(0, "Run: %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
132 /* minimal command environment taken from cpu_run_sbin_hotplug */
134 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
137 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
142 static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
145 set_bit(bit, map->map);
148 void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
149 struct ocfs2_node_map *map,
154 BUG_ON(bit >= map->num_nodes);
155 spin_lock(&osb->node_map_lock);
156 __ocfs2_node_map_set_bit(map, bit);
157 spin_unlock(&osb->node_map_lock);
160 static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
163 clear_bit(bit, map->map);
166 void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
167 struct ocfs2_node_map *map,
172 BUG_ON(bit >= map->num_nodes);
173 spin_lock(&osb->node_map_lock);
174 __ocfs2_node_map_clear_bit(map, bit);
175 spin_unlock(&osb->node_map_lock);
178 int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
179 struct ocfs2_node_map *map,
183 if (bit >= map->num_nodes) {
184 mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
187 spin_lock(&osb->node_map_lock);
188 ret = test_bit(bit, map->map);
189 spin_unlock(&osb->node_map_lock);