Jeff Mahoney
2006-Feb-21 16:57 UTC
[Ocfs2-devel] [PATCH 11/14] ocfs2: add check_node_status for resources that can distinguish between resources
This patch adds the ->check_node_status operation to the heartbeat resource. In doing so, it means that we don't need to request the bitmap and test it ourselves for heartbeat implementations that can check status more efficiently. This patch also creates a single __o2hb_check_node_heartbeating implementation, since the others were simply doing the same thing either with a lock or with the local node. fs/ocfs2/cluster/heartbeat.c | 70 +++++++++++++++++++------------------------ fs/ocfs2/cluster/heartbeat.h | 1 2 files changed, 32 insertions(+), 39 deletions(-) Signed-off-by: Jeff Mahoney <jeffm at suse.com> diff -ruNpX ../dontdiff linux-2.6.16-rc4.ocfs2-staging1/fs/ocfs2/cluster/heartbeat.c linux-2.6.16-rc4.ocfs2-staging2/fs/ocfs2/cluster/heartbeat.c --- linux-2.6.16-rc4.ocfs2-staging1/fs/ocfs2/cluster/heartbeat.c 2006-02-21 11:44:46.000000000 -0500 +++ linux-2.6.16-rc4.ocfs2-staging2/fs/ocfs2/cluster/heartbeat.c 2006-02-21 11:44:48.000000000 -0500 @@ -396,37 +396,47 @@ int o2hb_unregister_heartbeat_group(stru } EXPORT_SYMBOL_GPL(o2hb_unregister_heartbeat_group); -int o2hb_check_node_heartbeating(const char *resource, u8 node_num) +static int __o2hb_check_node_heartbeating(const char *resource, u8 node_num, + int need_lock) { - unsigned long testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; + int ret = 0; + if (need_lock) { + down_read(&o2hb_callback_sem); + spin_lock(&o2hb_live_lock); + } + + if (o2hb_active_group->check_node_status) { + ret = o2hb_active_group->check_node_status(resource, node_num); + } else { + unsigned long testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; + if( o2hb_fill_node_map_from_callback(resource, testing_map, + sizeof(testing_map)) == 0) + ret = test_bit(node_num, testing_map); + } + + if (need_lock) { + spin_unlock(&o2hb_live_lock); + up_read(&o2hb_callback_sem); + } - o2hb_fill_node_map(resource, testing_map, sizeof(testing_map)); - if (!test_bit(node_num, testing_map)) { + if (!ret) mlog(ML_HEARTBEAT, "node (%u) does not have heartbeating enabled.\n", node_num); - return 0; - } - return 1; + return ret; +} + +int o2hb_check_node_heartbeating(const char *resource, u8 node_num) +{ + return __o2hb_check_node_heartbeating(resource, node_num, 1); } EXPORT_SYMBOL_GPL(o2hb_check_node_heartbeating); int o2hb_check_node_heartbeating_from_callback(const char *resource, u8 node_num) { - unsigned long testing_map[BITS_TO_LONGS(O2NM_MAX_NODES)]; - - o2hb_fill_node_map_from_callback(resource, testing_map, - sizeof(testing_map)); - if (!test_bit(node_num, testing_map)) { - mlog(ML_HEARTBEAT, - "node (%u) does not have heartbeating enabled.\n", - node_num); - return 0; - } - - return 1; + return __o2hb_check_node_heartbeating(resource, node_num, 0); } EXPORT_SYMBOL_GPL(o2hb_check_node_heartbeating_from_callback); @@ -434,16 +444,7 @@ EXPORT_SYMBOL_GPL(o2hb_check_node_heartb * heartbeating. */ int o2hb_check_local_node_heartbeating(const char *resource) { - u8 node_num; - - /* if this node was set then we have networking */ - node_num = o2nm_this_node(); - if (node_num == O2NM_MAX_NODES) { - mlog(ML_HEARTBEAT, "this node has not been configured.\n"); - return 0; - } - - return o2hb_check_node_heartbeating(resource, node_num); + return __o2hb_check_node_heartbeating(resource, o2nm_this_node(), 1); } EXPORT_SYMBOL_GPL(o2hb_check_local_node_heartbeating); @@ -451,15 +452,6 @@ EXPORT_SYMBOL_GPL(o2hb_check_local_node_ * heartbeating. */ int o2hb_check_local_node_heartbeating_from_callback(const char *resource) { - u8 node_num; - - /* if this node was set then we have networking */ - node_num = o2nm_this_node(); - if (node_num == O2NM_MAX_NODES) { - mlog(ML_HEARTBEAT, "this node has not been configured.\n"); - return 0; - } - - return o2hb_check_node_heartbeating_from_callback(resource, node_num); + return __o2hb_check_node_heartbeating(resource, o2nm_this_node(), 0); } EXPORT_SYMBOL_GPL(o2hb_check_local_node_heartbeating_from_callback); diff -ruNpX ../dontdiff linux-2.6.16-rc4.ocfs2-staging1/fs/ocfs2/cluster/heartbeat.h linux-2.6.16-rc4.ocfs2-staging2/fs/ocfs2/cluster/heartbeat.h --- linux-2.6.16-rc4.ocfs2-staging1/fs/ocfs2/cluster/heartbeat.h 2006-02-21 11:44:46.000000000 -0500 +++ linux-2.6.16-rc4.ocfs2-staging2/fs/ocfs2/cluster/heartbeat.h 2006-02-21 11:44:48.000000000 -0500 @@ -49,6 +49,7 @@ struct o2hb_heartbeat_group { void (*exit)(struct o2hb_heartbeat_group *hs); int (*fill_node_map)(const char *resource, unsigned long *map, size_t bytes); + int (*check_node_status)(const char *resource, u8 node_num); atomic_t hs_count; struct list_head hs_list; };