blob: 2461eb3272edfab9c6c4949cb435252181938b72 [file] [log] [blame]
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * Copyright (C) 2004, 2005 Oracle. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA.
20 */
21
22#include <linux/kernel.h>
23#include <linux/sched.h>
24#include <linux/jiffies.h>
25#include <linux/module.h>
26#include <linux/fs.h>
27#include <linux/bio.h>
28#include <linux/blkdev.h>
29#include <linux/delay.h>
30#include <linux/file.h>
31#include <linux/kthread.h>
32#include <linux/configfs.h>
33#include <linux/random.h>
34#include <linux/crc32.h>
35#include <linux/time.h>
Sunil Mushran87d3d3f2008-12-17 14:17:42 -080036#include <linux/debugfs.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090037#include <linux/slab.h>
Mark Fasheha7f6a5f2005-12-15 14:31:23 -080038
39#include "heartbeat.h"
40#include "tcp.h"
41#include "nodemanager.h"
42#include "quorum.h"
43
44#include "masklog.h"
45
46
47/*
48 * The first heartbeat pass had one global thread that would serialize all hb
49 * callback calls. This global serializing sem should only be removed once
50 * we've made sure that all callees can deal with being called concurrently
51 * from multiple hb region threads.
52 */
53static DECLARE_RWSEM(o2hb_callback_sem);
54
55/*
56 * multiple hb threads are watching multiple regions. A node is live
57 * whenever any of the threads sees activity from the node in its region.
58 */
Ingo Molnar34af9462006-06-27 02:53:55 -070059static DEFINE_SPINLOCK(o2hb_live_lock);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -080060static struct list_head o2hb_live_slots[O2NM_MAX_NODES];
61static unsigned long o2hb_live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
62static LIST_HEAD(o2hb_node_events);
63static DECLARE_WAIT_QUEUE_HEAD(o2hb_steady_queue);
64
Sunil Mushran536f0742010-10-07 17:03:07 -070065/*
66 * In global heartbeat, we maintain a series of region bitmaps.
67 * - o2hb_region_bitmap allows us to limit the region number to max region.
Sunil Mushrane7d656b2010-10-06 17:55:18 -070068 * - o2hb_live_region_bitmap tracks live regions (seen steady iterations).
Sunil Mushran43182d22010-10-06 17:55:16 -070069 * - o2hb_quorum_region_bitmap tracks live regions that have seen all nodes
70 * heartbeat on it.
Sunil Mushranb1c5ebf2010-10-07 17:05:52 -070071 * - o2hb_failed_region_bitmap tracks the regions that have seen io timeouts.
Sunil Mushran536f0742010-10-07 17:03:07 -070072 */
73static unsigned long o2hb_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)];
Sunil Mushrane7d656b2010-10-06 17:55:18 -070074static unsigned long o2hb_live_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)];
Sunil Mushran43182d22010-10-06 17:55:16 -070075static unsigned long o2hb_quorum_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)];
Sunil Mushranb1c5ebf2010-10-07 17:05:52 -070076static unsigned long o2hb_failed_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)];
Sunil Mushran536f0742010-10-07 17:03:07 -070077
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -070078#define O2HB_DB_TYPE_LIVENODES 0
Sunil Mushrana6de0132010-10-06 17:55:13 -070079#define O2HB_DB_TYPE_LIVEREGIONS 1
80#define O2HB_DB_TYPE_QUORUMREGIONS 2
81#define O2HB_DB_TYPE_FAILEDREGIONS 3
Sunil Mushran1f285302010-10-06 17:55:12 -070082#define O2HB_DB_TYPE_REGION_LIVENODES 4
83#define O2HB_DB_TYPE_REGION_NUMBER 5
Sunil Mushran43695d02010-10-06 17:55:09 -070084#define O2HB_DB_TYPE_REGION_ELAPSED_TIME 6
Sunil Mushrancb0586b2010-12-14 14:14:30 -080085#define O2HB_DB_TYPE_REGION_PINNED 7
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -070086struct o2hb_debug_buf {
87 int db_type;
88 int db_size;
89 int db_len;
90 void *db_data;
91};
92
93static struct o2hb_debug_buf *o2hb_db_livenodes;
Sunil Mushrana6de0132010-10-06 17:55:13 -070094static struct o2hb_debug_buf *o2hb_db_liveregions;
95static struct o2hb_debug_buf *o2hb_db_quorumregions;
96static struct o2hb_debug_buf *o2hb_db_failedregions;
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -070097
Sunil Mushran87d3d3f2008-12-17 14:17:42 -080098#define O2HB_DEBUG_DIR "o2hb"
99#define O2HB_DEBUG_LIVENODES "livenodes"
Sunil Mushrana6de0132010-10-06 17:55:13 -0700100#define O2HB_DEBUG_LIVEREGIONS "live_regions"
101#define O2HB_DEBUG_QUORUMREGIONS "quorum_regions"
102#define O2HB_DEBUG_FAILEDREGIONS "failed_regions"
Sunil Mushran1f285302010-10-06 17:55:12 -0700103#define O2HB_DEBUG_REGION_NUMBER "num"
Sunil Mushran43695d02010-10-06 17:55:09 -0700104#define O2HB_DEBUG_REGION_ELAPSED_TIME "elapsed_time_in_ms"
Sunil Mushrancb0586b2010-12-14 14:14:30 -0800105#define O2HB_DEBUG_REGION_PINNED "pinned"
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -0700106
Sunil Mushran87d3d3f2008-12-17 14:17:42 -0800107static struct dentry *o2hb_debug_dir;
108static struct dentry *o2hb_debug_livenodes;
Sunil Mushrana6de0132010-10-06 17:55:13 -0700109static struct dentry *o2hb_debug_liveregions;
110static struct dentry *o2hb_debug_quorumregions;
111static struct dentry *o2hb_debug_failedregions;
Sunil Mushran87d3d3f2008-12-17 14:17:42 -0800112
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800113static LIST_HEAD(o2hb_all_regions);
114
115static struct o2hb_callback {
116 struct list_head list;
117} o2hb_callbacks[O2HB_NUM_CB];
118
119static struct o2hb_callback *hbcall_from_type(enum o2hb_callback_type type);
120
121#define O2HB_DEFAULT_BLOCK_BITS 9
122
Sunil Mushran54b51872010-10-07 15:26:08 -0700123enum o2hb_heartbeat_modes {
124 O2HB_HEARTBEAT_LOCAL = 0,
125 O2HB_HEARTBEAT_GLOBAL,
126 O2HB_HEARTBEAT_NUM_MODES,
127};
128
129char *o2hb_heartbeat_mode_desc[O2HB_HEARTBEAT_NUM_MODES] = {
130 "local", /* O2HB_HEARTBEAT_LOCAL */
131 "global", /* O2HB_HEARTBEAT_GLOBAL */
132};
133
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800134unsigned int o2hb_dead_threshold = O2HB_DEFAULT_DEAD_THRESHOLD;
Sunil Mushran54b51872010-10-07 15:26:08 -0700135unsigned int o2hb_heartbeat_mode = O2HB_HEARTBEAT_LOCAL;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800136
Sunil Mushran58a31582010-12-14 14:14:29 -0800137/*
138 * o2hb_dependent_users tracks the number of registered callbacks that depend
139 * on heartbeat. o2net and o2dlm are two entities that register this callback.
140 * However only o2dlm depends on the heartbeat. It does not want the heartbeat
141 * to stop while a dlm domain is still active.
142 */
143unsigned int o2hb_dependent_users;
144
145/*
146 * In global heartbeat mode, all regions are pinned if there are one or more
147 * dependent users and the quorum region count is <= O2HB_PIN_CUT_OFF. All
148 * regions are unpinned if the region count exceeds the cut off or the number
149 * of dependent users falls to zero.
150 */
151#define O2HB_PIN_CUT_OFF 3
152
153/*
154 * In local heartbeat mode, we assume the dlm domain name to be the same as
155 * region uuid. This is true for domains created for the file system but not
156 * necessarily true for userdlm domains. This is a known limitation.
157 *
158 * In global heartbeat mode, we pin/unpin all o2hb regions. This solution
159 * works for both file system and userdlm domains.
160 */
161static int o2hb_region_pin(const char *region_uuid);
162static void o2hb_region_unpin(const char *region_uuid);
163
Sunil Mushran2bd63212010-01-25 16:57:38 -0800164/* Only sets a new threshold if there are no active regions.
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800165 *
166 * No locking or otherwise interesting code is required for reading
167 * o2hb_dead_threshold as it can't change once regions are active and
168 * it's not interesting to anyone until then anyway. */
169static void o2hb_dead_threshold_set(unsigned int threshold)
170{
171 if (threshold > O2HB_MIN_DEAD_THRESHOLD) {
172 spin_lock(&o2hb_live_lock);
173 if (list_empty(&o2hb_all_regions))
174 o2hb_dead_threshold = threshold;
175 spin_unlock(&o2hb_live_lock);
176 }
177}
178
Sunil Mushran54b51872010-10-07 15:26:08 -0700179static int o2hb_global_hearbeat_mode_set(unsigned int hb_mode)
180{
181 int ret = -1;
182
183 if (hb_mode < O2HB_HEARTBEAT_NUM_MODES) {
184 spin_lock(&o2hb_live_lock);
185 if (list_empty(&o2hb_all_regions)) {
186 o2hb_heartbeat_mode = hb_mode;
187 ret = 0;
188 }
189 spin_unlock(&o2hb_live_lock);
190 }
191
192 return ret;
193}
194
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800195struct o2hb_node_event {
196 struct list_head hn_item;
197 enum o2hb_callback_type hn_event_type;
198 struct o2nm_node *hn_node;
199 int hn_node_num;
200};
201
202struct o2hb_disk_slot {
203 struct o2hb_disk_heartbeat_block *ds_raw_block;
204 u8 ds_node_num;
205 u64 ds_last_time;
206 u64 ds_last_generation;
207 u16 ds_equal_samples;
208 u16 ds_changed_samples;
209 struct list_head ds_live_item;
210};
211
212/* each thread owns a region.. when we're asked to tear down the region
213 * we ask the thread to stop, who cleans up the region */
214struct o2hb_region {
215 struct config_item hr_item;
216
217 struct list_head hr_all_item;
Sunil Mushran58a31582010-12-14 14:14:29 -0800218 unsigned hr_unclean_stop:1,
219 hr_item_pinned:1,
220 hr_item_dropped:1;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800221
222 /* protected by the hr_callback_sem */
223 struct task_struct *hr_task;
224
225 unsigned int hr_blocks;
226 unsigned long long hr_start_block;
227
228 unsigned int hr_block_bits;
229 unsigned int hr_block_bytes;
230
231 unsigned int hr_slots_per_page;
232 unsigned int hr_num_pages;
233
234 struct page **hr_slot_data;
235 struct block_device *hr_bdev;
236 struct o2hb_disk_slot *hr_slots;
237
Sunil Mushran823a6372010-10-06 17:55:21 -0700238 /* live node map of this region */
239 unsigned long hr_live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
Sunil Mushran536f0742010-10-07 17:03:07 -0700240 unsigned int hr_region_num;
Sunil Mushran823a6372010-10-06 17:55:21 -0700241
Sunil Mushran1f285302010-10-06 17:55:12 -0700242 struct dentry *hr_debug_dir;
243 struct dentry *hr_debug_livenodes;
244 struct dentry *hr_debug_regnum;
Sunil Mushran43695d02010-10-06 17:55:09 -0700245 struct dentry *hr_debug_elapsed_time;
Sunil Mushrancb0586b2010-12-14 14:14:30 -0800246 struct dentry *hr_debug_pinned;
Sunil Mushran1f285302010-10-06 17:55:12 -0700247 struct o2hb_debug_buf *hr_db_livenodes;
248 struct o2hb_debug_buf *hr_db_regnum;
Sunil Mushran43695d02010-10-06 17:55:09 -0700249 struct o2hb_debug_buf *hr_db_elapsed_time;
Sunil Mushrancb0586b2010-12-14 14:14:30 -0800250 struct o2hb_debug_buf *hr_db_pinned;
Sunil Mushran1f285302010-10-06 17:55:12 -0700251
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800252 /* let the person setting up hb wait for it to return until it
253 * has reached a 'steady' state. This will be fixed when we have
254 * a more complete api that doesn't lead to this sort of fragility. */
255 atomic_t hr_steady_iterations;
256
257 char hr_dev_name[BDEVNAME_SIZE];
258
259 unsigned int hr_timeout_ms;
260
261 /* randomized as the region goes up and down so that a node
262 * recognizes a node going up and down in one iteration */
263 u64 hr_generation;
264
David Howellsc4028952006-11-22 14:57:56 +0000265 struct delayed_work hr_write_timeout_work;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800266 unsigned long hr_last_timeout_start;
267
268 /* Used during o2hb_check_slot to hold a copy of the block
269 * being checked because we temporarily have to zero out the
270 * crc field. */
271 struct o2hb_disk_heartbeat_block *hr_tmp_block;
272};
273
274struct o2hb_bio_wait_ctxt {
275 atomic_t wc_num_reqs;
276 struct completion wc_io_complete;
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800277 int wc_error;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800278};
279
Sunil Mushranb1c5ebf2010-10-07 17:05:52 -0700280static int o2hb_pop_count(void *map, int count)
281{
282 int i = -1, pop = 0;
283
284 while ((i = find_next_bit(map, count, i + 1)) < count)
285 pop++;
286 return pop;
287}
288
David Howellsc4028952006-11-22 14:57:56 +0000289static void o2hb_write_timeout(struct work_struct *work)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800290{
Sunil Mushranb1c5ebf2010-10-07 17:05:52 -0700291 int failed, quorum;
292 unsigned long flags;
David Howellsc4028952006-11-22 14:57:56 +0000293 struct o2hb_region *reg =
294 container_of(work, struct o2hb_region,
295 hr_write_timeout_work.work);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800296
297 mlog(ML_ERROR, "Heartbeat write timeout to device %s after %u "
298 "milliseconds\n", reg->hr_dev_name,
Sunil Mushran2bd63212010-01-25 16:57:38 -0800299 jiffies_to_msecs(jiffies - reg->hr_last_timeout_start));
Sunil Mushranb1c5ebf2010-10-07 17:05:52 -0700300
301 if (o2hb_global_heartbeat_active()) {
302 spin_lock_irqsave(&o2hb_live_lock, flags);
303 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap))
304 set_bit(reg->hr_region_num, o2hb_failed_region_bitmap);
305 failed = o2hb_pop_count(&o2hb_failed_region_bitmap,
306 O2NM_MAX_REGIONS);
307 quorum = o2hb_pop_count(&o2hb_quorum_region_bitmap,
308 O2NM_MAX_REGIONS);
309 spin_unlock_irqrestore(&o2hb_live_lock, flags);
310
311 mlog(ML_HEARTBEAT, "Number of regions %d, failed regions %d\n",
312 quorum, failed);
313
314 /*
315 * Fence if the number of failed regions >= half the number
316 * of quorum regions
317 */
318 if ((failed << 1) < quorum)
319 return;
320 }
321
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800322 o2quo_disk_timeout();
323}
324
325static void o2hb_arm_write_timeout(struct o2hb_region *reg)
326{
Tao Mab31d3082009-12-22 10:32:15 +0800327 mlog(ML_HEARTBEAT, "Queue write timeout for %u ms\n",
328 O2HB_MAX_WRITE_TIMEOUT_MS);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800329
Sunil Mushranb1c5ebf2010-10-07 17:05:52 -0700330 if (o2hb_global_heartbeat_active()) {
331 spin_lock(&o2hb_live_lock);
332 clear_bit(reg->hr_region_num, o2hb_failed_region_bitmap);
333 spin_unlock(&o2hb_live_lock);
334 }
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800335 cancel_delayed_work(&reg->hr_write_timeout_work);
336 reg->hr_last_timeout_start = jiffies;
337 schedule_delayed_work(&reg->hr_write_timeout_work,
338 msecs_to_jiffies(O2HB_MAX_WRITE_TIMEOUT_MS));
339}
340
341static void o2hb_disarm_write_timeout(struct o2hb_region *reg)
342{
Tejun Heo9b00a812010-12-24 15:59:06 +0100343 cancel_delayed_work_sync(&reg->hr_write_timeout_work);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800344}
345
Philipp Reisnerb5592922007-01-11 10:58:10 +0100346static inline void o2hb_bio_wait_init(struct o2hb_bio_wait_ctxt *wc)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800347{
Philipp Reisnerb5592922007-01-11 10:58:10 +0100348 atomic_set(&wc->wc_num_reqs, 1);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800349 init_completion(&wc->wc_io_complete);
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800350 wc->wc_error = 0;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800351}
352
353/* Used in error paths too */
354static inline void o2hb_bio_wait_dec(struct o2hb_bio_wait_ctxt *wc,
355 unsigned int num)
356{
357 /* sadly atomic_sub_and_test() isn't available on all platforms. The
358 * good news is that the fast path only completes one at a time */
359 while(num--) {
360 if (atomic_dec_and_test(&wc->wc_num_reqs)) {
361 BUG_ON(num > 0);
362 complete(&wc->wc_io_complete);
363 }
364 }
365}
366
367static void o2hb_wait_on_io(struct o2hb_region *reg,
368 struct o2hb_bio_wait_ctxt *wc)
369{
Philipp Reisnerb5592922007-01-11 10:58:10 +0100370 o2hb_bio_wait_dec(wc, 1);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800371 wait_for_completion(&wc->wc_io_complete);
372}
373
Al Viro782e3b32007-10-12 07:17:47 +0100374static void o2hb_bio_end_io(struct bio *bio,
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800375 int error)
376{
377 struct o2hb_bio_wait_ctxt *wc = bio->bi_private;
378
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800379 if (error) {
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800380 mlog(ML_ERROR, "IO Error %d\n", error);
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800381 wc->wc_error = error;
382 }
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800383
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800384 o2hb_bio_wait_dec(wc, 1);
Philipp Reisnerb5592922007-01-11 10:58:10 +0100385 bio_put(bio);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800386}
387
388/* Setup a Bio to cover I/O against num_slots slots starting at
389 * start_slot. */
390static struct bio *o2hb_setup_one_bio(struct o2hb_region *reg,
391 struct o2hb_bio_wait_ctxt *wc,
Philipp Reisnerb5592922007-01-11 10:58:10 +0100392 unsigned int *current_slot,
393 unsigned int max_slots)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800394{
Philipp Reisnerb5592922007-01-11 10:58:10 +0100395 int len, current_page;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800396 unsigned int vec_len, vec_start;
397 unsigned int bits = reg->hr_block_bits;
398 unsigned int spp = reg->hr_slots_per_page;
Philipp Reisnerb5592922007-01-11 10:58:10 +0100399 unsigned int cs = *current_slot;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800400 struct bio *bio;
401 struct page *page;
402
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800403 /* Testing has shown this allocation to take long enough under
404 * GFP_KERNEL that the local node can get fenced. It would be
405 * nicest if we could pre-allocate these bios and avoid this
406 * all together. */
Philipp Reisnerb5592922007-01-11 10:58:10 +0100407 bio = bio_alloc(GFP_ATOMIC, 16);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800408 if (!bio) {
409 mlog(ML_ERROR, "Could not alloc slots BIO!\n");
410 bio = ERR_PTR(-ENOMEM);
411 goto bail;
412 }
413
414 /* Must put everything in 512 byte sectors for the bio... */
Philipp Reisnerb5592922007-01-11 10:58:10 +0100415 bio->bi_sector = (reg->hr_start_block + cs) << (bits - 9);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800416 bio->bi_bdev = reg->hr_bdev;
417 bio->bi_private = wc;
418 bio->bi_end_io = o2hb_bio_end_io;
419
Philipp Reisnerb5592922007-01-11 10:58:10 +0100420 vec_start = (cs << bits) % PAGE_CACHE_SIZE;
421 while(cs < max_slots) {
422 current_page = cs / spp;
423 page = reg->hr_slot_data[current_page];
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800424
Jan Karabc7e97c2007-10-10 16:25:42 +0200425 vec_len = min(PAGE_CACHE_SIZE - vec_start,
Philipp Reisnerb5592922007-01-11 10:58:10 +0100426 (max_slots-cs) * (PAGE_CACHE_SIZE/spp) );
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800427
428 mlog(ML_HB_BIO, "page %d, vec_len = %u, vec_start = %u\n",
Philipp Reisnerb5592922007-01-11 10:58:10 +0100429 current_page, vec_len, vec_start);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800430
431 len = bio_add_page(bio, page, vec_len, vec_start);
Philipp Reisnerb5592922007-01-11 10:58:10 +0100432 if (len != vec_len) break;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800433
Philipp Reisnerb5592922007-01-11 10:58:10 +0100434 cs += vec_len / (PAGE_CACHE_SIZE/spp);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800435 vec_start = 0;
436 }
437
438bail:
Philipp Reisnerb5592922007-01-11 10:58:10 +0100439 *current_slot = cs;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800440 return bio;
441}
442
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800443static int o2hb_read_slots(struct o2hb_region *reg,
444 unsigned int max_slots)
445{
Philipp Reisnerb5592922007-01-11 10:58:10 +0100446 unsigned int current_slot=0;
447 int status;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800448 struct o2hb_bio_wait_ctxt wc;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800449 struct bio *bio;
450
Philipp Reisnerb5592922007-01-11 10:58:10 +0100451 o2hb_bio_wait_init(&wc);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800452
Philipp Reisnerb5592922007-01-11 10:58:10 +0100453 while(current_slot < max_slots) {
454 bio = o2hb_setup_one_bio(reg, &wc, &current_slot, max_slots);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800455 if (IS_ERR(bio)) {
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800456 status = PTR_ERR(bio);
457 mlog_errno(status);
458 goto bail_and_wait;
459 }
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800460
Philipp Reisnerb5592922007-01-11 10:58:10 +0100461 atomic_inc(&wc.wc_num_reqs);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800462 submit_bio(READ, bio);
463 }
464
465 status = 0;
466
467bail_and_wait:
468 o2hb_wait_on_io(reg, &wc);
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800469 if (wc.wc_error && !status)
470 status = wc.wc_error;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800471
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800472 return status;
473}
474
475static int o2hb_issue_node_write(struct o2hb_region *reg,
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800476 struct o2hb_bio_wait_ctxt *write_wc)
477{
478 int status;
479 unsigned int slot;
480 struct bio *bio;
481
Philipp Reisnerb5592922007-01-11 10:58:10 +0100482 o2hb_bio_wait_init(write_wc);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800483
484 slot = o2nm_this_node();
485
Philipp Reisnerb5592922007-01-11 10:58:10 +0100486 bio = o2hb_setup_one_bio(reg, write_wc, &slot, slot+1);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800487 if (IS_ERR(bio)) {
488 status = PTR_ERR(bio);
489 mlog_errno(status);
490 goto bail;
491 }
492
Philipp Reisnerb5592922007-01-11 10:58:10 +0100493 atomic_inc(&write_wc->wc_num_reqs);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800494 submit_bio(WRITE, bio);
495
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800496 status = 0;
497bail:
498 return status;
499}
500
501static u32 o2hb_compute_block_crc_le(struct o2hb_region *reg,
502 struct o2hb_disk_heartbeat_block *hb_block)
503{
504 __le32 old_cksum;
505 u32 ret;
506
507 /* We want to compute the block crc with a 0 value in the
508 * hb_cksum field. Save it off here and replace after the
509 * crc. */
510 old_cksum = hb_block->hb_cksum;
511 hb_block->hb_cksum = 0;
512
513 ret = crc32_le(0, (unsigned char *) hb_block, reg->hr_block_bytes);
514
515 hb_block->hb_cksum = old_cksum;
516
517 return ret;
518}
519
520static void o2hb_dump_slot(struct o2hb_disk_heartbeat_block *hb_block)
521{
Mark Fasheh70bacbdb2006-03-02 11:10:05 -0800522 mlog(ML_ERROR, "Dump slot information: seq = 0x%llx, node = %u, "
523 "cksum = 0x%x, generation 0x%llx\n",
524 (long long)le64_to_cpu(hb_block->hb_seq),
525 hb_block->hb_node, le32_to_cpu(hb_block->hb_cksum),
526 (long long)le64_to_cpu(hb_block->hb_generation));
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800527}
528
529static int o2hb_verify_crc(struct o2hb_region *reg,
530 struct o2hb_disk_heartbeat_block *hb_block)
531{
532 u32 read, computed;
533
534 read = le32_to_cpu(hb_block->hb_cksum);
535 computed = o2hb_compute_block_crc_le(reg, hb_block);
536
537 return read == computed;
538}
539
540/* We want to make sure that nobody is heartbeating on top of us --
541 * this will help detect an invalid configuration. */
542static int o2hb_check_last_timestamp(struct o2hb_region *reg)
543{
544 int node_num, ret;
545 struct o2hb_disk_slot *slot;
546 struct o2hb_disk_heartbeat_block *hb_block;
547
548 node_num = o2nm_this_node();
549
550 ret = 1;
551 slot = &reg->hr_slots[node_num];
552 /* Don't check on our 1st timestamp */
553 if (slot->ds_last_time) {
554 hb_block = slot->ds_raw_block;
555
556 if (le64_to_cpu(hb_block->hb_seq) != slot->ds_last_time)
557 ret = 0;
558 }
559
560 return ret;
561}
562
563static inline void o2hb_prepare_block(struct o2hb_region *reg,
564 u64 generation)
565{
566 int node_num;
567 u64 cputime;
568 struct o2hb_disk_slot *slot;
569 struct o2hb_disk_heartbeat_block *hb_block;
570
571 node_num = o2nm_this_node();
572 slot = &reg->hr_slots[node_num];
573
574 hb_block = (struct o2hb_disk_heartbeat_block *)slot->ds_raw_block;
575 memset(hb_block, 0, reg->hr_block_bytes);
576 /* TODO: time stuff */
577 cputime = CURRENT_TIME.tv_sec;
578 if (!cputime)
579 cputime = 1;
580
581 hb_block->hb_seq = cpu_to_le64(cputime);
582 hb_block->hb_node = node_num;
583 hb_block->hb_generation = cpu_to_le64(generation);
Mark Fasheh0db638f2006-05-09 15:09:35 -0700584 hb_block->hb_dead_ms = cpu_to_le32(o2hb_dead_threshold * O2HB_REGION_TIMEOUT_MS);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800585
586 /* This step must always happen last! */
587 hb_block->hb_cksum = cpu_to_le32(o2hb_compute_block_crc_le(reg,
588 hb_block));
589
Mark Fasheh70bacbdb2006-03-02 11:10:05 -0800590 mlog(ML_HB_BIO, "our node generation = 0x%llx, cksum = 0x%x\n",
Mark Fasheh5fdf1e62007-04-27 16:50:03 -0700591 (long long)generation,
Mark Fasheh70bacbdb2006-03-02 11:10:05 -0800592 le32_to_cpu(hb_block->hb_cksum));
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800593}
594
595static void o2hb_fire_callbacks(struct o2hb_callback *hbcall,
596 struct o2nm_node *node,
597 int idx)
598{
599 struct list_head *iter;
600 struct o2hb_callback_func *f;
601
602 list_for_each(iter, &hbcall->list) {
603 f = list_entry(iter, struct o2hb_callback_func, hc_item);
604 mlog(ML_HEARTBEAT, "calling funcs %p\n", f);
605 (f->hc_func)(node, idx, f->hc_data);
606 }
607}
608
609/* Will run the list in order until we process the passed event */
610static void o2hb_run_event_list(struct o2hb_node_event *queued_event)
611{
612 int empty;
613 struct o2hb_callback *hbcall;
614 struct o2hb_node_event *event;
615
616 spin_lock(&o2hb_live_lock);
617 empty = list_empty(&queued_event->hn_item);
618 spin_unlock(&o2hb_live_lock);
619 if (empty)
620 return;
621
622 /* Holding callback sem assures we don't alter the callback
623 * lists when doing this, and serializes ourselves with other
624 * processes wanting callbacks. */
625 down_write(&o2hb_callback_sem);
626
627 spin_lock(&o2hb_live_lock);
628 while (!list_empty(&o2hb_node_events)
629 && !list_empty(&queued_event->hn_item)) {
630 event = list_entry(o2hb_node_events.next,
631 struct o2hb_node_event,
632 hn_item);
633 list_del_init(&event->hn_item);
634 spin_unlock(&o2hb_live_lock);
635
636 mlog(ML_HEARTBEAT, "Node %s event for %d\n",
637 event->hn_event_type == O2HB_NODE_UP_CB ? "UP" : "DOWN",
638 event->hn_node_num);
639
640 hbcall = hbcall_from_type(event->hn_event_type);
641
642 /* We should *never* have gotten on to the list with a
643 * bad type... This isn't something that we should try
644 * to recover from. */
645 BUG_ON(IS_ERR(hbcall));
646
647 o2hb_fire_callbacks(hbcall, event->hn_node, event->hn_node_num);
648
649 spin_lock(&o2hb_live_lock);
650 }
651 spin_unlock(&o2hb_live_lock);
652
653 up_write(&o2hb_callback_sem);
654}
655
656static void o2hb_queue_node_event(struct o2hb_node_event *event,
657 enum o2hb_callback_type type,
658 struct o2nm_node *node,
659 int node_num)
660{
661 assert_spin_locked(&o2hb_live_lock);
662
Sunil Mushran0e105d32010-10-07 17:00:16 -0700663 BUG_ON((!node) && (type != O2HB_NODE_DOWN_CB));
664
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800665 event->hn_event_type = type;
666 event->hn_node = node;
667 event->hn_node_num = node_num;
668
669 mlog(ML_HEARTBEAT, "Queue node %s event for node %d\n",
670 type == O2HB_NODE_UP_CB ? "UP" : "DOWN", node_num);
671
672 list_add_tail(&event->hn_item, &o2hb_node_events);
673}
674
675static void o2hb_shutdown_slot(struct o2hb_disk_slot *slot)
676{
677 struct o2hb_node_event event =
678 { .hn_item = LIST_HEAD_INIT(event.hn_item), };
679 struct o2nm_node *node;
680
681 node = o2nm_get_node_by_num(slot->ds_node_num);
682 if (!node)
683 return;
684
685 spin_lock(&o2hb_live_lock);
686 if (!list_empty(&slot->ds_live_item)) {
687 mlog(ML_HEARTBEAT, "Shutdown, node %d leaves region\n",
688 slot->ds_node_num);
689
690 list_del_init(&slot->ds_live_item);
691
692 if (list_empty(&o2hb_live_slots[slot->ds_node_num])) {
693 clear_bit(slot->ds_node_num, o2hb_live_node_bitmap);
694
695 o2hb_queue_node_event(&event, O2HB_NODE_DOWN_CB, node,
696 slot->ds_node_num);
697 }
698 }
699 spin_unlock(&o2hb_live_lock);
700
701 o2hb_run_event_list(&event);
702
703 o2nm_node_put(node);
704}
705
Sunil Mushran43182d22010-10-06 17:55:16 -0700706static void o2hb_set_quorum_device(struct o2hb_region *reg,
707 struct o2hb_disk_slot *slot)
708{
709 assert_spin_locked(&o2hb_live_lock);
710
711 if (!o2hb_global_heartbeat_active())
712 return;
713
714 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap))
715 return;
716
717 /*
718 * A region can be added to the quorum only when it sees all
719 * live nodes heartbeat on it. In other words, the region has been
720 * added to all nodes.
721 */
722 if (memcmp(reg->hr_live_node_bitmap, o2hb_live_node_bitmap,
723 sizeof(o2hb_live_node_bitmap)))
724 return;
725
726 if (slot->ds_changed_samples < O2HB_LIVE_THRESHOLD)
727 return;
728
729 printk(KERN_NOTICE "o2hb: Region %s is now a quorum device\n",
730 config_item_name(&reg->hr_item));
731
732 set_bit(reg->hr_region_num, o2hb_quorum_region_bitmap);
Sunil Mushran58a31582010-12-14 14:14:29 -0800733
734 /*
735 * If global heartbeat active, unpin all regions if the
736 * region count > CUT_OFF
737 */
738 if (o2hb_pop_count(&o2hb_quorum_region_bitmap,
739 O2NM_MAX_REGIONS) > O2HB_PIN_CUT_OFF)
740 o2hb_region_unpin(NULL);
Sunil Mushran43182d22010-10-06 17:55:16 -0700741}
742
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800743static int o2hb_check_slot(struct o2hb_region *reg,
744 struct o2hb_disk_slot *slot)
745{
746 int changed = 0, gen_changed = 0;
747 struct o2hb_node_event event =
748 { .hn_item = LIST_HEAD_INIT(event.hn_item), };
749 struct o2nm_node *node;
750 struct o2hb_disk_heartbeat_block *hb_block = reg->hr_tmp_block;
751 u64 cputime;
Mark Fasheh0db638f2006-05-09 15:09:35 -0700752 unsigned int dead_ms = o2hb_dead_threshold * O2HB_REGION_TIMEOUT_MS;
753 unsigned int slot_dead_ms;
Sunil Mushran0e105d32010-10-07 17:00:16 -0700754 int tmp;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800755
756 memcpy(hb_block, slot->ds_raw_block, reg->hr_block_bytes);
757
Sunil Mushran0e105d32010-10-07 17:00:16 -0700758 /*
759 * If a node is no longer configured but is still in the livemap, we
760 * may need to clear that bit from the livemap.
761 */
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800762 node = o2nm_get_node_by_num(slot->ds_node_num);
Sunil Mushran0e105d32010-10-07 17:00:16 -0700763 if (!node) {
764 spin_lock(&o2hb_live_lock);
765 tmp = test_bit(slot->ds_node_num, o2hb_live_node_bitmap);
766 spin_unlock(&o2hb_live_lock);
767 if (!tmp)
768 return 0;
769 }
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800770
771 if (!o2hb_verify_crc(reg, hb_block)) {
772 /* all paths from here will drop o2hb_live_lock for
773 * us. */
774 spin_lock(&o2hb_live_lock);
775
776 /* Don't print an error on the console in this case -
777 * a freshly formatted heartbeat area will not have a
778 * crc set on it. */
779 if (list_empty(&slot->ds_live_item))
780 goto out;
781
782 /* The node is live but pushed out a bad crc. We
783 * consider it a transient miss but don't populate any
784 * other values as they may be junk. */
785 mlog(ML_ERROR, "Node %d has written a bad crc to %s\n",
786 slot->ds_node_num, reg->hr_dev_name);
787 o2hb_dump_slot(hb_block);
788
789 slot->ds_equal_samples++;
790 goto fire_callbacks;
791 }
792
793 /* we don't care if these wrap.. the state transitions below
794 * clear at the right places */
795 cputime = le64_to_cpu(hb_block->hb_seq);
796 if (slot->ds_last_time != cputime)
797 slot->ds_changed_samples++;
798 else
799 slot->ds_equal_samples++;
800 slot->ds_last_time = cputime;
801
802 /* The node changed heartbeat generations. We assume this to
803 * mean it dropped off but came back before we timed out. We
804 * want to consider it down for the time being but don't want
805 * to lose any changed_samples state we might build up to
806 * considering it live again. */
807 if (slot->ds_last_generation != le64_to_cpu(hb_block->hb_generation)) {
808 gen_changed = 1;
809 slot->ds_equal_samples = 0;
Mark Fasheh70bacbdb2006-03-02 11:10:05 -0800810 mlog(ML_HEARTBEAT, "Node %d changed generation (0x%llx "
811 "to 0x%llx)\n", slot->ds_node_num,
812 (long long)slot->ds_last_generation,
813 (long long)le64_to_cpu(hb_block->hb_generation));
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800814 }
815
816 slot->ds_last_generation = le64_to_cpu(hb_block->hb_generation);
817
Mark Fasheh70bacbdb2006-03-02 11:10:05 -0800818 mlog(ML_HEARTBEAT, "Slot %d gen 0x%llx cksum 0x%x "
819 "seq %llu last %llu changed %u equal %u\n",
820 slot->ds_node_num, (long long)slot->ds_last_generation,
821 le32_to_cpu(hb_block->hb_cksum),
Sunil Mushran2bd63212010-01-25 16:57:38 -0800822 (unsigned long long)le64_to_cpu(hb_block->hb_seq),
Mark Fasheh70bacbdb2006-03-02 11:10:05 -0800823 (unsigned long long)slot->ds_last_time, slot->ds_changed_samples,
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800824 slot->ds_equal_samples);
825
826 spin_lock(&o2hb_live_lock);
827
828fire_callbacks:
829 /* dead nodes only come to life after some number of
830 * changes at any time during their dead time */
831 if (list_empty(&slot->ds_live_item) &&
832 slot->ds_changed_samples >= O2HB_LIVE_THRESHOLD) {
Mark Fasheh70bacbdb2006-03-02 11:10:05 -0800833 mlog(ML_HEARTBEAT, "Node %d (id 0x%llx) joined my region\n",
834 slot->ds_node_num, (long long)slot->ds_last_generation);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800835
Sunil Mushran823a6372010-10-06 17:55:21 -0700836 set_bit(slot->ds_node_num, reg->hr_live_node_bitmap);
837
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800838 /* first on the list generates a callback */
839 if (list_empty(&o2hb_live_slots[slot->ds_node_num])) {
Sunil Mushrand6aa1c72010-10-06 18:50:50 -0700840 mlog(ML_HEARTBEAT, "o2hb: Add node %d to live nodes "
841 "bitmap\n", slot->ds_node_num);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800842 set_bit(slot->ds_node_num, o2hb_live_node_bitmap);
843
844 o2hb_queue_node_event(&event, O2HB_NODE_UP_CB, node,
845 slot->ds_node_num);
846
847 changed = 1;
848 }
849
850 list_add_tail(&slot->ds_live_item,
851 &o2hb_live_slots[slot->ds_node_num]);
852
853 slot->ds_equal_samples = 0;
Mark Fasheh0db638f2006-05-09 15:09:35 -0700854
855 /* We want to be sure that all nodes agree on the
856 * number of milliseconds before a node will be
857 * considered dead. The self-fencing timeout is
858 * computed from this value, and a discrepancy might
859 * result in heartbeat calling a node dead when it
860 * hasn't self-fenced yet. */
861 slot_dead_ms = le32_to_cpu(hb_block->hb_dead_ms);
862 if (slot_dead_ms && slot_dead_ms != dead_ms) {
863 /* TODO: Perhaps we can fail the region here. */
864 mlog(ML_ERROR, "Node %d on device %s has a dead count "
865 "of %u ms, but our count is %u ms.\n"
866 "Please double check your configuration values "
867 "for 'O2CB_HEARTBEAT_THRESHOLD'\n",
868 slot->ds_node_num, reg->hr_dev_name, slot_dead_ms,
869 dead_ms);
870 }
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800871 goto out;
872 }
873
874 /* if the list is dead, we're done.. */
875 if (list_empty(&slot->ds_live_item))
876 goto out;
877
878 /* live nodes only go dead after enough consequtive missed
879 * samples.. reset the missed counter whenever we see
880 * activity */
881 if (slot->ds_equal_samples >= o2hb_dead_threshold || gen_changed) {
882 mlog(ML_HEARTBEAT, "Node %d left my region\n",
883 slot->ds_node_num);
884
Sunil Mushran823a6372010-10-06 17:55:21 -0700885 clear_bit(slot->ds_node_num, reg->hr_live_node_bitmap);
886
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800887 /* last off the live_slot generates a callback */
888 list_del_init(&slot->ds_live_item);
889 if (list_empty(&o2hb_live_slots[slot->ds_node_num])) {
Sunil Mushrand6aa1c72010-10-06 18:50:50 -0700890 mlog(ML_HEARTBEAT, "o2hb: Remove node %d from live "
891 "nodes bitmap\n", slot->ds_node_num);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800892 clear_bit(slot->ds_node_num, o2hb_live_node_bitmap);
893
Sunil Mushran0e105d32010-10-07 17:00:16 -0700894 /* node can be null */
895 o2hb_queue_node_event(&event, O2HB_NODE_DOWN_CB,
896 node, slot->ds_node_num);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800897
898 changed = 1;
899 }
900
901 /* We don't clear this because the node is still
902 * actually writing new blocks. */
903 if (!gen_changed)
904 slot->ds_changed_samples = 0;
905 goto out;
906 }
907 if (slot->ds_changed_samples) {
908 slot->ds_changed_samples = 0;
909 slot->ds_equal_samples = 0;
910 }
911out:
Sunil Mushran43182d22010-10-06 17:55:16 -0700912 o2hb_set_quorum_device(reg, slot);
913
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800914 spin_unlock(&o2hb_live_lock);
915
916 o2hb_run_event_list(&event);
917
Sunil Mushran0e105d32010-10-07 17:00:16 -0700918 if (node)
919 o2nm_node_put(node);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800920 return changed;
921}
922
923/* This could be faster if we just implmented a find_last_bit, but I
924 * don't think the circumstances warrant it. */
925static int o2hb_highest_node(unsigned long *nodes,
926 int numbits)
927{
928 int highest, node;
929
930 highest = numbits;
931 node = -1;
932 while ((node = find_next_bit(nodes, numbits, node + 1)) != -1) {
933 if (node >= numbits)
934 break;
935
936 highest = node;
937 }
938
939 return highest;
940}
941
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800942static int o2hb_do_disk_heartbeat(struct o2hb_region *reg)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800943{
944 int i, ret, highest_node, change = 0;
945 unsigned long configured_nodes[BITS_TO_LONGS(O2NM_MAX_NODES)];
Sunil Mushran0e105d32010-10-07 17:00:16 -0700946 unsigned long live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800947 struct o2hb_bio_wait_ctxt write_wc;
948
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800949 ret = o2nm_configured_node_map(configured_nodes,
950 sizeof(configured_nodes));
951 if (ret) {
952 mlog_errno(ret);
953 return ret;
954 }
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800955
Sunil Mushran0e105d32010-10-07 17:00:16 -0700956 /*
957 * If a node is not configured but is in the livemap, we still need
958 * to read the slot so as to be able to remove it from the livemap.
959 */
960 o2hb_fill_node_map(live_node_bitmap, sizeof(live_node_bitmap));
961 i = -1;
962 while ((i = find_next_bit(live_node_bitmap,
963 O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) {
964 set_bit(i, configured_nodes);
965 }
966
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800967 highest_node = o2hb_highest_node(configured_nodes, O2NM_MAX_NODES);
968 if (highest_node >= O2NM_MAX_NODES) {
969 mlog(ML_NOTICE, "ocfs2_heartbeat: no configured nodes found!\n");
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800970 return -EINVAL;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800971 }
972
973 /* No sense in reading the slots of nodes that don't exist
974 * yet. Of course, if the node definitions have holes in them
975 * then we're reading an empty slot anyway... Consider this
976 * best-effort. */
977 ret = o2hb_read_slots(reg, highest_node + 1);
978 if (ret < 0) {
979 mlog_errno(ret);
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800980 return ret;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800981 }
982
983 /* With an up to date view of the slots, we can check that no
984 * other node has been improperly configured to heartbeat in
985 * our slot. */
986 if (!o2hb_check_last_timestamp(reg))
987 mlog(ML_ERROR, "Device \"%s\": another node is heartbeating "
988 "in our slot!\n", reg->hr_dev_name);
989
990 /* fill in the proper info for our next heartbeat */
991 o2hb_prepare_block(reg, reg->hr_generation);
992
993 /* And fire off the write. Note that we don't wait on this I/O
994 * until later. */
Philipp Reisnerb5592922007-01-11 10:58:10 +0100995 ret = o2hb_issue_node_write(reg, &write_wc);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800996 if (ret < 0) {
997 mlog_errno(ret);
Mark Fasheha9e2ae32006-03-24 14:20:17 -0800998 return ret;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -0800999 }
1000
1001 i = -1;
1002 while((i = find_next_bit(configured_nodes, O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) {
1003
1004 change |= o2hb_check_slot(reg, &reg->hr_slots[i]);
1005 }
1006
1007 /*
1008 * We have to be sure we've advertised ourselves on disk
1009 * before we can go to steady state. This ensures that
1010 * people we find in our steady state have seen us.
1011 */
1012 o2hb_wait_on_io(reg, &write_wc);
Mark Fasheha9e2ae32006-03-24 14:20:17 -08001013 if (write_wc.wc_error) {
1014 /* Do not re-arm the write timeout on I/O error - we
1015 * can't be sure that the new block ever made it to
1016 * disk */
1017 mlog(ML_ERROR, "Write error %d on device \"%s\"\n",
1018 write_wc.wc_error, reg->hr_dev_name);
1019 return write_wc.wc_error;
1020 }
1021
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001022 o2hb_arm_write_timeout(reg);
1023
1024 /* let the person who launched us know when things are steady */
1025 if (!change && (atomic_read(&reg->hr_steady_iterations) != 0)) {
1026 if (atomic_dec_and_test(&reg->hr_steady_iterations))
1027 wake_up(&o2hb_steady_queue);
1028 }
Mark Fasheha9e2ae32006-03-24 14:20:17 -08001029
1030 return 0;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001031}
1032
1033/* Subtract b from a, storing the result in a. a *must* have a larger
1034 * value than b. */
1035static void o2hb_tv_subtract(struct timeval *a,
1036 struct timeval *b)
1037{
1038 /* just return 0 when a is after b */
1039 if (a->tv_sec < b->tv_sec ||
1040 (a->tv_sec == b->tv_sec && a->tv_usec < b->tv_usec)) {
1041 a->tv_sec = 0;
1042 a->tv_usec = 0;
1043 return;
1044 }
1045
1046 a->tv_sec -= b->tv_sec;
1047 a->tv_usec -= b->tv_usec;
1048 while ( a->tv_usec < 0 ) {
1049 a->tv_sec--;
1050 a->tv_usec += 1000000;
1051 }
1052}
1053
1054static unsigned int o2hb_elapsed_msecs(struct timeval *start,
1055 struct timeval *end)
1056{
1057 struct timeval res = *end;
1058
1059 o2hb_tv_subtract(&res, start);
1060
1061 return res.tv_sec * 1000 + res.tv_usec / 1000;
1062}
1063
1064/*
1065 * we ride the region ref that the region dir holds. before the region
1066 * dir is removed and drops it ref it will wait to tear down this
1067 * thread.
1068 */
1069static int o2hb_thread(void *data)
1070{
1071 int i, ret;
1072 struct o2hb_region *reg = data;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001073 struct o2hb_bio_wait_ctxt write_wc;
1074 struct timeval before_hb, after_hb;
1075 unsigned int elapsed_msec;
1076
1077 mlog(ML_HEARTBEAT|ML_KTHREAD, "hb thread running\n");
1078
1079 set_user_nice(current, -20);
1080
Sunil Mushrancfc069d2010-12-14 14:14:31 -08001081 /* Pin node */
1082 o2nm_depend_this_node();
1083
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001084 while (!kthread_should_stop() && !reg->hr_unclean_stop) {
1085 /* We track the time spent inside
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02001086 * o2hb_do_disk_heartbeat so that we avoid more than
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001087 * hr_timeout_ms between disk writes. On busy systems
1088 * this should result in a heartbeat which is less
1089 * likely to time itself out. */
1090 do_gettimeofday(&before_hb);
1091
Mark Fasheha9e2ae32006-03-24 14:20:17 -08001092 i = 0;
1093 do {
1094 ret = o2hb_do_disk_heartbeat(reg);
1095 } while (ret && ++i < 2);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001096
1097 do_gettimeofday(&after_hb);
1098 elapsed_msec = o2hb_elapsed_msecs(&before_hb, &after_hb);
1099
Tao Mab31d3082009-12-22 10:32:15 +08001100 mlog(ML_HEARTBEAT,
1101 "start = %lu.%lu, end = %lu.%lu, msec = %u\n",
Mark Fasheh215c7f92006-02-01 16:42:10 -08001102 before_hb.tv_sec, (unsigned long) before_hb.tv_usec,
1103 after_hb.tv_sec, (unsigned long) after_hb.tv_usec,
1104 elapsed_msec);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001105
1106 if (elapsed_msec < reg->hr_timeout_ms) {
1107 /* the kthread api has blocked signals for us so no
1108 * need to record the return value. */
1109 msleep_interruptible(reg->hr_timeout_ms - elapsed_msec);
1110 }
1111 }
1112
1113 o2hb_disarm_write_timeout(reg);
1114
1115 /* unclean stop is only used in very bad situation */
1116 for(i = 0; !reg->hr_unclean_stop && i < reg->hr_blocks; i++)
1117 o2hb_shutdown_slot(&reg->hr_slots[i]);
1118
1119 /* Explicit down notification - avoid forcing the other nodes
1120 * to timeout on this region when we could just as easily
1121 * write a clear generation - thus indicating to them that
1122 * this node has left this region.
1123 *
1124 * XXX: Should we skip this on unclean_stop? */
1125 o2hb_prepare_block(reg, 0);
Philipp Reisnerb5592922007-01-11 10:58:10 +01001126 ret = o2hb_issue_node_write(reg, &write_wc);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001127 if (ret == 0) {
1128 o2hb_wait_on_io(reg, &write_wc);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001129 } else {
1130 mlog_errno(ret);
1131 }
1132
Sunil Mushrancfc069d2010-12-14 14:14:31 -08001133 /* Unpin node */
1134 o2nm_undepend_this_node();
1135
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001136 mlog(ML_HEARTBEAT|ML_KTHREAD, "hb thread exiting\n");
1137
1138 return 0;
1139}
1140
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001141#ifdef CONFIG_DEBUG_FS
1142static int o2hb_debug_open(struct inode *inode, struct file *file)
1143{
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001144 struct o2hb_debug_buf *db = inode->i_private;
Sunil Mushran1f285302010-10-06 17:55:12 -07001145 struct o2hb_region *reg;
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001146 unsigned long map[BITS_TO_LONGS(O2NM_MAX_NODES)];
1147 char *buf = NULL;
1148 int i = -1;
1149 int out = 0;
1150
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001151 /* max_nodes should be the largest bitmap we pass here */
1152 BUG_ON(sizeof(map) < db->db_size);
1153
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001154 buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1155 if (!buf)
1156 goto bail;
1157
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001158 switch (db->db_type) {
1159 case O2HB_DB_TYPE_LIVENODES:
Sunil Mushrana6de0132010-10-06 17:55:13 -07001160 case O2HB_DB_TYPE_LIVEREGIONS:
1161 case O2HB_DB_TYPE_QUORUMREGIONS:
1162 case O2HB_DB_TYPE_FAILEDREGIONS:
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001163 spin_lock(&o2hb_live_lock);
1164 memcpy(map, db->db_data, db->db_size);
1165 spin_unlock(&o2hb_live_lock);
1166 break;
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001167
Sunil Mushran1f285302010-10-06 17:55:12 -07001168 case O2HB_DB_TYPE_REGION_LIVENODES:
1169 spin_lock(&o2hb_live_lock);
1170 reg = (struct o2hb_region *)db->db_data;
1171 memcpy(map, reg->hr_live_node_bitmap, db->db_size);
1172 spin_unlock(&o2hb_live_lock);
1173 break;
1174
1175 case O2HB_DB_TYPE_REGION_NUMBER:
1176 reg = (struct o2hb_region *)db->db_data;
1177 out += snprintf(buf + out, PAGE_SIZE - out, "%d\n",
1178 reg->hr_region_num);
1179 goto done;
1180
Sunil Mushran43695d02010-10-06 17:55:09 -07001181 case O2HB_DB_TYPE_REGION_ELAPSED_TIME:
1182 reg = (struct o2hb_region *)db->db_data;
1183 out += snprintf(buf + out, PAGE_SIZE - out, "%u\n",
1184 jiffies_to_msecs(jiffies -
1185 reg->hr_last_timeout_start));
1186 goto done;
1187
Sunil Mushrancb0586b2010-12-14 14:14:30 -08001188 case O2HB_DB_TYPE_REGION_PINNED:
1189 reg = (struct o2hb_region *)db->db_data;
1190 out += snprintf(buf + out, PAGE_SIZE - out, "%u\n",
1191 !!reg->hr_item_pinned);
1192 goto done;
1193
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001194 default:
1195 goto done;
1196 }
1197
1198 while ((i = find_next_bit(map, db->db_len, i + 1)) < db->db_len)
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001199 out += snprintf(buf + out, PAGE_SIZE - out, "%d ", i);
1200 out += snprintf(buf + out, PAGE_SIZE - out, "\n");
1201
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001202done:
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001203 i_size_write(inode, out);
1204
1205 file->private_data = buf;
1206
1207 return 0;
1208bail:
1209 return -ENOMEM;
1210}
1211
1212static int o2hb_debug_release(struct inode *inode, struct file *file)
1213{
1214 kfree(file->private_data);
1215 return 0;
1216}
1217
1218static ssize_t o2hb_debug_read(struct file *file, char __user *buf,
1219 size_t nbytes, loff_t *ppos)
1220{
1221 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
1222 i_size_read(file->f_mapping->host));
1223}
1224#else
1225static int o2hb_debug_open(struct inode *inode, struct file *file)
1226{
1227 return 0;
1228}
1229static int o2hb_debug_release(struct inode *inode, struct file *file)
1230{
1231 return 0;
1232}
1233static ssize_t o2hb_debug_read(struct file *file, char __user *buf,
1234 size_t nbytes, loff_t *ppos)
1235{
1236 return 0;
1237}
1238#endif /* CONFIG_DEBUG_FS */
1239
Alexey Dobriyan828c0952009-10-01 15:43:56 -07001240static const struct file_operations o2hb_debug_fops = {
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001241 .open = o2hb_debug_open,
1242 .release = o2hb_debug_release,
1243 .read = o2hb_debug_read,
1244 .llseek = generic_file_llseek,
1245};
1246
1247void o2hb_exit(void)
1248{
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001249 kfree(o2hb_db_livenodes);
Sunil Mushrana6de0132010-10-06 17:55:13 -07001250 kfree(o2hb_db_liveregions);
1251 kfree(o2hb_db_quorumregions);
1252 kfree(o2hb_db_failedregions);
1253 debugfs_remove(o2hb_debug_failedregions);
1254 debugfs_remove(o2hb_debug_quorumregions);
1255 debugfs_remove(o2hb_debug_liveregions);
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001256 debugfs_remove(o2hb_debug_livenodes);
1257 debugfs_remove(o2hb_debug_dir);
1258}
1259
1260static struct dentry *o2hb_debug_create(const char *name, struct dentry *dir,
1261 struct o2hb_debug_buf **db, int db_len,
1262 int type, int size, int len, void *data)
1263{
1264 *db = kmalloc(db_len, GFP_KERNEL);
1265 if (!*db)
1266 return NULL;
1267
1268 (*db)->db_type = type;
1269 (*db)->db_size = size;
1270 (*db)->db_len = len;
1271 (*db)->db_data = data;
1272
1273 return debugfs_create_file(name, S_IFREG|S_IRUSR, dir, *db,
1274 &o2hb_debug_fops);
1275}
1276
1277static int o2hb_debug_init(void)
1278{
1279 int ret = -ENOMEM;
1280
1281 o2hb_debug_dir = debugfs_create_dir(O2HB_DEBUG_DIR, NULL);
1282 if (!o2hb_debug_dir) {
1283 mlog_errno(ret);
1284 goto bail;
1285 }
1286
1287 o2hb_debug_livenodes = o2hb_debug_create(O2HB_DEBUG_LIVENODES,
1288 o2hb_debug_dir,
1289 &o2hb_db_livenodes,
1290 sizeof(*o2hb_db_livenodes),
1291 O2HB_DB_TYPE_LIVENODES,
1292 sizeof(o2hb_live_node_bitmap),
1293 O2NM_MAX_NODES,
1294 o2hb_live_node_bitmap);
1295 if (!o2hb_debug_livenodes) {
1296 mlog_errno(ret);
1297 goto bail;
1298 }
Sunil Mushrana6de0132010-10-06 17:55:13 -07001299
1300 o2hb_debug_liveregions = o2hb_debug_create(O2HB_DEBUG_LIVEREGIONS,
1301 o2hb_debug_dir,
1302 &o2hb_db_liveregions,
1303 sizeof(*o2hb_db_liveregions),
1304 O2HB_DB_TYPE_LIVEREGIONS,
1305 sizeof(o2hb_live_region_bitmap),
1306 O2NM_MAX_REGIONS,
1307 o2hb_live_region_bitmap);
1308 if (!o2hb_debug_liveregions) {
1309 mlog_errno(ret);
1310 goto bail;
1311 }
1312
1313 o2hb_debug_quorumregions =
1314 o2hb_debug_create(O2HB_DEBUG_QUORUMREGIONS,
1315 o2hb_debug_dir,
1316 &o2hb_db_quorumregions,
1317 sizeof(*o2hb_db_quorumregions),
1318 O2HB_DB_TYPE_QUORUMREGIONS,
1319 sizeof(o2hb_quorum_region_bitmap),
1320 O2NM_MAX_REGIONS,
1321 o2hb_quorum_region_bitmap);
1322 if (!o2hb_debug_quorumregions) {
1323 mlog_errno(ret);
1324 goto bail;
1325 }
1326
1327 o2hb_debug_failedregions =
1328 o2hb_debug_create(O2HB_DEBUG_FAILEDREGIONS,
1329 o2hb_debug_dir,
1330 &o2hb_db_failedregions,
1331 sizeof(*o2hb_db_failedregions),
1332 O2HB_DB_TYPE_FAILEDREGIONS,
1333 sizeof(o2hb_failed_region_bitmap),
1334 O2NM_MAX_REGIONS,
1335 o2hb_failed_region_bitmap);
1336 if (!o2hb_debug_failedregions) {
1337 mlog_errno(ret);
1338 goto bail;
1339 }
1340
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001341 ret = 0;
1342bail:
1343 if (ret)
1344 o2hb_exit();
1345
1346 return ret;
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001347}
1348
1349int o2hb_init(void)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001350{
1351 int i;
1352
1353 for (i = 0; i < ARRAY_SIZE(o2hb_callbacks); i++)
1354 INIT_LIST_HEAD(&o2hb_callbacks[i].list);
1355
1356 for (i = 0; i < ARRAY_SIZE(o2hb_live_slots); i++)
1357 INIT_LIST_HEAD(&o2hb_live_slots[i]);
1358
1359 INIT_LIST_HEAD(&o2hb_node_events);
1360
1361 memset(o2hb_live_node_bitmap, 0, sizeof(o2hb_live_node_bitmap));
Sunil Mushran536f0742010-10-07 17:03:07 -07001362 memset(o2hb_region_bitmap, 0, sizeof(o2hb_region_bitmap));
Sunil Mushrane7d656b2010-10-06 17:55:18 -07001363 memset(o2hb_live_region_bitmap, 0, sizeof(o2hb_live_region_bitmap));
Sunil Mushran43182d22010-10-06 17:55:16 -07001364 memset(o2hb_quorum_region_bitmap, 0, sizeof(o2hb_quorum_region_bitmap));
Sunil Mushranb1c5ebf2010-10-07 17:05:52 -07001365 memset(o2hb_failed_region_bitmap, 0, sizeof(o2hb_failed_region_bitmap));
Sunil Mushran87d3d3f2008-12-17 14:17:42 -08001366
Sunil Mushran58a31582010-12-14 14:14:29 -08001367 o2hb_dependent_users = 0;
1368
Sunil Mushran8ca8b0b2010-10-07 17:01:27 -07001369 return o2hb_debug_init();
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001370}
1371
1372/* if we're already in a callback then we're already serialized by the sem */
1373static void o2hb_fill_node_map_from_callback(unsigned long *map,
1374 unsigned bytes)
1375{
1376 BUG_ON(bytes < (BITS_TO_LONGS(O2NM_MAX_NODES) * sizeof(unsigned long)));
1377
1378 memcpy(map, &o2hb_live_node_bitmap, bytes);
1379}
1380
1381/*
1382 * get a map of all nodes that are heartbeating in any regions
1383 */
1384void o2hb_fill_node_map(unsigned long *map, unsigned bytes)
1385{
1386 /* callers want to serialize this map and callbacks so that they
1387 * can trust that they don't miss nodes coming to the party */
1388 down_read(&o2hb_callback_sem);
1389 spin_lock(&o2hb_live_lock);
1390 o2hb_fill_node_map_from_callback(map, bytes);
1391 spin_unlock(&o2hb_live_lock);
1392 up_read(&o2hb_callback_sem);
1393}
1394EXPORT_SYMBOL_GPL(o2hb_fill_node_map);
1395
1396/*
1397 * heartbeat configfs bits. The heartbeat set is a default set under
1398 * the cluster set in nodemanager.c.
1399 */
1400
1401static struct o2hb_region *to_o2hb_region(struct config_item *item)
1402{
1403 return item ? container_of(item, struct o2hb_region, hr_item) : NULL;
1404}
1405
1406/* drop_item only drops its ref after killing the thread, nothing should
1407 * be using the region anymore. this has to clean up any state that
1408 * attributes might have built up. */
1409static void o2hb_region_release(struct config_item *item)
1410{
1411 int i;
1412 struct page *page;
1413 struct o2hb_region *reg = to_o2hb_region(item);
1414
1415 if (reg->hr_tmp_block)
1416 kfree(reg->hr_tmp_block);
1417
1418 if (reg->hr_slot_data) {
1419 for (i = 0; i < reg->hr_num_pages; i++) {
1420 page = reg->hr_slot_data[i];
1421 if (page)
1422 __free_page(page);
1423 }
1424 kfree(reg->hr_slot_data);
1425 }
1426
1427 if (reg->hr_bdev)
Al Viro9a1c3542008-02-22 20:40:24 -05001428 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001429
1430 if (reg->hr_slots)
1431 kfree(reg->hr_slots);
1432
Sunil Mushran1f285302010-10-06 17:55:12 -07001433 kfree(reg->hr_db_regnum);
1434 kfree(reg->hr_db_livenodes);
1435 debugfs_remove(reg->hr_debug_livenodes);
1436 debugfs_remove(reg->hr_debug_regnum);
Sunil Mushrand4396ea2010-10-15 11:57:21 -07001437 debugfs_remove(reg->hr_debug_elapsed_time);
Sunil Mushrancb0586b2010-12-14 14:14:30 -08001438 debugfs_remove(reg->hr_debug_pinned);
Sunil Mushran1f285302010-10-06 17:55:12 -07001439 debugfs_remove(reg->hr_debug_dir);
1440
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001441 spin_lock(&o2hb_live_lock);
1442 list_del(&reg->hr_all_item);
1443 spin_unlock(&o2hb_live_lock);
1444
1445 kfree(reg);
1446}
1447
1448static int o2hb_read_block_input(struct o2hb_region *reg,
1449 const char *page,
1450 size_t count,
1451 unsigned long *ret_bytes,
1452 unsigned int *ret_bits)
1453{
1454 unsigned long bytes;
1455 char *p = (char *)page;
1456
1457 bytes = simple_strtoul(p, &p, 0);
1458 if (!p || (*p && (*p != '\n')))
1459 return -EINVAL;
1460
1461 /* Heartbeat and fs min / max block sizes are the same. */
1462 if (bytes > 4096 || bytes < 512)
1463 return -ERANGE;
1464 if (hweight16(bytes) != 1)
1465 return -EINVAL;
1466
1467 if (ret_bytes)
1468 *ret_bytes = bytes;
1469 if (ret_bits)
1470 *ret_bits = ffs(bytes) - 1;
1471
1472 return 0;
1473}
1474
1475static ssize_t o2hb_region_block_bytes_read(struct o2hb_region *reg,
1476 char *page)
1477{
1478 return sprintf(page, "%u\n", reg->hr_block_bytes);
1479}
1480
1481static ssize_t o2hb_region_block_bytes_write(struct o2hb_region *reg,
1482 const char *page,
1483 size_t count)
1484{
1485 int status;
1486 unsigned long block_bytes;
1487 unsigned int block_bits;
1488
1489 if (reg->hr_bdev)
1490 return -EINVAL;
1491
1492 status = o2hb_read_block_input(reg, page, count,
1493 &block_bytes, &block_bits);
1494 if (status)
1495 return status;
1496
1497 reg->hr_block_bytes = (unsigned int)block_bytes;
1498 reg->hr_block_bits = block_bits;
1499
1500 return count;
1501}
1502
1503static ssize_t o2hb_region_start_block_read(struct o2hb_region *reg,
1504 char *page)
1505{
1506 return sprintf(page, "%llu\n", reg->hr_start_block);
1507}
1508
1509static ssize_t o2hb_region_start_block_write(struct o2hb_region *reg,
1510 const char *page,
1511 size_t count)
1512{
1513 unsigned long long tmp;
1514 char *p = (char *)page;
1515
1516 if (reg->hr_bdev)
1517 return -EINVAL;
1518
1519 tmp = simple_strtoull(p, &p, 0);
1520 if (!p || (*p && (*p != '\n')))
1521 return -EINVAL;
1522
1523 reg->hr_start_block = tmp;
1524
1525 return count;
1526}
1527
1528static ssize_t o2hb_region_blocks_read(struct o2hb_region *reg,
1529 char *page)
1530{
1531 return sprintf(page, "%d\n", reg->hr_blocks);
1532}
1533
1534static ssize_t o2hb_region_blocks_write(struct o2hb_region *reg,
1535 const char *page,
1536 size_t count)
1537{
1538 unsigned long tmp;
1539 char *p = (char *)page;
1540
1541 if (reg->hr_bdev)
1542 return -EINVAL;
1543
1544 tmp = simple_strtoul(p, &p, 0);
1545 if (!p || (*p && (*p != '\n')))
1546 return -EINVAL;
1547
1548 if (tmp > O2NM_MAX_NODES || tmp == 0)
1549 return -ERANGE;
1550
1551 reg->hr_blocks = (unsigned int)tmp;
1552
1553 return count;
1554}
1555
1556static ssize_t o2hb_region_dev_read(struct o2hb_region *reg,
1557 char *page)
1558{
1559 unsigned int ret = 0;
1560
1561 if (reg->hr_bdev)
1562 ret = sprintf(page, "%s\n", reg->hr_dev_name);
1563
1564 return ret;
1565}
1566
1567static void o2hb_init_region_params(struct o2hb_region *reg)
1568{
1569 reg->hr_slots_per_page = PAGE_CACHE_SIZE >> reg->hr_block_bits;
1570 reg->hr_timeout_ms = O2HB_REGION_TIMEOUT_MS;
1571
1572 mlog(ML_HEARTBEAT, "hr_start_block = %llu, hr_blocks = %u\n",
1573 reg->hr_start_block, reg->hr_blocks);
1574 mlog(ML_HEARTBEAT, "hr_block_bytes = %u, hr_block_bits = %u\n",
1575 reg->hr_block_bytes, reg->hr_block_bits);
1576 mlog(ML_HEARTBEAT, "hr_timeout_ms = %u\n", reg->hr_timeout_ms);
1577 mlog(ML_HEARTBEAT, "dead threshold = %u\n", o2hb_dead_threshold);
1578}
1579
1580static int o2hb_map_slot_data(struct o2hb_region *reg)
1581{
1582 int i, j;
1583 unsigned int last_slot;
1584 unsigned int spp = reg->hr_slots_per_page;
1585 struct page *page;
1586 char *raw;
1587 struct o2hb_disk_slot *slot;
1588
1589 reg->hr_tmp_block = kmalloc(reg->hr_block_bytes, GFP_KERNEL);
1590 if (reg->hr_tmp_block == NULL) {
1591 mlog_errno(-ENOMEM);
1592 return -ENOMEM;
1593 }
1594
1595 reg->hr_slots = kcalloc(reg->hr_blocks,
1596 sizeof(struct o2hb_disk_slot), GFP_KERNEL);
1597 if (reg->hr_slots == NULL) {
1598 mlog_errno(-ENOMEM);
1599 return -ENOMEM;
1600 }
1601
1602 for(i = 0; i < reg->hr_blocks; i++) {
1603 slot = &reg->hr_slots[i];
1604 slot->ds_node_num = i;
1605 INIT_LIST_HEAD(&slot->ds_live_item);
1606 slot->ds_raw_block = NULL;
1607 }
1608
1609 reg->hr_num_pages = (reg->hr_blocks + spp - 1) / spp;
1610 mlog(ML_HEARTBEAT, "Going to require %u pages to cover %u blocks "
1611 "at %u blocks per page\n",
1612 reg->hr_num_pages, reg->hr_blocks, spp);
1613
1614 reg->hr_slot_data = kcalloc(reg->hr_num_pages, sizeof(struct page *),
1615 GFP_KERNEL);
1616 if (!reg->hr_slot_data) {
1617 mlog_errno(-ENOMEM);
1618 return -ENOMEM;
1619 }
1620
1621 for(i = 0; i < reg->hr_num_pages; i++) {
1622 page = alloc_page(GFP_KERNEL);
1623 if (!page) {
1624 mlog_errno(-ENOMEM);
1625 return -ENOMEM;
1626 }
1627
1628 reg->hr_slot_data[i] = page;
1629
1630 last_slot = i * spp;
1631 raw = page_address(page);
1632 for (j = 0;
1633 (j < spp) && ((j + last_slot) < reg->hr_blocks);
1634 j++) {
1635 BUG_ON((j + last_slot) >= reg->hr_blocks);
1636
1637 slot = &reg->hr_slots[j + last_slot];
1638 slot->ds_raw_block =
1639 (struct o2hb_disk_heartbeat_block *) raw;
1640
1641 raw += reg->hr_block_bytes;
1642 }
1643 }
1644
1645 return 0;
1646}
1647
1648/* Read in all the slots available and populate the tracking
1649 * structures so that we can start with a baseline idea of what's
1650 * there. */
1651static int o2hb_populate_slot_data(struct o2hb_region *reg)
1652{
1653 int ret, i;
1654 struct o2hb_disk_slot *slot;
1655 struct o2hb_disk_heartbeat_block *hb_block;
1656
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001657 ret = o2hb_read_slots(reg, reg->hr_blocks);
1658 if (ret) {
1659 mlog_errno(ret);
1660 goto out;
1661 }
1662
1663 /* We only want to get an idea of the values initially in each
1664 * slot, so we do no verification - o2hb_check_slot will
1665 * actually determine if each configured slot is valid and
1666 * whether any values have changed. */
1667 for(i = 0; i < reg->hr_blocks; i++) {
1668 slot = &reg->hr_slots[i];
1669 hb_block = (struct o2hb_disk_heartbeat_block *) slot->ds_raw_block;
1670
1671 /* Only fill the values that o2hb_check_slot uses to
1672 * determine changing slots */
1673 slot->ds_last_time = le64_to_cpu(hb_block->hb_seq);
1674 slot->ds_last_generation = le64_to_cpu(hb_block->hb_generation);
1675 }
1676
1677out:
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001678 return ret;
1679}
1680
1681/* this is acting as commit; we set up all of hr_bdev and hr_task or nothing */
1682static ssize_t o2hb_region_dev_write(struct o2hb_region *reg,
1683 const char *page,
1684 size_t count)
1685{
Joel Beckere6c352d2007-02-03 03:04:20 -08001686 struct task_struct *hb_task;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001687 long fd;
1688 int sectsize;
1689 char *p = (char *)page;
1690 struct file *filp = NULL;
1691 struct inode *inode = NULL;
1692 ssize_t ret = -EINVAL;
1693
1694 if (reg->hr_bdev)
1695 goto out;
1696
1697 /* We can't heartbeat without having had our node number
1698 * configured yet. */
1699 if (o2nm_this_node() == O2NM_MAX_NODES)
1700 goto out;
1701
1702 fd = simple_strtol(p, &p, 0);
1703 if (!p || (*p && (*p != '\n')))
1704 goto out;
1705
1706 if (fd < 0 || fd >= INT_MAX)
1707 goto out;
1708
1709 filp = fget(fd);
1710 if (filp == NULL)
1711 goto out;
1712
1713 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 ||
1714 reg->hr_block_bytes == 0)
1715 goto out;
1716
1717 inode = igrab(filp->f_mapping->host);
1718 if (inode == NULL)
1719 goto out;
1720
1721 if (!S_ISBLK(inode->i_mode))
1722 goto out;
1723
1724 reg->hr_bdev = I_BDEV(filp->f_mapping->host);
Tejun Heoe525fd82010-11-13 11:55:17 +01001725 ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, NULL);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001726 if (ret) {
1727 reg->hr_bdev = NULL;
1728 goto out;
1729 }
1730 inode = NULL;
1731
1732 bdevname(reg->hr_bdev, reg->hr_dev_name);
1733
Martin K. Petersene1defc42009-05-22 17:17:49 -04001734 sectsize = bdev_logical_block_size(reg->hr_bdev);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001735 if (sectsize != reg->hr_block_bytes) {
1736 mlog(ML_ERROR,
1737 "blocksize %u incorrect for device, expected %d",
1738 reg->hr_block_bytes, sectsize);
1739 ret = -EINVAL;
1740 goto out;
1741 }
1742
1743 o2hb_init_region_params(reg);
1744
1745 /* Generation of zero is invalid */
1746 do {
1747 get_random_bytes(&reg->hr_generation,
1748 sizeof(reg->hr_generation));
1749 } while (reg->hr_generation == 0);
1750
1751 ret = o2hb_map_slot_data(reg);
1752 if (ret) {
1753 mlog_errno(ret);
1754 goto out;
1755 }
1756
1757 ret = o2hb_populate_slot_data(reg);
1758 if (ret) {
1759 mlog_errno(ret);
1760 goto out;
1761 }
1762
David Howellsc4028952006-11-22 14:57:56 +00001763 INIT_DELAYED_WORK(&reg->hr_write_timeout_work, o2hb_write_timeout);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001764
1765 /*
1766 * A node is considered live after it has beat LIVE_THRESHOLD
1767 * times. We're not steady until we've given them a chance
1768 * _after_ our first read.
1769 */
1770 atomic_set(&reg->hr_steady_iterations, O2HB_LIVE_THRESHOLD + 1);
1771
Joel Beckere6c352d2007-02-03 03:04:20 -08001772 hb_task = kthread_run(o2hb_thread, reg, "o2hb-%s",
1773 reg->hr_item.ci_name);
1774 if (IS_ERR(hb_task)) {
1775 ret = PTR_ERR(hb_task);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001776 mlog_errno(ret);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001777 goto out;
1778 }
1779
Joel Beckere6c352d2007-02-03 03:04:20 -08001780 spin_lock(&o2hb_live_lock);
1781 reg->hr_task = hb_task;
1782 spin_unlock(&o2hb_live_lock);
1783
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001784 ret = wait_event_interruptible(o2hb_steady_queue,
1785 atomic_read(&reg->hr_steady_iterations) == 0);
1786 if (ret) {
Joel Beckere6df3a62007-02-06 15:45:39 -08001787 /* We got interrupted (hello ptrace!). Clean up */
Joel Beckere6c352d2007-02-03 03:04:20 -08001788 spin_lock(&o2hb_live_lock);
1789 hb_task = reg->hr_task;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001790 reg->hr_task = NULL;
Joel Beckere6c352d2007-02-03 03:04:20 -08001791 spin_unlock(&o2hb_live_lock);
1792
1793 if (hb_task)
1794 kthread_stop(hb_task);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001795 goto out;
1796 }
1797
Joel Beckere6df3a62007-02-06 15:45:39 -08001798 /* Ok, we were woken. Make sure it wasn't by drop_item() */
1799 spin_lock(&o2hb_live_lock);
1800 hb_task = reg->hr_task;
Sunil Mushrane7d656b2010-10-06 17:55:18 -07001801 if (o2hb_global_heartbeat_active())
1802 set_bit(reg->hr_region_num, o2hb_live_region_bitmap);
Joel Beckere6df3a62007-02-06 15:45:39 -08001803 spin_unlock(&o2hb_live_lock);
1804
1805 if (hb_task)
1806 ret = count;
1807 else
1808 ret = -EIO;
1809
Sunil Mushran18c50cb2010-10-06 18:26:59 -07001810 if (hb_task && o2hb_global_heartbeat_active())
1811 printk(KERN_NOTICE "o2hb: Heartbeat started on region %s\n",
1812 config_item_name(&reg->hr_item));
1813
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001814out:
1815 if (filp)
1816 fput(filp);
1817 if (inode)
1818 iput(inode);
1819 if (ret < 0) {
1820 if (reg->hr_bdev) {
Al Viro9a1c3542008-02-22 20:40:24 -05001821 blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001822 reg->hr_bdev = NULL;
1823 }
1824 }
1825 return ret;
1826}
1827
Zhen Wei92efc152006-12-08 00:48:17 -07001828static ssize_t o2hb_region_pid_read(struct o2hb_region *reg,
1829 char *page)
1830{
Joel Beckere6c352d2007-02-03 03:04:20 -08001831 pid_t pid = 0;
1832
1833 spin_lock(&o2hb_live_lock);
1834 if (reg->hr_task)
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -07001835 pid = task_pid_nr(reg->hr_task);
Joel Beckere6c352d2007-02-03 03:04:20 -08001836 spin_unlock(&o2hb_live_lock);
1837
1838 if (!pid)
Zhen Wei92efc152006-12-08 00:48:17 -07001839 return 0;
1840
Joel Beckere6c352d2007-02-03 03:04:20 -08001841 return sprintf(page, "%u\n", pid);
Zhen Wei92efc152006-12-08 00:48:17 -07001842}
1843
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001844struct o2hb_region_attribute {
1845 struct configfs_attribute attr;
1846 ssize_t (*show)(struct o2hb_region *, char *);
1847 ssize_t (*store)(struct o2hb_region *, const char *, size_t);
1848};
1849
1850static struct o2hb_region_attribute o2hb_region_attr_block_bytes = {
1851 .attr = { .ca_owner = THIS_MODULE,
1852 .ca_name = "block_bytes",
1853 .ca_mode = S_IRUGO | S_IWUSR },
1854 .show = o2hb_region_block_bytes_read,
1855 .store = o2hb_region_block_bytes_write,
1856};
1857
1858static struct o2hb_region_attribute o2hb_region_attr_start_block = {
1859 .attr = { .ca_owner = THIS_MODULE,
1860 .ca_name = "start_block",
1861 .ca_mode = S_IRUGO | S_IWUSR },
1862 .show = o2hb_region_start_block_read,
1863 .store = o2hb_region_start_block_write,
1864};
1865
1866static struct o2hb_region_attribute o2hb_region_attr_blocks = {
1867 .attr = { .ca_owner = THIS_MODULE,
1868 .ca_name = "blocks",
1869 .ca_mode = S_IRUGO | S_IWUSR },
1870 .show = o2hb_region_blocks_read,
1871 .store = o2hb_region_blocks_write,
1872};
1873
1874static struct o2hb_region_attribute o2hb_region_attr_dev = {
1875 .attr = { .ca_owner = THIS_MODULE,
1876 .ca_name = "dev",
1877 .ca_mode = S_IRUGO | S_IWUSR },
1878 .show = o2hb_region_dev_read,
1879 .store = o2hb_region_dev_write,
1880};
1881
Zhen Wei92efc152006-12-08 00:48:17 -07001882static struct o2hb_region_attribute o2hb_region_attr_pid = {
1883 .attr = { .ca_owner = THIS_MODULE,
1884 .ca_name = "pid",
1885 .ca_mode = S_IRUGO | S_IRUSR },
1886 .show = o2hb_region_pid_read,
1887};
1888
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001889static struct configfs_attribute *o2hb_region_attrs[] = {
1890 &o2hb_region_attr_block_bytes.attr,
1891 &o2hb_region_attr_start_block.attr,
1892 &o2hb_region_attr_blocks.attr,
1893 &o2hb_region_attr_dev.attr,
Zhen Wei92efc152006-12-08 00:48:17 -07001894 &o2hb_region_attr_pid.attr,
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08001895 NULL,
1896};
1897
1898static ssize_t o2hb_region_show(struct config_item *item,
1899 struct configfs_attribute *attr,
1900 char *page)
1901{
1902 struct o2hb_region *reg = to_o2hb_region(item);
1903 struct o2hb_region_attribute *o2hb_region_attr =
1904 container_of(attr, struct o2hb_region_attribute, attr);
1905 ssize_t ret = 0;
1906
1907 if (o2hb_region_attr->show)
1908 ret = o2hb_region_attr->show(reg, page);
1909 return ret;
1910}
1911
1912static ssize_t o2hb_region_store(struct config_item *item,
1913 struct configfs_attribute *attr,
1914 const char *page, size_t count)
1915{
1916 struct o2hb_region *reg = to_o2hb_region(item);
1917 struct o2hb_region_attribute *o2hb_region_attr =
1918 container_of(attr, struct o2hb_region_attribute, attr);
1919 ssize_t ret = -EINVAL;
1920
1921 if (o2hb_region_attr->store)
1922 ret = o2hb_region_attr->store(reg, page, count);
1923 return ret;
1924}
1925
1926static struct configfs_item_operations o2hb_region_item_ops = {
1927 .release = o2hb_region_release,
1928 .show_attribute = o2hb_region_show,
1929 .store_attribute = o2hb_region_store,
1930};
1931
1932static struct config_item_type o2hb_region_type = {
1933 .ct_item_ops = &o2hb_region_item_ops,
1934 .ct_attrs = o2hb_region_attrs,
1935 .ct_owner = THIS_MODULE,
1936};
1937
1938/* heartbeat set */
1939
1940struct o2hb_heartbeat_group {
1941 struct config_group hs_group;
1942 /* some stuff? */
1943};
1944
1945static struct o2hb_heartbeat_group *to_o2hb_heartbeat_group(struct config_group *group)
1946{
1947 return group ?
1948 container_of(group, struct o2hb_heartbeat_group, hs_group)
1949 : NULL;
1950}
1951
Sunil Mushran1f285302010-10-06 17:55:12 -07001952static int o2hb_debug_region_init(struct o2hb_region *reg, struct dentry *dir)
1953{
1954 int ret = -ENOMEM;
1955
1956 reg->hr_debug_dir =
1957 debugfs_create_dir(config_item_name(&reg->hr_item), dir);
1958 if (!reg->hr_debug_dir) {
1959 mlog_errno(ret);
1960 goto bail;
1961 }
1962
1963 reg->hr_debug_livenodes =
1964 o2hb_debug_create(O2HB_DEBUG_LIVENODES,
1965 reg->hr_debug_dir,
1966 &(reg->hr_db_livenodes),
1967 sizeof(*(reg->hr_db_livenodes)),
1968 O2HB_DB_TYPE_REGION_LIVENODES,
1969 sizeof(reg->hr_live_node_bitmap),
1970 O2NM_MAX_NODES, reg);
1971 if (!reg->hr_debug_livenodes) {
1972 mlog_errno(ret);
1973 goto bail;
1974 }
1975
1976 reg->hr_debug_regnum =
1977 o2hb_debug_create(O2HB_DEBUG_REGION_NUMBER,
1978 reg->hr_debug_dir,
1979 &(reg->hr_db_regnum),
1980 sizeof(*(reg->hr_db_regnum)),
1981 O2HB_DB_TYPE_REGION_NUMBER,
1982 0, O2NM_MAX_NODES, reg);
1983 if (!reg->hr_debug_regnum) {
1984 mlog_errno(ret);
1985 goto bail;
1986 }
1987
Sunil Mushran43695d02010-10-06 17:55:09 -07001988 reg->hr_debug_elapsed_time =
1989 o2hb_debug_create(O2HB_DEBUG_REGION_ELAPSED_TIME,
1990 reg->hr_debug_dir,
1991 &(reg->hr_db_elapsed_time),
1992 sizeof(*(reg->hr_db_elapsed_time)),
1993 O2HB_DB_TYPE_REGION_ELAPSED_TIME,
1994 0, 0, reg);
1995 if (!reg->hr_debug_elapsed_time) {
1996 mlog_errno(ret);
1997 goto bail;
1998 }
1999
Sunil Mushrancb0586b2010-12-14 14:14:30 -08002000 reg->hr_debug_pinned =
2001 o2hb_debug_create(O2HB_DEBUG_REGION_PINNED,
2002 reg->hr_debug_dir,
2003 &(reg->hr_db_pinned),
2004 sizeof(*(reg->hr_db_pinned)),
2005 O2HB_DB_TYPE_REGION_PINNED,
2006 0, 0, reg);
2007 if (!reg->hr_debug_pinned) {
2008 mlog_errno(ret);
2009 goto bail;
2010 }
2011
Sunil Mushran1f285302010-10-06 17:55:12 -07002012 ret = 0;
2013bail:
2014 return ret;
2015}
2016
Joel Beckerf89ab862008-07-17 14:53:48 -07002017static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *group,
2018 const char *name)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002019{
2020 struct o2hb_region *reg = NULL;
Sunil Mushran1f285302010-10-06 17:55:12 -07002021 int ret;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002022
Robert P. J. Daycd861282006-12-13 00:34:52 -08002023 reg = kzalloc(sizeof(struct o2hb_region), GFP_KERNEL);
Joel Beckerf89ab862008-07-17 14:53:48 -07002024 if (reg == NULL)
Joel Beckera6795e92008-07-17 15:21:29 -07002025 return ERR_PTR(-ENOMEM);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002026
Jiri Slaby1cf257f2010-11-06 10:06:52 +01002027 if (strlen(name) > O2HB_MAX_REGION_NAME_LEN) {
2028 ret = -ENAMETOOLONG;
2029 goto free;
2030 }
Sunil Mushranb3c85c42010-10-07 14:31:06 -07002031
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002032 spin_lock(&o2hb_live_lock);
Sunil Mushran536f0742010-10-07 17:03:07 -07002033 reg->hr_region_num = 0;
2034 if (o2hb_global_heartbeat_active()) {
2035 reg->hr_region_num = find_first_zero_bit(o2hb_region_bitmap,
2036 O2NM_MAX_REGIONS);
2037 if (reg->hr_region_num >= O2NM_MAX_REGIONS) {
2038 spin_unlock(&o2hb_live_lock);
Jiri Slaby1cf257f2010-11-06 10:06:52 +01002039 ret = -EFBIG;
2040 goto free;
Sunil Mushran536f0742010-10-07 17:03:07 -07002041 }
2042 set_bit(reg->hr_region_num, o2hb_region_bitmap);
2043 }
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002044 list_add_tail(&reg->hr_all_item, &o2hb_all_regions);
2045 spin_unlock(&o2hb_live_lock);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002046
Sunil Mushran536f0742010-10-07 17:03:07 -07002047 config_item_init_type_name(&reg->hr_item, name, &o2hb_region_type);
2048
Sunil Mushran1f285302010-10-06 17:55:12 -07002049 ret = o2hb_debug_region_init(reg, o2hb_debug_dir);
2050 if (ret) {
2051 config_item_put(&reg->hr_item);
Jiri Slaby1cf257f2010-11-06 10:06:52 +01002052 goto free;
Sunil Mushran1f285302010-10-06 17:55:12 -07002053 }
2054
Joel Beckera6795e92008-07-17 15:21:29 -07002055 return &reg->hr_item;
Jiri Slaby1cf257f2010-11-06 10:06:52 +01002056free:
2057 kfree(reg);
2058 return ERR_PTR(ret);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002059}
2060
2061static void o2hb_heartbeat_group_drop_item(struct config_group *group,
2062 struct config_item *item)
2063{
Joel Beckere6c352d2007-02-03 03:04:20 -08002064 struct task_struct *hb_task;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002065 struct o2hb_region *reg = to_o2hb_region(item);
Sunil Mushran58a31582010-12-14 14:14:29 -08002066 int quorum_region = 0;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002067
2068 /* stop the thread when the user removes the region dir */
Joel Beckere6c352d2007-02-03 03:04:20 -08002069 spin_lock(&o2hb_live_lock);
Sunil Mushrane7d656b2010-10-06 17:55:18 -07002070 if (o2hb_global_heartbeat_active()) {
Sunil Mushran536f0742010-10-07 17:03:07 -07002071 clear_bit(reg->hr_region_num, o2hb_region_bitmap);
Sunil Mushrane7d656b2010-10-06 17:55:18 -07002072 clear_bit(reg->hr_region_num, o2hb_live_region_bitmap);
Sunil Mushran58a31582010-12-14 14:14:29 -08002073 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap))
2074 quorum_region = 1;
Sunil Mushranffee2232010-12-14 14:14:28 -08002075 clear_bit(reg->hr_region_num, o2hb_quorum_region_bitmap);
Sunil Mushrane7d656b2010-10-06 17:55:18 -07002076 }
Joel Beckere6c352d2007-02-03 03:04:20 -08002077 hb_task = reg->hr_task;
2078 reg->hr_task = NULL;
Sunil Mushran58a31582010-12-14 14:14:29 -08002079 reg->hr_item_dropped = 1;
Joel Beckere6c352d2007-02-03 03:04:20 -08002080 spin_unlock(&o2hb_live_lock);
2081
2082 if (hb_task)
2083 kthread_stop(hb_task);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002084
Joel Beckere6df3a62007-02-06 15:45:39 -08002085 /*
2086 * If we're racing a dev_write(), we need to wake them. They will
2087 * check reg->hr_task
2088 */
2089 if (atomic_read(&reg->hr_steady_iterations) != 0) {
2090 atomic_set(&reg->hr_steady_iterations, 0);
2091 wake_up(&o2hb_steady_queue);
2092 }
2093
Sunil Mushran18c50cb2010-10-06 18:26:59 -07002094 if (o2hb_global_heartbeat_active())
2095 printk(KERN_NOTICE "o2hb: Heartbeat stopped on region %s\n",
2096 config_item_name(&reg->hr_item));
Sunil Mushran58a31582010-12-14 14:14:29 -08002097
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002098 config_item_put(item);
Sunil Mushran58a31582010-12-14 14:14:29 -08002099
2100 if (!o2hb_global_heartbeat_active() || !quorum_region)
2101 return;
2102
2103 /*
2104 * If global heartbeat active and there are dependent users,
2105 * pin all regions if quorum region count <= CUT_OFF
2106 */
2107 spin_lock(&o2hb_live_lock);
2108
2109 if (!o2hb_dependent_users)
2110 goto unlock;
2111
2112 if (o2hb_pop_count(&o2hb_quorum_region_bitmap,
2113 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF)
2114 o2hb_region_pin(NULL);
2115
2116unlock:
2117 spin_unlock(&o2hb_live_lock);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002118}
2119
2120struct o2hb_heartbeat_group_attribute {
2121 struct configfs_attribute attr;
2122 ssize_t (*show)(struct o2hb_heartbeat_group *, char *);
2123 ssize_t (*store)(struct o2hb_heartbeat_group *, const char *, size_t);
2124};
2125
2126static ssize_t o2hb_heartbeat_group_show(struct config_item *item,
2127 struct configfs_attribute *attr,
2128 char *page)
2129{
2130 struct o2hb_heartbeat_group *reg = to_o2hb_heartbeat_group(to_config_group(item));
2131 struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr =
2132 container_of(attr, struct o2hb_heartbeat_group_attribute, attr);
2133 ssize_t ret = 0;
2134
2135 if (o2hb_heartbeat_group_attr->show)
2136 ret = o2hb_heartbeat_group_attr->show(reg, page);
2137 return ret;
2138}
2139
2140static ssize_t o2hb_heartbeat_group_store(struct config_item *item,
2141 struct configfs_attribute *attr,
2142 const char *page, size_t count)
2143{
2144 struct o2hb_heartbeat_group *reg = to_o2hb_heartbeat_group(to_config_group(item));
2145 struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr =
2146 container_of(attr, struct o2hb_heartbeat_group_attribute, attr);
2147 ssize_t ret = -EINVAL;
2148
2149 if (o2hb_heartbeat_group_attr->store)
2150 ret = o2hb_heartbeat_group_attr->store(reg, page, count);
2151 return ret;
2152}
2153
2154static ssize_t o2hb_heartbeat_group_threshold_show(struct o2hb_heartbeat_group *group,
2155 char *page)
2156{
2157 return sprintf(page, "%u\n", o2hb_dead_threshold);
2158}
2159
2160static ssize_t o2hb_heartbeat_group_threshold_store(struct o2hb_heartbeat_group *group,
2161 const char *page,
2162 size_t count)
2163{
2164 unsigned long tmp;
2165 char *p = (char *)page;
2166
2167 tmp = simple_strtoul(p, &p, 10);
2168 if (!p || (*p && (*p != '\n')))
2169 return -EINVAL;
2170
2171 /* this will validate ranges for us. */
2172 o2hb_dead_threshold_set((unsigned int) tmp);
2173
2174 return count;
2175}
2176
Sunil Mushran54b51872010-10-07 15:26:08 -07002177static
2178ssize_t o2hb_heartbeat_group_mode_show(struct o2hb_heartbeat_group *group,
2179 char *page)
2180{
2181 return sprintf(page, "%s\n",
2182 o2hb_heartbeat_mode_desc[o2hb_heartbeat_mode]);
2183}
2184
2185static
2186ssize_t o2hb_heartbeat_group_mode_store(struct o2hb_heartbeat_group *group,
2187 const char *page, size_t count)
2188{
2189 unsigned int i;
2190 int ret;
2191 size_t len;
2192
2193 len = (page[count - 1] == '\n') ? count - 1 : count;
2194 if (!len)
2195 return -EINVAL;
2196
2197 for (i = 0; i < O2HB_HEARTBEAT_NUM_MODES; ++i) {
2198 if (strnicmp(page, o2hb_heartbeat_mode_desc[i], len))
2199 continue;
2200
2201 ret = o2hb_global_hearbeat_mode_set(i);
2202 if (!ret)
Sunil Mushran18c50cb2010-10-06 18:26:59 -07002203 printk(KERN_NOTICE "o2hb: Heartbeat mode set to %s\n",
Sunil Mushran54b51872010-10-07 15:26:08 -07002204 o2hb_heartbeat_mode_desc[i]);
2205 return count;
2206 }
2207
2208 return -EINVAL;
2209
2210}
2211
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002212static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_threshold = {
2213 .attr = { .ca_owner = THIS_MODULE,
2214 .ca_name = "dead_threshold",
2215 .ca_mode = S_IRUGO | S_IWUSR },
2216 .show = o2hb_heartbeat_group_threshold_show,
2217 .store = o2hb_heartbeat_group_threshold_store,
2218};
2219
Sunil Mushran54b51872010-10-07 15:26:08 -07002220static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_mode = {
2221 .attr = { .ca_owner = THIS_MODULE,
2222 .ca_name = "mode",
2223 .ca_mode = S_IRUGO | S_IWUSR },
2224 .show = o2hb_heartbeat_group_mode_show,
2225 .store = o2hb_heartbeat_group_mode_store,
2226};
2227
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002228static struct configfs_attribute *o2hb_heartbeat_group_attrs[] = {
2229 &o2hb_heartbeat_group_attr_threshold.attr,
Sunil Mushran54b51872010-10-07 15:26:08 -07002230 &o2hb_heartbeat_group_attr_mode.attr,
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002231 NULL,
2232};
2233
2234static struct configfs_item_operations o2hb_hearbeat_group_item_ops = {
2235 .show_attribute = o2hb_heartbeat_group_show,
2236 .store_attribute = o2hb_heartbeat_group_store,
2237};
2238
2239static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
2240 .make_item = o2hb_heartbeat_group_make_item,
2241 .drop_item = o2hb_heartbeat_group_drop_item,
2242};
2243
2244static struct config_item_type o2hb_heartbeat_group_type = {
2245 .ct_group_ops = &o2hb_heartbeat_group_group_ops,
2246 .ct_item_ops = &o2hb_hearbeat_group_item_ops,
2247 .ct_attrs = o2hb_heartbeat_group_attrs,
2248 .ct_owner = THIS_MODULE,
2249};
2250
2251/* this is just here to avoid touching group in heartbeat.h which the
2252 * entire damn world #includes */
2253struct config_group *o2hb_alloc_hb_set(void)
2254{
2255 struct o2hb_heartbeat_group *hs = NULL;
2256 struct config_group *ret = NULL;
2257
Robert P. J. Daycd861282006-12-13 00:34:52 -08002258 hs = kzalloc(sizeof(struct o2hb_heartbeat_group), GFP_KERNEL);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002259 if (hs == NULL)
2260 goto out;
2261
2262 config_group_init_type_name(&hs->hs_group, "heartbeat",
2263 &o2hb_heartbeat_group_type);
2264
2265 ret = &hs->hs_group;
2266out:
2267 if (ret == NULL)
2268 kfree(hs);
2269 return ret;
2270}
2271
2272void o2hb_free_hb_set(struct config_group *group)
2273{
2274 struct o2hb_heartbeat_group *hs = to_o2hb_heartbeat_group(group);
2275 kfree(hs);
2276}
2277
2278/* hb callback registration and issueing */
2279
2280static struct o2hb_callback *hbcall_from_type(enum o2hb_callback_type type)
2281{
2282 if (type == O2HB_NUM_CB)
2283 return ERR_PTR(-EINVAL);
2284
2285 return &o2hb_callbacks[type];
2286}
2287
2288void o2hb_setup_callback(struct o2hb_callback_func *hc,
2289 enum o2hb_callback_type type,
2290 o2hb_cb_func *func,
2291 void *data,
2292 int priority)
2293{
2294 INIT_LIST_HEAD(&hc->hc_item);
2295 hc->hc_func = func;
2296 hc->hc_data = data;
2297 hc->hc_priority = priority;
2298 hc->hc_type = type;
2299 hc->hc_magic = O2HB_CB_MAGIC;
2300}
2301EXPORT_SYMBOL_GPL(o2hb_setup_callback);
2302
Sunil Mushran58a31582010-12-14 14:14:29 -08002303/*
2304 * In local heartbeat mode, region_uuid passed matches the dlm domain name.
2305 * In global heartbeat mode, region_uuid passed is NULL.
2306 *
2307 * In local, we only pin the matching region. In global we pin all the active
2308 * regions.
2309 */
2310static int o2hb_region_pin(const char *region_uuid)
Joel Becker14829422007-06-14 21:40:49 -07002311{
Sunil Mushran58a31582010-12-14 14:14:29 -08002312 int ret = 0, found = 0;
2313 struct o2hb_region *reg;
2314 char *uuid;
Joel Becker14829422007-06-14 21:40:49 -07002315
2316 assert_spin_locked(&o2hb_live_lock);
2317
Sunil Mushran58a31582010-12-14 14:14:29 -08002318 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) {
2319 uuid = config_item_name(&reg->hr_item);
2320
2321 /* local heartbeat */
2322 if (region_uuid) {
2323 if (strcmp(region_uuid, uuid))
2324 continue;
2325 found = 1;
Joel Becker14829422007-06-14 21:40:49 -07002326 }
Sunil Mushran58a31582010-12-14 14:14:29 -08002327
2328 if (reg->hr_item_pinned || reg->hr_item_dropped)
2329 goto skip_pin;
2330
2331 /* Ignore ENOENT only for local hb (userdlm domain) */
2332 ret = o2nm_depend_item(&reg->hr_item);
2333 if (!ret) {
2334 mlog(ML_CLUSTER, "Pin region %s\n", uuid);
2335 reg->hr_item_pinned = 1;
2336 } else {
2337 if (ret == -ENOENT && found)
2338 ret = 0;
2339 else {
2340 mlog(ML_ERROR, "Pin region %s fails with %d\n",
2341 uuid, ret);
2342 break;
2343 }
2344 }
2345skip_pin:
2346 if (found)
2347 break;
Joel Becker14829422007-06-14 21:40:49 -07002348 }
2349
Joel Becker14829422007-06-14 21:40:49 -07002350 return ret;
2351}
2352
Sunil Mushran58a31582010-12-14 14:14:29 -08002353/*
2354 * In local heartbeat mode, region_uuid passed matches the dlm domain name.
2355 * In global heartbeat mode, region_uuid passed is NULL.
2356 *
2357 * In local, we only unpin the matching region. In global we unpin all the
2358 * active regions.
2359 */
2360static void o2hb_region_unpin(const char *region_uuid)
Joel Becker14829422007-06-14 21:40:49 -07002361{
2362 struct o2hb_region *reg;
Sunil Mushran58a31582010-12-14 14:14:29 -08002363 char *uuid;
2364 int found = 0;
2365
2366 assert_spin_locked(&o2hb_live_lock);
2367
2368 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) {
2369 uuid = config_item_name(&reg->hr_item);
2370 if (region_uuid) {
2371 if (strcmp(region_uuid, uuid))
2372 continue;
2373 found = 1;
2374 }
2375
2376 if (reg->hr_item_pinned) {
2377 mlog(ML_CLUSTER, "Unpin region %s\n", uuid);
2378 o2nm_undepend_item(&reg->hr_item);
2379 reg->hr_item_pinned = 0;
2380 }
2381 if (found)
2382 break;
2383 }
2384}
2385
2386static int o2hb_region_inc_user(const char *region_uuid)
2387{
2388 int ret = 0;
Joel Becker14829422007-06-14 21:40:49 -07002389
2390 spin_lock(&o2hb_live_lock);
2391
Sunil Mushran58a31582010-12-14 14:14:29 -08002392 /* local heartbeat */
2393 if (!o2hb_global_heartbeat_active()) {
2394 ret = o2hb_region_pin(region_uuid);
2395 goto unlock;
Joel Becker16c6a4f2007-06-19 11:34:03 -07002396 }
Sunil Mushran58a31582010-12-14 14:14:29 -08002397
2398 /*
2399 * if global heartbeat active and this is the first dependent user,
2400 * pin all regions if quorum region count <= CUT_OFF
2401 */
2402 o2hb_dependent_users++;
2403 if (o2hb_dependent_users > 1)
2404 goto unlock;
2405
2406 if (o2hb_pop_count(&o2hb_quorum_region_bitmap,
2407 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF)
2408 ret = o2hb_region_pin(NULL);
2409
2410unlock:
2411 spin_unlock(&o2hb_live_lock);
2412 return ret;
2413}
2414
2415void o2hb_region_dec_user(const char *region_uuid)
2416{
2417 spin_lock(&o2hb_live_lock);
2418
2419 /* local heartbeat */
2420 if (!o2hb_global_heartbeat_active()) {
2421 o2hb_region_unpin(region_uuid);
2422 goto unlock;
2423 }
2424
2425 /*
2426 * if global heartbeat active and there are no dependent users,
2427 * unpin all quorum regions
2428 */
2429 o2hb_dependent_users--;
2430 if (!o2hb_dependent_users)
2431 o2hb_region_unpin(NULL);
2432
2433unlock:
2434 spin_unlock(&o2hb_live_lock);
Joel Becker14829422007-06-14 21:40:49 -07002435}
2436
2437int o2hb_register_callback(const char *region_uuid,
2438 struct o2hb_callback_func *hc)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002439{
2440 struct o2hb_callback_func *tmp;
2441 struct list_head *iter;
2442 struct o2hb_callback *hbcall;
2443 int ret;
2444
2445 BUG_ON(hc->hc_magic != O2HB_CB_MAGIC);
2446 BUG_ON(!list_empty(&hc->hc_item));
2447
2448 hbcall = hbcall_from_type(hc->hc_type);
2449 if (IS_ERR(hbcall)) {
2450 ret = PTR_ERR(hbcall);
2451 goto out;
2452 }
2453
Joel Becker14829422007-06-14 21:40:49 -07002454 if (region_uuid) {
Sunil Mushran58a31582010-12-14 14:14:29 -08002455 ret = o2hb_region_inc_user(region_uuid);
2456 if (ret) {
2457 mlog_errno(ret);
Joel Becker14829422007-06-14 21:40:49 -07002458 goto out;
Sunil Mushran58a31582010-12-14 14:14:29 -08002459 }
Joel Becker14829422007-06-14 21:40:49 -07002460 }
2461
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002462 down_write(&o2hb_callback_sem);
2463
2464 list_for_each(iter, &hbcall->list) {
2465 tmp = list_entry(iter, struct o2hb_callback_func, hc_item);
2466 if (hc->hc_priority < tmp->hc_priority) {
2467 list_add_tail(&hc->hc_item, iter);
2468 break;
2469 }
2470 }
2471 if (list_empty(&hc->hc_item))
2472 list_add_tail(&hc->hc_item, &hbcall->list);
2473
2474 up_write(&o2hb_callback_sem);
2475 ret = 0;
2476out:
Sunil Mushran58a31582010-12-14 14:14:29 -08002477 mlog(ML_CLUSTER, "returning %d on behalf of %p for funcs %p\n",
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002478 ret, __builtin_return_address(0), hc);
2479 return ret;
2480}
2481EXPORT_SYMBOL_GPL(o2hb_register_callback);
2482
Joel Becker14829422007-06-14 21:40:49 -07002483void o2hb_unregister_callback(const char *region_uuid,
2484 struct o2hb_callback_func *hc)
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002485{
2486 BUG_ON(hc->hc_magic != O2HB_CB_MAGIC);
2487
Sunil Mushran58a31582010-12-14 14:14:29 -08002488 mlog(ML_CLUSTER, "on behalf of %p for funcs %p\n",
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002489 __builtin_return_address(0), hc);
2490
Joel Becker14829422007-06-14 21:40:49 -07002491 /* XXX Can this happen _with_ a region reference? */
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002492 if (list_empty(&hc->hc_item))
Joel Beckerc24f72c2007-02-03 03:14:30 -08002493 return;
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002494
Joel Becker14829422007-06-14 21:40:49 -07002495 if (region_uuid)
Sunil Mushran58a31582010-12-14 14:14:29 -08002496 o2hb_region_dec_user(region_uuid);
Joel Becker14829422007-06-14 21:40:49 -07002497
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002498 down_write(&o2hb_callback_sem);
2499
2500 list_del_init(&hc->hc_item);
2501
2502 up_write(&o2hb_callback_sem);
Mark Fasheha7f6a5f2005-12-15 14:31:23 -08002503}
2504EXPORT_SYMBOL_GPL(o2hb_unregister_callback);
2505
2506int o2hb_check_node_heartbeating(u8 node_num)
2507{
2508 unsigned long testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
2509
2510 o2hb_fill_node_map(testing_map, sizeof(testing_map));
2511 if (!test_bit(node_num, testing_map)) {
2512 mlog(ML_HEARTBEAT,
2513 "node (%u) does not have heartbeating enabled.\n",
2514 node_num);
2515 return 0;
2516 }
2517
2518 return 1;
2519}
2520EXPORT_SYMBOL_GPL(o2hb_check_node_heartbeating);
2521
2522int o2hb_check_node_heartbeating_from_callback(u8 node_num)
2523{
2524 unsigned long testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
2525
2526 o2hb_fill_node_map_from_callback(testing_map, sizeof(testing_map));
2527 if (!test_bit(node_num, testing_map)) {
2528 mlog(ML_HEARTBEAT,
2529 "node (%u) does not have heartbeating enabled.\n",
2530 node_num);
2531 return 0;
2532 }
2533
2534 return 1;
2535}
2536EXPORT_SYMBOL_GPL(o2hb_check_node_heartbeating_from_callback);
2537
2538/* Makes sure our local node is configured with a node number, and is
2539 * heartbeating. */
2540int o2hb_check_local_node_heartbeating(void)
2541{
2542 u8 node_num;
2543
2544 /* if this node was set then we have networking */
2545 node_num = o2nm_this_node();
2546 if (node_num == O2NM_MAX_NODES) {
2547 mlog(ML_HEARTBEAT, "this node has not been configured.\n");
2548 return 0;
2549 }
2550
2551 return o2hb_check_node_heartbeating(node_num);
2552}
2553EXPORT_SYMBOL_GPL(o2hb_check_local_node_heartbeating);
2554
2555/*
2556 * this is just a hack until we get the plumbing which flips file systems
2557 * read only and drops the hb ref instead of killing the node dead.
2558 */
2559void o2hb_stop_all_regions(void)
2560{
2561 struct o2hb_region *reg;
2562
2563 mlog(ML_ERROR, "stopping heartbeat on all active regions.\n");
2564
2565 spin_lock(&o2hb_live_lock);
2566
2567 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item)
2568 reg->hr_unclean_stop = 1;
2569
2570 spin_unlock(&o2hb_live_lock);
2571}
2572EXPORT_SYMBOL_GPL(o2hb_stop_all_regions);
Sunil Mushranb3c85c42010-10-07 14:31:06 -07002573
2574int o2hb_get_all_regions(char *region_uuids, u8 max_regions)
2575{
2576 struct o2hb_region *reg;
2577 int numregs = 0;
2578 char *p;
2579
2580 spin_lock(&o2hb_live_lock);
2581
2582 p = region_uuids;
2583 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) {
2584 mlog(0, "Region: %s\n", config_item_name(&reg->hr_item));
2585 if (numregs < max_regions) {
2586 memcpy(p, config_item_name(&reg->hr_item),
2587 O2HB_MAX_REGION_NAME_LEN);
2588 p += O2HB_MAX_REGION_NAME_LEN;
2589 }
2590 numregs++;
2591 }
2592
2593 spin_unlock(&o2hb_live_lock);
2594
2595 return numregs;
2596}
2597EXPORT_SYMBOL_GPL(o2hb_get_all_regions);
2598
2599int o2hb_global_heartbeat_active(void)
2600{
Sunil Mushran4d94aa12010-10-09 10:27:04 -07002601 return (o2hb_heartbeat_mode == O2HB_HEARTBEAT_GLOBAL);
Sunil Mushranb3c85c42010-10-07 14:31:06 -07002602}
2603EXPORT_SYMBOL(o2hb_global_heartbeat_active);