ocfs2/cluster: use bitmap API instead of hand-writing it
PATCH 1/3 ocfs2/cluster: use bitmap API instead of hand-writing it
Use bitmap_zero/bitmap_copy/bitmap_equal directly for bitmap operations.
Signed-off-by Joseph Qi <[email protected]>
--- fs/ocfs2/cluster/heartbeat.c | 20 ++++++++++---------- fs/ocfs2/cluster/nodemanager.c | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-)
fs/ocfs2/cluster/heartbeat.c +10 -10
@@ -335,7 +335,7 @@ static void o2hb_arm_timeout(struct o2hb_region *reg)/* negotiate timeout must be less than write timeout. */ schedule_delayed_work (®->hr_nego_timeout_work,msecs_to_jiffies (O2HB_NEGO_TIMEOUT_MS )); -memset (reg->hr_nego_node_bitmap,0 ,sizeof (reg->hr_nego_node_bitmap)); +bitmap_zero (reg->hr_nego_node_bitmap,O2NM_MAX_NODES ); }static void o2hb_disarm_timeout (struct o2hb_region *reg)
@@ -386,8 +386,8 @@ static void o2hb_nego_timeout(struct work_struct *work) config_item_name(®->hr_item), reg->hr_bdev);set_bit (master_node, reg->hr_nego_node_bitmap); } -if (memcmp (reg->hr_nego_node_bitmap, live_node_bitmap, -sizeof (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 * approve decision. */
@@ -856,8 +856,8 @@ static void o2hb_set_quorum_device(struct o2hb_region *reg)* live nodes heartbeat on it. In other words, the region has been * added to all nodes. */ -if (memcmp (reg->hr_live_node_bitmap, o2hb_live_node_bitmap, -sizeof (o2hb_live_node_bitmap))) +if (!bitmap_equal (reg->hr_live_node_bitmap, o2hb_live_node_bitmap, +O2NM_MAX_NODES )) goto unlock; printk(KERN_NOTICE "o2hb: Region %s (%pg) is now a quorum device\n",
@@ -1437,11 +1437,11 @@ void o2hb_init(void)for (i =0 ; i <ARRAY_SIZE (o2hb_live_slots); i++)INIT_LIST_HEAD (&o2hb_live_slots[i]); -memset (o2hb_live_node_bitmap,0 ,sizeof (o2hb_live_node_bitmap)); -memset (o2hb_region_bitmap,0 ,sizeof (o2hb_region_bitmap)); -memset (o2hb_live_region_bitmap,0 ,sizeof (o2hb_live_region_bitmap)); -memset (o2hb_quorum_region_bitmap,0 ,sizeof (o2hb_quorum_region_bitmap)); -memset (o2hb_failed_region_bitmap,0 ,sizeof (o2hb_failed_region_bitmap)); +bitmap_zero (o2hb_live_node_bitmap,O2NM_MAX_NODES ); +bitmap_zero (o2hb_region_bitmap,O2NM_MAX_REGIONS ); +bitmap_zero (o2hb_live_region_bitmap,O2NM_MAX_REGIONS ); +bitmap_zero (o2hb_quorum_region_bitmap,O2NM_MAX_REGIONS ); +bitmap_zero (o2hb_failed_region_bitmap,O2NM_MAX_REGIONS ); o2hb_dependent_users =0 ;
fs/ocfs2/cluster/nodemanager.c +1 -1
@@ -54,7 +54,7 @@ int o2nm_configured_node_map(unsigned long *map, unsigned bytes)return -EINVAL ;read_lock (&cluster->cl_nodes_lock); -memcpy (map, cluster->cl_nodes_bitmap,sizeof (cluster->cl_nodes_bitmap)); +bitmap_copy (map, cluster->cl_nodes_bitmap,O2NM_MAX_NODES );read_unlock (&cluster->cl_nodes_lock);return 0 ;
Signature · 7 lines
2.24.4 _______________________________________________ Ocfs2-devel mailing list [email protected] https://oss.oracle.com/mailman/listinfo/ocfs2-devel
PATCH 2/3 ocfs2: use bitmap API in fill_node_map
Pass bits directly into fill_node_map helper and use bitmap API directly to simplify code.
Signed-off-by Joseph Qi <[email protected]>
--- fs/ocfs2/cluster/heartbeat.c | 18 ++++++++---------- fs/ocfs2/cluster/heartbeat.h | 2 +- fs/ocfs2/cluster/netdebug.c | 2 +- fs/ocfs2/cluster/tcp.c | 6 ++---- fs/ocfs2/dlm/dlmdomain.c | 2 +- fs/ocfs2/stack_o2cb.c | 6 +++--- 6 files changed, 16 insertions(+), 20 deletions(-)
fs/ocfs2/cluster/heartbeat.c +8 -10
@@ -375,7 +375,7 @@ static void o2hb_nego_timeout(struct work_struct *work)if (reg->hr_last_hb_status)return ; -o2hb_fill_node_map (live_node_bitmap,sizeof (live_node_bitmap)); +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 );
@@ -1087,7 +1087,7 @@ static int o2hb_do_disk_heartbeat(struct o2hb_region *reg)* If a node is not configured but is in the livemap, we still need * to read the slot so as to be able to remove it from the livemap. */ -o2hb_fill_node_map (live_node_bitmap,sizeof (live_node_bitmap)); +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 ) {
@@ -1450,23 +1450,21 @@ void o2hb_init(void)/* if we're already in a callback then we're already serialized by the sem */ static void o2hb_fill_node_map_from_callback (unsigned long *map, -unsigned bytes) +unsigned int bits) { -BUG_ON (bytes < (BITS_TO_LONGS (O2NM_MAX_NODES ) *sizeof (unsigned long ))); - -memcpy (map, &o2hb_live_node_bitmap, bytes); +bitmap_copy (map, o2hb_live_node_bitmap, bits); }/* * get a map of all nodes that are heartbeating in any regions */ -void o2hb_fill_node_map (unsigned long *map,unsigned bytes) +void o2hb_fill_node_map (unsigned long *map,unsigned int 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, bytes); +o2hb_fill_node_map_from_callback (map, bits);spin_unlock (&o2hb_live_lock);up_read (&o2hb_callback_sem); }
@@ -2460,7 +2458,7 @@ int o2hb_check_node_heartbeating_no_sem(u8 node_num)unsigned long testing_map[BITS_TO_LONGS (O2NM_MAX_NODES )];spin_lock (&o2hb_live_lock); -o2hb_fill_node_map_from_callback (testing_map,sizeof (testing_map)); +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,
@@ -2477,7 +2475,7 @@ int o2hb_check_node_heartbeating_from_callback(u8 node_num) {unsigned long testing_map[BITS_TO_LONGS (O2NM_MAX_NODES )]; -o2hb_fill_node_map_from_callback (testing_map,sizeof (testing_map)); +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",
fs/ocfs2/cluster/heartbeat.h +1 -1
@@ -59,7 +59,7 @@ int o2hb_register_callback(const char *region_uuid,void o2hb_unregister_callback (const char *region_uuid,struct o2hb_callback_func *hc);void o2hb_fill_node_map (unsigned long *map, -unsigned bytes); +unsigned int bits);void o2hb_exit (void );void o2hb_init (void );int o2hb_check_node_heartbeating_no_sem (u8 node_num);
fs/ocfs2/cluster/netdebug.c +1 -1
@@ -438,7 +438,7 @@ static int o2net_fill_bitmap(char *buf, int len)unsigned long map[BITS_TO_LONGS (O2NM_MAX_NODES )];int i =-1 , out =0 ; -o2net_fill_node_map (map,sizeof (map)); +o2net_fill_node_map (map,O2NM_MAX_NODES );while ((i =find_next_bit (map,O2NM_MAX_NODES , i +1 )) <O2NM_MAX_NODES ) out +=scnprintf (buf + out,PAGE_SIZE - out,"%d " , i);
fs/ocfs2/cluster/tcp.c +2 -4
@@ -990,14 +990,12 @@ static int o2net_tx_can_proceed(struct o2net_node *nn, }/* Get a map of all nodes to which this node is currently connected to */ -void o2net_fill_node_map (unsigned long *map,unsigned bytes) +void o2net_fill_node_map (unsigned long *map,unsigned int bits) {struct o2net_sock_container *sc;int node, ret; -BUG_ON (bytes < (BITS_TO_LONGS (O2NM_MAX_NODES ) *sizeof (unsigned long ))); - -memset (map,0 , bytes); +bitmap_zero (map, bits);for (node =0 ; node <O2NM_MAX_NODES ; ++node) {if (!o2net_tx_can_proceed (o2net_nn_from_num (node), &sc, &ret))continue ;
fs/ocfs2/dlm/dlmdomain.c +1 -1
@@ -1604,7 +1604,7 @@ static int dlm_try_to_join_domain(struct dlm_ctxt *dlm)/* group sem locking should work for us here -- we're already * registered for heartbeat events so filling this should be * atomic wrt getting those handlers called. */ -o2hb_fill_node_map (dlm->live_nodes_map,sizeof (dlm->live_nodes_map)); +o2hb_fill_node_map (dlm->live_nodes_map,O2NM_MAX_NODES );spin_lock (&dlm->spinlock);memcpy (ctxt->live_map, dlm->live_nodes_map,sizeof (ctxt->live_map));
fs/ocfs2/stack_o2cb.c +3 -3
@@ -273,17 +273,17 @@ static int o2cb_cluster_check(void)*/ #define O2CB_MAP_STABILIZE_COUNT 60for (i =0 ; i <O2CB_MAP_STABILIZE_COUNT ; ++i) { -o2hb_fill_node_map (hbmap,sizeof (hbmap)); +o2hb_fill_node_map (hbmap,O2NM_MAX_NODES );if (!test_bit (node_num, hbmap)) {printk (KERN_ERR "o2cb: %s heartbeat has not been " "started.\n" , (o2hb_global_heartbeat_active () ?"Global" :"Local" ));return -EINVAL ; } -o2net_fill_node_map (netmap,sizeof (netmap)); +o2net_fill_node_map (netmap,O2NM_MAX_NODES );/* Force set the current node to allow easy compare */ set_bit (node_num, netmap); -if (!memcmp (hbmap, netmap,sizeof (hbmap))) +if (bitmap_equal (hbmap, netmap,O2NM_MAX_NODES ))return 0 ;if (i <O2CB_MAP_STABILIZE_COUNT -1 )msleep (1000 );
Signature · 7 lines
2.24.4 _______________________________________________ Ocfs2-devel mailing list [email protected] https://oss.oracle.com/mailman/listinfo/ocfs2-devel
PATCH 3/3 ocfs2/dlm: use bitmap API instead of hand-writing it
In reply to Joseph Qi via Ocfs2-develUse bitmap_zero/bitmap_copy/bitmap_qeual directly for bitmap operations.
Signed-off-by Joseph Qi <[email protected]>
--- fs/ocfs2/dlm/dlmcommon.h | 2 +- fs/ocfs2/dlm/dlmdomain.c | 17 +++++++---------- fs/ocfs2/dlm/dlmmaster.c | 30 +++++++++++++++--------------- fs/ocfs2/dlm/dlmrecovery.c | 2 +- 4 files changed, 24 insertions(+), 27 deletions(-)
fs/ocfs2/dlm/dlmcommon.h +1 -1
@@ -1094,7 +1094,7 @@ static inline enum dlm_status dlm_err_to_dlm_status(int err)static inline void dlm_node_iter_init (unsigned long *map,struct dlm_node_iter *iter) { -memcpy (iter->node_map, map,sizeof (iter->node_map)); +bitmap_copy (iter->node_map, map,O2NM_MAX_NODES ); iter->curnode =-1 ; }
fs/ocfs2/dlm/dlmdomain.c +7 -10
@@ -1576,8 +1576,8 @@ static int dlm_should_restart_join(struct dlm_ctxt *dlm,spin_lock (&dlm->spinlock);/* For now, we restart the process if the node maps have * changed at all */ - ret =memcmp (ctxt->live_map, dlm->live_nodes_map, -sizeof (dlm->live_nodes_map)); + ret = !bitmap_equal (ctxt->live_map, dlm->live_nodes_map, +O2NM_MAX_NODES );spin_unlock (&dlm->spinlock);if (ret)
@@ -1607,10 +1607,8 @@ static int dlm_try_to_join_domain(struct dlm_ctxt *dlm)o2hb_fill_node_map (dlm->live_nodes_map,O2NM_MAX_NODES );spin_lock (&dlm->spinlock); -memcpy (ctxt->live_map, dlm->live_nodes_map,sizeof (ctxt->live_map)); - +bitmap_copy (ctxt->live_map, dlm->live_nodes_map,O2NM_MAX_NODES );__dlm_set_joining_node (dlm, dlm->node_num); -spin_unlock (&dlm->spinlock); node =-1 ;
@@ -1643,8 +1641,7 @@ static int dlm_try_to_join_domain(struct dlm_ctxt *dlm)* yes_resp_map. Copy that into our domain map and send a join * assert message to clean up everyone elses state. */ spin_lock (&dlm->spinlock); -memcpy (dlm->domain_map, ctxt->yes_resp_map, -sizeof (ctxt->yes_resp_map)); +bitmap_copy (dlm->domain_map, ctxt->yes_resp_map,O2NM_MAX_NODES );set_bit (dlm->node_num, dlm->domain_map);spin_unlock (&dlm->spinlock);
@@ -2009,9 +2006,9 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain,mlog (0 ,"dlm->recovery_map=%p, &(dlm->recovery_map[0])=%p\n" , dlm->recovery_map, &(dlm->recovery_map[0 ])); -memset (dlm->recovery_map,0 ,sizeof (dlm->recovery_map)); -memset (dlm->live_nodes_map,0 ,sizeof (dlm->live_nodes_map)); -memset (dlm->domain_map,0 ,sizeof (dlm->domain_map)); +bitmap_zero (dlm->recovery_map,O2NM_MAX_NODES ); +bitmap_zero (dlm->live_nodes_map,O2NM_MAX_NODES ); +bitmap_zero (dlm->domain_map,O2NM_MAX_NODES ); dlm->dlm_thread_task =NULL ; dlm->dlm_reco_thread_task =NULL ;
fs/ocfs2/dlm/dlmmaster.c +15 -15
@@ -258,12 +258,12 @@ static void dlm_init_mle(struct dlm_master_list_entry *mle, mle->type = type;INIT_HLIST_NODE (&mle->master_hash_node);INIT_LIST_HEAD (&mle->hb_events); -memset (mle->maybe_map,0 ,sizeof (mle->maybe_map)); +bitmap_zero (mle->maybe_map,O2NM_MAX_NODES );spin_lock_init (&mle->spinlock);init_waitqueue_head (&mle->wq);atomic_set (&mle->woken,0 );kref_init (&mle->mle_refs); -memset (mle->response_map,0 ,sizeof (mle->response_map)); +bitmap_zero (mle->response_map,O2NM_MAX_NODES ); mle->master =O2NM_MAX_NODES ; mle->new_master =O2NM_MAX_NODES ; mle->inuse =0 ;
@@ -290,8 +290,8 @@ static void dlm_init_mle(struct dlm_master_list_entry *mle,atomic_inc (&dlm->mle_cur_count[mle->type]);/* copy off the node_map and register hb callbacks on our copy */ -memcpy (mle->node_map, dlm->domain_map,sizeof (mle->node_map)); -memcpy (mle->vote_map, dlm->domain_map,sizeof (mle->vote_map)); +bitmap_copy (mle->node_map, dlm->domain_map,O2NM_MAX_NODES ); +bitmap_copy (mle->vote_map, dlm->domain_map,O2NM_MAX_NODES );clear_bit (dlm->node_num, mle->vote_map);clear_bit (dlm->node_num, mle->node_map);
@@ -572,7 +572,7 @@ static void dlm_init_lockres(struct dlm_ctxt *dlm,spin_unlock (&dlm->track_lock);memset (res->lvb,0 ,DLM_LVB_LEN ); -memset (res->refmap,0 ,sizeof (res->refmap)); +bitmap_zero (res->refmap,O2NM_MAX_NODES ); } struct dlm_lock_resource *dlm_new_lockres(struct dlm_ctxt *dlm,
@@ -1036,10 +1036,10 @@ static int dlm_wait_for_lock_mastery(struct dlm_ctxt *dlm,spin_lock (&mle->spinlock); m = mle->master; - map_changed = (memcmp (mle->vote_map, mle->node_map, -sizeof (mle->vote_map)) !=0 ); - voting_done = (memcmp (mle->vote_map, mle->response_map, -sizeof (mle->vote_map)) ==0 ); + map_changed = !bitmap_equal (mle->vote_map, mle->node_map, +O2NM_MAX_NODES ); + voting_done =bitmap_equal (mle->vote_map, mle->response_map, +O2NM_MAX_NODES );/* restart if we hit any errors */ if (map_changed) {
@@ -1277,11 +1277,11 @@ static int dlm_restart_lock_mastery(struct dlm_ctxt *dlm,/* now blank out everything, as if we had never * contacted anyone */ -memset (mle->maybe_map,0 ,sizeof (mle->maybe_map)); -memset (mle->response_map,0 ,sizeof (mle->response_map)); +bitmap_zero (mle->maybe_map,O2NM_MAX_NODES ); +bitmap_zero (mle->response_map,O2NM_MAX_NODES );/* reset the vote_map to the current node_map */ -memcpy (mle->vote_map, mle->node_map, -sizeof (mle->node_map)); +bitmap_copy (mle->vote_map, mle->node_map, +O2NM_MAX_NODES );/* put myself into the maybe map */ if (mle->type !=DLM_MLE_BLOCK )set_bit (dlm->node_num, mle->maybe_map);
@@ -2094,7 +2094,7 @@ static void dlm_assert_master_worker(struct dlm_work_item *item, void *data) flags = item->u.am.flags;spin_lock (&dlm->spinlock); -memcpy (nodemap, dlm->domain_map,sizeof (nodemap)); +bitmap_copy (nodemap, dlm->domain_map,O2NM_MAX_NODES );spin_unlock (&dlm->spinlock);clear_bit (dlm->node_num, nodemap);
@@ -3447,7 +3447,7 @@ int dlm_finish_migration(struct dlm_ctxt *dlm, struct dlm_lock_resource *res, ret =0 ; } -memset (iter.node_map,0 ,sizeof (iter.node_map)); +bitmap_zero (iter.node_map,O2NM_MAX_NODES );set_bit (old_master, iter.node_map);mlog (0 ,"doing assert master of %.*s back to %u\n" , res->lockname.len, res->lockname.name, old_master);
fs/ocfs2/dlm/dlmrecovery.c +1 -1
@@ -733,7 +733,7 @@ static int dlm_init_recovery_area(struct dlm_ctxt *dlm, u8 dead_node)struct dlm_reco_node_data *ndata;spin_lock (&dlm->spinlock); -memcpy (dlm->reco.node_map, dlm->domain_map,sizeof (dlm->domain_map)); +bitmap_copy (dlm->reco.node_map, dlm->domain_map,O2NM_MAX_NODES );/* nodes can only be removed (by dying) after dropping * this lock, and death will be trapped later, so this should do */ spin_unlock (&dlm->spinlock);
Signature · 7 lines
2.24.4 _______________________________________________ Ocfs2-devel mailing list [email protected] https://oss.oracle.com/mailman/listinfo/ocfs2-devel