blob: dcac1a48728816d7027f5ede17fa2af0c22eb611 [file] [log] [blame]
Mark Fashehccd979b2005-12-15 14:31:24 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * heartbeat.c
5 *
6 * Register ourselves with the heartbaet service, keep our node maps
7 * up to date, and fire off recovery when needed.
8 *
9 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
10 *
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.
15 *
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.
20 *
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.
25 */
26
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>
32
Mark Fashehccd979b2005-12-15 14:31:24 -080033#define MLOG_MASK_PREFIX ML_SUPER
34#include <cluster/masklog.h>
35
36#include "ocfs2.h"
37
38#include "alloc.h"
39#include "heartbeat.h"
40#include "inode.h"
41#include "journal.h"
Mark Fashehccd979b2005-12-15 14:31:24 -080042
43#include "buffer_head_io.h"
44
Mark Fashehccd979b2005-12-15 14:31:24 -080045static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
46 int bit);
47static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
48 int bit);
Adrian Bunk00600052008-01-29 00:11:41 +020049
50/* special case -1 for now
51 * TODO: should *really* make sure the calling func never passes -1!! */
52static void ocfs2_node_map_init(struct ocfs2_node_map *map)
53{
54 map->num_nodes = OCFS2_NODE_MAP_MAX_NODES;
55 memset(map->map, 0, BITS_TO_LONGS(OCFS2_NODE_MAP_MAX_NODES) *
56 sizeof(unsigned long));
57}
Mark Fashehccd979b2005-12-15 14:31:24 -080058
59void ocfs2_init_node_maps(struct ocfs2_super *osb)
60{
61 spin_lock_init(&osb->node_map_lock);
Mark Fashehb4df6ed2006-02-22 17:35:08 -080062 ocfs2_node_map_init(&osb->osb_recovering_orphan_dirs);
Mark Fashehccd979b2005-12-15 14:31:24 -080063}
64
Joel Becker4670c462008-02-01 14:39:35 -080065void ocfs2_do_node_down(int node_num, void *data)
Mark Fashehccd979b2005-12-15 14:31:24 -080066{
Joel Becker4670c462008-02-01 14:39:35 -080067 struct ocfs2_super *osb = data;
68
Mark Fashehccd979b2005-12-15 14:31:24 -080069 BUG_ON(osb->node_num == node_num);
70
71 mlog(0, "ocfs2: node down event for %d\n", node_num);
72
Joel Becker4670c462008-02-01 14:39:35 -080073 if (!osb->cconn) {
Mark Fashehccd979b2005-12-15 14:31:24 -080074 /*
Joel Becker4670c462008-02-01 14:39:35 -080075 * No cluster connection means we're not even ready to
76 * participate yet. We check the slots after the cluster
77 * comes up, so we will notice the node death then. We
78 * can safely ignore it here.
Mark Fashehccd979b2005-12-15 14:31:24 -080079 */
80 return;
81 }
82
Mark Fashehccd979b2005-12-15 14:31:24 -080083 ocfs2_recovery_thread(osb, node_num);
Mark Fashehccd979b2005-12-15 14:31:24 -080084}
85
Mark Fashehccd979b2005-12-15 14:31:24 -080086void ocfs2_stop_heartbeat(struct ocfs2_super *osb)
87{
88 int ret;
89 char *argv[5], *envp[3];
90
Sunil Mushranc271c5c2006-12-05 17:56:35 -080091 if (ocfs2_mount_local(osb))
92 return;
93
Mark Fashehccd979b2005-12-15 14:31:24 -080094 if (!osb->uuid_str) {
95 /* This can happen if we don't get far enough in mount... */
96 mlog(0, "No UUID with which to stop heartbeat!\n\n");
97 return;
98 }
99
100 argv[0] = (char *)o2nm_get_hb_ctl_path();
101 argv[1] = "-K";
102 argv[2] = "-u";
103 argv[3] = osb->uuid_str;
104 argv[4] = NULL;
105
106 mlog(0, "Run: %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
107
108 /* minimal command environment taken from cpu_run_sbin_hotplug */
109 envp[0] = "HOME=/";
110 envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
111 envp[2] = NULL;
112
Jeremy Fitzhardinge86313c42007-07-17 18:37:03 -0700113 ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
Mark Fashehccd979b2005-12-15 14:31:24 -0800114 if (ret < 0)
115 mlog_errno(ret);
116}
117
Mark Fashehccd979b2005-12-15 14:31:24 -0800118static inline void __ocfs2_node_map_set_bit(struct ocfs2_node_map *map,
119 int bit)
120{
121 set_bit(bit, map->map);
122}
123
124void ocfs2_node_map_set_bit(struct ocfs2_super *osb,
125 struct ocfs2_node_map *map,
126 int bit)
127{
128 if (bit==-1)
129 return;
130 BUG_ON(bit >= map->num_nodes);
131 spin_lock(&osb->node_map_lock);
132 __ocfs2_node_map_set_bit(map, bit);
133 spin_unlock(&osb->node_map_lock);
134}
135
136static inline void __ocfs2_node_map_clear_bit(struct ocfs2_node_map *map,
137 int bit)
138{
139 clear_bit(bit, map->map);
140}
141
142void ocfs2_node_map_clear_bit(struct ocfs2_super *osb,
143 struct ocfs2_node_map *map,
144 int bit)
145{
146 if (bit==-1)
147 return;
148 BUG_ON(bit >= map->num_nodes);
149 spin_lock(&osb->node_map_lock);
150 __ocfs2_node_map_clear_bit(map, bit);
151 spin_unlock(&osb->node_map_lock);
152}
153
154int ocfs2_node_map_test_bit(struct ocfs2_super *osb,
155 struct ocfs2_node_map *map,
156 int bit)
157{
158 int ret;
159 if (bit >= map->num_nodes) {
160 mlog(ML_ERROR, "bit=%d map->num_nodes=%d\n", bit, map->num_nodes);
161 BUG();
162 }
163 spin_lock(&osb->node_map_lock);
164 ret = test_bit(bit, map->map);
165 spin_unlock(&osb->node_map_lock);
166 return ret;
167}
168