/* Only sets a new threshold if there are no active regions. * *Nolockingorotherwiseinterestingcodeisrequiredforreading *o2hb_dead_thresholdasitcan'tchangeonceregionsareactiveand
* it's not interesting to anyone until then anyway. */ staticvoid o2hb_dead_threshold_set(unsignedint threshold)
{ if (threshold > O2HB_MIN_DEAD_THRESHOLD) {
spin_lock(&o2hb_live_lock); if (list_empty(&o2hb_all_regions))
o2hb_dead_threshold = threshold;
spin_unlock(&o2hb_live_lock);
}
}
staticint o2hb_global_heartbeat_mode_set(unsignedint hb_mode)
{ int ret = -1;
if (hb_mode < O2HB_HEARTBEAT_NUM_MODES) {
spin_lock(&o2hb_live_lock); if (list_empty(&o2hb_all_regions)) {
o2hb_heartbeat_mode = hb_mode;
ret = 0;
}
spin_unlock(&o2hb_live_lock);
}
/* each thread owns a region.. when we're asked to tear down the region
* we ask the thread to stop, who cleans up the region */ struct o2hb_region { struct config_item hr_item;
/* let the person setting up hb wait for it to return until it *hasreacheda'steady'state.Thiswillbefixedwhenwehave
* a more complete api that doesn't lead to this sort of fragility. */
atomic_t hr_steady_iterations;
/* terminate o2hb thread if it does not reach steady state
* (hr_steady_iterations == 0) within hr_unsteady_iterations */
atomic_t hr_unsteady_iterations;
unsignedint hr_timeout_ms;
/* randomized as the region goes up and down so that a node
* recognizes a node going up and down in one iteration */
u64 hr_generation;
/* negotiate timer, used to negotiate extending hb timeout. */ struct delayed_work hr_nego_timeout_work; unsignedlong hr_nego_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)];
/* Used during o2hb_check_slot to hold a copy of the block *beingcheckedbecausewetemporarilyhavetozerooutthe
* crc field. */ struct o2hb_disk_heartbeat_block *hr_tmp_block;
staticvoid o2hb_arm_timeout(struct o2hb_region *reg)
{ /* Arm writeout only after thread reaches steady state */ if (atomic_read(®->hr_steady_iterations) != 0) return;
mlog(ML_HEARTBEAT, "Queue write timeout for %u ms\n",
O2HB_MAX_WRITE_TIMEOUT_MS);
cancel_delayed_work(®->hr_nego_timeout_work); /* negotiate timeout must be less than write timeout. */
schedule_delayed_work(®->hr_nego_timeout_work,
msecs_to_jiffies(O2HB_NEGO_TIMEOUT_MS));
bitmap_zero(reg->hr_nego_node_bitmap, O2NM_MAX_NODES);
}
if (ret == -EAGAIN || ret == -ENOMEM) {
msleep(100); goto again;
}
return ret;
}
staticvoid o2hb_nego_timeout(struct work_struct *work)
{ unsignedlong live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; int master_node, i, ret; struct o2hb_region *reg;
reg = container_of(work, struct o2hb_region, hr_nego_timeout_work.work); /* don't negotiate timeout if last hb failed since it is very *possibleiofailed.Shouldletwritetimeoutfenceself.
*/ if (reg->hr_last_hb_status) return;
o2hb_fill_node_map(live_node_bitmap, O2NM_MAX_NODES); /* lowest node as master node to make negotiate decision. */
master_node = find_first_bit(live_node_bitmap, O2NM_MAX_NODES);
if (master_node == o2nm_this_node()) { if (!test_bit(master_node, reg->hr_nego_node_bitmap)) {
printk(KERN_NOTICE "o2hb: node %d hb write hung for %ds on region %s (%pg).\n",
o2nm_this_node(), O2HB_NEGO_TIMEOUT_MS/1000,
config_item_name(®->hr_item), reg_bdev(reg));
set_bit(master_node, reg->hr_nego_node_bitmap);
} if (!bitmap_equal(reg->hr_nego_node_bitmap, live_node_bitmap,
O2NM_MAX_NODES)) { /* check negotiate bitmap every second to do timeout *approvedecision.
*/
schedule_delayed_work(®->hr_nego_timeout_work,
msecs_to_jiffies(1000));
return;
}
printk(KERN_NOTICE "o2hb: all nodes hb write hung, maybe region %s (%pg) is down.\n",
config_item_name(®->hr_item),
reg_bdev(reg)); /* approve negotiate timeout request. */
o2hb_arm_timeout(reg);
i = -1; while ((i = find_next_bit(live_node_bitmap,
O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) { if (i == master_node) continue;
mlog(ML_HEARTBEAT, "send NEGO_APPROVE msg to node %d\n", i);
ret = o2hb_send_nego_msg(reg->hr_key,
O2HB_NEGO_APPROVE_MSG, i); if (ret)
mlog(ML_ERROR, "send NEGO_APPROVE msg to node %d fail %d\n",
i, ret);
}
} else { /* negotiate timeout with master node. */
printk(KERN_NOTICE "o2hb: node %d hb write hung for %ds on region %s (%pg), negotiate timeout with node %d.\n",
o2nm_this_node(), O2HB_NEGO_TIMEOUT_MS/1000, config_item_name(®->hr_item),
reg_bdev(reg), master_node);
ret = o2hb_send_nego_msg(reg->hr_key, O2HB_NEGO_TIMEOUT_MSG,
master_node); if (ret)
mlog(ML_ERROR, "send NEGO_TIMEOUT msg to node %d fail %d\n",
master_node, ret);
}
}
/* Used in error paths too */ staticinlinevoid o2hb_bio_wait_dec(struct o2hb_bio_wait_ctxt *wc, unsignedint num)
{ /* sadly atomic_sub_and_test() isn't available on all platforms. The
* good news is that the fast path only completes one at a time */ while(num--) { if (atomic_dec_and_test(&wc->wc_num_reqs)) {
BUG_ON(num > 0);
complete(&wc->wc_io_complete);
}
}
}
/* Setup a Bio to cover I/O against num_slots slots starting at
* start_slot. */ staticstruct bio *o2hb_setup_one_bio(struct o2hb_region *reg, struct o2hb_bio_wait_ctxt *wc, unsignedint *current_slot, unsignedint max_slots, blk_opf_t opf)
{ int len, current_page; unsignedint vec_len, vec_start; unsignedint bits = reg->hr_block_bits; unsignedint spp = reg->hr_slots_per_page; unsignedint cs = *current_slot; struct bio *bio; struct page *page;
/* Testing has shown this allocation to take long enough under *GFP_KERNELthatthelocalnodecangetfenced.Itwouldbe *nicestifwecouldpre-allocatethesebiosandavoidthis
* all together. */
bio = bio_alloc(reg_bdev(reg), 16, opf, GFP_ATOMIC); if (!bio) {
mlog(ML_ERROR, "Could not alloc slots BIO!\n");
bio = ERR_PTR(-ENOMEM); goto bail;
}
/* Must put everything in 512 byte sectors for the bio... */
bio->bi_iter.bi_sector = (reg->hr_start_block + cs) << (bits - 9);
bio->bi_private = wc;
bio->bi_end_io = o2hb_bio_end_io;
/* We want to compute the block crc with a 0 value in the *hb_cksumfield.Saveitoffhereandreplaceafterthe
* crc. */
old_cksum = hb_block->hb_cksum;
hb_block->hb_cksum = 0;
ret = crc32_le(0, (unsignedchar *) hb_block, reg->hr_block_bytes);
/* Will run the list in order until we process the passed event */ staticvoid o2hb_run_event_list(struct o2hb_node_event *queued_event)
{ struct o2hb_callback *hbcall; struct o2hb_node_event *event;
/* Holding callback sem assures we don't alter the callback *listswhendoingthis,andserializesourselveswithother
* processes wanting callbacks. */
down_write(&o2hb_callback_sem);
/* *Ifanodeisnolongerconfiguredbutisstillinthelivemap,we *mayneedtoclearthatbitfromthelivemap.
*/
node = o2nm_get_node_by_num(slot->ds_node_num); if (!node) {
spin_lock(&o2hb_live_lock);
tmp = test_bit(slot->ds_node_num, o2hb_live_node_bitmap);
spin_unlock(&o2hb_live_lock); if (!tmp) return0;
}
if (!o2hb_verify_crc(reg, hb_block)) { /* all paths from here will drop o2hb_live_lock for
* us. */
spin_lock(&o2hb_live_lock);
/* Don't print an error on the console in this case - *afreshlyformattedheartbeatareawillnothavea
* crc set on it. */ if (list_empty(&slot->ds_live_item)) goto out;
/* The node is live but pushed out a bad crc. We *consideritatransientmissbutdon'tpopulateany
* other values as they may be junk. */
mlog(ML_ERROR, "Node %d has written a bad crc to %pg\n",
slot->ds_node_num, reg_bdev(reg));
o2hb_dump_slot(hb_block);
slot->ds_equal_samples++; goto fire_callbacks;
}
/* we don't care if these wrap.. the state transitions below
* clear at the right places */
cputime = le64_to_cpu(hb_block->hb_seq); if (slot->ds_last_time != cputime)
slot->ds_changed_samples++; else
slot->ds_equal_samples++;
slot->ds_last_time = cputime;
/* The node changed heartbeat generations. We assume this to *meanitdroppedoffbutcamebackbeforewetimedout.We *wanttoconsideritdownforthetimebeingbutdon'twant *toloseanychanged_samplesstatewemightbuildupto
* considering it live again. */ if (slot->ds_last_generation != le64_to_cpu(hb_block->hb_generation)) {
gen_changed = 1;
slot->ds_equal_samples = 0;
mlog(ML_HEARTBEAT, "Node %d changed generation (0x%llx " "to 0x%llx)\n", slot->ds_node_num,
(longlong)slot->ds_last_generation,
(longlong)le64_to_cpu(hb_block->hb_generation));
}
fire_callbacks: /* dead nodes only come to life after some number of
* changes at any time during their dead time */ if (list_empty(&slot->ds_live_item) &&
slot->ds_changed_samples >= O2HB_LIVE_THRESHOLD) {
mlog(ML_HEARTBEAT, "Node %d (id 0x%llx) joined my region\n",
slot->ds_node_num, (longlong)slot->ds_last_generation);
/* first on the list generates a callback */ if (list_empty(&o2hb_live_slots[slot->ds_node_num])) {
mlog(ML_HEARTBEAT, "o2hb: Add node %d to live nodes " "bitmap\n", slot->ds_node_num);
set_bit(slot->ds_node_num, o2hb_live_node_bitmap);
/* We want to be sure that all nodes agree on the *numberofmillisecondsbeforeanodewillbe *considereddead.Theself-fencingtimeoutis *computedfromthisvalue,andadiscrepancymight *resultinheartbeatcallinganodedeadwhenit
* hasn't self-fenced yet. */
slot_dead_ms = le32_to_cpu(hb_block->hb_dead_ms); if (slot_dead_ms && slot_dead_ms != dead_ms) { /* TODO: Perhaps we can fail the region here. */
mlog(ML_ERROR, "Node %d on device %pg has a dead count " "of %u ms, but our count is %u ms.\n" "Please double check your configuration values " "for 'O2CB_HEARTBEAT_THRESHOLD'\n",
slot->ds_node_num, reg_bdev(reg),
slot_dead_ms, dead_ms);
} goto out;
}
/* if the list is dead, we're done.. */ if (list_empty(&slot->ds_live_item)) goto out;
/* live nodes only go dead after enough consecutive missed *samples..resetthemissedcounterwheneverwesee
* activity */ if (slot->ds_equal_samples >= o2hb_dead_threshold || gen_changed) {
mlog(ML_HEARTBEAT, "Node %d left my region\n",
slot->ds_node_num);
/* last off the live_slot generates a callback */
list_del_init(&slot->ds_live_item); if (list_empty(&o2hb_live_slots[slot->ds_node_num])) {
mlog(ML_HEARTBEAT, "o2hb: Remove node %d from live " "nodes bitmap\n", slot->ds_node_num);
clear_bit(slot->ds_node_num, o2hb_live_node_bitmap);
/* node can be null */
o2hb_queue_node_event(&event, O2HB_NODE_DOWN_CB,
node, slot->ds_node_num);
changed = 1;
queued = 1;
}
/* We don't clear this because the node is still
* actually writing new blocks. */ if (!gen_changed)
slot->ds_changed_samples = 0; goto out;
} if (slot->ds_changed_samples) {
slot->ds_changed_samples = 0;
slot->ds_equal_samples = 0;
}
out:
spin_unlock(&o2hb_live_lock);
if (queued)
o2hb_run_event_list(&event);
if (node)
o2nm_node_put(node); return changed;
}
staticint o2hb_highest_node(unsignedlong *nodes, int numbits)
{ return find_last_bit(nodes, numbits);
}
staticint o2hb_lowest_node(unsignedlong *nodes, int numbits)
{ return find_first_bit(nodes, numbits);
}
staticint o2hb_do_disk_heartbeat(struct o2hb_region *reg)
{ int i, ret, highest_node, lowest_node; int membership_change = 0, own_slot_ok = 0; unsignedlong configured_nodes[BITS_TO_LONGS(O2NM_MAX_NODES)]; unsignedlong live_node_bitmap[BITS_TO_LONGS(O2NM_MAX_NODES)]; struct o2hb_bio_wait_ctxt write_wc;
ret = o2nm_configured_node_map(configured_nodes, sizeof(configured_nodes)); if (ret) {
mlog_errno(ret); goto bail;
}
/* *Ifanodeisnotconfiguredbutisinthelivemap,westillneed *toreadtheslotsoastobeabletoremoveitfromthelivemap.
*/
o2hb_fill_node_map(live_node_bitmap, O2NM_MAX_NODES);
i = -1; while ((i = find_next_bit(live_node_bitmap,
O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) {
set_bit(i, configured_nodes);
}
highest_node = o2hb_highest_node(configured_nodes, O2NM_MAX_NODES);
lowest_node = o2hb_lowest_node(configured_nodes, O2NM_MAX_NODES); if (highest_node >= O2NM_MAX_NODES || lowest_node >= O2NM_MAX_NODES) {
mlog(ML_NOTICE, "o2hb: No configured nodes found!\n");
ret = -EINVAL; goto bail;
}
/* No sense in reading the slots of nodes that don't exist *yet.Ofcourse,ifthenodedefinitionshaveholesinthem *thenwe'rereadinganemptyslotanyway...Considerthis
* best-effort. */
ret = o2hb_read_slots(reg, lowest_node, highest_node + 1); if (ret < 0) {
mlog_errno(ret); goto bail;
}
/* With an up to date view of the slots, we can check that no *othernodehasbeenimproperlyconfiguredtoheartbeatin
* our slot. */
own_slot_ok = o2hb_check_own_slot(reg);
/* fill in the proper info for our next heartbeat */
o2hb_prepare_block(reg, reg->hr_generation);
ret = o2hb_issue_node_write(reg, &write_wc); if (ret < 0) {
mlog_errno(ret); goto bail;
}
i = -1; while((i = find_next_bit(configured_nodes,
O2NM_MAX_NODES, i + 1)) < O2NM_MAX_NODES) {
membership_change |= o2hb_check_slot(reg, ®->hr_slots[i]);
}
/* *Wehavetobesurewe'veadvertisedourselvesondisk *beforewecangotosteadystate.Thisensuresthat *peoplewefindinoursteadystatehaveseenus.
*/
o2hb_wait_on_io(&write_wc); if (write_wc.wc_error) { /* Do not re-arm the write timeout on I/O error - we *can'tbesurethatthenewblockevermadeitto
* disk */
mlog(ML_ERROR, "Write error %d on device \"%pg\"\n",
write_wc.wc_error, reg_bdev(reg));
ret = write_wc.wc_error; goto bail;
}
/* Skip disarming the timeout if own slot has stale/bad data */ if (own_slot_ok) {
o2hb_set_quorum_device(reg);
o2hb_arm_timeout(reg);
reg->hr_last_timeout_start = jiffies;
}
bail: /* let the person who launched us know when things are steady */ if (atomic_read(®->hr_steady_iterations) != 0) { if (!ret && own_slot_ok && !membership_change) { if (atomic_dec_and_test(®->hr_steady_iterations))
wake_up(&o2hb_steady_queue);
}
}
if (atomic_read(®->hr_steady_iterations) != 0) { if (atomic_dec_and_test(®->hr_unsteady_iterations)) {
printk(KERN_NOTICE "o2hb: Unable to stabilize " "heartbeat on region %s (%pg)\n",
config_item_name(®->hr_item),
reg_bdev(reg));
atomic_set(®->hr_steady_iterations, 0);
reg->hr_aborted_start = 1;
wake_up(&o2hb_steady_queue);
ret = -EIO;
}
}
/* Pin node */
ret = o2nm_depend_this_node(); if (ret) {
mlog(ML_ERROR, "Node has been deleted, ret = %d\n", ret);
reg->hr_node_deleted = 1;
wake_up(&o2hb_steady_queue); return0;
}
while (!kthread_should_stop() &&
!reg->hr_unclean_stop && !reg->hr_aborted_start) { /* We track the time spent inside *o2hb_do_disk_heartbeatsothatweavoidmorethan *hr_timeout_msbetweendiskwrites.Onbusysystems *thisshouldresultinaheartbeatwhichisless
* likely to time itself out. */
before_hb = ktime_get_real();
ret = o2hb_do_disk_heartbeat(reg);
reg->hr_last_hb_status = ret;
mlog(ML_HEARTBEAT, "start = %lld, end = %lld, msec = %u, ret = %d\n",
before_hb, after_hb, elapsed_msec, ret);
if (!kthread_should_stop() &&
elapsed_msec < reg->hr_timeout_ms) { /* the kthread api has blocked signals for us so no
* need to record the return value. */
msleep_interruptible(reg->hr_timeout_ms - elapsed_msec);
}
}
o2hb_disarm_timeout(reg);
/* unclean stop is only used in very bad situation */ for(i = 0; !reg->hr_unclean_stop && i < reg->hr_blocks; i++)
o2hb_shutdown_slot(®->hr_slots[i]);
/* Explicit down notification - avoid forcing the other nodes *totimeoutonthisregionwhenwecouldjustaseasily *writeacleargeneration-thusindicatingtothemthat *thisnodehasleftthisregion.
*/ if (!reg->hr_unclean_stop && !reg->hr_aborted_start) {
o2hb_prepare_block(reg, 0);
ret = o2hb_issue_node_write(reg, &write_wc); if (ret == 0)
o2hb_wait_on_io(&write_wc); else
mlog_errno(ret);
}
#ifdef CONFIG_DEBUG_FS staticint o2hb_debug_open(struct inode *inode, struct file *file)
{ struct o2hb_debug_buf *db = inode->i_private; struct o2hb_region *reg; unsignedlong map[BITS_TO_LONGS(O2NM_MAX_NODES)]; unsignedlong lts; char *buf = NULL; int i = -1; int out = 0;
/* max_nodes should be the largest bitmap we pass here */
BUG_ON(sizeof(map) < db->db_size);
buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buf) goto bail;
switch (db->db_type) { case O2HB_DB_TYPE_LIVENODES: case O2HB_DB_TYPE_LIVEREGIONS: case O2HB_DB_TYPE_QUORUMREGIONS: case O2HB_DB_TYPE_FAILEDREGIONS:
spin_lock(&o2hb_live_lock);
memcpy(map, db->db_data, db->db_size);
spin_unlock(&o2hb_live_lock); break;
case O2HB_DB_TYPE_REGION_NUMBER:
reg = (struct o2hb_region *)db->db_data;
out += scnprintf(buf + out, PAGE_SIZE - out, "%d\n",
reg->hr_region_num); goto done;
case O2HB_DB_TYPE_REGION_ELAPSED_TIME:
reg = (struct o2hb_region *)db->db_data;
lts = reg->hr_last_timeout_start; /* If 0, it has never been set before */ if (lts)
lts = jiffies_to_msecs(jiffies - lts);
out += scnprintf(buf + out, PAGE_SIZE - out, "%lu\n", lts); goto done;
case O2HB_DB_TYPE_REGION_PINNED:
reg = (struct o2hb_region *)db->db_data;
out += scnprintf(buf + out, PAGE_SIZE - out, "%u\n",
!!reg->hr_item_pinned); goto done;
default: goto done;
}
while ((i = find_next_bit(map, db->db_len, i + 1)) < db->db_len)
out += scnprintf(buf + out, PAGE_SIZE - out, "%d ", i);
out += scnprintf(buf + out, PAGE_SIZE - out, "\n");
/* if we're already in a callback then we're already serialized by the sem */ staticvoid o2hb_fill_node_map_from_callback(unsignedlong *map, unsignedint bits)
{
bitmap_copy(map, o2hb_live_node_bitmap, bits);
}
/* *getamapofallnodesthatareheartbeatinginanyregions
*/ void o2hb_fill_node_map(unsignedlong *map, unsignedint bits)
{ /* callers want to serialize this map and callbacks so that they
* can trust that they don't miss nodes coming to the party */
down_read(&o2hb_callback_sem);
spin_lock(&o2hb_live_lock);
o2hb_fill_node_map_from_callback(map, bits);
spin_unlock(&o2hb_live_lock);
up_read(&o2hb_callback_sem);
}
EXPORT_SYMBOL_GPL(o2hb_fill_node_map);
/* drop_item only drops its ref after killing the thread, nothing should *beusingtheregionanymore.thishastocleanupanystatethat
* attributes might have built up. */ staticvoid o2hb_region_release(struct config_item *item)
{ int i; struct page *page; struct o2hb_region *reg = to_o2hb_region(item);
mlog(ML_HEARTBEAT, "hb region release (%pg)\n", reg_bdev(reg));
kfree(reg->hr_tmp_block);
if (reg->hr_slot_data) { for (i = 0; i < reg->hr_num_pages; i++) {
page = reg->hr_slot_data[i]; if (page)
__free_page(page);
}
kfree(reg->hr_slot_data);
}
/* Read in all the slots available and populate the tracking *structuressothatwecanstartwithabaselineideaofwhat's
* there. */ staticint o2hb_populate_slot_data(struct o2hb_region *reg)
{ int ret, i; struct o2hb_disk_slot *slot; struct o2hb_disk_heartbeat_block *hb_block;
ret = o2hb_read_slots(reg, 0, reg->hr_blocks); if (ret) goto out;
/* We only want to get an idea of the values initially in each *slot,sowedonoverification-o2hb_check_slotwill *actuallydetermineifeachconfiguredslotisvalidand
* whether any values have changed. */ for(i = 0; i < reg->hr_blocks; i++) {
slot = ®->hr_slots[i];
hb_block = (struct o2hb_disk_heartbeat_block *) slot->ds_raw_block;
/* Only fill the values that o2hb_check_slot uses to
* determine changing slots */
slot->ds_last_time = le64_to_cpu(hb_block->hb_seq);
slot->ds_last_generation = le64_to_cpu(hb_block->hb_generation);
}
out: return ret;
}
/* *thisisactingascommit;wesetupallofhr_bdev_fileandhr_taskor *nothing
*/ static ssize_t o2hb_region_dev_store(struct config_item *item, constchar *page,
size_t count)
{ struct o2hb_region *reg = to_o2hb_region(item); struct task_struct *hb_task; long fd; int sectsize; char *p = (char *)page;
ssize_t ret = -EINVAL; int live_threshold;
if (reg->hr_bdev_file) return -EINVAL;
/* We can't heartbeat without having had our node number
* configured yet. */ if (o2nm_this_node() == O2NM_MAX_NODES) return -EINVAL;
ret = kstrtol(p, 0, &fd); if (ret < 0) return -EINVAL;
if (fd < 0 || fd >= INT_MAX) return -EINVAL;
CLASS(fd, f)(fd); if (fd_empty(f)) return -EINVAL;
ret = wait_event_interruptible(o2hb_steady_queue,
atomic_read(®->hr_steady_iterations) == 0 ||
reg->hr_node_deleted); if (ret) {
atomic_set(®->hr_steady_iterations, 0);
reg->hr_aborted_start = 1;
}
if (reg->hr_aborted_start) {
ret = -EIO; goto out3;
}
if (reg->hr_node_deleted) {
ret = -EINVAL; goto out3;
}
/* Ok, we were woken. Make sure it wasn't by drop_item() */
spin_lock(&o2hb_live_lock);
hb_task = reg->hr_task; if (o2hb_global_heartbeat_active())
set_bit(reg->hr_region_num, o2hb_live_region_bitmap);
spin_unlock(&o2hb_live_lock);
if (hb_task)
ret = count; else
ret = -EIO;
if (hb_task && o2hb_global_heartbeat_active())
printk(KERN_NOTICE "o2hb: Heartbeat started on region %s (%pg)\n",
config_item_name(®->hr_item), reg_bdev(reg));
/* this is the same way to generate msg key as dlm, for local heartbeat, *nameisalsothesame,somakeinitialcrcvaluedifferenttoavoid *messagekeyconflict.
*/
reg->hr_key = crc32_le(reg->hr_region_num + O2NM_MAX_REGIONS,
name, strlen(name));
INIT_LIST_HEAD(®->hr_handler_list);
ret = o2net_register_handler(O2HB_NEGO_TIMEOUT_MSG, reg->hr_key, sizeof(struct o2hb_nego_msg),
o2hb_nego_timeout_handler,
reg, NULL, ®->hr_handler_list); if (ret) goto remove_item;
ret = o2net_register_handler(O2HB_NEGO_APPROVE_MSG, reg->hr_key, sizeof(struct o2hb_nego_msg),
o2hb_nego_approve_handler,
reg, NULL, ®->hr_handler_list); if (ret) goto unregister_handler;
/* stop the thread when the user removes the region dir */
spin_lock(&o2hb_live_lock);
hb_task = reg->hr_task;
reg->hr_task = NULL;
reg->hr_item_dropped = 1;
spin_unlock(&o2hb_live_lock);
if (hb_task)
kthread_stop(hb_task);
if (o2hb_global_heartbeat_active()) {
spin_lock(&o2hb_live_lock);
clear_bit(reg->hr_region_num, o2hb_region_bitmap);
clear_bit(reg->hr_region_num, o2hb_live_region_bitmap); if (test_bit(reg->hr_region_num, o2hb_quorum_region_bitmap))
quorum_region = 1;
clear_bit(reg->hr_region_num, o2hb_quorum_region_bitmap);
spin_unlock(&o2hb_live_lock);
printk(KERN_NOTICE "o2hb: Heartbeat %s on region %s (%pg)\n",
((atomic_read(®->hr_steady_iterations) == 0) ? "stopped" : "start aborted"), config_item_name(item),
reg_bdev(reg));
}
len = (page[count - 1] == '\n') ? count - 1 : count; if (!len) return -EINVAL;
for (i = 0; i < O2HB_HEARTBEAT_NUM_MODES; ++i) { if (strncasecmp(page, o2hb_heartbeat_mode_desc[i], len)) continue;
ret = o2hb_global_heartbeat_mode_set(i); if (!ret)
printk(KERN_NOTICE "o2hb: Heartbeat mode set to %s\n",
o2hb_heartbeat_mode_desc[i]); return count;
}
/* this is just here to avoid touching group in heartbeat.h which the
* entire damn world #includes */ struct config_group *o2hb_alloc_hb_set(void)
{ struct o2hb_heartbeat_group *hs = NULL; struct config_group *ret = NULL;
/* *Inlocalheartbeatmode,region_uuidpassedmatchesthedlmdomainname. *Inglobalheartbeatmode,region_uuidpassedisNULL. * *Inlocal,weonlypinthematchingregion.Inglobalwepinalltheactive *regions.
*/ staticint o2hb_region_pin(constchar *region_uuid)
{ int ret = 0, found = 0; struct o2hb_region *reg; char *uuid;
assert_spin_locked(&o2hb_live_lock);
list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) { if (reg->hr_item_dropped) continue;
uuid = config_item_name(®->hr_item);
/* local heartbeat */ if (region_uuid) { if (strcmp(region_uuid, uuid)) continue;
found = 1;
}
if (reg->hr_item_pinned || reg->hr_item_dropped) goto skip_pin;
/* Ignore ENOENT only for local hb (userdlm domain) */
ret = o2nm_depend_item(®->hr_item); if (!ret) {
mlog(ML_CLUSTER, "Pin region %s\n", uuid);
reg->hr_item_pinned = 1;
} else { if (ret == -ENOENT && found)
ret = 0; else {
mlog(ML_ERROR, "Pin region %s fails with %d\n",
uuid, ret); break;
}
}
skip_pin: if (found) break;
}
return ret;
}
/* *Inlocalheartbeatmode,region_uuidpassedmatchesthedlmdomainname. *Inglobalheartbeatmode,region_uuidpassedisNULL. * *Inlocal,weonlyunpinthematchingregion.Inglobalweunpinallthe *activeregions.
*/ staticvoid o2hb_region_unpin(constchar *region_uuid)
{ struct o2hb_region *reg; char *uuid; int found = 0;
assert_spin_locked(&o2hb_live_lock);
list_for_each_entry(reg, &o2hb_all_regions, hr_all_item) { if (reg->hr_item_dropped) continue;
uuid = config_item_name(®->hr_item); if (region_uuid) { if (strcmp(region_uuid, uuid)) continue;
found = 1;
}
if (reg->hr_item_pinned) {
mlog(ML_CLUSTER, "Unpin region %s\n", uuid);
o2nm_undepend_item(®->hr_item);
reg->hr_item_pinned = 0;
} if (found) break;
}
}
staticint o2hb_region_inc_user(constchar *region_uuid)
{ int ret = 0;
spin_lock(&o2hb_live_lock);
/* local heartbeat */ if (!o2hb_global_heartbeat_active()) {
ret = o2hb_region_pin(region_uuid); goto unlock;
}
int o2hb_check_node_heartbeating_no_sem(u8 node_num)
{ unsignedlong testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
spin_lock(&o2hb_live_lock);
o2hb_fill_node_map_from_callback(testing_map, O2NM_MAX_NODES);
spin_unlock(&o2hb_live_lock); if (!test_bit(node_num, testing_map)) {
mlog(ML_HEARTBEAT, "node (%u) does not have heartbeating enabled.\n",
node_num); return0;
}
int o2hb_check_node_heartbeating_from_callback(u8 node_num)
{ unsignedlong testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)];
o2hb_fill_node_map_from_callback(testing_map, O2NM_MAX_NODES); if (!test_bit(node_num, testing_map)) {
mlog(ML_HEARTBEAT, "node (%u) does not have heartbeating enabled.\n",
node_num); return0;
}
int o2hb_global_heartbeat_active(void)
{ return (o2hb_heartbeat_mode == O2HB_HEARTBEAT_GLOBAL);
}
EXPORT_SYMBOL(o2hb_global_heartbeat_active);
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.49Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.