1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Copyright (C) 2004, 2005 Oracle. All rights reserved. 4 */ 5 6 #include "linux/kstrtox.h" 7 #include <linux/kernel.h> 8 #include <linux/sched.h> 9 #include <linux/jiffies.h> 10 #include <linux/module.h> 11 #include <linux/fs.h> 12 #include <linux/bio.h> 13 #include <linux/blkdev.h> 14 #include <linux/delay.h> 15 #include <linux/file.h> 16 #include <linux/kthread.h> 17 #include <linux/configfs.h> 18 #include <linux/random.h> 19 #include <linux/crc32.h> 20 #include <linux/time.h> 21 #include <linux/debugfs.h> 22 #include <linux/slab.h> 23 #include <linux/bitmap.h> 24 #include <linux/ktime.h> 25 #include "heartbeat.h" 26 #include "tcp.h" 27 #include "nodemanager.h" 28 #include "quorum.h" 29 30 #include "masklog.h" 31 32 33 /* 34 * The first heartbeat pass had one global thread that would serialize all hb 35 * callback calls. This global serializing sem should only be removed once 36 * we've made sure that all callees can deal with being called concurrently 37 * from multiple hb region threads. 38 */ 39 static DECLARE_RWSEM(o2hb_callback_sem); 40 41 /* 42 * multiple hb threads are watching multiple regions. A node is live 43 * whenever any of the threads sees activity from the node in its region. 44 */ 45 static DEFINE_SPINLOCK(o2hb_live_lock); 46 static struct list_head o2hb_live_slots[O2NM_MAX_NODES]; 47 static unsigned long o2hb_live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; 48 static LIST_HEAD(o2hb_node_events); 49 static DECLARE_WAIT_QUEUE_HEAD(o2hb_steady_queue); 50 51 /* 52 * In global heartbeat, we maintain a series of region bitmaps. 53 * - o2hb_region_bitmap allows us to limit the region number to max region. 54 * - o2hb_live_region_bitmap tracks live regions (seen steady iterations). 55 * - o2hb_quorum_region_bitmap tracks live regions that have seen all nodes 56 * heartbeat on it. 57 * - o2hb_failed_region_bitmap tracks the regions that have seen io timeouts. 58 */ 59 static unsigned long o2hb_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)]; 60 static unsigned long o2hb_live_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)]; 61 static unsigned long o2hb_quorum_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)]; 62 static unsigned long o2hb_failed_region_bitmap[BITS_TO_LONGS(O2NM_MAX_REGIONS)]; 63 64 #define O2HB_DB_TYPE_LIVENODES 0 65 #define O2HB_DB_TYPE_LIVEREGIONS 1 66 #define O2HB_DB_TYPE_QUORUMREGIONS 2 67 #define O2HB_DB_TYPE_FAILEDREGIONS 3 68 #define O2HB_DB_TYPE_REGION_LIVENODES 4 69 #define O2HB_DB_TYPE_REGION_NUMBER 5 70 #define O2HB_DB_TYPE_REGION_ELAPSED_TIME 6 71 #define O2HB_DB_TYPE_REGION_PINNED 7 72 struct o2hb_debug_buf { 73 int db_type; 74 int db_size; 75 int db_len; 76 void *db_data; 77 }; 78 79 static struct o2hb_debug_buf *o2hb_db_livenodes; 80 static struct o2hb_debug_buf *o2hb_db_liveregions; 81 static struct o2hb_debug_buf *o2hb_db_quorumregions; 82 static struct o2hb_debug_buf *o2hb_db_failedregions; 83 84 #define O2HB_DEBUG_DIR "o2hb" 85 #define O2HB_DEBUG_LIVENODES "livenodes" 86 #define O2HB_DEBUG_LIVEREGIONS "live_regions" 87 #define O2HB_DEBUG_QUORUMREGIONS "quorum_regions" 88 #define O2HB_DEBUG_FAILEDREGIONS "failed_regions" 89 #define O2HB_DEBUG_REGION_NUMBER "num" 90 #define O2HB_DEBUG_REGION_ELAPSED_TIME "elapsed_time_in_ms" 91 #define O2HB_DEBUG_REGION_PINNED "pinned" 92 93 static struct dentry *o2hb_debug_dir; 94 95 static LIST_HEAD(o2hb_all_regions); 96 97 static struct o2hb_callback { 98 struct list_head list; 99 } o2hb_callbacks[O2HB_NUM_CB]; 100 101 static struct o2hb_callback *hbcall_from_type(enum o2hb_callback_type type); 102 103 enum o2hb_heartbeat_modes { 104 O2HB_HEARTBEAT_LOCAL = 0, 105 O2HB_HEARTBEAT_GLOBAL, 106 O2HB_HEARTBEAT_NUM_MODES, 107 }; 108 109 static const char *o2hb_heartbeat_mode_desc[O2HB_HEARTBEAT_NUM_MODES] = { 110 "local", /* O2HB_HEARTBEAT_LOCAL */ 111 "global", /* O2HB_HEARTBEAT_GLOBAL */ 112 }; 113 114 unsigned int o2hb_dead_threshold = O2HB_DEFAULT_DEAD_THRESHOLD; 115 static unsigned int o2hb_heartbeat_mode = O2HB_HEARTBEAT_LOCAL; 116 117 /* 118 * o2hb_dependent_users tracks the number of registered callbacks that depend 119 * on heartbeat. o2net and o2dlm are two entities that register this callback. 120 * However only o2dlm depends on the heartbeat. It does not want the heartbeat 121 * to stop while a dlm domain is still active. 122 */ 123 static unsigned int o2hb_dependent_users; 124 125 /* 126 * In global heartbeat mode, all regions are pinned if there are one or more 127 * dependent users and the quorum region count is <= O2HB_PIN_CUT_OFF. All 128 * regions are unpinned if the region count exceeds the cut off or the number 129 * of dependent users falls to zero. 130 */ 131 #define O2HB_PIN_CUT_OFF 3 132 133 /* 134 * In local heartbeat mode, we assume the dlm domain name to be the same as 135 * region uuid. This is true for domains created for the file system but not 136 * necessarily true for userdlm domains. This is a known limitation. 137 * 138 * In global heartbeat mode, we pin/unpin all o2hb regions. This solution 139 * works for both file system and userdlm domains. 140 */ 141 static int o2hb_region_pin(const char *region_uuid); 142 static void o2hb_region_unpin(const char *region_uuid); 143 144 /* Only sets a new threshold if there are no active regions. 145 * 146 * No locking or otherwise interesting code is required for reading 147 * o2hb_dead_threshold as it can't change once regions are active and 148 * it's not interesting to anyone until then anyway. */ 149 static void o2hb_dead_threshold_set(unsigned int threshold) 150 { 151 if (threshold > O2HB_MIN_DEAD_THRESHOLD) { 152 spin_lock(&o2hb_live_lock); 153 if (list_empty(&o2hb_all_regions)) 154 o2hb_dead_threshold = threshold; 155 spin_unlock(&o2hb_live_lock); 156 } 157 } 158 159 static int o2hb_global_heartbeat_mode_set(unsigned int hb_mode) 160 { 161 int ret = -1; 162 163 if (hb_mode < O2HB_HEARTBEAT_NUM_MODES) { 164 spin_lock(&o2hb_live_lock); 165 if (list_empty(&o2hb_all_regions)) { 166 o2hb_heartbeat_mode = hb_mode; 167 ret = 0; 168 } 169 spin_unlock(&o2hb_live_lock); 170 } 171 172 return ret; 173 } 174 175 struct o2hb_node_event { 176 struct list_head hn_item; 177 enum o2hb_callback_type hn_event_type; 178 struct o2nm_node *hn_node; 179 int hn_node_num; 180 }; 181 182 struct o2hb_disk_slot { 183 struct o2hb_disk_heartbeat_block *ds_raw_block; 184 u8 ds_node_num; 185 u64 ds_last_time; 186 u64 ds_last_generation; 187 u16 ds_equal_samples; 188 u16 ds_changed_samples; 189 struct list_head ds_live_item; 190 }; 191 192 /* each thread owns a region.. when we're asked to tear down the region 193 * we ask the thread to stop, who cleans up the region */ 194 struct o2hb_region { 195 struct config_item hr_item; 196 197 struct list_head hr_all_item; 198 unsigned hr_unclean_stop:1, 199 hr_aborted_start:1, 200 hr_item_pinned:1, 201 hr_item_dropped:1, 202 hr_node_deleted:1; 203 204 /* protected by the hr_callback_sem */ 205 struct task_struct *hr_task; 206 207 unsigned int hr_blocks; 208 unsigned long long hr_start_block; 209 210 unsigned int hr_block_bits; 211 unsigned int hr_block_bytes; 212 213 unsigned int hr_slots_per_page; 214 unsigned int hr_num_pages; 215 216 struct page **hr_slot_data; 217 struct file *hr_bdev_file; 218 struct o2hb_disk_slot *hr_slots; 219 220 /* live node map of this region */ 221 unsigned long hr_live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; 222 unsigned int hr_region_num; 223 224 struct dentry *hr_debug_dir; 225 struct o2hb_debug_buf *hr_db_livenodes; 226 struct o2hb_debug_buf *hr_db_regnum; 227 struct o2hb_debug_buf *hr_db_elapsed_time; 228 struct o2hb_debug_buf *hr_db_pinned; 229 230 /* let the person setting up hb wait for it to return until it 231 * has reached a 'steady' state. This will be fixed when we have 232 * a more complete api that doesn't lead to this sort of fragility. */ 233 atomic_t hr_steady_iterations; 234 235 /* terminate o2hb thread if it does not reach steady state 236 * (hr_steady_iterations == 0) within hr_unsteady_iterations */ 237 atomic_t hr_unsteady_iterations; 238 239 unsigned int hr_timeout_ms; 240 241 /* randomized as the region goes up and down so that a node 242 * recognizes a node going up and down in one iteration */ 243 u64 hr_generation; 244 245 struct delayed_work hr_write_timeout_work; 246 unsigned long hr_last_timeout_start; 247 248 /* negotiate timer, used to negotiate extending hb timeout. */ 249 struct delayed_work hr_nego_timeout_work; 250 unsigned long hr_nego_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; 251 252 /* Used during o2hb_check_slot to hold a copy of the block 253 * being checked because we temporarily have to zero out the 254 * crc field. */ 255 struct o2hb_disk_heartbeat_block *hr_tmp_block; 256 257 /* Message key for negotiate timeout message. */ 258 unsigned int hr_key; 259 struct list_head hr_handler_list; 260 261 /* last hb status, 0 for success, other value for error. */ 262 int hr_last_hb_status; 263 }; 264 265 static inline struct block_device *reg_bdev(struct o2hb_region *reg) 266 { 267 return reg->hr_bdev_file ? file_bdev(reg->hr_bdev_file) : NULL; 268 } 269 270 struct o2hb_bio_wait_ctxt { 271 atomic_t wc_num_reqs; 272 struct completion wc_io_complete; 273 int wc_error; 274 }; 275 276 #define O2HB_NEGO_TIMEOUT_MS (O2HB_MAX_WRITE_TIMEOUT_MS/2) 277 278 enum { 279 O2HB_NEGO_TIMEOUT_MSG = 1, 280 O2HB_NEGO_APPROVE_MSG = 2, 281 }; 282 283 struct o2hb_nego_msg { 284 u8 node_num; 285 }; 286 287 static void o2hb_write_timeout(struct work_struct *work) 288 { 289 int failed, quorum; 290 struct o2hb_region *reg = 291 container_of(work, struct o2hb_region, 292 hr_write_timeout_work.work); 293 294 mlog(ML_ERROR, "Heartbeat write timeout to device %pg after %u " 295 "milliseconds\n", reg_bdev(reg), 296 jiffies_to_msecs(jiffies - reg->hr_last_timeout_start)); 297 298 if (o2hb_global_heartbeat_active()) { 299 spin_lock(&o2hb_live_lock); 300 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap)) 301 set_bit(reg->hr_region_num, o2hb_failed_region_bitmap); 302 failed = bitmap_weight(o2hb_failed_region_bitmap, 303 O2NM_MAX_REGIONS); 304 quorum = bitmap_weight(o2hb_quorum_region_bitmap, 305 O2NM_MAX_REGIONS); 306 spin_unlock(&o2hb_live_lock); 307 308 mlog(ML_HEARTBEAT, "Number of regions %d, failed regions %d\n", 309 quorum, failed); 310 311 /* 312 * Fence if the number of failed regions >= half the number 313 * of quorum regions 314 */ 315 if ((failed << 1) < quorum) 316 return; 317 } 318 319 o2quo_disk_timeout(); 320 } 321 322 static void o2hb_arm_timeout(struct o2hb_region *reg) 323 { 324 /* Arm writeout only after thread reaches steady state */ 325 if (atomic_read(®->hr_steady_iterations) != 0) 326 return; 327 328 mlog(ML_HEARTBEAT, "Queue write timeout for %u ms\n", 329 O2HB_MAX_WRITE_TIMEOUT_MS); 330 331 if (o2hb_global_heartbeat_active()) { 332 spin_lock(&o2hb_live_lock); 333 clear_bit(reg->hr_region_num, o2hb_failed_region_bitmap); 334 spin_unlock(&o2hb_live_lock); 335 } 336 cancel_delayed_work(®->hr_write_timeout_work); 337 schedule_delayed_work(®->hr_write_timeout_work, 338 msecs_to_jiffies(O2HB_MAX_WRITE_TIMEOUT_MS)); 339 340 cancel_delayed_work(®->hr_nego_timeout_work); 341 /* negotiate timeout must be less than write timeout. */ 342 schedule_delayed_work(®->hr_nego_timeout_work, 343 msecs_to_jiffies(O2HB_NEGO_TIMEOUT_MS)); 344 bitmap_zero(reg->hr_nego_node_bitmap, O2NM_MAX_NODES); 345 } 346 347 static void o2hb_disarm_timeout(struct o2hb_region *reg) 348 { 349 cancel_delayed_work_sync(®->hr_write_timeout_work); 350 cancel_delayed_work_sync(®->hr_nego_timeout_work); 351 } 352 353 static int o2hb_send_nego_msg(int key, int type, u8 target) 354 { 355 struct o2hb_nego_msg msg; 356 int status, ret; 357 358 msg.node_num = o2nm_this_node(); 359 again: 360 ret = o2net_send_message(type, key, &msg, sizeof(msg), 361 target, &status); 362 363 if (ret == -EAGAIN || ret == -ENOMEM) { 364 msleep(100); 365 goto again; 366 } 367 368 return ret; 369 } 370 371 static void o2hb_nego_timeout(struct work_struct *work) 372 { 373 unsigned long live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; 374 int master_node, i, ret; 375 struct o2hb_region *reg; 376 377 reg = container_of(work, struct o2hb_region, hr_nego_timeout_work.work); 378 /* don't negotiate timeout if last hb failed since it is very 379 * possible io failed. Should let write timeout fence self. 380 */ 381 if (reg->hr_last_hb_status) 382 return; 383 384 o2hb_fill_node_map(live_node_bitmap, O2NM_MAX_NODES); 385 /* lowest node as master node to make negotiate decision. */ 386 master_node = find_first_bit(live_node_bitmap, O2NM_MAX_NODES); 387 388 if (master_node == o2nm_this_node()) { 389 if (!test_bit(master_node, reg->hr_nego_node_bitmap)) { 390 printk(KERN_NOTICE "o2hb: node %d hb write hung for %ds on region %s (%pg).\n", 391 o2nm_this_node(), O2HB_NEGO_TIMEOUT_MS/1000, 392 config_item_name(®->hr_item), reg_bdev(reg)); 393 set_bit(master_node, reg->hr_nego_node_bitmap); 394 } 395 if (!bitmap_equal(reg->hr_nego_node_bitmap, live_node_bitmap, 396 O2NM_MAX_NODES)) { 397 /* check negotiate bitmap every second to do timeout 398 * approve decision. 399 */ 400 schedule_delayed_work(®->hr_nego_timeout_work, 401 msecs_to_jiffies(1000)); 402 403 return; 404 } 405 406 printk(KERN_NOTICE "o2hb: all nodes hb write hung, maybe region %s (%pg) is down.\n", 407 config_item_name(®->hr_item), 408 reg_bdev(reg)); 409 /* approve negotiate timeout request. */ 410 o2hb_arm_timeout(reg); 411 412 i = -1; 413 while ((i = find_next_bit(live_node_bitmap, 414 O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) { 415 if (i == master_node) 416 continue; 417 418 mlog(ML_HEARTBEAT, "send NEGO_APPROVE msg to node %d\n", i); 419 ret = o2hb_send_nego_msg(reg->hr_key, 420 O2HB_NEGO_APPROVE_MSG, i); 421 if (ret) 422 mlog(ML_ERROR, "send NEGO_APPROVE msg to node %d fail %d\n", 423 i, ret); 424 } 425 } else { 426 /* negotiate timeout with master node. */ 427 printk(KERN_NOTICE "o2hb: node %d hb write hung for %ds on region %s (%pg), negotiate timeout with node %d.\n", 428 o2nm_this_node(), O2HB_NEGO_TIMEOUT_MS/1000, config_item_name(®->hr_item), 429 reg_bdev(reg), master_node); 430 ret = o2hb_send_nego_msg(reg->hr_key, O2HB_NEGO_TIMEOUT_MSG, 431 master_node); 432 if (ret) 433 mlog(ML_ERROR, "send NEGO_TIMEOUT msg to node %d fail %d\n", 434 master_node, ret); 435 } 436 } 437 438 static int o2hb_nego_timeout_handler(struct o2net_msg *msg, u32 len, void *data, 439 void **ret_data) 440 { 441 struct o2hb_region *reg = data; 442 struct o2hb_nego_msg *nego_msg; 443 444 nego_msg = (struct o2hb_nego_msg *)msg->buf; 445 printk(KERN_NOTICE "o2hb: receive negotiate timeout message from node %d on region %s (%pg).\n", 446 nego_msg->node_num, config_item_name(®->hr_item), 447 reg_bdev(reg)); 448 if (nego_msg->node_num < O2NM_MAX_NODES) 449 set_bit(nego_msg->node_num, reg->hr_nego_node_bitmap); 450 else 451 mlog(ML_ERROR, "got nego timeout message from bad node.\n"); 452 453 return 0; 454 } 455 456 static int o2hb_nego_approve_handler(struct o2net_msg *msg, u32 len, void *data, 457 void **ret_data) 458 { 459 struct o2hb_region *reg = data; 460 461 printk(KERN_NOTICE "o2hb: negotiate timeout approved by master node on region %s (%pg).\n", 462 config_item_name(®->hr_item), reg_bdev(reg)); 463 o2hb_arm_timeout(reg); 464 return 0; 465 } 466 467 static inline void o2hb_bio_wait_init(struct o2hb_bio_wait_ctxt *wc) 468 { 469 atomic_set(&wc->wc_num_reqs, 1); 470 init_completion(&wc->wc_io_complete); 471 wc->wc_error = 0; 472 } 473 474 /* Used in error paths too */ 475 static inline void o2hb_bio_wait_dec(struct o2hb_bio_wait_ctxt *wc, 476 unsigned int num) 477 { 478 /* sadly atomic_sub_and_test() isn't available on all platforms. The 479 * good news is that the fast path only completes one at a time */ 480 while(num--) { 481 if (atomic_dec_and_test(&wc->wc_num_reqs)) { 482 BUG_ON(num > 0); 483 complete(&wc->wc_io_complete); 484 } 485 } 486 } 487 488 static void o2hb_wait_on_io(struct o2hb_bio_wait_ctxt *wc) 489 { 490 o2hb_bio_wait_dec(wc, 1); 491 wait_for_completion(&wc->wc_io_complete); 492 } 493 494 static void o2hb_bio_end_io(struct bio *bio) 495 { 496 struct o2hb_bio_wait_ctxt *wc = bio->bi_private; 497 498 if (bio->bi_status) { 499 mlog(ML_ERROR, "IO Error %d\n", bio->bi_status); 500 wc->wc_error = blk_status_to_errno(bio->bi_status); 501 } 502 503 o2hb_bio_wait_dec(wc, 1); 504 bio_put(bio); 505 } 506 507 /* Setup a Bio to cover I/O against num_slots slots starting at 508 * start_slot. */ 509 static struct bio *o2hb_setup_one_bio(struct o2hb_region *reg, 510 struct o2hb_bio_wait_ctxt *wc, 511 unsigned int *current_slot, 512 unsigned int max_slots, blk_opf_t opf) 513 { 514 int len, current_page; 515 unsigned int vec_len, vec_start; 516 unsigned int bits = reg->hr_block_bits; 517 unsigned int spp = reg->hr_slots_per_page; 518 unsigned int cs = *current_slot; 519 struct bio *bio; 520 struct page *page; 521 522 /* Testing has shown this allocation to take long enough under 523 * GFP_KERNEL that the local node can get fenced. It would be 524 * nicest if we could pre-allocate these bios and avoid this 525 * all together. */ 526 bio = bio_alloc(reg_bdev(reg), 16, opf, GFP_ATOMIC); 527 if (!bio) { 528 mlog(ML_ERROR, "Could not alloc slots BIO!\n"); 529 bio = ERR_PTR(-ENOMEM); 530 goto bail; 531 } 532 533 /* Must put everything in 512 byte sectors for the bio... */ 534 bio->bi_iter.bi_sector = (reg->hr_start_block + cs) << (bits - 9); 535 bio->bi_private = wc; 536 bio->bi_end_io = o2hb_bio_end_io; 537 538 vec_start = (cs << bits) % PAGE_SIZE; 539 while(cs < max_slots) { 540 current_page = cs / spp; 541 page = reg->hr_slot_data[current_page]; 542 543 vec_len = min(PAGE_SIZE - vec_start, 544 (max_slots-cs) * (PAGE_SIZE/spp) ); 545 546 mlog(ML_HB_BIO, "page %d, vec_len = %u, vec_start = %u\n", 547 current_page, vec_len, vec_start); 548 549 len = bio_add_page(bio, page, vec_len, vec_start); 550 if (len != vec_len) break; 551 552 cs += vec_len / (PAGE_SIZE/spp); 553 vec_start = 0; 554 } 555 556 bail: 557 *current_slot = cs; 558 return bio; 559 } 560 561 static int o2hb_read_slots(struct o2hb_region *reg, 562 unsigned int begin_slot, 563 unsigned int max_slots) 564 { 565 unsigned int current_slot = begin_slot; 566 int status; 567 struct o2hb_bio_wait_ctxt wc; 568 struct bio *bio; 569 570 o2hb_bio_wait_init(&wc); 571 572 while(current_slot < max_slots) { 573 bio = o2hb_setup_one_bio(reg, &wc, ¤t_slot, max_slots, 574 REQ_OP_READ); 575 if (IS_ERR(bio)) { 576 status = PTR_ERR(bio); 577 mlog_errno(status); 578 goto bail_and_wait; 579 } 580 581 atomic_inc(&wc.wc_num_reqs); 582 submit_bio(bio); 583 } 584 585 status = 0; 586 587 bail_and_wait: 588 o2hb_wait_on_io(&wc); 589 if (wc.wc_error && !status) 590 status = wc.wc_error; 591 592 return status; 593 } 594 595 static int o2hb_issue_node_write(struct o2hb_region *reg, 596 struct o2hb_bio_wait_ctxt *write_wc) 597 { 598 int status; 599 unsigned int slot; 600 struct bio *bio; 601 602 o2hb_bio_wait_init(write_wc); 603 604 slot = o2nm_this_node(); 605 606 bio = o2hb_setup_one_bio(reg, write_wc, &slot, slot+1, 607 REQ_OP_WRITE | REQ_SYNC); 608 if (IS_ERR(bio)) { 609 status = PTR_ERR(bio); 610 mlog_errno(status); 611 goto bail; 612 } 613 614 atomic_inc(&write_wc->wc_num_reqs); 615 submit_bio(bio); 616 617 status = 0; 618 bail: 619 return status; 620 } 621 622 static u32 o2hb_compute_block_crc_le(struct o2hb_region *reg, 623 struct o2hb_disk_heartbeat_block *hb_block) 624 { 625 __le32 old_cksum; 626 u32 ret; 627 628 /* We want to compute the block crc with a 0 value in the 629 * hb_cksum field. Save it off here and replace after the 630 * crc. */ 631 old_cksum = hb_block->hb_cksum; 632 hb_block->hb_cksum = 0; 633 634 ret = crc32_le(0, (unsigned char *) hb_block, reg->hr_block_bytes); 635 636 hb_block->hb_cksum = old_cksum; 637 638 return ret; 639 } 640 641 static void o2hb_dump_slot(struct o2hb_disk_heartbeat_block *hb_block) 642 { 643 mlog(ML_ERROR, "Dump slot information: seq = 0x%llx, node = %u, " 644 "cksum = 0x%x, generation 0x%llx\n", 645 (long long)le64_to_cpu(hb_block->hb_seq), 646 hb_block->hb_node, le32_to_cpu(hb_block->hb_cksum), 647 (long long)le64_to_cpu(hb_block->hb_generation)); 648 } 649 650 static int o2hb_verify_crc(struct o2hb_region *reg, 651 struct o2hb_disk_heartbeat_block *hb_block) 652 { 653 u32 read, computed; 654 655 read = le32_to_cpu(hb_block->hb_cksum); 656 computed = o2hb_compute_block_crc_le(reg, hb_block); 657 658 return read == computed; 659 } 660 661 /* 662 * Compare the slot data with what we wrote in the last iteration. 663 * If the match fails, print an appropriate error message. This is to 664 * detect errors like... another node hearting on the same slot, 665 * flaky device that is losing writes, etc. 666 * Returns 1 if check succeeds, 0 otherwise. 667 */ 668 static int o2hb_check_own_slot(struct o2hb_region *reg) 669 { 670 struct o2hb_disk_slot *slot; 671 struct o2hb_disk_heartbeat_block *hb_block; 672 char *errstr; 673 674 slot = ®->hr_slots[o2nm_this_node()]; 675 /* Don't check on our 1st timestamp */ 676 if (!slot->ds_last_time) 677 return 0; 678 679 hb_block = slot->ds_raw_block; 680 if (le64_to_cpu(hb_block->hb_seq) == slot->ds_last_time && 681 le64_to_cpu(hb_block->hb_generation) == slot->ds_last_generation && 682 hb_block->hb_node == slot->ds_node_num) 683 return 1; 684 685 #define ERRSTR1 "Another node is heartbeating on device" 686 #define ERRSTR2 "Heartbeat generation mismatch on device" 687 #define ERRSTR3 "Heartbeat sequence mismatch on device" 688 689 if (hb_block->hb_node != slot->ds_node_num) 690 errstr = ERRSTR1; 691 else if (le64_to_cpu(hb_block->hb_generation) != 692 slot->ds_last_generation) 693 errstr = ERRSTR2; 694 else 695 errstr = ERRSTR3; 696 697 mlog(ML_ERROR, "%s (%pg): expected(%u:0x%llx, 0x%llx), " 698 "ondisk(%u:0x%llx, 0x%llx)\n", errstr, reg_bdev(reg), 699 slot->ds_node_num, (unsigned long long)slot->ds_last_generation, 700 (unsigned long long)slot->ds_last_time, hb_block->hb_node, 701 (unsigned long long)le64_to_cpu(hb_block->hb_generation), 702 (unsigned long long)le64_to_cpu(hb_block->hb_seq)); 703 704 return 0; 705 } 706 707 static inline void o2hb_prepare_block(struct o2hb_region *reg, 708 u64 generation) 709 { 710 int node_num; 711 u64 cputime; 712 struct o2hb_disk_slot *slot; 713 struct o2hb_disk_heartbeat_block *hb_block; 714 715 node_num = o2nm_this_node(); 716 slot = ®->hr_slots[node_num]; 717 718 hb_block = (struct o2hb_disk_heartbeat_block *)slot->ds_raw_block; 719 memset(hb_block, 0, reg->hr_block_bytes); 720 /* TODO: time stuff */ 721 cputime = ktime_get_real_seconds(); 722 if (!cputime) 723 cputime = 1; 724 725 hb_block->hb_seq = cpu_to_le64(cputime); 726 hb_block->hb_node = node_num; 727 hb_block->hb_generation = cpu_to_le64(generation); 728 hb_block->hb_dead_ms = cpu_to_le32(o2hb_dead_threshold * O2HB_REGION_TIMEOUT_MS); 729 730 /* This step must always happen last! */ 731 hb_block->hb_cksum = cpu_to_le32(o2hb_compute_block_crc_le(reg, 732 hb_block)); 733 734 mlog(ML_HB_BIO, "our node generation = 0x%llx, cksum = 0x%x\n", 735 (long long)generation, 736 le32_to_cpu(hb_block->hb_cksum)); 737 } 738 739 static void o2hb_fire_callbacks(struct o2hb_callback *hbcall, 740 struct o2nm_node *node, 741 int idx) 742 { 743 struct o2hb_callback_func *f; 744 745 list_for_each_entry(f, &hbcall->list, hc_item) { 746 mlog(ML_HEARTBEAT, "calling funcs %p\n", f); 747 (f->hc_func)(node, idx, f->hc_data); 748 } 749 } 750 751 /* Will run the list in order until we process the passed event */ 752 static void o2hb_run_event_list(struct o2hb_node_event *queued_event) 753 { 754 struct o2hb_callback *hbcall; 755 struct o2hb_node_event *event; 756 757 /* Holding callback sem assures we don't alter the callback 758 * lists when doing this, and serializes ourselves with other 759 * processes wanting callbacks. */ 760 down_write(&o2hb_callback_sem); 761 762 spin_lock(&o2hb_live_lock); 763 while (!list_empty(&o2hb_node_events) 764 && !list_empty(&queued_event->hn_item)) { 765 event = list_entry(o2hb_node_events.next, 766 struct o2hb_node_event, 767 hn_item); 768 list_del_init(&event->hn_item); 769 spin_unlock(&o2hb_live_lock); 770 771 mlog(ML_HEARTBEAT, "Node %s event for %d\n", 772 event->hn_event_type == O2HB_NODE_UP_CB ? "UP" : "DOWN", 773 event->hn_node_num); 774 775 hbcall = hbcall_from_type(event->hn_event_type); 776 777 /* We should *never* have gotten on to the list with a 778 * bad type... This isn't something that we should try 779 * to recover from. */ 780 BUG_ON(IS_ERR(hbcall)); 781 782 o2hb_fire_callbacks(hbcall, event->hn_node, event->hn_node_num); 783 784 spin_lock(&o2hb_live_lock); 785 } 786 spin_unlock(&o2hb_live_lock); 787 788 up_write(&o2hb_callback_sem); 789 } 790 791 static void o2hb_queue_node_event(struct o2hb_node_event *event, 792 enum o2hb_callback_type type, 793 struct o2nm_node *node, 794 int node_num) 795 { 796 assert_spin_locked(&o2hb_live_lock); 797 798 BUG_ON((!node) && (type != O2HB_NODE_DOWN_CB)); 799 800 event->hn_event_type = type; 801 event->hn_node = node; 802 event->hn_node_num = node_num; 803 804 mlog(ML_HEARTBEAT, "Queue node %s event for node %d\n", 805 type == O2HB_NODE_UP_CB ? "UP" : "DOWN", node_num); 806 807 list_add_tail(&event->hn_item, &o2hb_node_events); 808 } 809 810 static void o2hb_shutdown_slot(struct o2hb_disk_slot *slot) 811 { 812 struct o2hb_node_event event = 813 { .hn_item = LIST_HEAD_INIT(event.hn_item), }; 814 struct o2nm_node *node; 815 int queued = 0; 816 817 node = o2nm_get_node_by_num(slot->ds_node_num); 818 if (!node) 819 return; 820 821 spin_lock(&o2hb_live_lock); 822 if (!list_empty(&slot->ds_live_item)) { 823 mlog(ML_HEARTBEAT, "Shutdown, node %d leaves region\n", 824 slot->ds_node_num); 825 826 list_del_init(&slot->ds_live_item); 827 828 if (list_empty(&o2hb_live_slots[slot->ds_node_num])) { 829 clear_bit(slot->ds_node_num, o2hb_live_node_bitmap); 830 831 o2hb_queue_node_event(&event, O2HB_NODE_DOWN_CB, node, 832 slot->ds_node_num); 833 queued = 1; 834 } 835 } 836 spin_unlock(&o2hb_live_lock); 837 838 if (queued) 839 o2hb_run_event_list(&event); 840 841 o2nm_node_put(node); 842 } 843 844 static void o2hb_set_quorum_device(struct o2hb_region *reg) 845 { 846 if (!o2hb_global_heartbeat_active()) 847 return; 848 849 /* Prevent race with o2hb_heartbeat_group_drop_item() */ 850 if (kthread_should_stop()) 851 return; 852 853 /* Tag region as quorum only after thread reaches steady state */ 854 if (atomic_read(®->hr_steady_iterations) != 0) 855 return; 856 857 spin_lock(&o2hb_live_lock); 858 859 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap)) 860 goto unlock; 861 862 /* 863 * A region can be added to the quorum only when it sees all 864 * live nodes heartbeat on it. In other words, the region has been 865 * added to all nodes. 866 */ 867 if (!bitmap_equal(reg->hr_live_node_bitmap, o2hb_live_node_bitmap, 868 O2NM_MAX_NODES)) 869 goto unlock; 870 871 printk(KERN_NOTICE "o2hb: Region %s (%pg) is now a quorum device\n", 872 config_item_name(®->hr_item), reg_bdev(reg)); 873 874 set_bit(reg->hr_region_num, o2hb_quorum_region_bitmap); 875 876 /* 877 * If global heartbeat active, unpin all regions if the 878 * region count > CUT_OFF 879 */ 880 if (bitmap_weight(o2hb_quorum_region_bitmap, 881 O2NM_MAX_REGIONS) > O2HB_PIN_CUT_OFF) 882 o2hb_region_unpin(NULL); 883 unlock: 884 spin_unlock(&o2hb_live_lock); 885 } 886 887 static int o2hb_check_slot(struct o2hb_region *reg, 888 struct o2hb_disk_slot *slot) 889 { 890 int changed = 0, gen_changed = 0; 891 struct o2hb_node_event event = 892 { .hn_item = LIST_HEAD_INIT(event.hn_item), }; 893 struct o2nm_node *node; 894 struct o2hb_disk_heartbeat_block *hb_block = reg->hr_tmp_block; 895 u64 cputime; 896 unsigned int dead_ms = o2hb_dead_threshold * O2HB_REGION_TIMEOUT_MS; 897 unsigned int slot_dead_ms; 898 int tmp; 899 int queued = 0; 900 901 memcpy(hb_block, slot->ds_raw_block, reg->hr_block_bytes); 902 903 /* 904 * If a node is no longer configured but is still in the livemap, we 905 * may need to clear that bit from the livemap. 906 */ 907 node = o2nm_get_node_by_num(slot->ds_node_num); 908 if (!node) { 909 spin_lock(&o2hb_live_lock); 910 tmp = test_bit(slot->ds_node_num, o2hb_live_node_bitmap); 911 spin_unlock(&o2hb_live_lock); 912 if (!tmp) 913 return 0; 914 } 915 916 if (!o2hb_verify_crc(reg, hb_block)) { 917 /* all paths from here will drop o2hb_live_lock for 918 * us. */ 919 spin_lock(&o2hb_live_lock); 920 921 /* Don't print an error on the console in this case - 922 * a freshly formatted heartbeat area will not have a 923 * crc set on it. */ 924 if (list_empty(&slot->ds_live_item)) 925 goto out; 926 927 /* The node is live but pushed out a bad crc. We 928 * consider it a transient miss but don't populate any 929 * other values as they may be junk. */ 930 mlog(ML_ERROR, "Node %d has written a bad crc to %pg\n", 931 slot->ds_node_num, reg_bdev(reg)); 932 o2hb_dump_slot(hb_block); 933 934 slot->ds_equal_samples++; 935 goto fire_callbacks; 936 } 937 938 /* we don't care if these wrap.. the state transitions below 939 * clear at the right places */ 940 cputime = le64_to_cpu(hb_block->hb_seq); 941 if (slot->ds_last_time != cputime) 942 slot->ds_changed_samples++; 943 else 944 slot->ds_equal_samples++; 945 slot->ds_last_time = cputime; 946 947 /* The node changed heartbeat generations. We assume this to 948 * mean it dropped off but came back before we timed out. We 949 * want to consider it down for the time being but don't want 950 * to lose any changed_samples state we might build up to 951 * considering it live again. */ 952 if (slot->ds_last_generation != le64_to_cpu(hb_block->hb_generation)) { 953 gen_changed = 1; 954 slot->ds_equal_samples = 0; 955 mlog(ML_HEARTBEAT, "Node %d changed generation (0x%llx " 956 "to 0x%llx)\n", slot->ds_node_num, 957 (long long)slot->ds_last_generation, 958 (long long)le64_to_cpu(hb_block->hb_generation)); 959 } 960 961 slot->ds_last_generation = le64_to_cpu(hb_block->hb_generation); 962 963 mlog(ML_HEARTBEAT, "Slot %d gen 0x%llx cksum 0x%x " 964 "seq %llu last %llu changed %u equal %u\n", 965 slot->ds_node_num, (long long)slot->ds_last_generation, 966 le32_to_cpu(hb_block->hb_cksum), 967 (unsigned long long)le64_to_cpu(hb_block->hb_seq), 968 (unsigned long long)slot->ds_last_time, slot->ds_changed_samples, 969 slot->ds_equal_samples); 970 971 spin_lock(&o2hb_live_lock); 972 973 fire_callbacks: 974 /* dead nodes only come to life after some number of 975 * changes at any time during their dead time */ 976 if (list_empty(&slot->ds_live_item) && 977 slot->ds_changed_samples >= O2HB_LIVE_THRESHOLD) { 978 mlog(ML_HEARTBEAT, "Node %d (id 0x%llx) joined my region\n", 979 slot->ds_node_num, (long long)slot->ds_last_generation); 980 981 set_bit(slot->ds_node_num, reg->hr_live_node_bitmap); 982 983 /* first on the list generates a callback */ 984 if (list_empty(&o2hb_live_slots[slot->ds_node_num])) { 985 mlog(ML_HEARTBEAT, "o2hb: Add node %d to live nodes " 986 "bitmap\n", slot->ds_node_num); 987 set_bit(slot->ds_node_num, o2hb_live_node_bitmap); 988 989 o2hb_queue_node_event(&event, O2HB_NODE_UP_CB, node, 990 slot->ds_node_num); 991 992 changed = 1; 993 queued = 1; 994 } 995 996 list_add_tail(&slot->ds_live_item, 997 &o2hb_live_slots[slot->ds_node_num]); 998 999 slot->ds_equal_samples = 0; 1000 1001 /* We want to be sure that all nodes agree on the 1002 * number of milliseconds before a node will be 1003 * considered dead. The self-fencing timeout is 1004 * computed from this value, and a discrepancy might 1005 * result in heartbeat calling a node dead when it 1006 * hasn't self-fenced yet. */ 1007 slot_dead_ms = le32_to_cpu(hb_block->hb_dead_ms); 1008 if (slot_dead_ms && slot_dead_ms != dead_ms) { 1009 /* TODO: Perhaps we can fail the region here. */ 1010 mlog(ML_ERROR, "Node %d on device %pg has a dead count " 1011 "of %u ms, but our count is %u ms.\n" 1012 "Please double check your configuration values " 1013 "for 'O2CB_HEARTBEAT_THRESHOLD'\n", 1014 slot->ds_node_num, reg_bdev(reg), 1015 slot_dead_ms, dead_ms); 1016 } 1017 goto out; 1018 } 1019 1020 /* if the list is dead, we're done.. */ 1021 if (list_empty(&slot->ds_live_item)) 1022 goto out; 1023 1024 /* live nodes only go dead after enough consecutive missed 1025 * samples.. reset the missed counter whenever we see 1026 * activity */ 1027 if (slot->ds_equal_samples >= o2hb_dead_threshold || gen_changed) { 1028 mlog(ML_HEARTBEAT, "Node %d left my region\n", 1029 slot->ds_node_num); 1030 1031 clear_bit(slot->ds_node_num, reg->hr_live_node_bitmap); 1032 1033 /* last off the live_slot generates a callback */ 1034 list_del_init(&slot->ds_live_item); 1035 if (list_empty(&o2hb_live_slots[slot->ds_node_num])) { 1036 mlog(ML_HEARTBEAT, "o2hb: Remove node %d from live " 1037 "nodes bitmap\n", slot->ds_node_num); 1038 clear_bit(slot->ds_node_num, o2hb_live_node_bitmap); 1039 1040 /* node can be null */ 1041 o2hb_queue_node_event(&event, O2HB_NODE_DOWN_CB, 1042 node, slot->ds_node_num); 1043 1044 changed = 1; 1045 queued = 1; 1046 } 1047 1048 /* We don't clear this because the node is still 1049 * actually writing new blocks. */ 1050 if (!gen_changed) 1051 slot->ds_changed_samples = 0; 1052 goto out; 1053 } 1054 if (slot->ds_changed_samples) { 1055 slot->ds_changed_samples = 0; 1056 slot->ds_equal_samples = 0; 1057 } 1058 out: 1059 spin_unlock(&o2hb_live_lock); 1060 1061 if (queued) 1062 o2hb_run_event_list(&event); 1063 1064 if (node) 1065 o2nm_node_put(node); 1066 return changed; 1067 } 1068 1069 static int o2hb_highest_node(unsigned long *nodes, int numbits) 1070 { 1071 return find_last_bit(nodes, numbits); 1072 } 1073 1074 static int o2hb_lowest_node(unsigned long *nodes, int numbits) 1075 { 1076 return find_first_bit(nodes, numbits); 1077 } 1078 1079 static int o2hb_do_disk_heartbeat(struct o2hb_region *reg) 1080 { 1081 int i, ret, highest_node, lowest_node; 1082 int membership_change = 0, own_slot_ok = 0; 1083 unsigned long configured_nodes[BITS_TO_LONGS(O2NM_MAX_NODES)]; 1084 unsigned long live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; 1085 struct o2hb_bio_wait_ctxt write_wc; 1086 1087 ret = o2nm_configured_node_map(configured_nodes, 1088 sizeof(configured_nodes)); 1089 if (ret) { 1090 mlog_errno(ret); 1091 goto bail; 1092 } 1093 1094 /* 1095 * If a node is not configured but is in the livemap, we still need 1096 * to read the slot so as to be able to remove it from the livemap. 1097 */ 1098 o2hb_fill_node_map(live_node_bitmap, O2NM_MAX_NODES); 1099 i = -1; 1100 while ((i = find_next_bit(live_node_bitmap, 1101 O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) { 1102 set_bit(i, configured_nodes); 1103 } 1104 1105 highest_node = o2hb_highest_node(configured_nodes, O2NM_MAX_NODES); 1106 lowest_node = o2hb_lowest_node(configured_nodes, O2NM_MAX_NODES); 1107 if (highest_node >= O2NM_MAX_NODES || lowest_node >= O2NM_MAX_NODES) { 1108 mlog(ML_NOTICE, "o2hb: No configured nodes found!\n"); 1109 ret = -EINVAL; 1110 goto bail; 1111 } 1112 1113 /* No sense in reading the slots of nodes that don't exist 1114 * yet. Of course, if the node definitions have holes in them 1115 * then we're reading an empty slot anyway... Consider this 1116 * best-effort. */ 1117 ret = o2hb_read_slots(reg, lowest_node, highest_node + 1); 1118 if (ret < 0) { 1119 mlog_errno(ret); 1120 goto bail; 1121 } 1122 1123 /* With an up to date view of the slots, we can check that no 1124 * other node has been improperly configured to heartbeat in 1125 * our slot. */ 1126 own_slot_ok = o2hb_check_own_slot(reg); 1127 1128 /* fill in the proper info for our next heartbeat */ 1129 o2hb_prepare_block(reg, reg->hr_generation); 1130 1131 ret = o2hb_issue_node_write(reg, &write_wc); 1132 if (ret < 0) { 1133 mlog_errno(ret); 1134 goto bail; 1135 } 1136 1137 i = -1; 1138 while((i = find_next_bit(configured_nodes, 1139 O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) { 1140 membership_change |= o2hb_check_slot(reg, ®->hr_slots[i]); 1141 } 1142 1143 /* 1144 * We have to be sure we've advertised ourselves on disk 1145 * before we can go to steady state. This ensures that 1146 * people we find in our steady state have seen us. 1147 */ 1148 o2hb_wait_on_io(&write_wc); 1149 if (write_wc.wc_error) { 1150 /* Do not re-arm the write timeout on I/O error - we 1151 * can't be sure that the new block ever made it to 1152 * disk */ 1153 mlog(ML_ERROR, "Write error %d on device \"%pg\"\n", 1154 write_wc.wc_error, reg_bdev(reg)); 1155 ret = write_wc.wc_error; 1156 goto bail; 1157 } 1158 1159 /* Skip disarming the timeout if own slot has stale/bad data */ 1160 if (own_slot_ok) { 1161 o2hb_set_quorum_device(reg); 1162 o2hb_arm_timeout(reg); 1163 reg->hr_last_timeout_start = jiffies; 1164 } 1165 1166 bail: 1167 /* let the person who launched us know when things are steady */ 1168 if (atomic_read(®->hr_steady_iterations) != 0) { 1169 if (!ret && own_slot_ok && !membership_change) { 1170 if (atomic_dec_and_test(®->hr_steady_iterations)) 1171 wake_up(&o2hb_steady_queue); 1172 } 1173 } 1174 1175 if (atomic_read(®->hr_steady_iterations) != 0) { 1176 if (atomic_dec_and_test(®->hr_unsteady_iterations)) { 1177 printk(KERN_NOTICE "o2hb: Unable to stabilize " 1178 "heartbeat on region %s (%pg)\n", 1179 config_item_name(®->hr_item), 1180 reg_bdev(reg)); 1181 atomic_set(®->hr_steady_iterations, 0); 1182 reg->hr_aborted_start = 1; 1183 wake_up(&o2hb_steady_queue); 1184 ret = -EIO; 1185 } 1186 } 1187 1188 return ret; 1189 } 1190 1191 /* 1192 * we ride the region ref that the region dir holds. before the region 1193 * dir is removed and drops it ref it will wait to tear down this 1194 * thread. 1195 */ 1196 static int o2hb_thread(void *data) 1197 { 1198 int i, ret; 1199 struct o2hb_region *reg = data; 1200 struct o2hb_bio_wait_ctxt write_wc; 1201 ktime_t before_hb, after_hb; 1202 unsigned int elapsed_msec; 1203 1204 mlog(ML_HEARTBEAT|ML_KTHREAD, "hb thread running\n"); 1205 1206 set_user_nice(current, MIN_NICE); 1207 1208 /* Pin node */ 1209 ret = o2nm_depend_this_node(); 1210 if (ret) { 1211 mlog(ML_ERROR, "Node has been deleted, ret = %d\n", ret); 1212 reg->hr_node_deleted = 1; 1213 wake_up(&o2hb_steady_queue); 1214 return 0; 1215 } 1216 1217 while (!kthread_should_stop() && 1218 !reg->hr_unclean_stop && !reg->hr_aborted_start) { 1219 /* We track the time spent inside 1220 * o2hb_do_disk_heartbeat so that we avoid more than 1221 * hr_timeout_ms between disk writes. On busy systems 1222 * this should result in a heartbeat which is less 1223 * likely to time itself out. */ 1224 before_hb = ktime_get_real(); 1225 1226 ret = o2hb_do_disk_heartbeat(reg); 1227 reg->hr_last_hb_status = ret; 1228 1229 after_hb = ktime_get_real(); 1230 1231 elapsed_msec = (unsigned int) 1232 ktime_ms_delta(after_hb, before_hb); 1233 1234 mlog(ML_HEARTBEAT, 1235 "start = %lld, end = %lld, msec = %u, ret = %d\n", 1236 before_hb, after_hb, elapsed_msec, ret); 1237 1238 if (!kthread_should_stop() && 1239 elapsed_msec < reg->hr_timeout_ms) { 1240 /* the kthread api has blocked signals for us so no 1241 * need to record the return value. */ 1242 msleep_interruptible(reg->hr_timeout_ms - elapsed_msec); 1243 } 1244 } 1245 1246 o2hb_disarm_timeout(reg); 1247 1248 /* unclean stop is only used in very bad situation */ 1249 for(i = 0; !reg->hr_unclean_stop && i < reg->hr_blocks; i++) 1250 o2hb_shutdown_slot(®->hr_slots[i]); 1251 1252 /* Explicit down notification - avoid forcing the other nodes 1253 * to timeout on this region when we could just as easily 1254 * write a clear generation - thus indicating to them that 1255 * this node has left this region. 1256 */ 1257 if (!reg->hr_unclean_stop && !reg->hr_aborted_start) { 1258 o2hb_prepare_block(reg, 0); 1259 ret = o2hb_issue_node_write(reg, &write_wc); 1260 if (ret == 0) 1261 o2hb_wait_on_io(&write_wc); 1262 else 1263 mlog_errno(ret); 1264 } 1265 1266 /* Unpin node */ 1267 o2nm_undepend_this_node(); 1268 1269 mlog(ML_HEARTBEAT|ML_KTHREAD, "o2hb thread exiting\n"); 1270 1271 return 0; 1272 } 1273 1274 #ifdef CONFIG_DEBUG_FS 1275 static int o2hb_debug_open(struct inode *inode, struct file *file) 1276 { 1277 struct o2hb_debug_buf *db = inode->i_private; 1278 struct o2hb_region *reg; 1279 unsigned long map[BITS_TO_LONGS(O2NM_MAX_NODES)]; 1280 unsigned long lts; 1281 char *buf = NULL; 1282 int i = -1; 1283 int out = 0; 1284 1285 /* max_nodes should be the largest bitmap we pass here */ 1286 BUG_ON(sizeof(map) < db->db_size); 1287 1288 buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 1289 if (!buf) 1290 goto bail; 1291 1292 switch (db->db_type) { 1293 case O2HB_DB_TYPE_LIVENODES: 1294 case O2HB_DB_TYPE_LIVEREGIONS: 1295 case O2HB_DB_TYPE_QUORUMREGIONS: 1296 case O2HB_DB_TYPE_FAILEDREGIONS: 1297 spin_lock(&o2hb_live_lock); 1298 memcpy(map, db->db_data, db->db_size); 1299 spin_unlock(&o2hb_live_lock); 1300 break; 1301 1302 case O2HB_DB_TYPE_REGION_LIVENODES: 1303 spin_lock(&o2hb_live_lock); 1304 reg = (struct o2hb_region *)db->db_data; 1305 memcpy(map, reg->hr_live_node_bitmap, db->db_size); 1306 spin_unlock(&o2hb_live_lock); 1307 break; 1308 1309 case O2HB_DB_TYPE_REGION_NUMBER: 1310 reg = (struct o2hb_region *)db->db_data; 1311 out += scnprintf(buf + out, PAGE_SIZE - out, "%d\n", 1312 reg->hr_region_num); 1313 goto done; 1314 1315 case O2HB_DB_TYPE_REGION_ELAPSED_TIME: 1316 reg = (struct o2hb_region *)db->db_data; 1317 lts = reg->hr_last_timeout_start; 1318 /* If 0, it has never been set before */ 1319 if (lts) 1320 lts = jiffies_to_msecs(jiffies - lts); 1321 out += scnprintf(buf + out, PAGE_SIZE - out, "%lu\n", lts); 1322 goto done; 1323 1324 case O2HB_DB_TYPE_REGION_PINNED: 1325 reg = (struct o2hb_region *)db->db_data; 1326 out += scnprintf(buf + out, PAGE_SIZE - out, "%u\n", 1327 !!reg->hr_item_pinned); 1328 goto done; 1329 1330 default: 1331 goto done; 1332 } 1333 1334 while ((i = find_next_bit(map, db->db_len, i + 1)) < db->db_len) 1335 out += scnprintf(buf + out, PAGE_SIZE - out, "%d ", i); 1336 out += scnprintf(buf + out, PAGE_SIZE - out, "\n"); 1337 1338 done: 1339 i_size_write(inode, out); 1340 1341 file->private_data = buf; 1342 1343 return 0; 1344 bail: 1345 return -ENOMEM; 1346 } 1347 1348 static int o2hb_debug_release(struct inode *inode, struct file *file) 1349 { 1350 kfree(file->private_data); 1351 return 0; 1352 } 1353 1354 static ssize_t o2hb_debug_read(struct file *file, char __user *buf, 1355 size_t nbytes, loff_t *ppos) 1356 { 1357 return simple_read_from_buffer(buf, nbytes, ppos, file->private_data, 1358 i_size_read(file->f_mapping->host)); 1359 } 1360 #else 1361 static int o2hb_debug_open(struct inode *inode, struct file *file) 1362 { 1363 return 0; 1364 } 1365 static int o2hb_debug_release(struct inode *inode, struct file *file) 1366 { 1367 return 0; 1368 } 1369 static ssize_t o2hb_debug_read(struct file *file, char __user *buf, 1370 size_t nbytes, loff_t *ppos) 1371 { 1372 return 0; 1373 } 1374 #endif /* CONFIG_DEBUG_FS */ 1375 1376 static const struct file_operations o2hb_debug_fops = { 1377 .open = o2hb_debug_open, 1378 .release = o2hb_debug_release, 1379 .read = o2hb_debug_read, 1380 .llseek = generic_file_llseek, 1381 }; 1382 1383 void o2hb_exit(void) 1384 { 1385 debugfs_remove_recursive(o2hb_debug_dir); 1386 kfree(o2hb_db_livenodes); 1387 kfree(o2hb_db_liveregions); 1388 kfree(o2hb_db_quorumregions); 1389 kfree(o2hb_db_failedregions); 1390 } 1391 1392 static void o2hb_debug_create(const char *name, struct dentry *dir, 1393 struct o2hb_debug_buf **db, int db_len, int type, 1394 int size, int len, void *data) 1395 { 1396 *db = kmalloc(db_len, GFP_KERNEL); 1397 if (!*db) 1398 return; 1399 1400 (*db)->db_type = type; 1401 (*db)->db_size = size; 1402 (*db)->db_len = len; 1403 (*db)->db_data = data; 1404 1405 debugfs_create_file(name, S_IFREG|S_IRUSR, dir, *db, &o2hb_debug_fops); 1406 } 1407 1408 static void o2hb_debug_init(void) 1409 { 1410 o2hb_debug_dir = debugfs_create_dir(O2HB_DEBUG_DIR, NULL); 1411 1412 o2hb_debug_create(O2HB_DEBUG_LIVENODES, o2hb_debug_dir, 1413 &o2hb_db_livenodes, sizeof(*o2hb_db_livenodes), 1414 O2HB_DB_TYPE_LIVENODES, sizeof(o2hb_live_node_bitmap), 1415 O2NM_MAX_NODES, o2hb_live_node_bitmap); 1416 1417 o2hb_debug_create(O2HB_DEBUG_LIVEREGIONS, o2hb_debug_dir, 1418 &o2hb_db_liveregions, sizeof(*o2hb_db_liveregions), 1419 O2HB_DB_TYPE_LIVEREGIONS, 1420 sizeof(o2hb_live_region_bitmap), O2NM_MAX_REGIONS, 1421 o2hb_live_region_bitmap); 1422 1423 o2hb_debug_create(O2HB_DEBUG_QUORUMREGIONS, o2hb_debug_dir, 1424 &o2hb_db_quorumregions, 1425 sizeof(*o2hb_db_quorumregions), 1426 O2HB_DB_TYPE_QUORUMREGIONS, 1427 sizeof(o2hb_quorum_region_bitmap), O2NM_MAX_REGIONS, 1428 o2hb_quorum_region_bitmap); 1429 1430 o2hb_debug_create(O2HB_DEBUG_FAILEDREGIONS, o2hb_debug_dir, 1431 &o2hb_db_failedregions, 1432 sizeof(*o2hb_db_failedregions), 1433 O2HB_DB_TYPE_FAILEDREGIONS, 1434 sizeof(o2hb_failed_region_bitmap), O2NM_MAX_REGIONS, 1435 o2hb_failed_region_bitmap); 1436 } 1437 1438 void o2hb_init(void) 1439 { 1440 int i; 1441 1442 for (i = 0; i < ARRAY_SIZE(o2hb_callbacks); i++) 1443 INIT_LIST_HEAD(&o2hb_callbacks[i].list); 1444 1445 for (i = 0; i < ARRAY_SIZE(o2hb_live_slots); i++) 1446 INIT_LIST_HEAD(&o2hb_live_slots[i]); 1447 1448 bitmap_zero(o2hb_live_node_bitmap, O2NM_MAX_NODES); 1449 bitmap_zero(o2hb_region_bitmap, O2NM_MAX_REGIONS); 1450 bitmap_zero(o2hb_live_region_bitmap, O2NM_MAX_REGIONS); 1451 bitmap_zero(o2hb_quorum_region_bitmap, O2NM_MAX_REGIONS); 1452 bitmap_zero(o2hb_failed_region_bitmap, O2NM_MAX_REGIONS); 1453 1454 o2hb_dependent_users = 0; 1455 1456 o2hb_debug_init(); 1457 } 1458 1459 /* if we're already in a callback then we're already serialized by the sem */ 1460 static void o2hb_fill_node_map_from_callback(unsigned long *map, 1461 unsigned int bits) 1462 { 1463 bitmap_copy(map, o2hb_live_node_bitmap, bits); 1464 } 1465 1466 /* 1467 * get a map of all nodes that are heartbeating in any regions 1468 */ 1469 void o2hb_fill_node_map(unsigned long *map, unsigned int bits) 1470 { 1471 /* callers want to serialize this map and callbacks so that they 1472 * can trust that they don't miss nodes coming to the party */ 1473 down_read(&o2hb_callback_sem); 1474 spin_lock(&o2hb_live_lock); 1475 o2hb_fill_node_map_from_callback(map, bits); 1476 spin_unlock(&o2hb_live_lock); 1477 up_read(&o2hb_callback_sem); 1478 } 1479 EXPORT_SYMBOL_GPL(o2hb_fill_node_map); 1480 1481 /* 1482 * heartbeat configfs bits. The heartbeat set is a default set under 1483 * the cluster set in nodemanager.c. 1484 */ 1485 1486 static struct o2hb_region *to_o2hb_region(struct config_item *item) 1487 { 1488 return item ? container_of(item, struct o2hb_region, hr_item) : NULL; 1489 } 1490 1491 static void o2hb_unmap_slot_data(struct o2hb_region *reg) 1492 { 1493 int i; 1494 struct page *page; 1495 1496 if (reg->hr_slot_data) { 1497 for (i = 0; i < reg->hr_num_pages; i++) { 1498 page = reg->hr_slot_data[i]; 1499 if (page) { 1500 __free_page(page); 1501 reg->hr_slot_data[i] = NULL; 1502 } 1503 } 1504 kfree(reg->hr_slot_data); 1505 reg->hr_slot_data = NULL; 1506 } 1507 1508 kfree(reg->hr_slots); 1509 reg->hr_slots = NULL; 1510 1511 kfree(reg->hr_tmp_block); 1512 reg->hr_tmp_block = NULL; 1513 } 1514 1515 /* drop_item only drops its ref after killing the thread, nothing should 1516 * be using the region anymore. this has to clean up any state that 1517 * attributes might have built up. 1518 */ 1519 static void o2hb_region_release(struct config_item *item) 1520 { 1521 struct o2hb_region *reg = to_o2hb_region(item); 1522 1523 mlog(ML_HEARTBEAT, "hb region release (%pg)\n", reg_bdev(reg)); 1524 1525 o2hb_unmap_slot_data(reg); 1526 1527 if (reg->hr_bdev_file) 1528 fput(reg->hr_bdev_file); 1529 1530 debugfs_remove_recursive(reg->hr_debug_dir); 1531 kfree(reg->hr_db_livenodes); 1532 kfree(reg->hr_db_regnum); 1533 kfree(reg->hr_db_elapsed_time); 1534 kfree(reg->hr_db_pinned); 1535 1536 spin_lock(&o2hb_live_lock); 1537 list_del(®->hr_all_item); 1538 spin_unlock(&o2hb_live_lock); 1539 1540 o2net_unregister_handler_list(®->hr_handler_list); 1541 kfree(reg); 1542 } 1543 1544 static int o2hb_read_block_input(struct o2hb_region *reg, 1545 const char *page, 1546 unsigned long *ret_bytes, 1547 unsigned int *ret_bits) 1548 { 1549 unsigned long bytes; 1550 char *p = (char *)page; 1551 int ret; 1552 1553 ret = kstrtoul(p, 0, &bytes); 1554 if (ret) 1555 return ret; 1556 1557 /* Heartbeat and fs min / max block sizes are the same. */ 1558 if (bytes > 4096 || bytes < 512) 1559 return -ERANGE; 1560 if (hweight16(bytes) != 1) 1561 return -EINVAL; 1562 1563 if (ret_bytes) 1564 *ret_bytes = bytes; 1565 if (ret_bits) 1566 *ret_bits = ffs(bytes) - 1; 1567 1568 return 0; 1569 } 1570 1571 static ssize_t o2hb_region_block_bytes_show(struct config_item *item, 1572 char *page) 1573 { 1574 return sprintf(page, "%u\n", to_o2hb_region(item)->hr_block_bytes); 1575 } 1576 1577 static ssize_t o2hb_region_block_bytes_store(struct config_item *item, 1578 const char *page, 1579 size_t count) 1580 { 1581 struct o2hb_region *reg = to_o2hb_region(item); 1582 int status; 1583 unsigned long block_bytes; 1584 unsigned int block_bits; 1585 1586 if (reg->hr_bdev_file) 1587 return -EINVAL; 1588 1589 status = o2hb_read_block_input(reg, page, &block_bytes, 1590 &block_bits); 1591 if (status) 1592 return status; 1593 1594 reg->hr_block_bytes = (unsigned int)block_bytes; 1595 reg->hr_block_bits = block_bits; 1596 1597 return count; 1598 } 1599 1600 static ssize_t o2hb_region_start_block_show(struct config_item *item, 1601 char *page) 1602 { 1603 return sprintf(page, "%llu\n", to_o2hb_region(item)->hr_start_block); 1604 } 1605 1606 static ssize_t o2hb_region_start_block_store(struct config_item *item, 1607 const char *page, 1608 size_t count) 1609 { 1610 struct o2hb_region *reg = to_o2hb_region(item); 1611 unsigned long long tmp; 1612 char *p = (char *)page; 1613 ssize_t ret; 1614 1615 if (reg->hr_bdev_file) 1616 return -EINVAL; 1617 1618 ret = kstrtoull(p, 0, &tmp); 1619 if (ret) 1620 return -EINVAL; 1621 1622 reg->hr_start_block = tmp; 1623 1624 return count; 1625 } 1626 1627 static ssize_t o2hb_region_blocks_show(struct config_item *item, char *page) 1628 { 1629 return sprintf(page, "%d\n", to_o2hb_region(item)->hr_blocks); 1630 } 1631 1632 static ssize_t o2hb_region_blocks_store(struct config_item *item, 1633 const char *page, 1634 size_t count) 1635 { 1636 struct o2hb_region *reg = to_o2hb_region(item); 1637 unsigned long tmp; 1638 char *p = (char *)page; 1639 int ret; 1640 1641 if (reg->hr_bdev_file) 1642 return -EINVAL; 1643 1644 ret = kstrtoul(p, 0, &tmp); 1645 if (ret) 1646 return ret; 1647 1648 if (tmp > O2NM_MAX_NODES || tmp == 0) 1649 return -ERANGE; 1650 1651 reg->hr_blocks = (unsigned int)tmp; 1652 1653 return count; 1654 } 1655 1656 static ssize_t o2hb_region_dev_show(struct config_item *item, char *page) 1657 { 1658 unsigned int ret = 0; 1659 1660 if (to_o2hb_region(item)->hr_bdev_file) 1661 ret = sprintf(page, "%pg\n", reg_bdev(to_o2hb_region(item))); 1662 1663 return ret; 1664 } 1665 1666 static void o2hb_init_region_params(struct o2hb_region *reg) 1667 { 1668 reg->hr_slots_per_page = PAGE_SIZE >> reg->hr_block_bits; 1669 reg->hr_timeout_ms = O2HB_REGION_TIMEOUT_MS; 1670 1671 mlog(ML_HEARTBEAT, "hr_start_block = %llu, hr_blocks = %u\n", 1672 reg->hr_start_block, reg->hr_blocks); 1673 mlog(ML_HEARTBEAT, "hr_block_bytes = %u, hr_block_bits = %u\n", 1674 reg->hr_block_bytes, reg->hr_block_bits); 1675 mlog(ML_HEARTBEAT, "hr_timeout_ms = %u\n", reg->hr_timeout_ms); 1676 mlog(ML_HEARTBEAT, "dead threshold = %u\n", o2hb_dead_threshold); 1677 } 1678 1679 static int o2hb_map_slot_data(struct o2hb_region *reg) 1680 { 1681 int i, j; 1682 int ret = -ENOMEM; 1683 unsigned int last_slot; 1684 unsigned int spp = reg->hr_slots_per_page; 1685 struct page *page; 1686 char *raw; 1687 struct o2hb_disk_slot *slot; 1688 1689 reg->hr_tmp_block = kmalloc(reg->hr_block_bytes, GFP_KERNEL); 1690 if (!reg->hr_tmp_block) 1691 goto out; 1692 1693 reg->hr_slots = kzalloc_objs(struct o2hb_disk_slot, reg->hr_blocks); 1694 if (!reg->hr_slots) 1695 goto out; 1696 1697 for (i = 0; i < reg->hr_blocks; i++) { 1698 slot = ®->hr_slots[i]; 1699 slot->ds_node_num = i; 1700 INIT_LIST_HEAD(&slot->ds_live_item); 1701 slot->ds_raw_block = NULL; 1702 } 1703 1704 reg->hr_num_pages = (reg->hr_blocks + spp - 1) / spp; 1705 mlog(ML_HEARTBEAT, "Going to require %u pages to cover %u blocks " 1706 "at %u blocks per page\n", 1707 reg->hr_num_pages, reg->hr_blocks, spp); 1708 1709 reg->hr_slot_data = kzalloc_objs(struct page *, reg->hr_num_pages); 1710 if (!reg->hr_slot_data) 1711 goto out; 1712 1713 for (i = 0; i < reg->hr_num_pages; i++) { 1714 page = alloc_page(GFP_KERNEL); 1715 if (!page) 1716 goto out; 1717 1718 reg->hr_slot_data[i] = page; 1719 1720 last_slot = i * spp; 1721 raw = page_address(page); 1722 for (j = 0; 1723 (j < spp) && ((j + last_slot) < reg->hr_blocks); 1724 j++) { 1725 BUG_ON((j + last_slot) >= reg->hr_blocks); 1726 1727 slot = ®->hr_slots[j + last_slot]; 1728 slot->ds_raw_block = 1729 (struct o2hb_disk_heartbeat_block *) raw; 1730 1731 raw += reg->hr_block_bytes; 1732 } 1733 } 1734 1735 return 0; 1736 1737 out: 1738 o2hb_unmap_slot_data(reg); 1739 return ret; 1740 } 1741 1742 /* Read in all the slots available and populate the tracking 1743 * structures so that we can start with a baseline idea of what's 1744 * there. */ 1745 static int o2hb_populate_slot_data(struct o2hb_region *reg) 1746 { 1747 int ret, i; 1748 struct o2hb_disk_slot *slot; 1749 struct o2hb_disk_heartbeat_block *hb_block; 1750 1751 ret = o2hb_read_slots(reg, 0, reg->hr_blocks); 1752 if (ret) 1753 goto out; 1754 1755 /* We only want to get an idea of the values initially in each 1756 * slot, so we do no verification - o2hb_check_slot will 1757 * actually determine if each configured slot is valid and 1758 * whether any values have changed. */ 1759 for(i = 0; i < reg->hr_blocks; i++) { 1760 slot = ®->hr_slots[i]; 1761 hb_block = (struct o2hb_disk_heartbeat_block *) slot->ds_raw_block; 1762 1763 /* Only fill the values that o2hb_check_slot uses to 1764 * determine changing slots */ 1765 slot->ds_last_time = le64_to_cpu(hb_block->hb_seq); 1766 slot->ds_last_generation = le64_to_cpu(hb_block->hb_generation); 1767 } 1768 1769 out: 1770 return ret; 1771 } 1772 1773 /* 1774 * this is acting as commit; we set up all of hr_bdev_file and hr_task or 1775 * nothing 1776 */ 1777 static ssize_t o2hb_region_dev_store(struct config_item *item, 1778 const char *page, 1779 size_t count) 1780 { 1781 struct o2hb_region *reg = to_o2hb_region(item); 1782 struct task_struct *hb_task; 1783 long fd; 1784 int sectsize; 1785 char *p = (char *)page; 1786 ssize_t ret = -EINVAL; 1787 int live_threshold; 1788 1789 if (reg->hr_bdev_file) 1790 return -EINVAL; 1791 1792 /* We can't heartbeat without having had our node number 1793 * configured yet. */ 1794 if (o2nm_this_node() == O2NM_MAX_NODES) 1795 return -EINVAL; 1796 1797 ret = kstrtol(p, 0, &fd); 1798 if (ret < 0) 1799 return -EINVAL; 1800 1801 if (fd < 0 || fd >= INT_MAX) 1802 return -EINVAL; 1803 1804 CLASS(fd, f)(fd); 1805 if (fd_empty(f)) 1806 return -EINVAL; 1807 1808 if (reg->hr_blocks == 0 || reg->hr_start_block == 0 || 1809 reg->hr_block_bytes == 0) 1810 return -EINVAL; 1811 1812 if (!S_ISBLK(fd_file(f)->f_mapping->host->i_mode)) 1813 return -EINVAL; 1814 1815 reg->hr_bdev_file = bdev_file_open_by_dev(fd_file(f)->f_mapping->host->i_rdev, 1816 BLK_OPEN_WRITE | BLK_OPEN_READ, NULL, NULL); 1817 if (IS_ERR(reg->hr_bdev_file)) { 1818 ret = PTR_ERR(reg->hr_bdev_file); 1819 reg->hr_bdev_file = NULL; 1820 return ret; 1821 } 1822 1823 sectsize = bdev_logical_block_size(reg_bdev(reg)); 1824 if (sectsize != reg->hr_block_bytes) { 1825 mlog(ML_ERROR, 1826 "blocksize %u incorrect for device, expected %d", 1827 reg->hr_block_bytes, sectsize); 1828 ret = -EINVAL; 1829 goto out; 1830 } 1831 1832 reg->hr_aborted_start = 0; 1833 reg->hr_node_deleted = 0; 1834 o2hb_init_region_params(reg); 1835 1836 /* Generation of zero is invalid */ 1837 do { 1838 get_random_bytes(®->hr_generation, 1839 sizeof(reg->hr_generation)); 1840 } while (reg->hr_generation == 0); 1841 1842 ret = o2hb_map_slot_data(reg); 1843 if (ret) { 1844 mlog_errno(ret); 1845 goto out; 1846 } 1847 1848 ret = o2hb_populate_slot_data(reg); 1849 if (ret) { 1850 mlog_errno(ret); 1851 goto out; 1852 } 1853 1854 INIT_DELAYED_WORK(®->hr_write_timeout_work, o2hb_write_timeout); 1855 INIT_DELAYED_WORK(®->hr_nego_timeout_work, o2hb_nego_timeout); 1856 1857 /* 1858 * A node is considered live after it has beat LIVE_THRESHOLD 1859 * times. We're not steady until we've given them a chance 1860 * _after_ our first read. 1861 * The default threshold is bare minimum so as to limit the delay 1862 * during mounts. For global heartbeat, the threshold doubled for the 1863 * first region. 1864 */ 1865 live_threshold = O2HB_LIVE_THRESHOLD; 1866 if (o2hb_global_heartbeat_active()) { 1867 spin_lock(&o2hb_live_lock); 1868 if (bitmap_weight(o2hb_region_bitmap, O2NM_MAX_REGIONS) == 1) 1869 live_threshold <<= 1; 1870 spin_unlock(&o2hb_live_lock); 1871 } 1872 ++live_threshold; 1873 atomic_set(®->hr_steady_iterations, live_threshold); 1874 /* unsteady_iterations is triple the steady_iterations */ 1875 atomic_set(®->hr_unsteady_iterations, (live_threshold * 3)); 1876 1877 hb_task = kthread_run(o2hb_thread, reg, "o2hb-%s", 1878 reg->hr_item.ci_name); 1879 if (IS_ERR(hb_task)) { 1880 ret = PTR_ERR(hb_task); 1881 mlog_errno(ret); 1882 goto out; 1883 } 1884 1885 spin_lock(&o2hb_live_lock); 1886 reg->hr_task = hb_task; 1887 spin_unlock(&o2hb_live_lock); 1888 1889 ret = wait_event_interruptible(o2hb_steady_queue, 1890 atomic_read(®->hr_steady_iterations) == 0 || 1891 reg->hr_node_deleted); 1892 if (ret) { 1893 atomic_set(®->hr_steady_iterations, 0); 1894 reg->hr_aborted_start = 1; 1895 } 1896 1897 if (reg->hr_aborted_start) { 1898 ret = -EIO; 1899 goto out; 1900 } 1901 1902 if (reg->hr_node_deleted) { 1903 ret = -EINVAL; 1904 goto out; 1905 } 1906 1907 /* Ok, we were woken. Make sure it wasn't by drop_item() */ 1908 spin_lock(&o2hb_live_lock); 1909 hb_task = reg->hr_task; 1910 if (o2hb_global_heartbeat_active()) 1911 set_bit(reg->hr_region_num, o2hb_live_region_bitmap); 1912 spin_unlock(&o2hb_live_lock); 1913 1914 if (hb_task) 1915 ret = count; 1916 else 1917 ret = -EIO; 1918 1919 if (hb_task && o2hb_global_heartbeat_active()) 1920 printk(KERN_NOTICE "o2hb: Heartbeat started on region %s (%pg)\n", 1921 config_item_name(®->hr_item), reg_bdev(reg)); 1922 1923 out: 1924 if (ret < 0) { 1925 spin_lock(&o2hb_live_lock); 1926 hb_task = reg->hr_task; 1927 reg->hr_task = NULL; 1928 spin_unlock(&o2hb_live_lock); 1929 1930 if (hb_task) 1931 kthread_stop(hb_task); 1932 1933 o2hb_unmap_slot_data(reg); 1934 1935 fput(reg->hr_bdev_file); 1936 reg->hr_bdev_file = NULL; 1937 } 1938 return ret; 1939 } 1940 1941 static ssize_t o2hb_region_pid_show(struct config_item *item, char *page) 1942 { 1943 struct o2hb_region *reg = to_o2hb_region(item); 1944 pid_t pid = 0; 1945 1946 spin_lock(&o2hb_live_lock); 1947 if (reg->hr_task) 1948 pid = task_pid_nr(reg->hr_task); 1949 spin_unlock(&o2hb_live_lock); 1950 1951 if (!pid) 1952 return 0; 1953 1954 return sprintf(page, "%u\n", pid); 1955 } 1956 1957 CONFIGFS_ATTR(o2hb_region_, block_bytes); 1958 CONFIGFS_ATTR(o2hb_region_, start_block); 1959 CONFIGFS_ATTR(o2hb_region_, blocks); 1960 CONFIGFS_ATTR(o2hb_region_, dev); 1961 CONFIGFS_ATTR_RO(o2hb_region_, pid); 1962 1963 static struct configfs_attribute *o2hb_region_attrs[] = { 1964 &o2hb_region_attr_block_bytes, 1965 &o2hb_region_attr_start_block, 1966 &o2hb_region_attr_blocks, 1967 &o2hb_region_attr_dev, 1968 &o2hb_region_attr_pid, 1969 NULL, 1970 }; 1971 1972 static const struct configfs_item_operations o2hb_region_item_ops = { 1973 .release = o2hb_region_release, 1974 }; 1975 1976 static const struct config_item_type o2hb_region_type = { 1977 .ct_item_ops = &o2hb_region_item_ops, 1978 .ct_attrs = o2hb_region_attrs, 1979 .ct_owner = THIS_MODULE, 1980 }; 1981 1982 /* heartbeat set */ 1983 1984 struct o2hb_heartbeat_group { 1985 struct config_group hs_group; 1986 /* some stuff? */ 1987 }; 1988 1989 static struct o2hb_heartbeat_group *to_o2hb_heartbeat_group(struct config_group *group) 1990 { 1991 return group ? 1992 container_of(group, struct o2hb_heartbeat_group, hs_group) 1993 : NULL; 1994 } 1995 1996 static void o2hb_debug_region_init(struct o2hb_region *reg, 1997 struct dentry *parent) 1998 { 1999 struct dentry *dir; 2000 2001 dir = debugfs_create_dir(config_item_name(®->hr_item), parent); 2002 reg->hr_debug_dir = dir; 2003 2004 o2hb_debug_create(O2HB_DEBUG_LIVENODES, dir, &(reg->hr_db_livenodes), 2005 sizeof(*(reg->hr_db_livenodes)), 2006 O2HB_DB_TYPE_REGION_LIVENODES, 2007 sizeof(reg->hr_live_node_bitmap), O2NM_MAX_NODES, 2008 reg); 2009 2010 o2hb_debug_create(O2HB_DEBUG_REGION_NUMBER, dir, &(reg->hr_db_regnum), 2011 sizeof(*(reg->hr_db_regnum)), 2012 O2HB_DB_TYPE_REGION_NUMBER, 0, O2NM_MAX_NODES, reg); 2013 2014 o2hb_debug_create(O2HB_DEBUG_REGION_ELAPSED_TIME, dir, 2015 &(reg->hr_db_elapsed_time), 2016 sizeof(*(reg->hr_db_elapsed_time)), 2017 O2HB_DB_TYPE_REGION_ELAPSED_TIME, 0, 0, reg); 2018 2019 o2hb_debug_create(O2HB_DEBUG_REGION_PINNED, dir, &(reg->hr_db_pinned), 2020 sizeof(*(reg->hr_db_pinned)), 2021 O2HB_DB_TYPE_REGION_PINNED, 0, 0, reg); 2022 2023 } 2024 2025 static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *group, 2026 const char *name) 2027 { 2028 struct o2hb_region *reg = NULL; 2029 int ret; 2030 2031 reg = kzalloc_obj(struct o2hb_region); 2032 if (reg == NULL) 2033 return ERR_PTR(-ENOMEM); 2034 2035 if (strlen(name) > O2HB_MAX_REGION_NAME_LEN) { 2036 ret = -ENAMETOOLONG; 2037 goto free; 2038 } 2039 2040 spin_lock(&o2hb_live_lock); 2041 reg->hr_region_num = 0; 2042 if (o2hb_global_heartbeat_active()) { 2043 reg->hr_region_num = find_first_zero_bit(o2hb_region_bitmap, 2044 O2NM_MAX_REGIONS); 2045 if (reg->hr_region_num >= O2NM_MAX_REGIONS) { 2046 spin_unlock(&o2hb_live_lock); 2047 ret = -EFBIG; 2048 goto free; 2049 } 2050 set_bit(reg->hr_region_num, o2hb_region_bitmap); 2051 } 2052 list_add_tail(®->hr_all_item, &o2hb_all_regions); 2053 spin_unlock(&o2hb_live_lock); 2054 2055 config_item_init_type_name(®->hr_item, name, &o2hb_region_type); 2056 2057 /* this is the same way to generate msg key as dlm, for local heartbeat, 2058 * name is also the same, so make initial crc value different to avoid 2059 * message key conflict. 2060 */ 2061 reg->hr_key = crc32_le(reg->hr_region_num + O2NM_MAX_REGIONS, 2062 name, strlen(name)); 2063 INIT_LIST_HEAD(®->hr_handler_list); 2064 ret = o2net_register_handler(O2HB_NEGO_TIMEOUT_MSG, reg->hr_key, 2065 sizeof(struct o2hb_nego_msg), 2066 o2hb_nego_timeout_handler, 2067 reg, NULL, ®->hr_handler_list); 2068 if (ret) 2069 goto remove_item; 2070 2071 ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key, 2072 sizeof(struct o2hb_nego_msg), 2073 o2hb_nego_approve_handler, 2074 reg, NULL, ®->hr_handler_list); 2075 if (ret) 2076 goto unregister_handler; 2077 2078 o2hb_debug_region_init(reg, o2hb_debug_dir); 2079 2080 return ®->hr_item; 2081 2082 unregister_handler: 2083 o2net_unregister_handler_list(®->hr_handler_list); 2084 remove_item: 2085 spin_lock(&o2hb_live_lock); 2086 list_del(®->hr_all_item); 2087 if (o2hb_global_heartbeat_active()) 2088 clear_bit(reg->hr_region_num, o2hb_region_bitmap); 2089 spin_unlock(&o2hb_live_lock); 2090 free: 2091 kfree(reg); 2092 return ERR_PTR(ret); 2093 } 2094 2095 static void o2hb_heartbeat_group_drop_item(struct config_group *group, 2096 struct config_item *item) 2097 { 2098 struct task_struct *hb_task; 2099 struct o2hb_region *reg = to_o2hb_region(item); 2100 int quorum_region = 0; 2101 2102 /* stop the thread when the user removes the region dir */ 2103 spin_lock(&o2hb_live_lock); 2104 hb_task = reg->hr_task; 2105 reg->hr_task = NULL; 2106 reg->hr_item_dropped = 1; 2107 spin_unlock(&o2hb_live_lock); 2108 2109 if (hb_task) 2110 kthread_stop(hb_task); 2111 2112 if (o2hb_global_heartbeat_active()) { 2113 spin_lock(&o2hb_live_lock); 2114 clear_bit(reg->hr_region_num, o2hb_region_bitmap); 2115 clear_bit(reg->hr_region_num, o2hb_live_region_bitmap); 2116 if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap)) 2117 quorum_region = 1; 2118 clear_bit(reg->hr_region_num, o2hb_quorum_region_bitmap); 2119 spin_unlock(&o2hb_live_lock); 2120 printk(KERN_NOTICE "o2hb: Heartbeat %s on region %s (%pg)\n", 2121 ((atomic_read(®->hr_steady_iterations) == 0) ? 2122 "stopped" : "start aborted"), config_item_name(item), 2123 reg_bdev(reg)); 2124 } 2125 2126 /* 2127 * If we're racing a dev_write(), we need to wake them. They will 2128 * check reg->hr_task 2129 */ 2130 if (atomic_read(®->hr_steady_iterations) != 0) { 2131 reg->hr_aborted_start = 1; 2132 atomic_set(®->hr_steady_iterations, 0); 2133 wake_up(&o2hb_steady_queue); 2134 } 2135 2136 config_item_put(item); 2137 2138 if (!o2hb_global_heartbeat_active() || !quorum_region) 2139 return; 2140 2141 /* 2142 * If global heartbeat active and there are dependent users, 2143 * pin all regions if quorum region count <= CUT_OFF 2144 */ 2145 spin_lock(&o2hb_live_lock); 2146 2147 if (!o2hb_dependent_users) 2148 goto unlock; 2149 2150 if (bitmap_weight(o2hb_quorum_region_bitmap, 2151 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF) 2152 o2hb_region_pin(NULL); 2153 2154 unlock: 2155 spin_unlock(&o2hb_live_lock); 2156 } 2157 2158 static ssize_t o2hb_heartbeat_group_dead_threshold_show(struct config_item *item, 2159 char *page) 2160 { 2161 return sprintf(page, "%u\n", o2hb_dead_threshold); 2162 } 2163 2164 static ssize_t o2hb_heartbeat_group_dead_threshold_store(struct config_item *item, 2165 const char *page, size_t count) 2166 { 2167 unsigned long tmp; 2168 char *p = (char *)page; 2169 int ret; 2170 2171 ret = kstrtoul(p, 10, &tmp); 2172 if (ret) 2173 return ret; 2174 2175 /* this will validate ranges for us. */ 2176 o2hb_dead_threshold_set((unsigned int) tmp); 2177 2178 return count; 2179 } 2180 2181 static ssize_t o2hb_heartbeat_group_mode_show(struct config_item *item, 2182 char *page) 2183 { 2184 return sprintf(page, "%s\n", 2185 o2hb_heartbeat_mode_desc[o2hb_heartbeat_mode]); 2186 } 2187 2188 static ssize_t o2hb_heartbeat_group_mode_store(struct config_item *item, 2189 const char *page, size_t count) 2190 { 2191 unsigned int i; 2192 int ret; 2193 size_t len; 2194 2195 len = (page[count - 1] == '\n') ? count - 1 : count; 2196 if (!len) 2197 return -EINVAL; 2198 2199 for (i = 0; i < O2HB_HEARTBEAT_NUM_MODES; ++i) { 2200 if (strncasecmp(page, o2hb_heartbeat_mode_desc[i], len)) 2201 continue; 2202 2203 ret = o2hb_global_heartbeat_mode_set(i); 2204 if (!ret) 2205 printk(KERN_NOTICE "o2hb: Heartbeat mode set to %s\n", 2206 o2hb_heartbeat_mode_desc[i]); 2207 return count; 2208 } 2209 2210 return -EINVAL; 2211 2212 } 2213 2214 CONFIGFS_ATTR(o2hb_heartbeat_group_, dead_threshold); 2215 CONFIGFS_ATTR(o2hb_heartbeat_group_, mode); 2216 2217 static struct configfs_attribute *o2hb_heartbeat_group_attrs[] = { 2218 &o2hb_heartbeat_group_attr_dead_threshold, 2219 &o2hb_heartbeat_group_attr_mode, 2220 NULL, 2221 }; 2222 2223 static const struct configfs_group_operations o2hb_heartbeat_group_group_ops = { 2224 .make_item = o2hb_heartbeat_group_make_item, 2225 .drop_item = o2hb_heartbeat_group_drop_item, 2226 }; 2227 2228 static const struct config_item_type o2hb_heartbeat_group_type = { 2229 .ct_group_ops = &o2hb_heartbeat_group_group_ops, 2230 .ct_attrs = o2hb_heartbeat_group_attrs, 2231 .ct_owner = THIS_MODULE, 2232 }; 2233 2234 /* this is just here to avoid touching group in heartbeat.h which the 2235 * entire damn world #includes */ 2236 struct config_group *o2hb_alloc_hb_set(void) 2237 { 2238 struct o2hb_heartbeat_group *hs = NULL; 2239 struct config_group *ret = NULL; 2240 2241 hs = kzalloc_obj(struct o2hb_heartbeat_group); 2242 if (hs == NULL) 2243 goto out; 2244 2245 config_group_init_type_name(&hs->hs_group, "heartbeat", 2246 &o2hb_heartbeat_group_type); 2247 2248 ret = &hs->hs_group; 2249 out: 2250 if (ret == NULL) 2251 kfree(hs); 2252 return ret; 2253 } 2254 2255 void o2hb_free_hb_set(struct config_group *group) 2256 { 2257 struct o2hb_heartbeat_group *hs = to_o2hb_heartbeat_group(group); 2258 kfree(hs); 2259 } 2260 2261 /* hb callback registration and issuing */ 2262 2263 static struct o2hb_callback *hbcall_from_type(enum o2hb_callback_type type) 2264 { 2265 if (type == O2HB_NUM_CB) 2266 return ERR_PTR(-EINVAL); 2267 2268 return &o2hb_callbacks[type]; 2269 } 2270 2271 void o2hb_setup_callback(struct o2hb_callback_func *hc, 2272 enum o2hb_callback_type type, 2273 o2hb_cb_func *func, 2274 void *data, 2275 int priority) 2276 { 2277 INIT_LIST_HEAD(&hc->hc_item); 2278 hc->hc_func = func; 2279 hc->hc_data = data; 2280 hc->hc_priority = priority; 2281 hc->hc_type = type; 2282 hc->hc_magic = O2HB_CB_MAGIC; 2283 } 2284 EXPORT_SYMBOL_GPL(o2hb_setup_callback); 2285 2286 /* 2287 * In local heartbeat mode, region_uuid passed matches the dlm domain name. 2288 * In global heartbeat mode, region_uuid passed is NULL. 2289 * 2290 * In local, we only pin the matching region. In global we pin all the active 2291 * regions. 2292 */ 2293 static int o2hb_region_pin(const char *region_uuid) 2294 { 2295 int ret = 0, found = 0; 2296 struct o2hb_region *reg; 2297 char *uuid; 2298 2299 assert_spin_locked(&o2hb_live_lock); 2300 2301 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) { 2302 if (reg->hr_item_dropped) 2303 continue; 2304 2305 uuid = config_item_name(®->hr_item); 2306 2307 /* local heartbeat */ 2308 if (region_uuid) { 2309 if (strcmp(region_uuid, uuid)) 2310 continue; 2311 found = 1; 2312 } 2313 2314 if (reg->hr_item_pinned || reg->hr_item_dropped) 2315 goto skip_pin; 2316 2317 /* Ignore ENOENT only for local hb (userdlm domain) */ 2318 ret = o2nm_depend_item(®->hr_item); 2319 if (!ret) { 2320 mlog(ML_CLUSTER, "Pin region %s\n", uuid); 2321 reg->hr_item_pinned = 1; 2322 } else { 2323 if (ret == -ENOENT && found) 2324 ret = 0; 2325 else { 2326 mlog(ML_ERROR, "Pin region %s fails with %d\n", 2327 uuid, ret); 2328 break; 2329 } 2330 } 2331 skip_pin: 2332 if (found) 2333 break; 2334 } 2335 2336 return ret; 2337 } 2338 2339 /* 2340 * In local heartbeat mode, region_uuid passed matches the dlm domain name. 2341 * In global heartbeat mode, region_uuid passed is NULL. 2342 * 2343 * In local, we only unpin the matching region. In global we unpin all the 2344 * active regions. 2345 */ 2346 static void o2hb_region_unpin(const char *region_uuid) 2347 { 2348 struct o2hb_region *reg; 2349 char *uuid; 2350 int found = 0; 2351 2352 assert_spin_locked(&o2hb_live_lock); 2353 2354 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) { 2355 if (reg->hr_item_dropped) 2356 continue; 2357 2358 uuid = config_item_name(®->hr_item); 2359 if (region_uuid) { 2360 if (strcmp(region_uuid, uuid)) 2361 continue; 2362 found = 1; 2363 } 2364 2365 if (reg->hr_item_pinned) { 2366 mlog(ML_CLUSTER, "Unpin region %s\n", uuid); 2367 o2nm_undepend_item(®->hr_item); 2368 reg->hr_item_pinned = 0; 2369 } 2370 if (found) 2371 break; 2372 } 2373 } 2374 2375 static int o2hb_region_inc_user(const char *region_uuid) 2376 { 2377 int ret = 0; 2378 2379 spin_lock(&o2hb_live_lock); 2380 2381 /* local heartbeat */ 2382 if (!o2hb_global_heartbeat_active()) { 2383 ret = o2hb_region_pin(region_uuid); 2384 goto unlock; 2385 } 2386 2387 /* 2388 * if global heartbeat active and this is the first dependent user, 2389 * pin all regions if quorum region count <= CUT_OFF 2390 */ 2391 o2hb_dependent_users++; 2392 if (o2hb_dependent_users > 1) 2393 goto unlock; 2394 2395 if (bitmap_weight(o2hb_quorum_region_bitmap, 2396 O2NM_MAX_REGIONS) <= O2HB_PIN_CUT_OFF) 2397 ret = o2hb_region_pin(NULL); 2398 2399 unlock: 2400 spin_unlock(&o2hb_live_lock); 2401 return ret; 2402 } 2403 2404 static void o2hb_region_dec_user(const char *region_uuid) 2405 { 2406 spin_lock(&o2hb_live_lock); 2407 2408 /* local heartbeat */ 2409 if (!o2hb_global_heartbeat_active()) { 2410 o2hb_region_unpin(region_uuid); 2411 goto unlock; 2412 } 2413 2414 /* 2415 * if global heartbeat active and there are no dependent users, 2416 * unpin all quorum regions 2417 */ 2418 o2hb_dependent_users--; 2419 if (!o2hb_dependent_users) 2420 o2hb_region_unpin(NULL); 2421 2422 unlock: 2423 spin_unlock(&o2hb_live_lock); 2424 } 2425 2426 int o2hb_register_callback(const char *region_uuid, 2427 struct o2hb_callback_func *hc) 2428 { 2429 struct o2hb_callback_func *f; 2430 struct o2hb_callback *hbcall; 2431 int ret; 2432 2433 BUG_ON(hc->hc_magic != O2HB_CB_MAGIC); 2434 BUG_ON(!list_empty(&hc->hc_item)); 2435 2436 hbcall = hbcall_from_type(hc->hc_type); 2437 if (IS_ERR(hbcall)) { 2438 ret = PTR_ERR(hbcall); 2439 goto out; 2440 } 2441 2442 if (region_uuid) { 2443 ret = o2hb_region_inc_user(region_uuid); 2444 if (ret) { 2445 mlog_errno(ret); 2446 goto out; 2447 } 2448 } 2449 2450 down_write(&o2hb_callback_sem); 2451 2452 list_for_each_entry(f, &hbcall->list, hc_item) { 2453 if (hc->hc_priority < f->hc_priority) { 2454 list_add_tail(&hc->hc_item, &f->hc_item); 2455 break; 2456 } 2457 } 2458 if (list_empty(&hc->hc_item)) 2459 list_add_tail(&hc->hc_item, &hbcall->list); 2460 2461 up_write(&o2hb_callback_sem); 2462 ret = 0; 2463 out: 2464 mlog(ML_CLUSTER, "returning %d on behalf of %p for funcs %p\n", 2465 ret, __builtin_return_address(0), hc); 2466 return ret; 2467 } 2468 EXPORT_SYMBOL_GPL(o2hb_register_callback); 2469 2470 void o2hb_unregister_callback(const char *region_uuid, 2471 struct o2hb_callback_func *hc) 2472 { 2473 BUG_ON(hc->hc_magic != O2HB_CB_MAGIC); 2474 2475 mlog(ML_CLUSTER, "on behalf of %p for funcs %p\n", 2476 __builtin_return_address(0), hc); 2477 2478 /* XXX Can this happen _with_ a region reference? */ 2479 if (list_empty(&hc->hc_item)) 2480 return; 2481 2482 if (region_uuid) 2483 o2hb_region_dec_user(region_uuid); 2484 2485 down_write(&o2hb_callback_sem); 2486 2487 list_del_init(&hc->hc_item); 2488 2489 up_write(&o2hb_callback_sem); 2490 } 2491 EXPORT_SYMBOL_GPL(o2hb_unregister_callback); 2492 2493 int o2hb_check_node_heartbeating_no_sem(u8 node_num) 2494 { 2495 unsigned long testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; 2496 2497 spin_lock(&o2hb_live_lock); 2498 o2hb_fill_node_map_from_callback(testing_map, O2NM_MAX_NODES); 2499 spin_unlock(&o2hb_live_lock); 2500 if (!test_bit(node_num, testing_map)) { 2501 mlog(ML_HEARTBEAT, 2502 "node (%u) does not have heartbeating enabled.\n", 2503 node_num); 2504 return 0; 2505 } 2506 2507 return 1; 2508 } 2509 EXPORT_SYMBOL_GPL(o2hb_check_node_heartbeating_no_sem); 2510 2511 int o2hb_check_node_heartbeating_from_callback(u8 node_num) 2512 { 2513 unsigned long testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; 2514 2515 o2hb_fill_node_map_from_callback(testing_map, O2NM_MAX_NODES); 2516 if (!test_bit(node_num, testing_map)) { 2517 mlog(ML_HEARTBEAT, 2518 "node (%u) does not have heartbeating enabled.\n", 2519 node_num); 2520 return 0; 2521 } 2522 2523 return 1; 2524 } 2525 EXPORT_SYMBOL_GPL(o2hb_check_node_heartbeating_from_callback); 2526 2527 /* 2528 * this is just a hack until we get the plumbing which flips file systems 2529 * read only and drops the hb ref instead of killing the node dead. 2530 */ 2531 void o2hb_stop_all_regions(void) 2532 { 2533 struct o2hb_region *reg; 2534 2535 mlog(ML_ERROR, "stopping heartbeat on all active regions.\n"); 2536 2537 spin_lock(&o2hb_live_lock); 2538 2539 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) 2540 reg->hr_unclean_stop = 1; 2541 2542 spin_unlock(&o2hb_live_lock); 2543 } 2544 EXPORT_SYMBOL_GPL(o2hb_stop_all_regions); 2545 2546 int o2hb_get_all_regions(char *region_uuids, u8 max_regions) 2547 { 2548 struct o2hb_region *reg; 2549 int numregs = 0; 2550 char *p; 2551 2552 spin_lock(&o2hb_live_lock); 2553 2554 p = region_uuids; 2555 list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) { 2556 if (reg->hr_item_dropped) 2557 continue; 2558 2559 mlog(0, "Region: %s\n", config_item_name(®->hr_item)); 2560 if (numregs < max_regions) { 2561 memcpy(p, config_item_name(®->hr_item), 2562 O2HB_MAX_REGION_NAME_LEN); 2563 p += O2HB_MAX_REGION_NAME_LEN; 2564 } 2565 numregs++; 2566 } 2567 2568 spin_unlock(&o2hb_live_lock); 2569 2570 return numregs; 2571 } 2572 EXPORT_SYMBOL_GPL(o2hb_get_all_regions); 2573 2574 int o2hb_global_heartbeat_active(void) 2575 { 2576 return (o2hb_heartbeat_mode == O2HB_HEARTBEAT_GLOBAL); 2577 } 2578 EXPORT_SYMBOL(o2hb_global_heartbeat_active); 2579