367
367
static void o2hb_wait_on_io(struct o2hb_region *reg,
368
368
struct o2hb_bio_wait_ctxt *wc)
370
struct address_space *mapping = reg->hr_bdev->bd_inode->i_mapping;
372
blk_run_address_space(mapping);
373
370
o2hb_bio_wait_dec(wc, 1);
375
371
wait_for_completion(&wc->wc_io_complete);
544
540
/* We want to make sure that nobody is heartbeating on top of us --
545
541
* this will help detect an invalid configuration. */
546
static int o2hb_check_last_timestamp(struct o2hb_region *reg)
542
static void o2hb_check_last_timestamp(struct o2hb_region *reg)
549
544
struct o2hb_disk_slot *slot;
550
545
struct o2hb_disk_heartbeat_block *hb_block;
552
node_num = o2nm_this_node();
555
slot = ®->hr_slots[node_num];
548
slot = ®->hr_slots[o2nm_this_node()];
556
549
/* Don't check on our 1st timestamp */
557
if (slot->ds_last_time) {
558
hb_block = slot->ds_raw_block;
560
if (le64_to_cpu(hb_block->hb_seq) != slot->ds_last_time)
550
if (!slot->ds_last_time)
553
hb_block = slot->ds_raw_block;
554
if (le64_to_cpu(hb_block->hb_seq) == slot->ds_last_time &&
555
le64_to_cpu(hb_block->hb_generation) == slot->ds_last_generation &&
556
hb_block->hb_node == slot->ds_node_num)
559
#define ERRSTR1 "Another node is heartbeating on device"
560
#define ERRSTR2 "Heartbeat generation mismatch on device"
561
#define ERRSTR3 "Heartbeat sequence mismatch on device"
563
if (hb_block->hb_node != slot->ds_node_num)
565
else if (le64_to_cpu(hb_block->hb_generation) !=
566
slot->ds_last_generation)
571
mlog(ML_ERROR, "%s (%s): expected(%u:0x%llx, 0x%llx), "
572
"ondisk(%u:0x%llx, 0x%llx)\n", errstr, reg->hr_dev_name,
573
slot->ds_node_num, (unsigned long long)slot->ds_last_generation,
574
(unsigned long long)slot->ds_last_time, hb_block->hb_node,
575
(unsigned long long)le64_to_cpu(hb_block->hb_generation),
576
(unsigned long long)le64_to_cpu(hb_block->hb_seq));
567
579
static inline void o2hb_prepare_block(struct o2hb_region *reg,
987
999
/* With an up to date view of the slots, we can check that no
988
1000
* other node has been improperly configured to heartbeat in
990
if (!o2hb_check_last_timestamp(reg))
991
mlog(ML_ERROR, "Device \"%s\": another node is heartbeating "
992
"in our slot!\n", reg->hr_dev_name);
1002
o2hb_check_last_timestamp(reg);
994
1004
/* fill in the proper info for our next heartbeat */
995
1005
o2hb_prepare_block(reg, reg->hr_generation);
1006
while((i = find_next_bit(configured_nodes, O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) {
1016
while((i = find_next_bit(configured_nodes,
1017
O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) {
1008
1018
change |= o2hb_check_slot(reg, ®->hr_slots[i]);
1773
1781
* A node is considered live after it has beat LIVE_THRESHOLD
1774
1782
* times. We're not steady until we've given them a chance
1775
1783
* _after_ our first read.
1784
* The default threshold is bare minimum so as to limit the delay
1785
* during mounts. For global heartbeat, the threshold doubled for the
1777
atomic_set(®->hr_steady_iterations, O2HB_LIVE_THRESHOLD + 1);
1788
live_threshold = O2HB_LIVE_THRESHOLD;
1789
if (o2hb_global_heartbeat_active()) {
1790
spin_lock(&o2hb_live_lock);
1791
if (o2hb_pop_count(&o2hb_region_bitmap, O2NM_MAX_REGIONS) == 1)
1792
live_threshold <<= 1;
1793
spin_unlock(&o2hb_live_lock);
1795
atomic_set(®->hr_steady_iterations, live_threshold + 1);
1779
1797
hb_task = kthread_run(o2hb_thread, reg, "o2hb-%s",
1780
1798
reg->hr_item.ci_name);